/* ==== responsive layout ========================================================
   Phone first. Breakpoints:
     < 380px    small phones: tighter padding and type
     ≥ 760px    tablets, landscape phones, resized desktop windows: one-row header, two columns,
                grid lists, centred dialogs instead of bottom sheets
     ≥ 1024px   desktop: side navigation rail instead of the bottom tab bar, taller charts
     ≥ 1280px   header fits on a single line
   Figure grids (.kpis, .stats) follow the width of their card (container queries), not the window. */

.rail-brand { display: none; }

@container (min-width: 500px) {
  .kpis, .stats { grid-template-columns: repeat(4, 1fr); }
  .stats.n2 { grid-template-columns: repeat(2, 1fr); }
  .stats.n3, .stats.n6 { grid-template-columns: repeat(3, 1fr); }
}
@supports not (container-type: inline-size) {
  @media (min-width: 560px) {
    .kpis, .stats { grid-template-columns: repeat(4, 1fr); }
    .stats.n2 { grid-template-columns: repeat(2, 1fr); }
    .stats.n3, .stats.n6 { grid-template-columns: repeat(3, 1fr); }
  }
}

@media (max-width: 379px) {
  :root { --gutter: 10px; }
  body { font-size: 14.5px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .topbar-value { font-size: 26px; }
  .stat-pill { padding: 7px 10px; }
  .stat-pill-value { font-size: 15px; }
  .row { padding: 10px 12px; gap: 10px; }
  .row + .row::before { left: 12px; }
  .kv { padding: 9px 12px; }
  .kpi, .stat { padding: 10px 12px; }
  .kpi-value { font-size: 17px; }
  .coin-icon { width: 34px; height: 34px; border-radius: 10px; }
  .coin-icon.big { width: 44px; height: 44px; border-radius: 14px; }
  .coin-icon.sm { width: 28px; height: 28px; border-radius: 8px; }
  .seg button { padding: 6px 4px; font-size: 12.5px; }
  .funnel { padding: 6px 12px 12px; }
  .funnel-row { grid-template-columns: 78px 1fr 32px; font-size: 12.5px; }
  .btn-row { padding: 12px; }
  .lock-form { grid-template-columns: 1fr 1fr; padding: 10px 12px 12px; }
  .lock-form .btn { grid-column: 1 / -1; }
  .equity-delta { font-size: 21px; }
  .coin-price { font-size: 24px; }
  .tab { font-size: 10.5px; }
}

/* short landscape screens: don't pin the header over the little height there is */
@media (max-height: 480px) and (orientation: landscape) {
  .topbar { position: static; }
}

@media (min-width: 760px) {
  :root { --content-w: 1240px; --gutter: 20px; }

  /* header: equity · today/open · actions, status chips underneath */
  .topbar { padding-left: var(--gutter); padding-right: var(--gutter); }
  .topbar-main { grid-template-columns: auto minmax(0, 400px) 1fr auto; grid-template-areas: "eq stats . actions" "chips chips chips chips";
    column-gap: 20px; }
  .topbar-stats { align-self: center; }
  .topbar.compact .topbar-stats { display: grid; }
  .topbar.compact .stat-pill { padding: 4px 12px; }
  .topbar.compact .stat-pill-value { font-size: 14px; }

  /* two columns, each keeping its own vertical rhythm */
  .cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 var(--col-gap); align-items: start; }
  .cols.main-wide { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .view > .cols:first-child > .col > .block:first-child > .section-title,
  .view > .cols:first-child > .col > :is(.notice, .card):first-child { margin-top: 10px; }
  .flow { columns: 2; column-gap: var(--col-gap); }
  .flow > * { break-inside: avoid; display: flow-root; }

  /* long lists become a grid of rows (as many ~340px columns as fit their card) */
  .list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); margin: 0 -1px -1px 0; }
  .list-grid > .row { border-right: 1px solid var(--separator); border-bottom: 1px solid var(--separator); }
  .list-grid > .row::before { display: none; }

  /* coin tiles wrap into a grid instead of a side-scrolling strip; news pills wrap too */
  .cols .strip.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); overflow: visible; margin: 0; padding: 0; }
  .cols .strip.tiles .tile { min-width: 0; }
  .strip.pills { flex-wrap: wrap; overflow: visible; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }

  /* view-level segmented controls and filters don't need the full page width */
  .view > .seg-wrap > .seg, .filters .seg { max-width: 460px; }
  .filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 10px 0 4px; }
  .filters > .seg-wrap { margin: 0; flex: 1 1 300px; max-width: 460px; }
  .filters .field.bare { padding: 0; flex: 0 1 280px; }

  .chart { height: 180px; }
  .candles { height: 300px; }

  /* sheets become centred dialogs with a close button */
  .sheet { inset: 0; margin: auto; width: min(640px, calc(100vw - 48px)); max-width: none; height: fit-content;
    max-height: min(calc(var(--vh) - 64px), 900px); border-radius: 18px; padding: 0 20px 22px;
    box-shadow: 0 24px 64px rgb(0 0 0 / 35%); animation: pop .2s cubic-bezier(.2, .8, .2, 1); }
  .sheet.tall { width: min(1080px, calc(100vw - 48px)); max-height: calc(var(--vh) - 48px); }
  .sheet-grip { display: none; }
  .sheet-head { top: 0; margin: 0 -20px 6px; padding: 14px 14px 8px 20px; }
  .sheet-title { margin: 0 6px; }
  .sheet-close { display: grid; }
  .toast { bottom: calc(var(--tabs-h) + var(--safe-bottom) + 20px); }
}
@keyframes pop { from { transform: translateY(12px) scale(.985); opacity: 0; } to { transform: none; opacity: 1; } }

@media (min-width: 1024px) {
  :root { --gutter: 28px; --col-gap: 24px; }
  .has-nav { --rail-w: 224px; }
  .has-nav #app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); grid-template-rows: auto 1fr;
    grid-template-areas: "rail top" "rail view"; }
  .has-nav .topbar { grid-area: top; }
  .has-nav .view { grid-area: view; padding-bottom: 40px; }
  .has-nav .tabs { grid-area: rail; position: sticky; top: 0; align-self: start; height: 100vh; height: var(--vh);
    display: flex; flex-direction: column; gap: 2px; padding: calc(var(--safe-top) + 18px) 12px 18px;
    border-top: 0; border-right: 1px solid var(--separator); background: var(--section); }
  .has-nav .rail-brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; font-weight: 750; font-size: 16px; letter-spacing: -.01em; }
  .rail-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 11.5px; font-weight: 800;
    background: var(--accent); color: var(--accent-text); }
  .has-nav .tab { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px;
    font-size: 14.5px; font-weight: 600; }
  .has-nav .tab::before { display: none; }
  .has-nav .tab svg { width: 20px; height: 20px; }
  .has-nav .tab[aria-selected="true"] { background: var(--accent-soft); }
  .has-nav .tab .dot { position: static; margin-left: auto; }
  .has-nav .toast { bottom: 24px; left: calc(50% + var(--rail-w) / 2); max-width: calc(100% - var(--rail-w) - 48px); }
  .chart { height: 200px; }
  .candles { height: 340px; }
}

@media (min-width: 1280px) {
  .topbar-main { grid-template-columns: auto minmax(0, 400px) 1fr auto; grid-template-areas: "eq stats chips actions"; }
  .topbar-chips { justify-content: flex-end; }
  .topbar.compact .topbar-chips { display: flex; }
}

/* mouse & trackpad: hover feedback and slim scrollbars */
@media (hover: hover) and (pointer: fine) {
  button.row:hover, .more:hover { background: color-mix(in srgb, var(--hint) 9%, transparent); }
  .tile:hover { background: color-mix(in srgb, var(--hint) 10%, var(--section)); }
  .btn:not(:disabled):hover, .icon-btn:hover { filter: brightness(1.1); }
  .tab:hover, .pill:hover, .seg button:not([aria-pressed="true"]):not(:disabled):hover { color: var(--text); }
  .sheet, .strip { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--hint) 45%, transparent) transparent; }
}
