/* PipeWarden Design System — Apple HIG + Decart
 * Single source of truth for color, type, spacing, motion.
 * Dark-default; light mode via prefers-color-scheme.
 */

:root {
  /* ---------- Typography — SF Pro / system ---------- */
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
               'Inter', system-ui, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;

  /* Apple type scale (pt → px) */
  --fs-11: 11px;
  --fs-13: 13px;
  --fs-15: 15px;
  --fs-17: 17px;
  --fs-20: 20px;
  --fs-24: 24px;
  --fs-28: 28px;
  --fs-34: 34px;
  --fs-48: 48px;
  --fs-60: 60px;

  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* ---------- 8pt grid spacing ---------- */
  --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;

  /* ---------- Radii — Apple soft ---------- */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-full: 9999px;

  /* ---------- Motion — Apple ease curves ---------- */
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-emph: cubic-bezier(0.2, 0, 0, 1);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --dur-micro: 150ms;
  --dur-short: 220ms;
  --dur-med: 320ms;
  --dur-long: 480ms;

  /* ---------- Layout ---------- */
  --content-max: 1200px;
  --content-narrow: 720px;

  /* ---------- Color — dark base (Decart neutrals) ---------- */
  --bg: #07090c;
  --bg-elev-1: #0d1117;
  --bg-elev-2: #141a23;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.05);
  --surface-glass: rgba(13, 17, 23, 0.72);
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.14);

  --text: #f5f7fa;
  --text-secondary: #aab3c0;
  --text-tertiary: #6b7785;
  --text-inverted: #0a0c10;

  /* Apple system color palette — dark-mode variants */
  --sys-blue: #0A84FF;
  --sys-blue-hover: #2f95ff;
  --sys-indigo: #5E5CE6;
  --sys-teal: #64D2FF;
  --sys-green: #30D158;
  --sys-orange: #FF9F0A;
  --sys-red: #FF453A;
  --sys-yellow: #FFD60A;
  --sys-gray: #8E8E93;

  /* Product accent — keep green as security/signal brand */
  --accent: var(--sys-blue);         /* CTAs = Apple blue */
  --accent-hover: var(--sys-blue-hover);
  --accent-soft: rgba(10, 132, 255, 0.12);
  --signal: var(--sys-green);        /* in-product "healthy" */
  --warn: var(--sys-orange);
  --danger: var(--sys-red);

  /* ---------- Elevation — Apple layered shadows ---------- */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.30), 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.36), 0 2px 6px rgba(0, 0, 0, 0.20);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.44), 0 4px 10px rgba(0, 0, 0, 0.22);
  --shadow-focus: 0 0 0 4px rgba(10, 132, 255, 0.35);

  /* ---------- Glassmorphism ---------- */
  --glass-bg: rgba(13, 17, 23, 0.62);
  --glass-bg-strong: rgba(13, 17, 23, 0.82);
  --glass-border: rgba(255, 255, 255, 0.10);
  --glass-blur: saturate(180%) blur(20px);
}

/* ---------- Light mode (prefers-color-scheme) ---------- */
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"], :root:not([data-theme]) {
    --bg: #f7f8fa;
    --bg-elev-1: #ffffff;
    --bg-elev-2: #f0f2f5;
    --bg-card: rgba(0, 0, 0, 0.02);
    --bg-card-hover: rgba(0, 0, 0, 0.04);
    --surface-glass: rgba(255, 255, 255, 0.78);
    --hairline: rgba(0, 0, 0, 0.08);
    --hairline-strong: rgba(0, 0, 0, 0.14);

    --text: #0a0c10;
    --text-secondary: #4a5360;
    --text-tertiary: #8a939e;
    --text-inverted: #ffffff;

    --sys-blue: #007AFF;
    --sys-blue-hover: #0066d6;
    --sys-green: #34C759;
    --sys-orange: #FF9500;
    --sys-red: #FF3B30;

    --accent: var(--sys-blue);
    --accent-hover: var(--sys-blue-hover);
    --accent-soft: rgba(0, 122, 255, 0.10);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0, 0, 0, 0.06);

    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-bg-strong: rgba(255, 255, 255, 0.88);
    --glass-border: rgba(0, 0, 0, 0.06);
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Global reset (additive) ---------- */
html { -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-17);
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text);
  background: var(--bg);
}

/* ---------- Type — Apple scale ---------- */
.t-display { font-size: clamp(var(--fs-48), 6vw, var(--fs-60)); font-weight: var(--fw-bold); line-height: 1.08; letter-spacing: -0.03em; }
.t-title1  { font-size: var(--fs-34); font-weight: var(--fw-bold); line-height: 1.12; letter-spacing: -0.022em; }
.t-title2  { font-size: var(--fs-28); font-weight: var(--fw-bold); line-height: 1.15; letter-spacing: -0.018em; }
.t-title3  { font-size: var(--fs-24); font-weight: var(--fw-semibold); line-height: 1.18; letter-spacing: -0.012em; }
.t-headline { font-size: var(--fs-17); font-weight: var(--fw-semibold); line-height: 1.30; }
.t-body    { font-size: var(--fs-17); font-weight: var(--fw-regular); line-height: 1.47; }
.t-callout { font-size: var(--fs-15); font-weight: var(--fw-regular); line-height: 1.40; }
.t-caption { font-size: var(--fs-13); font-weight: var(--fw-regular); line-height: 1.38; color: var(--text-tertiary); }
.t-footnote { font-size: var(--fs-11); font-weight: var(--fw-regular); line-height: 1.30; color: var(--text-tertiary); letter-spacing: 0.01em; }

/* ---------- Button — Apple HIG 44pt ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px;
  padding: 0 var(--s-5);
  border: 0;
  border-radius: var(--r-sm);
  font: var(--fw-semibold) var(--fs-15)/1 var(--font-sans);
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform var(--dur-micro) var(--ease-standard),
              background var(--dur-short) var(--ease-standard),
              box-shadow var(--dur-short) var(--ease-standard),
              border-color var(--dur-short) var(--ease-standard);
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
.btn-secondary:hover { background: var(--bg-card-hover); border-color: rgba(255, 255, 255, 0.20); }

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

.btn-destructive { background: var(--danger); color: #fff; }
.btn-destructive:hover { background: #ff5c52; box-shadow: var(--shadow-md); }

.btn-lg { min-height: 52px; padding: 0 var(--s-6); font-size: var(--fs-17); border-radius: var(--r-md); }
.btn-sm { min-height: 36px; padding: 0 var(--s-4); font-size: var(--fs-13); }

/* ---------- Card — Decart soft elevation ---------- */
.card {
  background: var(--bg-elev-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--s-6);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-short) var(--ease-standard),
              transform var(--dur-short) var(--ease-standard),
              border-color var(--dur-short) var(--ease-standard);
}
.card--hoverable:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--hairline-strong); }
.card--glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-color: var(--glass-border);
}

/* ---------- Input — 44pt ---------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.field label, .field > span:first-child { font-size: var(--fs-13); color: var(--text-secondary); font-weight: var(--fw-medium); }
.field input, .field select, .field textarea {
  min-height: 44px;
  padding: 0 var(--s-4);
  border-radius: var(--r-sm);
  border: 1px solid var(--hairline-strong);
  background: var(--bg-elev-1);
  color: var(--text);
  font: var(--fw-regular) var(--fs-15)/1 var(--font-sans);
  transition: border-color var(--dur-short) var(--ease-standard),
              box-shadow var(--dur-short) var(--ease-standard);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

/* ---------- Nav — frosted glass ---------- */
.nav-glass {
  position: sticky; top: 0; z-index: 50;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
}

/* ---------- Utility ---------- */
.skip-link {
  position: absolute; top: -44px; left: var(--s-2);
  padding: var(--s-2) var(--s-4);
  background: var(--accent); color: #fff;
  font-weight: var(--fw-semibold); font-size: var(--fs-15);
  border-radius: var(--r-sm);
  z-index: 9999;
  transition: top var(--dur-micro) var(--ease-emph);
}
.skip-link:focus { top: var(--s-2); outline: 2px solid #fff; outline-offset: 2px; }

.container { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--s-6); }
.container-narrow { max-width: var(--content-narrow); margin: 0 auto; padding: 0 var(--s-6); }
