:root {
    --bg: #eef2f7;
    --panel: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #dbe3ec;

    --navy: #0f172a;
    --primary: #0f766e;
    --primary-dark: #115e59;

    --green: #166534;
    --green-bg: #dcfce7;

    --orange: #a16207;
    --orange-bg: #fef3c7;

    --red: #b91c1c;
    --red-bg: #fee2e2;

    --blue-bg: #e0f2fe;

    --shadow:
        0 8px 30px rgba(15, 23, 42, 0.07);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    opacity: 0.55;
    cursor: wait;
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--muted);
}

.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 50;

    min-height: 68px;
    padding: 10px 18px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;

    color: #ffffff;
    background: var(--navy);
}

.admin-brand {
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.admin-subbrand {
    margin-top: 2px;
    color: #cbd5e1;
    font-size: 12px;
}

.admin-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logout-form {
    margin: 0;
}

.dashboard-shell {
    width: min(100%, 1500px);
    margin: 0 auto;
    padding: 18px;
}

.panel {
    margin-bottom: 16px;
    padding: 18px;

    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.filter-grid {
    display: grid;
    grid-template-columns:
        minmax(180px, 0.7fr)
        minmax(280px, 1.5fr)
        minmax(220px, 0.8fr);
    gap: 14px;
    align-items: end;
}

.field {
    display: block;
}

.field > span,
.refresh-label {
    display: block;
    margin-bottom: 6px;

    color: #334155;
    font-size: 12px;
    font-weight: 800;
}

input,
select {
    width: 100%;
    min-height: 44px;
    padding: 8px 11px;

    color: var(--text);
    background: #ffffff;

    border: 1px solid #cbd5e1;
    border-radius: 10px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow:
        0 0 0 3px rgba(15, 118, 110, 0.11);
}

.refresh-row {
    min-height: 44px;

    display: flex;
    align-items: center;
    gap: 9px;
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;

    padding: 6px 9px;
    border-radius: 999px;

    color: var(--green);
    background: var(--green-bg);

    font-size: 11px;
    font-weight: 950;
    letter-spacing: 0.06em;
}

.live-indicator::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.live-indicator.paused {
    color: var(--orange);
    background: var(--orange-bg);
}

.live-indicator.error {
    color: var(--red);
    background: var(--red-bg);
}

.refresh-text {
    color: var(--muted);
    font-size: 12px;
}

.btn {
    min-height: 42px;
    padding: 8px 14px;

    border: 1px solid transparent;
    border-radius: 10px;

    font-weight: 800;
    text-decoration: none;
}

.btn-primary {
    color: #ffffff;
    background: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    color: #334155;
    background: #ffffff;
    border-color: #cbd5e1;
}

.btn-danger-outline {
    color: #fecaca;
    background: transparent;
    border-color: #7f1d1d;
}

.btn-small {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.summary-card {
    min-height: 120px;
    padding: 18px;

    display: flex;
    flex-direction: column;
    justify-content: center;

    border-radius: 16px;
    border: 1px solid var(--border);
    background: #ffffff;
    box-shadow: var(--shadow);
}

.summary-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.summary-card strong {
    margin-top: 3px;
    font-size: clamp(34px, 5vw, 52px);
    line-height: 1;
}

.summary-card:nth-child(2) {
    background: var(--green-bg);
    border-color: #bbf7d0;
}

.summary-card:nth-child(3) {
    background: var(--orange-bg);
    border-color: #fde68a;
}

.section-heading {
    margin-bottom: 14px;

    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.section-heading h2 {
    margin: 0;
    font-size: 18px;
}

.section-heading p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.last-updated {
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.category-card {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
}

.category-title {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 900;
}

.mini-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.mini-stats > div {
    min-width: 0;
    padding: 8px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.8);
    text-align: center;
}

.mini-stats span {
    display: block;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
}

.mini-stats strong {
    display: block;
    margin-top: 2px;
    font-size: 19px;
}

.departure-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(230px, 1fr));
    gap: 10px;
}

.departure-card {
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
}

.departure-card-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.departure-card-head strong {
    font-size: 13px;
}

.departure-card-head span {
    color: var(--primary);
    font-size: 12px;
    font-weight: 900;
}

.progress {
    height: 7px;
    margin: 10px 0;

    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
}

.progress-bar {
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
    transition: width 180ms ease;
}

.departure-stats > div {
    background: #ffffff;
}

.dashboard-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.data-panel {
    min-width: 0;
    margin-bottom: 0;
}

.table-wrap {
    width: 100%;
    overflow: auto;
    max-height: 440px;
}

.live-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.live-table th,
.live-table td {
    padding: 9px 8px;
    border-bottom: 1px solid #e2e8f0;
    text-align: right;
    white-space: nowrap;
}

.live-table th:first-child,
.live-table td:first-child {
    width: 100%;
    text-align: left;
    white-space: normal;
}

.live-table th {
    position: sticky;
    top: 0;
    z-index: 2;

    color: #475569;
    background: #f8fafc;

    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.empty-state {
    padding: 18px;
    color: var(--muted);
    text-align: center;
    font-size: 12px;
}

.dashboard-error {
    position: sticky;
    bottom: 16px;

    margin-top: 16px;
    padding: 12px 14px;

    color: #991b1b;
    background: var(--red-bg);

    border: 1px solid #fecaca;
    border-radius: 12px;

    font-size: 13px;
    font-weight: 700;
}


/* LOGIN */

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
    background:
        radial-gradient(
            circle at top,
            #1e293b,
            #0f172a 58%
        );
}

.login-shell {
    width: min(100%, 430px);
}

.login-card {
    padding: 28px;

    border-radius: 18px;
    background: #ffffff;
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.28);
}

.login-brand {
    color: var(--primary);
    font-size: 13px;
    font-weight: 950;
    letter-spacing: 0.1em;
}

.login-card h1 {
    margin: 5px 0 0;
    font-size: 27px;
}

.login-card p {
    margin: 7px 0 18px;
    font-size: 13px;
}

.login-card .field {
    margin-top: 13px;
}

.login-button {
    width: 100%;
    margin-top: 18px;
}

.login-error {
    margin-bottom: 14px;
    padding: 10px 12px;

    color: #991b1b;
    background: var(--red-bg);

    border: 1px solid #fecaca;
    border-radius: 10px;

    font-size: 12px;
    font-weight: 700;
}


@media (max-width: 950px) {
    .filter-grid {
        grid-template-columns: 1fr 1fr;
    }

    .refresh-block {
        grid-column: 1 / -1;
    }

    .dashboard-columns {
        grid-template-columns: 1fr;
    }
}


@media (max-width: 650px) {
    .admin-topbar {
        align-items: flex-start;
        padding: 10px 12px;
    }

    .admin-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .dashboard-shell {
        padding: 10px;
    }

    .panel {
        padding: 13px;
        border-radius: 13px;
    }

    .filter-grid {
        grid-template-columns: 1fr;
    }

    .refresh-block {
        grid-column: auto;
    }

    .summary-grid {
        gap: 6px;
    }

    .summary-card {
        min-height: 92px;
        padding: 10px;
        border-radius: 12px;
    }

    .summary-card span {
        font-size: 10px;
    }

    .summary-card strong {
        font-size: 31px;
    }

    .category-grid {
        grid-template-columns: 1fr;
    }

    .section-heading {
        flex-direction: column;
    }

    .last-updated {
        white-space: normal;
    }
}


/* ============================================================
   FAZA 6 - UNDO + AUDIT
   ============================================================ */

.audit-note {
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.audit-table-wrap {
    max-height: 520px;
}

.audit-history-wrap {
    max-height: 620px;
}

.audit-table td {
    vertical-align: top;
}

.audit-table td:first-child {
    width: auto;
    min-width: 150px;
}

.audit-table small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 10px;
}

.action-cell {
    width: 1%;
    text-align: right !important;
}

.reason-cell {
    min-width: 180px;
    white-space: normal !important;
}

.btn-danger {
    color: #ffffff;
    background: var(--red);
    border-color: var(--red);
}

.btn-danger-outline-dark {
    color: var(--red);
    background: #ffffff;
    border-color: #fecaca;
}

.event-badge {
    display: inline-flex;
    padding: 4px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 950;
    letter-spacing: 0.04em;
}

.event-checkin {
    color: var(--green);
    background: var(--green-bg);
}

.event-undo {
    color: var(--red);
    background: var(--red-bg);
}

.event-recheckin {
    color: #075985;
    background: var(--blue-bg);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;

    display: grid;
    place-items: center;

    padding: 18px;

    background: rgba(15, 23, 42, 0.68);
}

.modal-card {
    width: min(100%, 560px);
    max-height: min(90vh, 760px);
    overflow: auto;

    padding: 20px;

    border-radius: 16px;
    background: #ffffff;
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.32);
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.modal-head h2 {
    margin: 0;
    font-size: 20px;
}

.modal-head p {
    margin: 5px 0 0;
    font-size: 12px;
    line-height: 1.45;
}

.modal-close {
    width: 34px;
    height: 34px;

    display: grid;
    place-items: center;

    border: 0;
    border-radius: 9px;

    color: #475569;
    background: #f1f5f9;

    font-size: 24px;
    line-height: 1;
}

.undo-warning {
    margin-top: 15px;
    padding: 11px 12px;

    color: #92400e;
    background: #fffbeb;

    border: 1px solid #fde68a;
    border-radius: 10px;

    font-size: 12px;
    font-weight: 700;
    line-height: 1.45;
}

.undo-field {
    margin-top: 14px;
}

textarea {
    width: 100%;
    padding: 10px 11px;

    resize: vertical;

    color: var(--text);
    background: #ffffff;

    border: 1px solid #cbd5e1;
    border-radius: 10px;
    outline: none;
}

textarea:focus {
    border-color: var(--primary);
    box-shadow:
        0 0 0 3px rgba(15, 118, 110, 0.11);
}

.modal-actions {
    margin-top: 18px;

    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-error {
    margin-top: 12px;
    padding: 9px 11px;

    color: #991b1b;
    background: var(--red-bg);

    border: 1px solid #fecaca;
    border-radius: 9px;

    font-size: 12px;
    font-weight: 700;
}

@media (max-width: 650px) {
    .audit-table-wrap,
    .audit-history-wrap {
        max-height: 520px;
    }

    .modal-backdrop {
        align-items: end;
        padding: 0;
    }

    .modal-card {
        width: 100%;
        max-height: 88vh;

        border-radius: 18px 18px 0 0;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions .btn {
        width: 100%;
    }
}
