:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #6f7b87;
    --line: #e4e8ec;
    --accent: #1b4877;
    --accent-dark: #183c63;
    --danger: #b33a3a;
    --sidebar: #172533;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

button, input { font: inherit; }

button { cursor: pointer; }

[hidden] { display: none !important; }

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 15%, #e0eaf5 0, transparent 35%),
        linear-gradient(135deg, #f7f9fb, #eef2f7);
}

.login-card {
    width: min(420px, 100%);
    padding: 42px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 24px 70px rgba(32, 80, 137, 0.12);
}

.brand-mark {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--accent);
    color: white;
    font-weight: 800;
    font-size: 24px;
}

.brand-mark.small {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 17px;
}

.eyebrow {
    margin: 22px 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
}

h1, h2, p { margin-top: 0; }

h1 { margin-bottom: 8px; }

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

form label {
    display: grid;
    gap: 7px;
    margin-top: 18px;
    color: #3f4a54;
    font-size: 14px;
    font-weight: 650;
}

input {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid #cfd6dc;
    border-radius: 10px;
    background: white;
    color: var(--text);
    outline: none;
}

input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(32, 80, 137, 0.12);
}

.primary, .secondary {
    min-height: 42px;
    padding: 10px 17px;
    border-radius: 10px;
    border: 0;
    font-weight: 750;
}

.primary {
    background: var(--accent);
    color: white;
}

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

.secondary {
    background: #edf0f2;
    color: var(--text);
}

.login-card .primary {
    width: 100%;
    margin-top: 24px;
}

.error {
    margin: 14px 0 0;
    padding: 10px 12px;
    border-radius: 9px;
    background: #fff0f0;
    color: var(--danger);
    font-size: 14px;
}

.dashboard {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--sidebar);
    color: white;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 34px;
    font-weight: 800;
}

nav { display: grid; gap: 7px; }

.nav-item, .logout {
    padding: 12px 14px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #c8d4e1;
    text-align: left;
}

.nav-item.active {
    background: rgba(255,255,255,0.1);
    color: white;
}

.nav-item.disabled { opacity: 0.48; }

.logout { color: #dbe2ea; }

.content {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 34px 40px 50px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar .eyebrow { margin-top: 0; }

.user-badge {
    display: grid;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
}

.user-badge small { color: var(--muted); }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 16px;
    margin: 26px 0;
}

.summary-card {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: white;
}

.summary-card span {
    display: block;
    margin-bottom: 9px;
    color: var(--muted);
    font-size: 14px;
}

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

.panel {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: white;
}

.panel-header {
    padding: 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--line);
}

.panel-header h2 { margin-bottom: 5px; }

.panel-header p { margin-bottom: 0; }

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

.checkbox-label {
    display: flex;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 9px;
    margin: 0;
    font-weight: 550;
}

.checkbox-label input { width: auto; }

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 15px 20px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td { font-size: 14px; }

.status {
    display: inline-flex;
    padding: 5px 9px;
    border-radius: 999px;
    background: #ebf3fb;
    color: var(--accent);
    font-size: 12px;
    font-weight: 750;
}

.status.inactive {
    background: #f0f1f2;
    color: #727c84;
}

.row-button {
    border: 0;
    background: transparent;
    color: var(--accent);
    font-weight: 700;
}

.empty-state {
    padding: 60px 20px;
    display: grid;
    gap: 6px;
    place-items: center;
    color: var(--muted);
}

.empty-state strong { color: var(--text); }

dialog {
    width: min(680px, calc(100% - 32px));
    padding: 0;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 30px 90px rgba(0,0,0,0.25);
}

dialog::backdrop {
    background: rgba(16, 35, 61, 0.55);
}

dialog form { padding: 26px; }

.dialog-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
}

.dialog-header .eyebrow { margin-top: 0; }

.icon-button {
    border: 0;
    background: transparent;
    font-size: 30px;
    color: var(--muted);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
}

.full-width { grid-column: 1 / -1; }

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 25px;
}

@media (max-width: 800px) {
    .dashboard { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
    }
    nav, .logout { display: none; }
    .content { padding: 24px 16px; }
    .topbar, .panel-header {
        align-items: stretch;
        flex-direction: column;
    }
    .summary-grid { grid-template-columns: 1fr; }
    .actions {
        align-items: stretch;
        flex-direction: column;
    }
    .form-grid { grid-template-columns: 1fr; }
    .full-width { grid-column: auto; }
}

.nav-item {
    display: block;
    text-decoration: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.date-control {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0;
}

.date-control input {
    width: auto;
}

.summary-grid.four {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.mini-button {
    padding: 7px 11px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: white;
    color: var(--accent);
    font-size: 13px;
    font-weight: 750;
}

.mini-button:hover {
    background: #eff6fd;
}

.status.open {
    background: #fff3d8;
    color: #936600;
}

.status.absent {
    background: #f0f1f2;
    color: #727c84;
}

.status.closed {
    background: #ebf3fb;
    color: var(--accent);
}

@media (max-width: 1000px) {
    .summary-grid.four {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 800px) {
    .topbar-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .summary-grid.four {
        grid-template-columns: 1fr;
    }
}

/* Employee access page */
.access-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 24px;
}

.access-card {
    padding: 20px;
    border: 1px solid #e3e8ef;
    border-radius: 16px;
    background: #ffffff;
}

.access-card h3 {
    margin: 0 0 7px;
    font-size: 17px;
}

.access-card p {
    min-height: 22px;
    margin: 0 0 18px;
    color: #7b8792;
}

.access-card button {
    width: 100%;
    padding: 11px 16px;
    border: 0;
    border-radius: 10px;
    background: #205089;
    color: #ffffff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.access-card button:hover {
    background: #193f6b;
}

.access-card button:disabled {
    opacity: .6;
    cursor: wait;
}

.page-message {
    grid-column: 1 / -1;
    padding: 40px;
    text-align: center;
    color: #7b8792;
}

#codeDialog {
    width: min(440px, calc(100% - 32px));
    border: 0;
    border-radius: 20px;
    padding: 0;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .25);
}

#codeDialog::backdrop {
    background: rgba(10, 30, 52, .55);
}

.code-content {
    padding: 28px;
    text-align: center;
}

.personal-code {
    margin: 22px 0 12px;
    padding: 18px;
    border-radius: 14px;
    background: #f0f7fd;
    color: #205089;
    font: 700 30px/1 monospace;
    letter-spacing: 3px;
}

.code-note {
    margin-bottom: 22px;
    color: #7b8792;
    line-height: 1.5;
}

.code-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

@media (max-width: 700px) {
    .access-grid {
        grid-template-columns: 1fr;
        padding: 14px;
    }
}

/* Mileage administration */
.mileage-panel-header {
    align-items: flex-end;
}

.mileage-filters {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.mileage-filters label {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.mileage-filters input,
.mileage-filters select {
    display: block;
    width: auto;
    min-width: 145px;
    margin-top: 6px;
}

.mileage-filters button {
    width: auto;
    margin: 0;
}

.mileage-actions {
    display: flex;
    gap: 7px;
}

.mini-button.reject {
    border-color: #c84d45;
    color: #a33b32;
}

.mini-button.reject:hover {
    background: #fff0ef;
}

.status.submitted {
    background: #fff3d8;
    color: #936600;
}

.status.approved,
.status.paid {
    background: #ebf3fb;
    color: var(--accent);
}

.status.rejected {
    background: #fff0ef;
    color: #a33b32;
}

@media (max-width: 800px) {
    .mileage-filters {
        width: 100%;
    }

    .mileage-filters label,
    .mileage-filters input,
    .mileage-filters select,
    .mileage-filters button {
        width: 100%;
    }
}

/* Google Sheets synchronization */
.sync-panel-header {
    gap: 20px;
}

.sync-panel-header .primary {
    white-space: nowrap;
}

.sync-time {
    font-size: 17px !important;
}

.sync-badge {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 750;
}

.sync-success {
    color: #205089;
}

.sync-badge.sync-success {
    background: #ebf3fb;
}

.sync-failed {
    color: #b42318;
}

.sync-badge.sync-failed {
    background: #feeceb;
}

.sync-running {
    color: #936600;
}

.sync-badge.sync-running {
    background: #fff3d8;
}

.sync-message {
    margin: 0 24px 18px;
    padding: 12px 15px;
    border-radius: 10px;
    font-weight: 650;
}

.sync-message-success {
    background: #ebf3fb;
    color: #205089;
}

.sync-message-error {
    background: #feeceb;
    color: #b42318;
}

.sync-error-cell {
    max-width: 360px;
    white-space: normal;
}

@media (max-width: 800px) {
    .sync-panel-header {
        align-items: stretch;
        flex-direction: column;
    }

    .sync-panel-header .primary {
        width: 100%;
    }
}

/* Admin payroll */
.payroll-summary-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.payroll-panel-header {
    gap: 20px;
}

.payroll-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.payroll-actions input {
    width: 230px;
}

.payroll-position {
    display: block;
    margin-top: 4px;
    color: #7b8792;
    font-weight: 400;
}

.payroll-positive {
    color: #205089 !important;
    font-weight: 750;
}

.payroll-negative {
    color: #b42318 !important;
    font-weight: 750;
}

.payroll-missing-row {
    color: #8a939b;
    background: #fafafa;
}

@media (max-width: 1200px) {
    .payroll-summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 800px) {
    .payroll-summary-grid {
        grid-template-columns: 1fr;
    }

    .payroll-panel-header,
    .payroll-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .payroll-actions input {
        width: 100%;
    }
}

/* Admin notifications */
.notification-settings {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 24px;
}

.notification-settings h2 {
    margin: 0 0 8px;
}

.notification-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.push-status {
    margin: 0;
    color: #7b8792;
}

.push-status.enabled {
    color: #205089;
}

.push-status.error {
    color: #b73535;
}

.notifications-list {
    display: grid;
}

.notification-item {
    display: grid;
    grid-template-columns: 110px minmax(160px, 230px) 1fr auto;
    align-items: center;
    gap: 16px;
    width: 100%;
    padding: 18px 24px;
    border: 0;
    border-top: 1px solid #e8edf3;
    background: #ffffff;
    color: #24313f;
    text-align: left;
    cursor: pointer;
}

.notification-item.unread {
    background: #f3f8fe;
}

.notification-item small {
    color: #7b8792;
    white-space: nowrap;
}

.notification-severity {
    display: inline-flex;
    justify-content: center;
    padding: 6px 9px;
    border-radius: 999px;
    background: #ecf2f8;
    color: #4a6078;
    font-size: 12px;
    font-weight: 750;
}

.notification-severity.warning {
    background: #fff3d8;
    color: #936600;
}

.notification-severity.error {
    background: #fde8e8;
    color: #a42c2c;
}

@media (max-width: 800px) {
    .notification-settings {
        align-items: stretch;
        flex-direction: column;
    }

    .notification-actions {
        display: grid;
    }

    .notification-item {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .notification-item small {
        white-space: normal;
    }
}

.employee-row-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Individual attendance schedule */
.schedule-cell strong {
    display: block;
    color: var(--text);
    font-size: 14px;
}

.schedule-cell small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.attendance-alerts {
    display: grid;
    gap: 5px;
    margin-top: 7px;
}

.attendance-deviation {
    display: inline-flex;
    width: max-content;
    padding: 5px 8px;
    border-radius: 999px;
    background: #fff0ef;
    color: #a33b32;
    font-size: 12px;
    font-weight: 750;
}

.attendance-row-warning td {
    background: #fffafa;
}

/* Attendance work intervals */
.attendance-interval-toggle {
    display: block;
    margin-top: 7px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 12px;
    font-weight: 750;
    text-align: left;
}

.attendance-interval-toggle:hover {
    text-decoration: underline;
}

.attendance-interval-row > td {
    padding: 0 18px 16px;
    border-bottom: 1px solid var(--line);
    background: #f6f9fc;
    white-space: normal;
}

.attendance-interval-panel {
    padding: 16px;
    border: 1px solid #dce6f1;
    border-radius: 14px;
    background: white;
}

.attendance-interval-panel-title {
    margin-bottom: 11px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.attendance-interval-list {
    display: grid;
    grid-template-columns: repeat(
        auto-fit,
        minmax(190px, 1fr)
    );
    gap: 10px;
}

.attendance-interval-card {
    min-width: 0;
    padding: 13px;
    border: 1px solid #e1e8f0;
    border-radius: 12px;
    background: #f8fafd;
}

.attendance-interval-number {
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
}

.attendance-interval-times {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.attendance-interval-times strong {
    color: #193a5c;
    font-size: 16px;
}

.attendance-interval-times span {
    color: var(--accent);
    font-size: 12px;
    font-weight: 750;
}

.attendance-interval-meta {
    margin-top: 7px;
    overflow-wrap: anywhere;
    color: var(--muted);
    font-size: 11px;
}

@media (max-width: 800px) {
    .attendance-interval-row > td {
        padding: 0 10px 12px;
    }

    .attendance-interval-list {
        grid-template-columns: 1fr;
    }
}

/* Attendance mobile cards */
@media (max-width: 800px) {
    .table-wrap {
        overflow: visible;
    }

    .table-wrap table {
        display: block;
        width: 100%;
        min-width: 0 !important;
    }

    .table-wrap thead {
        display: none;
    }

    #attendance-body {
        display: grid;
        gap: 12px;
        padding: 12px;
    }

    #attendance-body .attendance-main-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0 14px;
        overflow: hidden;
        border: 1px solid var(--line);
        border-radius: 16px;
        background: white;
        box-shadow: 0 7px 22px rgba(32, 80, 137, .06);
    }

    #attendance-body .attendance-main-row > td {
        display: flex;
        min-width: 0;
        padding: 11px 14px;
        align-items: flex-start;
        justify-content: space-between;
        gap: 10px;
        border: 0;
        border-top: 1px solid #edf1f5;
        white-space: normal;
        text-align: right;
    }

    #attendance-body .attendance-main-row > td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--muted);
        font-size: 11px;
        font-weight: 750;
        text-align: left;
    }

    #attendance-body .attendance-employee-cell {
        grid-column: 1 / -1;
        display: block !important;
        padding: 15px 14px 13px !important;
        border-top: 0 !important;
        text-align: left !important;
    }

    #attendance-body .attendance-employee-cell::before {
        display: none;
    }

    #attendance-body .attendance-employee-cell > strong {
        display: block;
        font-size: 17px;
    }

    #attendance-body .schedule-cell,
    #attendance-body .attendance-main-row > td:nth-child(8),
    #attendance-body .attendance-action-cell {
        grid-column: 1 / -1;
    }

    #attendance-body .schedule-cell strong {
        font-size: 14px;
    }

    #attendance-body .schedule-cell small {
        display: none;
    }

    #attendance-body .attendance-interval-toggle {
        width: auto !important;
        min-height: 0 !important;
        margin: 7px 0 0 !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        color: var(--accent) !important;
        box-shadow: none !important;
        font-size: 12px !important;
        text-align: left !important;
    }

    #attendance-body .attendance-action-cell {
        padding: 12px 14px 14px;
    }

    #attendance-body .attendance-action-cell::before {
        display: none;
    }

    #attendance-body .attendance-action-cell .mini-button {
        width: 100%;
        min-height: 44px;
        margin: 0;
    }

    #attendance-body .attendance-interval-row {
        display: block;
        margin-top: -12px;
    }

    #attendance-body .attendance-interval-row[hidden] {
        display: none !important;
    }

    #attendance-body .attendance-interval-row > td {
        display: block;
        padding: 0;
        border: 0;
        background: transparent;
    }

    #attendance-body .attendance-interval-panel {
        border-radius: 0 0 16px 16px;
        border-top: 0;
    }
}

/* Attendance interval editing */
.attendance-interval-edit {
    width: auto;
    min-height: 0;
    margin: 11px 0 0;
    padding: 7px 10px;
    border: 1px solid #c9d8e8;
    border-radius: 9px;
    background: white;
    color: var(--accent);
    font: inherit;
    font-size: 12px;
    font-weight: 750;
}

.attendance-interval-edit:hover {
    background: #eff6fd;
}

#interval-edit-dialog .security-note {
    margin: 16px 0 0;
}

@media (max-width: 800px) {
    #attendance-body .attendance-interval-edit {
        width: 100%;
        min-height: 40px;
        margin-top: 12px;
    }

    #interval-edit-dialog .form-grid {
        grid-template-columns: 1fr;
    }
}

.field-hint {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

#monthly-salary-field[hidden] {
    display: none !important;
}

.field-hint {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

#monthly-salary-field[hidden] {
    display: none !important;
}

/* Employee payment dialog */
.payment-row-button {
    color: #205089;
}

.payment-dialog {
    width: min(620px, calc(100% - 24px));
}

.payment-success {
    margin: 14px 0 0;
    padding: 12px 14px;
    border-radius: 11px;
    background: #eaf3fc;
    color: #205089;
    font-size: 14px;
    font-weight: 700;
}

.payment-history-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.payment-history-section h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.payment-history {
    display: grid;
    gap: 9px;
}

.payment-history-item {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f8fafd;
}

.payment-history-item div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.payment-history-item span,
.payment-history-item small,
.payment-history-empty {
    color: var(--muted);
}

.payment-history-item small {
    display: block;
    margin-top: 6px;
    line-height: 1.4;
}

.payment-history-empty {
    margin: 0;
    padding: 12px;
    text-align: center;
}

@media (max-width: 800px) {
    .employee-row-actions {
        align-items: stretch;
    }

    .payment-dialog form {
        padding: 20px 16px;
    }
}
