/* PulseAI design system. Values come from docs/design.md and HANDOFF.md: one font, a fixed
   spacing scale, Tailwind type steps, flat backgrounds, motion only on transform and opacity. */

:root {
  --bg: #F5F3FF;
  --fg: #1E1B4B;
  --card: #FFFFFF;
  --muted: #EBEFF9;
  --muted-fg: #475569;
  --border: #E0E7FF;
  --input-border: #7C83A8;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-soft: #EEF0FF;
  --cta: #047857;
  --cta-hover: #065F46;
  --destructive: #DC2626;
  --warn-fg: #92400E; --warn-bg: #FEF3C7;
  --ok-fg: #065F46; --ok-bg: #D1FAE5;
  --err-fg: #991B1B; --err-bg: #FEE2E2;

  --s-25: 2px; --s-50: 4px; --s-75: 8px; --s-100: 12px; --s-200: 16px; --s-300: 24px;
  --s-400: 32px; --s-500: 40px; --s-600: 48px; --s-700: 64px; --s-800: 80px; --s-900: 96px;

  --r-md: 6px; --r-lg: 8px; --r-xl: 12px; --r-2xl: 16px; --r-3xl: 24px; --r-full: 9999px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow: 0 1px 2px rgba(30, 27, 75, 0.06), 0 8px 24px rgba(30, 27, 75, 0.06);
  --font: system-ui, "Segoe UI", "Noto Sans Hebrew", "Assistant", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  --page: 1120px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font);
  font-size: 16px; line-height: 24px; font-weight: 400; font-style: normal;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6, p { margin: 0; }
h1, h2, h3, h4, h5, h6 { text-wrap: balance; }
p, li, dd { text-wrap: pretty; }
img, svg { display: block; max-width: 100%; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); }
em, i { font-style: normal; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: var(--r-md); }

/* ---------- text styles ---------- */
.heading-1 { font-size: 60px; line-height: 60px; font-weight: 600; }
.heading-2 { font-size: 48px; line-height: 48px; font-weight: 600; }
.heading-3 { font-size: 36px; line-height: 40px; font-weight: 600; }
.heading-4 { font-size: 30px; line-height: 36px; font-weight: 600; }
.heading-5 { font-size: 24px; line-height: 32px; font-weight: 600; }
.heading-6 { font-size: 20px; line-height: 28px; font-weight: 600; }
.title-1 { font-size: 20px; line-height: 28px; font-weight: 500; }
.title-2 { font-size: 18px; line-height: 28px; font-weight: 500; }
.title-3 { font-size: 16px; line-height: 24px; font-weight: 500; }
.title-4 { font-size: 14px; line-height: 20px; font-weight: 500; }
.body-1 { font-size: 16px; line-height: 24px; font-weight: 600; }
.body-2 { font-size: 16px; line-height: 24px; font-weight: 500; }
.body-3 { font-size: 16px; line-height: 24px; font-weight: 400; }
.body-4 { font-size: 14px; line-height: 20px; font-weight: 600; }
.body-5 { font-size: 14px; line-height: 20px; font-weight: 500; }
.body-6 { font-size: 14px; line-height: 20px; font-weight: 400; }
.caption-1 { font-size: 14px; line-height: 20px; font-weight: 500; }
.caption-2 { font-size: 14px; line-height: 20px; font-weight: 400; }
.caption-3 { font-size: 12px; line-height: 16px; font-weight: 600; }
.caption-4 { font-size: 12px; line-height: 16px; font-weight: 500; }
.caption-5 { font-size: 12px; line-height: 16px; font-weight: 400; }
.muted { color: var(--muted-fg); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; }

@media (max-width: 767px) {
  .heading-1 { font-size: 36px; line-height: 40px; }
  .heading-2 { font-size: 30px; line-height: 36px; }
  .heading-3 { font-size: 30px; line-height: 36px; }
  .heading-4 { font-size: 24px; line-height: 32px; }
}

/* ---------- layout ---------- */
.container { width: 100%; max-width: var(--page); margin-inline: auto; padding-inline: var(--s-300); }
.stack > * + * { margin-block-start: var(--s-200); }
.stack-sm > * + * { margin-block-start: var(--s-75); }
.row { display: flex; gap: var(--s-100); align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: var(--s-200); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: var(--s-300); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.skip-link {
  position: absolute; inset-inline-start: var(--s-200); top: var(--s-200); z-index: 100;
  padding: var(--s-75) var(--s-100); background: var(--fg); color: #fff; border-radius: var(--r-lg);
  transform: translateY(-200%); transition: transform 300ms var(--ease);
}
.skip-link:focus { transform: translateY(0); color: #fff; }

/* ---------- buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-75);
  min-height: 44px; padding: var(--s-75) var(--s-200); border-radius: var(--r-lg);
  border: 1px solid transparent; background: var(--primary); color: #fff; cursor: pointer;
  font: inherit; font-size: 16px; line-height: 24px; font-weight: 600; text-decoration: none;
  transition: background-color 300ms var(--ease), transform 300ms var(--ease), opacity 300ms var(--ease);
  white-space: nowrap;
}
.button:hover { background: var(--primary-hover); color: #fff; }
.button:active { transform: scale(0.98); }
.button[disabled], .button[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.button-cta { background: var(--cta); }
.button-cta:hover { background: var(--cta-hover); }
.button-ghost { background: transparent; color: var(--fg); border-color: var(--border); }
.button-ghost:hover { background: var(--muted); color: var(--fg); }
.button-danger { background: var(--card); color: var(--destructive); border-color: var(--err-bg); }
.button-danger:hover { background: var(--err-bg); color: var(--err-fg); }
.button-sm { min-height: 44px; padding: var(--s-75) var(--s-100); font-size: 14px; line-height: 20px; }
.button-lg { padding: var(--s-100) var(--s-300); font-size: 18px; line-height: 28px; }
.button[aria-busy="true"] { opacity: 0.7; cursor: progress; }
.link-button {
  background: none; border: 0; padding: var(--s-75) 0; min-height: 44px; color: var(--primary);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- forms ---------- */
.field { display: grid; gap: var(--s-50); }
.field label, .label { font-size: 14px; line-height: 20px; font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: var(--s-75) var(--s-100); font: inherit; color: var(--fg);
  background: var(--card); border: 1px solid var(--input-border); border-radius: var(--r-lg);
  transition: border-color 300ms var(--ease);
}
.textarea { min-height: 120px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--destructive); }
.field-error { color: var(--err-fg); font-size: 14px; line-height: 20px; }
.hint { color: var(--muted-fg); font-size: 14px; line-height: 20px; }
.check { display: flex; gap: var(--s-75); align-items: flex-start; min-height: 44px; padding-block: var(--s-75); }
.check input { width: 20px; height: 20px; margin: var(--s-25) 0 0; accent-color: var(--primary); flex: none; }
.form-error {
  padding: var(--s-100) var(--s-200); border-radius: var(--r-lg); background: var(--err-bg); color: var(--err-fg);
}

/* ---------- surfaces ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-2xl);
  padding: var(--s-300); box-shadow: var(--shadow);
}
.card-flat { box-shadow: none; }
.card-muted { background: var(--muted); border-color: var(--muted); box-shadow: none; }
.badge {
  display: inline-flex; align-items: center; gap: var(--s-50); padding: var(--s-25) var(--s-75);
  border-radius: var(--r-full); font-size: 12px; line-height: 16px; font-weight: 600;
  background: var(--muted); color: var(--muted-fg); white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-err { background: var(--err-bg); color: var(--err-fg); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.notice { max-width: 560px; margin: var(--s-900) auto; padding-inline: var(--s-300); display: grid; gap: var(--s-200); text-align: center; justify-items: center; }
.alert { padding: var(--s-100) var(--s-200); border-radius: var(--r-lg); background: var(--warn-bg); color: var(--warn-fg); }
.alert-ok { background: var(--ok-bg); color: var(--ok-fg); }
.alert-err { background: var(--err-bg); color: var(--err-fg); }
.alert-info { background: var(--primary-soft); color: var(--fg); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-xl); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.table th, .table td { padding: var(--s-100) var(--s-200); text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-weight: 500; color: var(--muted-fg); background: var(--bg); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 300ms var(--ease); }
.table tbody tr:hover { background: var(--bg); }

/* ---------- stats ---------- */
.stat { display: grid; gap: var(--s-50); }
.stat-value { font-size: 30px; line-height: 36px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: var(--r-full); background: var(--muted); overflow: hidden; }
.meter > span { display: block; height: 100%; width: 100%; background: var(--primary); transform-origin: right; transition: transform 500ms var(--ease); }
.score { display: grid; place-items: center; width: 96px; height: 96px; border-radius: var(--r-full); border: 8px solid var(--muted); font-size: 30px; line-height: 36px; font-weight: 600; }
.score-good { border-color: var(--ok-bg); color: var(--ok-fg); }
.score-mid { border-color: var(--warn-bg); color: var(--warn-fg); }
.score-low { border-color: var(--err-bg); color: var(--err-fg); }

/* ---------- loading and empty ---------- */
.skeleton { background: var(--muted); border-radius: var(--r-lg); min-height: 20px; animation: pulse 1600ms var(--ease) infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.empty { display: grid; gap: var(--s-100); justify-items: center; text-align: center; padding: var(--s-600) var(--s-300); border: 1px dashed var(--input-border); border-radius: var(--r-2xl); }

/* ---------- toast and dialog ---------- */
.toasts { position: fixed; inset-inline: var(--s-200); bottom: var(--s-200); display: grid; gap: var(--s-75); justify-items: center; z-index: 200; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 480px; padding: var(--s-100) var(--s-200); border-radius: var(--r-lg);
  background: var(--fg); color: #fff; box-shadow: var(--shadow);
  animation: toast-in 500ms var(--ease);
}
.toast-err { background: var(--err-fg); }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px); } }
dialog { border: 0; border-radius: var(--r-2xl); padding: var(--s-300); max-width: min(560px, calc(100vw - 32px)); width: 100%; color: var(--fg); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(30, 27, 75, 0.4); }

/* ---------- site header ---------- */
.site-nav {
  position: sticky; top: var(--s-200); z-index: 50; margin: var(--s-200) auto 0; width: fit-content;
  max-width: calc(100% - var(--s-400)); display: flex; align-items: center; gap: var(--s-200);
  padding: var(--s-75) var(--s-75) var(--s-75) var(--s-200); border: 1px solid var(--border);
  border-radius: var(--r-2xl); background: rgba(255, 255, 255, 0.8);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: var(--s-75); color: var(--fg); text-decoration: none; font-weight: 600; font-size: 18px; line-height: 28px; min-height: 44px; }
.brand svg { width: 28px; height: 28px; }
.nav-links { display: flex; gap: var(--s-50); list-style: none; margin: 0; padding: 0; }
.nav-links a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: var(--s-100); border-radius: var(--r-lg); color: var(--fg); text-decoration: none; font-size: 14px; font-weight: 500; transition: background-color 300ms var(--ease); }
.nav-links a:hover, .nav-links a[aria-current="page"] { background: var(--muted); }
.menu-toggle { display: none; width: 44px; height: 44px; border: 0; background: transparent; border-radius: var(--r-lg); cursor: pointer; position: relative; }
.menu-toggle span { position: absolute; inset-inline: 12px; height: 2px; background: var(--fg); border-radius: 2px; transition: transform 500ms var(--ease), opacity 300ms var(--ease); }
.menu-toggle span:nth-child(1) { top: 15px; }
.menu-toggle span:nth-child(2) { top: 21px; }
.menu-toggle span:nth-child(3) { top: 27px; }
.menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.mobile-menu { position: fixed; inset: 0; z-index: 40; padding: 112px var(--s-300) var(--s-300); background: rgba(245, 243, 255, 0.96); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); display: grid; align-content: start; gap: var(--s-75); }
.mobile-menu a { display: flex; align-items: center; min-height: 56px; font-size: 24px; line-height: 32px; font-weight: 600; color: var(--fg); text-decoration: none; opacity: 0; transform: translateY(24px); animation: menu-in 500ms var(--ease) forwards; }
.mobile-menu .button { font-size: 18px; color: #fff; justify-content: center; }
@keyframes menu-in { to { opacity: 1; transform: none; } }
@media (max-width: 860px) {
  .site-nav { width: calc(100% - var(--s-400)); justify-content: space-between; }
  .site-nav .nav-links, .site-nav .nav-cta { display: none; }
  .menu-toggle { display: block; }
}

.site-footer { margin-top: var(--s-900); padding-block: var(--s-500); border-top: 1px solid var(--border); background: var(--card); }
.site-footer nav { display: flex; gap: var(--s-200); flex-wrap: wrap; }
.site-footer a { color: var(--muted-fg); display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- app shell (portals) ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--card); border-inline-end: 1px solid var(--border); padding: var(--s-300) var(--s-200); display: grid; align-content: start; gap: var(--s-300); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.tabs { display: grid; gap: var(--s-25); list-style: none; margin: 0; padding: 0; }
.tab { display: flex; align-items: center; gap: var(--s-75); width: 100%; min-height: 44px; padding: var(--s-75) var(--s-100); border: 0; border-radius: var(--r-lg); background: transparent; color: var(--fg); font: inherit; font-size: 14px; font-weight: 500; text-align: start; cursor: pointer; transition: background-color 300ms var(--ease); }
.tab:hover { background: var(--muted); }
.tab[aria-selected="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tab .count { margin-inline-start: auto; }
.main { padding: var(--s-400); min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s-200); flex-wrap: wrap; margin-bottom: var(--s-300); }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 30; height: auto; padding: var(--s-100) var(--s-200); gap: var(--s-100); border-inline-end: 0; border-bottom: 1px solid var(--border); }
  .tabs { display: flex; overflow-x: auto; gap: var(--s-50); scrollbar-width: none; }
  .tab { white-space: nowrap; width: auto; }
  .sidebar .side-extra { display: none; }
  .main { padding: var(--s-300) var(--s-200); }
}

/* ---------- reveal motion ---------- */
.reveal { opacity: 0; transform: translateY(32px); transition: opacity 700ms var(--ease), transform 700ms var(--ease); }
.reveal.is-in { opacity: 1; transform: none; }
.tagline .word { color: var(--fg); opacity: 0.3; transition: opacity 500ms var(--ease); }
.tagline .word.is-on { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .reveal { transform: none; transition: opacity 300ms linear; }
  .tagline .word { opacity: 1; transition: none; }
  .mobile-menu a { transform: none; }
}
