/* ==========================================================================
   Supporter Design System — foundation tokens + shared components
   Used by: marketing site (index.html), brand book (brand.html), product UI (app.html)
   ========================================================================== */

/* ---------- Tokens: light (default) ---------- */
:root {
  color-scheme: light;

  /* Grounds */
  --paper: #F4F6FB;
  --surface: #FFFFFF;
  --surface-2: #EDF0F7;
  --surface-3: #E4E8F2;

  /* Ink */
  --ink: #121A2E;
  --ink-2: #4B5469;
  --ink-3: #636C80;
  --line: #E1E5EE;
  --line-2: #CBD2E1;

  /* Brand — "Signal" blue: Supporter, AI, actions */
  --blue: #2749E6;
  --logo-tile: #2749E6;
  --blue-hover: #1D3BC6;
  --blue-tint: #EAEEFF;
  --blue-line: #C3CDFF;
  --on-blue: #FFFFFF;

  /* Human — "Warm" apricot: customers, people, the origin of every thread */
  --warm: #EC8747;
  --warm-tint: #FFEBDD;
  --warm-line: #F6CBAD;

  /* Semantic */
  /* Крапки, обводки й заливки статусів */
  --ok: #1B9A61;      --ok-tint: #E1F5EA;
  --warn: #C98400;    --warn-tint: #FFF1D3;
  --bad: #D6404E;     --bad-tint: #FDE5E8;
  /* Ті самі статуси як ТЕКСТ: світлі відтінки дають лише 2,8–3,7:1 на своїй
     підкладці, тому напис завжди бере темніший варіант (6:1 і вище). */
  --ok-text: #0F6B42; --warn-text: #7E5200; --bad-text: #A81D2B;

  /* Channels (tints only; glyphs stay ink) */
  --ch-telegram: #229ED9;
  --ch-instagram: #D62976;
  --ch-instagram-grad: linear-gradient(135deg, #F9CE34 0%, #EE2A7B 48%, #6228D7 100%);
  --ch-whatsapp: #25D366;
  --ch-viber: #7360F2;
  --ch-email: #5B657A;
  --ch-web: #2749E6;

  /* Dark band (final CTA, code blocks): stays dark in both themes */
  --band-bg: #121A2E;
  --band-fg: #FFFFFF;
  --band-muted: #B7BFD3;
  --band-line: #4A536B;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(18, 26, 46, .06);
  --shadow-2: 0 6px 20px -6px rgba(18, 26, 46, .14), 0 1px 2px rgba(18, 26, 46, .06);
  --shadow-3: 0 32px 64px -24px rgba(18, 26, 46, .28), 0 2px 6px rgba(18, 26, 46, .06);
  --ring: 0 0 0 3px var(--blue-line);

  /* Radius */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-bubble: 18px;
  --r-tail: 4px;     /* the "speaking corner" of a bubble */
  --r-pill: 999px;

  /* Spacing (4-pt) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px; --s20: 80px; --s28: 112px;

  /* Type */
  --font: 'Onest', 'Segoe UI', system-ui, -apple-system, Helvetica, Arial, sans-serif;
  --font-voice: 'Literata', Georgia, 'Times New Roman', serif; /* the customer's voice on the site */
  --t-xs: 0.75rem;   /* 12 */
  --t-sm: 0.8125rem; /* 13 */
  --t-ui: 0.875rem;  /* 14 — product UI body */
  --t-md: 1rem;      /* 16 */
  --t-body: 1.0625rem; /* 17 — marketing body */
  --t-lg: 1.25rem;
  --t-xl: 1.5rem;
  --t-h2: clamp(1.9rem, 1.2rem + 2.6vw, 2.75rem);
  --t-display: clamp(2.4rem, 1.4rem + 4.6vw, 4.6rem);

  --wrap: 1180px;
  --gutter: clamp(20px, 4vw, 40px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0C111F;
    --surface: #141A2B;
    --surface-2: #1B2236;
    --surface-3: #232B42;
    --ink: #EDF0F8;
    --ink-2: #AEB6C9;
    --ink-3: #8A93A9;
    --line: #262E45;
    --line-2: #34405E;
    --blue: #7188FF;
    --logo-tile: #3557F5;
    --blue-hover: #8A9DFF;
    --blue-tint: #1A2450;
    --blue-line: #33448C;
    --on-blue: #0C111F;
    --warm: #F2985E;
    --warm-tint: #3A2617;
    --warm-line: #6A3F21;
    --ok: #3DC486;  --ok-tint: #12321F;
    --warn: #E8A83A; --warn-tint: #3A2B0C;
    --bad: #F0616D; --bad-tint: #3E1418;
    /* На темних підкладках самі кольори вже дають 5–6,6:1 */
    --ok-text: #3DC486; --warn-text: #E8A83A; --bad-text: #F0616D;
    --band-bg: #1A2240;
    --band-line: #3C4870;
    --ch-email: #98A1B6;
    --ch-web: #7188FF;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 6px 20px -6px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
    --shadow-3: 0 32px 64px -24px rgba(0,0,0,.7), 0 2px 6px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0C111F;
  --surface: #141A2B;
  --surface-2: #1B2236;
  --surface-3: #232B42;
  --ink: #EDF0F8;
  --ink-2: #AEB6C9;
  --ink-3: #8A93A9;
  --line: #262E45;
  --line-2: #34405E;
  --blue: #7188FF;
  --logo-tile: #3557F5;
  --blue-hover: #8A9DFF;
  --blue-tint: #1A2450;
  --blue-line: #33448C;
  --on-blue: #0C111F;
  --warm: #F2985E;
  --warm-tint: #3A2617;
  --warm-line: #6A3F21;
  --ok: #3DC486;  --ok-tint: #12321F;
  --warn: #E8A83A; --warn-tint: #3A2B0C;
  --bad: #F0616D; --bad-tint: #3E1418;
  --ok-text: #3DC486; --warn-text: #E8A83A; --bad-text: #F0616D;
  --band-bg: #1A2240;
  --band-line: #3C4870;
  --ch-email: #98A1B6;
  --ch-web: #7188FF;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 6px 20px -6px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow-3: 0 32px 64px -24px rgba(0,0,0,.7), 0 2px 6px rgba(0,0,0,.4);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.12; text-wrap: balance; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: var(--r-xs); }
.tnum { font-variant-numeric: tabular-nums; }
.voice { font-family: var(--font-voice); font-style: italic; font-weight: 400; letter-spacing: 0; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }

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

/* ---------- Icons ---------- */
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ic.sm { width: 14px; height: 14px; }
.ic.lg { width: 22px; height: 22px; }
.ic-fill { fill: currentColor; stroke: none; }

/* ---------- Logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.03em; font-size: 1.25rem; color: var(--ink); }
.logo svg { width: 28px; height: 28px; }
/* The mark keeps its own colours in both themes: only the tile shifts a step lighter on dark. */
.logo-mark-bg { fill: var(--logo-tile); }
.logo-mark-s { fill: none; stroke: #FFFFFF; stroke-width: 3.4; stroke-linecap: round; }
.logo-mark-dot { fill: #EC8747; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px;
  border-radius: var(--r-md); border: 1px solid transparent;
  font-weight: 600; font-size: var(--t-md); line-height: 1; white-space: nowrap;
  cursor: pointer; transition: background .15s ease, border-color .15s ease, color .15s ease, transform .05s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: var(--on-blue); }
.btn-primary:hover { background: var(--blue-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); box-shadow: var(--shadow-1); }
.btn-secondary:hover { border-color: var(--ink-3); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-warm { background: var(--warm-tint); color: var(--ink); border-color: var(--warm-line); }
.btn-lg { height: 52px; padding: 0 24px; font-size: var(--t-body); border-radius: 14px; }
.btn-sm { height: 34px; padding: 0 12px; font-size: var(--t-ui); border-radius: var(--r-sm); }
.btn-xs { height: 28px; padding: 0 10px; font-size: var(--t-sm); border-radius: var(--r-xs); }
.btn .ic { width: 16px; height: 16px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Inputs ---------- */
.field { display: grid; gap: 6px; }
.field > label { font-size: var(--t-ui); font-weight: 600; color: var(--ink-2); }
.input {
  width: 100%; height: 44px; padding: 0 14px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: var(--r-md);
  font: inherit; font-size: var(--t-md);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: var(--ink-3); }
.input:hover { border-color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--blue); box-shadow: var(--ring); }
.input-wrap { position: relative; }
.input-wrap .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.input-wrap .input { padding-left: 40px; }
textarea.input { height: auto; min-height: 96px; padding: 12px 14px; line-height: 1.5; resize: vertical; }
.input.sm { height: 36px; font-size: var(--t-ui); border-radius: var(--r-sm); }
.help { font-size: var(--t-sm); color: var(--ink-3); }
.help.err { color: var(--bad-text); }
.input.err { border-color: var(--bad); }

/* ---------- Badges / chips / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: var(--t-xs); font-weight: 600; letter-spacing: .01em;
  background: var(--surface-2); color: var(--ink-2);
}
.badge-blue { background: var(--blue-tint); color: var(--blue); }
.badge-warm { background: var(--warm-tint); color: #A54E1A; }
:root[data-theme="dark"] .badge-warm { color: var(--warm); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge-warm { color: var(--warm); } }
.badge-ok { background: var(--ok-tint); color: var(--ok-text); }
.badge-warn { background: var(--warn-tint); color: var(--warn-text); }
.badge-bad { background: var(--bad-tint); color: var(--bad-text); }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px 0 10px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: var(--surface);
  font-size: var(--t-ui); font-weight: 500; color: var(--ink);
}
.chip .ic { width: 16px; height: 16px; color: var(--ink-2); }

.status { display: inline-flex; align-items: center; gap: 7px; font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.status-open::before { background: var(--blue); }
.status-waiting::before { background: var(--warn); }
.status-resolved::before { background: var(--ok); }
.status-urgent::before { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-tint); }
.status-snoozed::before { background: var(--ink-3); }

/* Channel marks: a circle tinted per channel, brand-style glyph stays white */
.ch { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; flex: none; }
.ch .ic { width: 15px; height: 15px; stroke-width: 2; color: #fff; }
.ch.lg { width: 42px; height: 42px; border-radius: 12px; box-shadow: 0 1px 2px rgba(18, 26, 46, .18), inset 0 1px 0 rgba(255, 255, 255, .18); }
.ch.lg .ic { width: 25px; height: 25px; }
.ch.xl { width: 56px; height: 56px; border-radius: 16px; box-shadow: 0 2px 6px rgba(18, 26, 46, .2), inset 0 1px 0 rgba(255, 255, 255, .18); }
.ch.xl .ic { width: 33px; height: 33px; }
.chip.big { height: 48px; padding: 0 18px 0 8px; gap: 12px; font-size: var(--t-md); font-weight: 600; border-radius: 14px; }
.ch-telegram { background: var(--ch-telegram); }
.ch-instagram { background: var(--ch-instagram); background-image: var(--ch-instagram-grad); }
.ch-whatsapp { background: var(--ch-whatsapp); }
.ch-viber { background: var(--ch-viber); }
.ch-email { background: var(--ch-email); }
.ch-web { background: var(--ch-web); }

/* ---------- Avatar ---------- */
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--warm-tint); color: var(--ink); font-size: var(--t-sm); font-weight: 700; flex: none; letter-spacing: 0; }
.avatar.agent { background: var(--blue-tint); color: var(--blue); }
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.lg { width: 44px; height: 44px; font-size: var(--t-md); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.card-pad { padding: var(--s5); }
.card-raised { box-shadow: var(--shadow-2); border-color: transparent; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-3); overflow: hidden; }

/* ---------- Conversation / chat ---------- */
.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 10px; max-width: 78%; align-items: flex-end; }
.msg.out { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  padding: 10px 14px; border-radius: var(--r-bubble);
  font-size: var(--t-ui); line-height: 1.45; color: var(--ink);
  background: var(--warm-tint); border: 1px solid var(--warm-line);
  border-bottom-left-radius: var(--r-tail);
}
.msg.out .bubble { background: var(--blue); color: var(--on-blue); border-color: var(--blue); border-bottom-left-radius: var(--r-bubble); border-bottom-right-radius: var(--r-tail); }
.msg-meta { font-size: var(--t-xs); color: var(--ink-3); margin-top: 4px; }
.msg.out .msg-meta { text-align: right; }
.msg-body { display: grid; gap: 2px; min-width: 0; }
.msg.out .msg-body { justify-items: end; }
.msg.system { align-self: center; max-width: 100%; }
.msg.system .bubble { background: transparent; border: none; color: var(--ink-3); font-size: var(--t-xs); padding: 4px 8px; }

/* AI suggestion card */
.ai-card { background: var(--blue-tint); border: 1px solid var(--blue-line); border-radius: var(--r-lg); padding: 12px 14px 12px; display: grid; gap: 10px; color: var(--ink); }
.ai-card-head { display: flex; align-items: center; gap: 8px; font-size: var(--t-sm); font-weight: 600; color: var(--blue); }
.ai-card-head .ic { width: 15px; height: 15px; }
.ai-card-body { font-size: var(--t-ui); line-height: 1.5; }
.ai-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sources { display: flex; gap: 6px; flex-wrap: wrap; }
.source { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 9px 0 7px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line-2); font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); }
.source .ic { width: 12px; height: 12px; color: var(--blue); }
.source b { color: var(--ink); font-weight: 600; }

/* Composer */
.composer { display: flex; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--surface); }
.composer .input { border: none; height: 36px; padding: 0 6px; box-shadow: none; background: transparent; }
.composer .input:focus { box-shadow: none; }

/* Conversation list row */
.convo { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.convo > div { min-width: 0; }
.convo:hover { background: var(--surface-2); }
.convo.active { background: var(--blue-tint); }
.convo-av { position: relative; }
.convo-av .ch { position: absolute; right: -4px; bottom: -3px; width: 16px; height: 16px; box-shadow: 0 0 0 2px var(--surface); }
.convo-av .ch .ic { width: 9px; height: 9px; }
.convo-name { font-size: var(--t-ui); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.convo-prev { font-size: var(--t-sm); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.convo-time { font-size: var(--t-xs); color: var(--ink-3); text-align: right; white-space: nowrap; }
.convo-count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--blue); color: var(--on-blue); font-size: 11px; font-weight: 700; margin-top: 6px; margin-left: auto; }

/* ---------- Tickets ---------- */
.ticket { display: grid; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.ticket-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ticket-id { font-size: var(--t-xs); font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ticket-title { font-size: var(--t-ui); font-weight: 600; line-height: 1.35; }
.ticket-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: var(--t-xs); color: var(--ink-3); }
.prio { display: inline-flex; align-items: center; gap: 5px; font-size: var(--t-xs); font-weight: 600; }
.prio i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.prio-high i { background: var(--bad); } .prio-med i { background: var(--warn); } .prio-low i { background: var(--ink-3); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: var(--t-ui); }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; font-weight: 500; }

/* ---------- Knowledge ---------- */
.kb-answer { display: grid; gap: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.kb-q { font-size: var(--t-md); font-weight: 600; }
.kb-a { font-size: var(--t-ui); color: var(--ink-2); line-height: 1.55; }
.kb-doc { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.kb-doc-ic { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink-2); }
.kb-doc-title { font-size: var(--t-ui); font-weight: 600; }
.kb-doc-meta { font-size: var(--t-xs); color: var(--ink-3); }

/* ---------- Nav (shared shell) ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s6); height: 64px; }
.nav-links { display: flex; gap: 4px; }
.nav-links a { display: inline-flex; align-items: center; height: 36px; padding: 0 12px; border-radius: var(--r-sm); font-size: var(--t-md); font-weight: 500; color: var(--ink-2); }
.nav-links a:hover, .nav-links a[aria-current] { color: var(--ink); background: var(--surface-2); }

/* Tabs / segmented */
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); gap: 2px; }
.seg button { height: 30px; padding: 0 12px; border: none; border-radius: 7px; background: transparent; color: var(--ink-2); font-size: var(--t-ui); font-weight: 600; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* Toggle */
.toggle { position: relative; width: 40px; height: 24px; border-radius: 12px; background: var(--line-2); border: none; cursor: pointer; transition: background .15s ease; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s ease; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle[aria-checked="true"] { background: var(--blue); }
.toggle[aria-checked="true"]::after { transform: translateX(16px); }

/* ---------- Layout helpers ---------- */
.wrap { width: min(var(--wrap), 100% - 2 * var(--gutter)); margin-inline: auto; }
.stack { display: grid; gap: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.divider { height: 1px; background: var(--line); }

/* Credit link: "built by the Systemer team" */
.made-by { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-ui); font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line-2); padding-bottom: 1px; transition: color .15s ease, border-color .15s ease; }
.made-by:hover { color: var(--blue); border-color: var(--blue); }
.made-by .ic { width: 13px; height: 13px; color: var(--ink-3); }
.made-by:hover .ic { color: var(--blue); }
