/* Shared look for both panels. Colours are tokens so dark mode is one switch. */
:root {
  --bg: #f5f6fa; --panel: #ffffff; --panel-2: #f9fafc; --text: #1b2130; --mute: #6b7385; --line: #e4e7ee;
  --brand: #4f46e5; --brand-2: #6366f1; --brand-soft: #eef0ff; --ok: #12805c; --ok-soft: #e3f6ee;
  --warn: #b45309; --warn-soft: #fff4e0; --bad: #c0362c; --bad-soft: #fdecea; --info: #0b6bcb; --info-soft: #e6f1fc;
  --side: #111827; --side-text: #cbd2e1; --side-mute: #7b8496; --side-active: #1f2937;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: "Inter", system-ui, "Segoe UI", Roboto, "Noto Sans", sans-serif; --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0e1117; --panel: #161b24; --panel-2: #1b212c; --text: #e6e9f0; --mute: #98a1b3; --line: #2a3140;
  --brand: #818cf8; --brand-2: #6366f1; --brand-soft: #23264a; --ok: #4ade80; --ok-soft: #12301f;
  --warn: #fbbf24; --warn-soft: #33270d; --bad: #f87171; --bad-soft: #3a1717; --info: #60a5fa; --info-soft: #132a45;
  --side: #0a0d13; --side-text: #c4cbd8; --side-mute: #6b7385; --side-active: #1a202b;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; } h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.mute { color: var(--mute); } .small { font-size: 12.5px; } .tiny { font-size: 11.5px; } .bold { font-weight: 600; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 16px; font-weight: 700; font-size: 16px; color: #fff; }
.side .brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--brand-2), #06b6d4); display: grid; place-items: center; color: #fff; font-size: 15px; }
.logo.has-img { background: #fff !important; overflow: hidden; padding: 2px; }
.logo.has-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.side nav { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.side .group { font-size: 10.5px; letter-spacing: .08em; color: var(--side-mute); margin: 14px 8px 6px; font-weight: 600; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--side-text); text-decoration: none; margin: 1px 0; }
.side nav a:hover { background: var(--side-active); }
.side nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand-2); }
.side nav a .ic { width: 18px; text-align: center; opacity: .9; }
.side .wallet { margin: 10px; padding: 12px; border-radius: 10px; background: var(--side-active); }
.side .wallet .lbl { font-size: 10.5px; letter-spacing: .08em; color: var(--side-mute); }
.side .wallet .amt { font-size: 20px; font-weight: 700; color: #fff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top .title { font-size: 17px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.top .spacer { flex: 1; }
.iconbtn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; height: 34px; min-width: 34px; padding: 0 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font: inherit; }
.iconbtn:hover { background: var(--panel-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.content { padding: 20px 22px 40px; max-width: 1400px; width: 100%; }
.menu-toggle { display: none; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; width: 250px; left: -260px; transition: left .2s; }
  .side.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 14px 16px 30px; }
}

/* ---------- building blocks ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.grid > .card + .card, .row > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; } .row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4, .g5 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.ghost { background: var(--panel); color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { background: var(--bad); } .btn.ok { background: var(--ok); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; } .btn.xs { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.link { background: none; color: var(--brand); padding: 0; height: auto; border: 0; }

label.f { display: block; font-size: 12.5px; font-weight: 550; color: var(--mute); margin: 0 0 4px; }
.field { margin-bottom: 12px; }
.field .help { font-size: 12px; color: var(--mute); margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=url], input[type=search], input[type=tel], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; }
textarea { height: auto; min-height: 90px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
textarea.code { font-family: var(--mono); font-size: 13px; min-height: 320px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type=range] { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* on/off switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .knob { width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .knob { background: var(--brand); }
.switch input:checked + .knob::after { left: 19px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--mute); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 13px; color: var(--text); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; font: inherit; color: var(--mute); cursor: pointer; white-space: nowrap; font-weight: 550; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; font: inherit; color: var(--mute); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

/* tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; font-weight: 600; color: var(--mute); background: var(--panel-2); white-space: nowrap; }
.tbl th.sort { cursor: pointer; } .tbl th.sort:hover { color: var(--text); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--panel-2); }
.tbl td.num, .tbl th.num { text-align: right; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 2px 0; font-size: 13px; color: var(--mute); }

/* stats */
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .lbl { font-size: 12.5px; color: var(--mute); display: flex; align-items: center; gap: 6px; }
.stat .val { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--mute); margin-top: 2px; }

.empty { text-align: center; padding: 40px 16px; color: var(--mute); }
.empty .big { font-size: 34px; margin-bottom: 6px; }
.note { background: var(--info-soft); color: var(--text); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.note.warn { background: var(--warn-soft); } .note.bad { background: var(--bad-soft); } .note.ok { background: var(--ok-soft); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 6px 12px; font-size: 13.5px; }
.kv > div { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) { .kv { grid-template-columns: 110px minmax(0, 1fr); } }
.kv > div:nth-child(odd) { color: var(--mute); }

/* collapsible section */
details.sec { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 10px; }
details.sec > summary { padding: 11px 14px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.sec > summary::before { content: "▸"; color: var(--mute); transition: transform .15s; }
details.sec[open] > summary::before { transform: rotate(90deg); }
details.sec > .body { padding: 2px 14px 14px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,14,22,.5); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.wide { width: min(900px, 100%); } .modal.xwide { width: min(1200px, 100%); }
.modal .mh { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal .mh h2 { margin: 0; flex: 1; }
.modal .mb { padding: 16px; overflow-y: auto; }
.modal .mf { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--mute); line-height: 1; }

/* dropdown menu */
.dd { position: relative; display: inline-block; }
.dd .menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); min-width: 220px; padding: 6px; z-index: 60; }
.dd .menu a, .dd .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 7px; border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
.dd .menu a:hover, .dd .menu button:hover { background: var(--panel-2); }

/* toast */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--panel); padding: 10px 14px; border-radius: 9px; box-shadow: 0 8px 20px rgba(0,0,0,.2); max-width: 380px; font-size: 13.5px; }
.toast.bad { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }

/* chat bubbles */
.chat { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.bubble.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble .who { font-size: 11px; opacity: .75; margin-bottom: 2px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--bg), var(--brand-soft)); }
.login-box { width: min(400px, 100%); }
.login-box .brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; margin-bottom: 16px; justify-content: center; }
.login-box .brand .logo { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, var(--brand-2), #06b6d4); display: grid; place-items: center; color: #fff; }
.err { color: var(--bad); font-size: 13px; margin-top: 8px; min-height: 18px; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--mute); }
