/* WorkTrack design system — mobile first */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --secondary: #0f172a;
  --background: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --border: #e2e8f0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 14px rgba(15, 23, 42, .06);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
}

*, *::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.45;
  color: var(--text); background: var(--background);
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.right { text-align: right; } .nowrap { white-space: nowrap; } .hidden { display: none !important; }
:focus-visible { outline: 3px solid rgba(37, 99, 235, .45); outline-offset: 2px; }
.icon { width: 22px; height: 22px; flex: none; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar { display: none; }
.content { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--secondary); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.main { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 1200px; margin: 0 auto; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head p { color: var(--muted); }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: .72rem; font-weight: 600; color: var(--muted); min-width: 0;
}
.bottomnav a.active { color: var(--primary); }
.bottomnav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: 250px 1fr; }
  .sidebar {
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 20px 14px;
    background: var(--secondary); color: #cbd5e1;
  }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; color: #fff; font-weight: 800; font-size: 1.15rem; }
  .sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--radius-sm);
    color: #cbd5e1; font-weight: 600;
  }
  .sidebar nav a:hover { background: rgba(255, 255, 255, .07); }
  .sidebar nav a.active { background: var(--primary); color: #fff; }
  .sidebar .me { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .1); font-size: .85rem; }
  .sidebar .me strong { display: block; color: #fff; }
  .sidebar .me button { margin-top: 10px; }
  .bottomnav, .topbar-brand { display: none; }
  .main { padding: 24px 32px 48px; }
  .topbar { padding: 14px 32px; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--primary); color: #fff;
  font-weight: 700; cursor: pointer; transition: background .15s, transform .05s; text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.loading { opacity: .6; cursor: not-allowed; }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--background); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--background); color: var(--text); }
.btn-success { background: var(--success); } .btn-success:hover { background: #166534; }
.btn-danger { background: var(--danger); } .btn-danger:hover { background: #b91c1c; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); } .btn-danger-soft:hover { background: #fecaca; }
.btn-success-soft { background: var(--success-soft); color: var(--success); } .btn-success-soft:hover { background: #bbf7d0; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .85rem; }
.btn-icon { min-width: 44px; padding: 0; position: relative; }
.btn-block { width: 100%; }
.sidebar .btn-ghost { color: #cbd5e1; width: 100%; justify-content: flex-start; }
.sidebar .btn-ghost:hover { background: rgba(255, 255, 255, .08); color: #fff; }

/* ---------- Cards / grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .stack > * + * { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
.cols { display: grid; gap: 16px; }
.cols > .card + .card, .grid > .card + .card { margin-top: 0; }
@media (min-width: 768px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } .cols-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .cols-3 { grid-template-columns: 2fr 1fr; } }

.stat { padding: 14px; }
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat .value { font-size: 1.6rem; font-weight: 800; margin-top: 2px; letter-spacing: -.02em; }
.stat .sub { color: var(--muted); font-size: .78rem; }
.stat.warn .value { color: var(--warning); } .stat.bad .value { color: var(--danger); } .stat.good .value { color: var(--success); }

.hero {
  background: linear-gradient(135deg, #2563eb, #3b82f6 60%, #60a5fa); color: #fff; border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.hero h1 { font-size: 1.35rem; } .hero p { opacity: .9; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: #e2e8f0; color: #475569; }
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: .85rem; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 16px; /* 16px stops iOS zoom */
}
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--primary); outline: 3px solid rgba(37, 99, 235, .2); }
.hint { color: var(--muted); font-size: .8rem; }
.form-error { color: var(--danger); font-size: .88rem; min-height: 1.2em; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar .input { flex: 1 1 180px; width: auto; }
.tabs { display: flex; gap: 4px; padding: 4px; background: #e8edf5; border-radius: var(--radius-sm); margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 1; min-height: 40px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

/* ---------- Tables → cards on mobile ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.table tfoot td { font-weight: 800; background: #f8fafc; }
@media (max-width: 767px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td, .table tfoot { display: block; width: 100%; }
  .table tr { padding: 12px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
  .table td { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border: 0; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; }
  .table td.cell-main { display: block; text-align: left; font-size: 1.02rem; }
  .table td.cell-main::before, .table td.actions::before { display: none; }
  .table td.actions { justify-content: flex-start; padding-top: 10px; }
  .table tfoot tr { background: #f8fafc; }
}

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.row-actions { display: flex; gap: 6px; }
button.row { width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; font-size: .85rem; flex: none; }
.avatar.lg { width: 72px; height: 72px; font-size: 1.5rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); flex: none; }
.dot.read { background: transparent; border: 2px solid var(--border); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 700; text-align: right; }
.kv .total { border-top: 1px solid var(--border); padding-top: 10px; font-size: 1.15rem; }

/* ---------- States ---------- */
.state { text-align: center; padding: 28px 16px; color: var(--muted); }
.state .state-icon { font-size: 2rem; margin-bottom: 6px; }
.state h3 { color: var(--text); margin-bottom: 4px; }
.state .btn { margin-top: 12px; }
.skeleton { display: block; border-radius: 8px; background: linear-gradient(90deg, #e8edf5 25%, #f4f6fb 50%, #e8edf5 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; height: 16px; margin: 10px 0; }
.skeleton.tall { height: 64px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } * { scroll-behavior: auto !important; } }

/* ---------- Attendance buttons ---------- */
.mark-btns { display: grid; gap: 12px; }
.mark-btn { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 76px; border: 0; border-radius: var(--radius); font-size: 1.15rem; font-weight: 800; letter-spacing: .02em; color: #fff; cursor: pointer; box-shadow: var(--shadow); }
.mark-btn.full { background: #16a34a; } .mark-btn.half { background: #60a5fa; }
.mark-btn:active { transform: scale(.985); } .mark-btn[disabled] { opacity: .55; }
.mark-btn .sym { font-size: 1.6rem; }
.status-box { padding: 14px; border-radius: var(--radius-sm); font-weight: 600; }
.status-box.pending { background: var(--warning-soft); color: var(--warning); }
.status-box.approved { background: var(--success-soft); color: var(--success); }
.status-box.rejected { background: var(--danger-soft); color: var(--danger); }
.status-box small { display: block; font-weight: 500; margin-top: 4px; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .72rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-day { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 52px; padding: 3px 1px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: default; font-size: .95rem; }
button.cal-day { cursor: pointer; }
.cal-day .cal-s { font-size: .62rem; font-weight: 700; line-height: 1.1; }
.cal-blank { border: 0; background: none; }
.cal-full { background: var(--success-soft); border-color: #86efac; color: var(--success); }
.cal-half { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; }
.cal-pending { background: var(--warning-soft); border-color: #fcd34d; color: var(--warning); }
.cal-rejected { background: var(--danger-soft); border-color: #fca5a5; color: var(--danger); }
.cal-absent { background: #f1f5f9; color: #475569; border-style: dashed; }
.cal-future { color: #94a3b8; background: transparent; }
.cal-today { outline: 2px solid var(--primary); outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 12px; font-size: .78rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; border: 1px solid var(--border); }

/* ---------- Charts ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--primary); } .chart .bar:hover { fill: var(--primary-dark); }
.chart .axis { stroke: var(--border); } .chart text { font-size: 10px; fill: var(--muted); }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: rgba(37, 99, 235, .1); } .chart .pt { fill: var(--primary); }
.hbar { display: grid; grid-template-columns: minmax(70px, 28%) 1fr auto; align-items: center; gap: 10px; padding: 5px 0; font-size: .85rem; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { display: block; background: #eef2f7; border-radius: 999px; height: 10px; overflow: hidden; }
.hbar .fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.stackbar { display: flex; height: 18px; border-radius: 999px; overflow: hidden; background: #eef2f7; }
.stackbar > span { height: 100%; }
.seg-full { background: #16a34a; } .seg-half { background: #60a5fa; } .seg-pending { background: #f59e0b; }
.seg-rejected { background: #ef4444; } .seg-missing { background: #94a3b8; }
.legend .l-full { background: #16a34a; } .legend .l-half { background: #60a5fa; } .legend .l-pending { background: #f59e0b; }
.legend .l-rejected { background: #ef4444; } .legend .l-missing { background: #94a3b8; }

/* ---------- Modal / toast / dropdown ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; background: rgba(15, 23, 42, .5); padding: 0; }
.modal { width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 20px; box-shadow: 0 -8px 40px rgba(0, 0, 0, .2); padding-bottom: calc(20px + var(--safe-b)); }
.modal h2 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 20px; } .modal { border-radius: 18px; } }
.toasts { position: fixed; z-index: 200; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; max-width: 440px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--secondary); color: #fff; font-weight: 600; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.error { background: var(--danger); } .toast.success { background: #166534; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 1024px) { .toasts { bottom: 24px; left: auto; right: 24px; align-items: flex-end; } }

.bell-wrap { position: relative; }
.badge-count { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .68rem; font-weight: 800; display: grid; place-items: center; }
.dropdown { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: min(380px, calc(100vw - 24px)); max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(15, 23, 42, .18); }
.dropdown header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 800; }
.dropdown .row { padding: 10px 14px; }
.dropdown footer { padding: 10px 14px; text-align: center; border-top: 1px solid var(--border); }
.notif-msg { font-size: .88rem; } .notif-time { color: var(--muted); font-size: .75rem; }
.notif-unread { background: #f5f8ff; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: linear-gradient(180deg, #eaf1ff, var(--background) 55%); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 22px; }
.auth-logo h1 { font-size: 1.6rem; color: var(--secondary); }
.splash { display: grid; place-items: center; min-height: 100vh; text-align: center; background: linear-gradient(180deg, #eaf1ff, #fff); }
.install-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; margin-bottom: 14px; }
.setup-box { max-width: 560px; margin: 10vh auto; padding: 22px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: #eef2f7; padding: 2px 6px; border-radius: 6px; }
.cred { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 12px; background: #f1f5f9; border-radius: var(--radius-sm); margin-top: 8px; word-break: break-all; }
