/* ============================================================================
   SRR Race Meetup — styles
   ----------------------------------------------------------------------------
   The design was built as an iPhone mockup (a fixed 390×844 frame). Here we keep
   every color, font, radius and spacing from that design, but drop the literal
   phone bezel and make it a real mobile-first responsive page:

     * On a phone the app fills the screen.
     * On a wider screen it centers in a phone-width column on a warm backdrop,
       so it still feels like the designed product.

   Most component styling lives inline in js/app.js (the design itself is almost
   entirely inline-styled, so mirroring that keeps the port faithful and easy to
   diff against the original). This file holds the shared shell, tokens, fonts,
   scrollbar and animation rules.
   ============================================================================ */

:root {
  --accent: #ffd400;
  --accent-deep: #e6be00;
  --ink: #1a1813;
  --bg: #faf7ee;
  --card: #ffffff;
  --line: #ece6d6;
  --muted: #8c8675;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: #e7e3d8;
  color: var(--ink);
  font-family: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

input,
textarea,
button,
select {
  font-family: 'Hanken Grotesk', system-ui, sans-serif;
}

/* Hide scrollbars on horizontal chip rows and the main scroll area (as in design). */
.scroll::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}
.scroll {
  scrollbar-width: none;
}

/* ---- responsive app shell (replaces the phone frame) ----------------------
   The frame is a fixed-height flex column: header on top, scrolling main in the
   middle, nav at the bottom. The header and nav are plain flex children OUTSIDE
   the scroll area, so they're frozen by construction — only .main scrolls. */
.frame {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  /* Size to the SMALL viewport so the frozen header + bottom nav always sit
     between iOS Safari's toolbars (svh = viewport with both bars shown). Because
     only .main scrolls — the body doesn't — the toolbars stay put, so there's no
     gap. Layered fallbacks: vh (old) -> dvh -> svh (winner where supported). */
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 520px) {
  body {
    padding: 24px 0;
  }
  .frame {
    height: calc(100vh - 48px);
    height: calc(100svh - 48px);
    border-radius: 28px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(0, 0, 0, 0.04);
  }
}

/* The left sidebar is desktop-only; the (min-width: 900px) block reveals it. */
.sidebar {
  display: none;
}

/* The body column: header + scroll area + (mobile) nav. On mobile it fills the
   phone frame; on desktop it's the content pane to the right of the sidebar. */
.app-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

/* top bar — frozen; shrinks when .compact is toggled on scroll */
.topbar {
  flex-shrink: 0;
  z-index: 40;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  transition: padding 0.18s ease;
}
.topbar.compact .topbar-row {
  padding: 7px 16px;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn i {
  font-size: 19px;
  color: var(--ink);
}
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 0 var(--accent-deep);
  flex-shrink: 0;
  transition: width 0.18s ease, height 0.18s ease;
}
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.topbar.compact .brand-logo {
  width: 27px;
  height: 27px;
}
.app-title {
  flex: 1;
  min-width: 0;
  font-weight: 800;
  font-size: 22px;
  color: var(--ink);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: font-size 0.18s ease, opacity 0.18s ease;
}
.topbar.compact .app-title {
  font-size: 17px;
}
/* Race page: hide the name in the bar at the top, reveal it once scrolled. */
.app-title.reveal {
  opacity: 0;
}
.topbar.compact .app-title.reveal {
  opacity: 1;
}
.level-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  flex-shrink: 0;
}
.level-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* the only scrolling region */
.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

/* bottom nav — frozen flex child below the scroll area */
.bottomnav {
  flex-shrink: 0;
  z-index: 45;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 9px 10px calc(10px + env(safe-area-inset-bottom));
}
.navbtn {
  flex: 1;
  min-width: 0; /* let labels ellipsis instead of forcing the row wider (6-item admin nav) */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---- bottom sheets -------------------------------------------------------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 8, 0.45);
  z-index: 200;
  animation: fadeIn 0.18s ease;
}
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 26px 26px 0 0;
  z-index: 201;
  padding: 10px 18px calc(26px + env(safe-area-inset-bottom));
  animation: sheetUp 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 92vh;
  overflow: auto;
}
.sheet-grip {
  width: 38px;
  height: 5px;
  border-radius: 99px;
  background: var(--line);
  margin: 0 auto 14px;
}

/* ---- toast ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  z-index: 300;
  text-align: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
  max-width: 86%;
  animation: toastIn 0.22s ease;
}

/* ---- small helpers reused across the app ---------------------------------- */
.arch {
  font-family: 'Archivo', system-ui, sans-serif;
}
.mono {
  font-family: 'DM Mono', monospace;
}
button {
  font-family: inherit;
}

/* ===========================================================================
   Responsive content + desktop layout
   ---------------------------------------------------------------------------
   Mobile (base): lists are single-column; the sidebar is hidden; sheets are
   bottom sheets. The .page wrapper is transparent. Everything desktop lives in
   the (min-width: 900px) block at the bottom.
   =========================================================================== */

/* Card lists: stacked on mobile, a responsive grid on desktop. */
.card-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Sidebar internals (only visible on desktop, but defined here). */
.sb-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 14px;
}
.sb-brand .brand-logo {
  width: 38px;
  height: 38px;
}
.sb-brand-title {
  font-weight: 800;
  font-size: 16px;
  color: var(--ink);
  line-height: 1.1;
}
.sb-brand-sub {
  font-size: 8px;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-top: 3px;
}
.sb-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}
.sb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: none;
  background: none;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--muted);
  text-align: left;
}
.sb-item i {
  font-size: 21px;
}
.sb-item:hover {
  background: var(--bg);
  color: var(--ink);
}
.sb-item.active {
  background: var(--ink);
  color: #fff;
}
.sb-item.active i {
  color: var(--accent);
}
.sb-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.sb-level {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--ink);
}
.sb-level .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-deep);
}
.sb-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: none;
  background: none;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
}
.sb-profile:hover,
.sb-profile.active {
  background: var(--bg);
}
.sb-profile-name {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ink);
}
.sb-profile-role {
  font-size: 11px;
  color: var(--muted);
}

@media (min-width: 900px) {
  /* The frame becomes a sidebar + content card that uses the wide screen. */
  .frame.app-shell {
    max-width: 1320px;
    flex-direction: row;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 248px;
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    overflow-y: auto;
  }
  .bottomnav {
    display: none;
  }
  /* On desktop the brand + level live in the sidebar, so drop them from the bar. */
  .topbar .brand-logo,
  .topbar .level-pill {
    display: none;
  }
  .topbar-row {
    padding: 16px 28px;
  }
  .topbar.compact .topbar-row {
    padding: 11px 28px;
  }
  /* Center + cap the content, with breathing room. */
  .page {
    max-width: 1040px;
    margin: 0 auto;
    padding: 6px 28px 28px;
  }
  /* Lists flow into columns. */
  .card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
    align-items: start;
  }
  /* Race detail: hero full-width, then info + who's-going side by side. */
  .race-hero {
    border-radius: 16px;
    margin-top: 6px;
  }
  .race-cols {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    align-items: start;
  }
  .race-info {
    padding-left: 0 !important;
  }
  /* Bottom sheets become centered dialogs. The drag grip is hidden here, so add
     top padding to give the dialog title room to breathe. */
  .sheet {
    left: 50%;
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: min(540px, calc(100vw - 48px));
    max-width: 540px;
    border-radius: 20px;
    max-height: 86vh;
    padding: 24px 24px 26px;
    animation: dialogIn 0.2s ease;
  }
  .sheet-grip {
    display: none;
  }
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translate(-50%, -46%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

@keyframes sheetUp {
  from {
    transform: translate(-50%, 100%);
  }
  to {
    transform: translate(-50%, 0);
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}
