/* Kerno Analytics — Design System */

:root {
  /* Brand palette */
  --kerno-cream: #f7f3eb;
  --kerno-cream-dark: #ede8dc;
  --kerno-grey-100: #f0eeea;
  --kerno-grey-200: #d9d6d0;
  --kerno-grey-300: #b8b4ac;
  --kerno-grey-400: #8a857c;
  --kerno-grey-500: #5c5850;
  --kerno-orange: #e86a1a;
  --kerno-orange-dark: #c45512;
  --kerno-orange-light: #fff4eb;

  /* Semantic */
  --kerno-up: #1a7a4a;
  --kerno-up-bg: #e8f5ee;
  --kerno-up-border: #a7d4bc;
  --kerno-down: #b91c1c;
  --kerno-down-bg: #fce8e8;
  --kerno-down-border: #f5b8b8;
  --kerno-neutral-bg: #ffffff;
  --kerno-bottom-line: #166534;
  --kerno-bottom-line-bg: #ecfdf3;
  --kerno-bottom-line-border: #86efac;

  /* Typography — single canonical declaration; do not redeclare elsewhere */
  --font-sans: "Iowan Old Style", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;

  /* Spacing — strict 8pt scale (1 unit = 0.5rem = 8px) */
  --space-xs: 0.25rem;   /* 4px  — half-step, hairline gaps only */
  --space-sm: 0.5rem;    /* 8px */
  --space-md: 1rem;      /* 16px */
  --space-lg: 1.5rem;    /* 24px */
  --space-xl: 2rem;      /* 32px */
  --space-2xl: 3rem;     /* 48px */

  /* Layout */
  --max-width: 72rem;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(92, 88, 80, 0.06);
  --shadow-md: 0 4px 12px rgba(92, 88, 80, 0.08);
  --kerno-surface: #ffffff;
  --kerno-surface-raised: #ffffff;
  --kerno-surface-alt: var(--kerno-cream);

  /* Skeleton shimmer */
  --skeleton-base: var(--kerno-grey-100);
  --skeleton-sheen: var(--kerno-grey-200);
}

/* Dark mode */
[data-theme="dark"] {
  color-scheme: dark;
  --kerno-cream: #12100e;
  --kerno-cream-dark: #1a1816;
  --kerno-grey-100: #24211e;
  --kerno-grey-200: #3a3632;
  --kerno-grey-300: #5c5650;
  --kerno-grey-400: #a39e94;
  --kerno-grey-500: #e8e4dc;
  --kerno-orange: #f07830;
  --kerno-orange-dark: #ff8c42;
  --kerno-orange-light: #3d2818;
  --kerno-up: #4ade80;
  --kerno-up-bg: #152820;
  --kerno-up-border: #2d5a40;
  --kerno-down: #f87171;
  --kerno-down-bg: #301818;
  --kerno-down-border: #5a2d2d;
  --kerno-neutral-bg: #24211e;
  --kerno-bottom-line: #86efac;
  --kerno-bottom-line-bg: #152820;
  --kerno-bottom-line-border: #2d5a40;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --kerno-surface: #1e1c19;
  --kerno-surface-raised: #24211e;
  --kerno-surface-alt: #24211e;
  --skeleton-base: #24211e;
  --skeleton-sheen: #3a3632;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--kerno-grey-500);
  background-color: var(--kerno-cream);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  z-index: 100;
  padding: var(--space-sm) var(--space-md);
  background: var(--kerno-orange);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.skip-link:focus {
  top: var(--space-md);
}

:focus-visible {
  outline: 2px solid var(--kerno-orange);
  outline-offset: 2px;
}

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--kerno-orange);
  text-decoration: none;
}

a:hover {
  color: var(--kerno-orange-dark);
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 var(--space-md);
  color: var(--kerno-grey-500);
  font-weight: 600;
  line-height: 1.25;
}

h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
}

h2 {
  font-size: clamp(1.35rem, 3vw, 1.75rem);
}

h3 {
  font-size: 1.125rem;
}

h4 {
  font-size: 0.9375rem;
  font-weight: 700;
}

p {
  margin: 0 0 var(--space-md);
}

/* Site chrome */

.site-header {
  background: var(--kerno-cream-dark);
  border-bottom: 1px solid var(--kerno-grey-200);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-md) var(--space-lg);
}

.site-header__end {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--kerno-grey-400);
  background: var(--kerno-surface);
  border: 1px solid var(--kerno-grey-200);
  border-radius: var(--radius-lg);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--kerno-orange);
  color: var(--kerno-orange);
}

.theme-toggle__track {
  display: inline-flex;
  align-items: center;
  width: 2.25rem;
  height: 1.25rem;
  padding: 2px;
  background: var(--kerno-grey-200);
  border-radius: 999px;
  transition: background 0.2s ease;
}

[data-theme="dark"] .theme-toggle__track {
  background: var(--kerno-orange);
}

.theme-toggle__thumb {
  width: 0.875rem;
  height: 0.875rem;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease;
}

[data-theme="dark"] .theme-toggle__thumb {
  transform: translateX(0.95rem);
}

.theme-toggle__label {
  display: none;
}

@media (min-width: 48rem) {
  .theme-toggle__label {
    display: inline;
  }
}

.site-nav__account {
  font-weight: 600;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--kerno-grey-500);
  text-decoration: none;
}

.site-logo:hover {
  color: var(--kerno-orange);
  text-decoration: none;
}

.site-logo__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: var(--kerno-orange);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 800;
  border-radius: var(--radius-sm);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm) var(--space-lg);
}

.site-nav a {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--kerno-grey-500);
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--kerno-orange);
}

.site-nav-toggle {
  display: none;
  padding: var(--space-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--kerno-grey-500);
  background: var(--kerno-surface);
  border: 1px solid var(--kerno-grey-200);
  border-radius: var(--radius-md);
  cursor: pointer;
}

@media (max-width: 40rem) {
  .site-nav-toggle {
    display: inline-flex;
  }

  .site-header__end {
    position: relative;
  }

  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    flex-direction: column;
    min-width: 10rem;
    padding: var(--space-sm);
    background: var(--kerno-surface-raised);
    border: 1px solid var(--kerno-grey-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
  }

  .site-nav.is-open {
    display: flex;
  }

  .site-header__inner {
    position: relative;
  }
}

.site-main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg) var(--space-2xl);
}

.site-footer {
  margin-top: auto;
  padding: var(--space-lg);
  background: var(--kerno-grey-100);
  border-top: 1px solid var(--kerno-grey-200);
  text-align: center;
  font-size: 0.875rem;
  color: var(--kerno-grey-400);
}

/* Utilities */

.page-hero {
  margin-bottom: var(--space-2xl);
}

.page-hero__eyebrow {
  display: inline-block;
  margin-bottom: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--kerno-orange);
  background: var(--kerno-orange-light);
  border-radius: var(--radius-sm);
}

.page-hero__lead {
  font-size: 1.125rem;
  max-width: 42rem;
  color: var(--kerno-grey-400);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn--primary {
  color: #fff;
  background: var(--kerno-orange);
}

.btn--primary:hover {
  background: var(--kerno-orange-dark);
  color: #fff;
  text-decoration: none;
}

.btn--secondary {
  color: var(--kerno-grey-500);
  background: var(--kerno-grey-100);
  border: 1px solid var(--kerno-grey-200);
}

.btn--secondary:hover {
  background: var(--kerno-grey-200);
  color: var(--kerno-grey-500);
  text-decoration: none;
}

.card-grid {
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}

.feature-card {
  padding: var(--space-lg);
  background: var(--kerno-surface);
  border: 1px solid var(--kerno-grey-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.feature-card h3 {
  color: var(--kerno-orange);
}

/* Home */

.home-hero {
  display: grid;
  gap: var(--space-2xl);
  margin-bottom: var(--space-2xl);
}

@media (min-width: 56rem) {
  .home-hero {
    grid-template-columns: 1fr 1.05fr;
    align-items: center;
  }
}

.home-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
}

.home-preview {
  position: relative;
}

.home-preview::before {
  content: "";
  position: absolute;
  inset: -0.5rem;
  background: linear-gradient(135deg, var(--kerno-orange-light), transparent 60%);
  border-radius: calc(var(--radius-lg) + 0.5rem);
  z-index: -1;
}

.home-preview .ticker-card {
  box-shadow: var(--shadow-md), 0 12px 40px rgba(92, 88, 80, 0.1);
}

.home-preview-note {
  margin-top: var(--space-md);
  font-size: 0.8125rem;
  color: var(--kerno-grey-400);
  text-align: center;
}

/* Search */

.search-wrap {
  position: relative;
  max-width: 20rem;
  margin-bottom: var(--space-lg);
}

.search-input {
  width: 100%;
  padding: 0.625rem 0.875rem 0.625rem 2.25rem;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--kerno-grey-500);
  background: var(--kerno-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238a857c' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.1a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 0.75rem center;
  border: 1px solid var(--kerno-grey-200);
  border-radius: var(--radius-md);
}

.search-input::placeholder {
  color: var(--kerno-grey-300);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: var(--space-xs);
  list-style: none;
  background: var(--kerno-surface);
  border: 1px solid var(--kerno-grey-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 20;
}

.search-result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.search-result:hover,
.search-result:focus-visible {
  background: var(--kerno-orange-light);
}

.search-result__ticker {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--kerno-orange);
}

.search-result__name {
  font-size: 0.8125rem;
  color: var(--kerno-grey-400);
}

.search-result--live {
  border-top: 1px solid var(--kerno-grey-100);
  margin-top: var(--space-xs);
  padding-top: var(--space-xs);
}

.search-result__name--live {
  color: var(--kerno-orange);
  font-weight: 500;
}

.search-empty {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  color: var(--kerno-grey-400);
}

.analysis-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.analysis-meta {
  margin: 0;
  font-size: 0.875rem;
  color: var(--kerno-grey-400);
}

.analysis-hint {
  margin: var(--space-sm) 0 0;
  font-size: 0.75rem;
  color: var(--kerno-grey-300);
}

/* ── Skeleton shimmer (loading state) ─────────────────────────────────── */

.skeleton-shimmer {
  position: relative;
  display: block;
  overflow: hidden;
  background: var(--skeleton-base);
}

.skeleton-shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--skeleton-sheen) 50%,
    transparent 100%
  );
  animation: kerno-shimmer-sweep 1.6s ease-in-out infinite;
}

@keyframes kerno-shimmer-sweep {
  100% { transform: translateX(100%); }
}

.reduce-motion .skeleton-shimmer::after {
  animation: none;
  opacity: 0.6;
}

/* ── Toast notifications ───────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: var(--space-xl);
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  width: max-content;
  max-width: calc(100vw - var(--space-xl) * 2);
  pointer-events: none;
}

.toast {
  padding: var(--space-sm) var(--space-lg);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--kerno-grey-500);
  background: var(--kerno-surface-raised);
  border: 1px solid var(--kerno-grey-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  animation: kerno-toast-in 0.2s ease;
}

.toast--success {
  color: var(--kerno-up);
  border-color: var(--kerno-up-border);
  background: var(--kerno-up-bg);
}

@keyframes kerno-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.reduce-motion .toast {
  animation: none;
}

/* ── Layout utilities ─────────────────────────────────────────────────── */

.u-mb-0 {
  margin-bottom: 0;
}
