/* JigjigaSale Tally — web UI */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --subtle: #f8fafc;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --side: #0f172a;
  --side-hover: #1e293b;
  --side-active: #312e81;
  --side-ink: #cbd5e1;
  --side-muted: #64748b;
  --dr: #0e7490;
  --cr: #b45309;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111827; --subtle: #0f172a; --ink: #e5e7eb; --muted: #94a3b8; --line: #1f2937;
    --accent: #818cf8; --accent-hover: #6366f1; --accent-soft: #1e1b4b; --dr: #67e8f9; --cr: #fbbf24;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111827; --subtle: #0f172a; --ink: #e5e7eb; --muted: #94a3b8; --line: #1f2937;
  --accent: #818cf8; --accent-hover: #6366f1; --accent-soft: #1e1b4b; --dr: #67e8f9; --cr: #fbbf24;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); min-height: 100vh; display: flex; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0 0 12px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.dr { color: var(--dr); } .cr { color: var(--cr); }
.error { color: var(--danger); }

/* ---------------------------------------------------------------- shell */
#sidebar { width: 256px; flex: 0 0 256px; background: var(--side); color: var(--side-ink); height: 100vh; position: sticky; top: 0;
  display: none; flex-direction: column; }
body.authed #sidebar { display: flex; }
.brand { display: block; color: #fff; font-weight: 700; font-size: 18px; padding: 20px 22px 16px; letter-spacing: -.01em; }
.brand span { color: #a5b4fc; }
.brand:hover { text-decoration: none; }
.chip { display: flex; gap: 10px; align-items: center; margin: 0 14px 10px; padding: 10px 12px; background: var(--side-hover);
  border-radius: 10px; color: #fff; }
.chip:hover { text-decoration: none; background: #273449; }
.chip b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.chip small { color: var(--side-ink); font-size: 11px; text-transform: capitalize; }
.mono { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: #4f46e5; color: #fff;
  font-weight: 700; font-size: 13px; flex: none; }
.mono.c1 { background: #0891b2; } .mono.c2 { background: #d97706; } .mono.c3 { background: #16a34a; } .mono.c4 { background: #db2777; }
#gateway { flex: 1; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
#gateway h3 { margin: 16px 14px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--side-muted); }
#gateway a { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 8px; color: var(--side-ink);
  border-left: 3px solid transparent; }
#gateway a:hover { background: var(--side-hover); text-decoration: none; }
#gateway a.active { background: var(--side-active); color: #fff; border-left-color: #818cf8; }
#gateway i { font-style: normal; width: 18px; text-align: center; opacity: .9; }
#gateway span { flex: 1; }
#gateway kbd { font: 11px Inter, sans-serif; color: var(--side-muted); }
#user { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--side-hover); }
#user .who { flex: 1; min-width: 0; }
#user b { display: block; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
#user small { color: var(--side-muted); font-size: 11px; }
#user a { color: var(--side-ink); font-size: 18px; }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: #334155; color: #fff;
  font-weight: 600; font-size: 13px; flex: none; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; background: var(--accent); margin-right: 6px; vertical-align: middle; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
#topbar { display: none; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
#topbar #company-name { font-weight: 600; }
#period { color: var(--muted); font-size: 12px; }
#menu { display: none; font-size: 18px; padding: 4px 10px; }
.spacer { flex: 1; }
#view { flex: 1; padding: 28px 32px; max-width: 1400px; width: 100%; }
#keys { font-size: 12px; color: var(--muted); padding: 8px 32px; border-top: 1px solid var(--line); background: var(--surface); }
#keys:empty { display: none; }
#scrim { display: none; }

/* --------------------------------------------------------------- blocks */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px;
  box-shadow: var(--shadow); }
.card > h2:first-child { font-size: 20px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 15px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.row > label { flex: 1; min-width: 170px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--muted); }
label > span { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; transition: border-color .15s, box-shadow .15s; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input:disabled, textarea:disabled, select:disabled { background: var(--subtle); color: var(--muted); }
button, .btn { font: inherit; font-weight: 600; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 8px 16px; border-radius: 8px; transition: background .15s; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.ghost, .btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
button.ghost:hover, .btn.ghost:hover { background: var(--subtle); }
button.danger { border-color: var(--danger); background: var(--danger); }
button.small { padding: 3px 10px; font-size: 12px; }
button.wide { width: 100%; justify-content: center; padding: 11px; }
.actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--subtle); }
tbody tr:nth-child(even) td, table tr:nth-child(even) td { background: color-mix(in srgb, var(--subtle) 60%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-soft) !important; }
tr.group td { font-weight: 600; }
tr.total td { font-weight: 700; background: var(--accent-soft) !important; border-top: 1px solid var(--accent); }
.lvl1 { padding-left: 28px !important; } .lvl2 { padding-left: 46px !important; } .lvl3 { padding-left: 64px !important; } .lvl4 { padding-left: 82px !important; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.two-col > div + div { border-left: 1px solid var(--line); }
.two-col h4 { margin: 0; padding: 10px 12px; background: var(--subtle); border-bottom: 1px solid var(--line); font-size: 13px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: capitalize;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.badge.role-accountant { background: #ecfeff; color: #0e7490; }
.badge.role-viewer { background: #f3f4f6; color: #4b5563; }
.badge.role-custom { background: #fffbeb; color: #b45309; }
.perm-box { border: 1px solid var(--accent); border-radius: 10px; padding: 16px 18px; margin: 14px 0; background: var(--subtle); }
table.perm td { padding: 6px 10px; }
table.perm td + td { text-align: center; width: 70px; }
table.perm tr.group td { background: transparent !important; color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; padding-top: 14px; }
table.perm input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }
#members select { margin-right: 6px; }
.curbal { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.curbal.dr { color: var(--dr); } .curbal.cr { color: var(--cr); } .curbal.low { color: var(--danger); }
.lines td.bal, .lines td.stock { vertical-align: middle; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.tile-top { display: flex; justify-content: space-between; align-items: center; }
.tile i { font-style: normal; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; color: #fff; background: #4f46e5; }
.tile.t1 i { background: #0891b2; } .tile.t2 i { background: #d97706; } .tile.t3 i { background: #16a34a; } .tile.t4 i { background: var(--danger); }
.tile.t4 .v { color: var(--danger); }
.tile .v { font-size: 22px; font-weight: 700; margin-top: 10px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.dash-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 18px; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 240px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.bars span { width: 34%; max-width: 20px; border-radius: 4px 4px 0 0; min-height: 0; transition: height .4s; }
.b1 { background: var(--accent); } .b2 { background: #f59e0b; }
.bar-col small { color: var(--muted); font-size: 11px; margin-top: 6px; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }

.co-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 20px; }
.co-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; color: var(--ink);
  box-shadow: var(--shadow); transition: transform .15s, border-color .15s, box-shadow .15s; }
.co-card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 8px 24px rgba(79, 70, 229, .12); }
.co-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.co-card h3 { font-size: 16px; }
.co-card p { margin: 4px 0 12px; font-size: 13px; }
.co-card .open { font-weight: 600; color: var(--accent); font-size: 13px; }
.empty { text-align: center; padding: 40px; }

.lines td { padding: 4px; }
.lines input, .lines select { width: 100%; }
.summary { margin-left: auto; min-width: 300px; width: auto; background: var(--subtle); border-radius: 10px; }
.summary td { border: none; padding: 5px 12px; background: transparent !important; }

/* --------------------------------------------------------------- auth */
body:not(.authed) #view { padding: 0; max-width: none; }
body:not(.authed) #keys { display: none; }
.auth-wrap { display: grid; grid-template-columns: minmax(320px, 5fr) 7fr; min-height: 100vh; }
.hero { background: linear-gradient(160deg, #4f46e5 0%, #312e81 45%, #0f172a 100%); color: #e0e7ff; padding: 56px 48px;
  position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; width: 340px; height: 340px; border: 2px solid rgba(165, 180, 252, .5); border-radius: 50%;
  right: -120px; top: -120px; }
.brand.big { padding: 0; font-size: 30px; line-height: 1.15; }
.brand.big span { display: block; }
.hero .lead { font-size: 17px; font-weight: 600; color: #fff; max-width: 360px; margin: 28px 0; line-height: 1.5; }
.hero ul { list-style: none; padding: 0; margin: 0; }
.hero li { margin: 12px 0; color: #c7d2fe; }
.hero li::before { content: "✓"; margin-right: 10px; color: #a5b4fc; }
form.auth { align-self: center; justify-self: center; width: min(400px, 90%); display: flex; flex-direction: column; gap: 14px; }
form.auth h1 { font-size: 28px; }
form.auth p { margin: -6px 0 8px; }

#toast { position: fixed; bottom: 24px; right: 24px; background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px;
  max-width: 420px; z-index: 20; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); border-left: 4px solid var(--ok); }
#toast.err { border-left-color: var(--danger); }

/* ---------------------------------------------------------- responsive */
@media (max-width: 900px) {
  body.authed #sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open #sidebar { transform: none; }
  body.nav-open #scrim { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 25; }
  body.authed #topbar { display: flex; }
  #menu { display: inline-flex; }
  #view { padding: 16px; }
  #keys { display: none; }
  .dash-grid, .two-col, .auth-wrap { grid-template-columns: 1fr; }
  .two-col > div + div { border-left: none; border-top: 1px solid var(--line); }
  .hero { padding: 32px 24px; }
  .hero ul { display: none; }
  .scroll, .card { overflow-x: auto; }
}
@media print {
  #sidebar, #topbar, #keys, .actions, .noprint, .quick { display: none !important; }
  #view { padding: 0; }
  .card { border: none; box-shadow: none; }
}
