/**
 * Mobile & touch UX — completely redesigned for phone-first everyday use
 * Loaded by: public/index.html
 */

/* ─────────────────────────────────────────────────
   1. GLOBAL MOBILE BASE
   ───────────────────────────────────────────────── */

/* No global overflow-x on .main-app — overflow-x: clip computes overflow-y: clip
   per the CSS spec, which clips padding-bottom and breaks bottom-nav clearance. */
.main-app {
  min-width: 0;
}

/* Prevent horizontal overflow on mobile using body (not html, to keep body
   as the scroll container so body padding-bottom controls scroll extent). */
@media (max-width: 840px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
  }

  body {
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Global overflow containment for all containers */
  .screen,
  .card,
  .form-stack,
  .form-grid {
    min-width: 0;
    max-width: 100%;
  }

  /* Ensure all inline content wraps */
  h1, h2, h3, h4, p, span, strong, em, label {
    overflow-wrap: break-word;
    word-break: break-word;
  }

  /* Smooth momentum scrolling everywhere */
  * {
    -webkit-overflow-scrolling: touch;
  }
}

/* ─────────────────────────────────────────────────
   2. SAFE AREAS (notched phones)
   ───────────────────────────────────────────────── */

/* Desktop safe areas */
@media (min-width: 841px) {
  @supports (padding: max(0px)) {
    .main-app {
      padding-left: max(28px, env(safe-area-inset-left));
      padding-right: max(28px, env(safe-area-inset-right));
      padding-bottom: max(32px, env(safe-area-inset-bottom));
    }
  }
}

/* Mobile safe areas — notched phones. Use max() to ensure a minimum
   that covers the safe area inset PLUS our layout needs. */
@media (max-width: 840px) {
  @supports (padding: max(0px)) {
    body {
      padding-bottom: max(78px, calc(70px + env(safe-area-inset-bottom)));
    }

    .main-app {
      padding-left: max(16px, env(safe-area-inset-left));
      padding-right: max(16px, env(safe-area-inset-right));
      padding-bottom: max(78px, calc(70px + env(safe-area-inset-bottom)));
    }

    .bottom-nav {
      padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .toast {
      bottom: max(86px, calc(70px + env(safe-area-inset-bottom) + 10px));
    }
  }
}

/* ─────────────────────────────────────────────────
   3. BOTTOM NAVIGATION — premium glass tab bar
   ───────────────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  gap: 0;
  padding: 8px 6px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.05);
}

/* New icon-based tab buttons */
.bottom-nav__btn {
  flex: 1;
  min-height: 54px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 2px;
  border-radius: 12px;
  color: #aaa;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: color 160ms ease, transform 100ms ease;
}

.bottom-nav__btn:active {
  transform: scale(0.9);
  transition: transform 60ms ease;
}

.bottom-nav__btn.is-active {
  color: var(--accent, #ff5a3d);
}

.bottom-nav__icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background 160ms ease, transform 160ms ease;
}

.bottom-nav__btn.is-active .bottom-nav__icon {
  background: rgba(255, 90, 61, 0.12);
  transform: scale(1.05);
}

.bottom-nav__icon svg {
  width: 22px;
  height: 22px;
  display: block;
}

.bottom-nav__label {
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
}

/* Fallback for legacy plain-text buttons (safety) */
.bottom-nav > button:not(.bottom-nav__btn) {
  flex: 1;
  min-height: 52px;
  border: none;
  background: transparent;
  color: #9a9a9a;
  font-size: 10px;
  font-weight: 600;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav > button:not(.bottom-nav__btn).is-active {
  color: var(--accent, #ff5a3d);
}

/* Pad content above bottom nav.
   body gets padding-bottom as the scroll container (guaranteed to work).
   .main-app gets it too so inline padding flow is also correct. */
@media (max-width: 840px) {
  body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .main-app {
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }
}

/* ─────────────────────────────────────────────────
   4. SIDEBAR DRAWER
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* Sidebar is a fixed overlay — takes no grid space */
  .app-shell,
  .app-shell.is-sidebar-collapsed {
    --sidebar-w: 0px;
  }

  /* Convert sticky sidebar to a fixed drawer */
  .sidebar,
  .sidebar.is-collapsed {
    position: fixed;
    top: 0;
    /* Stop above the bottom nav so the logout button stays visible */
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    height: auto;
    width: min(300px, calc(100vw - 48px));
    left: calc(-1 * min(300px, calc(100vw - 48px)) - 8px);
    box-shadow: none;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 21;
    border-radius: 0 20px 20px 0;
    transition: left 300ms cubic-bezier(0.32, 0.72, 0, 1), box-shadow 300ms ease;
  }

  .sidebar.is-open {
    left: 0;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.24);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 19;
    border: none;
    padding: 0;
    margin: 0;
    background: rgba(14, 24, 40, 0.48);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 260ms ease, visibility 260ms ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-backdrop.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.sidebar-menu-open {
    overflow: hidden;
    touch-action: none;
  }

  /* Bigger touch targets for sidebar nav items */
  .nav-btn {
    min-height: 48px;
  }

  /* Never use desktop collapsed rail on small screens */
  .sidebar.is-collapsed .brand-copy {
    display: block;
    opacity: 1;
    max-width: 200px;
    pointer-events: auto;
  }

  .sidebar.is-collapsed .brand-wrap {
    grid-template-columns: 52px 1fr;
    justify-items: stretch;
    padding: 10px 10px 10px 8px;
  }

  .sidebar.is-collapsed .brand-logo {
    width: 52px;
    height: 52px;
  }

  .sidebar.is-collapsed .nav-btn {
    justify-content: flex-start;
    padding: 0 11px;
  }

  .sidebar.is-collapsed .nav-btn::before {
    left: 0;
    top: 50%;
    bottom: auto;
    width: 3px;
    height: 0;
    transform: translateY(-50%);
  }

  .sidebar.is-collapsed .nav-btn.is-active::before {
    width: 3px;
    height: 22px;
  }
}

/* ─────────────────────────────────────────────────
   5. TOPBAR — compact single-row header
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* Only set top/left/right — bottom padding is controlled by bottom-nav section */
  .main-app {
    padding-top: 12px;
    padding-left: 16px;
    padding-right: 16px;
  }

  /* Topbar on mobile: scrolls with content, premium floating feel */
  .topbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 10px 14px;
    min-height: 54px;
    margin-bottom: 18px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
    border: 0.5px solid rgba(0, 0, 0, 0.04);
  }

  .menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 42px;
    height: 42px;
    min-height: 42px;
    flex-shrink: 0;
    border: 1.5px solid #e4e0db;
    border-radius: 12px;
    background: #fff;
    gap: 4px;
    padding: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 80ms ease, background 100ms ease;
  }

  .menu-btn:active {
    background: #f5f3f0;
    transform: scale(0.93);
  }

  .menu-btn span {
    width: 16px;
    height: 2px;
    background: #1a1a1a;
    display: block;
    border-radius: 1px;
  }

  /* Title: shrink and truncate */
  .topbar-heading {
    flex: 1;
    min-width: 0;
  }

  .topbar-title {
    font-size: clamp(1rem, 5vw, 1.3rem);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Actions: inline row, no wrapping — overrides styles.css 480px column rule */
  .topbar-actions {
    display: flex;
    flex-direction: row !important;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: 0;
    width: auto !important;
    flex-wrap: nowrap !important;
  }

  /* Reset the "every child = full width" rule from styles.css */
  .topbar-actions > * {
    width: auto !important;
    justify-content: initial;
  }

  /* Hide verbose utility buttons on mobile — logout moved to sidebar */
  #openUserGuideBtn,
  #refreshDataBtn,
  #logoutBtn {
    display: none !important;
  }

  /* Sign in link — compact */
  #signInLink {
    font-size: 13px;
    padding: 0 12px;
    min-height: 36px;
  }

  /* User panel: avatar + short name only */
  .user-panel {
    padding: 4px 8px 4px 4px;
    gap: 7px;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 160px;
  }

  .user-meta .user-display-name {
    font-size: 12px;
    max-width: 80px;
  }

  .user-meta span:last-child {
    font-size: 10px;
  }
}

@media (max-width: 420px) {
  .topbar-title {
    font-size: 1rem;
  }

  /* On very small screens: show avatar only, no name */
  .user-meta {
    display: none !important;
  }

  .user-panel {
    padding: 3px;
    border-radius: 50%;
    border-color: transparent;
    box-shadow: none;
    background: transparent;
    max-width: none;
    gap: 0;
  }

  .user-profile-avatar {
    width: 34px;
    height: 34px;
  }

  .user-profile-avatar svg {
    width: 18px;
    height: 18px;
  }
}

/* ─────────────────────────────────────────────────
   5b. FONT & ELEMENT SIZE OPTIMISATION
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* Topbar title smaller */
  .topbar-title {
    font-size: clamp(0.95rem, 4.5vw, 1.2rem);
  }

  /* Screen headers */
  .screen-head h2 {
    font-size: clamp(1.2rem, 4.5vw, 1.55rem);
  }

  /* Labels: stay at 13px, not 14px */
  label {
    font-size: 13px;
    gap: 7px;
  }

  /* Card headings */
  .card h3 {
    font-size: 0.95rem;
  }

  /* KPI numbers — smaller on mobile */
  .kpi-grid strong {
    font-size: 20px;
    margin-top: 4px;
  }

  .kpi-grid span {
    font-size: 11px;
  }

  /* Analytics KPI numbers */
  .analytics-kpi strong {
    font-size: 22px;
  }

  .analytics-kpi span {
    font-size: 10px;
  }

  /* muted line text */
  .muted-line {
    font-size: 12px;
    line-height: 1.4;
  }

  /* Table cells: compact */
  th, td {
    padding: 10px 8px;
    font-size: 13px;
  }

  th {
    font-size: 11px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  /* Screen eyebrow */
  .screen-eyebrow {
    font-size: 10px;
  }

  /* Event tag */
  .event-tag {
    font-size: 10px;
    padding: 3px 8px;
  }

  /* Buttons: premium mobile feel */
  .ghost-btn,
  .dark-btn,
  .accent-btn,
  .danger-btn {
    font-size: 14px;
    padding: 0 16px;
    min-height: 46px;
    border-radius: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: transform 100ms ease, opacity 100ms ease, box-shadow 100ms ease;
  }

  .dark-btn {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  .accent-btn {
    box-shadow: 0 2px 8px rgba(255, 90, 61, 0.2);
  }

  /* Wide buttons on mobile */
  .dark-btn.wide,
  .accent-btn.wide,
  .ghost-btn.wide {
    min-height: 52px;
    font-size: 15px;
    border-radius: 14px;
    font-weight: 700;
  }

  /* Small buttons */
  .ghost-btn.small,
  .dark-btn.small {
    font-size: 12px;
    padding: 0 12px;
    min-height: 38px;
    border-radius: 10px;
  }
}

/* ─────────────────────────────────────────────────
   6. GENERAL LAYOUT & GRID COLLAPSES
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  .form-grid,
  .kpi-grid,
  .kpi-grid--five,
  .analytics-kpi-grid,
  .analytics-kpi-grid--biz,
  .analytics-kpi-grid--future,
  .analytics-charts-grid,
  .analytics-tables-grid,
  .track-grid,
  .admin-tools-grid,
  .details-grid {
    grid-template-columns: 1fr;
  }

  .analytics-kpi--top {
    grid-column: auto;
  }

  .admin-panel-hint {
    min-height: 0;
  }

  .admin-panel-actions--split {
    flex-direction: column;
  }

  .admin-panel-actions--split .dark-btn,
  .admin-panel-actions--split .danger-btn {
    flex: 1 1 auto;
    width: 100%;
  }

  /* Screen heads */
  .screen-head {
    margin-bottom: 20px;
    padding-bottom: 14px;
  }

  /* Cards: premium rounded with subtle shadow */
  .card {
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.04);
    overflow: hidden;
  }

  /* Card padding: comfortable */
  .card {
    padding: 18px;
  }
}

/* ─────────────────────────────────────────────────
   7. FORMS — premium mobile feel
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* Prevents iOS Safari zoom on focus */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea,
  .money-input,
  .event-picker-search,
  .tracking-search-input {
    font-size: 16px !important;
    -webkit-text-size-adjust: 100%;
  }

  /* Premium input styling */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not(.money-input),
  select {
    min-height: 50px;
    border-radius: 12px;
    padding: 0 16px;
    border: 1.5px solid #e4e0db;
    background: #fefefe;
    transition: border-color 180ms ease, box-shadow 180ms ease;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not(.money-input):focus,
  select:focus,
  textarea:focus {
    border-color: #ff8a6e;
    box-shadow: 0 0 0 3px rgba(255, 90, 61, 0.1);
    outline: none;
  }

  .money-input {
    min-height: 50px;
    font-size: 16px !important;
  }

  .money-input-wrap {
    border-radius: 12px;
    border-width: 1.5px;
    border-color: #e4e0db;
    transition: border-color 180ms ease, box-shadow 180ms ease;
  }

  .money-input-wrap:focus-within {
    border-color: #ff8a6e;
    box-shadow: 0 0 0 3px rgba(255, 90, 61, 0.1);
  }

  textarea {
    min-height: 100px;
    border-radius: 12px;
    padding: 14px 16px;
    border: 1.5px solid #e4e0db;
    background: #fefefe;
    line-height: 1.5;
    transition: border-color 180ms ease, box-shadow 180ms ease;
  }

  /* Select arrow bigger on mobile */
  select {
    background-size: 18px;
    background-position: right 14px center;
    padding-right: 44px;
  }

  /* Labels: slightly bolder, more spacing */
  label {
    gap: 8px;
    font-size: 13px;
    font-weight: 650;
    color: #2a2520;
  }

  /* Form stack: more breathing room */
  .form-stack {
    gap: 20px;
  }

  .form-grid {
    gap: 20px 16px;
  }

  /* Form actions: primary CTA full-width, stacked */
  .form-actions:not(.dialog-actions) {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .form-actions:not(.dialog-actions) > * {
    width: 100%;
    text-align: center;
    justify-content: center;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-weight: 650;
  }

  /* Keep dialog action buttons as a row */
  .dialog-actions {
    flex-direction: row;
    justify-content: space-between;
    gap: 10px;
  }

  .dialog-actions > * {
    flex: 1;
    min-height: 48px;
    border-radius: 12px;
  }

  /* Multi-picker: bigger trigger */
  .multi-picker-trigger {
    min-height: 50px;
    font-size: 16px;
    border-radius: 12px;
    border-width: 1.5px;
    border-color: #e4e0db;
    transition: border-color 180ms ease, box-shadow 180ms ease;
  }

  .multi-picker.is-open .multi-picker-trigger {
    border-color: #ff8a6e;
    box-shadow: 0 0 0 3px rgba(255, 90, 61, 0.1);
  }

  .multi-picker-menu {
    border-radius: 14px;
    padding: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.14);
    border: 1px solid #ebe6df;
  }

  .multi-picker-option {
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 15px;
  }

  .multi-picker-option input {
    width: 20px;
    height: 20px;
  }
}

/* ─────────────────────────────────────────────────
   8. MODALS → BOTTOM SHEETS (premium mobile feel)
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  .toast {
    left: 16px;
    right: 16px;
    min-width: 0;
    max-width: none;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    border-radius: 14px;
    padding: 14px 18px;
    font-size: 14px;
    font-weight: 550;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  }

  .overlay {
    padding: 0;
    align-items: flex-end;
    overscroll-behavior: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .modal,
  .dialog-card {
    width: 100%;
    max-height: min(92dvh, 920px);
    padding: 0 20px calc(24px + env(safe-area-inset-bottom, 0px));
    padding-top: 0;
    border-radius: 24px 24px 0 0;
    gap: 18px;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.12);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* Drag handle */
  .modal::before,
  .dialog-card::before {
    content: "";
    display: block;
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: #d5d0ca;
    margin: 14px auto 8px;
    flex-shrink: 0;
  }

  .modal.party-edit-modal,
  .dialog-card.party-edit-modal {
    width: 100%;
    max-height: 96dvh;
    border-radius: 24px 24px 0 0;
  }

  /* Ensure modal content doesn't overflow */
  .modal *,
  .dialog-card * {
    max-width: 100%;
    min-width: 0;
  }
}

/* ─────────────────────────────────────────────────
   9. DASHBOARD — clean mobile-first layout
      (desktop keeps the full cork-board aesthetic)
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* ── Canvas: replace heavy cork board with a light clean surface ── */
  .dashboard-screen {
    margin: -12px -14px 0;
    padding: 16px 14px 20px;
    min-height: 0; /* Don't force vh height — let content flow */
    background: linear-gradient(160deg, #fdf9f6 0%, #f4ede6 100%) !important;
    background-image: none !important; /* Remove cork noise texture */
    border-radius: 0;
  }

  /* Remove blobs and decorative emojis — too distracting on small screens */
  .dashboard-decor {
    display: none;
  }

  .dashboard-moodboard {
    max-width: none;
  }

  /* ── Header: compact, no scribble underline taking up space ── */
  [data-panel="dashboard"] .dashboard-head {
    margin-bottom: 1.25rem;
  }

  [data-panel="dashboard"] .dashboard-head__title {
    font-size: clamp(1.35rem, 5.5vw, 1.65rem);
  }

  [data-panel="dashboard"] .dashboard-head__scribble {
    width: min(130px, 55%);
    height: 10px;
  }

  [data-panel="dashboard"] .dashboard-head p {
    font-size: 0.85rem;
    max-width: none;
  }

  [data-panel="dashboard"] .dashboard-sticker {
    font-size: 0.72rem;
    padding: 0.2rem 0.65rem;
    margin-bottom: 0.35rem;
  }

  /* ── KPI sticky notes → clean flat colored tiles ── */
  [data-panel="dashboard"] .studio-notes-grid {
    gap: 0.75rem 0.65rem;
    margin-bottom: 1.25rem;
  }

  [data-panel="dashboard"] .kpi-grid--five {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  [data-panel="dashboard"] .studio-note {
    /* Remove sticky note effect: no pin, no rotation, no heavy shadow */
    transform: none !important;
    border-radius: 14px !important;
    padding: 12px 12px 10px !important;
    padding-top: 12px !important; /* Remove extra space for pin */
    box-shadow: 0 2px 8px rgba(42, 36, 32, 0.07) !important;
    border: 1px solid rgba(42, 36, 32, 0.07);
  }

  [data-panel="dashboard"] .studio-note:hover {
    transform: none !important;
    box-shadow: 0 4px 14px rgba(42, 36, 32, 0.1) !important;
  }

  /* Remove the push pin */
  [data-panel="dashboard"] .studio-note::before {
    display: none !important;
  }

  /* Compact KPI number */
  [data-panel="dashboard"] .studio-note strong {
    font-size: clamp(1.3rem, 5.5vw, 1.7rem);
    margin-top: 0.1rem;
  }

  [data-panel="dashboard"] .studio-note span {
    font-size: 0.65rem;
  }

  [data-panel="dashboard"] .studio-note .kpi-hint,
  [data-panel="dashboard"] .studio-note em {
    font-size: 0.65rem;
    margin-top: 0.2rem;
  }

  /* ── Volunteer KPIs: 2-col ── */
  [data-panel="dashboard"] .volunteer-kpi-grid.studio-notes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* ── Volunteer welcome banner: clean card ── */
  [data-panel="dashboard"] .studio-banner {
    transform: none !important;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-soft);
    padding: 14px 16px;
  }

  [data-panel="dashboard"] .volunteer-dash-intro h3 {
    font-size: 1.15rem;
  }

  /* ── Clipboard table cards: clean white cards, no decoration ── */
  [data-panel="dashboard"] .studio-clipboard {
    transform: none !important;
    border: 1px solid var(--line) !important;
    border-radius: 14px !important;
    padding-top: 14px !important;
    box-shadow: var(--shadow-soft) !important;
    background: #fff !important;
    background-image: none !important; /* Remove ruled lines */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  [data-panel="dashboard"] .studio-clipboard .card-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  [data-panel="dashboard"] .studio-clipboard .card-head .ghost-btn.small {
    min-height: 38px;
  }

  /* Hide the metal clipboard clip */
  [data-panel="dashboard"] .studio-clip {
    display: none;
  }

  /* Table: compact but scrollable */
  [data-panel="dashboard"] .studio-clipboard table {
    min-width: 400px;
  }

  [data-panel="dashboard"] .studio-clipboard th {
    font-size: 10px;
    padding: 6px 6px;
  }

  [data-panel="dashboard"] .studio-clipboard td {
    font-size: 12px;
    padding: 7px 6px;
  }

  /* Remove washi tape decorations on dashboard cards */
  [data-panel="dashboard"] .card--taped::before,
  [data-panel="dashboard"] .card--taped::after {
    display: none;
  }

  /* ── Volunteer panels: stack vertically ── */
  [data-panel="dashboard"] .volunteer-dash-panels {
    grid-template-columns: 1fr;
  }

  /* ── Sales bento: 2-col ── */
  [data-panel="dashboard"] .studio-bento {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  [data-panel="dashboard"] .studio-bento .studio-note--featured {
    grid-column: span 2;
  }

  [data-panel="dashboard"] .studio-bento .studio-note--featured strong {
    font-size: clamp(1.5rem, 5vw, 1.9rem);
  }
}

@media (max-width: 400px) {
  [data-panel="dashboard"] .kpi-grid--five {
    grid-template-columns: 1fr;
  }

  [data-panel="dashboard"] .volunteer-kpi-grid.studio-notes-grid {
    grid-template-columns: 1fr;
  }
}

/* ─────────────────────────────────────────────────
   10. EVENTS SCREEN
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* Mode bar: horizontal scroller (pill tabs) */
  [data-panel="parties"] .events-mode-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    padding: 6px;
    gap: 6px;
    background: #f7f5f2;
    border-radius: 14px;
    /* Fade out at right edge to hint scroll */
    mask-image: linear-gradient(to right, #000 88%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent 100%);
  }

  [data-panel="parties"] .events-mode-bar::-webkit-scrollbar {
    display: none;
  }

  [data-panel="parties"] .events-mode-btn {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-width: max-content;
    min-height: 42px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    transition: background 140ms ease, color 140ms ease, transform 80ms ease;
  }

  [data-panel="parties"] .events-mode-btn:active {
    transform: scale(0.95);
  }

  /* History toolbar: single column */
  [data-panel="parties"] .events-history-toolbar {
    grid-template-columns: 1fr;
    padding: 14px;
    gap: 12px;
  }

  /* Tag chips: premium touch targets */
  .event-tag-chip {
    min-height: 42px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 550;
    border-radius: 12px;
    transition: transform 80ms ease, background 140ms ease;
  }

  /* Event cards: single column with refined spacing */
  .parties-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  /* Card action buttons */
  .party-box__foot {
    justify-content: stretch;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid #f0ebe5;
  }

  .party-box__view,
  .party-box__edit {
    flex: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
  }

  /* Washi tape: skip on mobile */
  [data-panel="parties"] .card--taped::before,
  [data-panel="parties"] .card--taped::after {
    display: none;
  }

  /* Create form padding */
  [data-panel="parties"] .parties-plan-card {
    padding: 16px;
  }

  /* After-party picker */
  .event-picker-list {
    max-height: min(300px, 42vh);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    padding: 4px;
  }

  .event-picker-item {
    border-radius: 14px;
    padding: 16px;
    border-width: 1.5px;
    transition: transform 80ms ease, border-color 140ms ease, background 140ms ease;
  }

  .event-picker-item.is-selected {
    border-color: #ff8a6e;
    background: #fff8f6;
    box-shadow: 0 0 0 3px rgba(255, 90, 61, 0.08);
  }

  .event-picker-search {
    min-height: 50px;
    border-radius: 12px;
    border: 1.5px solid #e4e0db;
    padding: 0 16px;
    transition: border-color 180ms ease, box-shadow 180ms ease;
  }

  .event-picker-search:focus {
    border-color: #ff8a6e;
    box-shadow: 0 0 0 3px rgba(255, 90, 61, 0.1);
    outline: none;
  }

  .event-picker-toolbar {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .after-party-meta {
    grid-template-columns: 1fr;
  }
}

/* ─────────────────────────────────────────────────
   11. TRACK EVENT — the critical daily workflow
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* Track event picker: scrollable list */
  .track-event-list {
    max-height: 260px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    gap: 10px;
    padding: 4px;
  }

  /* Larger event options for thumb taps */
  .track-event-list .event-picker-item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 16px 18px;
    min-height: 0;
    border-radius: 14px;
    overflow: hidden;
    border-width: 1.5px;
    transition: transform 80ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
  }

  .track-event-list .event-picker-item.is-selected {
    border-color: #ff8a6e;
    background: #fff8f6;
    box-shadow: 0 0 0 3px rgba(255, 90, 61, 0.08);
  }

  .track-event-list .event-picker-item__main {
    min-width: 0;
    width: 100%;
  }

  .track-event-list .event-picker-item__main strong {
    font-size: 15px;
    font-weight: 650;
    display: block;
    line-height: 1.3;
  }

  .track-event-list .event-picker-item__main .muted-line {
    font-size: 13px;
    line-height: 1.4;
  }

  .track-event-list .event-picker-item .event-tag {
    align-self: flex-start;
    max-width: 100%;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
  }

  .track-event-option {
    padding: 16px 18px;
    min-height: 0;
    border-radius: 14px;
    border-width: 1.5px;
  }

  /* Track workspace: stack all cards */
  .track-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  /* ─── CHECK-IN / CHECK-OUT: prominent and tactile ─── */
  #trackCheckinCard .cta-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 18px 0;
  }

  #checkInBtn,
  #checkOutBtn {
    min-height: 64px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 16px;
    letter-spacing: 0.01em;
    transition: transform 80ms ease, box-shadow 100ms ease;
  }

  #checkInBtn {
    background: #101010;
    color: #fff;
    border: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  }

  #checkOutBtn {
    background: var(--accent, #ff5a3d);
    color: #fff;
    border: none;
    box-shadow: 0 4px 16px rgba(255, 90, 61, 0.32);
  }

  #checkInBtn:active {
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  }

  #checkOutBtn:active {
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(255, 90, 61, 0.15);
  }

  /* Save button */
  #saveTrackBtn {
    min-height: 54px;
    font-size: 15px;
    border-radius: 14px;
    font-weight: 700;
  }

  /* Upload area — prominent and inviting */
  .upload-box {
    min-height: 92px;
    font-size: 15px;
    border-radius: 14px;
    border: 2px dashed #e0d8d0;
    background: #faf8f5;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 140ms ease, background 140ms ease;
  }

  .upload-box:active {
    border-color: #ffc2b6;
    background: #fff8f6;
  }

  /* Scroll margins */
  #trackEventWorkspace,
  #trackCheckinCard,
  #trackImagesCard {
    scroll-margin-top: clamp(72px, 12vw, 104px);
    scroll-margin-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

/* ─────────────────────────────────────────────────
   12. CALENDAR — tappable grid
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  .mini-calendar {
    gap: 6px;
  }

  /* Bigger cell tap targets */
  .mini-calendar button {
    min-height: 48px;
    font-size: 14px;
    border-radius: 12px;
    font-weight: 550;
    transition: transform 60ms ease, background 100ms ease;
  }

  .mini-calendar button:active {
    transform: scale(0.92);
  }

  .calendar-topline {
    gap: 10px;
  }

  /* Prev/Next buttons */
  #prevMonthBtn,
  #nextMonthBtn,
  #goTodayBtn {
    min-height: 42px;
    min-width: 56px;
    font-size: 13px;
    border-radius: 10px;
  }

  /* Month/year selects */
  #monthSelect,
  #yearSelect {
    min-height: 42px;
    font-size: 14px;
    border-radius: 10px;
  }

  /* Event accordion items */
  .event-accordion-trigger {
    padding: 16px;
    min-height: 58px;
    border-radius: 12px;
  }

  /* Calendar events actions */
  .event-details-actions .form-actions {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .event-details-actions .form-actions > * {
    width: 100%;
    min-height: 50px;
    justify-content: center;
    border-radius: 12px;
  }
}

/* ─────────────────────────────────────────────────
   13. ANALYTICS
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  /* 2-col KPI grid for analytics */
  .analytics-kpi-grid,
  .analytics-kpi-grid--biz,
  .analytics-kpi-grid--future {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .analytics-kpi {
    min-height: 80px;
    padding: 12px 14px;
  }

  .analytics-kpi strong {
    font-size: 24px;
  }

  /* Charts: single column */
  .analytics-charts-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .analytics-tables-grid {
    grid-template-columns: 1fr;
  }

  /* Reasonable chart heights on mobile */
  .chart-wrap {
    height: 240px;
  }

  .chart-wrap--compact {
    height: 220px;
    max-width: 100%;
  }

  .chart-wrap--tall {
    height: 280px;
  }

  /* Analytics table: horizontal scroll */
  .analytics-table-card {
    overflow-x: auto;
  }
}

/* ─────────────────────────────────────────────────
   14. GALLERY
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  .gallery-layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  /* Event list as collapsible with limited height */
  .gallery-sidebar {
    max-height: 260px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Photos: smaller thumbnails to show more */
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 6px;
  }
}

/* ─────────────────────────────────────────────────
   15. USER TRACKING
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  .tracking-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 18px;
    border-radius: 16px;
  }

  .tracking-filters {
    flex-direction: column;
    gap: 14px;
  }

  .tracking-period-label {
    width: 100%;
  }

  .tracking-period-select,
  .tracking-search-input {
    min-width: 0;
    width: 100%;
    min-height: 50px;
    font-size: 16px !important;
    border-radius: 12px;
    border: 1.5px solid #e4e0db;
  }

  .tracking-summary {
    flex-direction: row;
    gap: 12px;
  }

  .tracking-stat {
    flex: 1;
    min-width: 0;
    padding: 12px;
    border-radius: 12px;
    background: #faf8f5;
  }

  /* User tracking cards: single column */
  .user-tracking-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

/* ─────────────────────────────────────────────────
   16. OPT-IN FEED
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  .opt-in-feed {
    gap: 14px;
  }

  /* Opt-in cards: comfortable padding, premium feel */
  .opt-in-card {
    padding: 18px;
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.04);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  }
}

/* ─────────────────────────────────────────────────
   17. ACTIVITY MANAGEMENT
   ───────────────────────────────────────────────── */

@media (max-width: 840px) {
  .activity-manage-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .activity-catalog-card {
    max-height: min(420px, 55vh);
  }
}

/* ─────────────────────────────────────────────────
   18. TOUCH / INTERACTION STATES
   ───────────────────────────────────────────────── */

/* Remove desktop hover effects on touch devices */
@media (hover: none) {
  [data-panel="parties"] .party-box:hover,
  [data-panel="dashboard"] .studio-note:hover,
  [data-panel="dashboard"] .studio-clipboard:hover {
    transform: none;
    box-shadow: inherit;
  }

  .nav-btn:hover {
    background: transparent;
    color: #c5d3e6;
  }

  .nav-btn.is-active:hover {
    background: linear-gradient(90deg, rgba(255, 90, 61, 0.22), rgba(255, 138, 110, 0.08));
    color: #fff;
  }

  .kpi-grid article:hover {
    transform: none;
    box-shadow: var(--shadow-soft);
  }

  /* Premium tap feedback */
  .ghost-btn:active,
  .dark-btn:active,
  .accent-btn:active,
  .danger-btn:active {
    opacity: 0.8;
    transform: scale(0.96);
    transition: transform 60ms ease, opacity 60ms ease;
  }

  .dark-btn:active {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  }

  .accent-btn:active {
    box-shadow: 0 1px 4px rgba(255, 90, 61, 0.1);
  }

  .event-tag-chip:active {
    transform: scale(0.94);
    transition: transform 60ms ease;
  }

  .track-event-option:active,
  .event-picker-item:active {
    background: #fff3ef;
    border-color: #ffc2b6;
    transform: scale(0.98);
    transition: transform 60ms ease;
  }

  .nav-btn:active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
  }

  /* Cards get subtle press effect */
  .party-box:active {
    transform: scale(0.99);
    transition: transform 60ms ease;
  }

  .opt-in-card:active {
    transform: scale(0.99);
    transition: transform 60ms ease;
  }
}

/* ─────────────────────────────────────────────────
   19. VERY SMALL SCREENS (<420px)
   ───────────────────────────────────────────────── */

@media (max-width: 420px) {
  .main-app {
    padding-top: 10px;
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: 0;
  }

  /* KPI grids: single column */
  .analytics-kpi-grid,
  .analytics-kpi-grid--biz,
  .analytics-kpi-grid--future {
    grid-template-columns: 1fr;
  }

  /* Card padding: compact but still breathable */
  .card {
    padding: 16px;
    border-radius: 14px;
  }

  /* Event chips */
  .event-tag-chips {
    gap: 6px;
  }

  .event-tag-chip {
    font-size: 12px;
    padding: 8px 14px;
    min-height: 38px;
  }

  /* Bottom nav: tighter labels */
  .bottom-nav__label {
    font-size: 9px;
  }

  .bottom-nav__icon svg {
    width: 20px;
    height: 20px;
  }

  .bottom-nav__icon {
    width: 28px;
    height: 28px;
  }

  /* Form grid on events */
  .events-history-toolbar {
    padding: 14px;
  }

  /* Inputs slightly smaller */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not(.money-input),
  select {
    min-height: 48px;
  }

  /* Check-in buttons: slightly smaller */
  #checkInBtn,
  #checkOutBtn {
    min-height: 58px;
    font-size: 15px;
    border-radius: 14px;
  }

  /* Mode bar pills: tighter */
  [data-panel="parties"] .events-mode-btn {
    padding: 8px 14px;
    font-size: 12px;
    min-height: 38px;
  }
}

/* ─────────────────────────────────────────────────
   20. REDUCED MOTION
   ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .dashboard-decor__emoji,
  [data-panel="dashboard"] .volunteer-kpi--settlement.volunteer-kpi--alert.studio-note {
    animation: none;
  }

  [data-panel="dashboard"] .studio-note:hover,
  [data-panel="dashboard"] .studio-clipboard:hover {
    transform: none;
  }

  .bottom-nav__btn,
  .ghost-btn,
  .dark-btn,
  .accent-btn,
  .danger-btn {
    transition: none;
  }
}
