/* ==========================================================================
   Layout + components (desktop and mobile)
   ========================================================================== */

/* ---- App shell (desktop / tablet) ------------------------------------- */
.app { min-height: 100vh; display: flex; flex-wrap: wrap; align-items: stretch; }

.sidebar {
  flex: 1 1 var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--text); }
.brand__mark { width: 26px; height: 26px; flex: none; }
.brand__name { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .eyebrow { padding: 0 10px 6px; }
.nav__item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); }
.nav__item svg { width: 16px; height: 16px; flex: none; }
.nav__item[aria-current="page"] { background: var(--line); font-weight: 500; }
.sidebar__foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

.main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13.5px; color: var(--muted); }
.breadcrumb [aria-current] { color: var(--text); font-weight: 500; }
.topbar__actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

.content { padding: 20px 24px 32px; display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; flex-wrap: wrap; gap: var(--gap); align-items: stretch; }
.row > .grow-2 { flex: 2 1 560px; min-width: 0; }
.row > .grow-1 { flex: 1 1 340px; min-width: 0; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: var(--gap); }
.grid-cards--wide { grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); }
.grid-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: 12px; }
.section-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; }

/* ---- Card -------------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card__head { display: flex; flex-direction: column; gap: 2px; }
.card__head .caption { font-size: 13px; }
.card__foot { margin-top: auto; font-size: 12.5px; color: var(--muted); }
.card--flush { padding: 0; overflow: hidden; gap: 0; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 14px; border-radius: var(--radius-md);
  border: 1px solid var(--line-strong); background: var(--card); color: var(--text);
  font-size: 14px; font-weight: 500; white-space: nowrap;
}
.btn:hover { color: var(--text); border-color: var(--axis); }
.btn--primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn--primary:hover { color: var(--on-accent); filter: brightness(1.06); }
.btn--lg { height: 44px; }
.btn--block { width: 100%; }
.btn-icon {
  width: 40px; height: 40px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--card); color: var(--text);
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon--44 { width: 44px; height: 44px; }
.btn-icon--ghost { border-color: transparent; background: transparent; }

/* ---- Search ------------------------------------------------------------ */
.search {
  flex: 1 1 280px; max-width: 480px; margin-left: auto;
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-md);
}
.search svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; }

/* ---- Segmented control / tabs / chips --------------------------------- */
.segmented { display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-md); }
.segmented button { height: 32px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font-size: 13px; }
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--line); color: var(--text); font-weight: 500; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); max-width: 100%; }
.tabs button { height: 36px; padding: 0 14px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); font-size: 13.5px; }
.tabs button[aria-selected="true"] { background: var(--line); color: var(--text); font-weight: 500; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--card); color: var(--text); font-size: 13px; }
.chip[aria-pressed="true"], .chip[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--card); font-weight: 500; }

/* ---- Key / legend ------------------------------------------------------ */
.key { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--text-2); }
.key__item { display: inline-flex; align-items: center; gap: 6px; }
.key__bar { width: 14px; height: 10px; border-radius: 0 3px 3px 0; background: var(--c); }
.key__base { width: 2px; height: 14px; background: var(--baseline); }

/* ---- Stat tiles -------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-md); display: flex; flex-direction: column; gap: 4px; background: var(--card); }
.stat__label { font-size: 12.5px; color: var(--muted); }
.stat__value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat__unit { font-size: 13px; font-weight: 400; color: var(--muted); }
.stat__note { font-size: 12.5px; color: var(--muted); }
.stats--compact .stat { padding: 10px 12px; gap: 0; }
.stats--compact .stat__value { font-size: 20px; }
.stats--compact .stat__note { font-size: 11.5px; }

/* ---- Callout ("In plain words") --------------------------------------- */
.callout { padding: 14px; border-radius: var(--radius-md); background: var(--line); display: flex; flex-direction: column; gap: 4px; }
.callout__label { font-size: 12.5px; font-weight: 500; color: var(--accent-text); }
.callout p { text-wrap: pretty; }

/* ---- Area header / slots ---------------------------------------------- */
.area-head { display: flex; flex-direction: column; gap: 4px; }
.area-head__eyebrow { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.slot { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.slot__top { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.slot__name { font-size: 17px; font-weight: 600; }
.slot__remove { margin-left: auto; width: 32px; height: 32px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-size: 18px; }
.slot--add { border-style: dashed; border-color: var(--axis); gap: 8px; }
.slot--add .search { margin: 0; max-width: none; flex: none; }
.slot--baseline { background: var(--bg); }
.pill { font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--text-2); }

/* ---- Data notes -------------------------------------------------------- */
.notes { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; padding: 14px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); font-size: 13px; color: var(--muted); }
.notes strong { color: var(--text); font-weight: 500; }
.notes a { margin-left: auto; color: var(--accent-text); font-weight: 500; }

/* ---- Lists ------------------------------------------------------------- */
.list-plain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list-plain > li { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; text-wrap: pretty; }
.list-plain > li:last-child { border-bottom: 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 13.5px; }

/* ==========================================================================
   Mobile shell
   ========================================================================== */
.m-app { max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.m-header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 8px 0 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.m-header__title { flex: 1; font-size: 16px; font-weight: 600; }
.m-header--center .m-header__title { text-align: center; }
.m-back { display: inline-flex; align-items: center; gap: 4px; height: 44px; padding: 0 8px; margin-left: -8px; font-weight: 500; }
.m-content { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.m-content .card { padding: 16px; gap: 12px; }

.tabbar {
  position: sticky; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  height: 72px; padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--text-2); }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--accent-text); font-weight: 600; }

/* Mobile map screen: map fills the top, sheet overlaps it */
.m-map { position: relative; flex: 1; display: flex; flex-direction: column; background: var(--card); }
.m-map__top { position: absolute; z-index: 3; top: 12px; left: 16px; right: 16px; display: flex; flex-direction: column; gap: 10px; }
.m-map__top .search { margin: 0; max-width: none; height: 48px; border-radius: 14px; flex: none; }
.m-map__top .chips { margin: 0 -16px; padding: 0 16px; }
.m-map__canvas { position: relative; height: 54vh; min-height: 360px; padding-top: 104px; }
.m-map__canvas .map { height: 100%; }
.m-map__tools { position: absolute; z-index: 3; top: 122px; right: 12px; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); overflow: hidden; }
.m-map__tools button { width: 44px; height: 44px; border: 0; border-bottom: 1px solid var(--line); background: var(--card); display: flex; align-items: center; justify-content: center; }
.m-map__tools button:last-child { border-bottom: 0; }
.m-map__tools svg { width: 18px; height: 18px; }
.m-map__legend { position: absolute; z-index: 3; left: 12px; bottom: 32px; padding: 7px 10px; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-md); display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--text-2); }
.sheet {
  position: relative; z-index: 4; margin-top: -20px;
  background: var(--card); border-top: 1px solid var(--line); border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.18);
  padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px;
}
.sheet__handle { align-self: center; width: 36px; height: 4px; border-radius: 2px; background: var(--axis); }
.sheet__head { display: flex; align-items: flex-start; gap: 12px; }
.sheet__head > div { flex: 1; min-width: 0; }
.sheet__title { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }

/* Area chips on mobile compare */
.area-chip { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 4px 0 12px; background: var(--card); border: 1px solid var(--line-strong); border-radius: 999px; font-weight: 500; }
.area-chip button { width: 32px; height: 32px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: 17px; }
.add-chip { height: 40px; padding: 0 14px; border: 1px dashed var(--axis); border-radius: 999px; background: transparent; font-weight: 500; }
