:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #f0f4f2;
  --border: #e1e8e4;
  --text: #0f1f17;
  --muted: #5d6f66;
  --brand: #0e8a5f;
  --brand-strong: #0a6b49;
  --brand-soft: #e3f4ec;
  --danger: #c2372f;
  --danger-soft: #fdecea;
  --warn: #9a6400;
  --warn-soft: #fff4dc;
  --bubble-out: #dcf5e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(15 31 23 / 0.04), 0 8px 24px rgb(15 31 23 / 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1411;
    --surface: #141d19;
    --surface-2: #1a2520;
    --border: #25332c;
    --text: #e7efea;
    --muted: #93a69c;
    --brand: #2fbf86;
    --brand-strong: #49d39b;
    --brand-soft: #173428;
    --danger: #f07a70;
    --danger-soft: #3a1c1a;
    --warn: #f0b84a;
    --warn-soft: #3a2d12;
    --bubble-out: #1d3a2d;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; margin: 0; }
svg { flex: none; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---- top bar ---- */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 12px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 17px; }
.logo:hover { text-decoration: none; }
.logo-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.logo small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: -2px; }
.nav { display: flex; gap: 8px; align-items: center; }

/* ---- buttons / inputs ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-fb { background: #1877f2; border-color: #1877f2; color: #fff; height: 46px; padding: 0 20px; font-size: 15px; }
.btn-fb:hover { background: #0f65d4; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn svg { width: 18px; height: 18px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
label.field > small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.notice { border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-bottom: 14px; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--brand-soft); color: var(--brand-strong); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---- landing ---- */
.hero { padding: 72px 0 40px; text-align: center; }
.eyebrow { display: inline-block; background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; font-size: 13px; padding: 4px 12px; border-radius: 99px; }
.hero h1 { font-size: clamp(32px, 5vw, 52px); margin: 18px auto 14px; max-width: 760px; }
.hero p { color: var(--muted); font-size: 18px; max-width: 620px; margin: 0 auto 28px; }
.hero .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 14px; padding: 24px 0 64px; }
.feature { padding: 20px; }
.feature .ic { width: 38px; height: 38px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin-bottom: 12px; }
.feature h3 { font-size: 16px; margin-bottom: 6px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }
.footer { border-top: 1px solid var(--border); padding: 24px 0; color: var(--muted); font-size: 13px; }
.footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.footer nav { display: flex; gap: 16px; flex-wrap: wrap; }

/* ---- auth ---- */
.auth { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 32px 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { font-size: 24px; margin-bottom: 6px; }
.auth p.sub { color: var(--muted); margin: 0 0 22px; }
.auth .btn { width: 100%; }
.auth .switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }

/* ---- legal ---- */
.legal { max-width: 760px; margin: 40px auto 64px; padding: 32px; }
.legal h1 { font-size: 32px; margin-bottom: 4px; }
.legal h2 { font-size: 18px; margin: 28px 0 8px; }
.legal p, .legal li { color: var(--text); }
.legal ul { padding-left: 20px; }

/* ---- dashboard ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .logo { padding: 4px 8px 18px; }
.side a.item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.side a.item:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.side a.item.on { background: var(--brand-soft); color: var(--brand-strong); }
.side a.item svg { width: 18px; height: 18px; }
.side a.item em { margin-left: auto; font-style: normal; background: var(--brand); color: #fff; font-size: 11px; border-radius: 99px; padding: 0 7px; line-height: 18px; }
.side .spacer { flex: 1; }
.side .me { border-top: 1px solid var(--border); padding: 12px 8px 0; font-size: 13px; }
.side .me strong { display: block; }
.side .me button { margin-top: 8px; }
.shell > div { min-width: 0; }
.main { padding: 28px 32px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.mobile-nav { display: none; }

.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.status-pill.ok { background: var(--brand-soft); color: var(--brand-strong); }
.status-pill.bad { background: var(--danger-soft); color: var(--danger); }
.status-pill.warn { background: var(--warn-soft); color: var(--warn); }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.connect-card { padding: 28px; max-width: 720px; }
.connect-card h2 { font-size: 18px; margin-bottom: 6px; }
.steps { margin: 18px 0 22px; padding: 0; list-style: none; display: grid; gap: 10px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps b { width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; font-size: 12px; flex: none; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; margin: 18px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-all; }
details.dev { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 16px; }
details.dev summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
details.dev form { margin-top: 14px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 140px); min-height: 460px; overflow: hidden; }
.convos { border-right: 1px solid var(--border); overflow-y: auto; }
.convos .new { padding: 12px; border-bottom: 1px solid var(--border); }
.convo { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; font: inherit; color: inherit; }
.convo:hover { background: var(--surface-2); }
.convo.on { background: var(--brand-soft); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); color: var(--brand-strong); display: grid; place-items: center; font-weight: 700; flex: none; }
.convo .t { min-width: 0; flex: 1; }
.convo .t strong { display: flex; justify-content: space-between; gap: 6px; font-size: 14px; }
.convo .t strong small { color: var(--muted); font-weight: 500; font-size: 11px; }
.convo .t span { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo .badge { background: var(--brand); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; line-height: 18px; align-self: center; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.thread-head .t { flex: 1; min-width: 0; }
.thread-head small { color: var(--muted); display: block; }
.msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.bubble { max-width: min(560px, 80%); padding: 8px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); white-space: pre-wrap; word-wrap: break-word; font-size: 14px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-color: transparent; }
.bubble .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble .meta.failed { color: var(--danger); }
.bubble .tpl { display: block; font-size: 11px; font-weight: 600; color: var(--brand-strong); margin-bottom: 2px; }
.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 42px; height: 42px; max-height: 160px; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 24px; }

/* templates */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.panel { padding: 20px; }
.panel h2 { font-size: 16px; margin-bottom: 14px; }
.tpl-list { display: grid; gap: 10px; }
.tpl-item { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tpl-item header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.tpl-item header strong { font-size: 14px; word-break: break-all; }
.tpl-item p { margin: 0; font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.tpl-item .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; font-size: 12px; color: var(--muted); }
.tpl-item .row .btn { margin-left: auto; }
.preview { background: var(--bg); border-radius: 12px; padding: 16px; margin-top: 4px; }
.preview .bubble { max-width: 100%; }
.preview .bubble b { display: block; margin-bottom: 4px; }
.preview .bubble small { display: block; color: var(--muted); margin-top: 6px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .mobile-nav { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
  .mobile-nav a { white-space: nowrap; padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface-2); }
  .mobile-nav a.on { background: var(--brand-soft); color: var(--brand-strong); }
  .main { padding: 20px 16px; }
  .inbox { grid-template-columns: minmax(0, 1fr); height: auto; }
  .thread-head .status-pill { display: none; }
  .inbox.has-thread .convos { display: none; }
  .inbox:not(.has-thread) .thread { display: none; }
  .msgs { min-height: 50vh; }
  .grid-2, .row-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
