:root {
  --bg: #f4f7fb;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #172033;
  --muted: #64748b;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok: #138a4b;
  --ok-bg: #e6f6ec;
  --warning: #92620a;
  --warning-bg: #fff4d9;
  --critical: #b91c1c;
  --critical-bg: #fde8e8;
  --unknown: #64748b;
  --unknown-bg: #eef1f5;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--brand); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* --- baseline form field styling ---
   Low-specificity default so every bare <input>/<select>/<textarea> in the
   app gets a themed look even on pages with no dedicated form styles (e.g.
   a lone <select> or a <textarea> inside a .settings-form, which only
   styles input/select - see below). More specific component rules
   (.add-key-form input, .chat-form input, .settings-form input, etc.)
   still win for their own layout tweaks since they're more specific. */
input[type="text"], input[type="url"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], input[type="date"], input[type="tel"],
select, textarea {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
}
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); }

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

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 8px 30px #1720331a;
  text-align: center;
}

.login-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.login-card .dot { color: var(--brand); }
.login-card .sub { margin: 0 0 1.5rem; color: var(--muted); }
.login-card form { display: flex; flex-direction: column; gap: 1rem; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; font-weight: 600; }
.login-card input {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.login-card .error { color: var(--critical); font-size: 0.9rem; }

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

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: #eef2f7; }

/* --- top bar --- */

.topbar { background: var(--card-bg); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.9rem 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { font-weight: 800; font-size: 1.1rem; }
.brand .dot { color: var(--brand); }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.sidebar-toggle-btn {
  display: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 1rem;
  cursor: pointer;
}

/* --- app body / sidebar --- */

.app-body {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 0;
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.sidebar {
  width: 230px;
  flex: 0 0 230px;
  position: sticky;
  top: 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.side-nav { display: flex; flex-direction: column; gap: 0.15rem; }

.side-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  border-left: 3px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}
.side-link:hover { background: var(--bg); }
.side-link.active { background: var(--ok-bg); color: var(--brand); border-left-color: var(--brand); }

.side-group-toggle .side-caret { transition: transform 0.15s ease; font-size: 0.7rem; color: var(--muted); }
.side-group-open > .side-group-toggle .side-caret { transform: rotate(180deg); }

.side-submenu {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}
.side-group-open .side-submenu { max-height: 400px; }

.side-sublink {
  display: block;
  padding: 0.5rem 0.7rem 0.5rem 1.6rem;
  margin-top: 0.1rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.87rem;
  border-left: 3px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}
.side-sublink:hover { background: var(--bg); color: var(--text); }
.side-sublink.active { background: var(--ok-bg); color: var(--brand); font-weight: 600; border-left-color: var(--brand); }

.sidebar hr.side-sep { border: none; border-top: 1px solid var(--border); margin: 0.5rem 0.4rem; }

@media (max-width: 800px) {
  .sidebar-toggle-btn { display: inline-block; }
  .app-body { flex-direction: column; padding: 16px 16px 0; }
  .sidebar {
    width: 100%;
    flex: 1 1 auto;
    position: static;
    display: none;
  }
  .sidebar.sidebar-open { display: block; }
}

/* --- layout --- */

.wrap {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 auto;
  padding: 0 0 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
@media (max-width: 700px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

.tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
.tile-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.4rem; }
.tile-value { font-size: 1.6rem; font-weight: 700; display: inline-block; padding: 0.1rem 0.5rem; border-radius: 8px; }
.tile-value-plain { background: none; padding: 0; font-size: 1.2rem; }
.tile-sub { margin-top: 0.3rem; font-size: 0.8rem; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 800px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 0.75rem; flex-wrap: wrap; }
.card h2 { margin: 0; font-size: 1.05rem; }

.schedule-row { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: center; margin-bottom: 0.75rem; }
.schedule-row label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; }
.schedule-row select { padding: 0.4rem 0.6rem; border-radius: 8px; border: 1px solid var(--border); font-size: 0.9rem; }
.switch-label { flex-direction: row !important; align-items: center; gap: 0.5rem !important; font-weight: 500 !important; }

/* --- badges --- */

.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-critical { background: var(--critical-bg); color: var(--critical); }
.badge-unknown { background: var(--unknown-bg); color: var(--unknown); }

/* --- reports --- */

.reports-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; max-height: 420px; overflow-y: auto; }
.reports-list summary { cursor: pointer; display: flex; gap: 0.6rem; align-items: center; padding: 0.4rem 0; }
.report-time { font-size: 0.85rem; }
.report-body {
  white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.8rem;
  background: #f8fafc;
  border-radius: 8px;
  padding: 0.75rem;
  max-height: 300px;
  overflow-y: auto;
}

/* --- claude account / key vault --- */

.key-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.key-info { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.key-masked { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.8rem; color: var(--muted); }
.key-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.key-row-disabled { opacity: 0.6; }
.provider-badge { text-transform: uppercase; letter-spacing: 0.02em; font-size: 0.7rem; }
.add-key-form { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.add-key-form input, .add-key-form select {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  background: var(--card-bg);
  color: var(--text);
}
.add-key-form select { flex: 0 0 auto; }
.add-key-form input[type="text"] { flex: 1; min-width: 140px; }
.add-key-form input[type="password"] { flex: 2; min-width: 200px; }

/* --- coming soon --- */

.coming-soon-list { margin: 0.75rem 0 0; padding-left: 1.25rem; color: var(--muted); font-size: 0.9rem; display: flex; flex-direction: column; gap: 0.35rem; }

/* --- content automation --- */

.settings-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; align-items: end; }
.settings-form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; font-weight: 600; }
.settings-form textarea { grid-column: 1 / -1; width: 100%; }
.settings-form input, .settings-form select, .settings-form textarea {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  background: var(--card-bg);
  color: var(--text);
}
.settings-form .switch-label { flex-direction: row; align-items: center; gap: 0.5rem; }
.settings-actions { grid-column: 1 / -1; display: flex; gap: 0.6rem; }

.keyword-textarea {
  width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--card-bg);
  color: var(--text);
  resize: vertical;
}

.jobs-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; max-height: 480px; overflow-y: auto; }
.job-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.job-main { display: flex; align-items: flex-start; gap: 0.6rem; min-width: 0; }
.job-text { min-width: 0; }
.job-keyword { font-weight: 600; font-size: 0.92rem; word-break: break-word; }
.job-sub { margin-top: 0.15rem; word-break: break-word; }
.job-error { color: var(--critical); }
.job-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; flex: 0 0 auto; }

/* --- chat --- */

.chat-log {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  padding-right: 4px;
}
.chat-msg { padding: 0.5rem 0.75rem; border-radius: 10px; font-size: 0.9rem; max-width: 85%; white-space: pre-wrap; }
.chat-user { align-self: flex-end; background: var(--brand); color: white; }
.chat-assistant { align-self: flex-start; background: #f1f5f9; }
.chat-form { display: flex; gap: 0.5rem; }
.chat-form input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

/* ================================================================
   Settings & Integrations control center — component system
   ================================================================ */

/* --- AI Copilot nav highlight --- */
.side-link-copilot { background: linear-gradient(90deg, #7c3aed14, transparent); color: #7c3aed; font-weight: 700; }
.side-link-copilot:hover { background: linear-gradient(90deg, #7c3aed22, transparent); }
.side-copilot-dot { width: 8px; height: 8px; border-radius: 50%; background: #7c3aed; box-shadow: 0 0 0 3px #7c3aed22; }

/* --- Settings shell: secondary sidebar + breadcrumb --- */
.settings-sidebar { display: flex; flex-direction: column; gap: 0.5rem; }
.settings-back-link { font-size: 0.82rem; color: var(--muted); text-decoration: none; padding: 0.3rem 0.5rem; }
.settings-back-link:hover { color: var(--text); }
.settings-sidebar-title { font-weight: 800; font-size: 1rem; padding: 0 0.5rem 0.4rem; }

.settings-breadcrumb { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.settings-breadcrumb a { text-decoration: none; }
.settings-breadcrumb .crumb-sep { color: var(--border); }
.settings-breadcrumb .crumb-current { color: var(--text); font-weight: 600; }
.settings-wrap { padding-bottom: 100px; }

/* --- Settings Overview stat cards --- */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
@media (max-width: 1000px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 620px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; }
.stat-card .stat-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 0.2rem; }

.health-summary-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.health-summary-list li { display: flex; align-items: center; gap: 0.6rem; font-size: 0.92rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.health-summary-list li:last-child { border-bottom: none; }
.health-ok { color: var(--ok); font-weight: 700; }
.health-warn { color: var(--warning); font-weight: 700; }

/* --- status pills / dots --- */
.status-pill { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--unknown); }
.status-connected .status-dot { background: var(--ok); }
.status-connected { color: var(--ok); }
.status-syncing .status-dot { background: var(--brand); animation: pulse-dot 1.2s infinite; }
.status-syncing { color: var(--brand); }
.status-warning .status-dot { background: var(--warning); }
.status-warning { color: var(--warning); }
.status-expired .status-dot { background: var(--warning); }
.status-expired { color: var(--warning); }
.status-error .status-dot { background: var(--critical); }
.status-error { color: var(--critical); }
.status-disconnected .status-dot { background: var(--unknown); }
.status-disconnected { color: var(--muted); }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* --- integration card grid --- */
.integration-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.integration-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.integration-card-head { display: flex; align-items: center; gap: 0.6rem; }
.integration-logo { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 9px; background: var(--bg); border: 1px solid var(--border); display: grid; place-items: center; font-weight: 800; color: var(--brand); }
.integration-name { font-weight: 700; font-size: 0.95rem; }
.integration-meta { margin: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.integration-meta > div { display: flex; justify-content: space-between; font-size: 0.82rem; }
.integration-meta dt { color: var(--muted); margin: 0; font-weight: 400; }
.integration-meta dd { margin: 0; font-weight: 600; }
.integration-manage-btn { text-align: center; }

/* --- secrets --- */
.secret-mask { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.05em; color: var(--muted); background: var(--bg); padding: 0.15rem 0.5rem; border-radius: 6px; }

/* --- toggle switches --- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; font-size: 0.9rem; font-weight: 600; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle { position: relative; display: inline-block; width: 40px; height: 24px; flex: 0 0 40px; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background 0.15s ease; cursor: pointer; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 1px 3px #0003; transition: transform 0.15s ease; }
.toggle input:checked + .toggle-track { background: var(--brand); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* --- tabs --- */
.settings-tabs { display: flex; gap: 0.3rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.settings-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 0.65rem 0.9rem; font-size: 0.88rem; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; font-family: inherit; }
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel[hidden] { display: none; }

/* --- website / provider cards --- */
.website-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.website-card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.website-card-head h3 { margin: 0; font-size: 1.05rem; }
.website-card-url { color: var(--muted); font-size: 0.85rem; }
.website-connections { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.5rem; }
.website-connection-item { font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.2rem; }
.website-connection-item .label { color: var(--muted); font-size: 0.78rem; }

/* --- health / error banners --- */
.health-banner { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.9rem 1rem; border-radius: 10px; }
.health-banner.warn { background: var(--warning-bg); color: var(--warning); }
.health-banner.error { background: var(--critical-bg); color: var(--critical); }
.health-banner-icon { font-size: 1.2rem; line-height: 1; }
.health-banner-body strong { display: block; margin-bottom: 0.2rem; }
.health-banner-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* --- sticky save bar --- */
.save-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  box-shadow: 0 10px 30px #00000033;
  z-index: 40;
  font-weight: 600;
  font-size: 0.9rem;
}
.save-bar-actions { display: flex; gap: 0.5rem; }
.save-bar .btn-ghost { color: var(--bg); border-color: #ffffff44; }
.save-bar .btn-primary { background: var(--brand); }

/* --- connection test flow --- */
.test-flow-log { list-style: none; margin: 0.6rem 0 0; padding: 0; font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.25rem; }
.test-flow-log li.done { color: var(--ok); }
.test-result-box { margin-top: 0.75rem; padding: 0.75rem; border-radius: 8px; background: var(--ok-bg); color: var(--ok); font-size: 0.88rem; }
.test-result-box.is-error { background: var(--critical-bg); color: var(--critical); }

/* --- permission matrix --- */
.permission-matrix { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.permission-matrix th, .permission-matrix td { padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); text-align: center; }
.permission-matrix th:first-child, .permission-matrix td:first-child { text-align: left; }
.permission-matrix thead th { color: var(--muted); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
.perm-yes { color: var(--ok); font-weight: 800; }
.perm-no { color: var(--muted); }
.perm-read { color: var(--brand); font-weight: 700; font-size: 0.78rem; }

/* --- wizard --- */
.wizard-steps { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.wizard-step { flex: 1 1 0; min-width: 90px; text-align: center; padding: 0.5rem 0.3rem; border-radius: 8px; font-size: 0.78rem; font-weight: 700; color: var(--muted); background: var(--bg); border: 1px solid var(--border); }
.wizard-step.active { color: var(--brand); border-color: var(--brand); background: var(--ok-bg); }
.wizard-step.done { color: var(--ok); }
.wizard-panel[hidden] { display: none; }
.wizard-actions { display: flex; justify-content: space-between; margin-top: 1.25rem; }
.provider-choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.6rem; }
.provider-choice { display: flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.9rem; border: 1px solid var(--border); border-radius: 10px; background: var(--card-bg); cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.provider-choice input { accent-color: var(--brand); }

/* --- budget bar --- */
.budget-bar-track { height: 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; margin: 0.5rem 0; }
.budget-bar-fill { height: 100%; background: var(--brand); border-radius: 999px; }
.budget-bar-fill.is-high { background: var(--warning); }
.budget-bar-fill.is-critical { background: var(--critical); }

/* --- flow diagram (text-arrow style) --- */
.flow-diagram { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; font-size: 0.86rem; color: var(--muted); padding: 0.5rem 0; }
.flow-diagram .flow-step { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.9rem; font-weight: 600; color: var(--text); }
.flow-diagram .flow-arrow { color: var(--border); font-size: 1rem; }
.flow-diagram-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }

/* --- automation level cards --- */
.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.level-card { border: 1px solid var(--border); border-radius: 12px; padding: 1rem; background: var(--card-bg); }
.level-card.is-autonomous { border-color: var(--warning); }
.level-card h3 { margin: 0 0 0.5rem; font-size: 0.98rem; }
.level-card ol { margin: 0; padding-left: 1.1rem; font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.25rem; }

/* --- data table (audit log, usage, api keys, team) --- */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td { text-align: left; padding: 0.6rem 0.6rem; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 700; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.02em; }
.table-scroll { overflow-x: auto; }

.toast-flash {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ok);
  color: white;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 50;
  box-shadow: 0 8px 24px #0003;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f172a;
    --card-bg: #1a2436;
    --border: #2c3a53;
    --text: #e6ecf5;
    --muted: #94a3b8;
    --ok-bg: #113322;
    --warning-bg: #3a2e0c;
    --critical-bg: #3a1414;
    --unknown-bg: #232f42;
  }
  .report-body { background: #0f172a; }
  .chat-assistant { background: #232f42; }
  .btn-ghost:hover { background: #232f42; }
}

/* --- backlink agent ------------------------------------------------------ */
/* Additive only: everything below is namespaced .bl-* (or scoped under one)
   so nothing here can change how an existing page renders. */

.bl-score { display:inline-block; min-width:2.4rem; padding:0.15rem 0.45rem; border-radius:6px;
  font-weight:700; font-size:0.8rem; text-align:center; font-variant-numeric:tabular-nums; }
.bl-score-high { background:var(--ok-bg); color:var(--ok); }
.bl-score-mid { background:#e0edff; color:var(--brand-dark); }
.bl-score-low { background:var(--warning-bg); color:var(--warning); }
.bl-score-weak { background:var(--unknown-bg); color:var(--unknown); }
.bl-score-lg { font-size:1.6rem; min-width:3.6rem; padding:0.35rem 0.7rem; border-radius:10px; }

.bl-tile-link { text-decoration:none; color:inherit; transition:border-color .12s, transform .12s; }
.bl-tile-link:hover { border-color:var(--brand); transform:translateY(-1px); }

.bl-funnel { display:flex; align-items:stretch; gap:0.35rem; overflow-x:auto; padding:0.25rem 0 0.5rem; }
.bl-funnel-stage { flex:1 1 0; min-width:96px; display:flex; flex-direction:column; align-items:center;
  gap:0.15rem; padding:0.75rem 0.5rem; border:1px solid var(--border); border-radius:10px;
  background:var(--card-bg); text-decoration:none; color:inherit; transition:border-color .12s; }
.bl-funnel-stage:hover { border-color:var(--brand); }
.bl-funnel-count { font-size:1.35rem; font-weight:700; font-variant-numeric:tabular-nums; }
.bl-funnel-label { font-size:0.72rem; color:var(--muted); text-align:center; line-height:1.25; }
.bl-funnel-conv { font-size:0.7rem; font-weight:600; color:var(--brand); }
.bl-funnel-arrow { align-self:center; color:var(--muted); font-size:0.9rem; }

.bl-board { display:flex; gap:0.75rem; overflow-x:auto; padding-bottom:0.75rem; align-items:flex-start; }
.bl-board-col { flex:0 0 250px; background:var(--unknown-bg); border-radius:10px; padding:0.6rem; }
.bl-board-col-head { display:flex; justify-content:space-between; align-items:center; gap:0.5rem;
  font-size:0.78rem; font-weight:700; text-transform:uppercase; letter-spacing:.03em;
  color:var(--muted); margin-bottom:0.5rem; }
.bl-board-cards { display:flex; flex-direction:column; gap:0.45rem; min-height:2rem; }
.bl-card { display:block; background:var(--card-bg); border:1px solid var(--border); border-radius:8px;
  padding:0.55rem 0.6rem; text-decoration:none; color:inherit; font-size:0.82rem; }
.bl-card:hover { border-color:var(--brand); }
.bl-card-top { display:flex; justify-content:space-between; gap:0.4rem; align-items:flex-start; }
.bl-card-domain { font-weight:600; word-break:break-word; }
.bl-card-title { color:var(--muted); font-size:0.76rem; margin-top:0.2rem;
  display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.bl-card-meta { margin-top:0.35rem; font-size:0.72rem; color:var(--muted);
  display:flex; gap:0.4rem; flex-wrap:wrap; }

.bl-filters { display:flex; flex-wrap:wrap; gap:0.6rem; align-items:flex-end; }
.bl-filters label { display:flex; flex-direction:column; gap:0.25rem; font-size:0.78rem;
  font-weight:600; color:var(--muted); }
.bl-filters select, .bl-filters input { font-size:0.85rem; padding:0.4rem 0.5rem; }

.bl-evidence { margin:0.4rem 0 0; padding-left:1.1rem; line-height:1.65; font-size:0.88rem; }
.bl-evidence li { margin-bottom:0.3rem; }
.bl-evidence code { background:var(--unknown-bg); padding:0.1rem 0.3rem; border-radius:4px;
  font-size:0.82rem; word-break:break-all; }

.bl-score-table td { vertical-align:top; }
.bl-score-table td:last-child { max-width:32rem; }

.bl-timeline { list-style:none; margin:0.5rem 0 0; padding:0 0 0 1.1rem; border-left:2px solid var(--border); }
.bl-timeline-item { position:relative; padding:0 0 1rem 0.9rem; }
.bl-timeline-item::before { content:''; position:absolute; left:-1.45rem; top:0.35rem; width:0.6rem;
  height:0.6rem; border-radius:50%; background:var(--unknown); border:2px solid var(--card-bg); }
.bl-timeline-sent::before { background:var(--brand); }
.bl-timeline-reply::before { background:var(--ok); }
.bl-timeline-opened::before, .bl-timeline-clicked::before { background:var(--warning); }
.bl-timeline-bounced::before, .bl-timeline-failed::before, .bl-timeline-unsubscribed::before { background:var(--critical); }
.bl-timeline-when { font-size:0.74rem; color:var(--muted); }
.bl-timeline-quote { margin:0.4rem 0 0; padding:0.5rem 0.65rem; background:var(--unknown-bg);
  border-radius:6px; white-space:pre-wrap; font-family:inherit; font-size:0.82rem; line-height:1.5;
  max-height:14rem; overflow:auto; }

.bl-empty { text-align:center; padding:2.5rem 1rem; }
.bl-empty h3 { margin:0 0 0.4rem; font-size:1.05rem; }
.bl-empty p { max-width:36rem; margin:0 auto 1rem; }

.bl-toast { position:fixed; left:50%; bottom:1.5rem; transform:translate(-50%, 1rem);
  background:#172033; color:#fff; padding:0.7rem 1.1rem; border-radius:8px; font-size:0.88rem;
  max-width:min(34rem, calc(100vw - 2rem)); box-shadow:0 6px 24px rgba(15,23,42,.25);
  opacity:0; pointer-events:none; transition:opacity .16s, transform .16s; z-index:50; }
.bl-toast.is-visible { opacity:1; transform:translate(-50%, 0); }
.bl-toast.is-error { background:var(--critical); }

.bl-split { display:grid; grid-template-columns:minmax(0,2fr) minmax(0,1fr); gap:1rem; align-items:start; }
@media (max-width: 900px) { .bl-split { grid-template-columns:1fr; } }

.bl-kv { display:grid; grid-template-columns:auto 1fr; gap:0.3rem 0.9rem; font-size:0.86rem; margin:0; }
.bl-kv dt { color:var(--muted); }
.bl-kv dd { margin:0; word-break:break-word; }

.bl-email-editor textarea { width:100%; font-family:inherit; font-size:0.9rem; line-height:1.55;
  padding:0.7rem; border:1px solid var(--border); border-radius:8px; resize:vertical; }
.bl-email-editor input[type="text"] { width:100%; }
.bl-email-editor label { display:block; margin-bottom:0.6rem; font-size:0.8rem; font-weight:600; }

.bl-warn { background:var(--warning-bg); border:1px solid rgba(146,98,10,.25); color:var(--warning);
  border-radius:8px; padding:0.6rem 0.75rem; font-size:0.85rem; line-height:1.5; }
.bl-warn strong { display:block; margin-bottom:0.15rem; }
.bl-note { background:var(--unknown-bg); border-radius:8px; padding:0.6rem 0.75rem;
  font-size:0.85rem; line-height:1.5; color:var(--muted); }

.bl-weights { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:0.75rem; }
.bl-weights label { display:flex; flex-direction:column; gap:0.25rem; font-size:0.82rem; font-weight:600; }
.bl-weight-total { font-weight:700; }
.bl-weight-total.is-off { color:var(--warning); }

.bl-bar { height:6px; border-radius:3px; background:var(--unknown-bg); overflow:hidden; min-width:60px; }
.bl-bar span { display:block; height:100%; background:var(--brand); }

.bl-chart { display:flex; align-items:flex-end; gap:2px; height:90px; }
.bl-chart-col { flex:1 1 0; display:flex; flex-direction:column; justify-content:flex-end; gap:1px; min-width:2px; }
.bl-chart-col i { display:block; border-radius:1px; }
.bl-chart-sent { background:var(--brand); }
.bl-chart-replied { background:var(--warning); }
.bl-chart-acquired { background:var(--ok); }
.bl-legend { display:flex; gap:0.9rem; font-size:0.76rem; color:var(--muted); margin-top:0.4rem; flex-wrap:wrap; }
.bl-legend i { display:inline-block; width:0.6rem; height:0.6rem; border-radius:2px; margin-right:0.25rem; }

/* --- AI Visibility ------------------------------------------------------ */
/* The priority number and its confidence badge are always rendered together;
   these rules only size them, so they can never drift apart visually. */
.vis-score { font-size: 1rem; }
.vis-score-large { font-size: 1.6rem; }
.vis-evidence { list-style: none; padding: 0; margin: 0; }
.vis-evidence > li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.vis-evidence > li:last-child { border-bottom: 0; }
.vis-evidence blockquote { margin: 0.4rem 0 0; padding-left: 0.75rem;
  border-left: 3px solid var(--border); }
.vis-action-card { border-left: 3px solid var(--brand); }

/* --- WhatsApp AI inbox (whatsapp/inbox.php) ---
   Three panes: conversation list, thread, customer. The only layout in the
   app that wants the full viewport height rather than the usual scrolling
   page, so it opts out of .wrap's padding and manages its own overflow.
   Collapses to a single column on narrow screens, where the thread is shown
   on its own and a back link returns to the list. */

.wa-inbox {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(240px, 300px);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  height: calc(100vh - 190px);
  min-height: 420px;
}
.wa-pane { background: var(--card-bg); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.wa-pane-head {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  flex-wrap: wrap;
}
.wa-pane-head h2 { margin: 0; font-size: 0.95rem; }
.wa-pane-body { overflow-y: auto; flex: 1; min-height: 0; }

/* conversation list */
.wa-search { width: 100%; }
.wa-filters { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); }
.wa-chip {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 0.2rem 0.6rem; font-size: 0.78rem; font-weight: 600;
  cursor: pointer; font-family: inherit; text-decoration: none; display: inline-block;
}
.wa-chip:hover { background: #eef2f7; }
.wa-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.wa-chip-count { opacity: 0.75; margin-left: 0.25rem; }

.wa-conv {
  display: block; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
}
.wa-conv:hover { background: #f8fafc; }
.wa-conv.active { background: #eff4ff; border-left: 3px solid var(--brand); padding-left: calc(0.9rem - 3px); }
.wa-conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.wa-conv-name { font-weight: 650; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-conv-time { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.wa-conv-preview {
  color: var(--muted); font-size: 0.82rem; margin-top: 0.15rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wa-conv-meta { display: flex; gap: 0.3rem; margin-top: 0.35rem; flex-wrap: wrap; align-items: center; }
.wa-unread {
  background: var(--brand); color: #fff; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700; padding: 0.05rem 0.4rem; min-width: 1.15rem; text-align: center;
}

/* thread */
.wa-thread { padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.wa-day { align-self: center; color: var(--muted); font-size: 0.72rem; background: var(--unknown-bg); border-radius: 999px; padding: 0.1rem 0.6rem; margin: 0.4rem 0; }
.wa-bubble { max-width: min(74%, 560px); padding: 0.5rem 0.7rem; border-radius: 12px; font-size: 0.88rem; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.wa-bubble-in { align-self: flex-start; background: #eef1f5; border-bottom-left-radius: 3px; }
.wa-bubble-out { align-self: flex-end; background: #dcf7e3; border-bottom-right-radius: 3px; }
.wa-bubble-system { align-self: center; background: var(--warning-bg); color: var(--warning); font-size: 0.8rem; max-width: 80%; text-align: center; }
.wa-bubble-foot { display: flex; gap: 0.4rem; align-items: center; justify-content: flex-end; margin-top: 0.25rem; font-size: 0.68rem; color: var(--muted); }
.wa-bubble-author { font-size: 0.7rem; font-weight: 700; color: var(--muted); margin-bottom: 0.15rem; }
.wa-attachment { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--muted); font-style: italic; }

/* customer pane */
.wa-customer-field { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); }
.wa-customer-field dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin: 0 0 0.2rem; }
.wa-customer-field dd { margin: 0; font-size: 0.88rem; word-break: break-word; }

.wa-empty { padding: 2rem 1rem; text-align: center; color: var(--muted); font-size: 0.88rem; }

@media (max-width: 1100px) {
  .wa-inbox { grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); }
  .wa-pane-customer { display: none; }
}
@media (max-width: 760px) {
  .wa-inbox { grid-template-columns: 1fr; height: auto; }
  .wa-pane-list { max-height: 45vh; }
  .wa-pane-thread { min-height: 55vh; }
}

/* A reply the agent has written but nobody has approved. Visually unlike a
   sent bubble on purpose - it must never read as something the customer saw. */
.wa-draft {
  align-self: flex-end;
  max-width: min(80%, 620px);
  border: 1px dashed var(--brand);
  background: #f8faff;
  border-radius: 12px;
  padding: 0.6rem 0.7rem;
}
.wa-draft-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.4rem; }
.wa-draft-label { font-size: 0.7rem; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: 0.03em; }
.wa-draft textarea { width: 100%; font-size: 0.88rem; line-height: 1.45; min-height: 4.5rem; }
.wa-draft-actions { display: flex; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; align-items: center; }
.wa-draft-meta { font-size: 0.72rem; color: var(--muted); margin-top: 0.35rem; }
.wa-composer { padding: 0.7rem 0.9rem; border-top: 1px solid var(--border); display: flex; gap: 0.5rem; align-items: flex-end; }

/* Content Planner: keep the Notes column from stretching the backlog table
   on a long note - the full text is already one click away via "Why this?". */
.plan-notes-cell { max-width: 220px; }
.plan-notes {
  display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; cursor: default;
}
.wa-composer textarea { flex: 1; min-height: 2.6rem; font-size: 0.88rem; }
