/* ==========================================================================
   Lingsaa Support — shared tokens and base components (copied from Lingsaa Monitor)
   All colours are tokens on :root; dark mode is selected (not inverted).
   --series* tokens are for data only; UI chrome uses --accent*.
   ========================================================================== */

@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/assets/inter.woff2) format("woff2-variations");
}

:root {
  color-scheme: light;

  /* Surfaces & ink (cool slate) */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f1f4f9;        /* hover / subtle fill */
  --surface-3: #e9edf4;
  --text: #0e1525;
  --text-2: #4a5468;
  --muted: #7b8497;
  --grid: #e7ebf1;
  --axis: #cbd2de;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.15);
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 6px -1px rgba(16, 24, 40, 0.05);
  --shadow: 0 2px 4px rgba(16, 24, 40, 0.04), 0 16px 40px -10px rgba(16, 24, 40, 0.18);
  --shadow-hover: 0 2px 4px rgba(16, 24, 40, 0.05), 0 12px 28px -8px rgba(16, 24, 40, 0.16);
  --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --page-glow: radial-gradient(1200px 520px at 70% -180px, rgba(99, 102, 241, 0.09), transparent 70%);

  /* Brand accent (UI chrome: buttons, active nav, focus) */
  --accent: #5b5ce2;
  --accent-2: #8b5cf6;
  --accent-ink: #4b4cc9;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --accent-glow: 0 6px 18px -6px rgba(99, 102, 241, 0.55);

  /* Series (fixed mapping, colorblind-validated) */
  --series: #2a78d6;
  --s-2xx: #2a78d6;
  --s-3xx: #1baf7a;
  --s-4xx: #eda100;
  --s-5xx: #e87ba4;
  --s-rx: #2a78d6;
  --s-tx: #eb6834;

  /* Status (reserved for state; always with icon + label) */
  --good: #12a150;
  --warning: #f5a524;
  --serious: #ec835a;
  --critical: #e5484d;
  /* Text-safe inks of the status hues (WCAG AA on surface) */
  --good-ink: #0b7a3b;
  --warning-ink: #8a5300;
  --critical-ink: #c2262c;
  --neutral-ink: var(--text-2);

  /* Tints */
  --good-tint: color-mix(in srgb, var(--good) 11%, var(--surface));
  --warning-tint: color-mix(in srgb, var(--warning) 16%, var(--surface));
  --critical-tint: color-mix(in srgb, var(--critical) 10%, var(--surface));
  --muted-tint: color-mix(in srgb, var(--muted) 12%, var(--surface));
  --accent-tint: color-mix(in srgb, var(--accent) 9%, var(--surface));

  /* Meter tracks: lighter step of the fill hue */
  --track-accent: color-mix(in srgb, var(--series) 14%, var(--surface));
  --track-warning: color-mix(in srgb, var(--warning) 22%, var(--surface));
  --track-critical: color-mix(in srgb, var(--critical) 16%, var(--surface));

  /* Sidebar: deep navy in both themes */
  --side-bg: linear-gradient(180deg, #0f1430 0%, #0b0f22 100%);
  --side-text: #eef0fb;
  --side-text-2: #a6acc8;
  --side-muted: #6d7499;
  --side-hover: rgba(255, 255, 255, 0.06);
  --side-active: rgba(129, 132, 255, 0.16);
  --side-border: rgba(255, 255, 255, 0.07);

  --focus: #6366f1;
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter Variable", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", "Consolas", monospace;
  --sidebar-w: 256px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0c12;
    --surface: #12151d;
    --surface-2: #191d27;
    --surface-3: #212633;
    --text: #edf0f7;
    --text-2: #b1b9ca;
    --muted: #7a8398;
    --grid: #222736;
    --axis: #2f3546;
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.13);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 12px -4px rgba(0, 0, 0, 0.4);
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.35), 0 20px 48px -12px rgba(0, 0, 0, 0.7);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.35), 0 14px 32px -10px rgba(0, 0, 0, 0.65);
    --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    --page-glow: radial-gradient(1200px 520px at 70% -180px, rgba(99, 102, 241, 0.14), transparent 70%);
    --accent: #7c7ff5;
    --accent-ink: #a5a7ff;
    --accent-glow: 0 6px 20px -6px rgba(124, 127, 245, 0.55);
    --series: #3987e5;
    --s-2xx: #3987e5;
    --s-3xx: #199e70;
    --s-4xx: #c98500;
    --s-5xx: #d55181;
    --s-rx: #3987e5;
    --s-tx: #d95926;
    --good: #22b35e;
    --critical: #e5484d;
    --good-ink: #4fd18a;
    --warning-ink: #f5bf45;
    --critical-ink: #ff8589;
    --good-tint: color-mix(in srgb, var(--good) 15%, var(--surface));
    --warning-tint: color-mix(in srgb, var(--warning) 15%, var(--surface));
    --critical-tint: color-mix(in srgb, var(--critical) 16%, var(--surface));
    --side-bg: linear-gradient(180deg, #0d1020 0%, #090b14 100%);
    --focus: #7c7ff5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0c12;
  --surface: #12151d;
  --surface-2: #191d27;
  --surface-3: #212633;
  --text: #edf0f7;
  --text-2: #b1b9ca;
  --muted: #7a8398;
  --grid: #222736;
  --axis: #2f3546;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 12px -4px rgba(0, 0, 0, 0.4);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.35), 0 20px 48px -12px rgba(0, 0, 0, 0.7);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.35), 0 14px 32px -10px rgba(0, 0, 0, 0.65);
  --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --page-glow: radial-gradient(1200px 520px at 70% -180px, rgba(99, 102, 241, 0.14), transparent 70%);
  --accent: #7c7ff5;
  --accent-ink: #a5a7ff;
  --accent-glow: 0 6px 20px -6px rgba(124, 127, 245, 0.55);
  --series: #3987e5;
  --s-2xx: #3987e5;
  --s-3xx: #199e70;
  --s-4xx: #c98500;
  --s-5xx: #d55181;
  --s-rx: #3987e5;
  --s-tx: #d95926;
  --good: #22b35e;
  --critical: #e5484d;
  --good-ink: #4fd18a;
  --warning-ink: #f5bf45;
  --critical-ink: #ff8589;
  --good-tint: color-mix(in srgb, var(--good) 15%, var(--surface));
  --warning-tint: color-mix(in srgb, var(--warning) 15%, var(--surface));
  --critical-tint: color-mix(in srgb, var(--critical) 16%, var(--surface));
  --side-bg: linear-gradient(180deg, #0d1020 0%, #090b14 100%);
  --focus: #7c7ff5;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page-glow), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 0.75em; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Shared components (used by staff, portal and public pages) ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm), var(--highlight);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-weight: 550;
  cursor: pointer;
  transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent-grad); border-color: transparent; color: #fff; box-shadow: var(--accent-glow); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }

label.field { display: block; }
label.field > span { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; color: var(--text-2); }
.input, input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="search"], input[type="number"], select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.error-text { color: var(--critical-ink); font-size: 13px; }

.notice { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); }
.notice.good { background: var(--good-tint); border-color: color-mix(in srgb, var(--good) 30%, transparent); color: var(--good-ink); }
.notice.warning { background: var(--warning-tint); border-color: color-mix(in srgb, var(--warning) 35%, transparent); color: var(--warning-ink); }
.notice.critical { background: var(--critical-tint); border-color: color-mix(in srgb, var(--critical) 30%, transparent); color: var(--critical-ink); }

/* Pills: ticket status / priority. Always text, never colour alone. */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--muted-tint); color: var(--text-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.pill.status-new { background: var(--accent-tint); color: var(--accent-ink); }
.pill.status-open { background: var(--warning-tint); color: var(--warning-ink); }
.pill.status-waiting { background: var(--muted-tint); color: var(--text-2); }
.pill.status-on_hold { background: var(--muted-tint); color: var(--muted); }
.pill.status-solved { background: var(--good-tint); color: var(--good-ink); }
.pill.status-closed { background: var(--surface-3); color: var(--muted); }
.pill.priority-urgent { background: var(--critical-tint); color: var(--critical-ink); }
.pill.priority-high { background: var(--warning-tint); color: var(--warning-ink); }
.pill.priority-normal { background: var(--muted-tint); color: var(--text-2); }
.pill.priority-low { background: var(--surface-3); color: var(--muted); }
.pill.overdue { background: var(--critical-tint); color: var(--critical-ink); }
.pill.plain::before { display: none; }

table.table { width: 100%; border-collapse: collapse; }
table.table th, table.table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
table.table tr.clickable { cursor: pointer; }
table.table tr.clickable:hover td { background: var(--surface-2); }

/* Conversation bubbles (staff + portal) */
.thread { display: flex; flex-direction: column; gap: 12px; }
.msg { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); }
.msg .msg-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; margin-bottom: 6px; }
.msg .msg-head b { font-weight: 600; }
.msg .msg-body { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.from-customer { background: var(--surface); }
.msg.from-staff { background: var(--accent-tint); border-color: color-mix(in srgb, var(--accent) 18%, transparent); }
.msg.internal { background: var(--warning-tint); border-style: dashed; border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.msg.system { background: transparent; border: none; padding: 2px 4px; color: var(--muted); font-size: 12.5px; text-align: center; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attachments a { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 999px; font-size: 12.5px; background: var(--surface); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  z-index: 1000; max-width: calc(100vw - 32px);
}

@media (max-width: 640px) {
  .card { padding: 16px; border-radius: var(--radius-sm); }
  table.table th, table.table td { padding: 8px; }
}
