/* Shared sidebar: used by the home page and by every Django page, so the menu is always there.
   State lives on <html>: .nav-closed = collapsed on desktop, .nav-open = drawer open on a phone. */
[hidden] { display: none !important; }

.layout { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; }
.sidebar {
  flex: 0 0 300px; width: 300px; background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: flex-basis .2s, width .2s;
}
.nav-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px 16px; border: 0; cursor: pointer;
  background: none; color: var(--primary); font: inherit; font-weight: 700; text-align: left;
  border-bottom: 1px solid var(--border);
}
.nav-toggle:focus-visible, #nav-open:focus-visible, #loc-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chev {
  display: inline-block; flex: 0 0 auto; width: 10px; height: 10px; border-left: 3px solid currentColor;
  border-bottom: 3px solid currentColor; transform: rotate(45deg); margin: 0 4px 0 6px; transition: transform .2s;
}
.nav-body { padding: 16px; }
.nav-body label { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
#loc-select {
  width: 100%; font: inherit; font-size: .92rem; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.loc-info { margin-top: 14px; font-size: .88rem; color: var(--muted); }
.loc-info a { color: var(--primary); }
.loc-info div { margin: 3px 0; }
.nav-body .hint { font-size: .8rem; color: var(--muted); margin-top: 16px; }
.home-box { margin-top: 14px; }
.home-box .hint { margin: 6px 0 0; }
.home-box a { color: var(--primary); }
.home-btn {
  width: 100%; font: inherit; font-weight: 600; padding: 9px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--primary); background: transparent; color: var(--primary);
}
.home-btn:hover:not(:disabled) { background: var(--primary); color: #fff; }
.home-btn:disabled { opacity: .6; cursor: default; }
.home-set { font-weight: 600; color: var(--primary); }
.side-link {
  display: block; margin-top: 14px; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  color: var(--primary); font-weight: 600; text-decoration: none; text-align: center; background: var(--bg);
}
.side-link:hover, .side-link:focus-visible { border-color: var(--accent); outline: none; }
.side-link.active { border-color: var(--primary); background: var(--surface); box-shadow: inset 3px 0 0 var(--primary); }
.side-link.first { margin: 0 0 16px; }

#nav-open { display: none; }
.backdrop { display: none; }
.nav-rail { display: none; }

@media (min-width: 821px) {
  /* collapsed: a narrow strip of icon shortcuts. overflow stays visible so the hover labels can reach out past the strip */
  html.nav-closed .sidebar { flex-basis: 52px; width: 52px; overflow: visible; z-index: 15; }
  html.nav-closed .nav-toggle { padding: 14px 0; justify-content: center; }
  html.nav-closed .nav-toggle-label, html.nav-closed .nav-body { display: none; }
  html.nav-closed .chev { transform: rotate(-135deg); margin: 0; }
  html.nav-closed .nav-rail { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; }
  .rail-link {
    position: relative; display: flex; align-items: center; justify-content: center; width: 38px; height: 38px;
    border-radius: 9px; border: 1px solid transparent; color: var(--primary); text-decoration: none;
  }
  .rail-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .rail-link:hover, .rail-link:focus-visible { background: var(--bg); border-color: var(--accent); outline: none; }
  .rail-link.active { background: var(--bg); border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
  .rail-link::after {
    content: attr(data-tip); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
    white-space: nowrap; background: var(--text); color: var(--bg); font-size: .8rem; font-weight: 600;
    padding: 5px 10px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .12s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  }
  .rail-link:hover::after, .rail-link:focus-visible::after { opacity: 1; }
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed; z-index: 30; left: 0; top: 0; flex: none; width: min(300px, 86vw);
    box-shadow: 4px 0 24px rgba(0, 0, 0, .25); transform: translateX(-105%); transition: transform .2s;
  }
  html.nav-open .sidebar { transform: none; }
  html.nav-open .backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); }
  #nav-open {
    display: block; position: fixed; z-index: 10; left: 12px; top: 12px; padding: 8px 14px; border-radius: 999px;
    border: 0; background: var(--primary); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
  }
  html.nav-open #nav-open { display: none; }
  .top { padding-left: 110px; }   /* keep the header clear of the floating Menu button */
  .auth { top: 18px; }
}
