:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #e1e3ec;
  --text: #1c1e26;
  --muted: #5d6275;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eceafd;
  --good: #15803d;
  --good-soft: #e3f5e9;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --bad: #b91c1c;
  --bad-soft: #fde7e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131a;
    --surface: #1b1c25;
    --surface-2: #232431;
    --border: #2f3142;
    --text: #e8e9f0;
    --muted: #a0a4b8;
    --accent: #8b85ff;
    --accent-text: #11121a;
    --accent-soft: #2a2850;
    --good: #4ade80;
    --good-soft: #163322;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --bad: #f87171;
    --bad-soft: #3d1b1b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
p.sub { margin: 0 0 20px; color: var(--muted); }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; padding: 4px 8px 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 14px; }
.nav-group { margin: 12px 8px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.nav a {
  display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { border-top: 1px solid var(--border); margin-top: 16px; padding: 12px 8px 0; font-size: 14px; }
.who .role { color: var(--muted); font-size: 13px; }
.main { flex: 1; min-width: 0; padding: 28px 32px 64px; max-width: 1200px; }
.topbar { display: none; }

@media (max-width: 860px) {
  .shell { display: block; }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .topbar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px;
  }
  .main { padding: 20px 16px 64px; }
}

/* Cards and stats */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* Buttons */
button, .btn {
  font: inherit; font-size: 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 14px; cursor: pointer; min-height: 36px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.link { border: none; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; }
button:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.menu-btn { border: none; background: none; font-size: 22px; padding: 2px 8px; }

/* Forms */
form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.field .help { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--bad); }
input, select, textarea {
  font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); width: 100%; min-height: 38px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 14px; }
.check input { width: 18px; height: 18px; min-height: 0; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 20, .5); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px; border: 1px solid var(--border); }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); }

/* Toast */
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 60; padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--bg); max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }

/* Bars (analytics) */
.bar-row { display: grid; grid-template-columns: 92px 1fr 64px; gap: 10px; align-items: center; font-size: 13px; padding: 3px 0; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 12px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 4px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.note { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
pre.detail { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 300px; overflow: auto; }

/* Tables become stacked cards on phones */
@media (max-width: 640px) {
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { border-bottom: 1px solid var(--border); padding: 10px 0; }
  .table-wrap tr:last-child { border-bottom: none; }
  .table-wrap td { border: none; padding: 3px 0; display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; text-align: right; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  .table-wrap td:not([data-label])::before { content: none; }
  .table-wrap td:not([data-label]) { justify-content: flex-start; padding-top: 6px; }
  .table-wrap td.mono { word-break: break-all; }
  .card { padding: 14px; }
}
