/* CDL — operator UI stylesheet. ~280 lines, no framework. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-fg: #ffffff;
  --success: #047857;
  --success-bg: #d1fae5;
  --success-border: #6ee7b7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --danger-hover: #991b1b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2c;
    --surface-2: #182236;
    --text: #e2e8f0;
    --text-soft: #cbd5e1;
    --muted: #94a3b8;
    --border: #1f2a44;
    --border-strong: #334155;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --success: #34d399;
    --success-bg: #064e3b;
    --success-border: #047857;
    --warn: #fbbf24;
    --warn-bg: #422006;
    --danger: #f87171;
    --danger-bg: #450a0a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue",
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

h1 { font-size: 1.6rem; margin: 0 0 18px; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; margin: 28px 0 12px; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; margin: 0 0 10px; }

p { margin: 8px 0; }

.muted { color: var(--muted); font-size: 0.9em; }
.empty {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  color: var(--muted);
}

/* ---------- header / nav ---------- */

header.app {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

header.app .brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  font-size: 1rem;
}

header.app nav {
  display: flex;
  gap: 18px;
  margin-left: auto;
  align-items: center;
}

header.app nav a {
  color: var(--text-soft);
  font-size: 0.92rem;
  padding: 6px 4px;
  border-bottom: 2px solid transparent;
}
header.app nav a:hover {
  color: var(--accent);
  text-decoration: none;
  border-bottom-color: var(--accent);
}

main {
  max-width: 960px;
  margin: 28px auto;
  padding: 0 28px 64px;
}

/* ---------- buttons ---------- */

button, .btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  transition: background 80ms ease, border-color 80ms ease, transform 80ms ease;
}
button:hover, .btn:hover {
  background: var(--surface-2);
  border-color: var(--text-soft);
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.btn-link {
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 6px 4px;
  font-size: 0.92rem;
}
button.btn-link:hover {
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
}

button[type="submit"]:not(.btn-reject):not(.btn-link):not(.btn-approve) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}
button[type="submit"]:not(.btn-reject):not(.btn-link):not(.btn-approve):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-fg);
}

.btn-approve {
  flex: 1;
  background: var(--success);
  border-color: var(--success);
  color: white;
  font-weight: 600;
  padding: 12px 16px;
  font-size: 0.95rem;
}
.btn-approve:hover { background: #065f46; border-color: #065f46; color: white; }

.btn-reject {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--danger);
  font-weight: 500;
  padding: 12px 16px;
  font-size: 0.95rem;
}
.btn-reject:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger-hover);
}

/* ---------- tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 0.92rem;
}
th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-soft);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

input[type="text"], input[type="password"] {
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-width: 220px;
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

label { display: inline-flex; flex-direction: column; gap: 6px; margin-right: 12px; }

/* ---------- approval cards ---------- */

article.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 22px 24px;
  margin-bottom: 18px;
}
article.card h3 {
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

article.card .stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px 22px;
  margin-bottom: 18px;
}
article.card .stats .label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 3px;
}
article.card .stats .value {
  font-size: 1rem;
  color: var(--text);
  font-weight: 500;
}
article.card .stats .value.score-good { color: var(--success); }
article.card .stats .value.score-warn { color: var(--warn); }
article.card .stats .value .sparkline {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  color: var(--accent);
  opacity: 0.85;
}
article.card .threshold-note {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: -8px;
  margin-bottom: 14px;
  cursor: help;
}

article.card .copy-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  margin-bottom: 18px;
  line-height: 1.5;
}
article.card .copy-preview-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

article.card .confirm {
  margin: 4px 0 14px;
  font-size: 0.95rem;
  color: var(--text-soft);
}

article.card .actions {
  display: flex;
  gap: 12px;
}

.status-msg {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.status-approved {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}
.status-rejected {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* ---------- vendor-approval gate ---------- */

.vendor-approval-warn {
  margin: 12px 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--warning-bg, #fff8e1);
  color: var(--warning, #7a4f00);
  border: 1px solid var(--warning-border, #f0c14b);
  font-size: 0.92rem;
}
.vendor-approval-warn p {
  margin: 0 0 6px;
}
.vendor-approval-warn p:last-of-type {
  margin-bottom: 0;
}
.vendor-approval-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-weight: 500;
  cursor: pointer;
}
.btn-approve:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- LLM policy-risk surface ---------- */

.policy-risks {
  margin: 12px 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--warning-bg, #fff8e1);
  color: var(--warning, #7a4f00);
  border: 1px solid var(--warning-border, #f0c14b);
  font-size: 0.92rem;
}
.policy-risks p {
  margin: 0 0 6px;
}
.policy-risks p:last-of-type {
  margin-bottom: 0;
}
.policy-risks ul {
  margin: 6px 0 8px;
  padding-left: 20px;
}
.policy-risks li {
  margin-bottom: 4px;
}
.razao {
  margin: 8px 0 6px;
  font-size: 0.9rem;
  line-height: 1.4;
}

/* ---------- tier badge (P1 / P2 / DROPPED) ---------- */

.tier-badge {
  display: inline-block;
  padding: 2px 8px;
  margin-left: 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: middle;
  cursor: help;
}
.tier-p1 {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}
.tier-p2 {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.tier-dropped {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-style: italic;
}

/* ---------- keyword chips (operator-spec match types) ---------- */

.keywords-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 12px;
}
.keyword-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.85rem;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
  color: var(--text);
}
.keyword-chip[data-match="EXACT"] {
  border-color: var(--success-border);
  color: var(--success);
}
.keyword-chip[data-match="PHRASE"] {
  border-color: var(--accent, var(--success-border));
}

/* ---------- dashboard funnel (per-active-campanha) ---------- */

.funnel-list {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  margin-top: 8px;
}
.funnel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 12px);
  padding: 16px 18px;
}
.funnel-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}
.funnel-card-head h3 {
  margin: 0;
  font-size: 1.05rem;
}
.funnel-card-meta {
  font-size: 0.8rem;
  color: var(--muted);
}
.funnel-stages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.funnel-stage {
  display: grid;
  grid-template-columns: 90px 60px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}
.funnel-label {
  color: var(--text-soft);
  font-weight: 500;
}
.funnel-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
}
.funnel-bar {
  display: block;
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.funnel-bar-fill {
  display: block;
  height: 100%;
  background: var(--success);
  transition: width 200ms ease;
}
.funnel-bar-clicks { background: var(--success); }
.funnel-bar-ok    { background: var(--success); }
.funnel-bar-warn  { background: var(--warn); }
.funnel-bar-bad   { background: var(--danger); }
.funnel-pct {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.funnel-pct-ok    { color: var(--success); }
.funnel-pct-warn  { color: var(--warn); }
.funnel-pct-bad   { color: var(--danger); }

.funnel-spend {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 0.82rem;
}
.funnel-spend-label { color: var(--text-soft); margin-bottom: 4px; }
.funnel-spend-bar {
  height: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.funnel-spend-fill {
  display: block;
  height: 100%;
  background: var(--success);
  transition: width 200ms ease;
}
.funnel-spend-strict { background: var(--warn); }
.funnel-spend-relaxed { background: var(--success); }
.funnel-spend-hardstop {
  margin-top: 4px;
  font-size: 0.74rem;
}

/* ---------- dashboard / contas ---------- */

.revenue {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--success);
  background: var(--surface);
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: inline-block;
}

.roi-good { color: var(--success); font-weight: 600; }
.roi-warn { color: var(--warn); font-weight: 600; }
.roi-bad { color: var(--danger); font-weight: 600; }

/* ---------- login ---------- */

.login-card {
  max-width: 360px;
  margin: 80px auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { margin-top: 0; }
.login-card label { display: block; margin-bottom: 16px; width: 100%; }
.login-card input[type="password"] { width: 100%; min-width: 0; }
.login-card button { width: 100%; }
.login-card .error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.9rem;
}

/* ---------- card title link ---------- */

article.card h3 a.card-title-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
article.card h3 a.card-title-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
  text-decoration: none;
}

/* ---------- detail modal (htmx-loaded) ---------- */

.cdl-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 20px;
  overflow-y: auto;
}

.cdl-modal {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 760px;
  width: 100%;
  margin: auto;
}

.cdl-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 1;
}
.cdl-modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}
.cdl-modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.cdl-modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: transparent;
}

.cdl-modal-body {
  padding: 18px 22px 24px;
}

.cdl-detail-block {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.cdl-detail-block:last-child { border-bottom: none; }
.cdl-detail-block h3 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.cdl-detail-block h4.cdl-copy-subhead {
  margin: 14px 0 6px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.cdl-chart {
  width: 100%;
  height: auto;
  max-height: 220px;
  color: var(--accent);
  display: block;
}
.cdl-chart-bars rect:hover { fill-opacity: 1; }
.cdl-chart-line circle:hover { r: 3; }

.cdl-reasoning {
  margin: 0;
  padding: 12px 16px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-style: italic;
  line-height: 1.55;
}

ul.cdl-copy-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
ul.cdl-copy-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
ul.cdl-copy-list li:last-child { border-bottom: none; }
ul.cdl-copy-list .copy-line { flex: 1; }
ul.cdl-copy-list .copy-meta { font-size: 0.8rem; white-space: nowrap; }

@media (max-width: 640px) {
  .cdl-modal { max-width: 100%; }
  .cdl-modal-backdrop { padding: 8px; }
  .cdl-modal-head { padding: 14px 16px 10px; }
  .cdl-modal-body { padding: 14px 16px 20px; }
}

/* ---------- ops toolbar (manual task triggers) ---------- */

.ops-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 16px 0 24px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
}
.ops-toolbar-label { font-size: 0.85rem; color: var(--muted, #6b7280); }
.ops-toolbar button {
  padding: 6px 12px;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  cursor: pointer;
}
.ops-toolbar button:hover { background: #f3f4f6; }

.flash {
  margin: 12px 0 16px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
}
.flash-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ---------- alerts panel ---------- */

.alerts-panel {
  margin: 16px 0 24px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.alerts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #f3f4f6;
}
.alerts-head h2 {
  margin: 0;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.alerts-badge {
  display: inline-block;
  min-width: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}
.alerts-filter { display: flex; gap: 4px; }
.alerts-filter-tab {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: #6b7280;
  text-decoration: none;
  cursor: pointer;
}
.alerts-filter-tab:hover { background: #f3f4f6; }
.alerts-filter-tab.is-active { background: #111827; color: #fff; }

.alerts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 420px;
  overflow-y: auto;
}
.alert {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 12px 16px;
  border-top: 1px solid #f3f4f6;
}
.alert:first-child { border-top: 0; }
.alert.is-unread { background: #f9fafb; }
.alert.is-read { opacity: 0.65; }
.alert-icon {
  font-size: 1rem;
  line-height: 1.2;
  text-align: center;
}
.alert-row {
  display: flex;
  gap: 10px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.alert-kind { color: #4b5563; font-weight: 600; }
.alert-time { color: #9ca3af; }
.alert-title { font-weight: 500; margin-top: 2px; }
.alert-text { font-size: 0.85rem; margin-top: 4px; line-height: 1.4; }
.alert-actions { display: flex; align-items: start; }
.alert-actions .btn-link {
  background: transparent;
  border: 0;
  color: #2563eb;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 6px;
}
.alert-actions .btn-link:hover { text-decoration: underline; }

.alert-sev-info .alert-icon { color: #2563eb; }
.alert-sev-warn { border-left: 3px solid #f59e0b; }
.alert-sev-warn .alert-icon { color: #f59e0b; }
.alert-sev-error { border-left: 3px solid #dc2626; }
.alert-sev-error .alert-icon { color: #dc2626; }

/* ---------- network-health banner ---------- */

.health-banner {
  margin-bottom: 24px;
  border: 1px solid #fca5a5;
  background: #fee2e2;
  border-radius: 8px;
  padding: 12px 16px;
}
.health-banner-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.health-banner-row + .health-banner-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #fecaca;
}
.health-banner-icon {
  font-size: 20px;
  color: #dc2626;
}
.health-banner-text { flex: 1; }
.health-banner-text strong { color: #7f1d1d; }

/* refresh page form */
.refresh-form { display: flex; flex-direction: column; gap: 18px; max-width: 920px; }
.refresh-form label { display: block; font-weight: 600; margin-bottom: 4px; }
.refresh-form .help { font-size: 13px; color: #6b7280; margin-bottom: 6px; }
.refresh-form textarea {
  width: 100%;
  min-height: 140px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}
.refresh-form .err {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 12px;
  border-radius: 6px;
}
.refresh-form .ok {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 10px 12px;
  border-radius: 6px;
}

/* ---------- /ui/trends ---------- */

.trends-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}
.trend-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}
.trend-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 10px;
}
.trend-card-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.trend-card-title h3 { margin: 0; font-size: 1.05rem; }
.trend-rank {
  display: inline-block;
  min-width: 28px;
  text-align: center;
  background: var(--surface-2);
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}
.trend-gt {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
}
.trend-card-meta { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.78rem; }
.trend-stats {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px 16px;
}
.trend-stats li { display: flex; flex-direction: column; gap: 2px; }
.trend-stat-label { font-size: 0.78rem; }
.trend-stat-value { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.trend-layer-chip {
  display: inline-block;
  font-size: 0.75rem;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-soft);
  margin-right: 4px;
}
.trend-layer-l1 { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.trend-layer-l2 { background: #ecfeff; color: #155e75; border-color: #a5f3fc; }
.trend-layer-l3 { background: #fdf4ff; color: #86198f; border-color: #f5d0fe; }
.trend-layer-l4 { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.trend-layer-l5 { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
@media (prefers-color-scheme: dark) {
  .trend-layer-l1 { background: #1e1b4b; color: #c7d2fe; border-color: #3730a3; }
  .trend-layer-l2 { background: #083344; color: #a5f3fc; border-color: #155e75; }
  .trend-layer-l3 { background: #4a044e; color: #f5d0fe; border-color: #86198f; }
  .trend-layer-l4 { background: #431407; color: #fed7aa; border-color: #9a3412; }
  .trend-layer-l5 { background: #064e3b; color: #a7f3d0; border-color: #047857; }
}
.trend-signals > summary {
  cursor: pointer;
  padding: 6px 0;
  font-size: 0.92rem;
}
.trend-signals[open] > summary { margin-bottom: 8px; }
.trend-signals-table { width: 100%; font-size: 0.88rem; }
.trend-signals-table th,
.trend-signals-table td { padding: 6px 8px; vertical-align: top; }
.trend-payload {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  max-height: 260px;
  overflow: auto;
  font-size: 0.8rem;
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- mobile ---------- */

@media (max-width: 640px) {
  header.app { padding: 12px 16px; gap: 16px; flex-wrap: wrap; }
  header.app nav { gap: 12px; margin-left: 0; width: 100%; }
  main { padding: 0 16px 48px; margin-top: 16px; }
  article.card { padding: 18px 16px; }
  article.card .actions { flex-direction: column; }
}
