/* Ephemera — Nordic enterprise palette */
:root {
  --paper: #f6f4ef;
  --paper-2: #efece5;
  --paper-3: #e6e2d8;
  --ink: #14161a;
  --ink-2: #2a2e35;
  --ink-3: #5a6068;
  --ink-4: #8b9098;
  --rule: #d9d4c7;
  --rule-soft: #e9e4d7;
  --accent: oklch(0.55 0.15 255);
  --accent-ink: oklch(0.35 0.12 255);
  --accent-soft: oklch(0.94 0.03 255);
  --accent-line: oklch(0.82 0.06 255);
  --ok: oklch(0.58 0.11 160);
  --warn: oklch(0.68 0.13 75);
  --crit: oklch(0.55 0.17 25);
  --ok-soft: oklch(0.94 0.04 160);
  --warn-soft: oklch(0.95 0.05 75);
  --crit-soft: oklch(0.95 0.05 25);
  --font-sans: "Inter Tight", "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --shadow-1: 0 1px 0 rgba(20,22,26,0.03), 0 1px 2px rgba(20,22,26,0.04);
  --shadow-2: 0 1px 0 rgba(20,22,26,0.03), 0 8px 24px -12px rgba(20,22,26,0.12);
}

:root.dark {
  --paper: #0f1114;
  --paper-2: #15181d;
  --paper-3: #1c2026;
  --ink: #ecece8;
  --ink-2: #cfd0cb;
  --ink-3: #8e9198;
  --ink-4: #5c6068;
  --rule: #272b32;
  --rule-soft: #20242a;
  --accent: oklch(0.72 0.13 255);
  --accent-ink: oklch(0.82 0.1 255);
  --accent-soft: oklch(0.24 0.05 255);
  --accent-line: oklch(0.4 0.08 255);
  --ok-soft: oklch(0.24 0.05 160);
  --warn-soft: oklch(0.26 0.07 75);
  --crit-soft: oklch(0.26 0.08 25);
  --shadow-1: 0 1px 0 rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 1px 0 rgba(0,0,0,0.4), 0 8px 24px -12px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* { min-width: 0; }

.wl-shell { overflow-x: hidden; }

h1, h2, h3, p, a, span {
  overflow-wrap: anywhere;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { color: var(--accent); }

/* Primitives */
.mono { font-family: var(--font-mono); font-feature-settings: "ss02"; letter-spacing: 0; }
.serif { font-family: var(--font-serif); font-weight: 400; letter-spacing: -0.01em; }
.eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.rule { border: 0; border-top: 1px solid var(--rule); margin: 0; }

/* Tag / pill */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  background: var(--paper);
  letter-spacing: 0.02em;
}
.tag .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); }
.tag.ok .dot { background: var(--ok); }
.tag.warn .dot { background: var(--warn); }
.tag.crit .dot { background: var(--crit); }
.tag.accent .dot { background: var(--accent); }

/* Severity chip */
.sev {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: 0.06em; text-transform: uppercase;
  min-width: 72px;
}
.sev-crit { background: var(--crit-soft); color: var(--crit); }
.sev-warn { background: var(--warn-soft); color: var(--warn); }
.sev-ok   { background: var(--ok-soft); color: var(--ok); }
.sev-info { background: var(--accent-soft); color: var(--accent-ink); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--paper);
  font-size: 13.5px;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translateY(0.5px); }
.btn-primary {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
.btn-primary:hover { background: var(--ink-2); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--paper-2); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 5px; }

/* Card */
.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
}

/* Kbd */
kbd {
  font-family: var(--font-mono); font-size: 11px;
  padding: 1px 5px; border: 1px solid var(--rule);
  border-bottom-width: 2px; border-radius: 4px;
  background: var(--paper-2); color: var(--ink-2);
}

/* Scroll */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 10px; border: 3px solid var(--paper); }
::-webkit-scrollbar-track { background: transparent; }

/* Utility */
.hairline { height: 1px; background: var(--rule); }
.hairline-soft { height: 1px; background: var(--rule-soft); }

.grid-bg {
  background-image:
    linear-gradient(var(--rule-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule-soft) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* Marquee ticker */
@keyframes tick { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.ticker { display: flex; gap: 40px; white-space: nowrap; animation: tick 60s linear infinite; }

/* Progress shimmer */
@keyframes shimmer { 0% { background-position: 0% 0; } 100% { background-position: 200% 0; } }
.shimmer {
  background: linear-gradient(90deg, var(--paper-2) 0%, var(--paper-3) 40%, var(--paper-2) 80%);
  background-size: 200% 100%;
  animation: shimmer 1.6s ease infinite;
}

/* Focus */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Mini sparkline */
.spark { display: block; }

/* Fade in */
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fadeUp .4s ease both; }

/* Tweak panel */
.tweak-panel {
  position: fixed; right: 20px; bottom: 20px;
  width: 280px; padding: 14px; border-radius: 10px;
  background: var(--paper); border: 1px solid var(--rule);
  box-shadow: var(--shadow-2);
  z-index: 1000;
}
.tweak-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--rule-soft); }
.tweak-row:first-of-type { border-top: 0; }
.seg {
  display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden;
}
.seg button { padding: 4px 10px; font-size: 12px; color: var(--ink-3); font-family: var(--font-mono); }
.seg button.on { background: var(--ink); color: var(--paper); }

/* ---------------------------------------------------------------------------
   Responsive: tablet (≤ 900px)
--------------------------------------------------------------------------- */
@media (max-width: 900px) {
  body { font-size: 14.5px; }

  /* Collapse any inline grid to 2 columns, then 1 at phone width */
  [style*="grid-template-columns:repeat(4"],
  [style*="grid-template-columns: repeat(4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  [style*="grid-template-columns:repeat(3"],
  [style*="grid-template-columns: repeat(3"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Two-column receipts/heros fall to one column */
  [style*="1.05fr 0.95fr"],
  [style*="1.2fr 0.8fr"],
  [style*="1.4fr 1fr"],
  [style*="1fr 320px"],
  [style*="1fr 280px"],
  [style*="1fr 1fr"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Reduce max-width shells and section padding */
  [style*="max-width: 1240"], [style*="maxWidth:1240"],
  [style*="max-width: 1180"], [style*="maxWidth:1180"],
  [style*="max-width: 1100"], [style*="maxWidth:1100"],
  [style*="max-width: 1000"], [style*="maxWidth:1000"] {
    max-width: 100% !important;
  }
}

/* ---------------------------------------------------------------------------
   Responsive: phone (≤ 640px)
--------------------------------------------------------------------------- */
@media (max-width: 640px) {
  body { font-size: 14px; }

  /* Avoid iOS Safari auto-zoom on focused form fields */
  input, textarea, select { font-size: 16px; }

  /* Every inline grid collapses to a single column on phones */
  [style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Section padding compresses */
  section[style*="padding"] {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }
  section[style*="padding: 100px"],
  section[style*="padding:100px"] {
    padding-top: 56px !important;
    padding-bottom: 64px !important;
  }
  section[style*="padding: 72px"],
  section[style*="padding:72px"] {
    padding-top: 48px !important;
    padding-bottom: 24px !important;
  }
  section[style*="padding: 64px"],
  section[style*="padding:64px"] {
    padding-top: 40px !important;
    padding-bottom: 28px !important;
  }

  /* Hero h1 tightens */
  h1[style*="clamp(42px"] {
    font-size: clamp(30px, 9vw, 44px) !important;
    line-height: 1.06 !important;
  }
  h1[style*="clamp(28px"] { font-size: clamp(26px, 7.5vw, 34px) !important; }
  h2[style*="font-size: 40"], h2[style*="fontSize: 40"] {
    font-size: 28px !important;
  }

  /* Generic large serif headlines in CTA/quote blocks */
  .serif[style*="clamp(38px"] { font-size: clamp(26px, 7vw, 36px) !important; }

  /* All flex rows allow wrapping by default on phones */
  [style*="display: flex"], [style*="display:flex"] {
    flex-wrap: wrap;
  }

  /* Large buttons become full width */
  .btn[style*="padding: 12px 16px"],
  .btn[style*="padding:12px 16px"] {
    width: 100%;
    justify-content: center;
  }

  /* Tables in docs and comparison → horizontal scroll */
  .doc-shell table, [style*="border-collapse"] table, table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Tweak panel: shrink so it doesn't eat viewport */
  .tweak-panel {
    left: 12px !important;
    right: 12px !important;
    bottom: 12px !important;
    width: auto !important;
  }

  /* Pricing columns get separating borders when stacked */
  [style*="border-right: 1px solid var(--rule)"] {
    border-right: 0 !important;
    border-bottom: 1px solid var(--rule) !important;
  }

  /* Modal dialog scales down */
  [style*="max-width: 440"] { max-width: 100% !important; }

  /* Doc/status/policy shells: cramped padding */
  .doc-shell, .status-shell { padding-left: 20px !important; padding-right: 20px !important; padding-top: 32px !important; }
  .doc-shell h1 { font-size: clamp(26px, 8vw, 36px) !important; }
  .doc-nav { padding-left: 20px !important; padding-right: 20px !important; gap: 10px !important; flex-wrap: wrap; }

  /* Wordmark-heavy footers wrap cleanly */
  footer [style*="margin-left: auto"],
  footer [style*="marginLeft:auto"] { margin-left: 0 !important; }
}

/* ---------------------------------------------------------------------------
   Small phone (≤ 420px)
--------------------------------------------------------------------------- */
@media (max-width: 420px) {
  body { font-size: 13.5px; }
  section[style*="padding"] {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  /* Hide the status-head timestamp on the smallest screens to avoid overflow */
  .status-head [style*="auto-refreshes"] { display: none; }
  .status-head { flex-wrap: wrap; gap: 10px !important; }
}

/* ---------------------------------------------------------------------------
   Landing nav — hamburger on mobile
--------------------------------------------------------------------------- */
.landing-nav-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 6px;
}
.landing-nav-toggle span {
  display: block;
  width: 18px;
  height: 1.5px;
  background: var(--ink-2);
}
.landing-nav-drawer { display: none; }

@media (max-width: 840px) {
  .landing-nav-links { display: none !important; }
  .landing-nav-actions .landing-nav-signin { display: none; }
  .landing-nav-toggle { display: inline-flex; }
  .landing-nav-inner { padding: 12px 20px !important; gap: 12px !important; }
}
@media (max-width: 840px) {
  .landing-nav-drawer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--rule-soft);
    background: var(--paper);
  }
  .landing-nav-drawer a {
    font-size: 15px;
    color: var(--ink-2);
    padding: 6px 0;
  }
}

/* ---------------------------------------------------------------------------
   Dashboard shell — collapse sidebar to a drawer on mobile
--------------------------------------------------------------------------- */
.dash-drawer-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px;
  z-index: 40;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 6px;
  flex-direction: column; gap: 4px;
}
.dash-drawer-toggle span {
  display: block; width: 18px; height: 1.5px; background: var(--ink-2);
}
.dash-drawer-scrim { display: none; }

@media (max-width: 840px) {
  .dash-shell {
    display: block !important;
    grid-template-columns: none !important;
  }
  .dash-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px; max-width: 80vw;
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 50;
    box-shadow: var(--shadow-2);
    overflow-y: auto;
  }
  .dash-sidebar.open { transform: translateX(0); }
  .dash-drawer-toggle { display: inline-flex; }
  .dash-drawer-scrim {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 45;
  }
  .dash-shell main {
    padding-top: 48px;
  }
}

/* Compliance pages often use wide data tables/sidebars */
@media (max-width: 840px) {
  .compliance-shell { grid-template-columns: minmax(0, 1fr) !important; }
}

/* ---------------------------------------------------------------------------
   Upload page — ensure two-column layout stacks
--------------------------------------------------------------------------- */
@media (max-width: 840px) {
  .upload-shell { grid-template-columns: minmax(0, 1fr) !important; }
  .upload-shell aside { border-left: 0 !important; border-top: 1px solid var(--rule-soft) !important; }
}

/* Tap targets ≥ 40px on touch devices */
@media (hover: none) and (pointer: coarse) {
  .btn, .btn-sm { min-height: 36px; }
  .btn[style*="padding: 12px 16px"] { min-height: 44px; }
  a, button { touch-action: manipulation; }
}
