/* Pulsa Monitor design foundation — shared by login and authenticated surfaces. */
:root {
  color-scheme: light;

  /* Core palette */
  --color-ink: #171717;
  --color-paper: #fffdf6;
  --color-surface: #ffffff;
  --color-cream: #f5f0df;
  --color-muted: #625f58;
  --color-yellow: #ffd84d;
  --color-green: #8ee3a1;
  --color-pink: #ff9db5;
  --color-blue: #94c9ff;
  --color-purple: #b7a5ff;
  --color-red: #ff6b67;
  --color-positive: #08732d;
  --color-negative: #a9211e;

  /* Backwards-compatible aliases used by current dashboard components. */
  --ink: var(--color-ink);
  --paper: var(--color-paper);
  --cream: var(--color-cream);
  --muted: var(--color-muted);
  --yellow: var(--color-yellow);
  --green: var(--color-green);
  --pink: var(--color-pink);
  --blue: var(--color-blue);
  --purple: var(--color-purple);
  --red: var(--color-red);

  /* Type */
  --font-sans: Inter, Arial, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --text-xs: .68rem;
  --text-sm: .8rem;
  --text-md: 1rem;
  --text-lg: 1.25rem;
  --text-xl: clamp(1.55rem, 2.4vw, 2rem);
  --text-display: clamp(2.7rem, 6vw, 5rem);

  /* Spacing and layout */
  --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;
  --content-max: 1440px;

  /* Neo-brutalist geometry */
  --stroke-1: 1px;
  --stroke-2: 2px;
  --stroke-3: 3px;
  --radius-xs: 2px;
  --radius-sm: 4px;
  --radius-pill: 999px;
  --shadow-sm: 3px 3px 0 var(--color-ink);
  --shadow-md: 6px 6px 0 var(--color-ink);
  --shadow-lg: 9px 9px 0 var(--color-ink);
  --focus-ring: 4px solid var(--color-purple);

  /* Legacy geometry aliases */
  --border: var(--stroke-3) solid var(--color-ink);
  --shadow: var(--shadow-md);
  --radius: var(--radius-sm);

  font-family: var(--font-sans);
  color: var(--color-ink);
  background: var(--color-cream);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  background-color: var(--color-paper);
  background-image:
    linear-gradient(rgba(23, 23, 23, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 23, 23, .045) 1px, transparent 1px);
  background-size: 32px 32px;
  font-family: var(--font-sans);
  line-height: 1.45;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, select, input[type="checkbox"], input[type="radio"] { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:where(button, input, select, textarea, a, summary):focus-visible {
  outline: var(--focus-ring);
  outline-offset: 3px;
}
:where(button, input, select, textarea):disabled {
  cursor: not-allowed;
  opacity: .52;
}

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-weight: 950; text-wrap: balance; }
h1 { margin-bottom: var(--space-2); font-size: var(--text-display); line-height: .92; letter-spacing: -.06em; }
h2 { margin-bottom: 0; font-size: var(--text-xl); line-height: 1.05; letter-spacing: -.04em; }
h3 { margin-bottom: var(--space-1); font-size: var(--text-lg); line-height: 1.1; }
p { text-wrap: pretty; }
.muted { color: var(--color-muted); line-height: 1.6; }
.mono, .label, .eyebrow, .kicker, label, th, .poll-label, .counter {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.eyebrow, .kicker {
  display: inline-block;
  margin-bottom: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: var(--stroke-2) solid var(--color-ink);
  background: var(--color-yellow);
}

/* Surfaces */
.brutal-card, .surface {
  border: var(--border);
  border-radius: var(--radius-sm);
  background: var(--color-paper);
  box-shadow: var(--shadow-md);
}
.surface-flat { border: var(--stroke-2) solid var(--color-ink); background: var(--color-surface); }
.accent-yellow { background: var(--color-yellow); }
.accent-green { background: var(--color-green); }
.accent-pink { background: var(--color-pink); }
.accent-blue { background: var(--color-blue); }
.accent-purple { background: var(--color-purple); }
.accent-red { background: var(--color-red); }

/* Actions */
.button, .icon-button {
  min-height: 44px;
  border: var(--stroke-2) solid var(--color-ink);
  border-radius: var(--radius-xs);
  background: var(--color-paper);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 950;
  letter-spacing: .035em;
  text-transform: uppercase;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}
.button { padding: 10px 16px; }
.icon-button { display: inline-grid; width: 44px; padding: 0; place-items: center; font-size: 1.25rem; }
.button:hover:not(:disabled), .icon-button:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--color-ink); }
.button:active:not(:disabled), .icon-button:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.button-primary { background: var(--color-yellow); }
.button-secondary { background: var(--color-blue); }
.button-tertiary { background: var(--color-paper); }
.button-danger { border-color: var(--color-ink); background: var(--color-red); }
.button-wide { width: 100%; margin-top: var(--space-3); }
.button-small { min-height: 36px; padding: 7px 10px; font-size: .66rem; }

/* Form controls */
:where(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
  width: 100%;
  min-height: 46px;
  margin: 7px 0 16px;
  padding: 10px 12px;
  border: var(--stroke-2) solid var(--color-ink);
  border-radius: var(--radius-xs);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}
textarea { min-height: 96px; line-height: 1.55; resize: vertical; }
select { font-weight: 800; }
input::placeholder, textarea::placeholder { color: #817d74; opacity: 1; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { background: #fff3f2; border-color: var(--color-negative); }
.form-help { margin: -9px 0 16px; color: var(--color-muted); font-size: var(--text-sm); }
.form-error {
  margin: 0 0 var(--space-2);
  padding: 9px 11px;
  border: var(--stroke-2) solid var(--color-ink);
  background: var(--color-pink);
  font-size: .86rem;
  font-weight: 750;
}

/* Status primitives */
.status-pill, .status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 5px 9px;
  border: var(--stroke-2) solid var(--color-ink);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .035em;
  text-transform: uppercase;
}
.status-authenticated, [data-status="success"] { background: var(--color-green); }
.status-reauth_required, [data-status="warning"] { background: var(--color-yellow); }
.status-provider_unavailable, [data-status="error"] { background: var(--color-pink); }
[data-status="neutral"] { background: var(--color-purple); }

/* Overlay and feedback */
dialog.modal {
  width: min(560px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: clamp(20px, 4vw, 30px);
  overflow: auto;
  border: var(--border);
  border-radius: var(--radius-sm);
  background: var(--color-paper);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(23, 23, 23, .72); }
.toast {
  position: fixed;
  z-index: 50;
  right: 22px;
  bottom: 22px;
  max-width: min(430px, calc(100% - 44px));
  padding: 14px 18px;
  border: var(--border);
  border-radius: var(--radius-sm);
  background: var(--color-green);
  box-shadow: var(--shadow-md);
  font-weight: 850;
}
.toast.error { background: var(--color-pink); }

@media (max-width: 700px) {
  :root { --shadow-md: 4px 4px 0 var(--color-ink); --shadow-lg: 6px 6px 0 var(--color-ink); }
  h1 { font-size: clamp(2.5rem, 14vw, 4rem); }
  .toast { right: 12px; bottom: 12px; max-width: calc(100% - 24px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}

@media (forced-colors: active) {
  .brutal-card, .surface, .button, .icon-button, input, select, textarea { box-shadow: none; }
  .active, [aria-current="page"], [aria-pressed="true"] { outline: 3px solid CanvasText; outline-offset: -3px; }
}
