/* Sahayak Admin. Colours follow docs/05-design.md (the prototype's navy and gold). */
:root {
  --navy: #14213d;
  --navy-2: #22335c;
  --gold: #f29d38;
  --ink: #101828;
  --ink-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e9edf2;
  --bg: #f5f6f9;
  --surface: #ffffff;
  --green: #12b76a;
  --red: #f04438;
  --sky: #1f9ad6;
  --series-1: #2a78d6;
  --radius: 10px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Gujarati",
    "Gujarati Sangam MN", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--sky); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 800; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 800; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 700; color: var(--ink-2); }

/* ---- layout ---- */
.layout { display: grid; grid-template-columns: 228px 1fr; height: 100vh; }
.side {
  background: var(--navy);
  color: #d0d5dd;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.brand { padding: 18px 18px 14px; display: flex; gap: 10px; align-items: center; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--gold); color: var(--navy);
  display: grid; place-items: center; font-weight: 800;
}
.brand b { color: #fff; display: block; font-size: 15px; }
.brand small { color: var(--faint); font-size: 11.5px; }
.nav-group { padding: 10px 10px 4px; }
.nav-group > span {
  display: block; padding: 0 8px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: #8a94a8; font-weight: 700;
}
.nav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; border-radius: 8px; color: #d0d5dd; text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a.on { background: #ffffff1a; color: #fff; font-weight: 700; }
.nav a .n { font-size: 11.5px; color: #8a94a8; font-variant-numeric: tabular-nums; }
.side-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; color: #8a94a8; }
.side-foot button {
  background: none; border: 1px solid #ffffff33; color: #d0d5dd; border-radius: 8px;
  padding: 5px 10px; cursor: pointer; margin-top: 8px; width: 100%;
}
.main { overflow-y: auto; min-width: 0; }
.page { padding: 22px 26px 60px; max-width: 1600px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.page-note { color: var(--muted); margin: 0 0 16px; font-size: 13px; }

/* ---- controls ---- */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap;
  display: inline-flex; gap: 6px; align-items: center;
}
.btn:hover { border-color: #d0d5dd; background: #fafbfc; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: #b42318; border-color: #fecdca; }
.btn.danger:hover { background: #fef3f2; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 3px 8px; font-size: 12px; }
input.in, select.in, textarea.in {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--surface);
  min-width: 0;
}
input.in:focus, select.in:focus, textarea.in:focus, .btn:focus-visible {
  outline: 2px solid #1f9ad655; border-color: var(--sky);
}
.search { width: 280px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.toolbar .spacer { flex: 1; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.quick label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.quick select { min-width: 120px; max-width: 220px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; gap: 6px; align-items: center; background: #ebf6fc; color: #126b98;
  border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 12px; font-weight: 600;
}
.chip button {
  border: 0; background: #126b981a; border-radius: 999px; width: 18px; height: 18px;
  cursor: pointer; color: #126b98; line-height: 1; padding: 0;
}
.chip.toggle { padding: 4px 10px; cursor: pointer; border: 1px solid transparent; background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.chip.toggle.on { background: #ebf6fc; color: #126b98; border-color: #b9e0f5; }

/* ---- popovers ---- */
.pop-wrap { position: relative; }
.pop {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  box-shadow: 0 12px 32px #1018281f; min-width: 260px;
}
.pop.right { left: auto; right: 0; }
.pop .row { display: flex; gap: 6px; margin-bottom: 8px; }
.pop .cols { max-height: 320px; overflow-y: auto; display: grid; gap: 2px; }
.pop .cols label { display: flex; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.pop .cols label:hover { background: var(--bg); }

/* ---- cards and tables ---- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; cursor: default;
}
.tile[data-href] { cursor: pointer; }
.tile[data-href]:hover { border-color: #d0d5dd; }
.tile .label { font-size: 12px; color: var(--muted); }
.tile .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .value.warn { color: #b42318; }

.table-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: auto; max-height: calc(100vh - 250px);
}
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.data th {
  position: sticky; top: 0; z-index: 2; background: #f9fafb; text-align: left; font-weight: 700;
  color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
  font-size: 12px; user-select: none;
}
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--ink); }
table.data th .arrow { color: var(--sky); margin-left: 4px; }
table.data td {
  padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top;
  max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: #f9fbff; }
table.data tbody tr.sel td { background: #ebf6fc; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.plain { border-collapse: collapse; width: 100%; font-size: 13px; }
table.plain th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px 8px 6px 0; border-bottom: 1px solid var(--line); }
table.plain td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
table.plain td.num, table.plain th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.plain tr:last-child td { border-bottom: 0; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; color: var(--muted); font-size: 13px; }
.pager .spacer { flex: 1; }

/* ---- values ---- */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 12px; }
.badge {
  display: inline-block; border-radius: 6px; padding: 1px 7px; font-size: 11.5px; font-weight: 700;
  background: #f2f4f7; color: var(--ink-2); white-space: nowrap;
}
.badge.green { background: #ecfdf3; color: #067647; }
.badge.red { background: #fef3f2; color: #b42318; }
.badge.amber { background: #fffaeb; color: #b54708; }
.badge.blue { background: #ebf6fc; color: #126b98; }
.badge.violet { background: #f4f3ff; color: #5925dc; }
.badge.gold { background: #fff4e6; color: #b25e00; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.ref { color: var(--sky); }
.ref:hover { text-decoration: underline; }
.null { color: var(--faint); font-style: italic; }

/* ---- drawer ---- */
.drawer-back { position: fixed; inset: 0; background: #10182833; z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--surface);
  z-index: 41; display: flex; flex-direction: column; box-shadow: -12px 0 40px #1018282e;
}
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.drawer-head .t { flex: 1; min-width: 0; }
.drawer-head .t small { color: var(--muted); display: block; font-size: 12px; }
.drawer-head .t b { display: block; font-size: 16px; font-weight: 800; word-break: break-word; }
.drawer-body { padding: 14px 20px 30px; overflow-y: auto; flex: 1; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid var(--line); }
.fields { display: grid; grid-template-columns: 150px 1fr; gap: 0; font-size: 13px; }
.fields > div { padding: 7px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.fields .k { color: var(--muted); font-weight: 600; padding-right: 10px; word-break: break-all; }
.fields .k .edit-mark { color: var(--gold); margin-left: 3px; }
.fields .v { word-break: break-word; white-space: pre-wrap; }
.fields .v input, .fields .v select, .fields .v textarea { width: 100%; }
pre.json {
  margin: 0; font: 12px/1.5 var(--mono); background: #f9fafb; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto;
}
.related { margin-top: 18px; }
.related .grp { margin-bottom: 12px; }
.related .grp ul { margin: 0; padding: 0; list-style: none; }
.related .grp li { padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- activity ---- */
.feed { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.feed .day { padding: 8px 14px; font-size: 12px; font-weight: 800; color: var(--muted); background: #f9fafb; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; }
.feed .ev { display: grid; grid-template-columns: 64px 170px 1fr; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.feed .ev:hover { background: #f9fbff; }
.feed .ev .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.feed .ev .who { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .ev .who small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
.feed .ev .what { min-width: 0; }
.feed .ev .what .s { word-break: break-word; }
.feed .ev .what .x { color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-word; }

/* ---- chart (single series, small multiples) ---- */
.mini-chart { position: relative; }
.mini-chart .bars { display: flex; align-items: flex-end; gap: 2px; height: 90px; border-bottom: 1px solid var(--line); }
.mini-chart .bar-hit { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.mini-chart .bar { width: 100%; background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 0; }
.mini-chart .bar-hit:hover .bar { filter: brightness(1.12); }
.mini-chart .bar-hit.today .bar { background: var(--navy); }
.mini-chart .axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.mini-chart .head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.mini-chart .head b { font-size: 13px; color: var(--ink-2); }
.mini-chart .head span { font-size: 12px; color: var(--muted); }
.tip {
  position: fixed; z-index: 60; background: var(--ink); color: #fff; border-radius: 8px;
  padding: 6px 9px; font-size: 12px; pointer-events: none; white-space: nowrap;
}

/* ---- SQL ---- */
textarea.sql { width: 100%; min-height: 140px; font: 13px/1.5 var(--mono); resize: vertical; }

/* ---- sign-in ---- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--navy), var(--navy-2)); }
.login form { background: var(--surface); padding: 28px; border-radius: 14px; width: 320px; box-shadow: 0 20px 60px #0000004d; }
.login .logo { width: 44px; height: 44px; border-radius: 10px; background: var(--gold); color: var(--navy); display: grid; place-items: center; font-weight: 800; font-size: 20px; margin-bottom: 14px; }
.login input { width: 100%; font-size: 20px; letter-spacing: .3em; text-align: center; margin: 14px 0 10px; padding: 10px; }
.login .err { color: #b42318; font-size: 13px; min-height: 18px; }
.login button { width: 100%; justify-content: center; padding: 9px; }

/* ---- toast, empty, loading ---- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 70;
  transition: all .2s; pointer-events: none; font-weight: 600; font-size: 13px; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: #b42318; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.loading { padding: 30px; color: var(--muted); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { position: static; }
  .page { padding: 16px; }
  .search { width: 100%; }
  .feed .ev { grid-template-columns: 54px 1fr; }
  .feed .ev .what { grid-column: 1 / -1; }
}
