/* Desktop shell, 900 px and wider. Below that this file changes nothing: the phone app stays as it is.
   The shell follows COMPANY.md, "The roastery app": a light sidebar 248 wide, a top bar 98 high on the
   ground, the screen below it on a 12-column grid with 24 gaps and 64 padding. Tokens come from app.css.
   #device becomes the content area, so every position the phone code measures (popovers, the map,
   toasts) is measured inside it. */

#chrome { display: none; }

@media (min-width: 900px) {
  body { display: block; background: var(--bg); }
  #chrome { display: contents; }

  /* ---------- Sidebar ---------- */
  #side {
    position: fixed; left: 0; top: 0; bottom: 0; width: 248px; z-index: 1;
    background: linear-gradient(rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.02)), var(--bg); color: var(--ink);
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.1);
    display: flex; flex-direction: column; padding: 28px 16px 16px;
  }
  .side-mark {
    height: 50px; padding: 0 13px; display: flex; align-items: center; gap: 13px; white-space: nowrap;
    font-family: var(--dot); font-size: 28px; font-weight: 700; letter-spacing: 2px; line-height: 0.9;
  }
  .side-mark img { width: 35px; height: 49px; object-fit: cover; pointer-events: none; }
  .side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 40px; }
  .side-item {
    height: 44px; padding: 0 16px; border-radius: 22px; display: flex; align-items: center;
    font-size: 17px; font-weight: 600; color: var(--ink);
    transition: background-color 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
  }
  .side-item:active { transform: scale(0.98); }
  .side-item.is-on { background: var(--accent); color: var(--ink); }
  .side-person {
    margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 24px;
    background: rgba(255, 255, 255, 0.2); transition: background-color 150ms ease;
  }
  .side-person.is-open { background: rgba(255, 255, 255, 0.5); }
  .side-person .who { display: flex; flex-direction: column; gap: 2px; text-align: left; }
  .side-person .nm { font-size: 15px; font-weight: 500; }
  .side-person .rl { font-size: 13px; font-weight: 300; color: rgba(27, 27, 29, 0.55); }
  @media (hover: hover) and (pointer: fine) {
    .side-item:not(.is-on):hover { background: rgba(255, 255, 255, 0.2); }
    .side-person:hover { background: rgba(255, 255, 255, 0.35); }
  }

  /* ---------- Top bar ---------- */
  #topbar {
    position: fixed; left: 248px; right: 0; top: 0; height: 130px; z-index: 1;
    background: var(--bg); display: flex; align-items: center; gap: 12px; padding: 64px 64px 32px;
  }
  .tb-back {
    width: 36px; height: 36px; border-radius: 18px; background: var(--tile); display: grid; place-items: center;
    transition: transform 160ms var(--ease-out);
  }
  .tb-back:active { transform: scale(0.94); }
  .tb-title { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 34px; white-space: nowrap; }
  .tb-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
  .tb-date { font-family: var(--dot); font-size: 18px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; }
  .sync-pill {
    height: 27px; padding: 0 16px; border-radius: 20px; background: var(--pill); display: flex; align-items: center;
    font-size: 11px; font-weight: 600; letter-spacing: 1.2px; transition: transform 160ms var(--ease-out);
  }
  .sync-pill:active { transform: scale(0.95); }

  /* ---------- Content area ---------- */
  #device {
    position: fixed; left: 248px; top: 130px; right: 0; bottom: 0; width: auto; height: auto;
    border-radius: 0; box-shadow: none; z-index: 2;
  }
  #status { display: none; }
  .screen { padding-top: 0; }
  .scroll { scroll-padding: 24px 0 24px; }
  .content {
    padding: 32px 64px 64px; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 24px;
    align-items: start; align-content: start;
  }
  .content > * { grid-column: 1 / -1; }

  /* The phone header becomes a toolbar at the top right: the screen action (search, plan, share) and
     the main action. The title and the way back live in the top bar. */
  .screen[data-screen="home"] .hdr { display: none; }
  .screen:not([data-screen="map"]) .hdr {
    position: absolute; top: 56px; right: 64px; height: 44px; width: 44px; padding: 0;
    background: none !important; box-shadow: none !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
  }
  .hdr [data-act="back"], .hdr .hdr-title { display: none; }
  .hdr .hdr-action { width: 44px; height: 44px; border-radius: 22px; background: var(--tile); }
  .search-bar { left: auto; right: 0; top: 0; width: 360px; height: 44px; border-radius: 22px; z-index: 5; }
  .screen:has(.hdr.is-searching) .dock { opacity: 0; pointer-events: none; }
  .dock {
    position: absolute; top: 56px; right: 120px; z-index: 4; margin: 0; padding: 0; background: none;
    display: flex; gap: 12px; width: auto; transition: opacity 150ms ease;
  }
  .dock .btn-primary { height: 44px; width: auto; padding: 0 24px; border-radius: 22px; }
  .dock .btn-round { width: 44px; height: 44px; border-radius: 22px; }
  .content > .dock, .content [data-region] > .dock { grid-column: auto; }

  /* Heroes: the readouts sit in a row beside the big number */
  .hero { min-height: 0; padding: 0; }
  .readouts { flex-direction: row; align-items: flex-end; gap: 40px; }

  .tabs-scroller { margin: 0; padding: 0; overflow: visible; }
  .tabs-wrap::after { display: none; }

  /* ---------- Today ---------- */
  .screen[data-screen="home"] .home-hero { grid-column: span 5; background: var(--card-soft); border-radius: 24px; padding: 24px 28px; min-height: 152px; }
  .screen[data-screen="home"] .metrics { grid-column: span 7; align-self: stretch; align-items: stretch; gap: 24px; }
  .metric { padding: 24px; border-radius: 24px; justify-content: space-between; gap: 12px; }
  .cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: minmax(200px, auto); gap: 24px; }
  .cards .col { display: contents; }
  .cards .hcard { height: auto !important; }
  .cards:not(.more) .col:first-child > :first-child { grid-row: span 2; }
  .cards.more { margin-top: 0; }

  /* ---------- Roast schedule ---------- */
  .screen[data-screen="roast"] .days { grid-column: span 7; }
  .screen[data-screen="roast"] [data-region="roastDay"] {
    display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start;
  }
  .screen[data-screen="roast"] .roast-hero { background: var(--card-soft); border-radius: 24px; padding: 24px 28px; }

  /* ---------- Live batch: the curve takes two thirds ---------- */
  .screen[data-screen="batch"] .content { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .screen[data-screen="batch"] .content > :nth-child(1) { grid-column: 1 / -1; }
  .screen[data-screen="batch"] .content > .hero { grid-column: 2; grid-row: 2; flex-direction: column; align-items: flex-start; gap: 20px; background: var(--card-soft); border-radius: 24px; padding: 24px; }
  .screen[data-screen="batch"] .content > .hero .readouts { align-self: stretch; justify-content: flex-start; }
  .screen[data-screen="batch"] .content > .hero .readout { align-items: flex-start; }
  .screen[data-screen="batch"] .content > .curve-card { grid-column: 1; grid-row: 2 / span 2; padding: 28px; }
  .screen[data-screen="batch"] .content > :nth-child(4) { grid-column: 1; grid-row: 4; }
  .screen[data-screen="batch"] .content > :nth-child(5) { grid-column: 2; grid-row: 3 / span 2; }
  .plot { height: auto; aspect-ratio: 302 / 150; }
  .plot svg { width: 100%; height: 100%; }
  .plot svg :is(path, line, circle, rect) { vector-effect: non-scaling-stroke; }
  .plot .lbl-y, .plot .lbl-1c { font-size: calc(10px * var(--k, 1)); } /* --k undoes the curve's scale, set in desktop.js */

  /* ---------- Stock ---------- */
  .screen[data-screen="stock"] [data-region="stockBody"] {
    display: grid !important; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); align-items: start;
    grid-template-rows: auto auto auto 1fr;
  }
  .screen[data-screen="stock"] [data-region="stockBody"] > .hero,
  .screen[data-screen="stock"] [data-region="stockBody"] > .split { grid-column: 1 / -1; }
  .screen[data-screen="stock"] [data-region="stockBody"] > :nth-child(4) { grid-column: 1; grid-row: 3 / span 2; }
  .screen[data-screen="stock"] [data-region="stockBody"] > [data-low] { grid-column: 2; grid-row: 3; }
  .screen[data-screen="stock"] [data-region="stockBody"] > :nth-child(5) { grid-column: 2; grid-row: 4; }

  /* ---------- Orders: the cards in three columns ---------- */
  [data-orders] { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px !important; align-items: stretch; }
  [data-orders] > .collapse, [data-orders] > [data-act="moreDue"] { grid-column: 1 / -1; }
  [data-orders] > .collapse > div { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px !important; }
  .order { height: 100%; justify-content: space-between; }

  /* ---------- Deliveries: the map large, the stops beside it ---------- */
  .screen[data-screen="deliveries"] [data-region="delBody"] {
    display: grid !important; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); align-items: start;
  }
  .screen[data-screen="deliveries"] [data-region="delBody"] > .hero { grid-column: 1; grid-row: 1; }
  .screen[data-screen="deliveries"] [data-region="delBody"] > .map-card { grid-column: 1; grid-row: 2; }
  .screen[data-screen="deliveries"] [data-region="delBody"] > :nth-child(3) { grid-column: 2; grid-row: 1 / span 3; }
  .screen[data-screen="deliveries"] [data-region="delBody"] > :nth-child(4) { grid-column: 1; grid-row: 3; }
  .map-card { height: 520px; container-type: size; }
  /* the same cover fit as the phone card (image 1400 x 933), measured on the larger card */
  .map-card .van {
    --k: max(100cqw / 1400, 100cqh / 933);
    left: calc(var(--ix) * var(--k) + (100cqw - 1400 * var(--k)) / 2 - 16px) !important;
    top: calc(var(--iy) * var(--k) + (100cqh - 933 * var(--k)) / 2 - 16px) !important;
  }

  /* The full map: the stop card becomes a panel at the top right */
  .screen[data-screen="map"] .hdr { top: 24px !important; padding: 0 32px; }
  .screen[data-screen="map"] .scroll > .card { left: auto !important; right: 24px !important; top: 24px; bottom: auto !important; width: 400px; }

  /* ---------- Accounts ---------- */
  .screen[data-screen="accounts"] [data-region="acctBody"] {
    display: grid !important; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); align-items: start;
  }

  /* ---------- Revenue: the chart takes two thirds ---------- */
  .screen[data-screen="revenue"] [data-region="revBody"] {
    display: grid !important; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start;
  }
  .screen[data-screen="revenue"] [data-region="revBody"] > .hero { grid-column: 1 / -1; }
  .screen[data-screen="revenue"] [data-region="revBody"] > :nth-child(2) { grid-column: 1; grid-row: 2; }
  .screen[data-screen="revenue"] [data-region="revBody"] > :nth-child(3) { grid-column: 1; grid-row: 3; }
  .screen[data-screen="revenue"] [data-region="revBody"] > :nth-child(4) { grid-column: 2; grid-row: 2 / span 2; }

  /* ---------- Sheets become centred dialogs ---------- */
  .sheet-layer { position: fixed; inset: 0; }
  .sheet {
    inset: 0; margin: auto; width: 520px; height: fit-content; max-height: calc(100vh - 96px);
    border-radius: 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25); touch-action: auto;
  }
  .grab { display: none; }
  .sheet-body { padding: 28px 32px 32px; }

  /* Calls, the scanner, signed out: a dark panel over a dimmed window */
  .full {
    position: fixed; inset: 0; margin: auto; width: 420px; height: min(800px, calc(100vh - 80px));
    border-radius: 32px; padding: 96px 24px 40px;
    box-shadow: 0 0 0 100vmax rgba(14, 14, 15, 0.42), 0 30px 80px rgba(0, 0, 0, 0.3);
  }

  .toast { left: auto; right: 24px; top: 16px; width: 400px; }

  /* The profile menu, above the person in the sidebar */
  .desk-menu-layer { position: fixed; inset: 0; z-index: 30; }
  .desk-catch { position: absolute; inset: 0; }
  .desk-menu {
    position: absolute; left: 16px; bottom: 84px; width: 280px; padding: 8px; border-radius: 24px;
    background: var(--card); color: var(--ink); box-shadow: 0 16px 48px rgba(27, 27, 29, 0.25), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
    display: flex; flex-direction: column; gap: 4px; transform-origin: bottom left;
  }
  .desk-menu .profile { background: var(--tile); }
  .desk-row {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 16px;
    font-size: 15px; color: var(--ink); transition: background-color 120ms ease;
  }
  @media (hover: hover) and (pointer: fine) { .desk-row:hover { background: rgba(27, 27, 29, 0.06); } }
}
