:root {
  --brand: #ff6a00;
  --brand-dark: #e05a00;
  --brand-soft: #fff1e6;
  --navy: #0b1f4d;
  --navy-2: #16306b;
  --bg: #f5f6f9;
  --card: #fff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --ok: #1b7f3b;
  --ok-bg: #e3f5ea;
  --warn: #9a6200;
  --warn-bg: #fff4d6;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; }
input, select, textarea, button { font: inherit; color: inherit; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 240px; flex: none; background: var(--navy); color: #d5dcef; display: flex; flex-direction: column;
  padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 20px; color: #fff; }
.brand img { width: 50px; }
.brand b { display: block; font-size: 15px; }
.brand small { opacity: .6; font-size: 12px; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
.side nav a { display: flex; align-items: center; gap: 10px; color: inherit; padding: 9px 12px; border-radius: 8px; }
.side nav a:hover { background: var(--navy-2); text-decoration: none; }
.side nav a.on { background: var(--brand); color: #fff; font-weight: 600; }
.side nav .sep { height: 1px; background: rgba(255,255,255,.1); margin: 8px 4px; }
.side nav .cap { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .5; padding: 10px 12px 4px; }
.side .me { font-size: 12px; padding: 10px 12px; background: rgba(0,0,0,.18); border-radius: 8px; }
.side .me form { margin-top: 6px; }
.side .me button { background: none; border: 0; color: #ffb27a; padding: 0; cursor: pointer; }
.main { flex: 1; min-width: 0; padding: 26px 32px 60px; }
.impersonating { background: #fff4d6; border: 1px solid #f3d27a; padding: 8px 14px; border-radius: 8px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }

.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { font-size: 22px; }
.head p { margin: 3px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 18px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
a.stat:hover { border-color: var(--brand); text-decoration: none; }
a.stat { color: inherit; display: block; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c7cbd3; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--brand-dark); cursor: pointer; padding: 0; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: 12px; background: #eef0f3; color: #374151; text-transform: capitalize; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert ul { margin: 0; padding-left: 18px; }

/* Forms */
.form { display: grid; gap: 14px; }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
label.f { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
label.f small { font-weight: 400; color: var(--muted); }
.in, select.in, textarea.in { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-weight: 400; }
.in:focus { outline: 2px solid #ffd2b0; border-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline .in { width: auto; }

/* Tables */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.tbl-wrap.tall { max-height: calc(100vh - 260px); }
table.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl td.wrap { white-space: normal; }
.tbl th { background: #f7f8fb; font-weight: 600; position: sticky; top: 0; z-index: 1; }
.tbl tr:hover td { background: #fbf8f5; }
.tbl tr.sel td { background: var(--brand-soft); }
.tbl .num { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }
.pagination { margin-top: 14px; }
.pagination nav > div:first-child { display: none; }
.kv { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; word-break: break-word; gap: 6px 12px; }
.kv > div:nth-child(odd) { color: var(--muted); }

/* Data explorer (client) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--brand-dark); border-color: var(--brand); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .search { flex: 1; min-width: 200px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: 16px; background: #fff; font-size: 13px; cursor: pointer; user-select: none; }
.split { display: grid; grid-template-columns: 290px 1fr; gap: 14px; align-items: start; }
.picker { max-height: calc(100vh - 230px); display: flex; flex-direction: column; padding: 12px; }
.picker .list { overflow: auto; flex: 1; margin: 8px 0; }
.pick { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 6px; cursor: pointer; }
.pick:hover { background: var(--brand-soft); }
.pick .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .cnt { margin-left: auto; color: var(--muted); font-size: 12px; }
.sw { width: 10px; height: 10px; border-radius: 50%; background: #cfd4dc; flex: none; }
.more { padding: 10px; text-align: center; color: var(--muted); }

.qr-box { display: grid; grid-template-columns: 300px 1fr; gap: 26px; align-items: center; }
.qr { width: 280px; height: 280px; border: 1px solid var(--line); border-radius: 12px; display: flex; align-items: center; justify-content: center; background: #fff; }
.qr img { width: 264px; height: 264px; }
.steps { margin: 0; padding-left: 20px; line-height: 2; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 50; }

/* Login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login .art { background: var(--navy); display: flex; flex-direction: column; justify-content: center; align-items: center; color: #d5dcef; padding: 40px; text-align: center; }
.login .art img { width: 160px; margin-bottom: 22px; }
.login .art h2 { color: #fff; font-size: 26px; }
.login .box { display: flex; align-items: center; justify-content: center; padding: 30px; }
.login .box .card { width: 100%; max-width: 380px; padding: 28px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px 16px 40px; }
  .g2, .g3, .split, .qr-box, .login, .form .row2, .form .row3 { grid-template-columns: 1fr; }
  .login .art { display: none; }
}

/* "hidden" must win over display rules like .btn { display: inline-flex } */
[hidden] { display: none !important; }


/* ---------- Public website ---------- */
body.pub { background: #fff; }
.pub-wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.pub-nav { position: sticky; top: 0; z-index: 10; background: rgba(255,255,255,.95); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
.pub-nav .pub-wrap { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.pub-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--navy); font-size: 17px; }
.pub-brand img { width: 40px; }
.pub-brand:hover { text-decoration: none; }
.pub-nav nav { display: flex; align-items: center; gap: 20px; }
.pub-nav nav a:not(.btn) { color: var(--text); }
.pub-hero { background: linear-gradient(135deg, #0b1f4d 0%, #16306b 60%, #22407f 100%); color: #e6ebf7; padding: 72px 0; }
.pub-hero .pub-wrap { display: grid; grid-template-columns: 1.2fr 1fr; gap: 40px; align-items: center; }
.pub-hero h1 { font-size: 40px; line-height: 1.15; color: #fff; margin: 14px 0; }
.pub-hero p { font-size: 17px; opacity: .9; }
.pub-hero img { width: 100%; max-width: 380px; justify-self: center; background: #fff; border-radius: 20px; padding: 24px; }
.pub-hero .btn:not(.primary) { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.pub-sec { padding: 64px 0; }
.pub-sec.alt { background: var(--bg); }
.pub-sec h2 { font-size: 28px; margin-bottom: 24px; color: var(--navy); }
.pub-sec .card h3 { font-size: 17px; }
.pub-sec .card p { color: #4b5563; margin: 0; }
.step { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.pub-foot { background: var(--navy); color: #c9d2ea; padding: 40px 0; }
.pub-foot .pub-wrap:first-child { display: flex; justify-content: space-between; gap: 30px; flex-wrap: wrap; }
.pub-foot a { color: #ffb27a; }
.pub-links { display: flex; flex-direction: column; gap: 8px; }
.pub-doc { padding: 48px 20px 72px; max-width: 820px; line-height: 1.75; }
.pub-doc h1 { font-size: 32px; color: var(--navy); }
.pub-doc h2 { font-size: 20px; margin: 28px 0 8px; color: var(--navy); }
.pub-doc li { margin-bottom: 4px; }
@media (max-width: 900px) {
  .pub-hero .pub-wrap { grid-template-columns: 1fr; }
  .pub-hero h1 { font-size: 30px; }
  .pub-nav nav a:not(.btn) { display: none; }
}


/* ---------- Inbox (official numbers) ---------- */
.ib { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 330px); min-height: 460px; }
.ib-side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#ib-list { overflow: auto; flex: 1; }
.ib-row { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: inherit; }
.ib-row:hover { background: #fbf8f5; text-decoration: none; }
.ib-row.on { background: var(--brand-soft); }
.ib-top, .ib-bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ib-snip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-badge { background: #25d366; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.ib-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ib-head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.ib-thread { flex: 1; overflow: auto; padding: 16px; background: #efeae2; display: flex; flex-direction: column; gap: 6px; }
.ib-msg { max-width: 70%; padding: 7px 10px 4px; border-radius: 8px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; }
.ib-msg.out { align-self: flex-end; background: #d9fdd3; }
.ib-msg.in { align-self: flex-start; }
.ib-meta { font-size: 11px; color: #667781; text-align: right; margin-top: 2px; }
.ib-reply { padding: 12px 16px; border-top: 1px solid var(--line); }
@media (max-width: 900px) { .ib { grid-template-columns: 1fr; height: auto; } .ib-side { max-height: 300px; } .ib-thread { min-height: 360px; } }

/* Public API docs */
.docs { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 40px; align-items: start; }
.docs-toc { position: sticky; top: 80px; padding: 48px 0 24px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; max-height: calc(100vh - 80px); overflow-y: auto; }
.docs-toc a { color: #475569; padding: 4px 8px; border-radius: 6px; text-decoration: none; }
.docs-toc a:hover { background: #eef2ff; color: var(--navy); }
.docs-toc-title, .docs-toc-group { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #94a3b8; margin: 14px 8px 4px; }
.docs-toc-title { margin-top: 0; }
.docs-body { max-width: none; padding-left: 0; padding-right: 0; }
.docs-body .lead { font-size: 18px; color: #475569; }
.docs-body h2 { scroll-margin-top: 80px; padding-top: 12px; border-top: 1px solid #e5e7eb; margin-top: 36px; }
.docs-body h3 { scroll-margin-top: 80px; font-size: 16px; margin: 20px 0 6px; color: var(--navy); }
.docs-code { background: #0b1f4d; color: #e5e7eb; padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: 13px; line-height: 1.6; font-family: Consolas, Menlo, monospace; white-space: pre; }
.docs-tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0 16px; }
.docs-tbl th, .docs-tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
.docs-tbl th { color: #475569; font-weight: 600; white-space: nowrap; }
.docs-body code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.docs-code code, .docs-body pre code { background: none; padding: 0; }
.m { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 5px; margin-right: 6px; vertical-align: middle; color: #fff; }
.m.get { background: #0ea5e9; } .m.post { background: #16a34a; }
.docs-help { margin-top: 40px; padding: 16px; border-radius: 10px; background: #f8fafc; border: 1px solid #e5e7eb; }
@media (max-width: 860px) { .docs { grid-template-columns: 1fr; gap: 0; } .docs-toc { position: static; max-height: none; padding-bottom: 0; flex-direction: row; flex-wrap: wrap; } .docs-toc-title, .docs-toc-group { width: 100%; } }
