/* Surkora layout: app bar, views, map pane, tab bar, sheets, overlays.
   Mobile first; desktop (>= 900px) shows map and panel side by side. */

/* App bar */
.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(var(--appbar-h) + var(--safe-t));
  padding: var(--safe-t) 12px 0;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
  color: var(--ink);
  text-decoration: none;
}
.brand img { width: 30px; height: 30px; }
/* The wordmark is the brand board's own lettering, traced to a vector and painted in the theme's pine. */
.brand-text { display: block; line-height: 1; }
.wordmark {
  display: block;
  width: 86px;
  aspect-ratio: 405 / 91.5;
  background: var(--pine);
  font-size: 0;
  -webkit-mask: url(/wordmark.svg) no-repeat center / contain;
  mask: url(/wordmark.svg) no-repeat center / contain;
}
/* Alone beside the mark (no subtitle), the k's ascender fills the top third of the box:
   lift the letters so their body, not the box, sits on the mark's centre. */
@media (max-width: 899px) {
  .wordmark { transform: translateY(-16%); }
}
.brand-text small { display: none; margin-top: 3px; color: var(--muted); font-size: 11.5px; }
@media (max-width: 359px) {
  .brand-text { display: none; }
}

/* One tap opens the parcel sheet; the parcel's name lives in its tooltip and for screen readers. */
.parcel-switch {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--emerald);
}
.parcel-switch:hover { border-color: var(--emerald); }

.net-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--leaf);
  box-shadow: 0 0 0 3px var(--mint-tint);
}
.net-dot.off { border-radius: 2px; background: var(--gold-deep); box-shadow: 0 0 0 3px var(--gold-tint); transform: rotate(45deg); }

.auth-top-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--pine);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.auth-top-btn:hover { border-color: var(--emerald); color: var(--emerald); }
.auth-top-btn .ic { width: 16px; height: 16px; }
.auth-top-btn.is-signed { padding: 3px 10px 3px 4px; background: var(--mint-tint); border-color: #bfe0cb; }
.auth-chip-av {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--emerald);
  color: var(--cream);
  font-size: 13px;
  font-weight: 700;
}
.auth-chip-name { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 440px) {
  .auth-top-btn span:not(.auth-chip-av) { display: none; }
  .auth-top-btn { padding: 0 9px; }
  .auth-top-btn.is-signed { padding: 3px; }
}

.guest-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 10px 14px;
  border: 1px solid #bfe0cb;
  border-radius: var(--radius);
  background: var(--mint-tint);
  color: var(--pine);
  font-size: 13.5px;
  font-weight: 600;
}
.guest-banner[hidden] { display: none; }
.guest-banner-text { flex: 1 1 180px; }

/* Shell */
.shell { position: relative; }
.panel { position: relative; }
.views { padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); }

.view { display: none; flex-direction: column; gap: 14px; }
.view.active { display: flex; }
.subview { display: none; flex-direction: column; gap: 14px; }
.subview.active { display: flex; }

/* Map pane: flex column so Leaflet attribution stays visible above the HUD. */
.map-pane {
  position: relative;
  z-index: 0;
  display: none;
  flex-direction: column;
  background: var(--sunken);
}
#map { position: relative; flex: 1; min-height: 240px; background: #e6e2d6; }

.map-tools {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fab {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.fab:hover { border-color: var(--emerald); color: var(--emerald); }

.map-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 1000;
  width: max-content;
  max-width: calc(100% - 140px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(16, 35, 26, 0.88);
  color: var(--cream);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
}

.hud-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/* Tabs */
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
}
/* On phones the active icon sits in a mint pill. */
.tab .ic {
  width: 58px;
  height: 32px;
  padding: 4px 17px;
  border-radius: 999px;
  transition: background 0.2s;
}
.tab span { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tab.active { color: var(--pine); font-weight: 700; }
.tab.active .ic { background: var(--mint-tint); color: var(--emerald); stroke-width: 2.2; }
@media (hover: hover) {
  .tab:not(.active):hover .ic { background: var(--sunken); }
}

.tab-badge {
  position: absolute;
  top: 3px;
  left: calc(50% + 10px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 2px solid var(--surface);
  border-radius: 999px;
  background: var(--risk);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
}

/* Mobile: tab bar at the thumb, map takes the whole screen when chosen. */
@media (max-width: 899px) {
  .tabbar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding: 0 4px var(--safe-b);
    border-top: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 -8px 24px -20px rgba(16, 35, 26, 0.5);
  }
  html[data-view="mapa"] .map-pane {
    position: fixed;
    top: calc(var(--appbar-h) + var(--safe-t));
    right: 0;
    bottom: calc(var(--tabbar-h) + var(--safe-b));
    left: 0;
    display: flex;
  }
  html[data-view="mapa"] .views { display: none; }
  html[data-view="mapa"] body { overflow: hidden; }
}

/* Desktop: map left, panel right, underline tabs on top of the panel. */
@media (min-width: 900px) {
  .brand-text small { display: block; }
  .appbar { padding: 0 20px; }

  .shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 480px;
    height: calc(100dvh - var(--appbar-h));
  }
  .map-pane { display: flex; min-height: 0; }
  .panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-left: 1px solid var(--line);
    background: var(--paper);
  }
  .tabbar {
    display: flex;
    gap: 2px;
    padding: 0 12px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }
  .tab {
    flex: 1;
    flex-direction: row;
    gap: 6px;
    min-height: 48px;
    font-size: 14px;
  }
  .tab::after {
    position: absolute;
    right: 10px;
    bottom: -1px;
    left: 10px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: var(--emerald);
    content: "";
    opacity: 0;
  }
  .tab.active::after { opacity: 1; }
  .tab:hover { color: var(--ink); }
  .tab .ic,
  .tab.active .ic,
  .tab:not(.active):hover .ic { width: 18px; height: 18px; padding: 0; background: none; }
  .tab-map { display: none !important; }
  .tab-badge { position: static; border: 0; }

  .views {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 20px 32px;
    overscroll-behavior: contain;
  }
  .hud-card { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
}
@media (min-width: 1280px) {
  .shell { grid-template-columns: minmax(0, 1fr) 540px; }
}

/* Bottom sheets (centred dialog on desktop) */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(16, 35, 26, 0.48);
}
body.sheet-open { overflow: hidden; }

.sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  max-height: 88dvh;
  padding-bottom: var(--safe-b);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  box-shadow: 0 -10px 30px -16px rgba(16, 35, 26, 0.45);
  transform: translateY(104%);
  transition: transform 0.28s var(--spring);
}
.sheet[hidden] { display: none; }
.sheet.open { transform: none; }
.sheet-grip {
  width: 40px;
  height: 5px;
  margin: 8px auto 2px;
  border-radius: 999px;
  background: var(--line-strong);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 4px 18px;
}
.sheet-head h2 { font-size: 19px; }
.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 18px 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet-body h3 { margin-top: 6px; }

@media (min-width: 900px) {
  .sheet {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    width: min(520px, calc(100vw - 48px));
    max-height: min(80dvh, 760px);
    padding-bottom: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 22px;
    opacity: 0;
    transform: translate(-50%, -48%);
    transition: transform 0.24s var(--spring), opacity 0.18s;
  }
  .sheet.open { opacity: 1; transform: translate(-50%, -50%); }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 12px; }
}

/* Status overlays */
.offline-banner {
  position: relative;
  z-index: 45;
  padding: calc(6px + var(--safe-t)) 14px 6px;
  border-bottom: 1px solid #ebd27a;
  background: var(--gold-tint);
  color: var(--gold-text);
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
}
html.is-offline .shell { height: calc(100dvh - var(--appbar-h) - 34px); }

.loading {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 90;
  height: 3px;
  overflow: visible;
  pointer-events: none;
}
.loading-bar {
  display: block;
  width: 40%;
  height: 3px;
  background: var(--leaf);
  animation: load-slide 1.1s ease-in-out infinite;
}
@keyframes load-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
.loading-pill {
  position: absolute;
  top: calc(var(--appbar-h) + var(--safe-t) + 10px);
  left: 50%;
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--pine);
  color: var(--cream);
  font-size: 13px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  left: 50%;
  z-index: 95;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: var(--radius);
  background: var(--pine);
  color: var(--cream);
  font-size: 14px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}
@media (min-width: 900px) {
  .toast { bottom: 24px; }
}

/* Print: only the active view content, no chrome; open every detail. */
@media print {
  .appbar,
  .tabbar,
  .map-pane,
  .subtabs,
  .btn-row,
  .toast,
  .scrim,
  .sheet,
  .offline-banner,
  .loading,
  .ask-pill,
  .guest-banner,
  .quick-prompts { display: none !important; }
  .shell { display: block; height: auto; }
  .views { overflow: visible; padding: 0; }
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .vrow-list { grid-template-columns: 1fr !important; }
  .card,
  .vrow { break-inside: avoid; box-shadow: none; }
  .vrow-body { display: flex !important; }
}
