/* Nudge Support — design system.
   Tokens derived from nudge-prototype (styles.css + figma-export/tokens.json):
   warm-neutral monochrome canvas, color = signal not decoration, one brand
   color on every CTA, hierarchy by intensity not hue. Minimal cards, one focal
   signal, no inverted surfaces. Theme via [data-theme]. */

:root {
  /* brand / CTA — warm near-black anthracite */
  --brand: #1F1F1F;
  --brand-strong: #0D0D0D;
  --brand-ink: #F5F3EE;

  /* accent = "look here", warm ember */
  --accent: #D97706;
  --accent-soft: rgba(217, 118, 6, 0.14);

  /* severity palette (load-bearing, used sparingly) */
  --sev1: #B91C1C;   /* critical  */
  --sev2: #DC2626;   /* high      */
  --sev3: #D97706;   /* medium    */
  --sev4: #6B8FAE;   /* low        (slate-blue, calm) */
  --good: #7DA690;   /* resolved / verified */
  --info: #6B8FAE;

  --radius-card: 22px;
  --radius-section: 14px;
  --radius-pill: 999px;
  --radius-input: 12px;

  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --maxw: 1160px;
}

/* ---------- light (default) ---------- */
:root, [data-theme="light"] {
  --bg: #FDFDFC;
  --surface: #FFFFFF;
  --surface-2: #F7F6F3;
  --surface-3: #F0EEE9;
  --border: #E7E4DD;
  --border-strong: #D8D4CB;
  --text: #1C1B19;
  --text-2: #55524C;
  --text-3: #8A867E;
  --cta-bg: #2B2723;
  --cta-ink: #F5F3EE;
  --shadow-card: 0 1px 2px rgba(28, 27, 25, 0.04), 0 6px 20px rgba(28, 27, 25, 0.05);
  --shadow-raised: 0 2px 4px rgba(28, 27, 25, 0.06), 0 14px 40px rgba(28, 27, 25, 0.09);
}

/* ---------- dark (matte grey, not near-black) ---------- */
[data-theme="dark"] {
  --bg: #121212;
  --surface: #1A1A1A;
  --surface-2: #212121;
  --surface-3: #292929;
  --border: #2E2E2E;
  --border-strong: #3A3A3A;
  --text: #F1EFEA;
  --text-2: #B7B3AB;
  --text-3: #7E7A72;
  --cta-bg: #DDD8C9;
  --cta-ink: #1A1815;
  --accent-soft: rgba(217, 118, 6, 0.20);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.34);
  --shadow-raised: 0 2px 6px rgba(0, 0, 0, 0.5), 0 18px 46px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  font-feature-settings: "ss01", "cv11", "calt";
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }
.mono { font-family: var(--font-mono); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* ---------- app shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 30;
}
.brand-lockup { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-dots { display: inline-flex; gap: 3px; }
.brand-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text); display: block; }
.brand-dots i:nth-child(1) { opacity: .38; } .brand-dots i:nth-child(2) { opacity: .68; }
.brand-sub { color: var(--text-3); font-weight: 500; font-size: 13px; }
.topbar-spacer { flex: 1; }

/* segmented role/nav toggle */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2);
  font-size: 13px; font-weight: 600; padding: 6px 14px; border-radius: var(--radius-pill);
  transition: background .15s, color .15s;
}
.seg button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }

.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

.main { flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 28px 24px 64px; }
.page-head { margin-bottom: 22px; }
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin: 4px 0 4px; }
.page-sub { color: var(--text-2); font-size: 14px; margin: 0; max-width: 60ch; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: var(--radius-pill);
  padding: 9px 16px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 7px;
  transition: transform .06s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--cta-bg); color: var(--cta-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- cards (minimal, equal-height) ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); padding: 18px;
}
.grid { display: grid; gap: 14px; align-items: stretch; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* stat tile */
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-family: var(--font-mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.stat-value { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.stat-sub { font-size: 12px; color: var(--text-2); }

/* ---------- severity chip ---------- */
.sev-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; letter-spacing: .04em;
  padding: 3px 9px; border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}
.sev-dot { width: 8px; height: 8px; border-radius: 50%; }
.sev-1 .sev-dot { background: var(--sev1); } .sev-1 { color: var(--sev1); border-color: color-mix(in srgb, var(--sev1) 30%, var(--border)); }
.sev-2 .sev-dot { background: var(--sev2); } .sev-2 { color: var(--sev2); border-color: color-mix(in srgb, var(--sev2) 30%, var(--border)); }
.sev-3 .sev-dot { background: var(--sev3); } .sev-3 { color: var(--sev3); border-color: color-mix(in srgb, var(--sev3) 30%, var(--border)); }
.sev-4 .sev-dot { background: var(--sev4); } .sev-4 { color: var(--sev4); border-color: color-mix(in srgb, var(--sev4) 30%, var(--border)); }

/* status pill (friendly, calm) */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.status-pill .sev-dot { width: 7px; height: 7px; }
.status-logged .sev-dot { background: var(--text-3); }
.status-progress .sev-dot { background: var(--accent); }
.status-resolved { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, var(--border)); }
.status-resolved .sev-dot { background: var(--good); }

/* ---------- ticket list ---------- */
.ticket { display: flex; flex-direction: column; gap: 12px; }

.ticket-card {
  border: 1px solid var(--border); border-radius: var(--radius-section);
  background: var(--surface); overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.ticket-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-card); }
.ticket-card.is-open { border-color: var(--border-strong); box-shadow: var(--shadow-card); }

.ticket-row {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center;
  padding: 14px 16px;
}
.ticket-row-btn {
  width: 100%; border: 0; background: transparent; text-align: left; font: inherit; color: inherit;
}
.ticket-row-btn:hover { background: var(--surface-2); }
.ticket-row-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ticket-main { display: flex; flex-direction: column; min-width: 0; }
.ticket-key { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); }
.ticket-title { font-weight: 600; font-size: 14px; }
.ticket-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 6px; color: var(--text-3); font-size: 12px; }
.ticket-eta { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12px; }
.ticket-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.ticket-chev { color: var(--text-3); font-size: 15px; transition: transform .18s ease; line-height: 1; }
.ticket-chev.is-open { transform: rotate(180deg); }

/* expanded detail */
.ticket-detail { border-top: 1px solid var(--border); background: var(--surface-2); padding: 18px 16px; }
.ticket-detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 26px; align-items: start; }
@media (max-width: 820px) { .ticket-detail-grid { grid-template-columns: 1fr; gap: 20px; } }
.td-h { margin-bottom: 12px; }
.td-col { min-width: 0; }

.td-dl { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.td-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; align-items: baseline; }
@media (max-width: 560px) { .td-row { grid-template-columns: 1fr; gap: 2px; } }
.td-row dt { font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.td-row dd { margin: 0; font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
.td-row dd.is-empty { color: var(--text-3); font-style: italic; }
.td-actions { margin-top: 16px; display: flex; gap: 8px; align-items: center; }

/* status timeline */
.tl { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.tl-item { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 10px; padding-bottom: 16px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ""; position: absolute; left: 6px; top: 14px; bottom: 0; width: 1px; background: var(--border-strong);
}
.tl-item:last-child::before { display: none; }
.tl-dot {
  width: 11px; height: 11px; border-radius: 50%; margin-top: 3px;
  border: 2px solid var(--border-strong); background: var(--surface); z-index: 1;
}
.tl-item.is-done .tl-dot { background: var(--good); border-color: var(--good); }
.tl-item.is-pending { opacity: .62; }
.tl-body { min-width: 0; }
.tl-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.tl-label { font-size: 13px; font-weight: 600; }
.tl-when { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); white-space: nowrap; }
.tl-detail { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.kb-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 1px 8px; border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--info) 35%, var(--border));
  color: var(--info); background: color-mix(in srgb, var(--info) 8%, transparent);
}
.msg-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty h3 { color: var(--text-2); font-weight: 600; margin: 12px 0 4px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.chat-avatar { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.chat-avatar .brand-dots i { background: var(--brand-ink); }
.chat-head-txt strong { display: block; font-size: 14px; }
.chat-head-txt span { font-size: 12px; color: var(--text-3); }
.chat-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 88%; }
.msg-bubble { padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; }
.msg-agent { align-self: flex-start; }
.msg-agent .msg-bubble { background: var(--surface-2); border: 1px solid var(--border); border-top-left-radius: 5px; }
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-user .msg-bubble { background: var(--cta-bg); color: var(--cta-ink); border-top-right-radius: 5px; }
.msg-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.msg-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite both; }
.msg-typing i:nth-child(2) { animation-delay: .2s; } .msg-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.chat-composer { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-end; }
.chat-input {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: var(--radius-input);
  padding: 10px 12px; font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text);
  max-height: 120px; line-height: 1.4;
}
.chat-input:focus { outline: none; border-color: var(--border-strong); }
.chat-send { flex-shrink: 0; }

/* schema progress rail */
.schema-rail { border-top: 1px solid var(--border); padding: 12px 16px; background: var(--surface-2); }
.schema-rail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.schema-rail-head .eyebrow { margin: 0; }
.schema-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.schema-chip {
  font-size: 11px; padding: 3px 8px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); color: var(--text-3); display: inline-flex; gap: 5px; align-items: center;
}
.schema-chip.filled { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, var(--border)); background: color-mix(in srgb, var(--good) 8%, transparent); }
.schema-chip .tick { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* confirm card (inline in chat) */
.confirm-card { border: 1px solid var(--border-strong); border-radius: var(--radius-section); background: var(--surface); overflow: hidden; }
.confirm-head { padding: 14px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.confirm-head .eyebrow { margin-bottom: 6px; }
.confirm-title { font-weight: 700; font-size: 15px; margin: 0; }
.confirm-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.confirm-field label { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.confirm-field input, .confirm-field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px;
  font-family: inherit; font-size: 13px; background: var(--surface); color: var(--text); resize: vertical;
}
.confirm-field input:focus, .confirm-field textarea:focus { outline: none; border-color: var(--border-strong); }
.confirm-dupe { border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--accent-soft); border-radius: 10px; padding: 12px; }
.confirm-dupe strong { display: block; margin-bottom: 4px; }
.confirm-actions { display: flex; gap: 8px; padding: 14px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ---------- toast (ported from nudge) ---------- */
.nudge-toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--brand-strong); color: var(--brand-ink);
  padding: 11px 18px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 9px; z-index: 200;
  box-shadow: var(--shadow-raised); animation: toastIn .28s cubic-bezier(.2,.8,.2,1);
}
.nudge-toast-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- widget (embeddable bubble) ---------- */
.nsw-launcher {
  position: fixed; right: 22px; bottom: 22px; z-index: 100;
  border: 0; border-radius: var(--radius-pill); background: var(--brand); color: var(--brand-ink);
  padding: 12px 18px; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 9px;
  box-shadow: var(--shadow-raised);
}
.nsw-launcher .brand-dots i { background: var(--brand-ink); }
.nsw-panel {
  position: fixed; right: 22px; bottom: 22px; z-index: 101;
  width: min(400px, calc(100vw - 44px)); height: min(640px, calc(100vh - 44px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-raised); display: flex; flex-direction: column; overflow: hidden;
  animation: panelIn .24s cubic-bezier(.2,.8,.2,1);
}
@keyframes panelIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
.nsw-panel .chat { flex: 1; min-height: 0; }
.nsw-close { margin-left: auto; }

/* host demo page (mock nudge app behind the widget) */
.host { min-height: 100vh; background: var(--bg); }
.host-hero { max-width: 900px; margin: 0 auto; padding: 60px 24px; }
.host-mock-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 24px; }
.host-mock-card { height: 120px; border-radius: var(--radius-card); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-card); opacity: .6; }
@media (max-width: 720px) { .host-mock-grid { grid-template-columns: 1fr; } }

.banner { border: 1px dashed var(--border-strong); border-radius: var(--radius-section); padding: 10px 14px; font-size: 12px; color: var(--text-2); background: var(--surface-2); display: flex; gap: 8px; align-items: center; }
.banner .sev-dot { background: var(--accent); }

/* ---------- entry gate (customer login / admin login) ---------- */
.gate { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 32px 20px; }
.gate-card { width: 100%; max-width: 420px; padding: 28px; }
.gate-card .brand-lockup { margin-bottom: 18px; }
.gate-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 6px; }
.gate-sub { color: var(--text-2); font-size: 14px; margin: 0 0 18px; }
.gate-seg { width: 100%; margin-bottom: 18px; }
.gate-seg button { flex: 1; }
.gate-form { display: flex; flex-direction: column; gap: 14px; }
.gate-field { display: flex; flex-direction: column; gap: 6px; }
.gate-field span { font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.gate-field input {
  border: 1px solid var(--border); border-radius: var(--radius-input); padding: 11px 13px;
  font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text);
}
.gate-field input:focus { outline: none; border-color: var(--border-strong); }
.gate-submit { justify-content: center; margin-top: 2px; }
.gate-err { color: var(--warn, #DC2626); font-size: 13px; }
.gate-switch { text-align: center; font-size: 13px; color: var(--text-3); margin: 16px 0 0; }
.gate-switch a { color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.who-chip {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: var(--radius-pill); max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-tag { color: var(--accent); font-weight: 700; }
