/* Shared layout for the five tier pages: sidebar, tier navigation, account
   menu and the small-screen drawer. Loaded after each page's own <style>, so
   the responsive rules here override it. */

:root {
  --sidebar-width: 248px;
  --sidebar-bg: #f8f9fb;
  --nav-hover: #eef0f4;
  --nav-text: #4b5563;
  --mobile-bar-height: 52px;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 1100;
  width: var(--sidebar-width);
  display: flex; flex-direction: column;
  padding: 18px 12px 14px; overflow-y: auto;
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
}

.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; }
.brand-mark {
  flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; font-size: 14.5px; font-weight: 700; line-height: 1.2; }
.brand-text small {
  margin-top: 3px; color: var(--muted); font-size: 11.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav-section { display: flex; flex-direction: column; gap: 2px; }
.nav-section-title,
.dashboard-tier-nav-title {
  padding: 12px 10px 6px; color: var(--muted);
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
}

.sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 0; border-radius: 8px;
  color: var(--nav-text); font-size: 13.5px; font-weight: 500; text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.sidebar a:hover { background: var(--nav-hover); color: var(--ink); }
.sidebar a.router-link-exact-active,
.sidebar a.dashboard-tier-nav-active {
  background: #fff; color: var(--accent); font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), inset 0 0 0 1px var(--border);
}
.sidebar a:focus-visible,
.sidebar select:focus-visible,
.sidebar button:focus-visible,
.nav-toggle:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---- Tier navigation ("Views"), drawn by tier-demo/app.js ---- */
.dashboard-tier-nav { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; margin-bottom: 2px; border-bottom: 1px solid var(--border); }
.dashboard-tier-nav:empty { display: none; }
.dashboard-tier-nav-title { padding-top: 4px; }
.sidebar .dashboard-tier-nav a { flex-direction: column; align-items: flex-start; gap: 1px; }
.dashboard-tier-nav-label { font-size: 13.5px; }
.dashboard-tier-nav-sub {
  max-width: 100%; color: var(--muted); font-size: 11.5px; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dashboard-tier-nav-picker {
  display: flex; flex-direction: column; gap: 1px;
  padding: 8px 10px; border-radius: 8px; color: var(--nav-text); font-size: 13.5px; font-weight: 500;
}
.dashboard-tier-nav-picker.dashboard-tier-nav-active {
  background: #fff; color: var(--accent); font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), inset 0 0 0 1px var(--border);
}
.dashboard-tier-nav-picker select {
  width: 100%; margin-top: 6px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--ink);
  font: inherit; font-size: 12.5px; font-weight: 400; cursor: pointer;
}
.dashboard-tier-nav-picker select:hover { border-color: #c7cbd3; }

/* ---- Account (bottom of the sidebar) ---- */
.dashboard-auth-slot { position: relative; margin-top: auto; padding: 12px 0 0; border-top: 1px solid var(--border); }
.dashboard-auth-link {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 36px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
  color: var(--ink); font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.sidebar a.dashboard-auth-link:hover { border-color: var(--accent); background: #fff; color: var(--accent); }
.dashboard-auth-account {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; text-align: left; font-family: inherit; cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.dashboard-auth-account:hover { border-color: #c7cbd3; box-shadow: 0 1px 3px rgba(16, 24, 40, 0.08); }
.dashboard-auth-name { display: block; color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1.3; }
.dashboard-auth-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 11.5px; line-height: 1.35; overflow-wrap: anywhere; }
.dashboard-auth-menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 10;
  padding: 4px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; box-shadow: 0 12px 28px rgba(16, 24, 40, 0.14);
}
.sidebar .dashboard-auth-menu-item {
  display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: none;
  color: var(--ink); font: inherit; font-size: 13px; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer;
}
.sidebar .dashboard-auth-menu-item:hover { background: var(--accent-soft); color: var(--accent); }

/* ---- Main area ---- */
.main { margin-left: var(--sidebar-width); }
/* Grid children default to min-width: auto, so a chart canvas keeps its
   desktop width and pushes the card off a narrow screen. */
.grid-2 > *, .tiles > * { min-width: 0; }
.export-bar { flex-wrap: wrap; }
/* Keeps Leaflet's high z-indexes inside the map, under the sticky bars. */
.map-wrap { position: relative; z-index: 0; }

/* ---- Small screens: the sidebar becomes a drawer ---- */
.mobile-bar, .nav-backdrop { display: none; }

@media (max-width: 960px) {
  .mobile-bar {
    position: sticky; top: 0; z-index: 1000;
    display: flex; align-items: center; gap: 10px;
    height: var(--mobile-bar-height); padding: 0 12px;
    background: #fff; border-bottom: 1px solid var(--border);
  }
  .nav-toggle {
    display: grid; place-content: center; gap: 4px; width: 38px; height: 38px; flex: none;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer;
  }
  .nav-toggle span { display: block; width: 16px; height: 2px; border-radius: 2px; background: var(--ink); }
  .mobile-bar-title { font-size: 14px; font-weight: 700; white-space: nowrap; }
  .mobile-bar-view {
    min-width: 0; color: var(--muted); font-size: 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .sidebar {
    width: min(300px, 86vw);
    transform: translateX(-100%); visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .sidebar.open {
    transform: none; visibility: visible;
    transition: transform 0.2s ease, visibility 0s;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
  }
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 1050; background: rgba(15, 23, 42, 0.38); }

  .main { margin-left: 0; }
  .topbar { top: var(--mobile-bar-height); padding: 12px 16px; }
  .content { padding: 20px 16px 48px; }
  .refreshing { top: calc(var(--mobile-bar-height) + 10px); }

  /* Grid pages scroll inside .main, so their top bar sticks to its top. */
  .main.main-fill { height: calc(100vh - var(--mobile-bar-height)); height: calc(100dvh - var(--mobile-bar-height)); }
  .main-fill .topbar { top: 0; }
}

@media (max-width: 420px) {
  /* One column: fields that span two would otherwise force a second one. */
  .filterbar { grid-template-columns: 1fr; }
  .filterbar .field { grid-column: auto !important; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar.open, .sidebar a, .dashboard-auth-account { transition: none; }
}
