/* Delivery locations screen — namespaced .loc-* classes only.
   Layout/spacing/sizing copied from the SDOS Workspace design handoff
   (Delivery locations, lines 1146-1252); colors mapped onto theme tokens so
   dark mode adapts. Map↔list↔detail; detail loads in the loc-detail frame. */

@layer screens {
  /* Bound the whole screen to the viewport ONLY on this page, so the three
     panes each scroll internally instead of growing the page. */
  .content:has(.loc-screen) { display: flex; flex-direction: column; min-height: 0; padding-bottom: 0; }
  /* Desktop: pin the 3-pane to the viewport (each pane scrolls internally).
     Below this the panes stack and the page scrolls normally. */
  @media (min-width: 1101px) { .shell:has(.loc-screen) { height: 100vh; overflow: hidden; } }

  .loc-screen { flex: 1; min-height: 0; display: flex; gap: 0; }

  /* ---- left: brand → branch tree ---- */
  .loc-side {
    width: 300px; flex-shrink: 0; overflow-y: auto;
    padding: 2px 14px 24px 4px; display: flex; flex-direction: column; gap: 10px;
  }

  /* ---- middle: stats (brand-aggregate or single-branch), scrolls ---- */
  .loc-mid { width: 384px; flex-shrink: 0; overflow-y: auto; padding: 2px 12px 24px 0; }
  #loc-stats, turbo-frame#loc-stats { display: block; }
  .loc-follow {
    background: var(--warn-bg); border: 1px solid var(--warn); color: var(--warn-fg);
    border-radius: 11px; padding: 10px 13px; font-size: 13px; font-weight: 600;
    display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  }
  .loc-geocode-btn {
    background: var(--primary); color: #fff; border: none; border-radius: 8px;
    padding: 7px 12px; font-size: 12.5px; font-weight: 700; cursor: pointer;
  }
  .loc-geocode-btn:hover { filter: brightness(1.05); }
  .loc-group { display: flex; flex-direction: column; gap: 8px; }

  .loc-brand {
    background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px;
    padding: 11px 14px; display: flex; flex-direction: column; gap: 6px;
    text-decoration: none; color: var(--text); cursor: pointer;
  }
  .loc-brand:hover { box-shadow: var(--shadow-card); text-decoration: none; }
  .loc-brand.is-selected { border-color: var(--primary); background: var(--primary-soft); }
  .loc-brand-top { display: flex; align-items: center; gap: 8px; }
  .loc-swatch { width: 9px; height: 9px; flex-shrink: 0; border-radius: 3px; background: var(--primary); }
  .loc-brand-name { font-size: 14.5px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
  .loc-pill-primary { border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
  .loc-pill { border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }

  .loc-branches { display: flex; flex-direction: column; gap: 8px; }
  .loc-branches.is-grouped { margin-left: 12px; padding-left: 10px; border-left: 2px solid var(--line); }

  .loc-card {
    display: flex; flex-direction: column; gap: 5px; text-decoration: none;
    background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px;
    padding: 11px 13px; cursor: pointer; color: var(--text);
  }
  .loc-card:hover { box-shadow: var(--shadow-card); text-decoration: none; }
  .loc-card.is-selected { border-color: var(--primary); background: var(--primary-soft); }
  .loc-card-top { display: flex; align-items: center; gap: 8px; }
  .loc-card-name { font-size: 13.5px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .loc-count { border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
  .loc-card-addr { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .loc-card-meta { display: flex; gap: 10px; font-size: 12px; color: var(--muted); align-items: baseline; }
  .loc-card-contact { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .loc-card-last { white-space: nowrap; }

  /* urgency / status tags */
  .loc-tag { display: inline-flex; align-self: flex-start; border-radius: 6px; padding: 2.5px 9px; font-size: 11.5px; font-weight: 700; }
  .loc-tag-now  { background: var(--danger-bg); color: var(--danger-fg); }
  .loc-tag-soon { background: var(--warn-bg); color: var(--warn-fg); }
  .loc-tag-ok   { background: var(--ok-bg); color: var(--ok-fg); }
  .loc-tag-none { background: var(--surface-2); color: var(--muted); }

  .loc-empty { color: var(--muted); padding: 20px 4px; }

  /* ---- right: map column (fills the pane height) ---- */
  .loc-mapcol {
    flex: 1; min-width: 0; position: relative; overflow: hidden;
    border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2);
    margin: 2px 4px 24px 0;
  }
  .loc-map { position: absolute; inset: 0; }
  .loc-detail {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
    padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
  }
  .loc-empty-detail { padding: 30px; text-align: center; color: var(--muted); }

  .loc-detail-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
  .loc-detail-name { font-size: 16px; font-weight: 700; color: var(--text); }
  .loc-detail-addr { font-size: 13px; color: var(--text-2); flex: 1; min-width: 0; }
  .loc-detail-contact { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

  .loc-ana { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
  .loc-ana-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
  .loc-ana-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
  .loc-ana-value { font-size: 16.5px; font-weight: 700; color: var(--text); }
  .loc-ana-sub { font-size: 11.5px; color: var(--muted); }

  .loc-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
  .loc-sizes { display: flex; flex-wrap: wrap; gap: 6px; }
  .loc-size-chip { border-radius: 7px; padding: 3px 9px; font-size: 11.5px; font-weight: 600; }

  /* usage bar chart */
  .loc-chart { display: flex; align-items: flex-end; gap: 12px; padding: 2px 2px 0; }
  .loc-bar-col { flex: 1; max-width: 58px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
  .loc-bar-qty { font-size: 10.5px; font-weight: 600; color: var(--text-2); height: 14px; }
  .loc-bar-track { width: 100%; height: 70px; display: flex; align-items: flex-end; }
  .loc-bar { width: 100%; min-height: 2px; background: var(--primary-soft); border: 1px solid var(--primary-border); border-radius: 5px 5px 0 0; }
  .loc-bar-label { font-size: 10.5px; color: var(--muted); }

  /* history table */
  .loc-hist { display: flex; flex-direction: column; }
  .loc-hist-head, .loc-hist-row {
    display: grid; grid-template-columns: 88px minmax(150px, 1.4fr) 100px 110px 110px 130px;
    gap: 8px; padding: 7px 10px; align-items: center;
  }
  .loc-hist-head { font-size: 11.5px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); }
  .loc-hist-row { font-size: 13px; color: var(--text); border-bottom: 1px solid var(--line); }
  .loc-mono { font-family: var(--font-mono); font-size: 12px; }
  .loc-ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .loc-r { text-align: right; }
  .loc-hist-empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }

  /* brand stats: drill-in branch list */
  .loc-minilist { display: flex; flex-direction: column; gap: 5px; }
  .loc-mini {
    display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text);
    border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; font-size: 13px;
  }
  .loc-mini:hover { background: var(--surface-2); text-decoration: none; }
  .loc-mini-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--line-strong); }
  .loc-mini-dot.is-located { background: var(--primary); }
  .loc-mini-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .loc-mini-count { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

  @media (max-width: 1100px) {
    .loc-screen { flex-direction: column; }
    .loc-side, .loc-mid { width: 100%; max-height: 38vh; padding: 2px 4px 12px; }
    .loc-mapcol { min-height: 320px; margin: 0 4px 12px; }
  }

  /* selected map pin highlight (additive; only locations sets selectable) */
  .map-pin-selected { outline: 3px solid var(--primary); outline-offset: 1px; }

  /* ---- pin status + adjust (geocode) — subtle footer below the history ---- */
  .loc-geo {
    display: flex; flex-direction: column; gap: 7px;
    border-top: 1px solid var(--line); padding-top: 11px; margin-top: 2px;
  }
  .loc-geo-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
  .loc-geo-row .loc-eyebrow { margin-top: 0; }
  .loc-geo-coords { color: var(--text-2); }
  .loc-geo-spacer { flex: 1; }
  .loc-geo-find-form { display: inline; }
  .loc-geo-find {
    background: var(--primary-soft); color: var(--primary); border: 1px solid var(--primary-border);
    border-radius: 8px; padding: 6px 11px; font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap;
  }
  .loc-geo-find:hover { background: var(--primary); color: #fff; }
  .loc-geo-form { display: flex; gap: 7px; }
  .loc-geo-input {
    flex: 1; min-width: 0; border: 1px solid var(--line-strong); border-radius: 8px;
    padding: 7px 10px; font-size: 12.5px; font-family: var(--font-mono);
    background: var(--surface); color: var(--text);
  }
  .loc-geo-input.is-picked { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
  .loc-geo-save {
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
    padding: 7px 13px; font-size: 12.5px; font-weight: 700; color: var(--text); cursor: pointer; white-space: nowrap;
  }
  .loc-geo-save:hover { background: var(--surface-3); }
  .loc-geo-hint { font-size: 11.5px; color: var(--muted); }
}
