/* Design tokens */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #15202b;
  --text-2: #5b6878;
  --border: #e3e8ee;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --good: #15803d;
  --good-soft: #e6f6ec;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fff4e5;
  --info: #0e7490;
  --info-soft: #e3f6fa;
  --muted-soft: #eef1f4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --sidebar: 240px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2330;
    --text: #e6edf3;
    --text-2: #9aa7b6;
    --border: #2a3340;
    --accent: #5b9bff;
    --accent-soft: #15223a;
    --good: #3fb950;
    --good-soft: #12261a;
    --bad: #f87171;
    --bad-soft: #2d1515;
    --warn: #f0b24a;
    --warn-soft: #2b2110;
    --info: #4cc2d9;
    --info-soft: #0f2a30;
    --muted-soft: #1f2733;
    --shadow: none;
  }
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--bg);
}
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: 0.85rem; margin: 0 0 6px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-2); }
.small { font-size: 0.85rem; }
.block { display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.right { margin-left: auto; }
.truncate { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad { padding: 16px 20px; }

/* Shell */
body.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 20px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; flex: none; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.nav a[href$="/admin/connect"] svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 16px; border-top: 1px solid var(--border); }
.sidebar-foot .button.small { padding: 6px 10px; font-size: 0.85rem; }
.sidebar-foot .button.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.who { display: flex; flex-direction: column; font-size: 0.9rem; }
.content { padding: 28px 32px 56px; max-width: 1180px; width: 100%; }
.content.narrow { max-width: 760px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; max-width: 60ch; }
.crumbs { color: var(--text-2); font-size: 0.9rem; margin-bottom: 6px; }

/* Buttons and forms */
button, .button, input, textarea, select { font: inherit; }
button, .button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; font-weight: 500; line-height: 1.2;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover, button.primary:hover { filter: brightness(1.05); background: var(--accent); }
.ghost, button.ghost { background: transparent; }
button.small { padding: 6px 10px; font-size: 0.85rem; }
.block.primary, button.block { width: 100%; justify-content: center; }
.form label, .stack label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form label > span:first-child, .stack label > span { font-weight: 500; }
input, textarea, select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit input { max-width: 140px; }
.with-unit span { color: var(--text-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form .panel { margin-bottom: 16px; }
.form .panel h2 { margin-bottom: 12px; }
.error { color: var(--bad); }
.error:empty { display: none; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.actions form { display: inline; }

/* Alerts and flash */
.alert, .flash { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid transparent; }
.alert.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.alert.good, .flash { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 30%, transparent); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.stat-label { color: var(--text-2); font-size: 0.85rem; font-weight: 500; }
.stat-value { font-size: 1.9rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.stat-note { color: var(--text-2); font-size: 0.85rem; }
.stat.accent { border-color: var(--accent); }
.stat.accent .stat-value { color: var(--accent); }
.stat.attention { border-color: var(--warn); background: var(--warn-soft); }
.stat.problem .stat-value { color: var(--bad); }

.funnel { margin-bottom: 24px; }
.funnel-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--muted-soft); margin-bottom: 8px; }
.seg { display: block; min-width: 0; }
.seg.sent { background: var(--accent); }
.seg.waiting { background: color-mix(in srgb, var(--accent) 40%, transparent); }
.seg.other { background: transparent; }

/* Panels, tables, lists */
.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--text-2); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); }
.table tr:last-child td { border-bottom: none; }
.table.rows-link tbody tr:hover { background: var(--surface-2); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 20px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.list li:last-child { border-bottom: none; }

/* Pills */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  background: var(--muted-soft); color: var(--text-2); text-transform: capitalize; white-space: nowrap;
}
.pill.s-scheduled { background: var(--accent-soft); color: var(--accent); }
.pill.s-sent, .pill.s-follow_up_sent, .pill.s-delivered, .pill.s-received { background: var(--info-soft); color: var(--info); }
.pill.s-clicked { background: var(--good-soft); color: var(--good); }
.pill.s-failed, .pill.s-expired { background: var(--bad-soft); color: var(--bad); }
.pill.s-pending { background: var(--warn-soft); color: var(--warn); }
.pill.c-positive, .pill.c-new_booking { background: var(--good-soft); color: var(--good); }
.pill.c-complaint { background: var(--bad-soft); color: var(--bad); }
.pill.c-question { background: var(--warn-soft); color: var(--warn); }
.pill.c-stop { background: var(--muted-soft); color: var(--text-2); }

/* Cards */
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.quote { margin: 0; padding: 10px 14px; border-left: 3px solid var(--border); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; white-space: pre-wrap; word-break: break-word; }
.draft-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.draft-body { margin: 0; padding: 12px 14px; background: var(--accent-soft); border-radius: var(--radius-sm); white-space: pre-wrap; font: inherit; }

/* Timeline and messages */
.timeline { list-style: none; margin: 0; padding: 16px 20px; }
.timeline li { display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding-bottom: 16px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 14px; bottom: -2px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--muted-soft); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border); margin-top: 3px; }
.timeline li.good .dot { background: var(--good); }
.timeline li.bad .dot { background: var(--bad); }
.timeline li.info .dot { background: var(--info); }
.timeline li div { display: flex; flex-direction: column; }
.timeline time { color: var(--text-2); font-size: 0.85rem; }
.messages { list-style: none; margin: 0; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.messages li { max-width: 92%; }
.messages li.out { align-self: flex-end; }
.messages li.in { align-self: flex-start; }
.msg-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-2); margin-bottom: 4px; }
.msg-body { margin: 0; padding: 10px 14px; border-radius: 14px; background: var(--surface-2); white-space: pre-wrap; word-break: break-word; }
.messages li.out .msg-body { background: var(--accent-soft); border-bottom-right-radius: 4px; }
.messages li.in .msg-body { border-bottom-left-radius: 4px; }

/* Empty states */
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 36px 28px; text-align: center; max-width: 620px; margin: 24px auto; }
.empty h2 { margin-bottom: 8px; }
.empty p { color: var(--text-2); }

/* Auth */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 24px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .muted { margin-bottom: 20px; }

/* Responsive */
@media (max-width: 900px) {
  .two-col, .draft-grid, .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 20px 16px 48px; }
}
@media (max-width: 760px) {
  body.shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 12px 16px; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav a { padding: 6px 10px; font-size: 0.9rem; }
  .nav svg { display: none; }
  .sidebar-foot { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; border-top: none; padding-top: 0; gap: 12px; }
  .who strong { display: none; }
  .hide-sm { display: none; }
  .stat-value { font-size: 1.5rem; }
  .messages li { max-width: 100%; }
}

/* Sign-up */
.auth-card.wide { max-width: 640px; }
.plans { border: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.plans legend { font-weight: 500; margin-bottom: 8px; }
.plan { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; margin: 0; }
.plan:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.plan input { width: auto; margin: 4px 0 0; }
.plan-body { display: flex; flex-direction: column; gap: 2px; }
.plan-name { font-weight: 600; }
.plan-price { color: var(--accent); font-weight: 600; }
.check { display: flex !important; flex-direction: row !important; gap: 10px; align-items: flex-start; }
.check input { width: auto; margin: 4px 0 0; }
.center { text-align: center; }

/* Key-value lists (settings billing panel) */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0 0 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
.billing { margin-top: 24px; }

/* Report cards */
.stats.compact { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin-bottom: 12px; }
.stats.compact .stat { padding: 10px 12px; }
.stats.compact .stat-value { font-size: 1.4rem; }
.card.report .card-head h2 { margin-right: 8px; }
.themes { margin-top: 8px; }

/* Activity chart */
.chart-panel { margin-bottom: 20px; }
.legend { color: var(--text-2); font-size: 0.85rem; display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 8px; }
.swatch.sent { background: var(--accent); }
.swatch.opened { background: var(--good); }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 16px 20px 0; }
.chart .col { flex: 1; display: flex; align-items: flex-end; gap: 2px; height: 100%; border-left: 1px solid transparent; }
.chart .col.week { border-left-color: var(--border); }
.chart .bar { flex: 1; min-height: 2px; border-radius: 3px 3px 0 0; background: var(--muted-soft); }
.chart .bar.sent { background: var(--accent); }
.chart .bar.opened { background: var(--good); }
.chart-axis { display: flex; justify-content: space-between; padding: 6px 20px 12px; color: var(--text-2); font-size: 0.8rem; }

/* Calendar panel */
.calendar { margin-top: 24px; }
.calendar .preview { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.calendar .stack label { margin-bottom: 10px; }

/* Team and password panels */
.team { margin-top: 24px; }
#password { margin-top: 24px; }
.team .table { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.team td.actions { display: flex; gap: 6px; }

/* Message preview */
.preview-panel { margin-bottom: 16px; }
.panel-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toggle-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 5px 12px; border-radius: 999px; font-size: 0.85rem; color: var(--text-2); }
.seg button.on { background: var(--accent); color: #fff; }
.preview-target { min-height: 80px; }
.phone { max-width: 360px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 18px; padding: 14px; }
.phone.is-email { max-width: 560px; border-radius: var(--radius); }
.phone-head { border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 8px; font-size: 0.95rem; }
.bubble-out { margin: 0; background: var(--accent-soft); border-radius: 16px 16px 4px 16px; padding: 10px 14px; white-space: pre-wrap; word-break: break-word; font-size: 0.95rem; }
.preview-meta { margin-top: 8px; }
.code { margin: 0 0 10px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; white-space: pre-wrap; word-break: break-all; }
.routes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.route h2 { margin: 8px 0 6px; }
.route .button { margin-top: 8px; }
.newkey { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 14px; }
.newkey strong { display: block; margin-bottom: 8px; }
.plain { padding-left: 18px; margin: 0; }
.rules-panel { margin-top: 14px; }
@media (max-width: 900px) { .routes { grid-template-columns: 1fr; } }

.emailin { margin-top: 24px; }

#activity { margin-top: 24px; }

.legal-links { margin: 0; }
.legal-links a { color: var(--text-2); }
