/* ==========================================================================
   Base: reset, typography, unified app shell (left sidebar, topbar, mobile nav)
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Every figure in this app lines up in a column somewhere. */
table, .num, input[type="number"] { font-variant-numeric: tabular-nums; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--surface-1); padding: 8px 12px; border-radius: var(--radius);
}
.skip-link:focus { left: 8px; }

.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── App Shell (Sidebar + Main Workspace) ─────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
  max-width: 100vw;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* ── Persistent Left Sidebar ──────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border-right: 1px solid var(--line);
  z-index: 40;
  user-select: none;
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text-1); flex: 0 0 auto; }
.brand:hover { text-decoration: none; }
.brand-crest { width: 30px; height: 30px; border-radius: 50%; overflow: hidden; flex: 0 0 auto; }
.brand-crest img { width: 100%; height: 100%; object-fit: cover; display: none; }
.brand-crest img.for-light { display: block; }
.theme-dark .brand-crest img.for-light { display: none; }
.theme-dark .brand-crest img.for-dark { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.brand-sub {
  font-size: 10px; font-weight: 650; letter-spacing: 0.11em;
  text-transform: uppercase; color: var(--brand);
}

.sidebar-close-btn { display: none !important; }

.sidebar-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-group-title {
  padding: 4px 10px 6px;
  font-size: 10.5px;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-3);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 33px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.sidebar-link:hover {
  background: var(--surface-2);
  color: var(--text-1);
  text-decoration: none;
}
.sidebar-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  font-weight: 700;
}
.sidebar-link.has-me {
  color: var(--pos);
}

.sidebar-icon {
  width: 18px;
  text-align: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-badge {
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 750;
  background: var(--accent);
  color: #fff;
  font-variant-numeric: tabular-nums;
}

/* Collapsible dropdown navigation */
.sidebar-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 33px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.sidebar-dropdown-toggle:hover {
  background: var(--surface-2);
  color: var(--text-1);
}
.sidebar-dropdown-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.sidebar-dropdown-toggle.sidebar-group-toggle {
  font-weight: 700;
  color: var(--text-1);
}
.sidebar-dropdown-toggle.has-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}
.sidebar-dropdown-toggle.is-open {
  color: var(--text-1);
}

.sidebar-chevron {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--text-3);
  transition: transform 0.18s ease, color 0.18s ease;
  flex-shrink: 0;
}
.sidebar-chevron svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.sidebar-dropdown-toggle:hover .sidebar-chevron {
  color: var(--text-1);
}
.sidebar-dropdown-toggle[aria-expanded="true"] .sidebar-chevron {
  transform: rotate(90deg);
  color: var(--text-1);
}

.sidebar-submenu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 4px 13px;
  padding-left: 9px;
  border-left: 1.5px solid var(--line);
}
.sidebar-submenu[hidden] {
  display: none !important;
}

.sidebar-sublink {
  height: 31px;
  padding: 0 8px;
  font-size: 12.5px;
}
.sidebar-sublink .sidebar-icon {
  font-size: 13px;
  width: 16px;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-classic-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
}
.sidebar-classic-link:hover {
  color: var(--text-1);
  background: var(--surface-2);
  text-decoration: none;
}

.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 39;
}

/* ── Top bar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-row {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--topbar-h); padding: 6px var(--gutter);
}

.mobile-menu-btn { display: none !important; }
.mobile-brand {
  display: none;
  font-weight: 750;
  font-size: 14.5px;
  color: var(--text-1);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.mobile-brand:hover { text-decoration: none; }

.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; flex: 0 0 auto; }
.sync { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; margin-right: 4px; }
.sync.is-error { color: var(--neg); }

/* ── Sub bar ──────────────────────────────────────────────────────────── */
.subbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 7px var(--gutter); border-top: 1px solid var(--line);
}
.subbar[hidden] { display: none !important; }
.subbar .week-slider-wrap { margin-left: 0; }

/* ── Personal Standing Banner Slot ────────────────────────────────────── */
.standing-banner-slot {
  padding: 10px var(--gutter) 0;
}
.standing-banner-slot[hidden] { display: none !important; }

/* ── View outlet ──────────────────────────────────────────────────────── */
.view {
  padding: 16px var(--gutter) 72px;
  outline: none;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}
.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.view-title { font-size: var(--fs-xl); }
.view-sub { color: var(--text-2); font-size: var(--fs-sm); margin-top: 2px; }

/* ── Mobile Sticky Bottom Bar ─────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 58px;
  background: color-mix(in srgb, var(--surface-1) 96%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-top: 1px solid var(--line-strong);
  z-index: 35;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10.5px;
  font-weight: 650;
  color: var(--text-2);
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: none;
}
.mobile-nav-item:hover { text-decoration: none; color: var(--text-1); }
.mobile-nav-item.is-active { color: var(--accent); font-weight: 750; }
.mobile-nav-icon { font-size: 16px; line-height: 1.1; }

/* ── Responsive frame (< 960px) ───────────────────────────────────────── */
@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 272px;
    transform: translateX(-104%);
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: var(--shadow-pop);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .sidebar-close-btn { display: inline-flex !important; }
  .mobile-menu-btn { display: inline-flex !important; }
  .mobile-brand { display: inline-flex; align-items: center; }

  .topbar-row {
    flex-wrap: wrap;
    min-height: auto;
    padding: 6px 10px 8px;
    gap: 6px;
  }
  .topbar-row .clan-switch {
    order: 3;
    flex: 1 0 100%;
  }
  .findme-name {
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: bottom;
  }

  .subbar {
    padding: 6px 10px;
    gap: 8px 12px;
  }
  .standing-banner-slot {
    padding: 10px 12px 0;
  }
  .mobile-nav { display: grid; }
  .sync { display: none; }
  .view { padding: 12px 12px 84px; }
}

@media (max-width: 600px) {
  .hide-xs { display: none !important; }
  .week-slider { display: none; }
  .week-slider-wrap {
    max-width: 100%;
    flex-wrap: wrap;
    padding: 3px 8px;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
