/* ─── Cwik Agents dashboard ────────────────────────────────────────────────
   Light editorial design system in the colours of cwik-consulting.de: warm
   paper, ink instead of black, bronze as the brand thread. Serif display type
   (DM Serif Display) for headings and figures, DM Sans for everything else.

   Two shells share one palette:
   - html[data-mode='admin']  platform administration — dark ink sidebar
   - html[data-mode='tenant'] customer area — light paper sidebar
   An admin inside the customer area gets the customer shell plus a dark
   "Kundenansicht" bar, so the current perspective is always obvious. */

/* Self-hosted brand fonts (SIL OFL 1.1) — same files as cwik-consulting.de.
   Google Fonts would be blocked by the CSP and would send user IPs to Google. */
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(/assets/fonts/dmsans-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(/assets/fonts/dmsans-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'DM Serif Display';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/dmserifdisplay-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'DM Serif Display';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/dmserifdisplay-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Paper & ink */
  --bg: #faf6ef;            /* page: warm paper */
  --surface: #fffdf8;       /* cards */
  --surface-2: #f4eee2;     /* bands: sidebar, table heads, inputs on hover */
  --surface-3: #ece4d3;
  --border: #e6dec9;
  --border-strong: #d0c4a6;
  --ink: #26221b;
  --text: #26221b;
  --text-muted: #5a5244;
  --text-dim: #86795f;

  /* Brand: bronze, darkened for light backgrounds */
  --primary: #9a621c;
  --primary-hover: #7c4e13;
  --primary-fg: #ffffff;
  --accent-soft: rgba(154, 98, 28, 0.1);

  /* States — muted, paper-friendly */
  --success: #2f6b3f;
  --success-bg: #e2f1e1;
  --danger: #a63a2b;
  --danger-bg: #f8e3de;
  --warning: #93600b;
  --warning-bg: #f8ecd2;
  --info: #2d5f73;
  --info-bg: #e1edf0;

  /* Admin shell */
  --night: #1f1b16;
  --night-2: #2b261f;
  --night-line: #3a332a;
  --night-text: #eee7d8;
  --night-muted: #a89c86;
  --night-accent: #d69a4b;

  --font-display: 'DM Serif Display', Georgia, 'Times New Roman', serif;
  --font-body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 1px 2px rgba(58, 50, 36, 0.04);
  --shadow-lg: 0 24px 60px rgba(38, 34, 27, 0.18);
  --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: rgba(193, 140, 58, 0.24); color: var(--ink); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3 { color: var(--text); margin: 0 0 0.5rem; }
h1, h2 { font-family: var(--font-display); font-weight: 400; letter-spacing: -0.01em; }
h1 { font-size: 2.75rem; line-height: 1.05; }
h2 { font-size: 1.45rem; line-height: 1.2; }
h3 { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
p { margin: 0 0 12px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

code, .mono { font-family: var(--mono); font-size: 0.85em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.token-box code, pre code { background: none; padding: 0; }

.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }

/* ─── Shell ─────────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 14px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 14px;
  color: var(--text);
}
.sidebar-brand:hover { text-decoration: none; color: var(--text); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: inline-flex; background: #0e0e0e;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.32); }
.brand-name { font-family: var(--font-display); font-size: 27px; line-height: 1; letter-spacing: 0.005em; white-space: nowrap; align-self: baseline; }
.brand-sub {
  font-family: var(--font-body); font-size: 14px; font-weight: 600; line-height: 1;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--primary); white-space: nowrap;
  margin-left: -4px; align-self: baseline;
}
[data-mode='admin'] .brand-sub { color: var(--night-accent); }
.brand-tag {
  margin-left: auto; padding: 3px 7px; border-radius: 999px;
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}

/* Customer context card ("Portal für …") */
.sidebar-context {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.ctx-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-muted); font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em;
}
.ctx-kicker { font-size: 11.5px; color: var(--text-dim); line-height: 1.2; }
.ctx-name { font-weight: 600; font-size: 13.5px; line-height: 1.3; overflow-wrap: anywhere; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section {
  margin: 18px 12px 6px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim);
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 15px; font-weight: 500;
  border: 1px solid transparent;
}
.sidebar-nav a .icon { color: var(--text-dim); }
.sidebar-nav a:hover { color: var(--text); background: color-mix(in srgb, var(--surface) 55%, transparent); text-decoration: none; }
.sidebar-nav a.active {
  color: var(--text); font-weight: 600;
  background: var(--surface); border-color: var(--border); box-shadow: var(--shadow);
}
.sidebar-nav a.active .icon { color: var(--primary); }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.user-card { display: flex; align-items: center; gap: 11px; padding: 8px 8px 8px 10px; border-radius: var(--radius-sm); color: var(--text); }
.user-card:hover { text-decoration: none; color: var(--text); background: color-mix(in srgb, var(--surface) 55%, transparent); }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 700; letter-spacing: 0.02em;
}
.user-meta { flex: 1; min-width: 0; line-height: 1.3; }
.user-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 12px; color: var(--text-dim); }
.user-card .icon { color: var(--text-dim); }
.sidebar-logout {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; border: 0; border-radius: var(--radius-sm); background: none; cursor: pointer;
  color: var(--text-muted); font: inherit; font-size: 15px; font-weight: 500; text-align: left;
}
.sidebar-logout:hover { color: var(--text); background: color-mix(in srgb, var(--surface) 55%, transparent); }
.sidebar-legal { display: flex; gap: 14px; padding: 8px 12px 0; font-size: 12px; }
.sidebar-legal a { color: var(--text-dim); }
.sidebar-legal a:hover { color: var(--text); }

/* Admin shell: dark sidebar, bronze highlights */
[data-mode='admin'] .sidebar { background: var(--night); border-right-color: var(--night); color: var(--night-text); }
[data-mode='admin'] .sidebar-brand,
[data-mode='admin'] .sidebar-brand:hover { color: var(--night-text); }
[data-mode='admin'] .brand-tag { background: color-mix(in srgb, var(--night-accent) 18%, transparent); color: var(--night-accent); }
[data-mode='admin'] .nav-section { color: var(--night-muted); opacity: 0.8; }
[data-mode='admin'] .sidebar-nav a { color: var(--night-muted); }
[data-mode='admin'] .sidebar-nav a .icon { color: var(--night-muted); }
[data-mode='admin'] .sidebar-nav a:hover { color: var(--night-text); background: var(--night-2); }
[data-mode='admin'] .sidebar-nav a.active { color: #fffaf0; background: var(--night-2); border-color: var(--night-line); box-shadow: none; }
[data-mode='admin'] .sidebar-nav a.active .icon { color: var(--night-accent); }
[data-mode='admin'] .sidebar-foot { border-top-color: var(--night-line); }
[data-mode='admin'] .user-card,
[data-mode='admin'] .user-card:hover { color: var(--night-text); }
[data-mode='admin'] .user-card:hover,
[data-mode='admin'] .sidebar-logout:hover { background: var(--night-2); }
[data-mode='admin'] .user-avatar { background: var(--night-accent); color: var(--night); }
[data-mode='admin'] .user-role,
[data-mode='admin'] .user-card .icon,
[data-mode='admin'] .sidebar-legal a { color: var(--night-muted); }
[data-mode='admin'] .sidebar-logout { color: var(--night-muted); }
[data-mode='admin'] .sidebar-logout:hover,
[data-mode='admin'] .sidebar-legal a:hover { color: var(--night-text); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mobile-bar {
  display: none; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px; position: sticky; top: 0; z-index: 30;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.mobile-bar { gap: 8px; }
.mobile-bar .brand-name { font-size: 23px; }
[data-mode='admin'] .mobile-bar { background: var(--night); color: var(--night-text); border-bottom-color: var(--night); }
.content { width: 100%; max-width: 1180px; margin: 0 auto; padding: 44px 56px 72px; }
.inline-form { margin: 0; display: inline-flex; }

/* Customer view bar: the admin previews a customer's area */
.view-bar {
  position: sticky; top: 0; z-index: 25;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 9px 56px; min-height: 52px;
  background: var(--night); color: var(--night-text); font-size: 13.5px;
}
.view-bar .icon { color: var(--night-accent); }
.view-bar strong { color: #fffaf0; font-weight: 600; }
.view-bar .view-bar-text { flex: 1; min-width: 220px; }
.view-bar .muted { color: var(--night-muted); }
.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--night-2); border: 1px solid var(--night-line); }
.segmented button {
  border: 0; background: none; color: var(--night-muted); font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.segmented button:hover { color: var(--night-text); }
.segmented button[aria-pressed='true'] { background: var(--night-text); color: var(--night); }
.view-bar .btn { background: transparent; border-color: var(--night-line); color: var(--night-text); }
.view-bar .btn:hover { background: var(--night-2); color: #fffaf0; }

/* ─── Page head ─────────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; gap: 12px 20px; margin-bottom: 32px; flex-wrap: wrap; }
.page-head > h1 { margin-bottom: 0; }
.page-head .spacer, .page-title + .spacer { flex: 1; }
.page-title { flex: 1; min-width: 260px; }
.page-title h1 { margin: 0; }
.page-lead { margin: 12px 0 0; max-width: 680px; color: var(--text-muted); font-size: 1.08rem; line-height: 1.6; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.crumb {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px;
  color: var(--text-muted); font-size: 0.87rem; font-weight: 500;
}
.crumb:hover { color: var(--text); text-decoration: none; }
.crumb .sep { color: var(--text-dim); }
.page-head .badge { margin-bottom: 8px; }

/* Tabs (sub-navigation) */
.subnav {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); margin: -8px 0 32px;
}
.subnav a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 11px 14px; margin-bottom: -1px;
  color: var(--text-muted); font-weight: 500; font-size: 0.9rem;
  border-bottom: 2px solid transparent;
}
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--ink); }
.count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--surface-3); color: var(--text-muted); font-size: 0.72rem; font-weight: 600;
}

.icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.mobile-bar .icon-btn { border-color: transparent; color: inherit; }
.menu-toggle { display: none; }

/* ─── Cards, sections & grids ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.card-head { padding: 20px 24px 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head h2 { font-size: 1.3rem; }
.card-head .spacer { flex: 1; }
.card-head + .card-body { padding-top: 16px; }
.card-head + .card-body.tight { padding-top: 16px; }
.card-body { padding: 20px 24px 24px; }
.card-body.tight { padding: 0; }
.card-body.tight .empty { margin: 0 24px 24px; }
.card-body > :last-child { margin-bottom: 0; }
.card-foot { padding: 14px 24px; border-top: 1px solid var(--border); }
.card-foot.pagination { margin-top: 0; }
.card-split { border-top: 1px solid var(--border); }
.card.dashed { background: transparent; border-style: dashed; border-color: var(--border-strong); box-shadow: none; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.danger-zone .card-head h2 { color: var(--danger); }

/* Sections without card chrome (CK-style headings above lists) */
.section { margin-bottom: 40px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 1.55rem; }
.section-head .spacer { flex: 1; }
.section-head a.more { font-size: 0.85rem; text-decoration: underline; text-underline-offset: 3px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-bottom: 24px; }
.grid-2 > .card, .grid-2 > .section { margin-bottom: 0; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 40px; align-items: start; }
.grid-sidebar { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 24px; align-items: start; }
.align-start { align-items: start; }

/* Stat tiles with serif figures */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 32px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 22px 18px; box-shadow: var(--shadow); min-width: 0;
}
a.stat { display: block; color: inherit; }
a.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat .label { color: var(--text-muted); font-size: 0.84rem; font-weight: 500; }
.stat .value {
  font-family: var(--font-display); font-weight: 400; font-size: 2.6rem; line-height: 1.05;
  margin-top: 10px; letter-spacing: -0.01em; font-variant-numeric: lining-nums; overflow-wrap: anywhere;
}
.stat .value.sm { font-size: 1.9rem; }
.stat .sub { color: var(--text-dim); font-size: 0.8rem; margin-top: 6px; }
.stat.is-alert .value { color: var(--danger); }

/* ─── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th {
  text-align: left; padding: 12px 16px; background: var(--surface-2); color: var(--text-muted);
  font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { padding-left: 24px; }
table.data th:last-child, table.data td:last-child { padding-right: 24px; }
table.data td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
table.data td.num, table.data th.right { text-align: right; }
table.data td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data.compact th, table.data.compact td { padding: 7px 10px; }
table.data input { min-width: 90px; }
table.data td a strong { color: var(--text); }
table.data td a:hover strong { color: var(--primary); }
/* A card whose body is only a table: round the header row with the card. */
.card > .card-body.tight:first-child table.data thead th:first-child { border-top-left-radius: calc(var(--radius) - 1px); }
.card > .card-body.tight:first-child table.data thead th:last-child { border-top-right-radius: calc(var(--radius) - 1px); }
.card-head + .card-body.tight table.data th { border-top: 1px solid var(--border); }

.empty {
  padding: 28px 24px; text-align: left; color: var(--text-muted); font-size: 0.92rem;
  border: 1px dashed var(--border-strong); border-radius: 12px;
}
.empty p { margin: 0 0 12px; }
.empty p:last-child { margin: 0; }
.empty strong { color: var(--text); }
.empty.center { text-align: center; }

/* Row lists (CK-style lists of items with meta on the right) */
.row-list { list-style: none; margin: 0; padding: 0; }
.row-list > li { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.row-list > li:last-child { border-bottom: none; }
.row-list .row-main { flex: 1; min-width: 0; }
.row-list .row-title { font-weight: 600; color: var(--text); }
.row-list a.row-title:hover { color: var(--primary); text-decoration: none; }
.row-list .row-meta { font-size: 0.82rem; color: var(--text-dim); }
.row-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px 20px; }

/* ─── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted); line-height: 1.5;
}
.badge.ok::before, .badge.enabled::before, .badge.pending::before, .badge.err::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
a.badge:hover { text-decoration: none; filter: brightness(0.97); }
.badge.ok, .badge.enabled { background: var(--success-bg); color: var(--success); }
.badge.err { background: var(--danger-bg); color: var(--danger); }
.badge.pending { background: var(--warning-bg); color: var(--warning); }
.badge.muted, .badge.disabled { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.admin { background: var(--ink); color: var(--bg); letter-spacing: 0.06em; text-transform: uppercase; font-size: 0.68rem; }
.badge-row { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 0.88rem; font-family: inherit;
  cursor: pointer; text-decoration: none; line-height: 1.1; transition: background 0.15s, border-color 0.15s, color 0.15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fffaf0; }
.btn.primary:hover { background: #3b352b; border-color: #3b352b; color: #fffaf0; }
.btn.accent { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.accent:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(0.94); color: #fff; }
.btn.danger-ghost { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.btn.danger-ghost:hover { background: var(--danger-bg); color: var(--danger); }
.btn.sm { padding: 7px 13px; font-size: 0.8rem; gap: 6px; }
.btn.ghost { background: none; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.is-busy { opacity: 0.8; cursor: progress; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn-row .spacer { flex: 1; }
.justify-end { justify-content: flex-end; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ─── Forms ─────────────────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 18px 20px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > label, .label-text { font-weight: 600; font-size: 0.86rem; color: var(--text); }
.hint { color: var(--text-dim); font-size: 0.8rem; line-height: 1.5; }
.hint.block, .block { display: block; }
input[type='text'], input[type='email'], input[type='password'], input[type='number'],
input[type='url'], input[type='search'], input[type='date'], select, textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 0.93rem; font-family: inherit; line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input:hover, select:hover, textarea:hover { border-color: #bfb190; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, select:disabled, textarea:disabled { opacity: 0.65; background: var(--surface-2); }
select {
  appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2326221b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
}
textarea { resize: vertical; min-height: 76px; }
.code-editor { font-family: var(--mono); font-size: 0.84rem; line-height: 1.6; tab-size: 2; }
.num-input { text-align: right; font-variant-numeric: tabular-nums; }
input[type='checkbox'], input[type='radio'] { accent-color: var(--ink); width: 16px; height: 16px; }
.checkbox { display: flex; align-items: center; gap: 9px; font-weight: 400; cursor: pointer; }
.checkbox input { width: auto; margin: 0; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; padding-top: 6px; }
.option-card {
  display: flex; gap: 12px; align-items: flex-start; padding: 13px 15px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-weight: 400; background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
.option-card + .option-card { margin-top: 8px; }
.option-card:hover { border-color: var(--border-strong); }
.option-card input { margin-top: 3px; }
.option-card:has(input:checked) { border-color: var(--ink); background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.switch-list { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 16px; background: var(--surface); }
.switch-row { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); cursor: pointer; font-weight: 400; }
.switch-row:last-child { border-bottom: none; }
.switch-row input { width: auto; margin-top: 3px; flex-shrink: 0; }
.switch-row strong { font-weight: 600; }
.section-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim);
  margin: 28px 0 12px; font-weight: 600; font-family: var(--font-body);
}
.char-count { font-size: 0.8rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.char-count.over { color: var(--danger); font-weight: 700; }
.color-field { display: flex; align-items: center; gap: 10px; }
input[type='color'] {
  width: 46px; height: 40px; padding: 3px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.form-foot {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin: 0 0 32px; padding: 14px 0;
  background: linear-gradient(to top, var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
}
.box { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); }

/* ─── Flash & callouts ──────────────────────────────────────────────────── */
.flash {
  display: block; padding: 14px 18px; border-radius: 12px; margin-bottom: 24px;
  font-weight: 500; font-size: 0.92rem; border: 1px solid transparent;
}
.flash.success { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 18%, transparent); }
.flash.error { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 18%, transparent); }
.flash.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 15%, transparent); }
.flash.warn { background: var(--warning-bg); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 18%, transparent); }
.flash a { color: inherit; text-decoration: underline; }
.flash code { color: inherit; background: rgba(255, 255, 255, 0.5); }
.flash .flash-link { margin-top: 10px; color: var(--text); background: var(--surface); }
.callout {
  display: flex; align-items: center; gap: 14px; padding: 22px 26px; margin-bottom: 32px;
  border-radius: var(--radius); background: var(--success-bg); color: var(--success); font-weight: 500;
}
.callout.neutral { background: var(--surface); color: var(--text); border: 1px dashed var(--border-strong); }
.callout .grow { flex: 1; }
.admin-note {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 16px; border-radius: 12px; margin-bottom: 24px;
  background: var(--surface-2); color: var(--text-muted); font-size: 0.88rem;
}
.admin-note .icon { color: var(--primary); margin-top: 2px; }

/* ─── Token / snippet box ───────────────────────────────────────────────── */
.token-box {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 0.82rem; word-break: break-all;
}
.token-box .val { flex: 1; white-space: pre-wrap; }

/* ─── Toolbar / filter row ──────────────────────────────────────────────── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 20px; }
.toolbar .field { min-width: 180px; gap: 5px; }
.toolbar .field > label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.toolbar .grow { flex: 1; }
.filter-panel { padding: 18px 20px; margin-bottom: 20px; border-radius: var(--radius); background: var(--surface-2); }
.filter-panel .toolbar { margin-bottom: 0; }

/* ─── Definition list ───────────────────────────────────────────────────── */
.dl { display: grid; grid-template-columns: 200px 1fr; gap: 0; margin: 0; }
.dl dt { color: var(--text-muted); padding: 11px 0; border-bottom: 1px solid var(--border); font-weight: 500; font-size: 0.9rem; }
.dl dd { padding: 11px 0; border-bottom: 1px solid var(--border); margin: 0; word-break: break-word; }
.dl > :nth-last-child(-n + 2) { border-bottom: none; }
.dl.stacked { grid-template-columns: 1fr; }
.dl.stacked dt { border-bottom: none; padding-bottom: 0; font-size: 0.78rem; }
.dl.stacked dd { padding-top: 2px; }

.plain-list { list-style: none; padding: 0; margin: 0 0 12px; }
.plain-list li { padding: 4px 0; }
.plain-list.bullets li { padding-left: 16px; position: relative; margin-bottom: 6px; }
.plain-list.bullets li::before { content: '–'; position: absolute; left: 0; color: var(--text-dim); }

.pagination { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 16px; flex-wrap: wrap; }
.pagination .info { color: var(--text-muted); font-size: 0.85rem; }

/* ─── Setup checklist ───────────────────────────────────────────────────── */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: none; }
.check-icon {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; border: 1px solid var(--border-strong); color: var(--text-muted);
}
.checklist li.done .check-icon { background: var(--success-bg); color: var(--success); border-color: transparent; }
.checklist li.done .check-label { color: var(--text-dim); text-decoration: line-through; text-decoration-color: var(--border-strong); }

/* ─── Meter (budget) ────────────────────────────────────────────────────── */
.meter {
  height: 8px; border-radius: 999px; overflow: hidden;
  background: color-mix(in srgb, var(--primary) 14%, var(--surface));
}
.meter-fill { height: 100%; border-radius: 999px; background: var(--primary); }
.meter.level-warn { background: color-mix(in srgb, var(--warning) 20%, var(--surface)); }
.meter.level-warn .meter-fill { background: var(--warning); }
.meter.level-over { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); }
.meter.level-over .meter-fill { background: var(--danger); }
.meter.sm { height: 6px; width: 84px; flex-shrink: 0; }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.meter-head .spacer { flex: 1; }
.meter-label { color: var(--text-muted); font-size: 0.86rem; font-weight: 500; }
.meter-value { font-family: var(--font-display); font-size: 2.1rem; line-height: 1; }

/* ─── Column chart ──────────────────────────────────────────────────────── */
figure.chart { margin: 0 0 24px; }
.bar-chart {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  grid-template-rows: 180px auto;
  padding: 22px 24px 10px 8px;
}
.bc-axis { grid-row: 1; grid-column: 1; position: relative; }
.bc-axis span {
  position: absolute; right: 10px; transform: translateY(50%);
  font-size: 0.72rem; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.bc-plot {
  grid-row: 1; grid-column: 2; position: relative;
  display: flex; align-items: flex-end; gap: 2px;
  border-bottom: 1px solid var(--border-strong);
}
.bc-grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed var(--border); pointer-events: none; }
.bc-col {
  flex: 1 1 0; min-width: 0; height: 100%; position: relative;
  display: flex; align-items: flex-end; justify-content: center;
  border-radius: 4px 4px 0 0; outline: none;
}
.bc-col:hover, .bc-col:focus-visible { background: color-mix(in srgb, var(--text) 4%, transparent); }
.bc-col:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }
.bc-bar { width: 100%; max-width: 16px; background: var(--primary); border-radius: 4px 4px 0 0; }
.bc-col:hover .bc-bar, .bc-col:focus-visible .bc-bar { background: var(--primary-hover); }
.bc-xlabels { grid-row: 2; grid-column: 2; display: flex; gap: 2px; padding-top: 6px; }
.bc-xlabels span {
  flex: 1 1 0; min-width: 0; font-size: 0.72rem; color: var(--text-dim);
  white-space: nowrap; overflow: visible; text-align: left;
}
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; white-space: nowrap;
  background: var(--ink); color: var(--bg); border-radius: var(--radius-xs);
  padding: 6px 10px; font-size: 0.78rem; transform: translate(-50%, -100%);
}
.chart-tip strong { display: block; font-size: 0.92rem; color: #fffaf0; }
.chart-tip span { color: #cfc4ae; }
.chart-table { padding: 0 24px 16px; }
.chart-table summary { cursor: pointer; color: var(--text-muted); font-size: 0.82rem; width: max-content; }
.chart-table table { margin-top: 10px; max-width: 420px; }

/* ─── Agent: appearance preview ─────────────────────────────────────────── */
.widget-preview {
  --wp-primary: #2563eb; --wp-fg: #ffffff; --wp-bg: #f8fafc; --wp-surface: #ffffff; --wp-text: #111827;
  --wp-header-bg: var(--wp-primary); --wp-header-fg: var(--wp-fg); --wp-radius: 14px;
  --wp-font: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --wp-border: color-mix(in srgb, var(--wp-text) 13%, var(--wp-surface));
  --wp-backdrop: 0;
  position: relative; isolation: isolate;
  display: flex; flex-direction: column; align-items: flex-end; gap: 14px;
  padding: 22px; min-height: 440px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px dashed var(--border-strong);
}
.widget-preview::before {
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background: rgb(0 0 0 / var(--wp-backdrop)); transition: background .18s ease;
}
.widget-preview.pos-left { align-items: flex-start; }
.wp-panel {
  width: 300px; max-width: 100%; overflow: hidden; border-radius: calc(var(--wp-radius) + 2px);
  background: var(--wp-surface); color: var(--wp-text); border: 1px solid var(--wp-border); font-family: var(--wp-font);
  box-shadow: 0 12px 32px rgba(38, 34, 27, 0.12);
}
.wp-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--wp-header-bg); color: var(--wp-header-fg);
  border-bottom: 1px solid color-mix(in srgb, var(--wp-header-fg) 10%, transparent);
}
.wp-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: color-mix(in srgb, var(--wp-header-fg) 22%, transparent);
}
.wp-avatar img { width: 100%; height: 100%; object-fit: contain; background: #ffffff; display: block; }
.wp-title { font-weight: 700; font-size: 0.92rem; }
.wp-subtitle { font-size: 0.75rem; opacity: 0.85; }
.wp-body { display: flex; flex-direction: column; gap: 8px; padding: 14px; min-height: 170px; background: var(--wp-bg); }
.wp-bubble {
  max-width: 85%; padding: 8px 11px; font-size: 0.82rem;
  background: var(--wp-surface); color: var(--wp-text); border: 1px solid var(--wp-border);
  border-radius: var(--wp-radius) var(--wp-radius) var(--wp-radius) calc(var(--wp-radius) / 3);
}
.wp-disclosure {
  align-self: center; max-width: 94%; text-align: center; font-size: 0.72rem; line-height: 1.4;
  color: color-mix(in srgb, var(--wp-text) 72%, var(--wp-bg));
}
.wp-bubble.wp-user {
  align-self: flex-end; background: var(--wp-primary); color: var(--wp-fg); border-color: transparent;
  border-radius: var(--wp-radius) var(--wp-radius) calc(var(--wp-radius) / 3) var(--wp-radius);
}
.wp-input {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px 8px 14px; font-size: 0.8rem; background: var(--wp-surface);
  color: color-mix(in srgb, var(--wp-text) 50%, var(--wp-surface)); border-top: 1px solid var(--wp-border);
}
.wp-send {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; background: var(--wp-primary); color: var(--wp-fg);
}
.wp-launcher-row { display: flex; align-items: center; gap: 10px; }
.pos-left .wp-launcher-row { flex-direction: row-reverse; }
.wp-launcher {
  width: 54px; height: 54px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--wp-primary); color: var(--wp-fg);
}
.wp-launcher-text {
  padding: 7px 12px; font-size: 0.8rem; border-radius: 12px; font-family: var(--wp-font);
  background: var(--wp-surface); color: var(--wp-text); border: 1px solid var(--wp-border);
}
.avatar-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.avatar-thumb { width: 40px; height: 40px; border-radius: 50%; object-fit: contain; border: 1px solid var(--border); background: #ffffff; }
.branding-result {
  margin-top: 10px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.swatches { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.swatch { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.swatch i { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--border); display: inline-block; }

/* ─── Agent: test ───────────────────────────────────────────────────────── */
.test-layout { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 24px; align-items: start; }
.phone-frame {
  height: 640px; border: 1px solid var(--border); border-radius: 22px; overflow: hidden; background: var(--surface);
  box-shadow: 0 18px 40px rgba(38, 34, 27, 0.08);
}
.phone-frame iframe { display: block; width: 100%; height: 100%; border: 0; }

/* ─── Transcript ────────────────────────────────────────────────────────── */
.transcript { display: flex; flex-direction: column; gap: 16px; }
.t-msg { max-width: 82%; }
.t-user { align-self: flex-end; }
.t-meta { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; font-size: 0.75rem; color: var(--text-dim); }
.t-user .t-meta { justify-content: flex-end; }
.t-bubble {
  padding: 11px 14px; border-radius: 14px 14px 14px 4px; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface-2); border: 1px solid var(--border);
}
.t-user .t-bubble {
  border-radius: 14px 14px 4px 14px;
  background: var(--ink); color: #fffaf0; border-color: var(--ink);
}
.t-msg.is-flagged .t-bubble { opacity: 0.7; }

/* ─── Auth pages ────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand {
  display: flex; gap: 12px; align-items: center; justify-content: center; margin-bottom: 10px; color: var(--text);
}
.auth-card .brand .brand-mark { width: 40px; height: 40px; font-size: 22px; }
.auth-card .brand .brand-name { font-size: 32px; }
.auth-card .brand .dot { display: none; }
.auth-card h1 { text-align: center; font-size: 2.1rem; margin: 18px 0 6px; }
.auth-card .sub { text-align: center; color: var(--text-muted); margin-bottom: 24px; }
.auth-card .card { margin-bottom: 18px; }
.auth-card .card-body { padding: 26px; }
.auth-card .btn.primary { width: 100%; padding: 12px 18px; }
.auth-links { text-align: center; font-size: 0.85rem; color: var(--text-dim); }
.auth-links a { color: var(--text-muted); }

/* ─── Error page ────────────────────────────────────────────────────────── */
.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.error-card { text-align: center; max-width: 440px; }
.error-code { font-family: var(--font-display); font-size: 5.5rem; line-height: 1; color: var(--text); margin-bottom: 12px; }
.error-message { color: var(--text-muted); margin-bottom: 24px; font-size: 1.05rem; }

/* ─── Utilities ─────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.small { font-size: 0.82rem; }
.text-sm { font-size: 0.85rem; }
.font-medium { font-weight: 600; }
.text-danger { color: var(--danger); }
.mt-0 { margin-top: 0; } .mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; } .mt-20 { margin-top: 20px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-4 { margin-bottom: 4px; } .mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.right { text-align: right; }

/* ─── Job progress ──────────────────────────────────────────────────────── */
.job-status { margin-top: 14px; }
.job-progress-wrap { background: var(--surface-3); border-radius: 6px; height: 6px; overflow: hidden; }
.job-progress-bar { background: var(--primary); height: 100%; border-radius: 6px; transition: width 0.4s ease; }
.job-progress-bar.done { background: var(--success); }
.job-progress-bar.error { background: var(--danger); }
.job-events { margin-top: 8px; max-height: 180px; overflow-y: auto; font-size: 12.5px; line-height: 1.5; padding: 6px 0; }
.job-event { padding: 1px 0; color: var(--text-muted); }
.job-event.warn { color: var(--warning); }
.job-event.error { color: var(--danger); }
.job-cost { font-size: 12px; }

/* ─── Add-ons: knowledge base, tools, images ────────────────────────────── */
.kb-explorer {
  position: relative; display: grid; grid-template-columns: 280px minmax(0, 1fr);
  min-height: 580px; overflow: hidden;
}
.kb-tree { display: flex; flex-direction: column; min-width: 0; background: var(--surface-2); border-right: 1px solid var(--border); }
.kb-tree-head { display: flex; align-items: center; gap: 2px; padding: 8px 8px 8px 16px; min-height: 52px; border-bottom: 1px solid var(--border); }
.kb-tree-title { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.kb-tree-head .spacer { flex: 1; }
.kb-action { width: 32px; height: 32px; border-color: transparent; cursor: pointer; }
.kb-tree-empty { flex: 1; padding: 24px 16px; font-size: 0.85rem; color: var(--text-muted); }
.kb-files { list-style: none; margin: 0; padding: 6px; flex: 1; overflow-y: auto; max-height: 560px; }
.kb-file {
  display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: var(--radius-xs);
  color: var(--text); font-size: 0.86rem; line-height: 1.3;
}
.kb-file:hover { background: color-mix(in srgb, var(--text) 5%, transparent); text-decoration: none; color: var(--text); }
.kb-file.is-active { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }
.kb-ext {
  flex-shrink: 0; width: 38px; padding: 2px 0; text-align: center; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
}
.kb-file.is-active .kb-ext { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }
.kb-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--success); }
.kb-dot.is-failed { background: var(--danger); }
.kb-dot.is-pending, .kb-dot.is-processing { background: var(--warning); animation: kb-pulse 1.2s ease-in-out infinite; }
@keyframes kb-pulse { 50% { opacity: 0.35; } }
.kb-tree-foot { padding: 10px 16px 12px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--text-muted); }
.kb-storage { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.kb-tree-foot .meter { height: 5px; }

.kb-pane { display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.kb-editor-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.kb-pane-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 14px; min-height: 52px; border-bottom: 1px solid var(--border); }
.kb-pane-head input.kb-title-input {
  flex: 1; min-width: 0; padding: 5px 8px; border-color: transparent; background: transparent; box-shadow: none;
  font-family: var(--font-display); font-size: 1.25rem;
}
.kb-pane-head input.kb-title-input:hover:not(:disabled) { border-color: var(--border); }
.kb-meta { padding: 10px 22px 0; font-size: 0.78rem; color: var(--text-dim); }
.kb-pane textarea.kb-editor {
  flex: 1; min-height: 440px; padding: 14px 22px; border: 0; border-radius: 0; resize: none; box-shadow: none;
  background: var(--surface); font-family: var(--mono); font-size: 0.86rem; line-height: 1.65;
}
.kb-pane textarea.kb-editor:focus { outline: none; box-shadow: none; }
.kb-pane textarea.kb-editor[readonly] { color: var(--text-muted); }
.kb-pane-foot { display: flex; align-items: center; gap: 10px; padding: 8px 22px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--text-muted); }
.kb-pane-foot .spacer { flex: 1; }
.kb-unsaved { color: var(--warning); font-weight: 600; }
.kb-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 40px 24px; text-align: center; color: var(--text-muted);
}
.kb-empty strong { color: var(--text); font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; }
.kb-empty p { max-width: 420px; margin: 0; }
.kb-empty-icon { color: color-mix(in srgb, var(--primary) 60%, var(--text-muted)); }
.kb-empty .btn-row { justify-content: center; margin-top: 6px; }
.kb-drop-hint {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center; z-index: 2;
  font-weight: 600; color: var(--primary); border: 2px dashed var(--primary); border-radius: var(--radius);
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}
.kb-explorer.is-dragover .kb-drop-hint { display: flex; }
.kb-explorer.is-uploading .kb-drop-hint { display: flex; }
.kb-explorer.is-uploading .kb-drop-hint::before { content: 'Wird hochgeladen …'; }
.kb-explorer.is-uploading .kb-drop-hint { font-size: 0; }
.kb-explorer.is-uploading .kb-drop-hint::before { font-size: 0.95rem; }
@media (max-width: 900px) {
  .kb-explorer { grid-template-columns: 1fr; }
  .kb-tree { border-right: 0; border-bottom: 1px solid var(--border); }
  .kb-files { max-height: 240px; }
  .kb-pane textarea.kb-editor { min-height: 320px; }
}
.kb-preview-text {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.82rem; max-height: 240px; overflow-y: auto;
  padding: 8px 10px; margin-top: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.kb-results { margin: 16px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 12px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-fields select { min-width: 110px; }
.tool-log li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.tool-log li:first-child { padding-top: 0; }
.tool-log li:last-child { border-bottom: none; padding-bottom: 0; }
.t-image { margin-bottom: 6px; }
.t-user .t-image { text-align: right; }
.t-image img { max-width: 240px; max-height: 240px; border-radius: 10px; border: 1px solid var(--border); display: inline-block; }
.t-image-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; text-align: left; }
.t-image-desc summary { cursor: pointer; }
.scroll-box { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.scroll-box table.data th { position: sticky; top: 0; }

/* Tool cards (admin + customer) */
.tool-card .card-head { align-items: flex-start; }
.tool-card .tool-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--primary);
}
.tool-card .tool-title { flex: 1; min-width: 0; }
.tool-card .tool-title p { margin: 2px 0 0; font-size: 0.86rem; color: var(--text-muted); }

/* ─── Auto-prompt preview modal ─────────────────────────────────────────── */
.ap-modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(31, 27, 22, 0.45); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.ap-modal-overlay[hidden] { display: none; }
.ap-modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  width: 100%; max-width: 780px; max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.ap-modal-head { display: flex; align-items: center; gap: 12px; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.ap-modal-head h2 { flex: 1; }
.ap-modal-close {
  background: none; border: none; color: var(--text-muted); font-size: 1.4rem;
  cursor: pointer; padding: 4px 10px; line-height: 1; border-radius: 999px;
}
.ap-modal-close:hover { background: var(--surface-2); color: var(--text); }
.ap-modal-body { flex: 1; overflow-y: auto; padding: 22px 24px; display: flex; flex-direction: column; gap: 22px; }
.ap-modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }
.ap-check-header { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ap-section h3 { font-size: 0.78rem; font-weight: 600; margin: 0 0 8px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.ap-preview-text {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.82rem; line-height: 1.55;
  max-height: 320px; overflow-y: auto;
  padding: 12px 14px; margin: 0; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: var(--mono); color: var(--text);
}
.ap-preview-inline { font-size: 0.88rem; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.ap-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ap-tag { font-size: 0.8rem; padding: 4px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; color: var(--text); }
.ap-missing-list { padding-left: 20px; margin: 0; font-size: 0.85rem; color: var(--warning); }
.ap-missing-list li { margin-bottom: 4px; }
.ap-kb-entries { display: flex; flex-direction: column; gap: 10px; }
.ap-kb-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; background: var(--surface-2); }
.ap-kb-check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.88rem; }
.ap-kb-check input[type="checkbox"] { margin: 0; }
.ap-kb-toggle { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.78rem; padding: 2px 0; margin-left: 4px; }
.ap-kb-toggle:hover { text-decoration: underline; }
.ap-kb-content {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.78rem; line-height: 1.5;
  max-height: 200px; overflow-y: auto;
  padding: 10px 12px; margin: 8px 0 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: var(--mono); color: var(--text);
}

/* ─── Funnel flow ───────────────────────────────────────────────────────── */
.flow-steps {
  list-style: none; margin: 0 0 14px; padding: 0;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
}
.flow-step { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0 6px; text-align: center; }
.flow-label { color: var(--text-muted); font-size: 0.78rem; font-weight: 500; }
.flow-value { font-family: var(--font-display); font-size: 2.1rem; line-height: 1.15; font-variant-numeric: lining-nums; }
.flow-rate { color: var(--text-dim); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.flow-chart { display: block; width: 100%; height: auto; }
.flow-node { fill: var(--primary); }
.flow-keep { fill: var(--primary); fill-opacity: 0.28; transition: fill-opacity 0.12s; }
.flow-keep:hover { fill-opacity: 0.42; }
.flow-drop { transition: opacity 0.12s; }
.flow-drop:hover { opacity: 0.6; }
.flow-fade-start { stop-color: var(--text-dim); stop-opacity: 0.26; }
.flow-fade-end { stop-color: var(--text-dim); stop-opacity: 0.02; }
.flow-drops { position: relative; height: 38px; margin-top: 6px; }
.flow-drop-label {
  position: absolute; top: 0; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  font-size: 0.75rem; line-height: 1.3; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.flow-drop-label strong { color: var(--text); font-weight: 600; }
.flow-conversion { color: var(--text); font-size: 0.95rem; margin-left: 4px; }
.funnel-rate { display: inline-block; min-width: 3.4em; margin-left: 6px; text-align: right; color: var(--text-dim); font-size: 0.75rem; }
.mini-funnel { display: inline-flex; align-items: flex-end; gap: 3px; height: 22px; vertical-align: middle; }
.mini-funnel i { display: block; width: 7px; min-height: 2px; border-radius: 2px 2px 0 0; background: var(--primary); }
.mini-funnel i + i { opacity: 0.8; }
.activity-path code { overflow-wrap: anywhere; }

/* ─── Legal pages ───────────────────────────────────────────────────────── */
.legal-wrap { max-width: 760px; margin: 0 auto; padding: 56px 24px 80px; }
.legal-wrap h1 { margin: 0 0 8px; }
.legal-wrap .meta { color: var(--text-dim); font-size: 14px; margin-bottom: 32px; }
.legal-wrap .content { line-height: 1.7; font-size: 15.5px; }
.legal-wrap .content h2 { margin: 32px 0 12px; }
.legal-wrap .content h3 { margin: 24px 0 8px; }
.legal-wrap .content ul, .legal-wrap .content ol { margin: 0 0 14px; padding-left: 24px; }
/* Demo links (admin list + public page) */
.demo-link-cell { min-width: 320px; }
.demo-link-cell .val { word-break: break-all; }
.demo-wrap { max-width: 1040px; margin: 0 auto; padding: 48px 24px 64px; }
.demo-wrap .brand { display: flex; gap: 10px; align-items: baseline; }
.demo-wrap h1 { margin: 0 0 8px; }
.demo-wrap .page-lead { margin-bottom: 24px; }
@media (max-width: 640px) { .demo-wrap { padding: 28px 16px 48px; } }

.legal-nav { display: flex; gap: 16px; margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border); font-size: 14px; }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .content { padding: 36px 32px 64px; }
  .view-bar { padding: 9px 32px; }
  .grid-main { grid-template-columns: 1fr; gap: 8px; }
}
@media (max-width: 980px) {
  .grid-2, .grid-sidebar, .test-layout { grid-template-columns: 1fr; }
  .form-grid.cols-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .mobile-bar { display: flex; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 24px 16px 56px; }
  .view-bar { position: static; padding: 10px 16px; gap: 10px; }
  .view-bar .view-bar-text .muted { display: none; }
  .view-bar .view-bar-text { min-width: 0; flex-basis: calc(100% - 32px); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 16px; }
  .stat .label { font-size: 0.78rem; }
  h1 { font-size: 2.1rem; }
  .page-head { margin-bottom: 24px; }
  .stat .value, .stat .value.sm { font-size: 1.8rem; }
  .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { border-bottom: none; padding-bottom: 0; }
  .card-head { padding: 18px 18px 0; }
  .card-body { padding: 18px; }
  table.data th:first-child, table.data td:first-child { padding-left: 18px; }
  table.data th:last-child, table.data td:last-child { padding-right: 18px; }
  .bar-chart { grid-template-rows: 150px auto; }
  .flow-value { font-size: 1.4rem; }
  .flow-label { font-size: 0.66rem; }
  .flow-rate, .flow-drop-label { font-size: 0.7rem; }
}

/* ═══ Cwik Mailbox ═══════════════════════════════════════════════════════ */

[hidden] { display: none !important; }

.justify-center { justify-content: center; }
.center { text-align: center; }
.btn.lg { padding: 13px 26px; font-size: 0.95rem; }
.switch-row.compact { margin-top: 12px; text-align: left; font-size: 0.86rem; }

/* Browser test call */
.test-call {
  display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 24px; align-items: start;
}
.test-call .debug-panel { grid-column: 1 / -1; }
.call-stage { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 12px 0 4px; }
.call-orb { position: relative; width: 132px; height: 132px; margin: 8px 0 18px; }
.orb-ring, .orb-core { position: absolute; inset: 0; border-radius: 50%; }
.orb-ring { background: radial-gradient(circle, color-mix(in srgb, var(--primary) 26%, transparent) 0%, transparent 70%); transform: scale(0.9); opacity: 0; }
.orb-core {
  inset: 22px; display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: #fffaf0; box-shadow: 0 10px 30px rgba(38, 34, 27, 0.18);
  transition: background 0.3s, transform 0.3s;
}
.call-orb[data-state='connecting'] .orb-ring { opacity: 1; animation: orb-pulse 1.4s ease-in-out infinite; }
.call-orb[data-state='listening'] .orb-core { background: var(--success); }
.call-orb[data-state='listening'] .orb-ring { opacity: 0.6; }
.call-orb[data-state='thinking'] .orb-core { background: var(--info); }
.call-orb[data-state='thinking'] .orb-ring { opacity: 1; animation: orb-pulse 0.9s ease-in-out infinite; }
.call-orb[data-state='speaking'] .orb-core { background: var(--primary); transform: scale(1.04); }
.call-orb[data-state='speaking'] .orb-ring { opacity: 1; animation: orb-pulse 0.6s ease-in-out infinite; }
.call-orb[data-state='error'] .orb-core { background: var(--danger); }
.call-orb[data-state='ended'] .orb-core { background: var(--text-dim); }
@keyframes orb-pulse { 0%, 100% { transform: scale(0.88); } 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .orb-ring { animation: none !important; } }
.call-status { font-family: var(--font-display); font-size: 1.45rem; line-height: 1.2; min-height: 1.8rem; }
.call-timer { color: var(--text-dim); margin: 4px 0 14px; font-size: 0.95rem; }
.level { width: 180px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 18px; }
.level span { display: block; height: 100%; width: 0; background: var(--success); transition: width 0.08s linear; }
.live-transcript { min-height: 320px; max-height: 560px; overflow-y: auto; padding-right: 4px; }
.t-note { align-self: center; font-size: 0.82rem; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); }
.t-note.ok { background: var(--success-bg); color: var(--success); }
.t-note.info { background: var(--info-bg); color: var(--info); }
.t-note.err { background: var(--danger-bg); color: var(--danger); }
.t-msg.t-tool { align-self: center; max-width: 100%; }
.t-msg.t-tool .t-bubble { background: none; border-style: dashed; font-family: var(--mono); font-size: 0.78rem; color: var(--text-muted); }
.call-result { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.event-log { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.event-log li { padding: 4px 0; border-bottom: 1px dashed var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.event-log li.err { color: var(--danger); }
.event-log li.tool { color: var(--info); }
.event-log li.usage { color: var(--text-dim); }
.prompt-box {
  white-space: pre-wrap; font-family: var(--mono); font-size: 0.8rem; line-height: 1.55;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; max-height: 520px; overflow: auto; margin: 10px 0 0;
}

/* Messages inbox */
.msg-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 18px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.msg-card:last-child { border-bottom: 0; }
.msg-card.is-done { opacity: 0.62; }
.msg-card.is-urgent { box-shadow: inset 4px 0 0 var(--danger); }
.msg-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.msg-head strong { font-size: 1.02rem; }
.msg-concern { grid-column: 1 / -1; white-space: pre-wrap; }
.msg-meta { grid-column: 1 / -1; font-size: 0.8rem; color: var(--text-dim); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.msg-actions { display: flex; gap: 8px; align-items: flex-start; }
.phone-link { font-family: var(--mono); font-weight: 600; }

/* Calls per hour of day */
.hour-chart { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; align-items: end; height: 110px; padding: 8px 4px 0; }
.hour-chart .h { background: color-mix(in srgb, var(--primary) 70%, var(--surface)); border-radius: 3px 3px 0 0; min-height: 2px; }
.hour-chart .h.zero { background: var(--surface-2); }
.hour-labels { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; font-size: 0.68rem; color: var(--text-dim); padding: 4px 4px 0; }
.hour-labels span { text-align: center; }

.hours-grid { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px 16px; align-items: center; }
.hours-grid label { font-weight: 500; }
.setup-steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.setup-steps li { counter-increment: step; position: relative; padding: 0 0 14px 38px; }
.setup-steps li::before {
  content: counter(step); position: absolute; left: 0; top: -1px; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 700;
  background: var(--surface-2); color: var(--text-muted);
}
.setup-steps li.done::before { content: '✓'; background: var(--success-bg); color: var(--success); }
.status-list { list-style: none; padding: 0; margin: 0; }
.status-list li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.status-list li:last-child { border-bottom: 0; }
.status-list .grow { flex: 1; min-width: 0; }
.price-table input { width: 84px; padding: 6px 8px; font-size: 0.84rem; }
.price-table input.model { width: 180px; }

@media (max-width: 980px) {
  .test-call { grid-template-columns: 1fr; }
  .hours-grid { grid-template-columns: 1fr; gap: 4px; }
}
