:root {
            --primary: #2ecc71;
            --primary-dark: #27ae60;
            --danger: #e74c3c;
            --text: #333;
            --bg: #f5f5f5;
            --card: #fff;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: var(--bg);
            color: var(--text);
        }

        #app {
            max-width: 760px;
            margin: 0 auto;
            min-height: 100vh;
            background: #fff;
            display: flex;
            flex-direction: column;
        }

        #app.admin-fullwidth {
            max-width: 100%;
            width: 100%;
        }

        @media (min-width: 768px) {
            #app.admin-fullwidth {
                max-width: 1400px;
                margin: 0 auto;
            }
        }

        @media (min-width: 1100px) {
            #app {
                max-width: min(96vw, 1280px);
            }

            #app.admin-fullwidth {
                max-width: min(98vw, 1800px);
            }

            .screen {
                padding: 24px 28px;
            }
        }

        header {
            background: var(--primary);
            color: white;
            padding: 1rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        header h1 {
            margin: 0;
            font-size: 1.2rem;
        }

        .screen {
            padding: 20px;
            flex: 1;
            display: flex;
            flex-direction: column;
            gap: 15px;
            /* Make each screen its own scroll container (reduces nested scroll jank) */
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }

        .hidden {
            display: none !important;
        }

        button {
            background: var(--primary);
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 8px;
            font-size: 1rem;
            cursor: pointer;
            width: 100%;
            margin-top: 10px;
        }

        button:disabled {
            background: #ccc;
        }

        button.secondary {
            background: #3498db;
        }

        button.stop-btn {
            background: var(--danger);
            font-weight: bold;
            padding: 20px;
            font-size: 1.2rem;
            margin-top: auto;
        }

        button.small-btn {
            width: auto;
            padding: 5px 10px;
            font-size: 0.8rem;
            background: rgba(0, 0, 0, 0.2);
        }

        button.sync-ok {
            background: #1f8f4a;
            color: #fff;
        }

        button.sync-pending {
            background: #b3261e;
            color: #fff;
        }

        button.back-btn {
            width: auto;
            background: transparent;
            color: var(--text);
            padding: 0;
            margin: 0 0 10px 0;
            text-align: left;
        }

        .qr-reader {
            width: 100%;
            min-height: 250px;
            background: #000;
            margin-bottom: 10px;
        }

        .form-group {
            margin-bottom: 15px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        select,
        input,
        textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 1rem;
            box-sizing: border-box;
        }

        .check-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 8px;
        }

        .check-grid label {
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 500;
            margin: 0;
        }

        .check-grid input[type="checkbox"] {
            width: auto;
            padding: 0;
            margin: 0;
        }

        .signature-canvas {
            width: 100%;
            max-width: 560px;
            border: 1px solid #c9c9c9;
            border-radius: 8px;
            background: #fff;
            touch-action: none;
        }

        .menu-grid {
            display: grid;
            gap: 15px;
            margin-top: 20px;
        }

        .big-btn {
            padding: 30px;
            font-size: 1.2rem;
        }

        .status-card {
            text-align: center;
            padding: 30px;
            background: #f9f9f9;
            border-radius: 10px;
            margin-bottom: 20px;
        }

        .timer {
            font-size: 3rem;
            font-family: monospace;
            font-weight: bold;
            color: var(--text);
            margin: 20px 0;
        }

        .toggle-group {
            display: flex;
            gap: 10px;
        }

        .admin-tabs {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 15px;
        }

        .admin-tab {
            flex: 1 1 120px;
            padding: 10px;
            font-size: 0.95rem;
            border: 1px solid #aeb7c2;
            border-radius: 8px;
            background: #cfd6df;
            color: #1f2937;
            cursor: pointer;
        }

        .admin-tab:hover {
            background: #c3ccd7;
        }

        .admin-tab.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .admin-panel {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .form-row {
            display: flex;
            flex-wrap: wrap;
            gap: 12px;
        }

        .form-row .form-group {
            flex: 1;
            min-width: 120px;
        }

        .admin-grid-container {
            min-height: 200px;
            border: 1px solid #eee;
            border-radius: 8px;
        }

        .admin-grid-container .tabulator {
            font-size: 0.9rem;
        }

        .fix-actions-wrap {
            display: flex;
            gap: 6px;
            align-items: center;
        }

        .admin-grid-container .tabulator button.fix-action-btn {
            width: auto;
            margin-top: 0;
            padding: 4px 8px;
            font-size: 0.82rem;
            line-height: 1.2;
            border-radius: 6px;
            min-width: 74px;
            text-align: center;
        }

        .admin-grid-container .tabulator button.delete-entry-btn.fix-action-btn {
            background: var(--danger);
        }

        .admin-grid-container .tabulator button.delete-entry-btn.fix-action-btn:hover {
            background: #c0392b;
        }

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

        .today-card {
            border: 1px solid #e5e5e5;
            border-radius: 8px;
            padding: 10px;
            background: #fafafa;
        }

        .today-card .label {
            font-size: 0.85rem;
            color: #666;
            margin-bottom: 4px;
        }

        .today-card .value {
            font-size: 1.6rem;
            font-weight: 700;
            color: var(--text);
        }

        .admin-kpi-row {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }

        .admin-kpi-chip {
            border: 1px solid #d5d5d5;
            border-radius: 999px;
            padding: 5px 10px;
            font-size: 0.85rem;
            background: #f8f8f8;
        }

        .week-progress-strip-label {
            font-size: 0.85rem;
            font-weight: 600;
            margin: 8px 0 4px;
            color: #444;
        }

        .week-progress-map-frame {
            border: 2px solid #333;
            border-radius: 8px;
            padding: 10px 12px 14px;
            margin-top: 12px;
            background: #fafafa;
            max-width: 100%;
            box-sizing: border-box;
        }

        .week-progress-map-inner {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .wpm-row-head,
        .wpm-row-strip,
        .wpm-row-path {
            display: grid;
            grid-template-columns: 2rem 1fr;
            gap: 8px;
            align-items: stretch;
        }

        .wpm-gutter {
            grid-column: 1;
        }

        .wpm-dual-head {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
            align-items: stretch;
            min-width: 0;
        }

        .wpm-dual-head .wpm-gh-title {
            text-align: center;
            font-weight: 700;
            font-size: 0.9rem;
            color: #222;
            padding: 2px 4px;
        }

        .wpm-vdivider {
            width: 3px;
            background: #333;
            border-radius: 2px;
            align-self: stretch;
        }

        .wpm-side-label {
            font-size: 0.8rem;
            font-weight: 600;
            color: #555;
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding-right: 4px;
        }

        .wpm-strips-pair {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
            align-items: stretch;
            min-width: 0;
            gap: 0;
        }

        .wpm-pathway-horizontal {
            grid-column: 2;
            border: 2px solid #444;
            border-radius: 4px;
            background: repeating-linear-gradient(
                -45deg,
                #ececec,
                #ececec 8px,
                #f5f5f5 8px,
                #f5f5f5 16px
            );
            padding: 10px 12px;
            text-align: center;
            font-weight: 700;
            font-size: 0.85rem;
            color: #222;
            letter-spacing: 0.04em;
            box-sizing: border-box;
        }

        .week-progress-cell-row {
            display: flex;
            flex-wrap: nowrap;
            gap: 2px;
            overflow-x: auto;
            align-items: stretch;
            padding: 4px 2px;
            border: 1px solid #bbb;
            border-radius: 4px;
            background: #fff;
            min-height: 44px;
            box-sizing: border-box;
        }

        .week-progress-cell {
            flex: 0 0 11px;
            width: 11px;
            min-height: 38px;
            border-radius: 2px;
            flex-shrink: 0;
        }

        .week-progress-cell.done {
            background: #2e7d32;
        }

        .week-progress-cell.in_progress {
            background: #f9a825;
        }

        .week-progress-cell.not_started {
            background: #c62828;
        }

        .week-progress-cell.empty {
            background: #cfd8dc;
        }

        .week-dash-unmapped {
            font-size: 0.85rem;
            color: #666;
            margin-top: 8px;
        }

        tr.week-progress-summary-highlight td {
            background: #e8f5e9;
            font-weight: 600;
        }

        #modal-edit-entry-overlay,
        #modal-delete-entry-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: flex-start;
            justify-content: center;
            z-index: 999;
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
            padding: 16px;
            box-sizing: border-box;
        }

        #modal-edit-entry,
        #modal-delete-entry {
            background: var(--card);
            border-radius: 10px;
            max-width: 420px;
            width: 90%;
            max-height: min(92vh, calc(100dvh - 32px));
            padding: 20px;
            margin: auto;
            margin-top: max(16px, env(safe-area-inset-top, 0px));
            margin-bottom: max(16px, env(safe-area-inset-bottom, 0px));
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
            overflow-x: hidden;
            overflow-y: auto;
            box-sizing: border-box;
            flex-shrink: 0;
        }

        #modal-edit-entry-header,
        #modal-delete-entry-header {
            font-weight: 700;
            margin-bottom: 12px;
        }

        #modal-edit-entry-context,
        #modal-delete-entry-context {
            border: 1px solid #ececec;
            border-radius: 8px;
            background: #fafafa;
            padding: 10px;
            margin-bottom: 10px;
            font-size: 0.85rem;
        }

        #modal-edit-entry-context .ctx-row {
            margin-bottom: 4px;
        }

        #modal-edit-entry-context .ctx-row:last-child {
            margin-bottom: 0;
        }

        #modal-edit-entry-fields .form-group {
            margin-bottom: 10px;
        }

        #modal-edit-entry-fields label {
            display: block;
            margin-bottom: 4px;
            font-weight: 500;
        }

        #modal-edit-entry-fields input,
        #modal-edit-entry-fields select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
        }

        .edit-entry-btn {
            padding: 6px 12px;
            font-size: 0.9rem;
            cursor: pointer;
            background: var(--primary, #2d7d46);
            color: #fff;
            border: none;
            border-radius: 6px;
        }

        .edit-entry-btn:hover {
            opacity: 0.9;
        }

        #modal-edit-entry-reason {
            width: 100%;
            min-height: 80px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
            resize: vertical;
        }

        #modal-edit-entry-hint {
            font-size: 0.85rem;
            color: #666;
            margin-top: 6px;
        }

        .toggle-btn {
            background: #eee;
            color: #666;
            flex: 1;
        }

        .toggle-btn.selected {
            background: var(--primary);
            color: white;
        }

        .stat-card {
            background: #fff;
            border: 1px solid #eee;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        }

        .table-container {
            border: 1px solid #eee;
            border-radius: 10px;
            overflow: auto;
            max-height: 55vh;
            background: #fff;
            -webkit-overflow-scrolling: touch;
            /* Hint to browser: keep layout/paint local */
            contain: content;
        }

        .data-table {
            width: 100%;
            border-collapse: collapse;
            min-width: 520px;
            /* horizontal scroll on narrow screens */
        }

        .data-table th,
        .data-table td {
            padding: 10px;
            border-bottom: 1px solid #eee;
            text-align: left;
            vertical-align: top;
            font-size: 0.95rem;
        }

        .data-table th {
            position: sticky;
            top: 0;
            background: #fafafa;
            z-index: 2;
            font-weight: 700;
        }

        .data-table td small {
            color: #666;
        }

        /* Reduce scroll jank on small screens */
        @media (max-width: 600px) {

            /* Avoid nested scroll areas on mobile: let the screen scroll instead */
            .table-container {
                max-height: none;
                overflow: visible;
                border-radius: 0;
            }

            .data-table {
                min-width: 0;
            }

            .data-table th {
                position: static;
                /* sticky headers can be janky on some mobile browsers */
            }

            /* Shadows can be expensive on mobile scroll */
            .stat-card {
                box-shadow: none;
            }
        }

        .big-number {
            font-size: 2rem;
            font-weight: bold;
            color: var(--primary);
        }

        #notification {
            background: #333;
            color: white;
            padding: 10px;
            text-align: center;
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            border-radius: 20px;
            z-index: 1000;
        }

        /* Modal (in-app replacement for alert/confirm) */
        #modal-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 2000;
            padding: 20px;
        }

        #modal {
            width: 100%;
            max-width: 520px;
            background: #fff;
            border-radius: 14px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
            overflow: hidden;
        }

        #modal-header {
            padding: 14px 16px;
            border-bottom: 1px solid #eee;
            font-weight: 700;
        }

        #modal-body {
            padding: 16px;
            white-space: pre-wrap;
            line-height: 1.35;
        }

        #modal-actions {
            padding: 12px 16px;
            border-top: 1px solid #eee;
            display: flex;
            gap: 10px;
            justify-content: flex-end;
        }

        #modal-actions button {
            width: auto;
            margin-top: 0;
        }

        #modal-actions button.secondary {
            background: #eee;
            color: #333;
        }
    
