/* ============================================================================
 * Layout — the map is the whole page. Chrome floats over it or reveals on demand.
 * ==========================================================================*/

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--t-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Grid: header on top, map fills the rest. Right rail is a slide-in overlay,
   not a permanent column. Legacy .a-left / .a-toolbar remain in the DOM but
   are hidden — their content is delivered via floating overlays. */
body {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header"
    "map"
    "status";
}

.a-header { grid-area: header; }
.a-map    { grid-area: map; overflow: hidden; position: relative; background: var(--map-bg); }
.a-status { grid-area: status; }

/* Non-essential chrome grid areas — hidden by default, resurfaced as popovers. */
.a-toolbar, .a-left { display: none; }

/* -- Header ------------------------------------------------------------ */
.a-header {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  padding: var(--sp-3) var(--sp-6);
  background: var(--paper);
  border-bottom: 1px solid var(--hair);
  position: relative; z-index: 20;
}
.a-header h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0.005em;
  color: var(--ink);
}
.a-header .subtitle {
  color: var(--ink-3);
  font-size: var(--t-caps);
  letter-spacing: var(--small-caps-letter-spacing);
  text-transform: uppercase;
  margin-top: 2px;
}
.a-header .h-nav {
  margin-left: auto;
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
/* Language toggle in the header — a compact pill that shows the OPPOSITE
 * language (i.e. what a click would switch to). Persists via localStorage
 * and reloads the page. */
.a-header .h-btn.h-lang {
  min-width: 32px;
  text-align: center;
  font-family: var(--sans);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.a-header .h-btn.h-lang[aria-pressed="true"] {
  background: var(--sel-bg);
  border-color: var(--sel);
  color: var(--ink);
}
.a-header .search-wrap { flex: 0 0 300px; }

/* -- Right rail — slide-in feature panel ------------------------------- */
.a-right {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 90vw);
  background: var(--card);
  border-left: 1px solid var(--hair);
  box-shadow: var(--shadow-float);
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-4) transparent;
  transform: translateX(100%);
  transition: transform var(--motion-base) var(--ease);
  z-index: 30;
}
.a-right::-webkit-scrollbar { width: 8px; }
.a-right::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 4px; }
.a-right::-webkit-scrollbar-track { background: transparent; }
.a-right.open { transform: translateX(0); }
.a-right .close-btn {
  position: sticky; top: 0;
  background: linear-gradient(to bottom, var(--card) 60%, transparent 100%);
  display: flex; justify-content: flex-end;
  padding: var(--sp-3) var(--sp-4) 0;
  z-index: 5;
}
.a-right .close-btn button {
  background: none; border: 0; cursor: pointer;
  color: var(--ink-3); font-size: 20px; line-height: 1;
  padding: 4px 8px; border-radius: var(--rad-sm);
  transition: background var(--motion-fast);
}
.a-right .close-btn button:hover { background: var(--card-quiet); color: var(--ink); }

.a-right .detail-slot { padding: 0 var(--sp-5) var(--sp-6); }

/* -- Status bar -------------------------------------------------------- */
.a-status {
  background: var(--paper);
  border-top: 1px solid var(--hair);
  padding: 6px var(--sp-4);
  font-family: var(--mono);
  font-size: var(--t-meta);
  color: var(--ink-3);
  display: flex;
  gap: var(--sp-5);
  align-items: center;
  height: 30px;
}
.a-status .s-item { display: flex; gap: 4px; align-items: center; }
.a-status .s-label { color: var(--ink-4); }
.a-status .s-value { color: var(--ink-2); }
.a-status .spacer  { flex: 1; }

/* -- Print ------------------------------------------------------------- */
@media print {
  body { grid-template-rows: auto 1fr auto; overflow: visible; height: auto; }
  .a-map { min-height: 80vh; break-inside: avoid; }
  .a-right { display: none !important; }
  .a-status { border-top: 1px solid #000; color: #000; }
}

/* -- Mobile ------------------------------------------------------------ */
@media (max-width: 700px) and (min-width: 641px) {
  /* Tablet-ish narrow: keep the old behaviour of wrapping the search
   * onto its own row while everything else stays desktop-shaped. */
  .a-header { padding: var(--sp-2) var(--sp-3); flex-wrap: wrap; }
  .a-header .search-wrap { flex: 1 1 100%; margin-top: var(--sp-2); }
  .a-right { width: 100vw; }
}

/* ── True mobile (≤ 640 px): the atlas becomes a Google-Maps-style app ──
 * Compact 56 px header, full-bleed map, bottom-sheet detail panel with
 * three snap heights, FAB stack for primary actions. Everything below
 * activates ONLY under the breakpoint so desktop is untouched. */
@media (max-width: 640px) {
  /* Ensure the outer grid still fits — no status bar row on mobile. */
  body {
    grid-template-rows: auto 1fr;
    grid-template-areas: "header" "map";
  }
  .a-status { display: none !important; }

  /* Compact header — 56 px, brand + hamburger + search icon */
  .a-header {
    height: 56px;
    padding: 0 12px;
    gap: 8px;
    flex-wrap: nowrap;
    align-items: center;
  }
  .a-header > div:first-child {
    flex: 1;
    min-width: 0;
    display: flex; align-items: center; gap: 10px;
  }
  .a-header h1 {
    font-size: 17px;
    letter-spacing: -0.005em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .a-header h1 a { color: inherit; text-decoration: none; }
  .a-header .subtitle { display: none; }
  .a-header .h-nav { display: none; }
  .a-header .search-wrap { display: none; }

  /* Bottom sheet — .a-right becomes a bottom-anchored sheet on mobile.
   * The sheet's height is driven inline by MobileChrome.js's sheet
   * driver per snap (peek/half/full) because in this codebase's CSS
   * ordering, the base .a-right rule's max-height/transform couldn't
   * be overridden from a mobile @media block — inline `height` +
   * `max-height` with !important is what actually wins. */
  .a-right {
    top: auto !important;
    left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    border-left: none !important;
    border-top: 1px solid var(--hair) !important;
    border-radius: 20px 20px 0 0 !important;
    transform: none !important;
    visibility: hidden;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.14) !important;
    padding-top: 18px;
    z-index: 25;
    transition: height 0.24s cubic-bezier(0.32, 0.72, 0.24, 1), visibility 0s 0.24s;
  }
  .a-right.open {
    visibility: visible;
    transition: height 0.24s cubic-bezier(0.32, 0.72, 0.24, 1), visibility 0s 0s;
  }
  /* Drag handle rendered as a ::before on the sheet — tap-cycles through
   * peek → half → full via the MobileChrome sheet driver. */
  .a-right::before {
    content: "";
    position: absolute; top: 6px; left: 50%;
    transform: translateX(-50%);
    display: block;
    width: 40px; height: 4px;
    background: var(--ink-4);
    border-radius: 2px;
    opacity: 0.35;
    cursor: pointer;
    z-index: 6;
    padding: 8px 20px;   /* hit target padding without affecting visual */
    background-clip: content-box;
  }
  .a-right .close-btn {
    padding: 4px var(--sp-3) 0;
    background: transparent;
  }
  .a-right .close-btn button {
    width: 32px; height: 32px;
    border-radius: 999px;
    background: rgba(0,0,0,0.06);
    display: flex; align-items: center; justify-content: center;
    padding: 0;
  }
  .a-right .detail-slot { padding: 0 var(--sp-4) var(--sp-4); }
}
