/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
/* Author `display` rules (e.g. .notification-bar's display: flex) otherwise
   beat the UA stylesheet's [hidden] { display: none }, regardless of
   specificity -- an element can be hidden and still render. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-chrome);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Mobile shell (default) ── */
/* A hard height (not min-height) + overflow:hidden here, matching the
   desktop media query below, is load-bearing: .main-content is the only
   element meant to scroll (its own overflow-y:auto, see below), but
   without a capped ancestor height the flex column just grows to fit
   content and the *document* ends up scrolling instead -- which both
   makes .chrome-row's position:sticky look like "the topbar is the only
   thing that scrolls" and silently breaks the scroll-shadow listener,
   since that only fires on #main-content's own scroll event. One bug,
   two symptoms -- see GitHub issue #206/#207. */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.chrome-row {
  position: sticky;
  top: 0;
  z-index: 100;
  background: transparent;
  color: var(--text);
  border-bottom: 1px solid transparent;
  padding: 0.75rem 1rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

/* Keep the scroll shadow outside the header's paint box so it can extend
   cleanly over the independently scrolling content below. */
.chrome-row::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  pointer-events: none;
  transition: box-shadow var(--transition-fast);
}

/* Flat at rest; a shadow only appears once content has actually scrolled
   under the row, toggled by base.html's scroll listener on #main-content. */
.chrome-row.scrolled {
  border-bottom-color: var(--border);
}

.chrome-row.scrolled::after {
  box-shadow: var(--shadow-scroll);
}

.chrome-center {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.topbar-search-link,
.topbar-notification-link {
  display: flex;
  color: var(--text-muted);
}

.topbar-search-link svg,
.topbar-notification-link svg {
  width: 20px;
  height: 20px;
}

.topbar-search-link:hover,
.topbar-notification-link:hover {
  color: var(--text);
}

/* ── Mobile nav drawer ── */
.nav-drawer-wrapper {
  position: relative;
}

.hamburger-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
}

.hamburger-btn svg {
  width: 22px;
  height: 22px;
}

.nav-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--backdrop);
}

.nav-drawer-panel {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 80%;
  max-width: 280px;
  background: var(--surface);
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.drawer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(0.75rem + env(safe-area-inset-top)) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.drawer-brand {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.drawer-close:hover {
  color: var(--text);
}

.drawer-links {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

.drawer-links a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.drawer-links a svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.drawer-links a.active {
  color: var(--text);
  background: var(--surface-sunken);
}

.drawer-footer {
  padding: var(--space-4);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.drawer-user-name {
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: var(--space-2);
}

.drawer-footer-link {
  display: block;
  width: 100%;
  padding: var(--space-1) 0;
  color: var(--text-muted);
  text-decoration: none;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}

.drawer-footer-link:hover {
  color: var(--text);
}

.drawer-switch-section {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.drawer-switch-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

/* ── Theme toggle (drawer footer + desktop sidebar footer) ── */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.theme-toggle .theme-toggle-option {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--space-2) 0;
  margin: 0;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  color: var(--text-muted);
  cursor: pointer;
}

.theme-toggle .theme-toggle-option:not(:first-child) {
  border-left: none;
}

.theme-toggle .theme-toggle-option:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.theme-toggle .theme-toggle-option:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.theme-toggle .theme-toggle-option:not(:first-child):not(:last-child) {
  border-radius: 0;
}

.theme-toggle .theme-toggle-option svg {
  width: 15px;
  height: 15px;
}

.theme-toggle .theme-toggle-option:hover {
  color: var(--text);
}

.theme-toggle .theme-toggle-option.is-active {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--accent);
  position: relative;
  z-index: 1;
}

.dropdown-label {
  padding: 0.375rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--text);
  text-align: left;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast);
  line-height: 1.4;
}

/* .armed is added by property-menu.js's press-select drag (#207) --
   .dropdown-item predates that gesture and only ever had :hover, so a
   held-over item during a drag showed no feedback at all. */
.dropdown-item:hover,
.dropdown-item.armed { background: var(--surface-sunken); color: var(--text); }

.dropdown-divider { height: 1px; background: var(--border); margin: 0.25rem 0; }

.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notifications-area {
  padding: 0;
}

.notifications-area:has(.notification-bar:not([hidden])) {
  padding: 0.75rem 1rem 0;
}

.ptr-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ptr-indicator {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.ptr-indicator svg {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-fast);
}

.ptr-indicator.ptr-ready svg {
  transform: rotate(180deg);
}

.ptr-indicator.ptr-loading svg {
  animation: ptr-spin 0.6s linear infinite;
}

@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

.main-content {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  background: var(--bg);
  padding: var(--space-1) 1rem calc(1rem + env(safe-area-inset-bottom));
}

/* ── Sidebar (desktop only, hidden by default) ── */
.sidebar { display: none; }

/* ── Notification bars ── */
.notification-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  margin-bottom: 0.625rem;
  background: var(--warning-tint);
  border: 1px solid var(--warning);
  border-radius: var(--radius-control);
  font-size: 0.875rem;
  color: var(--warning);
}

.notif-dismiss {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--warning);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.notif-enable-btn {
  font-size: 0.8rem;
}

/* ── Desktop layout ── */
@media (min-width: 768px) {
  .app-shell {
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
  }

  .chrome-row { display: none; }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    height: 100vh;
  }

  .sidebar-brand {
    display: block;
    padding: 1.25rem 1.25rem 1rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-search-link,
  .sidebar-notification-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 0;
    margin: 0.5rem 0.75rem 0;
    color: var(--text-muted);
    border-radius: var(--radius-control);
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
  }

  .sidebar-search-link svg,
  .sidebar-notification-link svg {
    width: 18px;
    height: 18px;
  }

  .sidebar-search-link:hover,
  .sidebar-notification-link:hover {
    background: var(--surface-sunken);
    color: var(--text);
  }

  .sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
  }

  .sidebar-nav a {
    display: block;
    padding: 0.5rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: var(--radius-control);
    margin: 0 0.5rem 0.125rem;
    transition: background var(--transition-fast);
  }

  .sidebar-nav a:hover {
    background: var(--surface-sunken);
    color: var(--text);
  }

  .sidebar-nav a.active {
    background: var(--surface-sunken);
    color: var(--text);
    border-left: 3px solid var(--accent);
    padding-left: calc(1.25rem - 3px);
  }

  .sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.8125rem;
    color: var(--text-muted);
  }

  .sidebar-footer a,
  .sidebar-footer button {
    color: var(--text-muted);
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    font-size: 0.8125rem;
    font-family: inherit;
    cursor: pointer;
  }

  .sidebar-footer a:hover,
  .sidebar-footer button:hover {
    color: var(--text);
  }

  .sidebar-user-name {
    color: var(--text);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
  }

  .sidebar-admin-link {
    display: block;
    margin-top: 0.5rem;
  }

  .sidebar-switch-section {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
  }

  .sidebar-switch-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
  }

  .sidebar-switch-link {
    display: block;
    padding: 0.2rem 0;
  }

  .main-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .notifications-area {
    padding: 0;
  }

  .notifications-area:has(.notification-bar:not([hidden])) {
    padding: 1.25rem 2rem 0;
  }

  .main-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3) 2rem 2rem;
  }

  .page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 1.5rem;
  }
}
