/* Jana Bala admin. Design tokens first; every component below uses only these variables.
   Rubik for headings and numbers, Nunito for text, the yellow "sun" as the accent (same palette as the app). */

:root {
  --font-head: 'Rubik', 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --bg: #FFF6E9;
  --bg-2: #FBEBD3;
  --surface: #FFFFFF;
  --surface-2: #FFFBF4;
  --ink: #3A244C;
  --ink-soft: #76668B;
  --ink-faint: #A898B8;
  --line: rgba(58, 36, 76, 0.12);
  --line-strong: rgba(58, 36, 76, 0.22);

  --sun: #FDCB39;
  --sun-deep: #E9A800;
  --sun-soft: #FFF1C4;
  --on-sun: #3A244C;
  --coral: #FD865B;
  --coral-soft: #FFE4D8;
  --mint: #3F9E61;
  --mint-soft: #DDF3E3;
  --sky: #2F8FDA;
  --sky-soft: #DCEEFE;
  --grape: #8E5BD6;
  --grape-soft: #F1E5FE;
  --danger: #D9483B;
  --danger-soft: #FDE2DE;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 1px 2px rgba(58, 36, 76, 0.06), 0 6px 20px rgba(58, 36, 76, 0.07);
  --shadow-lg: 0 18px 50px rgba(58, 36, 76, 0.22);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --tabbar-h: 64px;
  --gap: 16px;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #17111E;
  --bg-2: #1F1729;
  --surface: #241B2F;
  --surface-2: #2B2138;
  --ink: #F5EEFB;
  --ink-soft: #BCAED0;
  --ink-faint: #8A7B9E;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --sun-soft: rgba(253, 203, 57, 0.16);
  --coral-soft: rgba(253, 134, 91, 0.16);
  --mint: #6CCB8D;
  --mint-soft: rgba(108, 203, 141, 0.15);
  --sky: #7CC2FA;
  --sky-soft: rgba(124, 194, 250, 0.15);
  --grape: #C9A2FB;
  --grape-soft: rgba(201, 162, 251, 0.15);
  --danger: #FF7A6B;
  --danger-soft: rgba(255, 122, 107, 0.15);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #17111E;
    --bg-2: #1F1729;
    --surface: #241B2F;
    --surface-2: #2B2138;
    --ink: #F5EEFB;
    --ink-soft: #BCAED0;
    --ink-faint: #8A7B9E;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.18);
    --sun-soft: rgba(253, 203, 57, 0.16);
    --coral-soft: rgba(253, 134, 91, 0.16);
    --mint: #6CCB8D;
    --mint-soft: rgba(108, 203, 141, 0.15);
    --sky: #7CC2FA;
    --sky-soft: rgba(124, 194, 250, 0.15);
    --grape: #C9A2FB;
    --grape-soft: rgba(201, 162, 251, 0.15);
    --danger: #FF7A6B;
    --danger-soft: rgba(255, 122, 107, 0.15);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

/* ── Base ── */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; margin: 0; line-height: 1.2; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .money { font-family: var(--font-head); font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.right { text-align: right; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--sun) 70%, transparent); outline-offset: 2px; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-spinner, .spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 4px solid var(--sun-soft); border-top-color: var(--sun);
  animation: spin 0.8s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 48px 0; }

/* ── Shell ── */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; background: var(--sun); color: var(--on-sun);
  display: grid; place-items: center; font: 700 18px var(--font-head); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.brand-name { font: 700 17px var(--font-head); }
.brand-sub { font-size: 12px; color: var(--ink-soft); }
.nav-group { margin-top: 10px; }
.nav-group-title { font: 600 11px var(--font-head); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); padding: 6px 12px; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 12px;
  text-decoration: none; color: var(--ink-soft); font-weight: 700;
}
.nav-link:hover { background: var(--bg); color: var(--ink); }
.nav-link.active { background: var(--sun-soft); color: var(--ink); }
.nav-link.active .icon { color: var(--sun-deep); }
.nav-badge { margin-left: auto; background: var(--coral); color: #fff; border-radius: 999px; font: 600 11px var(--font-head); padding: 1px 7px; }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grape-soft); color: var(--grape); display: grid; place-items: center; font: 600 14px var(--font-head); flex: none; }
.who { min-width: 0; flex: 1; }
.who-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { font-size: 12px; color: var(--ink-soft); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; height: var(--topbar-h);
  display: none; align-items: center; gap: 10px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font: 600 17px var(--font-head); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view { padding: 24px 28px 40px; max-width: 1400px; width: 100%; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: none;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
  grid-template-columns: repeat(5, 1fr);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--ink-soft); font-size: 11px; font-weight: 800; background: none; border: 0; cursor: pointer;
}
.tab.active { color: var(--ink); }
.tab.active .icon { color: var(--sun-deep); }

.scrim { position: fixed; inset: 0; background: rgba(23, 17, 30, 0.42); z-index: 40; opacity: 0; transition: opacity 0.2s; }
.scrim.open { opacity: 1; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); z-index: 50;
    transform: translateX(-102%); transition: transform 0.22s ease; box-shadow: var(--shadow-lg);
    padding-top: calc(18px + env(safe-area-inset-top, 0px));
  }
  .sidebar.open { transform: none; }
  .topbar { display: flex; }
  .tabbar { display: grid; }
  .view { padding: 16px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom, 0px)); }
}

/* ── Icons & buttons ── */
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-weight: 800; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 0.06s, background 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--sun); border-color: transparent; color: var(--on-sun); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.1); }
.btn.primary:hover { background: color-mix(in srgb, var(--sun) 88%, #000); }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg-2); }
.btn.sm { min-height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn.icon-only { width: 40px; padding: 0; }
.btn.sm.icon-only { width: 32px; }

/* ── Page header ── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { font-size: 26px; font-weight: 700; }
.page-sub { color: var(--ink-soft); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 900px) { .page-head .page-title { font-size: 22px; } }

/* ── Cards & KPI tiles ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-title { font: 600 16px var(--font-head); margin-bottom: 12px; }
.grid { display: grid; gap: var(--gap); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi {
  position: relative; display: block; text-decoration: none; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
a.kpi:hover, button.kpi:hover { border-color: var(--line-strong); cursor: pointer; }
.kpi::before { content: ''; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--tone, var(--sun)); }
.kpi-label { color: var(--ink-soft); font-weight: 700; font-size: 13px; }
.kpi-value { font: 600 24px var(--font-head); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-hint { color: var(--ink-faint); font-size: 12px; margin-top: 2px; }
.tone-sun { --tone: var(--sun); } .tone-coral { --tone: var(--coral); } .tone-mint { --tone: var(--mint); }
.tone-sky { --tone: var(--sky); } .tone-grape { --tone: var(--grape); } .tone-danger { --tone: var(--danger); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--bg-2); color: var(--ink-soft); white-space: nowrap; }
.badge.sun { background: var(--sun-soft); color: var(--ink); }
.badge.coral { background: var(--coral-soft); color: var(--coral); }
.badge.mint { background: var(--mint-soft); color: var(--mint); }
.badge.sky { background: var(--sky-soft); color: var(--sky); }
.badge.grape { background: var(--grape-soft); color: var(--grape); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ── Toolbar ── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); }
.search input { padding-left: 40px; }

/* ── Forms ── */
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface); outline: none;
}
.textarea { min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--sun-deep); box-shadow: 0 0 0 3px var(--sun-soft); }
.select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.toolbar .select { width: auto; min-width: 150px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; grid-column: span 2; }
.field.half { grid-column: span 1; }
.field label { font-weight: 800; font-size: 13px; color: var(--ink-soft); }
.field .hint { font-size: 12px; color: var(--ink-faint); }
.field .err { font-size: 12px; color: var(--danger); font-weight: 700; }
.field.invalid .input, .field.invalid .select, .field.invalid .textarea { border-color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--sun-deep); }
@media (max-width: 600px) { .field.half { grid-column: span 2; } }

/* ── Table ── */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font: 600 12px var(--font-head); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-faint);
  padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--surface-2); }
.table .right { text-align: right; }
.table .thumb { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: var(--bg-2); display: block; }
.empty { padding: 44px 20px; text-align: center; color: var(--ink-soft); }
.empty .icon { width: 36px; height: 36px; color: var(--ink-faint); margin-bottom: 8px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 2px; color: var(--ink-soft); font-size: 13px; flex-wrap: wrap; }
.pager-buttons { display: flex; gap: 6px; }

/* ── Drawer ── */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(720px, 100vw);
  background: var(--bg); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(104%); transition: transform 0.24s ease;
}
.drawer.open { transform: none; }
.drawer.wide { width: min(980px, 100vw); }
.drawer-head { padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer-top { display: flex; align-items: flex-start; gap: 12px; }
.drawer-titles { flex: 1; min-width: 0; }
.drawer-title { font-size: 20px; font-weight: 700; }
.drawer-sub { color: var(--ink-soft); margin-top: 2px; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tabs { display: flex; gap: 4px; margin-top: 14px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  border: 0; background: none; padding: 10px 14px; font-weight: 800; color: var(--ink-soft); cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab-btn.active { color: var(--ink); border-bottom-color: var(--sun); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 20px calc(28px + env(safe-area-inset-bottom, 0px)); }

/* ── Modal ── */
.modal-layer { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal-layer .scrim { z-index: auto; position: absolute; }
.modal {
  position: relative; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 22px;
  transform: translateY(8px) scale(0.98); opacity: 0; transition: transform 0.16s, opacity 0.16s;
}
.modal.wide { width: min(760px, 100%); }
.modal-layer.open .modal { transform: none; opacity: 1; }
.modal-title { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.modal-text { color: var(--ink-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

/* ── Toast ── */
.toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(460px, calc(100vw - 32px)); }
@media (max-width: 900px) { .toasts { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px)); } }
.toast {
  pointer-events: auto; background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 14px; box-shadow: var(--shadow-lg);
  font-weight: 700; display: flex; gap: 10px; align-items: center; animation: toast-in 0.18s ease;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.ok .icon { color: var(--sun); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ── Upload ── */
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--ink-soft);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--sun-deep); background: var(--sun-soft); color: var(--ink); }
.dropzone .icon { width: 30px; height: 30px; margin-bottom: 6px; }
.progress { height: 8px; border-radius: 999px; background: var(--bg-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--sun); width: 0; transition: width 0.15s; }
.upload-list { display: grid; gap: 8px; margin-top: 10px; }
.upload-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; font-size: 13px; }
.upload-item .progress { grid-column: span 2; }

/* ── Key/value list ── */
.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 8px 16px; }
.kv dt { color: var(--ink-soft); font-weight: 700; }
.kv dd { margin: 0; }

/* ── PIN screen ── */
.pin-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--sun-soft), transparent 70%), var(--bg);
}
.pin-card { width: min(360px, 100%); text-align: center; }
.pin-card .brand { justify-content: center; padding-bottom: 22px; }
.pin-title { font: 600 20px var(--font-head); }
.pin-hint { color: var(--ink-soft); margin-top: 6px; min-height: 22px; font-weight: 700; }
.pin-hint.error { color: var(--danger); }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 22px 0 26px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); transition: background 0.12s, border-color 0.12s, transform 0.12s; }
.pin-dot.optional { border-style: dashed; }
.pin-dot.filled { background: var(--sun); border-color: var(--sun-deep); transform: scale(1.1); }
.pin-dots.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-key {
  height: 64px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  font: 600 24px var(--font-head); cursor: pointer; display: grid; place-items: center;
}
.pin-key:active { transform: translateY(1px); background: var(--sun-soft); }
.pin-key.go { background: var(--sun); color: var(--on-sun); border-color: transparent; }
.pin-key:disabled { opacity: 0.4; cursor: not-allowed; }
.pin-key.blank { visibility: hidden; }

/* ── Misc ── */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.section-gap { margin-top: 24px; }
.stub {
  display: grid; gap: 10px; place-items: center; text-align: center; padding: 56px 20px;
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); color: var(--ink-soft);
}
.stub .icon { width: 40px; height: 40px; color: var(--sun-deep); }
.stub h3 { color: var(--ink); }
.stub ul { text-align: left; margin: 6px 0 0; padding-left: 20px; }

@media print {
  .sidebar, .topbar, .tabbar, .page-actions, .toolbar, .pager, .toasts { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}
