/* Chicky design tokens and shared components. Load before any page stylesheet.
   The rules behind these values are in frontend/DESIGN.md: change them there and here together. */
:root {
  /* Colour */
  --ink: #425664;            /* text, icons, recorded data */
  --muted: #66767f;          /* secondary text; 4.6:1 on --page */
  --subtle: #9aa6af;         /* decorative or switched-off icons only, never text */
  --teal: #1ba098;           /* brand accent: focus ring, selected outlines, predictions, icon fills */
  --teal-strong: #0f7d77;    /* teal behind or as text: buttons, user bubbles, success text */
  --teal-hover: #0b6a65;
  --teal-soft: #d9efec;      /* selected state */
  --teal-tint: #ebf6f5;      /* hover state */
  --neutral-soft: #f1f4f5;   /* neutral hover, assistant bubbles, inactive tags */
  --border: #d8dce1;         /* control and card outlines */
  --divider: #e6e8eb;        /* rules between rows and sections */
  --page: #fffcf5;           /* warm cream page background */
  --surface: #fff;           /* cards, controls, menus */
  --surface-muted: #fbfcfc;  /* inset areas: drop zone, cards inside the assistant */
  --error: #b3261e;
  --error-soft: #fdecea;
  --warning: #7a4b00;
  --warning-soft: #fff1d6;
  /* Sequential teal for magnitude (the dashboard's revenue heatmap), light to dark. Validated
     as an ordinal ramp on --surface: one hue, even steps, the lightest at 2.09:1. */
  --heat-1: #74c1b8;
  --heat-2: #36a499;
  --heat-3: #12827a;
  --heat-4: #0a5c57;
  --header-gradient: linear-gradient(90deg, #a9dcd6 0%, #dfe5dc 55%, #f5e3d2 100%);

  /* Type */
  --font-display: "Kaisei HarunoUmi", Georgia, "Times New Roman", serif;
  --font-ui: Inter, Arial, sans-serif;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 32px;
  --text-number: 40px;

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgb(66 86 100 / 7%), 0 6px 20px rgb(66 86 100 / 8%);
  --shadow-card-hover: 0 2px 4px rgb(66 86 100 / 8%), 0 14px 32px rgb(66 86 100 / 14%);
  --shadow-menu: 0 8px 24px rgb(66 86 100 / 13%);
  --shadow-float: 0 8px 24px rgb(0 0 0 / 18%);
  --control-height: 40px;

  /* Motion. js/guide.js mirrors these durations. */
  --duration-fast: 160ms;    /* menus, hover */
  --duration-base: 300ms;    /* fades, page changes */
  --duration-slow: 450ms;    /* the tour's spotlight moving */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1); /* small overshoot: buttons popping in */
  --duration-enter: 520ms;   /* cards and rows rising in when a page loads */
  --stagger: 70ms;           /* gap between one card and the next as they rise in */
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font: var(--text-md)/1.5 var(--font-display);
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 400; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

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

/* App header: menu, wordmark, account */
.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: max(12px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  background: var(--header-gradient);
}
.brand { color: var(--teal-strong); font-size: 24px; text-decoration: none; }
/* Both header menus are <details>: js/app-shell.js closes them on an outside click or Escape. */
.topbar details { position: relative; }
.topbar summary { list-style: none; cursor: pointer; }
.topbar summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  top: 48px;
  left: 0;
  width: 220px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-menu);
}
details[open] > .menu-panel { animation: menu-in var(--duration-fast) var(--ease-out); }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }

.navigation summary {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  transition: background var(--duration-fast);
}
.navigation summary:hover { background: rgb(255 255 255 / 40%); }
.navigation summary img { width: 24px; height: 24px; opacity: 0.6; }
.navigation a {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-decoration: none;
}
.navigation a:hover { background: var(--teal-tint); }
.navigation a[aria-current="page"] { background: var(--teal-soft); }

.account-menu { margin-left: auto; }
.account-menu .menu-panel { right: 0; left: auto; width: 240px; padding: 16px; }
.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ink);
  transition: box-shadow var(--duration-fast);
}
.avatar:hover, .account-menu[open] .avatar { box-shadow: 0 0 0 3px rgb(255 255 255 / 60%); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-name { overflow-wrap: anywhere; }
.account-email { margin-bottom: 12px; color: var(--muted); font-size: var(--text-sm); overflow-wrap: anywhere; }
.account-unconfirmed { margin: -4px 0 12px; color: var(--warning); font-size: var(--text-xs); }
.account-unconfirmed .text-button { font-size: var(--text-xs); }
.account-menu .secondary-button { width: 100%; }
.account-menu .account-link { margin-bottom: 8px; }
.account-menu .status-text:empty { display: none; }

/* Page layout */
.page {
  width: min(1120px, 100% - 48px);
  margin: 0 auto;
  /* Bottom room so the assistant button never covers content, plus the iPhone home bar. */
  padding: 40px 0 calc(96px + env(safe-area-inset-bottom));
}
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.page-heading h1 { font-size: var(--text-xl); }
.lede { margin-top: 4px; color: var(--muted); }
.eyebrow { color: var(--teal-strong); font-size: var(--text-xs); letter-spacing: 0.08em; text-transform: uppercase; }

.section { margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--divider); }
.section-heading h2 { font-size: var(--text-lg); }
.section-heading p { margin-top: 4px; color: var(--muted); font-size: var(--text-sm); }

/* Cards */
.card {
  padding: 20px 24px;
  border: 1px solid #f0ece4;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--duration-base) var(--ease-out), transform var(--duration-base) var(--ease-out);
}
.card-title { margin-bottom: 12px; font-size: var(--text-md); }

/* A big figure with its caption, e.g. "838 portions". */
.headline { font-size: var(--text-sm); }
.headline .card-title { margin-bottom: 0; }
.headline .number { display: block; margin-top: 4px; font-size: var(--text-number); line-height: 1.1; color: var(--ink); }
.headline .unit { font-size: var(--text-md); }
.headline .note { display: block; color: var(--muted); }

/* Buttons */
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-height);
  padding: 0 16px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.primary-button { border: 1px solid var(--teal-strong); background: var(--teal-strong); color: #fff; }
.primary-button:hover { border-color: var(--teal-hover); background: var(--teal-hover); }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.secondary-button:hover { background: var(--teal-tint); }
.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--teal-strong);
  font-size: var(--text-sm);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
:is(.primary-button, .secondary-button, .text-button):disabled { opacity: 0.45; cursor: not-allowed; }

/* Two to four mutually exclusive views; the chosen button has aria-pressed="true". */
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--neutral-soft);
}
.segmented button {
  padding: 5px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 15%); }

/* Form fields */
.field { display: grid; gap: 4px; }
.field > label, .field > legend { padding: 0; font-size: var(--text-sm); }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.input {
  width: 100%;
  min-width: 0;
  height: var(--control-height);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: var(--text-sm);
}
.input::placeholder { color: var(--muted); opacity: 1; }
.input:disabled { background: var(--neutral-soft); cursor: not-allowed; }
.select-wrap { position: relative; }
.select-wrap .input { appearance: none; padding-right: 36px; cursor: pointer; }
.select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 14px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

/* Inline feedback. Add .is-error or .is-success; never use alert(). */
.status-text { min-height: 1.5em; margin-top: 8px; color: var(--muted); font-size: var(--text-sm); }
.status-text.is-error { color: var(--error); }
.status-text.is-success { color: var(--teal-strong); }

/* The last row of every form: its status on the left, its buttons on the right with the primary
   button last. On phones the status takes its own line above the buttons. */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 16px;
  margin-top: 16px;
}
.form-actions .status-text { flex: 1 1 240px; margin: 0; }
.form-actions .status-text:empty { display: none; }

/* Small labels, e.g. "Used by active model" */
.tag {
  display: inline-block;
  width: fit-content;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--neutral-soft);
  color: var(--muted);
  font-size: var(--text-xs);
}
.tag.is-active { background: var(--teal-soft); color: var(--teal-strong); }
.tag.is-warning { background: var(--warning-soft); color: var(--warning); }

.empty-state { padding: 40px 4px; color: var(--muted); text-align: center; }

/* Moving between pages: the header stays put while the page content cross-fades. The guided tour
   skips the fade (js/guide.js) because it carries its own dimmed screen over to the next page;
   the names are off during tours too, in case a browser runs the fade anyway.
   The opt-in, @view-transition { navigation: auto; }, is an inline <style> in each page's <head>:
   from this file Chrome sometimes reads it too late and skips the transition. */
.topbar { view-transition-name: topbar; }
.page { view-transition-name: page; }
.guide-active :is(.topbar, .page) { view-transition-name: none; }
::view-transition-old(page) { animation: page-out var(--duration-fast) ease-in both; }
::view-transition-new(page) { animation: page-in var(--duration-base) var(--ease-out) 60ms both; }
::view-transition-group(page) { animation-duration: var(--duration-base); }
@keyframes page-out { to { opacity: 0; transform: translateY(-6px); } }
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } }

/* ---- Motion and polish (DESIGN.md, "Motion") ----
   Interaction feedback (hover, press, focus) applies everywhere. Entrance and ambient motion is
   inside `prefers-reduced-motion: no-preference`, so it simply doesn't exist for people who
   asked for less motion, and is off during the guided tour (.guide-active), which measures where
   things are and must not chase a card that is still rising. */

/* Controls: colour, lift and press. */
.primary-button,
.secondary-button {
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}
.primary-button:hover:not(:disabled) { box-shadow: 0 6px 16px rgb(15 125 119 / 24%); transform: translateY(-1px); }
.secondary-button:hover:not(:disabled) { border-color: #b9dcd8; box-shadow: 0 4px 12px rgb(66 86 100 / 8%); transform: translateY(-1px); }
:is(.primary-button, .secondary-button):active:not(:disabled) { box-shadow: none; transform: translateY(0) scale(0.97); transition-duration: 60ms; }
.text-button { text-decoration-color: rgb(15 125 119 / 40%); transition: text-decoration-color var(--duration-fast), color var(--duration-fast); }
.text-button:hover:not(:disabled) { color: var(--teal-hover); text-decoration-color: currentColor; }
.segmented button { transition: background-color var(--duration-fast), color var(--duration-fast), box-shadow var(--duration-fast); }
.segmented button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.tag { transition: background-color var(--duration-fast), color var(--duration-fast); }

.input { transition: border-color var(--duration-fast), box-shadow var(--duration-fast), background-color var(--duration-fast); }
.input:hover:not(:disabled, :focus) { border-color: var(--subtle); }
/* Replaces the outline on fields: a teal border (3.2:1) plus a soft halo. */
.input:focus-visible { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgb(27 160 152 / 22%); }

/* Cards lift a little under the pointer, so it's clear which one you're reading. Cards holding a
   form stay put: a card that moves while you type in it is unsettling. */
@media (hover: hover) {
  .card:not(:has(form)):hover { box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }
}

/* Header: the avatar and menu button respond, menu items nudge towards the pointer. */
.avatar { transition: box-shadow var(--duration-fast), transform var(--duration-fast) var(--ease-out); }
.avatar:hover { transform: scale(1.05); }
.navigation summary img { transition: opacity var(--duration-fast); }
.navigation summary:hover img, .navigation[open] summary img { opacity: 0.9; }
.navigation a { transition: background-color var(--duration-fast), padding-left var(--duration-fast) var(--ease-out); }
.navigation a:hover:not([aria-current="page"]) { padding-left: 16px; }

/* Status lines settle in when they report a result. */
.status-text:is(.is-success, .is-error):not(:empty) { animation: status-in var(--duration-base) var(--ease-out); }
@keyframes status-in { from { opacity: 0; transform: translateY(-3px); } }

/* "Loading…" text shimmers (js/motion.js adds .is-loading), and so does a card's "--" figure while
   its caption is loading. A slow sweep, not a spinner. */
.is-loading,
.headline:has(.is-loading) .number {
  background: linear-gradient(100deg, var(--muted) 40%, #b9c2c8 50%, var(--muted) 60%) 0 0 / 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.headline:has(.is-loading) .number { background-image: linear-gradient(100deg, var(--ink) 40%, #b9c2c8 50%, var(--ink) 60%); }

/* Order of arrival: each direct child of the page, and each card inside a grid wrapper, gets an
   index; cards rise in that order. Rows in lists and tables have their own short sequence. */
.page > :nth-child(2) { --enter: 1; } .page > :nth-child(3) { --enter: 2; } .page > :nth-child(4) { --enter: 3; }
.page > :nth-child(5) { --enter: 4; } .page > :nth-child(6) { --enter: 5; } .page > :nth-child(n + 7) { --enter: 6; }
.page > * > :nth-child(2) { --enter-step: 1; } .page > * > :nth-child(3) { --enter-step: 2; }
.page > * > :nth-child(n + 4) { --enter-step: 3; }
:is(.page ul, .page ol, .page tbody) > :nth-child(2) { --row: 1; } :is(.page ul, .page ol, .page tbody) > :nth-child(3) { --row: 2; }
:is(.page ul, .page ol, .page tbody) > :nth-child(4) { --row: 3; } :is(.page ul, .page ol, .page tbody) > :nth-child(5) { --row: 4; }
:is(.page ul, .page ol, .page tbody) > :nth-child(6) { --row: 5; } :is(.page ul, .page ol, .page tbody) > :nth-child(n + 7) { --row: 6; }

@media (prefers-reduced-motion: no-preference) {
  /* Page content rises in, card by card. `backwards` only, so once it has arrived hover can move it. */
  :root:not(.guide-active) :is(.page-heading, .card, .section, .chat-box) {
    animation: rise-in var(--duration-enter) var(--ease-out) backwards;
    animation-delay: calc((var(--enter, 0) + var(--enter-step, 0)) * var(--stagger));
  }
  :root:not(.guide-active) .page-heading > div > * { animation: rise-in var(--duration-enter) var(--ease-out) backwards; }
  :root:not(.guide-active) .page-heading .lede { animation-delay: 80ms; }

  /* Rows arrive whenever a list is filled, including after it is refreshed. */
  :root:not(.guide-active) :is(.page ul, .page ol, .page tbody) > :is(li, tr) {
    animation: row-in 380ms var(--ease-out) backwards;
    animation-delay: calc(var(--row, 0) * 45ms + 60ms);
  }

  /* The revenue heatmap fills week by week, left to right (js/motion.js sets --n). */
  :root:not(.guide-active) .heatmap .heat-cell {
    animation: cell-in 420ms var(--ease-out) backwards;
    animation-delay: calc(var(--n, 0) * 14ms);
  }

  /* The header's gradient drifts very slowly between teal and sand. */
  .topbar {
    background: linear-gradient(90deg, #a9dcd6 0%, #dfe5dc 27.5%, #f5e3d2 50%, #dfe5dc 72.5%, #a9dcd6 100%) 0 0 / 200% 100%;
    animation: header-drift 28s ease-in-out infinite alternate;
  }
  .guide-active .topbar { animation-play-state: paused; }

  .is-loading, .headline:has(.is-loading) .number { animation: shimmer 1.6s linear infinite; }

}

@keyframes rise-in { from { opacity: 0; transform: translateY(14px); } }
@keyframes row-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes cell-in { from { opacity: 0; transform: scale(0.4); } }
@keyframes header-drift { to { background-position: 100% 0; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
/* Used by chickyMotion.leave() (js/motion.js) when a row is removed: fade, then fold away. */
.is-leaving { overflow: hidden; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* Touch screens: 44px tap targets, and 16px text in fields because iOS zooms the page in when you
   tap a field with smaller text. */
@media (pointer: coarse) {
  :root { --control-height: 44px; }
  .input, select, textarea { font-size: var(--text-md); }
  .navigation summary, .avatar { width: 44px; height: 44px; }
  .brand { padding-block: 4px; }
  .segmented button { min-height: 44px; }
  .text-button { min-height: 44px; }
}

@media (max-width: 760px) {
  .topbar { padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left)); }
  .page { width: min(100% - 32px, 1120px); padding-top: 28px; }
  .page-heading { display: block; }
  .page-heading h1 { font-size: 28px; }
}
