/*
 * Facilis UI — shared design system for customer demos.
 * Cribbed from facilisplatform's index.css :root tokens.
 * Vanilla CSS only — no Tailwind, no build step.
 *
 * Anti-slop rules:
 *   - No gradients on chrome (only on functional things like progress bars).
 *   - No shadows on cards except the glass shadow.
 *   - Single accent color (#6E8BFF). Data colors signal value, not decoration.
 *   - All radii from the scale below. No ad-hoc 4px or 6px junk.
 *   - Borders are 1px, semi-transparent white. Never solid grey.
 */

:root {
  --bg-deep: #08080A;
  --bg-surface: #0D0D10;
  --bg-elevated: #15151A;
  --bg-raised: #1C1C22;
  --bg-glass: rgba(22, 22, 28, 0.62);
  --bg-glass-strong: rgba(22, 22, 28, 0.82);

  --bg-hover: rgba(255, 255, 255, 0.045);
  --bg-hover-strong: rgba(255, 255, 255, 0.07);
  --bg-active: rgba(255, 255, 255, 0.06);
  --bg-quiet: rgba(255, 255, 255, 0.025);

  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-soft: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.15);
  --border-focus: rgba(110, 139, 255, 0.55);

  --text-primary: rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.66);
  --text-muted: rgba(255, 255, 255, 0.46);
  --text-quiet: rgba(255, 255, 255, 0.30);

  --accent: #6E8BFF;
  --accent-hover: #8AA0FF;
  --accent-soft: rgba(110, 139, 255, 0.14);
  --accent-line: rgba(110, 139, 255, 0.42);

  --data-good: #4ABE93;
  --data-good-soft: rgba(74, 190, 147, 0.12);
  --data-good-line: rgba(74, 190, 147, 0.36);
  --data-warn: #E8B257;
  --data-warn-soft: rgba(232, 178, 87, 0.12);
  --data-warn-line: rgba(232, 178, 87, 0.42);
  --data-bad: #E36464;
  --data-bad-soft: rgba(227, 100, 100, 0.10);
  --data-bad-line: rgba(227, 100, 100, 0.42);
  --data-info: #5BC0DE;
  --data-neutral: #7A8290;
  --ot-write: #C77DFF;

  --r-tight: 6px;
  --r-small: 8px;
  --r-card: 10px;
  --r-card-md: 12px;
  --r-card-lg: 16px;
  --r-panel: 20px;
  --r-popover: 22px;
  --r-pill: 9999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-quick: 80ms;
  --t-base: 140ms;
  --t-slow: 240ms;

  --shadow-glass: 0 1px 0 rgba(255,255,255,0.04) inset, 0 12px 32px -12px rgba(0,0,0,0.5);
  --shadow-popover: 0 1px 0 rgba(255,255,255,0.04) inset, 0 24px 48px -16px rgba(0,0,0,0.6);

  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}

/* Atmospheric body — single soft accent halo top-left, no gradients on chrome */
body {
  position: relative;
  overflow-x: hidden;
}
body::before {
  content: '';
  position: fixed;
  top: -240px;
  left: -240px;
  width: 720px;
  height: 720px;
  background: radial-gradient(circle, rgba(110, 139, 255, 0.10) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.018) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 56px 56px;
  pointer-events: none;
  z-index: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; display: block; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

::selection { background: var(--accent-soft); }

/* ============== Layout ============== */

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 18px 32px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(8, 8, 10, 0.55);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.topbar .brand-mark {
  height: 22px;
  width: 22px;
  display: block;
  object-fit: contain;
  opacity: 0.92;
}
.topbar .title {
  font-size: 14px;
  color: var(--text-secondary);
  margin-left: var(--space-2);
}
.topbar .title strong {
  color: var(--text-primary);
  font-weight: 500;
}
.topbar .spacer { flex: 1; }
.topbar .meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.topbar .meta .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--data-good);
  box-shadow: 0 0 8px rgba(74, 190, 147, 0.6);
  display: inline-block;
}

.page {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px;
}
.page-narrow { max-width: 980px; }
.page-wide { max-width: 1480px; }

.page-head {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
  margin-bottom: 28px;
}
.page-head h1 {
  font-size: 28px;
  letter-spacing: -0.022em;
  font-weight: 500;
  line-height: 1.18;
}
.page-head .lede {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 56ch;
  margin-top: 6px;
}
.page-head .head-meta {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.eyebrow .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-line);
}

/* ============== Surfaces ============== */

.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(32px) saturate(1.5);
  -webkit-backdrop-filter: blur(32px) saturate(1.5);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-glass);
}
.glass-strong {
  background: var(--bg-glass-strong);
  backdrop-filter: blur(40px) saturate(1.6);
  -webkit-backdrop-filter: blur(40px) saturate(1.6);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-popover);
}
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-card-lg);
}
.card-pad { padding: 22px; }
.card-pad-lg { padding: 28px; }

.section-h {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}
.section-h::before {
  content: '';
  width: 3px;
  height: 12px;
  background: var(--accent);
  border-radius: 2px;
}

.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 20px 0;
}

/* ============== Buttons ============== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-small);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: all var(--t-base) var(--ease-out);
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-soft);
  user-select: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover-strong); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #0A0A0F;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
  background: var(--data-bad-soft);
  color: var(--data-bad);
  border-color: var(--data-bad-line);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 22px; font-size: 14px; }
.btn-block { width: 100%; }

/* ============== Inputs ============== */

.input, .select, .textarea {
  background: var(--bg-quiet);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-small);
  color: var(--text-primary);
  padding: 9px 12px;
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: border-color var(--t-base) var(--ease-out), background var(--t-base);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--border-focus);
  background: var(--bg-hover);
}
.input::placeholder { color: var(--text-quiet); }

.label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  outline: none;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-deep);
  box-shadow: 0 0 0 1px var(--accent);
}
.range::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-deep);
}

/* ============== Dropzone ============== */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 56px 32px;
  border: 1px dashed var(--border-soft);
  border-radius: var(--r-card-lg);
  background: var(--bg-quiet);
  cursor: pointer;
  transition: all var(--t-base) var(--ease-out);
  text-align: center;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.dropzone .dz-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  font-size: 18px;
  color: var(--text-secondary);
}
.dropzone .dz-text {
  font-size: 14px;
  color: var(--text-primary);
}
.dropzone .dz-text u {
  text-decoration: none;
  color: var(--accent);
  border-bottom: 1px solid var(--accent-line);
}
.dropzone .dz-hint {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.dropzone img.preview {
  max-width: 100%;
  max-height: 280px;
  border-radius: 12px;
  margin-top: 4px;
}

/* ============== Pills ============== */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border-soft);
  white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
.pill-good { background: var(--data-good-soft); color: var(--data-good); border-color: var(--data-good-line); }
.pill-good .dot { background: var(--data-good); }
.pill-warn { background: var(--data-warn-soft); color: var(--data-warn); border-color: var(--data-warn-line); }
.pill-warn .dot { background: var(--data-warn); }
.pill-bad  { background: var(--data-bad-soft);  color: var(--data-bad);  border-color: var(--data-bad-line); }
.pill-bad .dot { background: var(--data-bad); }
.pill-accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

/* ============== KPI ============== */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}
.kpi {
  padding: 18px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-card-lg);
}
.kpi .kpi-label {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.kpi .kpi-value {
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.022em;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1.1;
}
.kpi .kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.kpi.accent .kpi-value { color: var(--accent); }
.kpi.good .kpi-value { color: var(--data-good); }
.kpi.warn .kpi-value { color: var(--data-warn); }
.kpi.bad  .kpi-value { color: var(--data-bad); }

/* ============== Probability bars ============== */

.prob-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.prob-row b {
  color: var(--text-primary);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.prob-track {
  height: 6px;
  background: var(--bg-hover);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-bottom: 14px;
}
.prob-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width var(--t-slow) var(--ease-out);
}
.prob-fill.good { background: var(--data-good); }
.prob-fill.bad  { background: var(--data-bad); }
.prob-fill.warn { background: var(--data-warn); }

/* ============== Table ============== */

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border-subtle);
}
.tbl td {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--bg-hover); }

/* ============== Spinner ============== */

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bg-hover-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 0%, var(--bg-hover-strong) 50%, var(--bg-hover) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-card);
}
@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* ============== Toast ============== */

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 12px 16px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(40px) saturate(1.6);
  -webkit-backdrop-filter: blur(40px) saturate(1.6);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-card-md);
  box-shadow: var(--shadow-popover);
  font-size: 13px;
  color: var(--text-primary);
  max-width: 360px;
  z-index: 50;
  animation: toast-in 240ms var(--ease-out);
}
.toast.bad   { border-color: var(--data-bad-line);  color: var(--data-bad); }
.toast.good  { border-color: var(--data-good-line); color: var(--data-good); }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ============== Helpers ============== */

.row { display: flex; gap: var(--space-4); }
.col { display: flex; flex-direction: column; gap: var(--space-4); }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.muted { color: var(--text-muted); }
.quiet { color: var(--text-quiet); }
.tabular { font-variant-numeric: tabular-nums; }
.text-12 { font-size: 12px; }
.text-13 { font-size: 13px; }
.text-18 { font-size: 18px; letter-spacing: -0.014em; }
.text-22 { font-size: 22px; letter-spacing: -0.014em; line-height: 1.25; }
.text-28 { font-size: 28px; letter-spacing: -0.022em; line-height: 1.18; }
.weight-500 { font-weight: 500; }
.mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-feature-settings: normal; }

.hidden { display: none !important; }
