:root {
            --border: #cfcfcf;
            --background: #f4f4f4;
            --panel: #ffffff;
            --soft: #f8f8f8;
            --text: #222222;
            --muted: #666666;
            --primary: #222222;
            --danger: #9b1c1c;
        }

        * {
            box-sizing: border-box;
        }

        html {
            -webkit-text-size-adjust: 100%;
        }

        body {
            margin: 0;
            background: var(--background);
            color: var(--text);
            font-family: Arial, Helvetica, sans-serif;
            line-height: 1.4;
        }

        button,
        input {
            font: inherit;
        }

        button {
            min-height: 46px;
            padding: 12px 18px;
            border: 1px solid #888;
            border-radius: 6px;
            background: #fff;
            color: var(--text);
            cursor: pointer;
            touch-action: manipulation;
        }

        button:hover {
            background: #eee;
        }

        button:focus-visible,
        input:focus-visible {
            outline: 3px solid rgba(0, 0, 0, 0.18);
            outline-offset: 2px;
        }
        button#currentWeekButton {
            background-color: #00ccff;
            border-color: #00ccff;
            color: #fff;
        }

        .app {
            width: calc(100% - 40px);
            max-width: 1100px;
            margin: 30px auto;
            padding: 25px;
            background: var(--panel);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
        }


        /* ==================================================
           HEADER
           ================================================== */

        .app-header {
            margin-bottom: 25px;
            text-align: center;
        }

        .app-header h1 {
            margin: 0 0 10px;
            font-size: clamp(1.65rem, 4vw, 2rem);
        }

        #currentDate {
            margin: 0;
            color: var(--muted);
        }

        .live-clock {
            margin-top: 10px;
            font-size: clamp(2rem, 7vw, 2.7rem);
            line-height: 1.1;
            font-weight: bold;
            font-variant-numeric: tabular-nums;
        }


        /* ==================================================
           CLOCK PANEL
           ================================================== */

        .clock-panel {
            margin-bottom: 30px;
            padding: 25px;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: var(--soft);
            text-align: center;
        }

        .status-box {
            margin-bottom: 20px;
        }

        .status-label {
            display: block;
            margin-bottom: 5px;
            color: var(--muted);
            font-size: 0.9rem;
        }

        #statusText {
            font-size: 1.3rem;
            color: blue;
        }

        .clock-button {
            width: min(100%, 400px);
            min-height: 64px;
            padding: 18px 20px;
            border-color: var(--primary);
            background: var(--primary);
            color: #fff;
            font-size: 1.25rem;
            font-weight: bold;
        }

        .clock-button:hover {
            background: #444;
        }

        .action-message {
            min-height: 24px;
            margin: 15px 0 0;
            color: var(--muted);
        }


        /* ==================================================
           WEEK HEADER
           ================================================== */

        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            gap: 20px;
            margin-bottom: 15px;
        }

        .section-header h2 {
            margin: 0;
        }

        #weekRange {
            margin: 5px 0 0;
            color: var(--muted);
        }

        .week-controls {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }


        /* ==================================================
           TIMESHEET
           ================================================== */

        .table-wrapper {
            width: 100%;
            overflow-x: auto;
        }

        table {
            width: 100%;
            min-width: 750px;
            border-collapse: collapse;
        }

        th,
        td {
            padding: 10px;
            border: 1px solid var(--border);
            text-align: center;
            vertical-align: middle;
        }

        th {
            background: #eee;
            white-space: nowrap;
        }

        td {
            font-variant-numeric: tabular-nums;
        }

        .day-name {
            font-weight: bold;
        }


        /* ==================================================
           WEEKLY TOTALS
           ================================================== */

        .totals {
            display: flex;
            justify-content: flex-end;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 20px;
        }

        .total-card {
            min-width: 180px;
            padding: 15px;
            border: 1px solid var(--border);
            border-radius: 6px;
            background: #fff;
        }

        .total-card span {
            display: block;
            margin-bottom: 6px;
            color: var(--muted);
            font-size: 0.9rem;
        }

        .total-card strong {
            font-size: 1.5rem;
            font-variant-numeric: tabular-nums;
        }

        .total-highlight {
            border-width: 2px;
            font-weight: bold;
        }


        /* ==================================================
           PAYROLL SUMMARY
           ================================================== */

        .payroll-summary {
            margin-top: 30px;
            padding: 22px;
            border: 2px solid var(--border);
            border-radius: 8px;
            background: #fafafa;
        }

        .payroll-header {
            margin-bottom: 18px;
        }

        .payroll-header h2 {
            margin: 0 0 5px;
        }

        .payroll-header p {
            margin: 0;
            color: var(--muted);
        }

        #payPeriodRange {
            margin-top: 5px;
            font-weight: bold;
        }

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

        .payroll-card {
            padding: 15px;
            border: 1px solid var(--border);
            border-radius: 6px;
            background: #fff;
        }

        .payroll-card span {
            display: block;
            margin-bottom: 6px;
            color: var(--muted);
            font-size: 0.9rem;
        }

        .payroll-card strong {
            display: block;
            font-size: 1.4rem;
            font-variant-numeric: tabular-nums;
        }

        .payroll-card small {
            display: block;
            margin-top: 6px;
            color: var(--muted);
            line-height: 1.35;
        }

        .payroll-total {
            border-width: 2px;
        }

        .payroll-pay {
            border: 2px solid var(--primary);
        }

        .payroll-pay strong {
            font-size: 1.65rem;
        }


        /* ==================================================
           BOTTOM CONTROLS
           ================================================== */

        .bottom-controls {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-top: 30px;
        }

        .primary-button {
            border-color: var(--primary);
            background: var(--primary);
            color: #fff;
            font-weight: bold;
        }

        .primary-button:hover {
            background: #444;
        }

        .danger-button {
            margin-left: auto;
            border-color: #c98f8f;
            background: #fff5f5;
            color: var(--danger);
        }

        .danger-button:hover {
            background: #ffeaea;
        }


        /* ==================================================
           EDIT PANEL
           ================================================== */

        .edit-panel {
            margin-top: 30px;
            padding: 25px;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: var(--soft);
        }

        .edit-panel > h2 {
            margin-top: 0;
        }

        .hidden {
            display: none;
        }

        .edit-day {
            margin-bottom: 25px;
            padding-bottom: 20px;
            border-bottom: 1px solid var(--border);
        }

        .edit-day:last-child {
            margin-bottom: 0;
            border-bottom: 0;
        }

        .edit-day h3 {
            margin: 0 0 15px;
        }

        .edit-fields {
            display: grid;
            grid-template-columns: repeat(4, minmax(130px, 1fr));
            gap: 12px;
        }

        .edit-fields label {
            display: flex;
            flex-direction: column;
            gap: 6px;
            font-size: 0.9rem;
            font-weight: bold;
        }

        .edit-fields input {
            width: 100%;
            min-height: 46px;
            padding: 10px;
            border: 1px solid #aaa;
            border-radius: 5px;
            background: #fff;
        }

        .edit-controls {
            display: flex;
            gap: 10px;
            margin-top: 20px;
        }

        .print-footer {
            display: none;
        }


        /* ==================================================
           TABLET
           ================================================== */

        @media (max-width: 900px) {
            .app {
                width: calc(100% - 24px);
                margin: 12px auto;
                padding: 22px;
            }

            .section-header {
                align-items: flex-start;
                flex-direction: column;
                gap: 14px;
            }

            .week-controls {
                width: 100%;
            }

            .week-controls button {
                flex: 1 1 150px;
            }

            .edit-fields {
                grid-template-columns: repeat(2, minmax(0, 1fr));
            }

            .totals,
            .payroll-grid {
                display: grid;
                grid-template-columns: repeat(2, 1fr);
            }

            .total-highlight,
            .payroll-pay {
                grid-column: 1 / -1;
            }

            .total-card {
                min-width: 0;
            }

            .bottom-controls button {
                flex: 1 1 180px;
            }

            .danger-button {
                margin-left: 0;
            }
        }


        /* ==================================================
           MOBILE
           ================================================== */

        @media (max-width: 700px) {
            body {
                background: #fff;
            }

            .edit-fields input[type="datetime-local"] {
                color: #1473e6;
                font-weight: 600;
            }


            .app {
                width: 100%;
                margin: 0;
                padding: 16px;
                box-shadow: none;
            }

            .app-header {
                margin-top: 8px;
                margin-bottom: 20px;
            }

            .clock-panel {
                margin-bottom: 25px;
                padding: 20px 15px;
            }

            .clock-button {
                width: 100%;
                min-height: 68px;
                font-size: 1.15rem;
            }

            .week-controls {
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 8px;
            }

            #currentWeekButton {
                grid-column: 1 / -1;
                grid-row: 1;

            }


            /* Mobile day cards */

            .table-wrapper {
                overflow: visible;
            }

            table {
                display: block;
                min-width: 0;
            }

            thead {
                display: none;
            }

            tbody {
                display: grid;
                gap: 12px;
            }

            tr {
                display: block;
                overflow: hidden;
                border: 1px solid var(--border);
                border-radius: 8px;
                background: #fff;
                box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
            }

            td {
                display: flex;
                justify-content: space-between;
                align-items: center;
                gap: 15px;
                width: 100%;
                min-height: 44px;
                padding: 10px 12px;
                border: 0;
                border-bottom: 1px solid #eee;
                text-align: right;
            }

            td:last-child {
                border-bottom: 0;
            }

            td::before {
                content: attr(data-label);
                flex: 0 0 auto;
                color: var(--muted);
                text-align: left;
            }

            td.day-name {
                display: block;
                padding: 12px;
                background: #eee;
                text-align: left;
            }

            td.day-name::before {
                display: none;
            }

            td.total-hours-cell {
                background: #fafafa;
                font-weight: bold;
            }


            /* Mobile totals */

            .totals,
            .payroll-grid {
                grid-template-columns: 1fr;
            }

            .total-highlight,
            .payroll-pay {
                grid-column: auto;
            }

            .payroll-summary {
                padding: 18px 15px;
            }


            /* Mobile controls */

            .bottom-controls,
            .edit-controls {
                display: grid;
                grid-template-columns: 1fr;
            }

            .bottom-controls button,
            .edit-controls button {
                width: 100%;
            }


            /* Mobile editing */

            .edit-panel {
                padding: 18px 15px;
            }

            .edit-day {
                margin-bottom: 15px;
                padding: 16px;
                border: 1px solid var(--border);
                border-radius: 7px;
                background: #fff;
            }

            .edit-day:last-child {
                border-bottom: 1px solid var(--border);
            }

            .edit-fields {
                grid-template-columns: 1fr;
                gap: 14px;
            }

            .edit-fields input {
                min-height: 50px;
                font-size: 16px;
            }
        }


        /* ==================================================
           SMALL PHONES
           ================================================== */

        @media (max-width: 420px) {
            .app {
                padding: 13px;
            }

            .week-controls {
                grid-template-columns: 1fr;
            }

            #currentWeekButton {
                grid-column: auto;
                grid-row: auto;
            }

            .total-card {
                display: flex;
                justify-content: space-between;
                align-items: center;
                gap: 20px;
            }

            .total-card span {
                margin-bottom: 0;
            }
        }


        /* ==================================================
           PRINT
           ================================================== */

        @media print {
            @page {
                size: portrait;
                margin: 0.5in;
            }

            body {
                background: #fff;
            }

            .app {
                width: 100%;
                max-width: none;
                margin: 0;
                padding: 0;
                box-shadow: none;
            }

            .no-print,
            .edit-panel {
                display: none !important;
            }

            .live-clock {
                display: none;
            }

            .table-wrapper {
                overflow: visible;
            }

            table {
                display: table;
                width: 100%;
                min-width: 0;
            }

            thead {
                display: table-header-group;
            }

            tbody {
                display: table-row-group;
            }

            tr {
                display: table-row;
                border: 0;
                box-shadow: none;
            }

            th,
            td,
            td.day-name {
                display: table-cell;
                padding: 7px;
                border: 1px solid var(--border);
                background: transparent;
                font-size: 10pt;
                text-align: center;
            }

            td::before {
                display: none !important;
            }

            .totals {
                display: flex;
                justify-content: flex-end;
            }

            .total-card {
                display: block;
                min-width: 150px;
            }

            .payroll-summary {
                break-inside: avoid;
            }

            .payroll-grid {
                grid-template-columns: repeat(3, 1fr);
            }

            .payroll-pay {
                grid-column: auto;
            }

            .print-footer {
                display: flex;
                justify-content: space-between;
                margin-top: 50px;
                font-size: 11pt;
            }
        }

/* ==================================================
   SERVER APP / LOGIN
   ================================================== */

.employee-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin: -5px 0 22px;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.employee-bar strong,
.employee-bar span {
    display: block;
}

.employee-bar span {
    color: var(--muted);
    font-size: 0.85rem;
}

.employee-bar a {
    color: var(--text);
    text-decoration: none;
    font-weight: bold;
}

.login-shell {
    width: calc(100% - 30px);
    max-width: 430px;
    margin: 9vh auto 30px;
}

.login-card {
    padding: 28px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,.12);
}

.login-card h1 {
    margin: 0 0 8px;
}

.login-card p {
    color: var(--muted);
}

.login-card label {
    display: block;
    margin: 15px 0 6px;
    font-weight: bold;
}

.login-card input {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid #aaa;
    border-radius: 6px;
    font-size: 16px;
}

.login-card button {
    width: 100%;
    margin-top: 20px;
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
    font-weight: bold;
}

.login-error,
.app-message.error {
    color: #8b1111;
}

.app-message {
    min-height: 24px;
    margin: 12px 0 0;
    text-align: center;
}

.payroll-grid.payroll-expanded {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 900px) {
    .payroll-grid.payroll-expanded {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 700px) {
    .employee-bar {
        align-items: flex-start;
    }

    .payroll-grid.payroll-expanded {
        grid-template-columns: 1fr;
    }
}
