/* Cadence. One accent, neutral greys, radius rule: panels 14px, controls 10px, badges full. */
:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --text: #16191d;
  --muted: #5c6670;
  --line: #e2e6ea;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn-soft: #fff4e0;
  --warn: #8a5300;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(22 25 29 / 0.04), 0 4px 16px rgb(22 25 29 / 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1214;
    --surface: #171b1e;
    --surface-2: #1e2327;
    --text: #e8ecef;
    --muted: #9aa5ae;
    --line: #2a3136;
    --accent: #3cc4a4;
    --accent-ink: #062019;
    --accent-soft: #12312a;
    --danger: #ff8a80;
    --danger-soft: #3a1c1a;
    --warn-soft: #3a2c12;
    --warn: #f3c46b;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1214;
  --surface: #171b1e;
  --surface-2: #1e2327;
  --text: #e8ecef;
  --muted: #9aa5ae;
  --line: #2a3136;
  --accent: #3cc4a4;
  --accent-ink: #062019;
  --accent-soft: #12312a;
  --danger: #ff8a80;
  --danger-soft: #3a1c1a;
  --warn-soft: #3a2c12;
  --warn: #f3c46b;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 620; }
p { margin: 0; }
.muted { color: var(--muted); }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Layout */
.main { max-width: 1080px; margin: 0 auto; padding: 32px 20px 120px; }
.with-nav { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.with-nav .main { width: 100%; }
.bare .main { display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px; }

.nav {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 24px;
  padding: 24px 14px; border-right: 1px solid var(--line); background: var(--surface);
}
.nav .brand { font-weight: 700; font-size: 1.05rem; color: var(--text); padding: 0 10px; }
.nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav li a {
  display: block; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); transition: background 160ms var(--ease), color 160ms var(--ease);
}
.nav li a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav li a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-foot { margin-top: auto; display: grid; gap: 6px; }
.nav-foot form { margin: 0; }

@media (max-width: 767px) {
  .with-nav { display: block; }
  .nav {
    position: fixed; inset: auto 0 0 0; height: auto; z-index: 10;
    flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
  }
  .nav .brand, .nav-foot { display: none; }
  .nav ul { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .nav li a { text-align: center; font-size: 0.75rem; padding: 8px 2px; }
  .main { padding: 20px 16px 96px; }
}

/* Page structure */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.section { margin-top: 32px; }
.section > h2 { margin-bottom: 12px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 767px) { .grid-2 { grid-template-columns: 1fr; } }

/* Stats */
.stats { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }
.stat { display: grid; gap: 6px; }
.stat .value { font-size: 2rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .label { color: var(--muted); font-size: 0.85rem; }
.meter { appearance: none; width: 100%; height: 6px; border: 0; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
.meter::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.meter::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
nav.row a { color: var(--muted); padding: 4px 10px; border-radius: 999px; }
nav.row a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
details summary { cursor: pointer; color: var(--muted); }
@media (max-width: 767px) { .stats { grid-template-columns: 1fr 1fr; } .stats .stat:first-child { grid-column: 1 / -1; } }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 14px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .line { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.list a.item { color: inherit; display: block; }
.list a.item:hover { text-decoration: none; }
.list a.item:hover .title { color: var(--accent); }
.title { font-weight: 600; }
.excerpt { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread .title::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 8px; border-radius: 50%; background: var(--accent); vertical-align: middle; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem;
  font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok, .badge.sent, .badge.running, .badge.working, .badge.replied { background: var(--accent-soft); color: var(--accent); }
.badge.failed, .badge.unknown, .badge.stopped { background: var(--danger-soft); color: var(--danger); }
.badge.paused, .badge.scan_qr, .badge.no_whatsapp, .badge.excluded { background: var(--warn-soft); color: var(--warn); }

/* Forms */
.field { display: grid; gap: 6px; }
.field > span { font-size: 0.85rem; font-weight: 600; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; width: 100%;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="file"] { padding: 8px; }
small { font-size: 0.8rem; }

button, .button {
  font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  transition: background 160ms var(--ease), transform 120ms var(--ease), border-color 160ms var(--ease);
  white-space: nowrap; text-decoration: none;
}
button:hover, .button:hover { border-color: var(--muted); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover, .button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.small, .button.small { padding: 6px 10px; font-size: 0.85rem; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }

.alert { margin: 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); list-style: none; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent); }
.warn { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); }

/* Auth */
.auth { width: 100%; max-width: 380px; display: grid; gap: 20px; }
.auth h1 { font-size: 1.4rem; }

/* Empty states */
.empty { display: grid; gap: 12px; justify-items: start; padding: 32px 0; color: var(--muted); }

/* Conversation */
.thread { display: grid; gap: 10px; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.out { justify-self: end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.bubble.in { justify-self: start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble time { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

.preview { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--accent-soft); border-radius: 16px; border-bottom-right-radius: 4px; padding: 10px 14px; min-height: 44px; }
.qr { width: 264px; max-width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); background: #fff; padding: 8px; }

.htmx-request { opacity: 0.6; transition: opacity 160ms var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Filters */
.filters { align-items: end; }
.filters .field { flex: 1 1 160px; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 0.9rem; padding-bottom: 10px; }
.check input { width: auto; }
