/* ============================================
   MOBILE / RESPONSIVE STYLES
   ============================================ */

.mobile-header,
.mobile-footer,
.home-col-switch { display: none; }
.home-reveal-bar { display: none; }

.mobile-menu-btn:hover { background-color: #1e1e23; color: #fff; }

.mobile-menu-btn {
  background: none;
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-18);
  flex-shrink: 0;
}

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999;
}

.mobile-overlay.open {
  display: block;
}

@media (max-width: 819px) {
  .mobile-menu-btn { display: flex; }

  /* Opening the drawer pushes the whole page across, header and footer included,
     rather than sliding over a static page. --drawer-w keeps the sidebar's width and
     the shift distance in lockstep. */
  :root { --drawer-w: 275px; }
  #app-sidebar.open ~ .mobile-header,
  #app-sidebar.open ~ .mobile-footer,
  #app-sidebar.open ~ .main-content { transform: translateX(var(--drawer-w)); }
  #app-sidebar.open ~ .mobile-header { z-index: 1001; }
  .mobile-header,
  .mobile-footer,
  .main-content { transition: transform var(--dur-base) ease; }

  /* The shifted content would otherwise be scrollable-overflow to the right.
     !important because <body> carries an inline `overflow: auto`. */
  html { overflow-x: hidden; }
  body { overflow-x: hidden !important; }

  /* ---- Fixed header ---- */
  .mobile-header {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    z-index: 900;
    padding: 0 8px;
    background: #000;
    border-bottom: 1px solid #2f3336;
  }
  /* Matches the sidebar logo: same drawn mark, same weights. */
  .mobile-header-title {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    line-height: 1;
    text-decoration: none;
  }
  .mobile-header-title svg { display: block; height: 24px; width: auto; }
  /* Bold state is a second drawing rather than a heavier stroke — see the
     sidebar logo for why the geometry cannot come from CSS. */
  .mobile-header-title .apex-mark-bold { display: none; }
  .mobile-header-title.is-home .apex-mark-rest,
  .mobile-header-title:hover .apex-mark-rest { display: none; }
  .mobile-header-title.is-home .apex-mark-bold,
  .mobile-header-title:hover .apex-mark-bold { display: block; }
  .mobile-header-title:hover { text-decoration: none; }
  .mobile-header-spacer { width: 40px; flex-shrink: 0; }

  /* ---- Fixed footer nav ---- */
  .mobile-footer {
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #000;
    border-top: 1px solid #2f3336;
  }
  .mobile-footer-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 56px;
    height: 48px;
    padding: 0 4px;
    border-radius: var(--radius-lg);
    color: var(--text-3);
    font-size: var(--fs-18);
    text-decoration: none;
    transition: color var(--dur-fast), background-color var(--dur-fast);
  }
  /* The global a:hover underline outranks a class-level reset, so restate it here. */
  @media (hover: hover) { .mobile-footer-link:hover { color: #fff; text-decoration: none; background-color: #1e1e23; } }
  .mobile-footer-link { -webkit-tap-highlight-color: transparent; }
  /* New: a button among the links, its + in the accent's green pill like the drawer's New. */
  .mobile-footer-new { border: none; background: none; font: inherit; cursor: pointer; }
  .mobile-footer-new-mark {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 26px; border-radius: 9999px;
    background-color: var(--accent); color: #06130a; font-size: 15px;
    /* Takes the 18px an icon does, so New's label lines up with the others'. */
    margin: -4px 0;
  }
  .mobile-footer-new:active .mobile-footer-new-mark { filter: brightness(0.9); }
  @media (hover: hover) { .mobile-footer-new:hover { background-color: transparent; } }
  /* The footer's New replaces the drawer's, which stuck to the bottom of the menu and
     floated over its list. The menu stays in the DOM: New's form reads its items. */
  .sidebar-compose-wrap { display: none; }
  /* Where you are, at a glance: the tab's icon in the accent, a short bar above it. */
  .mobile-footer-link { position: relative; }
  .mobile-footer-link.is-active { color: #fff; }
  .mobile-footer-link.is-active i { color: var(--accent); }
  .mobile-footer-link.is-active .mobile-footer-label { font-weight: 600; }
  .mobile-footer-link.is-active::before { content: ""; position: absolute; top: -4px; left: 50%; width: 20px; height: 2px; border-radius: 2px; background: var(--accent); transform: translateX(-50%); }
  .mobile-footer-label { font-size: 10px; font-weight: 500; line-height: 1; letter-spacing: 0.01em; }

  /* A little room at the end of the home columns' scroll so the last row (the day's
     footer tally) doesn't end hard against the footer. border-box so the padding stays
     inside the columns' height: 100%. */
  #home-container .daily-column,
  #home-container .categories-column {
    box-sizing: border-box;
    padding-bottom: 16px;
  }

  /* ---- Home: one column at a time, schedule first ----
     Paged by the chevrons beside the header logo, or a sideways swipe (row_tools.js).
     (Tried 2026-11 as one scroll, the areas under the day; the user preferred paging.) */
  /* Drawn as the menu button's sibling: same 40px box, same radius, same
     bare-glyph-on-hover-fill treatment. */
  .home-col-switch {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: none;
    color: var(--text-2);
    font-size: var(--fs-18);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--dur-fast), color var(--dur-fast);
  }
  .home-col-switch:active { background-color: #1e1e23; color: #fff; }
  @media (hover: hover) { .home-col-switch:hover { background-color: #1e1e23; color: #fff; } }

  /* The two chevrons close in on the logo so the three read as one group, a pager for
     the thing between them. The title gives up flex: 1 so the auto margins have slack. */
  .mobile-header:has(.home-col-switch) .mobile-header-title { flex: 0 0 auto; }
  .home-col-prev { margin-left: auto; }
  .home-col-next { margin-right: auto; }
  /* visibility, not display: the inactive chevron keeps its slot so the logo between
     them doesn't jump sideways when you page across. */
  body.mobile-show-categories .home-col-prev,
  body:not(.mobile-show-categories) .home-col-next { visibility: hidden; }

  /* ---- Collapsed chart/calendar, each with its own reveal bar ----
     The pie chart and the month calendar each eat most of a phone screen before a
     single task is visible, so both start collapsed here. Each bar is the first thing
     inside its own column's scroller, so it scrolls away with the content instead of
     sitting under the fixed header, and each column remembers its own state. */
  .home-reveal-bar {
    display: flex;
    align-items: center;
    margin: 0;
  }
  /* Only once something is expanded does the bar need breathing room under it. */
  body.mobile-reveal-categories .categories-column .home-reveal-bar,
  body.mobile-reveal-schedule .daily-column .home-reveal-bar { margin-bottom: 6px; }
  /* Collapsed, the first card sits straight under the bar. The hidden chart/calendar
     row is still the bar's next sibling, so `+ *` is whatever card comes first -
     inbox, beliefs block or category list on one side, the day list on the other -
     without having to name each of them. */
  body:not(.mobile-reveal-categories) .categories-column > .pie-chart-row + *,
  body:not(.mobile-reveal-schedule) .daily-column > .calendar-row + * { margin-top: 0 !important; }
  /* ...and its first child too: when that block is a plain list wrapper (#categories-list,
     .daily-past-days) the leading gap lives on the first card inside it - every category
     card carries margin-top: 21px - not on the wrapper. */
  body:not(.mobile-reveal-categories) .categories-column > .pie-chart-row + * > *:first-child,
  body:not(.mobile-reveal-schedule) .daily-column > .calendar-row + * > *:first-child { margin-top: 0 !important; }
  .home-reveal-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 0;
    /* A solid blue band is the loudest thing on the page at rest, for a control
       that only unfolds a panel - and blue is the app's interaction colour, which
       should mean "you are touching this", not "this is here". So it rests as a
       hairline the width of the column with a quiet chevron sitting on it, and
       takes the blue only while pressed. */
    background-color: transparent;
    box-shadow: inset 0 -1px 0 var(--border-panel);
    color: var(--text-3);
    font-size: var(--fs-11);
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--dur-fast), color var(--dur-fast);
  }
  .home-reveal-btn:hover,
  .home-reveal-btn:active {
    background-color: var(--blue);
    color: #06131f;
    box-shadow: none;
  }
  /* Expanded, it is holding something open rather than advertising itself, so it
     stays quiet but reads as active. */
  body.mobile-reveal-categories .categories-column .home-reveal-btn,
  body.mobile-reveal-schedule .daily-column .home-reveal-btn { color: var(--text-2); }
  .home-reveal-btn i { transition: transform var(--dur-base) ease; }
  body.mobile-reveal-categories .categories-column .home-reveal-btn i,
  body.mobile-reveal-schedule .daily-column .home-reveal-btn i { transform: rotate(180deg); }

  /* One continuous panel per column rather than a stack of rounded cards: the day
     cards and the category cards go square and full-bleed, so the only rounding left
     is the column's own bottom corners. Task rows keep their pill corners. */
  .daily-column .day-section {
    border-radius: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-left: none;
    border-right: none;
  }
  .category-card-border,
  .category-header,
  .inbox-header,
  .inbox-footer,
  .unplaced-head-card,
  .unplaced-foot-card {
    border-radius: 0 !important;
  }

  .pie-chart-row,
  .calendar-row { display: none !important; }
  body.mobile-reveal-categories .pie-chart-row { display: flex !important; }
  body.mobile-reveal-schedule .calendar-row { display: flex !important; }

  /* One frame at a time: the day unless the areas were paged to. */
  #home-container > turbo-frame#categories { display: none; }
  body.mobile-show-categories #home-container > turbo-frame#categories { display: block; }
  body.mobile-show-categories #home-container > turbo-frame#task_schedule_daily { display: none; }

  /* Sidebar: off-screen by default, slides in when .open */
  /* !important: the sidebar carries an inline `position: sticky` for the desktop shell,
     which outranks a plain media-query rule. Without this it stays in flow and keeps its
     275px flex slot while translated off-screen, squeezing the content column. */
  #app-sidebar {
    /* A short screen scrolls the drawer rather than clipping its last rows. */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    position: fixed !important;
    top: 0;
    left: 0;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform var(--dur-base) ease;
    z-index: 1000;
    border-right: none;
  }

  #app-sidebar.open {
    transform: translateX(0);
  }

  /* Remove sidebar margin from main content */
  .main-content {
    max-width: 100% !important;
    padding-top: 52px;
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  /* Home page: stack two columns vertically */
  #home-container {
    flex-direction: column !important;
    /* The inline `justify-content: center` centres the desktop's two columns; in one
       column taller than the screen it would centre the overflow too, pushing the top
       of the day above the scroll's reach. */
    justify-content: flex-start !important;
    height: calc(100dvh - 52px - 56px - env(safe-area-inset-bottom)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 0 !important;
    gap: 0 !important;
    /* Touch devices draw overlay scrollbars anyway; a classic one would reserve a
       gutter down the right edge. */
    scrollbar-width: none;
    overscroll-behavior: contain;
  }
  #home-container::-webkit-scrollbar { width: 0; height: 0; }

  #home-container > turbo-frame {
    max-width: 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    /* !important: each frame carries an inline `flex: 1 1 0` for the desktop's two
       columns side by side, which here would stretch both to share the screen's
       height instead of each being as tall as what it holds. */
    flex: none !important;
    min-height: 0;
  }

  /* The day ends where its last card does, with the areas a short gap below. */
  #home-container .daily-column { padding-bottom: 0; }
  #home-container .daily-column .day-section:not(:has(~ .day-section)) { margin-bottom: 0 !important; }

  .categories-column,
  .daily-column {
    height: auto !important;
    overflow: visible !important;
    /* Full-bleed since the container padding went, so the cards inside would otherwise
       meet the screen edge square. A radius on a scroll container clips its content,
       so this rounds the column itself and everything scrolling through it. Top corners
       stay square: the blue reveal bar is the first thing in the scroller and has to sit
       flush under the header. */
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    /* Both columns scroll, and the global 8px classic scrollbar reserves a gutter
       inside each one - which reads as dead space down the right edge once the
       container padding is gone. Touch devices draw overlay scrollbars anyway, so
       there is nothing to lose by hiding them here. */
    scrollbar-width: none;
    overscroll-behavior: contain;
  }
  .categories-column::-webkit-scrollbar,
  .daily-column::-webkit-scrollbar { width: 0; height: 0; }

  /* No leading gap above the pie chart once it is expanded. */
  .pie-chart-row {
    margin-top: 0 !important;
  }

  /* Tasks index: full width with less padding */
  .main-content > turbo-frame > div[style*="max-width: 700px"] {
    padding: 1rem 0.75rem !important;
  }
}

/* ---- Home widgets scale with the single-column width (<=819px) ----
   Below 820px each column goes full-bleed, but the pie chart is a hard 319px box
   (its category icons are absolutely positioned in px computed from that 319) and
   the calendar is sized in em off an inline 100px base. Neither grows, so on the
   wider phones and small tablets in this range they sit marooned in a column two
   or three times their width.

   `zoom` rather than `transform: scale()`: it scales the used values, so the pie's
   px-positioned icon overlays stay on their segments and the layout box grows with
   the art instead of overlapping what follows. Browsers without it simply keep
   today's size. Steps rather than a fluid clamp() because zoom takes a plain
   number, which no vw-based calc() can produce. */
@media (min-width: 481px) and (max-width: 640px) {
  #pie-chart-container { zoom: 1.15; }
  .schedule-calendar-panel { zoom: 1.15; }
}
@media (min-width: 641px) and (max-width: 819px) {
  #pie-chart-container { zoom: 1.35; }
  .schedule-calendar-panel { zoom: 1.35; }
}

/* The phone's slide-out menu: rows a touch tighter, and "+ New" and your card pinned to
   the foot of the drawer, so they're always in reach rather than below its bottom edge. */
@media (max-width: 819px) {
  #app-sidebar .sidebar-nav-link { padding-block: 7px; }
  #app-sidebar > ul > li.nav-divider { margin-block: 4px !important; }
  #app-sidebar .sidebar-compose-wrap { position: sticky; bottom: 74px; z-index: 3; margin-top: auto; padding: 10px 0 8px; background: #000; }
  #app-sidebar .sidebar-account { position: sticky; bottom: 0; z-index: 3; margin-top: 0; margin-bottom: 0; padding-bottom: calc(9px + env(safe-area-inset-bottom)); background: #000; }
}
