/* StablRamp design tokens
   Single source of truth for both surfaces.
   Default: "paper" surface for the customer app and marketing site.
   [data-surface="ops"]: dark, dense surface for the admin console.
   Brand values are placeholders and will move to packages/config/brand.config.ts. */

@import url("https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wght@0,400..700;1,400..700&family=Geist+Mono:wght@400..600&display=swap");

:root {
  color-scheme: light;

  --font-display: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-ui: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;

  --text-2xs: 0.6875rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
  --text-3xl: 2.5rem;
  --text-4xl: 3.5rem;
  --text-5xl: 4.75rem;

  --leading-tight: 1.02;
  --leading-snug: 1.25;
  --leading-body: 1.5;
  --tracking-caps: 0.09em;

  --s-1: 4px;  --s-2: 8px;   --s-3: 12px;  --s-4: 16px;  --s-5: 20px;
  --s-6: 24px; --s-8: 32px;  --s-10: 40px; --s-12: 48px; --s-16: 64px;
  --s-20: 80px; --s-24: 96px; --s-32: 128px;

  --radius-xs: 2px;
  --radius-sm: 3px;
  --radius: 6px;
  --radius-pill: 999px;

  --bg: #f6f3ee;
  --bg-deep: #ede8df;
  --surface: #fbf9f5;
  --surface-raised: #ffffff;
  --ink: #14130f;
  --ink-2: #4b4942;
  --ink-3: #807c74;
  --ink-4: #c2bdb3;
  --hairline: rgba(20, 19, 15, 0.12);
  --hairline-strong: rgba(20, 19, 15, 0.34);
  --accent: #1f4d3a;
  --accent-strong: #163a2c;
  --accent-soft: #2f6b52;
  --accent-tint: rgba(31, 77, 58, 0.08);
  --accent-contrast: #f6f3ee;
  --focus: #1f4d3a;
  --selection: rgba(31, 77, 58, 0.18);

  --status-pending: #7d796f;
  --status-pending-tint: rgba(125, 121, 111, 0.14);
  --status-processing: #2a63a6;
  --status-processing-tint: rgba(42, 99, 166, 0.11);
  --status-review: #91620a;
  --status-review-tint: rgba(184, 125, 20, 0.16);
  --status-hold: #a4472b;
  --status-hold-tint: rgba(176, 82, 46, 0.14);
  --status-completed: #2b7a45;
  --status-completed-tint: rgba(43, 122, 69, 0.13);
  --status-failed: #ad3434;
  --status-failed-tint: rgba(173, 52, 52, 0.12);
  --status-cancelled: #7d796f;

  --grain-opacity: 0.32;
  --grain-blend: multiply;
  --shadow-1: 0 1px 0 rgba(20, 19, 15, 0.05);
  --shadow-2: 0 1px 2px rgba(20, 19, 15, 0.08), 0 10px 28px -14px rgba(20, 19, 15, 0.22);

  /* Data colours. Validated as a categorical set on the paper surface:
     lightness band, chroma floor, CVD separation, normal-vision floor, contrast. */
  --series-1: #1a8f5c;
  --series-2: #2a78d6;
  --series-3: #eb6834;
  --series-1-wash: rgba(26, 143, 92, 0.10);
  --chart-grid: #e6e2da;
  --chart-axis: #c9c4ba;
  --chart-label: #807c74;
}

[data-surface="ops"] {
  color-scheme: dark;
  --bg: #0b0d10;
  --bg-deep: #07080a;
  --surface: #111418;
  --surface-raised: #171b21;
  --ink: #e6e8eb;
  --ink-2: #a9aeb6;
  --ink-3: #6f7680;
  --ink-4: #3a4048;
  --hairline: rgba(230, 232, 235, 0.09);
  --hairline-strong: rgba(230, 232, 235, 0.22);
  --accent: #f5b942;
  --accent-strong: #ffd070;
  --accent-soft: #d9a136;
  --accent-tint: rgba(245, 185, 66, 0.10);
  --accent-contrast: #0b0d10;
  --focus: #f5b942;
  --selection: rgba(245, 185, 66, 0.22);

  --status-pending: #8a919a;
  --status-pending-tint: rgba(138, 145, 154, 0.14);
  --status-processing: #5b9be6;
  --status-processing-tint: rgba(91, 155, 230, 0.14);
  --status-review: #f2b84b;
  --status-review-tint: rgba(242, 184, 75, 0.14);
  --status-hold: #ee8a5c;
  --status-hold-tint: rgba(238, 138, 92, 0.14);
  --status-completed: #4fc46a;
  --status-completed-tint: rgba(79, 196, 106, 0.14);
  --status-failed: #e66767;
  --status-failed-tint: rgba(230, 103, 103, 0.14);
  --status-cancelled: #8a919a;

  --grain-opacity: 0.16;
  --grain-blend: overlay;
  --shadow-1: 0 1px 0 rgba(0, 0, 0, 0.4);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.5), 0 12px 32px -12px rgba(0, 0, 0, 0.7);

  /* Data colours, validated on the ops surface. */
  --series-1: #3987e5;
  --series-2: #c98500;
  --series-3: #199e70;
  --series-1-wash: rgba(57, 135, 229, 0.12);
  --chart-grid: #1f242b;
  --chart-axis: #2f353d;
  --chart-label: #6f7680;
}

/* Base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

h1, h2, h3, h4 { margin: 0; font-weight: 400; line-height: var(--leading-snug); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
table { border-collapse: collapse; }
::selection { background: var(--selection); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-xs); }

/* Type utilities */

.display { font-family: var(--font-display); font-weight: 500; letter-spacing: -0.025em; line-height: 1.06; }
.display em { font-style: normal; color: var(--accent); white-space: nowrap; }
.eyebrow {
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-3);
}
.mono, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums slashed-zero;
  letter-spacing: 0;
}
.num { font-feature-settings: "tnum" 1; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }

/* Shared components */

.wordmark { font-family: var(--font-ui); font-weight: 600; font-size: var(--text-lg); letter-spacing: -0.02em; line-height: 1; }
.wordmark--ops {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wordmark--ops::before { content: ""; width: 8px; height: 8px; background: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 var(--s-5);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}
.btn .icon { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { border: 1px solid var(--hairline-strong); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-quiet { color: var(--ink-2); padding: 0 var(--s-3); }
.btn-quiet:hover { color: var(--ink); background: var(--accent-tint); }
.btn-sm { height: 30px; padding: 0 var(--s-3); font-size: var(--text-xs); }
.btn:active { transform: translateY(1px); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px 2px 7px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge[data-status="pending"]    { color: var(--status-pending);    background: var(--status-pending-tint); }
.badge[data-status="processing"] { color: var(--status-processing); background: var(--status-processing-tint); }
.badge[data-status="review"]     { color: var(--status-review);     background: var(--status-review-tint); }
.badge[data-status="hold"]       { color: var(--status-hold);       background: var(--status-hold-tint); }
.badge[data-status="completed"]  { color: var(--status-completed);  background: var(--status-completed-tint); }
.badge[data-status="failed"]     { color: var(--status-failed);     background: var(--status-failed-tint); }
.badge[data-status="cancelled"]  { color: var(--status-cancelled);  background: var(--status-pending-tint); text-decoration: line-through; }
.badge[data-status="processing"]::before { animation: pulse 1.6s ease-in-out infinite; }

.hr { border: 0; border-top: 1px solid var(--hairline); margin: 0; }
.hr-strong { border-top-color: var(--ink); }

.kbd {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  padding: 1px 5px;
  border: 1px solid var(--hairline-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  color: var(--ink-2);
}

.icon { width: 16px; height: 16px; flex: none; }

.copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-3);
  font-size: var(--text-xs);
  transition: color .15s ease;
}
.copy:hover { color: var(--accent); }
.copy .icon { width: 13px; height: 13px; }

/* Charts and sparklines */

.chart { background: var(--surface); border: 1px solid var(--hairline); padding: var(--s-4) var(--s-5) var(--s-3); min-width: 0; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-2); }
.chart-head h3 { font-size: var(--text-sm); font-weight: 600; margin: 0; }
.chart-head .unit { font-size: var(--text-xs); color: var(--ink-3); }
.chart .mermaid { display: block; margin: 0; font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-3); min-height: 120px; }
.chart .mermaid svg { display: block; max-width: 100%; height: auto; color: var(--chart-axis); }
.chart .mermaid[data-processed="true"] { color: inherit; }
.chart .mermaid .grid .tick line { stroke: var(--chart-grid) !important; opacity: 1 !important; }
.chart .mermaid .grid path { stroke-width: 0 !important; }
.chart .mermaid .grid .tick text { fill: var(--chart-label) !important; font-family: var(--font-mono) !important; font-size: 11px !important; }
.chart .mermaid .sectionTitle { fill: var(--ink-3) !important; font-size: 11px !important; }
.chart .mermaid .taskText, .chart .mermaid .taskTextOutsideRight, .chart .mermaid .taskTextOutsideLeft { font-size: 12px !important; }
.chart .mermaid .nodeLabel { font-size: 15px; }
.chart .mermaid .edgeLabel { font-size: 12px; color: var(--ink-2); }
.chart .note { font-size: var(--text-2xs); color: var(--ink-3); margin-top: var(--s-2); }
.chart-table { margin-top: var(--s-2); font-size: var(--text-xs); }
.chart-table summary { cursor: pointer; color: var(--ink-3); list-style: none; }
.chart-table summary::-webkit-details-marker { display: none; }
.chart-table summary:hover { color: var(--accent); }
.chart-table table { width: 100%; margin-top: var(--s-2); }
.chart-table th { text-align: left; font-weight: 500; color: var(--ink-3); padding: 4px 8px 4px 0; border-bottom: 1px solid var(--hairline-strong); }
.chart-table td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--hairline); }
.chart-table td.num, .chart-table th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.spark { display: block; overflow: visible; }
.spark polyline { fill: none; stroke: var(--series-1); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark .end { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.spark.quiet polyline { stroke: var(--ink-4); }
.spark.quiet .end { fill: var(--ink-3); }

/* Motion */

.reveal { animation: rise .8s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--i, 0) * 90ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; }
  .badge::before { animation: none; }
  * { transition: none !important; }
}
