/*
 * Patre Design System
 *
 * Dark-mode design system built on Josh W. Comeau's CSS Reset.
 * Styles semantic HTML directly — no CSS classes needed.
 *
 * Contents:
 *   1. Reset
 *   2. Design Tokens
 *   3. Global
 *   4. Typography
 *   5. Layout
 *   6. Navigation
 *   7. Forms
 *   8. Feedback
 *   9. Lists
 */

/* ==========================================================================
   1. RESET — Josh's Custom CSS Reset
   https://www.joshwcomeau.com/css/custom-css-reset/
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: color-mix(
    in srgb,
    var(--accent) 25%,
    transparent
  );
}

[hidden] {
  display: none !important;
}

#app-widgets > turbo-frame {
  display: block;
  border-bottom: 1px solid var(--surface-2);
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
}

#app-widgets > turbo-frame:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

*:not(dialog) {
  margin: 0;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    interpolate-size: allow-keywords;
  }
}

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  outline: none;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

p {
  text-wrap: pretty;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
}

/* ==========================================================================
   2. DESIGN TOKENS
   ========================================================================== */

:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:
    ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;

  /* Surfaces */
  --surface-0: #09090b;
  --surface-1: #111113;
  --surface-2: #27272a;
  --surface-3: #3f3f46;

  /* Text */
  --text-0: #fafafa;
  --text-1: #d4d4d8;
  --text-2: #a1a1aa;

  /* Accent — Indigo */
  --accent: #818cf8;
  --accent-hover: #a5b4fc;

  /* Feedback */
  --success: #4ade80;
  --success-subtle: #052e16;
  --danger: #f87171;
  --danger-subtle: #450a0a;
  --warning: #fbbf24;
  --warning-subtle: #422006;

  /* Sizing */
  --content-width: 56rem;
  --narrow-width: 24rem;
  --radius: 0.1875rem;
  --radius-sm: 0.1875rem;

  /* Mobile adaptive — touch targets & chrome sizing */
  /* 44px: WCAG 2.5.8 minimum touch target size for pointer inputs */
  --touch-target: 2.75rem;
  /* 48px: comfortable touch target for items with text labels (e.g. menu rows) */
  --touch-target-comfortable: 3rem;
  /* 48px: bottom nav button height — comfortable touch target with text */
  --mobile-footer-height: 3rem;
  /* Mobile header corner rounding and inset from screen edges */
  --mobile-header-radius: 0;
  --mobile-header-margin: 0rem;
  /* Bottom nav bar corner rounding and inset from screen edges */
  --mobile-footer-radius: 0.1875rem;
  --mobile-footer-margin: 0.5rem;
  --mobile-footer-gap: 0.15rem;
  /* Carousel slide animation duration */
  --carousel-duration: 200ms;

  /* Shadows — layered for depth, hue-matched to surface */
  --shadow-color: 240deg 6% 0%;
  --shadow-sm:
    0 0.5px 1px hsl(var(--shadow-color) / 0.5),
    0 1px 2px hsl(var(--shadow-color) / 0.5);
  --shadow-md:
    0 1px 1px hsl(var(--shadow-color) / 0.4),
    0 2px 2px hsl(var(--shadow-color) / 0.4),
    0 4px 4px hsl(var(--shadow-color) / 0.4);
  --shadow-lg:
    0 1px 2px hsl(var(--shadow-color) / 0.3),
    0 2px 4px hsl(var(--shadow-color) / 0.3),
    0 4px 8px hsl(var(--shadow-color) / 0.3),
    0 8px 16px hsl(var(--shadow-color) / 0.3);
}

/* ==========================================================================
   3. GLOBAL
   ========================================================================== */

html {
  color-scheme: dark;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
}

/* ==========================================================================
   4. TYPOGRAPHY
   ========================================================================== */

body {
  font-family: var(--font-sans);
  background: var(--surface-0);
  color: var(--text-0);
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
}
h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-1);
}
h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-1);
}

a {
  color: var(--accent);
  text-decoration: none;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      color: var(--accent-hover);
      text-decoration: underline;
    }
  }
}

small {
  font-size: 0.875rem;
  color: var(--text-2);
}

hr {
  border: none;
  border-top: 1px solid var(--surface-3);
  margin-block: 1.5rem;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--surface-2);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   5. LAYOUT
   ========================================================================== */

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Authenticated pages — main fills remaining space */
main {
  flex: 1;
  width: 100%;
  max-width: var(--content-width);
  margin-inline: auto;
  padding: 2rem 1.5rem;
}

/* Flow spacing within main content */
main > * + * {
  margin-block-start: 1.5rem;
}

/* Guest pages (no header) — center everything */
body:not(:has(> .desktop-header)):not(:has(> .mobile-header)) > main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  gap: 1rem;
}

body:not(:has(> .desktop-header)):not(:has(> .mobile-header)) > main > * {
  width: 100%;
  max-width: var(--narrow-width);
}

/* Article — card container */
article {
  background: var(--surface-1);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: var(--narrow-width);
  margin-inline: auto;
}

article > header {
  text-align: center;
}

article > * + * {
  margin-block-start: 1rem;
}

article > footer {
  margin-block-start: 1.5rem;
  padding-block-start: 1rem;
  border-top: 1px solid var(--surface-2);
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-2);
}

/* Sections */
section {
  margin-block-start: 2rem;
}

section > * + * {
  margin-block-start: 0.75rem;
}

section > p {
  color: var(--text-1);
}

/* ==========================================================================
   6. NAVIGATION
   ========================================================================== */

.desktop-header {
  border-bottom: 1px solid var(--surface-2);
  background: var(--surface-1);
}

.desktop-header > nav {
  position: relative;
  max-width: var(--content-width);
  margin-inline: auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Logo link */
.desktop-header nav > a {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  color: var(--text-0);
  font-weight: 600;
  font-size: 1.125rem;
  line-height: 1;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      color: var(--text-0);
      text-decoration: none;
    }
  }
}

/* Nav menu (desktop header hamburger) */
.nav-menu-btn {
  background: none;
  border: none;
  color: var(--text-1);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.nav-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  background: var(--surface-1);
  border: 1px solid var(--surface-2);
  border-radius: 0.5rem;
  min-width: 12rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 100;
  overflow: hidden;
}

.nav-menu-section {
  padding: 0.5rem;
  border-bottom: 1px solid var(--surface-2);
}

.nav-menu-section:last-child {
  border-bottom: none;
}

/* button_to inside nav-menu generates a form */
.nav-menu-section form {
  display: contents;
}

.nav-menu-section button[type="submit"],
.nav-menu-section a {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  color: var(--text-1);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  border-radius: 0.25rem;
}

.nav-menu-section button[type="submit"]:hover,
.nav-menu-section a:hover {
  background: var(--surface-2);
}

/* Hamburger menu selectors (locale, worktree picker, etc.) */
.hamburger-selector {
  display: contents;
}

.hamburger-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a1a1aa' d='M3 5l3 3 3-3'/%3E%3C/svg%3E") no-repeat right 0.5rem center;
  color: var(--text-1);
  border: 1px solid var(--surface-3, var(--surface-2));
  border-radius: 0.375rem;
  padding: 0.375rem 1.5rem 0.375rem 0.5rem;
  font-size: 0.875rem;
  width: 100%;
  cursor: pointer;
}

.hamburger-select:focus {
  outline: 2px solid var(--accent, #3b82f6);
  outline-offset: 1px;
}




/* Breadcrumbs */
.breadcrumbs {
  padding: 0.5rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-2);
  border-bottom: 1px solid var(--surface-2);
}

/* button_to generates a <form>; make it invisible to layout */
nav form {
  display: contents;
}

/* Don't constrain widget forms */
.todo-list-widget form {
  max-width: none;
}

/* Todo item row */
.todo-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0;
}

.todo-item-title {
  flex: 1;
  cursor: pointer;
}

.todo-item-title.checked {
  text-decoration: line-through;
  color: var(--text-2);
}

.todo-item input[type="text"] {
  flex: 1;
  min-width: 0;
}

/* ==========================================================================
   7. FORMS
   ========================================================================== */

form label {
  display: block;
  margin-block-start: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-1);
}

form label:first-child {
  margin-block-start: 0;
}

input:not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  padding: 0.5rem 0.75rem 0.25rem;
  background: var(--surface-2);
  border-width: 0 0 0.25rem;
  border-style: solid;
  border-color: var(--surface-3);
  border-radius: var(--radius-sm);
  color: var(--text-0);

  &::placeholder {
    color: var(--text-2);
  }
}

form input:not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
form select,
form textarea {
  display: block;
  width: 100%;
}

form select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23d4d4d8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-inline-end: 2.5rem;
}

/* Constrain forms inside wider layouts */
section > form {
  max-width: var(--narrow-width);
}

/* Buttons — shared base */
button,
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background-color 0.15s,
    color 0.15s;
}

/* Primary — form submit */
input[type="submit"] {
  margin-block-start: 1.5rem;
  width: 100%;
  background: var(--accent);
  color: #fff;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: var(--accent-hover);
      color: #1e1b4b;
    }
  }
}

/* Ghost — standalone buttons (nav, actions) */
button {
  background: var(--surface-1);
  color: var(--text-1);
  border-color: var(--surface-3);

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: var(--surface-2);
      color: var(--text-0);
    }
  }
}

/* Emoji-only action buttons (cancel, remove, move, members) */
button[data-action$="#cancel"],
button[data-action$="#remove"],
button[data-action$="#moveUp"],
button[data-action$="#moveDown"],
.btn-link {
  border: none;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  color: inherit;
  transition: background-color 0.15s;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      background: var(--surface-2);
      color: inherit;
      text-decoration: none;
    }
  }
}

/* App installer form row */
[data-app-installer-target="form"] {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  & input {
    flex: 1;
    min-width: 0;
  }
}

/* Widget actions row (wraps title + engine actions) */
[data-controller="todo-widget"],
.notes-widget > .widget-title-row,
[data-controller="joint-costs-widget"] {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Mobile-only "New note" button — hidden on desktop */
.mobile-new-note-btn {
  display: none;
}

/* Editable widget title row */
[data-controller="widget-title"] {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  overflow-x: auto;

  & h3 {
    flex: 1;
  }

  & input {
    flex: 1;
    min-width: 10rem;
  }
}

/* Group title row */
[data-controller="group-title"],
.group-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  & h1 {
    flex: 1;
  }

  & input {
    flex: 1;
    min-width: 0;
  }
}

/* ==========================================================================
   8. FEEDBACK — Flash Messages
   ========================================================================== */

[role="alert"] {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--danger-subtle);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}

[role="status"] {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--success-subtle);
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 25%, transparent);
}

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  text-align: center;
}

.offline-banner--danger {
  background: var(--danger-subtle);
  color: var(--danger);
  border-bottom: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}

.offline-banner--syncing {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  animation: offline-pulse 1.5s ease-in-out infinite;
}

@keyframes offline-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.offline-banner--success {
  background: var(--success-subtle);
  color: var(--success);
  border-bottom: 1px solid color-mix(in srgb, var(--success) 25%, transparent);
}

[data-offline] {
  padding-top: 2rem;
}

[data-offline] form:not([data-offline-capable]) {
  pointer-events: none;
  opacity: 0.5;
}

[data-offline] [data-offline-disable] {
  pointer-events: none;
  opacity: 0.5;
}

/* ==========================================================================
   9. LISTS
   ========================================================================== */

ul,
ol {
  padding-inline-start: 0;
  list-style: none;
}

ul > li,
ol > li {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--surface-2);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

ul > li:last-child,
ol > li:last-child {
  border-bottom: none;
}

/* ==========================================================================
   10. ADAPTIVE — Mobile
   ========================================================================== */

/* --- Mobile chrome (hidden on desktop, shown on mobile) --- */

.mobile-header {
  display: none;
}

.bottom-nav {
  display: none;
}

.hamburger-menu {
  display: none;
}

/* ==========================================================================
   7. BOTTOM SHEET
   ========================================================================== */

.bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 20;
  transition: background 300ms ease;
}

.bottom-sheet--open .bottom-sheet-backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.bottom-sheet-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface-1);
  border-top: 1px solid var(--surface-2);
  border-radius: 0.75rem 0.75rem 0 0;
  box-shadow: var(--shadow-lg);
  z-index: 21;
  transform: translateY(100%);
  transition: transform 300ms ease;
  max-height: 70dvh;
  overflow-y: auto;
}

.bottom-sheet--open .bottom-sheet-panel {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 2.5rem;
  height: 0.25rem;
  background: var(--surface-3);
  border-radius: 2px;
  margin: 0.75rem auto 0.25rem;
}

.bottom-sheet-content button,
.bottom-sheet-content input[type="submit"] {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: var(--touch-target-comfortable);
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--surface-2);
  color: var(--text-0);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}

.bottom-sheet-content button:last-child,
.bottom-sheet-content form:last-child input[type="submit"] {
  border-bottom: none;
}

.bottom-sheet-content button:active,
.bottom-sheet-content input[type="submit"]:active {
  background: var(--surface-2);
}

.bottom-sheet-danger {
  color: var(--danger);
}

.bottom-sheet-app-actions:empty {
  display: none;
}

.bottom-sheet-app-actions {
  border-bottom: 1px solid var(--surface-2);
}

.bottom-sheet-app-actions form {
  display: contents;
}

@media (max-width: 639px) {
  /*
   * Mobile layout uses CSS Grid for robust viewport containment.
   *
   *   body (grid, 100dvh)
   *     <header .mobile-header>   — auto row
   *     <main>                    — 1fr row (only this scrolls)
   *     <footer .bottom-nav>      — auto row
   *
   * Grid with explicit row templates guarantees header/main/footer
   * never exceed 100dvh regardless of content height. No overflow
   * restriction on body needed, which preserves pull-to-refresh.
   *
   * Applied on all pages — the mobile-header (hamburger) is always
   * rendered so every page gets the grid layout on mobile.
   */

  body:has(.mobile-header) {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100dvh;
    min-height: 0;
  }

  main {
    position: relative;
    overflow-y: auto;
    /* Hide the scrollbar for a cleaner native-app feel.
     * Content remains scrollable via touch. */
    scrollbar-width: none;
    padding: 0 1rem 1rem;
    min-height: 0;
  }

  main > * + * {
    margin-block-start: 0.75rem;
  }

  /* Pull-to-refresh indicator (iOS only — injected by pull_refresh controller) */
  .pull-refresh-indicator {
    position: absolute;
    top: -2.5rem;
    left: 50%;
    translate: -50% 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--text-2);
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
    z-index: 1;
  }

  .pull-refresh-indicator.pull-refresh-ready {
    color: var(--text-0);
  }

  @keyframes pull-refresh-spin {
    to { rotate: 360deg; }
  }

  .pull-refresh-indicator.pull-refresh-loading {
    animation: pull-refresh-spin 0.6s linear infinite;
  }

  /* Remove top margin on carousel and widget sections so app content
   * starts immediately below the header. */
  #app-widgets,
  .app-widget {
    margin-block-start: 0;
  }

  /* --- Hide desktop chrome on mobile --- */

  /* Desktop header — hidden when mobile header is present.
   * Pages without group context (index, members) keep the desktop header. */
  body:has(.mobile-header) > .desktop-header {
    display: none;
  }

  .breadcrumbs {
    display: none;
  }

  /* Desktop group management — moved to hamburger menu */
  [data-controller="group-title"],
  .group-title-row,
  [data-controller="app-installer"] {
    display: none;
  }

  /* Show app-installer when activated from hamburger menu */
  [data-controller="app-installer"].app-installer-active {
    display: block;
  }

  /* Widget reorder/delete controls — moved to FAB */
  [data-widget-title-target="moveUp"],
  [data-widget-title-target="moveDown"],
  [data-widget-title-target="delete"] {
    display: none;
  }

  /* Widget title row — hidden on mobile, title is shown in the footer instead.
   * Targets both the editable row with actions (managers) and the plain h3 (guests). */
  [data-controller="todo-widget"],
  .notes-widget > .widget-title-row,
  [data-controller="joint-costs-widget"],
  #app-widgets h3[id$="_title"] {
    display: none;
  }

  /* Mobile "New note" button at top of notes widget */
  .mobile-new-note-btn {
    display: block;
    width: 100%;
    margin-bottom: 0.75rem;
  }

  /* Desktop-only in-widget buttons — on mobile these move to the FAB */
  .joint-costs-clear-btn {
    display: none;
  }

  /* Disable tap highlight entirely on mobile for a native-app feel */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* --- Mobile header (<header> element, flex sibling of main) --- */

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--touch-target-comfortable);
    padding: 0.5rem 1rem;
    margin: var(--mobile-header-margin) var(--mobile-header-margin) 0;
    background: transparent;
    border: none;
    border-radius: var(--mobile-header-radius);
    /* Anchors the hamburger dropdown menu */
    position: relative;
    z-index: 20;
  }

  .mobile-header a {
    color: var(--text-0);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .mobile-header .mobile-back {
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
  }

  .mobile-header .mobile-group-name {
    flex: 1;
    font-weight: 600;
    font-size: 1.125rem;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header .hamburger-btn {
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-0);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
  }

  /* --- Bottom nav (<footer> element, flex sibling of main) --- */

  .bottom-nav {
    display: flex;
    align-items: end;
    gap: var(--mobile-footer-gap);
    padding: 0;
    margin: 0 var(--mobile-footer-margin) var(--mobile-footer-margin);
    background: transparent;
    border: none;
    border-radius: 0;
  }

  .bottom-nav > button {
    min-width: var(--touch-target);
    height: var(--mobile-footer-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-1);
    border: 1px solid var(--surface-2);
    box-shadow: var(--shadow-sm);
    color: var(--text-1);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
  }

  .bottom-nav > button[data-carousel-action="prev"] {
    border-radius: var(--radius) 0 0 var(--radius);
  }

  .bottom-nav > button[data-carousel-action="next"] {
    border-radius: 0 var(--radius) var(--radius) 0;
  }

  .bottom-nav .bottom-nav-center-wrapper {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .bottom-nav .bottom-sheet-handle {
    box-sizing: content-box;
    background-clip: content-box;
    margin-top: -1.5rem;
    cursor: grab;
  }

  .bottom-nav .bottom-nav-center {
    width: 100%;
    height: var(--mobile-footer-height);
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Reset button styles */
    background: var(--surface-1);
    border: 1px solid var(--surface-2);
    border-radius: 0;
    box-shadow: var(--shadow-sm);
    color: inherit;
    font: inherit;
    padding: 0.125rem 0.5rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav .bottom-nav-title {
    display: block;
    max-width: 100%;
    font-weight: 500;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* Ensure text clips within the button even though button is overflow:visible */
    align-self: stretch;
  }

  .bottom-nav .bottom-nav-position {
    display: block;
    font-size: 0.75rem;
    color: var(--text-2);
  }

  /* --- Hamburger dropdown menu --- */

  .hamburger-menu {
    /* Override base display: none when hidden is removed.
     * When hidden is present, [hidden] { display: none !important } wins. */
    display: block;
    position: absolute;
    top: 100%;
    right: 0.5rem;
    background: var(--surface-1);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    box-shadow:
      0 4px 12px rgba(0, 0, 0, 0.3),
      0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 20;
    min-width: 200px;
    overflow: hidden;
  }

  .hamburger-menu a,
  .hamburger-menu button {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: var(--touch-target-comfortable);
    padding: 0.75rem 1rem;
    color: var(--text-0);
    font-size: 0.875rem;
    text-decoration: none;
    border: none;
    border-bottom: 1px solid var(--surface-2);
    background: none;
    text-align: left;
    cursor: pointer;
  }

  .hamburger-menu a:last-child,
  .hamburger-menu button:last-child {
    border-bottom: none;
  }

  .hamburger-menu a:active,
  .hamburger-menu button:active {
    background: var(--surface-2);
  }

  .hamburger-menu-divider {
    border-top: 1px solid var(--surface-2);
    margin: 0.25rem 0;
  }

  .hamburger-menu .hamburger-selector {
    display: block;
    padding: 0.5rem 1rem;
  }

  .hamburger-menu .hamburger-select {
    width: 100%;
  }

  /* --- Carousel: single-app view with slide animation --- */

  /* Before carousel JS activates, only show the first widget to prevent
   * content from overflowing the grid row and causing body scroll.
   * Once the carousel controller adds .carousel-active, it takes over
   * visibility management via the hidden attribute. */
  #app-widgets:not(.carousel-active) > turbo-frame:not(:first-child) {
    display: none;
  }

  #app-widgets {
    position: relative;
    overflow: hidden;
  }

  #app-widgets > turbo-frame {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
    /* Slide animation for carousel transitions */
    transition:
      opacity var(--carousel-duration) ease-out,
      transform var(--carousel-duration) ease-out;
  }

  #app-widgets > turbo-frame[hidden] {
    display: none !important;
  }

  /* During animation, the outgoing widget is taken out of flow so it
   * doesn't affect container height. The incoming widget sizes the
   * container immediately, preventing a height snap at the end. */
  #app-widgets > turbo-frame.slide-exiting {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
  }

  #app-widgets > turbo-frame.slide-out-left {
    opacity: 0;
    transform: translateX(-30%);
  }

  #app-widgets > turbo-frame.slide-out-right {
    opacity: 0;
    transform: translateX(30%);
  }

  #app-widgets > turbo-frame.slide-in-left {
    opacity: 0;
    transform: translateX(-30%);
  }

  #app-widgets > turbo-frame.slide-in-right {
    opacity: 0;
    transform: translateX(30%);
  }
}

/* Chrome, Safari, Edge — hide scrollbar on main content area.
 * Declared outside @media so the pseudo-element selector isn't
 * nested inside a media query, which some WebKit versions ignore
 * for vendor-prefixed pseudo-elements. The scrollbar-width: none
 * above handles Firefox. */
@media (max-width: 639px) {
  main::-webkit-scrollbar {
    display: none;
  }
}

/* ==========================================================================
   HOTWIRE NATIVE — Hide web-only chrome when running inside a native shell.
   The body.hotwire-native class is set server-side via hotwire_native_app?.
   ========================================================================== */

body.hotwire-native .desktop-header,
body.hotwire-native .breadcrumbs {
  display: none !important;
}

/* In native, the mobile-header only provides the hamburger menu.
   The native nav bar handles back navigation and the group name title. */
body.hotwire-native .mobile-header .mobile-back,
body.hotwire-native .mobile-header .mobile-group-name {
  display: none !important;
}

body.hotwire-native .mobile-header {
  justify-content: flex-end;
  min-height: 0;
  padding: 0 0.5rem;
}



