:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Shell */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.brand-name {
    display: block;
    font-weight: 700;
    color: #fff;
    font-size: 0.95rem;
    line-height: 1.2;
}

.brand-sub {
    display: block;
    font-size: 0.75rem;
    color: #94a3b8;
}

.sidebar-nav {
    padding: 0.75rem 0.75rem;
    flex: 1;
    overflow-y: auto;
}

.nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 0.9rem 0.6rem 0.35rem;
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: 7px;
    color: var(--sidebar-text);
    font-weight: 500;
    margin-bottom: 2px;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    text-decoration: none;
}

.nav-link.active {
    background: var(--primary);
    color: #fff;
}

.nav-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #334155;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.user-name {
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}

.user-role {
    color: #94a3b8;
    font-size: 0.75rem;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    font-size: 1.1rem;
    cursor: pointer;
}

.page-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
}

.clock-pill {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.content {
    padding: 1.5rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* Cards & Grids */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.card-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

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

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

.stat-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 1.25rem;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 1rem;
}

.form-group {
    margin-bottom: 0.9rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 0.35rem;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.inline-form {
    display: flex;
    gap: 0.65rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.52rem 1rem;
    border-radius: 7px;
    font-weight: 600;
    font-size: 0.875rem;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
    text-decoration: none;
}

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

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

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #15803d;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}

.btn-warning:hover {
    background: #b45309;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: inherit;
}

.btn-outline:hover {
    background: rgba(148, 163, 184, 0.12);
}

.btn-sm {
    padding: 0.32rem 0.65rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.75rem 1.4rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.main-area {
    overflow-x: hidden;
}

.sidebar-backdrop {
    display: none;
}

.sidebar-close {
    display: none;
    margin-left: auto;
    background: none;
    border: none;
    color: #cbd5e1;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th,
td {
    padding: 0.68rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    background: var(--surface-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

tr:hover td {
    background: #fafcff;
}

tr.row-warning td {
    background: #fffbeb;
}

tr.row-warning:hover td {
    background: #fef3c7;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
}

.badge-success {
    background: var(--success-soft);
    color: #166534;
}

.badge-warning {
    background: var(--warning-soft);
    color: #92400e;
}

.badge-danger {
    background: var(--danger-soft);
    color: #991b1b;
}

.badge-info {
    background: var(--primary-soft);
    color: #1e40af;
}

.badge-muted {
    background: #e2e8f0;
    color: #475569;
}

/* Alerts */
.alert {
    padding: 0.8rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-soft);
    color: #166534;
    border-color: #bbf7d0;
}

.alert-warning {
    background: var(--warning-soft);
    color: #92400e;
    border-color: #fde68a;
}

.alert-error,
.alert-danger {
    background: var(--danger-soft);
    color: #991b1b;
    border-color: #fecaca;
}

.alert-info {
    background: var(--primary-soft);
    color: #1e40af;
    border-color: #bfdbfe;
}

/* Time Clock Hero */
.clock-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.clock-timer {
    font-size: 2.2rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.clock-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Auth & Installer Pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.auth-card {
    background: #fff;
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.installer-card {
    max-width: 680px;
}

.step-pills {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.step-pill {
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #e2e8f0;
    color: #475569;
}

.step-pill.active {
    background: var(--primary);
    color: #fff;
}

.step-pill.done {
    background: var(--success-soft);
    color: #166534;
}

/* Schedule Grid */
.schedule-grid th,
.schedule-grid td {
    min-width: 135px;
    vertical-align: top;
}

.shift-chip {
    background: var(--primary-soft);
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.78rem;
}

.shift-chip.warn {
    background: var(--warning-soft);
    border-color: #fcd34d;
}

.avail-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

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

.text-right {
    text-align: right;
}

@media (max-width: 900px) {
    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 60;
        width: 270px;
        max-width: 85vw;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(15, 23, 42, 0.35);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: inline-block;
    }

    .sidebar-backdrop.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 50;
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 38px;
        min-height: 38px;
    }

    .topbar {
        padding: 0.75rem 1rem;
    }

    .content {
        padding: 1rem;
    }
}

@media (max-width: 640px) {
    .topbar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .page-title {
        font-size: 1.05rem;
        flex: 1;
        min-width: 0;
    }

    .clock-pill {
        display: none;
    }

    .card {
        padding: 1rem;
    }

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

    .inline-form {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .inline-form>*,
    .inline-form .form-control {
        width: 100% !important;
        min-width: 0 !important;
    }

    .clock-hero {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .clock-timer {
        font-size: 1.85rem;
    }

    .clock-actions {
        flex-direction: column;
        width: 100%;
    }

    .clock-actions form {
        width: 100%;
        flex-direction: column;
        align-items: stretch !important;
    }

    .clock-actions .form-control,
    .clock-actions .btn {
        width: 100% !important;
        min-height: 44px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr));
        gap: 0.75rem;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    th,
    td {
        padding: 0.55rem 0.5rem;
        font-size: 0.82rem;
    }
}

@media (max-width: 480px) {
    .auth-page {
        padding: 1rem;
    }

    .auth-card {
        padding: 1.25rem;
    }
}