/* ==================================================================
   DeeployOS Foundations — design tokens + primitives
   Source of truth: /static/foundations.html
   ================================================================== */

/* ------------------------------------------------------------------
   Tokens
------------------------------------------------------------------ */
:root {
  --ff-sys: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --ff-display: var(--ff-sys);
  --ff-ui: var(--ff-sys);
  --ff-mono: ui-monospace, "SF Mono", Menlo, monospace;

  --text-xs: 0.75rem;      /* 12 */
  --text-sm: 0.8125rem;    /* 13 */
  --text-base: 0.9375rem;  /* 15 */
  --text-md: 1rem;         /* 16 */
  --text-lg: 1.125rem;     /* 18 */
  --text-xl: 1.5rem;       /* 24 */
  --text-2xl: 2rem;        /* 32 */
  --text-3xl: 2.75rem;     /* 44 */
  --text-4xl: 4rem;        /* 64 */

  --lh-tight: 1.05;
  --lh-display: 1.12;
  --lh-ui: 1.45;
  --lh-body: 1.6;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px; --sp-9: 96px;

  --r-sm: 4px; --r-md: 6px; --r-lg: 10px; --r-pill: 9999px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 120ms; --dur: 180ms; --dur-slow: 260ms;
}

/* Palette — light only. Dark mode removed per product direction. */
:root {
  --bg: oklch(98.5% 0.004 235);
  --bg-sunk: oklch(96.5% 0.006 235);
  --surface: oklch(100% 0 0);
  --surface-hover: oklch(97% 0.006 235);
  --border: oklch(91% 0.008 235);
  --border-strong: oklch(82% 0.012 235);
  --text: oklch(22% 0.025 235);
  --text-muted: oklch(48% 0.015 235);
  --text-subtle: oklch(62% 0.012 235);
  --text-invert: oklch(99% 0.004 235);
  /* Brand palette — source: brand.deeploy.co.
     Deploy Red  #DF3E5B · Blue King #172D3D (primary)
     Baby Blue   #8BC9DB · Orange Cone #FF8500 (secondary) */
  --accent: oklch(60% 0.19 13);            /* Deploy Red #DF3E5B */
  --accent-hover: oklch(54% 0.195 13);
  --accent-soft: oklch(94% 0.04 13);
  --accent-fg: oklch(99% 0.005 13);
  --brand-navy: oklch(25% 0.037 236);      /* Blue King #172D3D */
  --brand-navy-soft: oklch(93% 0.012 236);
  --info: oklch(62% 0.07 220);             /* Baby Blue #8BC9DB, darkened for text/icons */
  --info-soft: oklch(90% 0.04 220);        /* Baby Blue background tint */
  --warn: oklch(72% 0.20 55);              /* Orange Cone #FF8500 */
  --warn-soft: oklch(95% 0.06 55);
  --success: oklch(52% 0.13 155);
  --success-soft: oklch(94% 0.04 155);
  --danger: oklch(56% 0.20 25);
  --danger-soft: oklch(95% 0.04 25);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px oklch(60% 0.19 13 / 0.65);
}

/* ------------------------------------------------------------------
   .ds baseline — wrap feature pages in .ds to get the body/typography
   baseline (color, line-height, font). Explicit `.ds <tag>` rules
   below win over Tailwind Preflight via class specificity.
------------------------------------------------------------------ */
.ds {
  font-family: var(--ff-ui);
  font-size: var(--text-base);
  line-height: var(--lh-ui);
  color: var(--text);
  background: var(--bg);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.ds h1, .ds h2, .ds h3, .ds h4 {
  margin: 0;
  font-family: var(--ff-display);
  font-weight: 500;
  line-height: var(--lh-display);
  letter-spacing: -0.015em;
  color: var(--text);
}
.ds p { margin: 0; }
.ds hr { border: 0; border-top: 1px solid var(--border); margin: 0; }
.ds code { font-family: var(--ff-mono); font-size: 0.875em; }
.ds ::selection { background: var(--accent-soft); color: var(--text); }

.ds .num, .ds .tabular, .ds [data-tabular] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ------------------------------------------------------------------
   Typography roles (match foundations.html type-spec section)
------------------------------------------------------------------ */
.ds .hero-title {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--text-3xl);
  line-height: var(--lh-display);
  letter-spacing: -0.025em;
  color: var(--text);
}
.ds .page-title {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--text-2xl);
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text);
}
.ds .section-title {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--text-xl);
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--text);
}
.ds .card-title {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--text-lg);
  line-height: 1.3;
  letter-spacing: -0.005em;
  color: var(--text);
}
.ds .lede {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--text-lg);
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--text-muted);
  max-width: 60ch;
  font-variant-numeric: tabular-nums;
}

/* Eyebrow — tiny uppercase label (11px) */
.ds .eyebrow {
  font-family: var(--ff-ui);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* Section kicker — small accent-colored label (12px Clash, 0.14em) */
.ds .section-kicker {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--text-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Masthead mark — 13px Clash 700 uppercase, with pixel dots */
.ds .mast-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  font-family: var(--ff-display);
  font-weight: 700;
  font-size: var(--text-sm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ds .mark-dot {
  width: 10px; height: 10px;
  background: var(--accent);
  border-radius: 1px;
  display: inline-block;
}
.ds .mark-dot + .mark-dot { width: 6px; height: 6px; }

/* Live pulse dot — 8px, accent, ring pulse */
.ds .live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  box-shadow: 0 0 0 0 var(--accent);
  animation: ds-live-pulse 2000ms var(--ease-out) infinite;
}
@keyframes ds-live-pulse {
  0%   { box-shadow: 0 0 0 0 oklch(from var(--accent) l c h / 0.5); }
  100% { box-shadow: 0 0 0 8px oklch(from var(--accent) l c h / 0); }
}

/* ------------------------------------------------------------------
   Masthead block (editorial page header)
------------------------------------------------------------------ */
.ds .masthead {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-5);
  align-items: end;
  padding-bottom: var(--sp-6);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-7);
}
.ds .masthead .mast-mark { margin-bottom: var(--sp-4); }
.ds .masthead .lede { margin-top: var(--sp-4); }
@media (max-width: 700px) {
  .ds .masthead { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------
   Section head (kicker + title + optional note)
------------------------------------------------------------------ */
.ds .section-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: var(--sp-5);
  margin-bottom: var(--sp-6);
}
.ds .section-head .section-title { margin-top: var(--sp-2); }
.ds .section-note {
  max-width: 32ch;
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: var(--lh-body);
  text-align: right;
}
@media (max-width: 700px) {
  .ds .section-head { grid-template-columns: 1fr; }
  .ds .section-note { text-align: left; max-width: 60ch; }
}

/* ------------------------------------------------------------------
   Page shell
------------------------------------------------------------------ */
.ds-page {
  min-height: 100%;
  padding: var(--sp-7) var(--sp-6) var(--sp-9);
  background: var(--bg);
  color: var(--text);
  font-family: var(--ff-ui);
}

@media (max-width: 640px) {
  .ds-page {
    padding: var(--sp-5) var(--sp-4) var(--sp-7);
  }
  .ds .hero-title {
    font-size: clamp(1.75rem, 8vw, var(--text-3xl));
    word-break: break-word;
  }
  .ds .page-title {
    font-size: clamp(1.375rem, 6vw, var(--text-2xl));
    word-break: break-word;
  }
  .ds .panel-head {
    padding: var(--sp-3) var(--sp-4);
    gap: var(--sp-3);
  }
  .ds .panel-body {
    padding: var(--sp-4);
  }
}

/* ------------------------------------------------------------------
   Panel
------------------------------------------------------------------ */
.ds .panel {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.ds .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.ds .panel-title {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  color: var(--text);
}
.ds .panel-subtitle {
  font-size: var(--text-xs);
  color: var(--text-subtle);
  margin-top: 2px;
}
.ds .panel-body { padding: var(--sp-5); }
.ds .panel-body.flush { padding: 0; }

.ds .panel-empty {
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}
.ds .panel-empty h4 {
  font-family: var(--ff-display);
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
  margin: 0;
}
.ds .panel-empty p {
  color: var(--text-muted);
  max-width: 40ch;
  font-size: var(--text-sm);
  line-height: var(--lh-body);
  margin: 0;
}

/* ------------------------------------------------------------------
   Buttons
------------------------------------------------------------------ */
.ds .btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px 14px;
  font-family: var(--ff-ui);
  font-weight: 500;
  font-size: var(--text-sm);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-border);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--dur) var(--ease-out),
    color var(--dur) var(--ease-out),
    border-color var(--dur) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}
.ds .btn:hover { background: var(--surface-hover); }
.ds .btn:active { transform: translateY(0.5px); }
.ds .btn:focus-visible { outline: 0; box-shadow: var(--focus-ring); }
.ds .btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ds .btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-fg);
  --btn-border: var(--accent);
}
.ds .btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.ds .btn--ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-fg: var(--text-muted);
}
.ds .btn--ghost:hover { color: var(--text); background: var(--surface-hover); }

.ds .btn--danger {
  --btn-fg: var(--danger);
  --btn-border: color-mix(in oklch, var(--danger) 35%, var(--border));
}
.ds .btn--danger:hover { background: var(--danger-soft); color: var(--danger); }

.ds .btn--sm { padding: 5px 10px; font-size: var(--text-xs); border-radius: var(--r-sm); }
.ds .btn--icon { padding: 8px; }
.ds .btn svg { width: 15px; height: 15px; stroke-width: 1.75; flex-shrink: 0; }

/* ------------------------------------------------------------------
   Inputs
------------------------------------------------------------------ */
.ds .field { display: flex; flex-direction: column; gap: 6px; }
.ds .field > label {
  font-family: var(--ff-ui);
  font-weight: 500;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.ds .field-help { font-size: var(--text-xs); color: var(--text-subtle); }
.ds .field-error { font-size: var(--text-xs); color: var(--danger); }

.ds .input, .ds .select, .ds .textarea {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--ff-ui);
  font-size: var(--text-sm);
  line-height: 1.4;
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.ds .input::placeholder, .ds .textarea::placeholder { color: var(--text-subtle); }
.ds .input:hover, .ds .select:hover, .ds .textarea:hover { border-color: var(--text-subtle); }
.ds .input:focus, .ds .select:focus, .ds .textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px oklch(from var(--accent) l c h / 0.18);
}
.ds .input[aria-invalid="true"] { border-color: var(--danger); }

.ds .textarea { min-height: 84px; resize: vertical; }
.ds .select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23808a95' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* ------------------------------------------------------------------
   Badges
------------------------------------------------------------------ */
.ds .badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-family: var(--ff-ui);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.02em;
  background: var(--bg-sunk);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.ds .badge .pip { width: 6px; height: 6px; border-radius: 50%; background: currentcolor; }
.ds .badge--open { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in oklch, var(--accent) 25%, transparent); }
.ds .badge--won  { background: var(--success-soft); color: var(--success); border-color: color-mix(in oklch, var(--success) 25%, transparent); }
.ds .badge--lost { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in oklch, var(--danger) 25%, transparent); }
.ds .badge--info { background: var(--info-soft); color: var(--info); border-color: color-mix(in oklch, var(--info) 25%, transparent); }
.ds .badge--warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in oklch, var(--warn) 25%, transparent); }

.ds .count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------
   Table
------------------------------------------------------------------ */
.ds .table { width: 100%; border-collapse: collapse; }
.ds .table thead th {
  text-align: left;
  padding: 10px var(--sp-4);
  font-family: var(--ff-ui);
  font-weight: 500;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunk);
}
.ds .table tbody td {
  padding: 11px var(--sp-4);
  font-size: var(--text-sm);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ds .table tbody tr:last-child td { border-bottom: 0; }
.ds .table tbody tr { transition: background var(--dur-fast) var(--ease-out); }
.ds .table tbody tr:hover { background: var(--bg-sunk); }
.ds .table .muted { color: var(--text-muted); }
.ds .table .align-right { text-align: right; font-variant-numeric: tabular-nums; }

.ds .avatar {
  width: 24px; height: 24px;
  background: var(--brand-navy-soft);
  color: var(--brand-navy);
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--ff-display);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ------------------------------------------------------------------
   Definition list
------------------------------------------------------------------ */
.ds .dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: var(--sp-6);
  row-gap: var(--sp-3);
}
.ds .dl > dt {
  font-family: var(--ff-ui);
  font-size: var(--text-xs);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--sp-3) 0 var(--sp-1);
  border-top: 1px solid var(--border);
}
.ds .dl > dd {
  margin: 0;
  padding: var(--sp-3) 0 var(--sp-1);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------
   Skeleton + pixel loader + pixel mark
------------------------------------------------------------------ */
.ds .skeleton {
  display: inline-block;
  background: linear-gradient(90deg, var(--bg-sunk) 0%, var(--surface-hover) 50%, var(--bg-sunk) 100%);
  background-size: 200% 100%;
  border-radius: 3px;
  animation: ds-shimmer 1400ms ease-in-out infinite;
}
@keyframes ds-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ds .pixel-loader { display: inline-flex; gap: 3px; vertical-align: middle; }
.ds .pixel-loader span {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 1px;
  animation: ds-pixel-bounce 1000ms var(--ease-in-out) infinite;
}
.ds .pixel-loader span:nth-child(2) { animation-delay: 100ms; }
.ds .pixel-loader span:nth-child(3) { animation-delay: 200ms; }
.ds .pixel-loader span:nth-child(4) { animation-delay: 300ms; }
@keyframes ds-pixel-bounce {
  0%, 40%, 100% { transform: translateY(0); opacity: 0.4; }
  20% { transform: translateY(-4px); opacity: 1; }
}

.ds .pixel-mark {
  display: grid;
  grid-template-columns: repeat(4, 8px);
  grid-template-rows: repeat(7, 8px);
  gap: 2px;
}
.ds .pixel-mark span { background: var(--accent); border-radius: 1px; animation: ds-pixel-fade 2600ms var(--ease-out) infinite; }
.ds .pixel-mark span.empty-cell { background: transparent; animation: none; }
@keyframes ds-pixel-fade {
  0%, 55% { opacity: 1; }
  75%, 100% { opacity: 0.18; }
}

@media (prefers-reduced-motion: reduce) {
  .ds .skeleton,
  .ds .pixel-loader span,
  .ds .pixel-mark span,
  .ds .live-dot { animation: none; }
}

/* ------------------------------------------------------------------
   Utilities
------------------------------------------------------------------ */
.ds .stack > * + * { margin-top: var(--sp-4); }
.ds .stack-lg > * + * { margin-top: var(--sp-6); }
.ds .row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.ds .cluster { display: flex; gap: var(--sp-4); flex-wrap: wrap; align-items: center; }
