:root {
  --bg: #f4f6fb; --panel: #ffffff; --line: #e1e6f0; --text: #141b2e; --muted: #5d6781;
  --brand-soft: #e8eeff; --out: #d9f5e3;
  --red: #c0392b; --red-soft: #fdecea; --amber: #a86400; --amber-soft: #fff4dc; --blue: #1c6fd1; --blue-soft: #e6f0fc;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 48, .06), 0 4px 14px rgba(16, 24, 48, .05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
code { background: #eef2f0; padding: 1px 6px; border-radius: 5px; font-size: 13px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hide { display: none !important; }

/* layout */
.shell { display: flex; height: 100vh; }
.side { width: 216px; flex: none; background: var(--ink); color: #cfd6ea; display: flex; flex-direction: column; padding: 16px 10px; }
.logo { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; color: #fff; padding: 2px 10px 18px; }
.logo span.mark { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; font-size: 15px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-radius: 8px; color: inherit; text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: rgba(255, 255, 255, .07); }
.nav a.on { background: var(--brand); color: #fff; }
.badge { background: #ffcf5c; color: #3b2a00; border-radius: 99px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.side .foot { margin-top: auto; padding: 10px 12px 0; font-size: 12.5px; border-top: 1px solid rgba(255, 255, 255, .1); }
.side .foot a { color: #b9c8ff; cursor: pointer; }
.main { flex: 1; min-width: 0; overflow: auto; }
.page { padding: 24px 28px 48px; max-width: 1180px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* building blocks */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12.5px; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 13px; border-radius: 8px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c5cec9; background: #f8faf9; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--brand-dark); }
button.danger { color: var(--red); }
button.link { border: 0; background: none; padding: 0; color: var(--brand); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.sm { padding: 4px 9px; font-size: 12.5px; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid #cfd7d3; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--brand); }
textarea { resize: vertical; min-height: 80px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
label.f > small { display: block; color: var(--muted); margin-top: 4px; font-size: 12.5px; }
label.check { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; cursor: pointer; }
label.check input { margin-top: 4px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef2f0; color: #40504a; white-space: nowrap; }
.pill.green { background: #e3f3ed; color: #085c45; }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.tag { display: inline-block; background: #eef2f0; border-radius: 6px; padding: 0 7px; font-size: 12px; margin: 1px 3px 1px 0; }
.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; background: var(--amber-soft); color: #5c3b00; }
.notice.info { background: var(--blue-soft); color: #153f73; }
.notice.bad { background: var(--red-soft); color: #7d2318; }
.bar { height: 8px; background: #e8eeeb; border-radius: 99px; overflow: hidden; min-width: 90px; }
.bar i { display: block; height: 100%; background: var(--brand); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.copy { display: flex; gap: 8px; align-items: center; }
.copy code { flex: 1; padding: 7px 10px; }

/* checklist */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 10px; padding: 7px 0; align-items: center; }
.steps .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #c5cec9; flex: none; display: grid; place-items: center; font-size: 12px; color: #fff; }
.steps li.done .dot { background: var(--brand); border-color: var(--brand); }
.steps li.done span.t { color: var(--muted); text-decoration: line-through; }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.chart .bars { display: flex; align-items: flex-end; gap: 2px; height: 100%; width: 100%; justify-content: center; }
.chart .bars i { width: 42%; max-width: 16px; border-radius: 3px 3px 0 0; background: var(--brand); min-height: 1px; }
.chart .bars i.in { background: #8db4e8; }
.chart small { font-size: 10.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 5px 0 12px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; }

/* modal + toast */
.overlay { position: fixed; inset: 0; background: rgba(12, 26, 21, .5); display: grid; place-items: start center; padding: 5vh 16px; overflow: auto; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 860px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast { background: #17211e; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: var(--shadow); }
.toast.bad { background: var(--red); }

/* inbox */
.inbox { display: flex; height: 100vh; }
.inbox .list { width: 310px; flex: none; border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; }
.inbox .list .top { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.inbox .items { overflow: auto; flex: 1; }
.conv { padding: 11px 13px; border-bottom: 1px solid var(--line); cursor: pointer; display: block; color: inherit; text-decoration: none; }
.conv:hover { background: #f6f9f7; }
.conv.on { background: var(--brand-soft); }
.conv .n { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.conv .n time { font-weight: 400; color: var(--muted); font-size: 12px; flex: none; }
.conv .p { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.thread { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #efeae2; }
.thread .head { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(74%, 560px); padding: 7px 10px 5px; border-radius: 10px; background: #fff; align-self: flex-start; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg.note { align-self: center; background: #fff7d6; font-size: 13px; text-align: center; }
.msg.failed { background: var(--red-soft); }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; white-space: normal; }
.msg .meta .read { color: var(--blue); }
.msg .meta .err { color: var(--red); }
.msg img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
.composer { background: #fff; border-top: 1px solid var(--line); padding: 10px 12px; }
.composer textarea { min-height: 54px; max-height: 180px; }
.composer.note-mode textarea { background: #fffbe8; }
.details { width: 280px; flex: none; border-left: 1px solid var(--line); background: #fff; overflow: auto; padding: 16px; }
.details h3 { margin-top: 16px; }
.bubble-preview { background: var(--out); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 360px; }

@media (max-width: 1100px) { .details { display: none; } }
@media (max-width: 760px) {
  .shell { flex-direction: column; height: auto; min-height: 100vh; }
  .side { width: auto; flex-direction: row; align-items: center; padding: 8px; overflow-x: auto; }
  .logo { padding: 0 8px; } .logo b { display: none; }
  .nav { display: flex; } .nav a { margin: 0 2px; gap: 6px; }
  .side .foot { margin: 0 0 0 auto; border: 0; padding: 0 8px; white-space: nowrap; } .side .foot div { display: none; }
  .page { padding: 16px; }
  .inbox { height: calc(100vh - 56px); }
  .inbox .list { width: 100%; } .inbox.open .list { display: none; } .inbox:not(.open) .thread { display: none; }
}

/* plan banner + billing */
.planbox { margin: 10px 2px; padding: 10px 12px; border-radius: 8px; background: rgba(255, 255, 255, .08); font-size: 12.5px; }
.planbox b { color: #fff; display: block; }
.planbox.warn { background: var(--accent); color: #2b1400; } .planbox.warn b, .planbox.warn a { color: #2b1400; }
.plans { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.plan { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: #fff; display: flex; flex-direction: column; }
.plan.pop { border: 2px solid var(--brand); }
.plan .price { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0; } .plan .price small { font-size: 13px; font-weight: 400; color: var(--muted); }
.plan ul { list-style: none; padding: 0; margin: 10px 0 16px; flex: 1; } .plan li { padding: 3px 0 3px 20px; position: relative; }
.plan li::before { content: "✓"; position: absolute; left: 0; color: var(--brand); font-weight: 700; }
.usage { margin-bottom: 12px; } .usage .bar { height: 10px; margin-top: 4px; } .usage .bar i.hot { background: var(--accent); }
