/*
  ZonePulse base styles and shared component classes.

  One stylesheet for both worlds:
    - static pages link it right after tokens.css
      (<link rel="stylesheet" href="/zp-base.css">),
    - the React app imports it from src/index.css, and the ui/ components in
      src/components/ui/ are thin wrappers around these classes.

  Everything sits in cascade layers, so a page's own unlayered <style> and
  Tailwind utilities (layer "utilities") always win over it. That keeps it
  safe to link on a page that still has its own styles.

  Colours come only from the semantic --zp-* tokens in tokens.css, so every
  class here follows the dark / light theme on its own.

  Motion: everything moves on --zp-ease-out. Overlays (dialogs, drawers,
  sheets, menus, toasts) animate in with keyframes and out when their
  element carries data-state="closed"; the owner removes the element after
  --zp-dur-slow / --zp-dur-slower. prefers-reduced-motion switches it all off.
*/
@layer base, components;

/* ----------------------------------------------------------------------- */
@layer base {
  /* Thin scrollbars everywhere (page and every scrolling panel).
     Chrome/Edge/Safari use the ::-webkit-scrollbar rules; Firefox, which has
     no such pseudo-elements, gets the standard properties instead. (Chrome
     121+ ignores the ::-webkit rules when scrollbar-width is set, hence the
     @supports split.) */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  ::-webkit-scrollbar-track,
  ::-webkit-scrollbar-corner {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--zp-border-strong);
    border-radius: var(--zp-radius-full);
  }
  ::-webkit-scrollbar-thumb:hover {
    background: var(--zp-text-subtle);
  }
  @supports not selector(::-webkit-scrollbar) {
    * {
      scrollbar-width: thin;
      scrollbar-color: var(--zp-border-strong) transparent;
    }
  }

  html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-text-size-adjust: 100%;
  }

  body {
    font-family: var(--zp-font-sans);
    line-height: var(--zp-lh-normal);
  }

  code, kbd, samp, pre {
    font-family: var(--zp-font-mono);
  }

  ::selection {
    background: color-mix(in srgb, var(--zp-brand) 28%, transparent);
  }

  :focus-visible {
    outline: 2px solid var(--zp-focus-ring);
    outline-offset: 2px;
  }
}

/* ----------------------------------------------------------------------- */
@layer components {

  /* ---- Numbers: prices, counts, percentages line up in columns ---- */
  .zp-num {
    font-variant-numeric: tabular-nums;
  }
  .zp-mono {
    font-family: var(--zp-font-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
  }

  /* ---- Type helpers ---- */
  .zp-eyebrow {
    font-size: var(--zp-fs-2xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--zp-text-subtle);
  }
  .zp-heading {
    font-weight: 600;
    letter-spacing: var(--zp-tracking-tight);
    line-height: var(--zp-lh-tight);
    color: var(--zp-text);
  }
  /* Page titles, hero lines and dialog titles */
  .zp-display {
    font-family: var(--zp-font-display);
    font-weight: 600;
    letter-spacing: var(--zp-tracking-display);
    line-height: var(--zp-lh-tight);
    color: var(--zp-text);
  }

  /* ---- Brand lockup: the logo mark + "ZonePulse" in Sora. One size
     everywhere (landing header, sign-in dialog, app bar, auth pages,
     admin) so the brand never shifts between pages. ---- */
  .zp-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--zp-text);
    text-decoration: none;
    line-height: 1;
  }
  .zp-brand img {
    display: block;
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex: none;
  }
  .zp-brand-name {
    font-family: var(--zp-font-display);
    font-weight: 600;
    font-size: 19px;
    letter-spacing: var(--zp-tracking-display);
    white-space: nowrap;
  }
  /* "Zone" is set in the brand green, "Pulse" in the text colour (the
     emails do the same in services/email_layout.py). */
  .zp-brand-zone {
    color: var(--zp-brand);
  }

  /* ---- Surfaces ---- */
  .zp-card {
    background: var(--zp-surface);
    border: 1px solid var(--zp-hairline);
    border-radius: var(--zp-radius-lg);
    box-shadow: var(--zp-highlight);
  }
  .zp-card-hover {
    transition: border-color var(--zp-dur-base) var(--zp-ease-out),
                box-shadow var(--zp-dur-base) var(--zp-ease-out),
                transform var(--zp-dur-slow) var(--zp-ease-out);
  }
  .zp-card-hover:hover {
    border-color: var(--zp-hairline-strong);
    transform: translateY(-2px);
  }
  /* Nested tile inside a card (metrics, settings rows) */
  .zp-tile {
    background: var(--zp-surface-raised);
    border: 1px solid var(--zp-hairline);
    border-radius: var(--zp-radius-md);
  }
  /* Frosted panel for layers that float over content: bars, dialogs, toasts */
  .zp-glass {
    background: var(--zp-glass);
    -webkit-backdrop-filter: saturate(140%) blur(var(--zp-glass-blur));
    backdrop-filter: saturate(140%) blur(var(--zp-glass-blur));
    border: 1px solid var(--zp-hairline);
  }
  .zp-divider {
    height: 1px;
    border: 0;
    background: var(--zp-hairline);
    margin: 0;
  }

  /* ---- Buttons ----
     .zp-btn gives the layout (height, padding, icon gap); a variant class
     gives the paint. The variants also work on their own, so older markup
     that sizes buttons with utilities keeps working. */
  .zp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--zp-space-2);
    height: var(--zp-control-md);
    padding: 0 var(--zp-space-4);
    font-family: inherit;
    font-size: var(--zp-fs-base);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
  }
  .zp-btn-sm {
    height: var(--zp-control-sm);
    padding: 0 var(--zp-space-3);
    font-size: var(--zp-fs-sm);
    border-radius: var(--zp-radius-sm);
  }
  .zp-btn-lg {
    height: var(--zp-control-lg);
    padding: 0 var(--zp-space-6);
    font-size: 15px;
  }
  .zp-btn-icon {
    width: var(--zp-control-md);
    padding: 0;
  }
  .zp-btn-sm.zp-btn-icon { width: var(--zp-control-sm); }
  .zp-btn-lg.zp-btn-icon { width: var(--zp-control-lg); }

  .zp-btn-primary,
  .zp-btn-secondary,
  .zp-btn-ghost,
  .zp-btn-danger {
    border-radius: var(--zp-radius-md);
    transition: background-color var(--zp-dur-base) var(--zp-ease-out),
                border-color var(--zp-dur-base) var(--zp-ease-out),
                color var(--zp-dur-base) var(--zp-ease-out),
                box-shadow var(--zp-dur-base) var(--zp-ease-out),
                opacity var(--zp-dur-base) var(--zp-ease-out),
                transform var(--zp-dur-base) var(--zp-ease-out);
  }
  .zp-btn-primary:active:not(:disabled),
  .zp-btn-secondary:active:not(:disabled),
  .zp-btn-ghost:active:not(:disabled),
  .zp-btn-danger:active:not(:disabled) {
    transform: scale(0.97);
  }
  .zp-btn-primary:disabled,
  .zp-btn-secondary:disabled,
  .zp-btn-ghost:disabled,
  .zp-btn-danger:disabled,
  .zp-btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
  }

  .zp-btn-primary {
    background: var(--zp-gradient-action);
    color: var(--zp-on-action);
    border: 1px solid transparent;
    box-shadow: var(--zp-shadow-action);
  }
  .zp-btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--zp-shadow-action-hover);
  }

  .zp-btn-secondary {
    background: var(--zp-surface-raised);
    border: 1px solid var(--zp-hairline-strong);
    color: var(--zp-text);
  }
  .zp-btn-secondary:hover:not(:disabled) {
    background: var(--zp-surface-strong);
  }

  .zp-btn-ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--zp-text-muted);
  }
  .zp-btn-ghost:hover:not(:disabled) {
    background: var(--zp-fill-muted);
    color: var(--zp-text);
  }

  .zp-btn-danger {
    background: var(--zp-supply-tint);
    border: 1px solid transparent;
    color: var(--zp-danger);
  }
  .zp-btn-danger:hover:not(:disabled) {
    background: color-mix(in srgb, var(--zp-danger) 22%, transparent);
  }

  /* Plain text button (inline links that act, e.g. "Forgot password?") */
  .zp-link-btn {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-weight: 600;
    color: var(--zp-link);
    cursor: pointer;
    text-decoration: none;
  }
  .zp-link-btn:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  /* ---- Pills / badges ---- */
  .zp-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 10px;
    border-radius: var(--zp-radius-full);
    font-size: var(--zp-fs-xs);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: var(--zp-text);
    background: var(--zp-fill-muted);
  }
  .zp-pill-brand   { color: var(--zp-brand-soft); background: var(--zp-brand-tint); }
  .zp-pill-demand  { color: var(--zp-demand);     background: var(--zp-demand-tint); }
  .zp-pill-supply  { color: var(--zp-supply);     background: var(--zp-supply-tint); }
  .zp-pill-danger  { color: var(--zp-danger);     background: var(--zp-supply-tint); }
  .zp-pill-warning { color: var(--zp-warning);    background: var(--zp-warning-tint); }
  .zp-pill-info    { color: var(--zp-info);       background: var(--zp-info-tint); }
  .zp-pill-neutral { color: var(--zp-text-muted); background: var(--zp-neutral-tint); }
  .zp-pill-dot::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--zp-radius-full);
    background: currentColor;
  }

  /* Live dot: a soft ring breathes out of it (market open, live prices) */
  .zp-live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    flex: none;
    border-radius: var(--zp-radius-full);
    background: var(--zp-brand);
    animation: zp-breathe 2.4s ease-in-out infinite;
  }

  /* ---- Form controls ---- */
  .zp-label {
    display: block;
    margin-bottom: var(--zp-space-2);
    font-size: var(--zp-fs-sm);
    font-weight: 500;
    color: var(--zp-text-muted);
  }
  .zp-hint {
    margin-top: 6px;
    font-size: var(--zp-fs-xs);
    color: var(--zp-text-subtle);
  }
  .zp-hint-error {
    color: var(--zp-danger);
  }
  .zp-input {
    display: block;
    box-sizing: border-box;
    width: 100%;
    height: 44px;
    padding: 0 14px;
    font: inherit;
    font-size: var(--zp-fs-base);
    font-weight: 500;
    color: var(--zp-text);
    background: var(--zp-surface-raised);
    border: 1px solid var(--zp-hairline-strong);
    border-radius: var(--zp-radius-md);
    outline: none;
    transition: border-color var(--zp-dur-base) var(--zp-ease-out),
                box-shadow var(--zp-dur-base) var(--zp-ease-out),
                background-color var(--zp-dur-base) var(--zp-ease-out);
  }
  textarea.zp-input {
    height: auto;
    min-height: 96px;
    padding: 12px 14px;
    line-height: var(--zp-lh-normal);
    resize: vertical;
  }
  /* Native arrow replaced by a token-coloured chevron (two gradient halves)
     so the select matches input height and follows the theme. */
  select.zp-input {
    -webkit-appearance: none;
    appearance: none;
    padding-right: var(--zp-space-8);
    cursor: pointer;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--zp-text-muted) 50%),
      linear-gradient(135deg, var(--zp-text-muted) 50%, transparent 50%);
    background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
  }
  .zp-input::placeholder {
    color: var(--zp-text-subtle);
  }
  /* Number fields: no browser spinner arrows; type or use the arrow keys */
  .zp-input[type="number"] {
    -moz-appearance: textfield;
  }
  .zp-input[type="number"]::-webkit-inner-spin-button,
  .zp-input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
  .zp-input:focus,
  .zp-input:focus-visible {
    border-color: var(--zp-brand);
    box-shadow: 0 0 0 4px var(--zp-brand-tint);
    background-color: var(--zp-surface);
    outline: none;
  }
  .zp-input:disabled,
  .zp-input[readonly] {
    color: var(--zp-text-muted);
  }
  .zp-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
  .zp-input[aria-invalid="true"] {
    border-color: var(--zp-danger);
  }
  /* An input with a leading icon: wrap both in .zp-input-icon */
  .zp-input-icon {
    position: relative;
  }
  .zp-input-icon > svg,
  .zp-input-icon > .zp-input-adorn {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--zp-text-subtle);
    pointer-events: none;
  }
  .zp-input-icon > .zp-input {
    padding-left: 42px;
  }

  /* ---- Switch ---- */
  .zp-switch {
    position: relative;
    flex: none;
    width: 40px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: var(--zp-radius-full);
    background: var(--zp-hairline-strong);
    cursor: pointer;
    transition: background-color var(--zp-dur-base) var(--zp-ease-out);
  }
  .zp-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: var(--zp-radius-full);
    background: var(--zp-white);
    box-shadow: var(--zp-shadow-sm);
    transition: transform var(--zp-dur-slow) var(--zp-ease-out);
  }
  .zp-switch[aria-checked="true"] {
    background: var(--zp-green-500);
  }
  .zp-switch[aria-checked="true"]::after {
    transform: translateX(16px);
  }
  .zp-switch:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* ---- Segmented control (tabs, timeframes, theme switch) ----
     A .zp-segmented-thumb child, positioned by script, slides under the
     selected option; without one the selected option paints itself. */
  .zp-segmented {
    position: relative;
    display: inline-flex;
    padding: 3px;
    background: var(--zp-surface-raised);
    border: 1px solid var(--zp-hairline);
    border-radius: var(--zp-radius-md);
  }
  .zp-segmented > button {
    position: relative;
    z-index: 1;
    height: 32px;
    padding: 0 var(--zp-space-3);
    font: inherit;
    font-size: var(--zp-fs-sm);
    font-weight: 600;
    color: var(--zp-text-muted);
    background: transparent;
    border: 0;
    border-radius: var(--zp-radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color var(--zp-dur-base) var(--zp-ease-out),
                color var(--zp-dur-base) var(--zp-ease-out);
  }
  .zp-segmented > button:hover {
    color: var(--zp-text);
  }
  .zp-segmented > button[aria-pressed="true"],
  .zp-segmented > button[aria-selected="true"] {
    color: var(--zp-text);
    background: var(--zp-surface-strong);
  }
  .zp-segmented-thumb {
    position: absolute;
    z-index: 0;
    top: 3px;
    bottom: 3px;
    left: 0;
    border-radius: var(--zp-radius-sm);
    background: var(--zp-surface-strong);
    box-shadow: var(--zp-shadow-sm);
    transition: transform var(--zp-dur-slow) var(--zp-ease-out),
                width var(--zp-dur-slow) var(--zp-ease-out),
                background-color var(--zp-dur-slow) var(--zp-ease-out);
  }
  .zp-segmented:has(> .zp-segmented-thumb) > button[aria-pressed="true"],
  .zp-segmented:has(> .zp-segmented-thumb) > button[aria-selected="true"] {
    background: transparent;
  }

  /* ---- Tables ---- */
  .zp-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
  }
  .zp-table th {
    text-align: left;
    height: 44px;
    background: var(--zp-surface);
    color: var(--zp-text-subtle);
    font-weight: 600;
    text-transform: uppercase;
    font-size: var(--zp-fs-2xs);
    letter-spacing: 0.06em;
    white-space: nowrap;
    border-bottom: 1px solid var(--zp-hairline);
  }
  .zp-table td {
    border-bottom: 1px solid var(--zp-hairline);
  }
  .zp-table tbody tr {
    transition: background-color var(--zp-dur-base) var(--zp-ease-out);
  }
  .zp-table tbody tr:hover {
    background: var(--zp-fill-subtle);
  }
  .zp-table tbody tr[aria-selected="true"] {
    background: var(--zp-brand-tint);
  }
  /* A whole row that opens something: put .zp-row-link on the main button
     or link in the row, and position: relative on the row. Its hit area
     stretches over the row; other buttons in the row need z-index: 1.
     Not for table rows: Safari doesn't let a <tr> contain the stretched
     layer, so each one covers the whole table. Put onClick on the <tr>
     instead (the layer is switched off inside .zp-table below). */
  .zp-row-link {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    color: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }
  .zp-row-link::after {
    content: "";
    position: absolute;
    inset: 0;
  }
  .zp-table .zp-row-link::after {
    content: none;
  }
  .zp-table .zp-row-link:focus-visible {
    outline: 2px solid var(--zp-focus-ring);
    outline-offset: 2px;
    border-radius: var(--zp-radius-xs);
  }
  .zp-row-link:focus-visible {
    outline: none;
  }
  .zp-row-link:focus-visible::after {
    outline: 2px solid var(--zp-focus-ring);
    outline-offset: -2px;
    border-radius: var(--zp-radius-xs);
  }

  /* ---- Distance meter: a fuller bar means price is closer to the zone ---- */
  .zp-meter {
    position: relative;
    height: 6px;
    border-radius: var(--zp-radius-full);
    background: var(--zp-surface-strong);
    overflow: hidden;
  }
  .zp-meter > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: currentColor;
    transition: width var(--zp-dur-slower) var(--zp-ease-out);
  }

  /* ---- Progress bar with a moving sheen (scans, refreshes) ---- */
  .zp-progress {
    position: relative;
    height: 4px;
    border-radius: var(--zp-radius-full);
    background: var(--zp-surface-strong);
    overflow: hidden;
  }
  .zp-progress > span {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--zp-green-600), var(--zp-green-300));
    transition: width 300ms linear;
  }
  .zp-progress-sheen::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30%;
    background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--zp-white) 35%, transparent), transparent);
    animation: zp-sheen 1.4s ease-in-out infinite;
  }

  /* ---- Dialog ---- */
  .zp-modal-bg {
    position: fixed;
    inset: 0;
    z-index: var(--zp-z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--zp-space-4);
    background: var(--zp-scrim);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    animation: zp-fade-in var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-modal {
    background: var(--zp-surface-overlay);
    border: 1px solid var(--zp-hairline-strong);
    border-radius: var(--zp-radius-xl);
    box-shadow: var(--zp-shadow-lg), var(--zp-highlight);
    padding: var(--zp-space-6);
    max-height: 88vh;
    overflow: auto;
    animation: zp-pop-in var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-modal-bg[data-state="closed"] {
    animation: zp-fade-out var(--zp-dur-base) var(--zp-ease-out) both;
  }
  .zp-modal-bg[data-state="closed"] .zp-modal {
    animation: zp-pop-out var(--zp-dur-base) var(--zp-ease-out) both;
  }
  /* Glass variant: sign-in dialogs over the Ghost Fibers background */
  .zp-modal-bg.zp-modal-bg-frost {
    -webkit-backdrop-filter: blur(14px) saturate(120%);
    backdrop-filter: blur(14px) saturate(120%);
  }
  .zp-modal.zp-modal-glass {
    background: var(--zp-glass);
    -webkit-backdrop-filter: blur(28px);
    backdrop-filter: blur(28px);
  }

  /* ---- Full-screen chart (over the details drawer) ---- */
  .zp-chartview-bg {
    position: fixed;
    inset: 0;
    z-index: var(--zp-z-modal);
    display: flex;
    padding: var(--zp-space-4);
    background: var(--zp-scrim);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    animation: zp-fade-in var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-chartview {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    background: var(--zp-surface-overlay);
    border: 1px solid var(--zp-hairline-strong);
    border-radius: var(--zp-radius-xl);
    box-shadow: var(--zp-shadow-lg), var(--zp-highlight);
    overflow: hidden;
    outline: none;
    animation: zp-pop-in var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-chartview-bg[data-state="closed"] {
    animation: zp-fade-out var(--zp-dur-base) var(--zp-ease-out) both;
  }
  .zp-chartview-bg[data-state="closed"] .zp-chartview {
    animation: zp-pop-out var(--zp-dur-base) var(--zp-ease-out) both;
  }
  /* phones: edge to edge, clear of the notch and home bar */
  @media (max-width: 767px) {
    .zp-chartview-bg {
      padding: 0;
    }
    .zp-chartview {
      border: 0;
      border-radius: 0;
      padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
  }

  /* ---- Drawer (desktop side panel) and sheet (phone bottom panel) ---- */
  .zp-drawer-bg {
    position: fixed;
    inset: 0;
    z-index: var(--zp-z-drawer);
    background: var(--zp-scrim);
    animation: zp-fade-in var(--zp-dur-slower) var(--zp-ease-out) both;
  }
  .zp-drawer {
    position: fixed;
    z-index: var(--zp-z-drawer);
    top: 0;
    right: 0;
    bottom: 0;
    width: min(560px, 100%);
    display: flex;
    flex-direction: column;
    background: var(--zp-surface);
    border-left: 1px solid var(--zp-hairline-strong);
    box-shadow: var(--zp-shadow-lg);
    outline: none;
    animation: zp-slide-in-right var(--zp-dur-slower) var(--zp-ease-out) both;
  }
  .zp-drawer-bg[data-state="closed"] {
    animation: zp-fade-out var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-drawer[data-state="closed"] {
    animation: zp-slide-out-right var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-sheet {
    position: fixed;
    z-index: var(--zp-z-drawer);
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: var(--zp-surface);
    border-top: 1px solid var(--zp-hairline-strong);
    border-radius: var(--zp-radius-2xl) var(--zp-radius-2xl) 0 0;
    box-shadow: var(--zp-shadow-lg);
    padding-bottom: env(safe-area-inset-bottom);
    outline: none;
    animation: zp-slide-in-up var(--zp-dur-slower) var(--zp-ease-out) both;
  }
  .zp-sheet[data-state="closed"] {
    animation: zp-slide-out-down var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-sheet-grabber {
    display: grid;
    place-items: center;
    width: 64px;
    height: 24px;
    margin: 0 auto;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
  }
  .zp-sheet-grabber::before {
    content: "";
    width: 40px;
    height: 5px;
    border-radius: var(--zp-radius-full);
    background: var(--zp-hairline-strong);
  }

  /* ---- Menu / popover ---- */
  .zp-menu {
    position: absolute;
    z-index: var(--zp-z-nav);
    min-width: 220px;
    padding: 6px;
    background: var(--zp-surface-overlay);
    border: 1px solid var(--zp-hairline-strong);
    border-radius: var(--zp-radius-lg);
    box-shadow: var(--zp-shadow-lg);
    transform-origin: top right;
    animation: zp-menu-in var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-menu[data-state="closed"] {
    animation: zp-menu-out var(--zp-dur-base) var(--zp-ease-out) both;
  }
  .zp-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 38px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--zp-radius-sm);
    background: transparent;
    color: var(--zp-text);
    font: inherit;
    font-size: var(--zp-fs-base);
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--zp-dur-fast) var(--zp-ease-out);
  }
  .zp-menu-item:hover,
  .zp-menu-item:focus-visible {
    background: var(--zp-fill-muted);
    outline: none;
  }

  /* ---- Toasts ---- */
  .zp-toasts {
    position: fixed;
    z-index: var(--zp-z-toast);
    top: 76px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(380px, calc(100% - 32px));
    pointer-events: none;
  }
  .zp-toast {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 14px 16px;
    overflow: hidden;
    border-radius: var(--zp-radius-lg);
    background: var(--zp-glass);
    -webkit-backdrop-filter: saturate(140%) blur(var(--zp-glass-blur));
    backdrop-filter: saturate(140%) blur(var(--zp-glass-blur));
    border: 1px solid var(--zp-hairline-strong);
    box-shadow: var(--zp-shadow-lg);
    pointer-events: auto;
    animation: zp-toast-in var(--zp-dur-slow) var(--zp-ease-out) both;
  }
  .zp-toast[data-state="closed"] {
    animation: zp-toast-out var(--zp-dur-base) var(--zp-ease-out) both;
  }
  .zp-toast-icon {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: var(--zp-radius-sm);
  }
  /* The thin line along the bottom that drains while the toast is shown */
  .zp-toast-timer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: currentColor;
    opacity: 0.7;
    transform-origin: left;
    animation: zp-drain linear both;
  }
  .zp-toast:hover .zp-toast-timer {
    animation-play-state: paused;
  }
  @media (max-width: 640px) {
    .zp-toasts {
      top: 12px;
      right: 16px;
      left: 16px;
      width: auto;
    }
  }

  /* ---- Loading ---- */
  .zp-spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--zp-radius-full);
    animation: zp-spin 0.7s linear infinite;
    vertical-align: -0.125em;
  }
  .zp-skeleton {
    display: block;
    border-radius: var(--zp-radius-sm);
    background: linear-gradient(90deg,
      var(--zp-fill-subtle) 0%,
      var(--zp-fill-muted) 50%,
      var(--zp-fill-subtle) 100%);
    background-size: 200% 100%;
    animation: zp-shimmer 1.4s ease-in-out infinite;
  }

  /* ---- Entrance: content rises into place, optionally staggered ---- */
  .zp-rise {
    animation: zp-rise var(--zp-dur-slower) var(--zp-ease-out) both;
  }
  .zp-rise-1 { animation-delay: 60ms; }
  .zp-rise-2 { animation-delay: 120ms; }
  .zp-rise-3 { animation-delay: 180ms; }
  .zp-rise-4 { animation-delay: 240ms; }

  /* ---- Scroll reveal (zp-zones.js): children of [data-zp-reveal] rise in
     one after another. A keyframe animation, not a transition, so a page's
     own unlayered transition rules (cards) can't cancel it. The script adds
     .zp-rv only when it runs and motion is allowed. ---- */
  .zp-rv {
    opacity: 0;
  }
  .zp-rv.zp-in {
    animation: zp-reveal 800ms var(--zp-ease-out) calc(var(--zp-d, 0) * 80ms) both;
  }

  /* ---- Zone strip (zp-zones.js): a faint candlestick chart with one zone.
     Solid in the page gutters, almost gone behind the content column. ---- */
  .zp-zstrip {
    --zs-theme: 1;
    --zs-small: 1;
    position: absolute;
    left: 50%;
    top: var(--y, 50%);
    z-index: 0;
    width: 1600px;
    height: var(--h, 260px);
    margin-left: -800px;
    pointer-events: none;
    opacity: calc(var(--zs-op, 0.6) * var(--zs-theme) * var(--zs-small));
    transform: translate3d(0, calc(-50% + var(--py, 0px)), 0);
    will-change: transform;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, var(--zp-bg) 9%, color-mix(in srgb, var(--zp-bg) 22%, transparent) 24%, color-mix(in srgb, var(--zp-bg) 6%, transparent) 50%, color-mix(in srgb, var(--zp-bg) 22%, transparent) 76%, var(--zp-bg) 91%, transparent 100%);
            mask-image: linear-gradient(90deg, transparent 0, var(--zp-bg) 9%, color-mix(in srgb, var(--zp-bg) 22%, transparent) 24%, color-mix(in srgb, var(--zp-bg) 6%, transparent) 50%, color-mix(in srgb, var(--zp-bg) 22%, transparent) 76%, var(--zp-bg) 91%, transparent 100%);
  }
  :root[data-theme="light"] .zp-zstrip { --zs-theme: 1.25; }
  @media (max-width: 860px) {
    .zp-zstrip { --zs-small: 0.6; }
  }
  .zp-zstrip svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
  }
  .zp-zs-grid { fill: none; stroke: var(--zp-hairline); stroke-width: 1; }
  .zp-zs-up { fill: var(--zp-demand); }
  .zp-zs-dn { fill: var(--zp-supply); }
  .zp-zs-wu { stroke: var(--zp-demand); stroke-width: 1; }
  .zp-zs-wd { stroke: var(--zp-supply); stroke-width: 1; }
  /* Candles draw in left to right, then the zone extends, then its label */
  .zp-zs-c {
    opacity: 0;
    transition: opacity 500ms var(--zp-ease-out) calc(var(--i) * 16ms);
  }
  .zp-zs-zone {
    transform: scaleX(0);
    transform-box: fill-box;
    transform-origin: left center;
    transition: transform 1600ms var(--zp-ease-out) 500ms;
  }
  .zp-zs-label {
    font: 600 11px var(--zp-font-mono);
    letter-spacing: 0.04em;
    opacity: 0;
    transition: opacity 800ms var(--zp-ease-out) 1600ms;
  }
  .zp-zstrip.zp-in .zp-zs-c,
  .zp-zstrip.zp-in .zp-zs-label { opacity: 1; }
  .zp-zstrip.zp-in .zp-zs-zone { transform: none; }
  .zp-zs-zone rect { stroke-width: 1; }
  .zp-zs-zone.zp-zs-demand rect { fill: var(--zp-demand-tint); stroke: color-mix(in srgb, var(--zp-demand) 55%, transparent); }
  .zp-zs-zone.zp-zs-supply rect { fill: var(--zp-supply-tint); stroke: color-mix(in srgb, var(--zp-supply) 55%, transparent); }
  .zp-zs-zone .zp-zs-glow { stroke: none; animation: zp-zs-breathe 5s ease-in-out infinite; }
  .zp-zs-label.zp-zs-demand { fill: var(--zp-demand); }
  .zp-zs-label.zp-zs-supply { fill: var(--zp-supply); }
  .zp-zs-ltp { stroke-width: 1; stroke-dasharray: 3 4; }
  .zp-zs-ltp.zp-zs-demand { stroke: var(--zp-demand); }
  .zp-zs-ltp.zp-zs-supply { stroke: var(--zp-supply); }
  /* The live (last) candle ticks */
  .zp-zs-tick {
    transform-box: fill-box;
    transform-origin: center bottom;
    animation: zp-zs-tick 2.6s ease-in-out infinite;
  }

  /* ---- Scan line (zp-zones.js): a hairline across the top of a section;
     a light sweeps along it once when it comes into view ---- */
  .zp-scanline {
    position: absolute;
    top: 0;
    left: 50%;
    z-index: 1;
    width: min(1200px, calc(100% - 32px));
    height: 1px;
    overflow: hidden;
    transform: translateX(-50%);
    background: linear-gradient(90deg, transparent, var(--zp-hairline-strong), transparent);
    pointer-events: none;
  }
  .zp-scanline::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent 35%, var(--zp-fiber-a) 50%, transparent 65%);
  }
  .zp-scanline.zp-in::after {
    animation: zp-scan-sweep 2.2s var(--zp-ease-out) 100ms both;
  }

  /* ---- Empty state ---- */
  .zp-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--zp-space-2);
    padding: var(--zp-space-10) var(--zp-space-6);
    color: var(--zp-text-muted);
  }
  .zp-empty-icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: var(--zp-space-2);
    border-radius: var(--zp-radius-md);
    background: var(--zp-brand-tint);
    color: var(--zp-brand-soft);
    font-size: 20px;
  }
  .zp-empty p {
    margin: 0;
  }
  .zp-empty-title {
    font-size: var(--zp-fs-md);
    font-weight: 600;
    color: var(--zp-text);
  }
}

/* ---- Keyframes (not layered: animation names are global) ---- */
@keyframes zp-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes zp-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes zp-pop-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes zp-pop-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(8px) scale(0.98); }
}
@keyframes zp-slide-in-right {
  from { transform: translateX(104%); }
  to { transform: none; }
}
@keyframes zp-slide-out-right {
  from { transform: none; }
  to { transform: translateX(104%); }
}
@keyframes zp-slide-in-up {
  from { transform: translateY(104%); }
  to { transform: none; }
}
@keyframes zp-slide-out-down {
  from { transform: none; }
  to { transform: translateY(104%); }
}
@keyframes zp-menu-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes zp-menu-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(-4px) scale(0.98); }
}
@keyframes zp-toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes zp-toast-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateX(16px); }
}
@keyframes zp-drain {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}
@keyframes zp-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes zp-breathe {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--zp-brand) 55%, transparent); }
  60% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--zp-brand) 0%, transparent); }
}
@keyframes zp-sheen {
  from { transform: translateX(-100%); }
  to { transform: translateX(350%); }
}
@keyframes zp-spin {
  to { transform: rotate(360deg); }
}
@keyframes zp-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}
@keyframes zp-reveal {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}
@keyframes zp-zs-breathe {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}
@keyframes zp-zs-tick {
  0%, 100% { transform: scaleY(1); }
  30% { transform: scaleY(1.45); }
  65% { transform: scaleY(0.8); }
}
@keyframes zp-scan-sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  .zp-modal-bg,
  .zp-modal,
  .zp-drawer-bg,
  .zp-drawer,
  .zp-sheet,
  .zp-menu,
  .zp-toast,
  .zp-rise,
  .zp-skeleton,
  .zp-live-dot,
  .zp-progress-sheen::after,
  .zp-zs-glow,
  .zp-zs-tick,
  .zp-scanline::after {
    animation: none !important;
  }
  .zp-zs-c,
  .zp-zs-zone,
  .zp-zs-label {
    transition: none;
  }
  .zp-spinner {
    animation-duration: 1.6s;
  }
  .zp-card-hover:hover,
  .zp-btn-primary:hover,
  .zp-btn-primary:active,
  .zp-btn-secondary:active,
  .zp-btn-ghost:active,
  .zp-btn-danger:active {
    transform: none;
  }
  .zp-switch::after,
  .zp-segmented-thumb,
  .zp-meter > span {
    transition: none;
  }
}
