:root {
  --brand: #1F2A44;
  --accent: #E8762B;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --text: #151A24;
  --muted: #667085;
  --line: #E3E6EB;
  --ok-bg: #ECF8F1; --ok: #146C43;
  --warn-bg: #FFF4E5; --warn: #8A4B00;
  --bad: #B42318;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F131B; --surface: #1A202B; --text: #ECEFF4; --muted: #9AA3B2; --line: #2A3240;
    --ok-bg: #12291E; --ok: #6FD3A0; --warn-bg: #2E2312; --warn: #F3C27A; --bad: #FF8A80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0.4em 0; }
code { font-size: 0.9em; background: var(--bg); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }

/* shell */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--brand); color: #fff; font-size: 17px;
}
.top img { border-radius: 7px; }
.main { max-width: 720px; margin: 0 auto; padding: 14px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  position: relative; flex: 1; max-width: 200px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); font-weight: 600; }
.badge {
  position: absolute; top: 8px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

.page-title { font-size: 24px; margin: 4px 0 4px; }
.stack > * + * { margin-top: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.card h2 { font-size: 17px; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 0; }
input, textarea, select {
  display: block; width: 100%; margin-top: 5px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.grid2, .grid3 { display: grid; gap: 0 12px; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 11px;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.block { width: 100%; margin-top: 16px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 24px; width: 40px; cursor: pointer; }

/* notices */
.notice {
  display: block; width: 100%; text-align: left; margin-bottom: 10px;
  padding: 11px 14px; border-radius: 12px; border: 0; font: inherit; font-size: 14px;
  background: var(--surface); color: var(--muted);
}
button.notice { cursor: pointer; }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.accent { background: var(--accent); color: #fff; font-weight: 600; }

/* segmented */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; margin: 4px 0 12px; }
.seg button { border: 0; background: none; font: inherit; font-size: 14px; padding: 7px 18px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }

/* leads */
.leads > * + * { margin-top: 12px; }
.lead.hl { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.lead.done { opacity: 0.6; }
.lead-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.lead-head h3 { font-size: 17px; }
.chip { flex: none; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.excerpt { font-size: 14px; background: var(--bg); padding: 10px 12px; border-radius: 10px; margin-top: 10px; white-space: pre-wrap; cursor: pointer; }
.excerpt.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.reply { margin-top: 10px; font-size: 15px; line-height: 1.45; }
.empty { text-align: center; padding: 48px 12px; }
.empty .big { font-size: 19px; font-weight: 600; }

/* setup */
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.step-head h2 { margin: 0; }
.step-num {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--bg); color: var(--muted);
}
.step.complete .step-num { background: var(--ok-bg); color: var(--ok); }
.howto { padding-left: 20px; margin: 8px 0; }
.howto li { margin: 5px 0; }
.codebox { margin-top: 12px; }
.codebox textarea { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; }

/* settings */
.group-row { display: grid; grid-template-columns: 1fr 40px; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.group-row input:first-child { grid-column: 1; }
.group-row input:nth-child(2) { grid-column: 1; margin-top: 0; }
.group-row .icon-btn { grid-column: 2; grid-row: 1 / span 2; }
.groups { margin-bottom: 12px; }
@media (min-width: 560px) {
  .group-row { grid-template-columns: 1fr 2fr 40px; }
  .group-row input:nth-child(2) { grid-column: 2; margin-top: 5px; }
  .group-row .icon-btn { grid-column: 3; grid-row: 1; }
}
.savebar {
  position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px);
  background: transparent;
}
.savebar .btn { box-shadow: 0 6px 20px rgba(0,0,0,0.15); }

/* auth */
.auth { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 32px) 16px 40px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand img { border-radius: 16px; }
.auth-brand h1 { font-size: 26px; margin: 12px 0 6px; }
.auth-brand p { color: var(--muted); }
.auth-form h2 { font-size: 20px; }
.error { color: var(--bad); font-size: 14px; margin-top: 12px; }
.loading { padding: 80px 16px; text-align: center; color: var(--muted); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 20px); opacity: 0; transition: all 0.25s ease;
  background: #151A24; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 20; text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.bad { background: var(--bad); }

/* admin */
.main.wide { max-width: 960px; padding-bottom: 40px; }
.top-link { margin-left: auto; color: #fff; opacity: 0.85; font-size: 14px; text-decoration: none; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 12px; }
.stat { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat strong { font-size: 15px; }
.stat.ok strong { color: var(--ok); }
.stat.warn strong { color: var(--warn); }
.hint { display: block; font-weight: 400; font-size: 12.5px; margin-top: 4px; }
.agent h3, .invite h3 { font-size: 17px; }
.invite h3 { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.05em; }
