/* Reset a základní styly */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8f9fa;
    min-height: 100vh;
    line-height: 1.6;
    color: #333;
}

.app-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: white;
    border-bottom: 1px solid #e9ecef;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    height: 70px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo img {
    height: 40px;
    width: auto;
    display: block;
}

/* Rozbalovací část (na desktopu inline, na mobilu panel) */
.header-menu {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex: 1;
    min-width: 0;
}

.header-nav {
    display: flex;
    gap: 1rem;
    flex: 1;
    min-width: 0;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.header-nav a {
    color: #495057;
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.header-nav a:hover {
    background: #fff3cd;
    color: #856404;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.header-ip {
    font-size: 0.875rem;
    color: #6c757d;
    padding: 0.5rem 1rem;
    background: #e9ecef;
    border-radius: 20px;
    white-space: nowrap;
}

.header-user {
    font-size: 0.875rem;
    color: #495057;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-user a {
    color: #0066cc;
    text-decoration: none;
    font-weight: 500;
}

.header-user a:hover {
    text-decoration: underline;
}

/* Zvýrazněné odhlášení */
.header-user a.btn-logout {
    color: #dc3545;
    border: 1px solid #dc3545;
    padding: 0.35rem 0.9rem;
    border-radius: 6px;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.header-user a.btn-logout:hover {
    background: #dc3545;
    color: #fff;
    text-decoration: none;
}

/* Uživatelské okno – v hlavičce zůstane jen kolečko s iniciálami */
.user-menu {
    position: relative;
    flex-shrink: 0;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid #dee2e6;
    background: #e9ecef;
    color: #495057;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.user-avatar:hover,
.user-avatar.open {
    background: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 240px;
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 200;
}

.user-menu-panel[hidden] {
    display: none;
}

.user-menu-head {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 0.5rem 0.5rem;
    border-bottom: 1px solid #e9ecef;
    word-break: break-word;
}

.user-menu-head strong {
    color: #212529;
    font-size: 0.9rem;
}

.user-menu-head span {
    color: #6c757d;
    font-size: 0.8rem;
}

.user-menu-item {
    color: #495057;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.user-menu-item:hover {
    background: #fff3cd;
    color: #856404;
    text-decoration: none;
}

.user-menu-ip {
    font-size: 0.8rem;
    color: #6c757d;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
    word-break: break-all;
}

.user-menu-panel a.btn-logout {
    color: #dc3545;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    text-align: center;
    border: 1px solid #dc3545;
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.user-menu-panel a.btn-logout:hover {
    background: #dc3545;
    color: #fff;
    text-decoration: none;
}

/* Hamburger – skrytý na desktopu */
.hamburger {
    display: none;
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.hamburger span {
    display: block;
    width: 24px;
    height: 3px;
    background: #495057;
    border-radius: 2px;
    margin: 5px 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.hamburger.open span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* Main content */
main {
    flex: 1;
    width: 100%;
    padding: 0.5rem 1rem 2rem 1rem;
}

/* Typography */
h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: #212529;
    margin-bottom: 2rem;
    text-align: center;
}

h2 {
    font-size: 1.875rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 1.5rem;
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 1rem;
}

/* Dashboard specifické styly */
.dashboard-stats {
    margin-bottom: 3rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.25rem;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid #e9ecef;
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: #ffc107;
    margin-bottom: 0.25rem;
}

.stat-label {
    color: #6c757d;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Quick Actions Section */
.quick-actions {
    margin-top: 3rem;
}

.quick-actions h2 {
    margin-bottom: 1.5rem;
    color: #212529;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.action-card {
    background: white;
    padding: 0.85rem 1.1rem;
    border-radius: 10px;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid #e9ecef;
    display: block;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    border-color: #ffc107;
}

/* Ikona + název na jednom řádku */
.action-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.action-icon {
    font-size: 1.4rem;
    line-height: 1;
}

.action-title {
    font-size: 1rem;
    font-weight: 600;
    color: #212529;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 16px;
    margin: 4px 2px;
    text-decoration: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
    color: white;
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #1e7e34;
    color: white;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
    color: white;
}

/* Forms */
form:not(:has(table)) {
    max-width: 600px;
}

label {
    display: block;
    font-weight: 500;
    color: #495057;
    margin-bottom: 0.5rem;
    margin-top: 1rem;
}

label:first-of-type {
    margin-top: 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    margin-bottom: 0.5rem;
    background: white;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

button,
.btn {
    background: #0066cc;
    color: white;
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s ease;
}

button:hover,
.btn:hover {
    background: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 102, 204, 0.3);
}

.btn.btn-warning {
    background: #ffc107;
    color: #212529;
}

.btn.btn-warning:hover {
    background: #e0a800;
    box-shadow: 0 4px 15px rgba(255, 193, 7, 0.3);
}

/* Tables */
table {
    width: 100%;
    table-layout: auto;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid #e9ecef;
    margin-bottom: 2rem;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    background: #f8f9fa;
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #e9ecef;
}

td {
    padding: 0.75rem;
    border-bottom: 1px solid #e9ecef;
    white-space: nowrap;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

td.no-truncate {
    max-width: none;
    white-space: normal;
    overflow: visible;
}

tr:hover {
    background: #f8f9fa;
}


/* === Zmrazení prvního sloupce ve všech tabulkách === */
/* Funguje při vodorovném scrollu (uvnitř overflow kontejneru i na úrovni stránky). */
th:first-child,
td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    /* Svislý oddělovač zmrazeného sloupce – box-shadow funguje i u border-collapse tabulek */
    box-shadow: 1px 0 0 #e9ecef;
}

/* Pozadí musí být neprůhledné, aby pod zmrazeným sloupcem neprosvítal posouvaný obsah */
td:first-child { background: #ffffff; }
th:first-child { background: #f8f9fa; z-index: 3; }
tr:hover td:first-child { background: #f8f9fa; }

/* Statistické tabulky mají vlastní pruhování řádků a barvu záhlaví – zachováme je i ve zmrazeném sloupci */
.stats-table th:first-child { background: #f2f2f2; }
.stats-table td:first-child { background: #ffffff; }
.stats-table tr:nth-child(even) td:first-child { background: #f9f9f9; }
.stats-table tr:hover td:first-child { background: #f8f9fa; }


/* === Když je první sloupec checkbox, zmrazíme i druhý (hodnotový) sloupec === */
/* Pevná šířka checkbox sloupce, aby offset druhého sloupce přesně seděl */
.col-checkbox,
table:has(td:first-child input[type="checkbox"]) th:first-child,
table:has(td:first-child input[type="checkbox"]) td:first-child {
    box-sizing: border-box;
    width: 48px;
    min-width: 48px;
    max-width: 48px;
    text-align: center;
    padding-left: 8px;
    padding-right: 8px;
}

/* Druhý sloupec přilepený hned za checkbox sloupcem */
table:has(td:first-child input[type="checkbox"]) th:nth-child(2),
table:has(td:first-child input[type="checkbox"]) td:nth-child(2) {
    position: sticky;
    left: 48px;
    z-index: 2;
    box-shadow: 1px 0 0 #e9ecef;
}
table:has(td:first-child input[type="checkbox"]) td:nth-child(2) { background: #ffffff; }
table:has(td:first-child input[type="checkbox"]) th:nth-child(2) { background: #f8f9fa; z-index: 3; }
table:has(td:first-child input[type="checkbox"]) tr:hover td:nth-child(2) { background: #f8f9fa; }


/* === Seznam projektů (/projects): zmrazit první 3 sloupce (checkbox, Akce, Název kampaně) === */
/* Pevná šířka sloupce Akce, aby offset třetího sloupce přesně seděl */
#projectsTable:has(.col-checkbox) th:nth-child(2),
#projectsTable:has(.col-checkbox) td:nth-child(2) {
    box-sizing: border-box;
    width: 130px;
    min-width: 130px;
    max-width: 130px;
}
/* Třetí sloupec (Název kampaně) přilepený za checkbox (48px) + Akce (130px) */
#projectsTable:has(.col-checkbox) th:nth-child(3),
#projectsTable:has(.col-checkbox) td:nth-child(3) {
    position: sticky;
    left: 178px;
    z-index: 2;
    box-shadow: 1px 0 0 #e9ecef;
}
#projectsTable:has(.col-checkbox) td:nth-child(3) { background: #ffffff; }
#projectsTable:has(.col-checkbox) th:nth-child(3) { background: #f8f9fa; z-index: 3; }
#projectsTable:has(.col-checkbox) tr:hover td:nth-child(3) { background: #f8f9fa; }


/* === E-maily v projektu (/projects/view): zmrazit první 3 sloupce (checkbox, Akce, Název e-mailu) === */
#campaignsTable:has(.col-checkbox) th:nth-child(2),
#campaignsTable:has(.col-checkbox) td:nth-child(2) {
    box-sizing: border-box;
    width: 110px;
    min-width: 110px;
    max-width: 110px;
}
/* Třetí sloupec (Název e-mailu) přilepený za checkbox (48px) + Akce (110px) */
#campaignsTable:has(.col-checkbox) th:nth-child(3),
#campaignsTable:has(.col-checkbox) td:nth-child(3) {
    position: sticky;
    left: 158px;
    z-index: 2;
    box-shadow: 1px 0 0 #e9ecef;
}
#campaignsTable:has(.col-checkbox) td:nth-child(3) { background: #ffffff; }
#campaignsTable:has(.col-checkbox) th:nth-child(3) { background: #f8f9fa; z-index: 3; }
#campaignsTable:has(.col-checkbox) tr:hover td:nth-child(3) { background: #f8f9fa; }


/* === Šablony (/templates): zmrazit první 2 sloupce (Akce, Název šablony) === */
/* Pevná šířka sloupce Akce, aby offset druhého sloupce přesně seděl */
#templatesTable th:first-child,
#templatesTable td:first-child {
    box-sizing: border-box;
    width: 130px;
    min-width: 130px;
    max-width: 130px;
}
/* Druhý sloupec (Název šablony) přilepený za Akce (130px) */
#templatesTable th:nth-child(2),
#templatesTable td:nth-child(2) {
    position: sticky;
    left: 130px;
    z-index: 2;
    box-shadow: 1px 0 0 #e9ecef;
}
#templatesTable td:nth-child(2) { background: #ffffff; }
#templatesTable th:nth-child(2) { background: #f8f9fa; z-index: 3; }
#templatesTable tr:hover td:nth-child(2) { background: #f8f9fa; }


/* === Pravidla (/rules): zmrazit první 2 sloupce (Akce, Název) === */
/* Pevná šířka sloupce Akce (5 ikon: upravit, logy, duplikovat, test, smazat) */
#rulesTable th:first-child,
#rulesTable td:first-child {
    box-sizing: border-box;
    width: 175px;
    min-width: 175px;
    max-width: 175px;
}
/* Druhý sloupec (Název) přilepený za Akce (175px) */
#rulesTable th:nth-child(2),
#rulesTable td:nth-child(2) {
    position: sticky;
    left: 175px;
    z-index: 2;
    box-shadow: 1px 0 0 #e9ecef;
}
#rulesTable td:nth-child(2) { background: #ffffff; }
#rulesTable th:nth-child(2) { background: #f8f9fa; z-index: 3; }
#rulesTable tr:hover td:nth-child(2) { background: #f8f9fa; }


/* Sortable table headers */
th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    background-color: #e2e2e2;
}

th.sortable.asc::after {
    content: ' ↑';
}

th.sortable.desc::after {
    content: ' ↓';
}

/* Links */
a {
    color: #0066cc;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Footer */
footer {
    background: #495057;
    color: white;
    text-align: center;
    padding: 2rem;
    margin-top: 3rem;
}

/* Utility classes */
.text-center {
    text-align: center;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-4 {
    margin-bottom: 2rem;
}

/* Alerts/Flash messages */
.alert {
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

/* Responsive – hamburger menu */
@media (max-width: 1330px) {
    .hamburger {
        display: block;
    }

    .header-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        background: white;
        border-bottom: 1px solid #e9ecef;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
        padding: 0.5rem 1rem 1rem 1rem;
    }

    .header-menu.open {
        display: flex;
    }

    .header-nav {
        flex-direction: column;
        gap: 0;
    }

    .header-nav a {
        padding: 0.75rem 1rem;
        border-radius: 6px;
    }

    .header-meta {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        margin-top: 0.5rem;
        padding-top: 1rem;
        border-top: 1px solid #e9ecef;
    }

    .header-ip {
        text-align: center;
    }

    .header-user {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        text-align: center;
    }

    .user-menu {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .user-avatar {
        align-self: center;
    }

    /* V rozbaleném mobilním menu není kam plout – okno se vloží do proudu */
    .user-menu-panel {
        position: static;
        min-width: 0;
        box-shadow: none;
    }

    .header-user a.btn-logout {
        display: block;
        text-align: center;
        padding: 0.6rem 1rem;
        background: #dc3545;
        color: #fff;
        font-weight: 600;
    }
}

/* Responsive */
@media (max-width: 768px) {
    main {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    .stats-grid,
    .actions-grid {
        grid-template-columns: 1fr;
    }
}
/* Flash zprávy (Flash::display()) */
.flash {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.flash.success {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.flash.error {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.flash.warning {
    background: #fff3cd;
    border-color: #ffeeba;
    color: #856404;
}
