/* Admin shell layout — dark sidebar + light content area.
   Variables exposed here are the contract every /plotex/* page consumes. */

/* Smooth cross-document navigation: for the routes _spa.js doesn't handle (login,
   sub-pages), opt into the View Transitions API so supporting browsers crossfade
   instead of white-flashing, and keep the sidebar visually stable across pages.
   Progressive enhancement — unsupported browsers just navigate normally. */
@view-transition { navigation: auto; }
.sidebar { view-transition-name: admin-sidebar; }

:root {
  --bg-dark: #1a1f2e;
  --bg-dark-2: #232838;
  --bg-light: #f4f6f9;
  --card-bg: #ffffff;
  --text-light: #f5f7fb;
  --text-dim: #8a93a6;
  --text-body: #2a2f3a;
  --text-muted: #6b7280;
  --accent-green: #4CAF50;
  --accent-green-dim: rgba(76, 175, 80, 0.14);
  --accent-green-dark: #3d9140;
  --accent-red: #ff4444;
  --accent-red-dim: rgba(255, 68, 68, 0.12);
  --accent-blue: #2f7df0;
  --accent-blue-dim: rgba(47, 125, 240, 0.12);
  --accent-yellow: #f3e795;
  --accent-purple: #8b5cf6;
  --border: #e3e7ee;
  --border-dark: #2a3145;
  --status-available: #4CAF50;
  --status-sold: #ff4444;
  --status-booked: #f3e795;
  --status-builder: #bababa;
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-elev: 0 8px 24px rgba(15, 23, 42, 0.12);
  --sidebar-w: 220px;
  --header-h: 64px;
  --radius: 10px;
  --radius-sm: 6px;
  --font-stack: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* The canvas behind any overscroll/rubber-band is the <html> background — left
   unset it paints WHITE, which flashes against the dark sidebar/top bar when
   scrolling (worst on small screens). Paint it dark to match the chrome and stop
   the bounce where the platform allows. */
html {
  background: var(--bg-dark);
  overscroll-behavior-y: none;
}
body { overscroll-behavior-y: none; }

body.admin {
  font-family: var(--font-stack);
  background: var(--bg-light);
  color: var(--text-body);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ── Sidebar ─────────────────────────────────────────────── */
.admin-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-dark);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;   /* dynamic viewport: stays correct while the mobile URL bar collapses */
  border-right: 1px solid var(--border-dark);
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border-dark);
}
.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand-row img {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: #fff;
  padding: 3px;
  object-fit: contain;
}
.sidebar-brand-name {
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 14px;
  color: var(--accent-green);
}
.sidebar-project {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-light);
  font-weight: 600;
}
.sidebar-admin-pill {
  display: inline-block;
  margin-top: 6px;
  background: var(--accent-green);
  color: #08130a;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
}

/* Pages wrap the menu as <nav><ul class="sidebar-nav"></ul></nav>. The <nav>
   wrapper is the REAL flex item — without sizing it, it grows to the menu's full
   content height, the sidebar overflows the viewport, the list never gets a
   scrollbar and the logout button lands off-screen ("can't scroll" bug). */
.sidebar > nav {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 12px 0;
  flex: 1;
  min-height: 0;    /* let this flex child shrink below its content so overflow-y engages */
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-dark) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 14px;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.sidebar-nav a .nav-icon {
  width: 18px; height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: .85;
}
.sidebar-nav a:hover {
  color: var(--text-light);
  background: var(--bg-dark-2);
}
.sidebar-nav a.is-active {
  color: var(--accent-green);
  background: var(--accent-green-dim);
  border-left-color: var(--accent-green);
  font-weight: 600;
}
.sidebar-nav a.is-active .nav-icon { opacity: 1; }
.sidebar-nav .nav-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-dim);
  opacity: 0.5;
  padding: 14px 16px 4px;
  pointer-events: none;
  user-select: none;
}
.sidebar-nav li.nav-section:first-child { padding-top: 2px; }

.sidebar-foot {
  border-top: 1px solid var(--border-dark);
  padding: 10px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-foot a,
.sidebar-foot button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 17px;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  background: transparent;
  border: none;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.sidebar-foot a:hover,
.sidebar-foot button:hover { color: var(--text-light); background: var(--bg-dark-2); }
.sidebar-foot .logout-form { margin: 0; }
.sidebar-foot .logout-btn { color: var(--accent-red); }
.sidebar-foot .logout-btn:hover { color: #ff7575; background: rgba(255,68,68,.08); }

/* ── Content ─────────────────────────────────────────────── */
.admin-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-light);
  position: relative;
}
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;   /* header actions wrap instead of overflowing at mid widths */
  gap: 16px;
  padding: 18px 28px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
}
.admin-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: var(--text-body);
}
.admin-header .header-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}
.admin-header .header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-body {
  padding: 22px 28px 72px;
  flex: 1;
  min-width: 0;
}

.powered-by {
  position: fixed;
  right: 14px;
  bottom: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11px;
  color: var(--text-muted);
  box-shadow: var(--shadow-card);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.powered-by strong { color: var(--accent-green); font-weight: 700; }

/* ── Collapsible sidebar (desktop only) — icon rail ───────────────────────────
   Toggled by the button _chrome.js injects into .sidebar-foot; state persisted in
   localStorage (admin_nav_collapsed) and restored in <head> by _spa.js so there's
   no flash. Class lives on <html>. Gated to ≥769px so the mobile drawer (which
   shows full labels) is unaffected. Labels are hidden with font-size:0 (no markup
   change needed); the icon keeps its own font-size. */
@media (min-width: 769px) {
  html.nav-collapsed { --sidebar-w: 66px; }

  html.nav-collapsed .sidebar-brand { padding: 16px 0 14px; }
  html.nav-collapsed .sidebar-brand-row { justify-content: center; gap: 0; }
  html.nav-collapsed .sidebar-brand-name,
  html.nav-collapsed .sidebar-project,
  html.nav-collapsed .sidebar-admin-pill { display: none; }

  /* Section headers → a thin divider instead of text. */
  html.nav-collapsed .sidebar-nav .nav-section {
    font-size: 0;
    padding: 8px 0 6px;
  }
  html.nav-collapsed .sidebar-nav .nav-section::after {
    content: "";
    display: block;
    height: 1px;
    background: var(--border-dark);
    margin: 0 16px;
  }
  html.nav-collapsed .sidebar-nav li.nav-section:first-child { padding-top: 2px; }
  html.nav-collapsed .sidebar-nav li.nav-section:first-child::after { display: none; }

  /* Nav + foot links: hide the text label, centre the icon. */
  html.nav-collapsed .sidebar-nav a,
  html.nav-collapsed .sidebar-foot a,
  html.nav-collapsed .sidebar-foot button {
    font-size: 0;
    gap: 0;
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
  html.nav-collapsed .sidebar-nav a .nav-icon,
  html.nav-collapsed .sidebar-foot a .nav-icon,
  html.nav-collapsed .sidebar-foot button .nav-icon { font-size: 15px; }
  /* Keep the active green left-border readable on the narrow rail. */
  html.nav-collapsed .sidebar-nav a { border-left-width: 3px; }
}

/* Collapse/expand toggle — a ☰ bar pinned to the TOP of the sidebar by _chrome.js. */
.nav-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 18px;
  background: var(--bg-dark-2);
  border: none;
  border-bottom: 1px solid var(--border-dark);
  color: var(--text-light);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle .nav-icon { font-size: 17px; width: 18px; display: inline-flex; justify-content: center; flex-shrink: 0; }
.nav-toggle:hover { background: #2b3346; }
@media (min-width: 769px) {
  html.nav-collapsed .nav-toggle { justify-content: center; padding-left: 0; padding-right: 0; font-size: 0; gap: 0; }
  html.nav-collapsed .nav-toggle .nav-icon { font-size: 18px; }
}
@media (max-width: 768px) { #nav-collapse-btn { display: none; } }   /* drawer uses the top-bar hamburger */

/* ── Mobile chrome (top bar + drawer) — injected by _chrome.js ─────────────────
   The old ≤768px layout turned the sidebar into a horizontally-scrolling pill bar:
   with 20+ items it was unreachable by mouse wheel, hid the section labels, and the
   page behind it flashed white on overscroll. Replaced with the standard pattern:
   a fixed dark top bar with a hamburger, and the sidebar as a slide-in drawer
   (vertical, scrollable, all items + sections visible). */
.admin-mobilebar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  body.admin { padding-top: 54px; }              /* room for the fixed top bar */
  .admin-shell { grid-template-columns: 1fr; }

  .admin-mobilebar {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 54px;
    z-index: 300;
    background: var(--bg-dark);
    color: var(--text-light);
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border-bottom: 1px solid var(--border-dark);
  }
  .admin-mobilebar .nav-burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px; height: 42px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-light);
    cursor: pointer;
    flex-shrink: 0;
  }
  .admin-mobilebar .nav-burger:active { background: var(--bg-dark-2); }
  .admin-mobilebar .mobilebar-title {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .admin-mobilebar .mobilebar-brand {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--accent-green);
    flex-shrink: 0;
  }

  /* Sidebar becomes an off-canvas drawer: fixed, full-height, scrollable. */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: auto;                                 /* top+bottom pin it; avoids vh quirks */
    width: min(280px, 84vw);
    transform: translateX(-105%);
    transition: transform .25s ease;
    z-index: 320;
    border-right: 1px solid var(--border-dark);
    overscroll-behavior: contain;                 /* drawer scroll never chains to the page */
  }
  body.nav-open .sidebar {
    transform: none;
    box-shadow: 0 0 44px rgba(0, 0, 0, 0.5);
  }
  .sidebar-nav a { padding: 12px 16px 12px 14px; }   /* comfortable touch targets */
  .sidebar-foot a, .sidebar-foot button { padding: 12px 16px 12px 17px; }

  .sidebar-backdrop {
    display: block;                                /* present but invisible; fades in/out */
    position: fixed;
    inset: 0;
    z-index: 310;
    background: rgba(10, 14, 24, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }              /* lock page scroll while drawer is open */

  .admin-header { padding: 14px 16px; }
  .admin-header h1 { font-size: 18px; }
  .admin-body { padding: 16px 14px 80px; }
  .powered-by { right: 8px; bottom: 8px; font-size: 10px; padding: 4px 9px; }
}
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar-backdrop { transition: none; }
}
