/* =========================================================================
   Chandrike HRMS - app styles
   Mobile first. Sidebar from 1024px, bottom navigation below that.
   ========================================================================= */

:root {
    --brand: #1e40af;
    --brand-600: #1d4ed8;
    --brand-50: #eef2ff;
    --accent: #0d9488;
    --accent-50: #e6f7f5;

    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;
    --border: #e3e8ef;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --overlay: rgba(15, 23, 42, 0.5);

    --ok: #059669;     --ok-bg: #d1fae5;     --ok-fg: #065f46;
    --bad: #dc2626;    --bad-bg: #fee2e2;    --bad-fg: #991b1b;
    --warn: #d97706;   --warn-bg: #fef3c7;   --warn-fg: #92400e;
    --info: #4f46e5;   --info-bg: #e0e7ff;   --info-fg: #3730a3;
    --idle: #6b7280;   --idle-bg: #f1f5f9;   --idle-fg: #374151;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow: 0 4px 16px -4px rgba(15, 23, 42, 0.10), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.25);
    --ring: 0 0 0 3px rgba(37, 99, 235, 0.25);

    --sidebar-w: 264px;
    --topbar-h: 60px;
    --bottomnav-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --brand: #60a5fa; --brand-600: #3b82f6; --brand-50: #172554;
        --accent: #2dd4bf; --accent-50: #042f2e;
        --bg: #0b1220; --surface: #111a2e; --surface-2: #0f1729; --surface-3: #1a2540;
        --border: #23304d; --border-strong: #33446b;
        --text: #e5ecf6; --text-2: #c3cede; --muted: #8b9ab3; --overlay: rgba(2, 6, 23, 0.7);
        --ok: #34d399; --ok-bg: #064e3b; --ok-fg: #a7f3d0;
        --bad: #f87171; --bad-bg: #4c1d1d; --bad-fg: #fecaca;
        --warn: #fbbf24; --warn-bg: #4a3410; --warn-fg: #fde68a;
        --info: #a5b4fc; --info-bg: #262a5c; --info-fg: #c7d2fe;
        --idle: #94a3b8; --idle-bg: #1e293b; --idle-fg: #cbd5e1;
        --shadow: 0 4px 16px -4px rgba(0, 0, 0, 0.5);
        --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --brand: #60a5fa; --brand-600: #3b82f6; --brand-50: #172554;
    --accent: #2dd4bf; --accent-50: #042f2e;
    --bg: #0b1220; --surface: #111a2e; --surface-2: #0f1729; --surface-3: #1a2540;
    --border: #23304d; --border-strong: #33446b;
    --text: #e5ecf6; --text-2: #c3cede; --muted: #8b9ab3; --overlay: rgba(2, 6, 23, 0.7);
    --ok: #34d399; --ok-bg: #064e3b; --ok-fg: #a7f3d0;
    --bad: #f87171; --bad-bg: #4c1d1d; --bad-fg: #fecaca;
    --warn: #fbbf24; --warn-bg: #4a3410; --warn-fg: #fde68a;
    --info: #a5b4fc; --info-bg: #262a5c; --info-fg: #c7d2fe;
    --idle: #94a3b8; --idle-bg: #1e293b; --idle-fg: #cbd5e1;
    --shadow: 0 4px 16px -4px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.9em; background: var(--surface-3); padding: 1px 6px; border-radius: 6px; }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.pre-line { white-space: pre-line; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ---------- Buttons ---------- */
.btn {
    --btn-bg: var(--surface);
    --btn-fg: var(--text);
    --btn-bd: var(--border);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px; padding: 0 16px;
    border-radius: 10px; border: 1px solid var(--btn-bd);
    background: var(--btn-bg); color: var(--btn-fg);
    font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
    transition: transform .08s ease, background-color .15s ease, box-shadow .15s ease, opacity .15s ease;
    user-select: none; text-decoration: none !important;
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { --btn-bg: var(--brand-600); --btn-fg: #fff; --btn-bd: transparent; box-shadow: 0 4px 12px -4px rgba(37, 99, 235, .55); }
.btn-accent  { --btn-bg: var(--accent); --btn-fg: #fff; --btn-bd: transparent; }
.btn-success { --btn-bg: var(--ok); --btn-fg: #fff; --btn-bd: transparent; }
.btn-danger  { --btn-bg: var(--bad); --btn-fg: #fff; --btn-bd: transparent; }
.btn-soft    { --btn-bg: var(--brand-50); --btn-fg: var(--brand); --btn-bd: transparent; }
.btn-ghost   { --btn-bg: transparent; --btn-bd: transparent; }
.btn-ghost:hover { --btn-bg: var(--surface-3); filter: none; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { min-height: 52px; padding: 0 22px; font-size: 16px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 38px; min-height: 38px; padding: 0; border-radius: 10px; }
.btn-icon.btn-sm { width: 32px; min-height: 32px; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
    content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
    border: 2.5px solid currentColor; border-color: var(--btn-fg) transparent var(--btn-fg) transparent;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) {
    .form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
    .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
    .form-grid .span-2 { grid-column: span 2; }
    .form-grid .span-all { grid-column: 1 / -1; }
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
    width: 100%; min-height: 44px; padding: 10px 12px;
    font: inherit; font-size: 15px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
    transition: border-color .15s ease, box-shadow .15s ease;
    appearance: none; -webkit-appearance: none;
}
textarea.input { min-height: 90px; resize: vertical; }
select.input {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input:focus { outline: none; border-color: var(--brand-600); box-shadow: var(--ring); }
.input[readonly] { background: var(--surface-3); }
.input-icon { position: relative; }
.input-icon > i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > .input { padding-left: 38px; }
.input-icon > .btn-ghost { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.check-list { display: flex; flex-wrap: wrap; gap: 8px; }
.check-chip { position: relative; }
.check-chip input { position: absolute; opacity: 0; pointer-events: none; }
.check-chip span {
    display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
    border: 1px solid var(--border-strong); border-radius: 999px; font-size: 14px; font-weight: 500;
    cursor: pointer; background: var(--surface); transition: all .15s ease;
}
.check-chip input:checked + span { background: var(--brand-50); border-color: var(--brand-600); color: var(--brand); font-weight: 600; }
.check-chip input:checked + span::before { content: "\f00c"; font-family: "Font Awesome 6 Free"; font-weight: 900; font-size: 11px; }
.check-chip input:focus-visible + span { box-shadow: var(--ring); }

.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-3); border-radius: 12px; width: 100%; }
.segmented button {
    flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
    font-weight: 600; font-size: 14px; color: var(--muted);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: 16px; display: flex; align-items: center; gap: 10px; }
.card-head h2 i, .card-head h3 i { color: var(--accent); }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } .grid.cols-3-2 { grid-template-columns: 3fr 2fr; } }

/* ---------- Stats ---------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) { .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
.stat {
    display: flex; align-items: center; gap: 12px; padding: 14px; text-align: left;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); min-width: 0;
}
button.stat { cursor: pointer; font: inherit; width: 100%; }
button.stat:hover { border-color: var(--border-strong); }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 639px) {
    .stats.three .stat { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; }
    .stats.three .stat-icon { width: 34px; height: 34px; font-size: 14px; border-radius: 10px; }
}
.stat-icon { flex: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 17px; }
.stat-icon.blue { background: var(--brand-50); color: var(--brand); }
.stat-icon.green { background: var(--ok-bg); color: var(--ok); }
.stat-icon.red { background: var(--bad-bg); color: var(--bad); }
.stat-icon.violet { background: var(--info-bg); color: var(--info); }
.stat-icon.amber { background: var(--warn-bg); color: var(--warn); }
.stat-icon.teal { background: var(--accent-50); color: var(--accent); }
.stat-value { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--idle-bg); color: var(--idle-fg);
}
.badge.present, .badge.active, .badge.approved, .badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.absent, .badge.inactive, .badge.rejected, .badge.bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge.leave, .badge.info { background: var(--info-bg); color: var(--info-fg); }
.badge.pending, .badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Tables (turn into cards on phones) ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    position: sticky; top: 0; z-index: 1;
    text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
    color: var(--muted); background: var(--surface-2); padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.cell-title { font-weight: 600; }
.cell-sub { font-size: 12.5px; color: var(--muted); }

@media (max-width: 767px) {
    .table.responsive thead { display: none; }
    .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
    .table.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
    .table.responsive tbody tr:last-child { border-bottom: 0; }
    .table.responsive tbody tr:hover td { background: transparent; }
    .table.responsive td {
        border: 0; padding: 5px 0; display: grid; grid-template-columns: minmax(84px, 36%) minmax(0, 1fr);
        column-gap: 12px; row-gap: 2px; align-items: center; text-align: right; overflow-wrap: anywhere;
    }
    .table.responsive td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 9; align-self: start; padding-top: 2px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; }
    .table.responsive td:not(.td-head):not(.td-wide):not(.td-actions) > * { grid-column: 2; justify-self: end; min-width: 0; max-width: 100%; }
    .table.responsive .badge { white-space: normal; text-align: center; }
    .table.responsive td[data-label=""]::before { display: none; }
    .table.responsive td[data-label=""] { display: flex; justify-content: flex-end; }
    .table.responsive td.td-head { display: block; text-align: left; padding-bottom: 6px; }
    .table.responsive td.td-wide { display: block; text-align: left; color: var(--muted); font-size: 13px; padding: 2px 0 6px; }
    .table.responsive td.td-wide::before { display: none; }
    .table.responsive td.td-head::before { display: none; }
    .table.responsive td .actions { justify-content: flex-end; }
    .table.responsive td.td-actions { padding-top: 10px; display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
    .table.responsive td.td-actions::before { display: none; }
}

/* ---------- Empty / loading ---------- */
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.empty i { font-size: 30px; margin-bottom: 10px; opacity: .55; display: block; }
.empty strong { display: block; color: var(--text-2); margin-bottom: 4px; }
.skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: 10px; min-height: 16px; }
.skeleton::after {
    content: ""; position: absolute; inset: 0; transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.page-loader { display: grid; gap: 14px; }
.page-loader .skeleton:nth-child(1) { height: 90px; }
.page-loader .skeleton:nth-child(2) { height: 220px; }
.page-loader .skeleton:nth-child(3) { height: 160px; }

/* =========================================================================
   App shell
   ========================================================================= */
.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
    display: none; flex-direction: column;
    background: linear-gradient(180deg, #172554 0%, #1e3a8a 60%, #134e4a 140%); color: #e2e8f0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 16px; }
.brand-logo { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: rgba(255,255,255,.12); font-size: 18px; color: #fff; flex: none; }
.brand-name { font-weight: 800; font-size: 16px; color: #fff; }
.brand-sub { font-size: 12px; color: rgba(226,232,240,.7); }
.nav { flex: 1; overflow-y: auto; padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: rgba(226,232,240,.5); padding: 14px 12px 6px; font-weight: 700; }
.nav a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: rgba(226,232,240,.85); font-weight: 500; font-size: 14.5px; text-decoration: none;
}
.nav a i { width: 18px; text-align: center; opacity: .9; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav a .count { margin-left: auto; background: #f59e0b; color: #1f2937; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.1); }

.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
    background: linear-gradient(135deg, #3b82f6, #14b8a6); color: #fff; font-weight: 700; font-size: 15px;
}
.user-chip .who { min-width: 0; }
.user-chip .who b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who small { display: block; font-size: 12px; opacity: .7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; padding-bottom: calc(var(--bottomnav-h) + var(--safe-b) + 16px); }
.topbar {
    position: sticky; top: 0; z-index: 30; height: calc(var(--topbar-h) + var(--safe-t)); padding: var(--safe-t) 16px 0;
    display: flex; align-items: center; gap: 12px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar .titles { flex: 1; min-width: 0; }
.topbar h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .clock { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); font-weight: 600; display: none; }
.topbar .avatar-btn { border: 0; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.content { padding: 16px; max-width: 1280px; margin: 0 auto; }
.page { display: flex; flex-direction: column; gap: 16px; animation: fadeUp .22s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    height: calc(var(--bottomnav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    display: flex; background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px -12px rgba(15,23,42,.25);
}
.bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; border: 0; background: none; cursor: pointer;
    position: relative; min-width: 0;
}
.bottom-nav i { font-size: 19px; }
.bottom-nav .active { color: var(--brand); }
.bottom-nav .active::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--brand); }
.bottom-nav .dot { position: absolute; top: 9px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 10px; display: grid; place-items: center; }

@media (min-width: 1024px) {
    .sidebar { display: flex; }
    .main { margin-left: var(--sidebar-w); padding-bottom: 32px; }
    .bottom-nav { display: none; }
    .topbar { padding: 0 28px; }
    .topbar .clock { display: block; }
    .content { padding: 24px 28px; }
}

/* ---------- Menu sheet (mobile "More", user menu) ---------- */
.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-list a, .menu-list button {
    display: flex; align-items: center; gap: 14px; padding: 12px 12px; border-radius: 12px;
    color: var(--text); font-weight: 500; text-decoration: none; border: 0; background: none; cursor: pointer; text-align: left; width: 100%;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-3); text-decoration: none; }
.menu-list i { width: 22px; text-align: center; color: var(--muted); }
.menu-list .active { background: var(--brand-50); color: var(--brand); }
.menu-list .active i { color: var(--brand); }
.menu-list .danger, .menu-list .danger i { color: var(--bad); }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.menu-grid a {
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px; border-radius: 14px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 12.5px; font-weight: 600; text-align: center; text-decoration: none;
}
.menu-grid a i { font-size: 20px; color: var(--brand); }
.menu-grid a.active { border-color: var(--brand-600); background: var(--brand-50); }

/* =========================================================================
   Dialog (modal on desktop, bottom sheet on phones)
   ========================================================================= */
dialog.modal {
    border: 0; padding: 0; margin: auto; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
    background: var(--surface); color: var(--text); border-radius: 20px; box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column; overflow: hidden;
}
dialog.modal:not([open]) { display: none; }
dialog.modal.wide { width: min(820px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: popIn .18s ease; }
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { flex: 1; font-size: 17px; }
.modal-head [data-close] { margin-left: auto; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--border); background: var(--surface-2); }
.modal-foot .btn { min-width: 110px; }
.confirm-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; margin: 4px auto 12px; }
.confirm-icon.warn { background: var(--warn-bg); color: var(--warn); }
.confirm-icon.bad { background: var(--bad-bg); color: var(--bad); }
.confirm-icon.ok { background: var(--ok-bg); color: var(--ok); }
.confirm-icon.info { background: var(--info-bg); color: var(--info); }
.confirm-text { text-align: center; }
.confirm-text h3 { font-size: 18px; margin-bottom: 6px; }
.confirm-text p { color: var(--muted); white-space: pre-line; }

@media (max-width: 639px) {
    dialog.modal, dialog.modal.wide {
        width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0 0;
        border-radius: 22px 22px 0 0;
    }
    dialog.modal[open] { animation: sheetUp .24s cubic-bezier(.2,.8,.2,1); }
    .modal-head::before { content: ""; position: absolute; left: 50%; top: 7px; width: 38px; height: 4px; border-radius: 4px; background: var(--border-strong); transform: translateX(-50%); }
    .modal-head { position: relative; padding-top: 22px; }
    .modal-foot .btn { flex: 1; }
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

/* ---------- Toasts ---------- */
#toast-root { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); top: calc(12px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast {
    pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--info);
    border-radius: 12px; box-shadow: var(--shadow-lg); animation: toastIn .2s ease; font-size: 14px;
}
.toast i { margin-top: 2px; }
.toast.success { border-left-color: var(--ok); } .toast.success i { color: var(--ok); }
.toast.error { border-left-color: var(--bad); } .toast.error i { color: var(--bad); }
.toast.warning { border-left-color: var(--warn); } .toast.warning i { color: var(--warn); }
.toast.info i { color: var(--info); }
.toast .msg { flex: 1; white-space: pre-line; }
.toast button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; }
.toast.out { animation: toastOut .2s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* =========================================================================
   Login
   ========================================================================= */
.login {
    min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(37,99,235,.22), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, rgba(13,148,136,.22), transparent 60%),
        var(--bg);
}
.login-card { width: 100%; max-width: 410px; padding: 30px 26px; border-radius: 24px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.login-logo { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px; display: grid; place-items: center; font-size: 28px; color: #fff; background: linear-gradient(135deg, #2563eb, #0d9488); box-shadow: 0 12px 24px -10px rgba(37,99,235,.6); }
.login h1 { text-align: center; font-size: 22px; }
.login .tagline { text-align: center; color: var(--muted); font-size: 14px; margin: 4px 0 22px; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login .foot { text-align: center; margin-top: 18px; font-size: 12.5px; color: var(--muted); }

/* =========================================================================
   Employee duty screen
   ========================================================================= */
.duty-hero {
    position: relative; overflow: hidden; padding: 20px; border-radius: 22px; color: #fff;
    background: linear-gradient(135deg, #1e40af 0%, #2563eb 45%, #0d9488 100%);
    box-shadow: 0 18px 40px -18px rgba(30,64,175,.6);
}
.duty-hero::after { content: ""; position: absolute; width: 260px; height: 260px; right: -80px; top: -110px; border-radius: 50%; background: rgba(255,255,255,.08); }
.duty-hero .hello { font-size: 14px; opacity: .85; }
.duty-hero .name { font-size: 22px; font-weight: 800; margin-top: 2px; }
.duty-hero .clock-big { font-size: 38px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 14px; line-height: 1; }
.duty-hero .date { font-size: 14px; opacity: .85; margin-top: 6px; }
.duty-hero .where { margin-top: 12px; font-size: 13px; opacity: .9; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.duty-status {
    position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 8px; margin-top: 14px;
    padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.16); font-weight: 600; font-size: 14px;
}
.duty-status.on { background: rgba(16,185,129,.28); }
.duty-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.duty-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    min-height: 112px; border-radius: 20px; border: 0; cursor: pointer; font-weight: 700; font-size: 16px; color: #fff;
    box-shadow: var(--shadow); transition: transform .1s ease, opacity .15s ease;
}
.duty-btn i { font-size: 28px; }
.duty-btn small { font-weight: 500; font-size: 12px; opacity: .85; }
.duty-btn:active { transform: scale(.97); }
.duty-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.duty-btn.in { background: linear-gradient(135deg, #059669, #10b981); }
.duty-btn.out { background: linear-gradient(135deg, #e11d48, #f97316); }
.duty-btn.is-busy { pointer-events: none; opacity: .8; }
.shift-list { display: flex; flex-direction: column; }
.shift-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border: 0; border-top: 1px solid var(--border); width: 100%; background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.shift-item:hover { background: var(--surface-2); }
.shift-item:first-child { border-top: 0; }
.shift-item .times { flex: 1; font-weight: 600; font-variant-numeric: tabular-nums; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: 13.5px; background: var(--warn-bg); color: var(--warn-fg); }
.notice.info { background: var(--info-bg); color: var(--info-fg); }

/* ---------- Camera ---------- */
.camera-box { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 56dvh; border-radius: 18px; overflow: hidden; background: #000; }
@media (min-width: 640px) { .camera-box { aspect-ratio: 4 / 3; } }
.camera-box video, .camera-box img { width: 100%; height: 100%; object-fit: cover; }
.camera-box video.mirror { transform: scaleX(-1); }
.camera-box .face-guide { position: absolute; inset: 14% 22%; border: 3px dashed rgba(255,255,255,.55); border-radius: 50% / 45%; pointer-events: none; }
.camera-box .cam-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: #e2e8f0; font-size: 14px; }
.geo-line { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin-top: 12px; color: var(--text-2); }
.geo-line.ok i { color: var(--ok); }
.geo-line.bad i { color: var(--bad); }
.geo-line.wait i { color: var(--warn); }

/* ---------- Thumbnails / lightbox ---------- */
.thumb { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; cursor: zoom-in; border: 1px solid var(--border); background: var(--surface-3); }
.lightbox-img { width: 100%; max-height: 70dvh; object-fit: contain; border-radius: 12px; background: #000; }

/* ---------- Filters bar ---------- */
.filters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.filters .search { grid-column: 1 / -1; }
.filters .btns { grid-column: 1 / -1; display: flex; gap: 8px; }
.filters .btns .btn { flex: 1; }
@media (min-width: 900px) {
    .filters { grid-template-columns: 180px 220px 1fr auto; align-items: end; }
    .filters .search { grid-column: auto; }
    .filters .btns { grid-column: auto; }
    .filters .btns .btn { flex: none; }
    .filters.f3 { grid-template-columns: 180px 1fr auto; }
    .filters.f4 { grid-template-columns: 170px 170px 220px auto; }
}

/* ---------- Leave cards ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--border); align-items: flex-start; }
.list-item:first-child { border-top: 0; }
.list-item .li-icon { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-item .li-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-item .li-text { font-size: 14px; color: var(--text-2); margin-top: 6px; overflow-wrap: anywhere; }
.list-item .li-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
@media (max-width: 559px) {
    .list-item { flex-wrap: wrap; }
    .list-item .li-side { flex-direction: row; width: 100%; justify-content: flex-end; }
}

/* ---------- Reports ---------- */
.chart-box { position: relative; height: 240px; }
.matrix-wrap { overflow: auto; max-height: 70vh; }
.matrix { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.matrix th, .matrix td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 6px 6px; text-align: center; white-space: nowrap; }
.matrix thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 2; font-weight: 700; color: var(--text-2); }
.matrix thead tr:nth-child(2) th { top: 31px; font-size: 10px; font-weight: 600; color: var(--muted); }
.matrix th.off, .matrix td.off { background: var(--surface-3); }
.matrix .name { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; min-width: 150px; max-width: 190px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.matrix thead .name { z-index: 3; background: var(--surface-2); }
.matrix .tot { font-weight: 700; }
.mx-p { color: var(--ok); font-weight: 700; }
.mx-a { color: var(--bad); font-weight: 700; }
.mx-l { color: var(--info); font-weight: 700; }
.mx-t { font-variant-numeric: tabular-nums; line-height: 1.3; font-size: 11px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }

/* ---------- Key/value list ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* ---------- Setup error page ---------- */
.setup-error { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.setup-card { max-width: 560px; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.setup-card h1 { font-size: 20px; margin: 12px 0 8px; }
.setup-card ol { padding-left: 20px; line-height: 1.8; }
.setup-card pre { white-space: pre-wrap; background: var(--bad-bg); color: var(--bad-fg); padding: 12px; border-radius: 10px; font-size: 13px; }
.setup-icon { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; background: var(--bad-bg); color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* =========================================================================
   Mobile-first helpers (v1.1)
   ========================================================================= */
.cell-title, .cell-sub, .li-title, .li-meta { overflow-wrap: anywhere; }
select.input { max-width: 100%; text-overflow: ellipsis; }
input[type="date"].input, input[type="time"].input { min-width: 0; padding-right: 8px; }
.head-select { width: auto; min-width: 0; max-width: 260px; min-height: 38px; }
.show-sm { display: none !important; }
.m-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.m-times { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; margin-top: 6px; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
tr.tap { cursor: pointer; }
.stats.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) { .stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

@media (max-width: 767px) {
    .hide-sm { display: none !important; }
    span.show-sm, b.show-sm, i.show-sm { display: inline !important; }
    div.show-sm { display: block !important; }
    div.m-row.show-sm { display: flex !important; }
    .card-head { padding: 14px; }
    .card-head > .row { width: 100%; flex-wrap: nowrap; }
    .card-head > .row .head-select { flex: 1; max-width: none; }
    .card-head > .segmented { max-width: none !important; }
    .card-body { padding: 14px; }
    .content { padding: 12px; }
    .page { gap: 12px; }
    .topbar h1 { font-size: 17px; }
    .list-item { padding: 12px 14px; }
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; }
    .btn-icon.btn-sm { width: 38px; min-height: 38px; }
}
@media (max-width: 419px) {
    .filters { grid-template-columns: 1fr; padding: 12px 14px; }
    .filters .btns .btn { flex: 1; }
    .stats:not(.three) .stat { padding: 12px; gap: 10px; }
    .stat-value { font-size: 20px; }
    .duty-hero .clock-big { font-size: 34px; }
}
@media (min-width: 900px) { .filters.f-audit { grid-template-columns: 170px 170px 220px 1fr; } }

/* ---------- Attendance detail ---------- */
.att-detail { display: grid; gap: 18px; }
@media (min-width: 720px) { .att-detail { grid-template-columns: 260px 1fr; } }
.att-photo { display: flex; flex-direction: column; gap: 8px; }
.att-photo img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 16px; background: var(--surface-3); cursor: zoom-in; }
.att-nophoto { aspect-ratio: 3 / 4; border-radius: 16px; background: var(--surface-3); color: var(--muted); display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center; text-align: center; padding: 16px; font-size: 13px; }
.att-nophoto i { font-size: 34px; opacity: .5; }
@media (max-width: 719px) { .att-photo img, .att-nophoto { aspect-ratio: 4 / 3; max-height: 46dvh; } }
.att-info { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.att-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.att-name { font-size: 18px; font-weight: 800; }
.att-times { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .att-times { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.att-times > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.att-times b { font-size: 15px; font-variant-numeric: tabular-nums; }
.loc-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .loc-grid { grid-template-columns: 1fr 1fr; } }
.loc-card { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; min-width: 0; }
.loc-title { font-weight: 600; font-size: 13px; }
.att-remarks { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; overflow-wrap: anywhere; }
.att-history { border-top: 1px solid var(--border); padding-top: 12px; }
.hist-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; }

/* ---------- Attendance list rows ---------- */
.att-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.att-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; border-top: 1px solid var(--border); background: var(--surface); text-align: left; cursor: pointer; width: 100%; font: inherit; color: inherit; }
.att-row:first-child { border-top: 0; }
.att-row:hover { background: var(--surface-2); }
.att-row-date { flex: none; width: 46px; height: 46px; border-radius: 12px; background: var(--brand-50); color: var(--brand); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.att-row-date b { font-size: 17px; }
.att-row-date span { font-size: 10px; text-transform: uppercase; font-weight: 600; }
.att-row-main { flex: 1; min-width: 0; }
.att-row-times { font-weight: 600; font-variant-numeric: tabular-nums; }
.att-row .badge { flex: none; }

/* ---------- Audit log ---------- */
.log-item { width: 100%; border: 0; border-top: 1px solid var(--border); background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.log-item:hover { background: var(--surface-2); }
.li-icon.li-pending { background: var(--warn-bg); color: var(--warn); }
.li-icon.li-absent { background: var(--bad-bg); color: var(--bad); }
pre.json { margin: 0; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; }
.thumb-missing { width: 42px; height: 42px; border-radius: 10px; display: inline-grid; place-items: center; background: var(--surface-3); color: var(--muted); font-size: 16px; }
.m-times { white-space: nowrap; }
@media (max-width: 767px) { .m-row .badge { font-size: 11px; padding: 3px 8px; } }
