/* ============================================================
   H&P DASHBOARD — SHARED COMPONENTS
   Cards, buttons, headers, terminals, row states
   ============================================================ */

/* Global: let icon strokes that hit the viewBox edge render past it — prevents the hair-thin clipping seen on many peach glyphs. */
svg { overflow: visible; }

/* ============================================================
   PAGE LAYOUT
   ============================================================ */

.page {
  /* No max-width — content area follows the screen edges (with --side-gutter
     padding). Cards inside section-col stay centered at their own max-width
     (--card-width = 560px), so on wide desktop they sit centered with lots of
     breathing room rather than pinned to a 800px container.
     On mobile (≤480px) --card-width drops to 100% so the card fills the
     available width minus gutter — the natural narrow-viewport behavior. */
  margin: 0 auto;
  padding: 0 var(--side-gutter) 60px;
  box-sizing: border-box;
}

/* Section column — full available width of .page (which is now uncapped),
   so the section spans the full viewport with --side-gutter on each edge.
   Cards inside still center at --card-width, getting the breathing-room feel
   the user asked for. On mobile (≤480px) --card-width drops to 100% so the
   card fills the column naturally. */
.section-col {
  width: 100%;
  margin: 0 auto;
}

/* Card wrapper — 560px centered. Card itself doesn't expand; the terminal
   panels inside (Full Message, AI Summary, Draft Reply, Summary, etc.)
   are what expand to viewport edges. */
.card-wrap {
  width: min(var(--card-width), 100%);
  margin: 0 auto;
}

/* Hidden-by-status cards: Lost/Limbo events + Lost contacts. Rendered to
   the DOM with their searchable text but invisible in the default view.
   applySearch() sets an inline `display:block` when a query matches,
   which overrides this rule and reveals the card temporarily. Clearing
   the search resets inline display to '' and the card hides again.
   Implementation note: uses display:none (not visibility) so the layout
   does NOT reserve space for these cards in the default view. */
.card-wrap.hidden-by-status {
  display: none;
}

/* ============================================================
   SECTION LAYOUT
   ============================================================ */

.section {
  margin-top: var(--gap-section);
}

.section:first-child {
  margin-top: 20px;
}

.subsection {
  margin-top: var(--gap-sub);
}

/* ============================================================
   SECTION HEADING (24px peach above card)
   ============================================================ */

.section-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 0 10px 0;
  /* Section column is now full-width — the old --section-col-offset (100px)
     was sized to align titles with the card-wrap edge in a 760px section-col.
     Now that section-col spans the viewport, that fixed offset would stick
     titles to the left while cards float centered. Use a calc that derives
     the card's left edge from current section width: (section-width - card-
     width) / 2 produces the correct title-aligns-with-card position at any
     screen width. Falls back to 0 on narrow viewports where card width is
     100% and title sits flush with the card edge. */
  padding-left: max(0px, calc((100% - var(--card-width)) / 2));
}

/* First subsection directly under a title — no extra top margin (title padding already provides 20px) */
.section-title + .subsection {
  margin-top: 0;
}

.section-title-text {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 24px;
  line-height: 35px;
  letter-spacing: 2.4px;
  color: var(--peach);
  text-transform: uppercase;
}

/* Small icon beside section title (e.g. @ icon next to COMMS STATUS) */
.section-title-icon {
  display: inline-flex;
  align-items: center;
  color: var(--peach);
  opacity: 0.6;
  margin-left: 4px;
}

/* ============================================================
   SECTION HEADER BAR (peach bar with title + count)
   ============================================================ */

.section-header {
  width: 100%;
  height: 54px;
  background: var(--peach);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 var(--card-pad-r) 0 var(--card-pad-l);
}

.section-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.section-header-title {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 18px;
  line-height: 35px;
  letter-spacing: 1.8px;
  color: var(--on-peach);
  text-transform: uppercase;
}

.section-header-right {
  text-align: right;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 1px;
}

/* Count row: label + number inline on one line */
.section-header-count-row {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.section-header-label {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0;
  color: var(--on-peach-dim);
  text-transform: uppercase;
}

.section-header-count {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 18px;
  line-height: 18px;
  color: var(--on-peach);
}

.section-header-sub {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0;
  color: var(--on-peach);
  text-transform: uppercase;
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  width: 100%;
  background: var(--bg2);
  border: var(--border-w) solid var(--border);
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  position: relative;
  overflow: visible;
}

/* Card body: left col + right col */
.card-body {
  display: flex;
  padding: var(--card-pad-t) var(--card-pad-r) 0 0;
  min-height: 80px;
}

.card-left {
  width: var(--left-col);
  min-width: var(--left-col);
  padding: 0 0 0 var(--card-pad-l);
  flex-shrink: 0;
  position: relative;
}

.card-right {
  flex: 1;
  min-width: 0;
}

/* Date and type labels */
.card-date {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  overflow-wrap: break-word;
  letter-spacing: 0;
  color: var(--peach);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.card-type {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0;
  color: var(--peach-25);
  text-transform: uppercase;
}

/* Icon row below date/type */
.card-icons {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
}

.card-icons .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-dim { opacity: 0.25; }

/* Right col content */
.card-name {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  letter-spacing: 0;
  color: var(--peach);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.card-name-dim {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  color: var(--peach-25);
  text-transform: uppercase;
}

.card-venue {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  color: var(--peach-25);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.card-pkg {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  color: var(--red);
  text-transform: uppercase;
  margin-top: var(--card-pad-t);
}

/* Event card SUMMARY panel — rich block (Crew + Inventory + Notes) rendered
   under the Claude-generated AI summary text. Mirrors the dynamic logistics
   URL inventory layout but compact for the in-card terminal panel. */
.evt-summary-section { margin-top: 16px; }
.evt-summary-section-lbl {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--peach);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 0.5px solid rgba(126,121,121,0.3);
}

/* Crew grid — fluid columns set inline per render */
.evt-summary-crew-grid { display: grid; gap: 6px; }
.evt-summary-crew-box  {
  background: rgba(43,43,43,0.5);
  border-radius: 2px;
  padding: 8px 10px;
}
.evt-summary-crew-name {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.evt-summary-crew-role {
  font-size: 10px;
  color: rgba(219,219,219,0.7);
  line-height: 1.4;
}

/* Inventory groups + per-group footer */
.evt-summary-group { margin-bottom: 12px; }
.evt-summary-group-lbl {
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255,190,159,0.55);
  margin-bottom: 5px;
}
.evt-summary-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.evt-summary-list li {
  font-size: 11px;
  color: var(--body, #DBDBDB);
  display: flex;
  gap: 8px;
  line-height: 1.4;
  padding: 1px 0;
}
.evt-summary-qty { color: var(--peach); min-width: 22px; font-size: 10px; flex-shrink: 0; }
.evt-summary-totals {
  font-size: 9px;
  color: rgba(219,219,219,0.5);
  letter-spacing: 0.5px;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 0.5px solid rgba(126,121,121,0.18);
}

/* Grand Total band — same Helvetica bold treatment as the URL */
.evt-summary-grand-total {
  background: rgba(255,190,159,0.05);
  border-radius: 2px;
  padding: 12px 14px;
  margin-top: 10px;
}
.evt-summary-grand-lbl-row {
  font-size: 8px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--peach);
  margin-bottom: 10px;
  text-align: center;
}
.evt-summary-grand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 10px 6px;
}
.evt-summary-grand-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.evt-summary-grand-qty {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  color: var(--peach);
  padding-bottom: 5px;
}
.evt-summary-grand-item-lbl {
  font-size: 8px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: rgba(219,219,219,0.45);
  text-align: center;
  line-height: 1.2;
}

/* Notes — preserves whitespace + line breaks from AT */
.evt-summary-notes {
  font-size: 11px;
  color: rgba(219,219,219,0.85);
  line-height: 1.5;
  white-space: pre-wrap;
  background: rgba(43,43,43,0.4);
  padding: 10px 12px;
  border-radius: 2px;
}

/* Agentic Query — Loadout response.
   Date-range inventory rollup, styled to match the logistics-URL Grand Total
   so the planner gets the same "what to pack" treatment in the query panel. */
.loadout-hdr { margin-bottom: 12px; }
.loadout-answer {
  font-size: 11px;
  color: var(--peach);
  letter-spacing: 0.3px;
}
.loadout-section-lbl {
  font-size: 8px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(255,190,159,0.5);
  margin-bottom: 6px;
}
.loadout-events { margin-bottom: 14px; }
.loadout-events-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 3px; }
.loadout-events-list li {
  font-size: 11px;
  color: var(--body, #DBDBDB);
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
}
.loadout-event-date {
  font-size: 9px;
  letter-spacing: 0.5px;
  color: var(--peach);
  min-width: 70px;
  flex-shrink: 0;
}
.loadout-event-name { font-weight: 700; }
.loadout-event-meta { color: rgba(255,190,159,0.4); font-size: 9px; }

.loadout-grand-total {
  background: rgba(255,190,159,0.05);
  border-radius: 2px;
  padding: 14px 16px;
}
.loadout-grand-lbl {
  font-size: 8px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--peach);
  margin-bottom: 12px;
  text-align: center;
}
.loadout-grand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 12px 8px;
}
.loadout-grand-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.loadout-grand-qty {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
  color: var(--peach);
  padding-bottom: 5px;
}
.loadout-grand-item-lbl {
  font-size: 8px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(219,219,219,0.4);
  text-align: center;
  line-height: 1.3;
}
.loadout-empty {
  font-size: 11px;
  color: rgba(219,219,219,0.5);
  font-style: italic;
  padding: 10px 0;
}

/* EVENT DAY pill — matches .badge sizing.
   Visible at Month of Prep / Week of Prep stages.
   Click → always opens dynamic logistics URL in new tab. */
.event-day-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--peach);
  color: #2B2B2B;
  border: 0;
  cursor: pointer;
  margin-top: 6px;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.event-day-pill.incomplete { opacity: 0.5; }
.event-day-pill:active     { opacity: 0.8; }

/* 30-day separator — subtle horizontal rule between events ≤30 days and >30 days.
   Lives inline within the unified Active Events list. No label, just the rule. */
.events-30day-sep {
  height: 0;
  border-top: 1px solid rgba(126,121,121,0.3);
  margin: 10px 0 10px;
}

.card-event-line {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  color: var(--peach-25);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.card-last-contact-label {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  color: var(--peach-25);
  text-transform: uppercase;
}

.card-last-contact-date {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  color: var(--peach);
  text-transform: uppercase;
}

.card-preview {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 10px;
  line-height: 12px;
  color: var(--peach);
  margin-top: 2px;
  /* Force long unbreakable strings (URLs, tracking links) to wrap inside the card */
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ============================================================
   BUTTON ROW (bottom of card)
   ============================================================ */

.card-btns {
  display: flex;
  align-items: center;
  padding: 0 0 10px var(--card-pad-l);
  margin-top: var(--card-pad-t);
}

/* Buttons act as tabs — flush with open terminal below */
.card:has(.terminal.is-open) .card-btns {
  padding-bottom: 0;
}

/* Thread bar cards — remove card-btns bottom padding so thread bar controls its own spacing */
.card:has(.mail-thread-bar) .card-btns {
  padding-bottom: 0;
}

/* Right-side icon buttons (G, Hb) pinned to card right */
.card-btns-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding-right: var(--card-pad-r);
}

/* Base button */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 25px;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  outline: none;
  transition: opacity 0.15s;
}

/* Inactive: semi-dark bg, very dim peach text */
.btn-inactive {
  background: rgba(43,43,43,0.5);
  color: var(--peach-20);
  padding: 0 12px;
}

/* Selected/active expand state */
.btn-selected {
  background: var(--bg);
  color: var(--peach);
  padding: 0 10px;
}

/* Primary actions by state */
.btn-peach   { background: var(--peach); color: var(--on-peach); padding: 0 10px; }
.btn-red     { background: var(--red);   color: var(--on-peach); padding: 0 10px; }
.btn-green   { background: var(--green); color: var(--on-peach); padding: 0 10px; }

/* Dim secondaries */
.btn-dim-peach { background: var(--peach-20); color: rgba(43,43,43,0.5); padding: 0 10px; }
.btn-dim-red   { background: var(--red-20);   color: rgba(43,43,43,0.5); padding: 0 10px; }
.btn-dim-green { background: var(--green-20); color: rgba(43,43,43,0.5); padding: 0 10px; }

/* Outline buttons (Draft Reply panel) */
.btn-outline {
  background: transparent;
  border: 0.5px solid var(--border);
  color: var(--peach);
  padding: 0 10px;
}
.btn-outline-red   { border-color: var(--border); color: var(--red); }
.btn-outline-green { border-color: var(--border); color: var(--green); }

/* Pill / save feedback button */
.btn-pill {
  background: var(--peach-25);
  color: var(--on-peach);
  padding: 0 16px;
  border-radius: var(--radius-save);
  height: 22px;
}

/* ============================================================
   ROW STATE MODIFIERS
   ============================================================ */

/* Default: standard peach */
.row-default { border-color: var(--border); }

/* Urgent: red border, red text overrides */
.row-urgent {
  border: 1px solid var(--red) !important;
}
.row-urgent .card-date,
.row-urgent .card-name,
.row-urgent .card-pkg     { color: var(--red); }
.row-urgent .card-type    { color: var(--red-25); }
.row-urgent .card-event-line { color: var(--red-25); }
.row-urgent .card-preview { color: var(--red); }
.row-urgent .card-last-contact-date { color: var(--red); }
.row-urgent .card-last-contact-label { color: var(--red-25); }
.row-urgent .icon         { color: var(--red); }

/* Confirmed: standard, CONFIRMED button */
/* (no extra styles needed — just uses .btn-peach on secondary button) */

/* Dormant: green tint throughout */
.row-dormant .card-date,
.row-dormant .card-name,
.row-dormant .card-pkg         { color: var(--green); }
.row-dormant .card-type        { color: var(--green-50); }
.row-dormant .card-event-line  { color: var(--green-50); }
.row-dormant .card-preview     { color: var(--green); }
.row-dormant .card-last-contact-date  { color: var(--green); }
.row-dormant .card-last-contact-label { color: var(--green-50); }
.row-dormant .card-venue       { color: var(--green-50); }
.row-dormant .icon             { color: var(--green); }

/* ============================================================
   TERMINAL / VIEWPORT PANELS
   ============================================================ */

.terminal {
  width: 100%;
  background: var(--bg);
  border-radius: var(--radius-card);
  position: relative;
  overflow: visible;
  padding: 14px;
  display: none; /* hidden by default, shown when expanded */
}

.terminal.is-open { display: block; }

.terminal-text {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 10px;
  line-height: 12px;
  letter-spacing: 1px;
  color: var(--peach);
}

.terminal-text.is-urgent  { color: var(--red); }
.terminal-text.is-dormant { color: var(--green); }
.terminal-text.is-white   { color: var(--white-body); }

/* SUMMARY panel — cap height + internal scroll so a packed event card
   (long Claude summary + crew + inventory + notes) doesn't push everything
   else off the screen. Hidden scrollbar matches the Mail Station pattern. */
.terminal[data-panel="summary"] .terminal-text {
  max-height: 60vh;
  overflow-y: auto;
  scrollbar-width: none;       /* Firefox */
  -ms-overflow-style: none;    /* IE/Edge */
}
.terminal[data-panel="summary"] .terminal-text::-webkit-scrollbar { display: none; }

.terminal ul {
  list-style: disc;
  padding-left: 14px;
  margin-bottom: 8px;
}

.terminal li {
  margin-bottom: 2px;
}

.terminal-head {
  font-weight: 700;
  font-size: 10px;
  line-height: 10px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  margin-bottom: 6px;
  display: block;
}

/* Minimize button — circular, centered on right edge of terminal, vertically centered */
.btn-minimize {
  position: absolute;
  top: 50%;
  right: -7.5px;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--peach);
  background: none;
  border: none;
  padding: 0;
  flex-shrink: 0;
}
.btn-minimize.is-urgent  { color: var(--red); }
.btn-minimize.is-dormant { color: var(--green); }

/* ============================================================
   SCROLL DOTS + MINIMIZE RAIL (Mail Station right edge)
   Combined vertical strip: minimize button on top, dots below.
   Sits outside the terminal box on the right.
   ============================================================ */

/* Rail: absolutely positioned strip to the right of any terminal */
.terminal-rail {
  position: absolute;
  right: -8px;
  top: 0;
  bottom: 0;
  width: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Minimize button inside rail — sits between top and bottom dot groups */
.terminal-rail .btn-minimize {
  position: static;
  transform: none;
  flex-shrink: 0;
  margin: 18px 0; /* 18px edge-to-edge gap between button and nearest dot */
}

/* Scroll dots inside rail — tight group, no flex grow, centered by rail's justify-content */
.terminal-rail .scroll-dots {
  position: static;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
  width: auto;
}

.scroll-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--peach);
  opacity: 0.15;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.scroll-dot.is-active { opacity: 1; }

/* Scrollable content area — leave room for the rail */
.terminal-scrollable {
  overflow-y: auto;
  max-height: 275px;
  padding-right: 8px;
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* IE/Edge */
}
.terminal-scrollable::-webkit-scrollbar { display: none; } /* Chrome/Safari */

/* On mobile: rail moves inside (no bleed outside section-col) */
@media (max-width: 480px) {
  .terminal-rail {
    right: 4px;
  }
}

/* ============================================================
   NAV BAR
   ============================================================ */

.nav {
  background: var(--peach);
  width: 100%;
  transition: height 0.25s ease;
}

.nav-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  height: 70px;
  position: relative;
  display: flex;
  align-items: center;
  transition: height 0.25s ease;
}

.nav-logo {
  position: absolute;
  /* Anchored to the same side gutter as the page + query panel so the logo's
     left edge aligns vertically with all body content below. */
  left: var(--side-gutter);
  top: 0;
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: width 0.25s ease, height 0.25s ease;
}

.nav-logo svg {
  flex-shrink: 0;
  transition: width 0.25s ease, height 0.25s ease;
}

/* Compact nav — collapses to button height on scroll */
.nav.is-compact,
.nav.is-compact .nav-inner {
  height: 25px;
  overflow: visible; /* let logo spill below */
}

/* Logo shrinks to 75% of full height (52px), bottom hangs below the compact bar */
.nav.is-compact .nav-logo {
  width: 52px;
  height: 52px;
}

.nav.is-compact .nav-logo svg {
  width: 52px;
  height: 52px;
}

.nav-buttons {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 25px;
  padding: 0 20px;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: var(--peach);
  color: var(--on-peach);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.nav-btn.is-active {
  background: var(--bg);
  color: var(--peach);
}

/* Hamburger (mobile) */
.nav-hamburger {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px;
}

.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--on-peach);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

/* Mobile dropdown */
.nav-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--peach);
  flex-direction: column;
  z-index: 200;
}

.nav-dropdown.is-open { display: flex; }

.nav-dropdown .nav-btn {
  height: 35px;
  width: 100%;
  justify-content: center;
  border-top: 0.5px solid rgba(59,59,59,0.15);
}

.nav-sync {
  position: absolute;
  /* Mirror of .nav-logo's left gutter so the sync indicator's right edge
     aligns vertically with the page + query panel's right edges. */
  right: var(--side-gutter);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-sync-time {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 8px;
  line-height: 35px;
  color: var(--bg);
  white-space: nowrap;
}

.nav-sync-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

@keyframes sync-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.nav-sync-icon.is-syncing svg {
  animation: sync-spin 0.65s linear;
}

.nav-signout-btn {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 8px;
  letter-spacing: 1px;
  line-height: 35px;
  color: var(--bg);
  background: none;
  border: none;
  padding: 0 4px;
  margin-left: 4px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 120ms;
}
.nav-signout-btn:hover { opacity: 1; }

/* ============================================================
   PAGINATION — Show More pill
   ============================================================ */

/* Items hidden by pagination — overrideable by inline style during search */
.is-over-limit { display: none; }

.show-more-wrap {
  padding: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.show-more-pill {
  background: var(--peach);
  border: none;
  border-radius: 10px;
  height: 16px;
  padding: 0 18px 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.show-more-count {
  font-weight: 700;
  color: #3B3B3B;
}
.show-more-label {
  color: rgba(59,59,59,0.4);
  font-weight: 400;
}
.show-more-collapse {
  width: 16px;
  height: 16px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--peach);
  flex-shrink: 0;
}

/* ============================================================
   NAV SEARCH
   ============================================================ */

.nav-search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px;
  margin-right: 8px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.nav-search-btn:hover,
.nav-search-btn.is-active { opacity: 1; }

.nav-search-wrap {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 280px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 150ms ease, opacity 150ms ease;
  z-index: 100;
}
.nav-search-wrap.is-open {
  max-height: 35px;
  opacity: 1;
}
.nav-search-pill-inner {
  display: flex;
  align-items: center;
  background: rgba(43,43,43,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 0.5px solid #7E7979;
  border-radius: 10px;
  height: 25px;
  padding: 0 12px;
  gap: 6px;
}
.nav-search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 10px;
  color: #DBDBDB;
  letter-spacing: 1px;
  min-width: 0;
}
.nav-search-input::placeholder { color: rgba(219,219,219,0.35); }
.nav-search-clear {
  background: none;
  border: none;
  color: #7E7979;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
.nav-search-clear:hover { color: #DBDBDB; }

.search-zero {
  padding: 12px;
  color: var(--peach-25);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 10px;
  text-align: center;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Strategy C — full-history search fallback container.
   Sits above the events list, only shown when local DOM filter returns 0 hits. */
.search-history {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: rgba(0,0,0,0.18);
  border: 0.5px solid rgba(255,190,159,0.18);
  border-radius: 4px;
}
.search-history-header {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--peach);
  margin-bottom: 8px;
}
.search-history-loading,
.search-history-empty {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--peach-25);
  text-align: center;
  padding: 8px 0;
}
.search-history-section {
  margin-top: 10px;
}
.search-history-section:first-of-type { margin-top: 4px; }
.search-history-section-label {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: rgba(255,190,159,0.5);
  margin: 6px 0 4px;
}
.search-history-row {
  padding: 5px 0;
  border-bottom: 0.5px solid rgba(255,190,159,0.06);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.search-history-row:last-child { border-bottom: none; }
.search-history-row-primary {
  font-size: 11px;
  color: var(--peach);
  margin-bottom: 1px;
}
.search-history-row-secondary {
  font-size: 9px;
  color: rgba(219,219,219,0.45);
  letter-spacing: 0.3px;
}

/* ============================================================
   LEGEND PILLS (Comms Status bottom)
   ============================================================ */

.legend-pills {
  display: flex;
  align-items: center;
  width: 234px;
  height: 21px;
  margin: 12px auto 0;
}

.legend-pill {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--on-peach);
}

.legend-pill-green {
  background: var(--green-50);
  border-radius: var(--radius-pill) 0 0 var(--radius-pill);
}

.legend-pill-peach {
  background: rgba(255,190,159,0.5);
}

.legend-pill-red {
  background: var(--red-50);
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
}

/* ============================================================
   ACCOUNT LABELS (Mail header)
   ============================================================ */

.acct-label {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  line-height: 10px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: var(--on-peach);
}

.acct-label.is-dim {
  color: rgba(59,59,59,0.2);
}

/* ============================================================
   EMAIL / TIMESTAMP ROW
   ============================================================ */

.card-email {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  color: var(--peach-25);
  text-transform: uppercase;
}

.card-timestamp {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 12px;
  line-height: 14px;
  color: var(--peach);
}

.card-timestamp-dim {
  font-weight: 300;
  font-size: 12px;
  color: var(--peach);
  margin-left: 6px;
}

/* ============================================================
   DRAFT REPLY PANEL
   ============================================================ */

.draft-header {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  line-height: 10px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: var(--peach);
  margin-bottom: 8px;
}

.draft-header-dim {
  color: var(--peach-25);
}

.draft-body-box {
  border: 0.5px solid var(--border);
  padding: 8px 10px;
  margin-bottom: 6px;
}

.draft-body-text {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 10px;
  line-height: 12px;
  color: var(--white-body);
}

.draft-feedback-box {
  border: 0.5px solid var(--border);
  padding: 8px 10px;
  margin-bottom: 8px;
}

.draft-feedback-placeholder {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 10px;
  line-height: 12px;
  color: var(--white-body);
  opacity: 0.5;
}

.draft-quality-label {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  line-height: 12px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: var(--peach-25);
}

/* ============================================================
   MAIL THREAD COMPONENTS (Frances Cook thread expansion)
   ============================================================ */

/* Small thread-count pill — inline next to sender name */
.mail-thread-count {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  background: var(--peach);
  border-radius: 999px;
  padding: 2px 8px;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  line-height: 14px;
  color: var(--on-peach);
  white-space: nowrap;
  margin-right: 5px;
}

/* Bar that sits at bottom of card — always visible on thread cards.
   Padding mirrors the standard card-pad-* tokens so the gap between the
   tabs above and the MORE BELOW button matches every other vertical
   spacing in the card. */
.mail-thread-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: var(--card-pad-t) var(--card-pad-r) var(--card-pad-t) var(--card-pad-l);
}

/* Expand pill button */
.mail-thread-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--peach);
  border-radius: 999px;
  padding: 2px 14px;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  line-height: 14px;
  color: var(--on-peach);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mail-thread-btn-dim {
  color: var(--on-peach-dim);
}

.mail-thread-btn.is-expanded {
  background: var(--bg);
  color: var(--peach);
}

.mail-thread-btn.is-expanded .mail-thread-btn-dim {
  color: var(--peach-25);
}

/* Thread rows container — sibling to card-wrap, same 560px centered width
   so threaded messages line up with their parent card. */
.mail-thread-rows {
  display: none;
  width: min(var(--card-width), 100%);
  margin: 0 auto;
  position: relative;
}

.mail-thread-rows.is-open {
  display: block;
}

/* Bottom minimize button — centered on the last row's bottom border */
.mail-thread-rows .btn-minimize {
  position: absolute;
  bottom: -7.5px;
  left: 50%;
  top: auto;
  right: auto;
  transform: translateX(-50%);
}

/* Collapsed: same gap as all other cards */
.mail-thread-rows + .card-wrap {
  margin-top: 5px;
}
/* Expanded: extra room for the minimize button overhang */
.mail-thread-rows.is-open + .card-wrap {
  margin-top: 18px;
}

/* Individual thread message rows — two columns: left info + right body */
.mail-thread-row {
  display: flex;
  align-items: stretch;
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-top: none;
}

.mail-thread-row:first-child {
  border-top: 0.5px solid var(--border);
}

.mail-thread-row:last-child {
  border-radius: 0 0 var(--radius-card) var(--radius-card);
}

/* Left column — mirrors card-left width, shows sender time/date/name */
.thread-row-left {
  width: var(--left-col);
  min-width: var(--left-col);
  padding: 12px 8px 12px var(--card-pad-l);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-row-time {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 10px;
  line-height: 12px;
  color: var(--peach);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.thread-row-date-inline {
  font-weight: 300;
  font-size: 10px;
  color: var(--peach);
  margin-left: 5px;
  letter-spacing: 0.5px;
}

.thread-row-from {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 10px;
  line-height: 12px;
  color: var(--dim-text);
  letter-spacing: 0.3px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Right column — message body, capped height so long threads don't swallow the screen */
.thread-row-body {
  flex: 1;
  min-width: 0;
  padding: 12px var(--card-pad-r) 12px 10px;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-size: 10px;
  line-height: 14px;
  color: var(--peach);
  max-height: 90px;
  overflow-y: auto;
  overflow-x: hidden;
  /* Force long unbreakable strings (URLs, tracking links) to wrap inside the card */
  overflow-wrap: anywhere;
  word-break: break-word;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.thread-row-body::-webkit-scrollbar { display: none; }

/* Attachment indicator — sits below body text, dot separator above */
.thread-row-attach {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding-top: 8px;
  position: relative;
}
.thread-row-attach::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--on-peach-dim);
}
.thread-row-attach-icon {
  color: var(--on-peach-dim);
  flex-shrink: 0;
  line-height: 1;
}
.thread-row-attach-name {
  font-size: 9px;
  font-weight: 700;
  color: var(--on-peach-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   PAYMENT PROGRESS BAR
   ============================================================ */

.progress-bar {
  height: 4px;
  background: rgba(255,190,159,0.15);
  border-radius: 2px;
  overflow: hidden;
  margin: 6px 0;
}

.progress-fill {
  height: 100%;
  background: var(--peach);
  border-radius: 2px;
  transition: width 0.3s;
}

.progress-fill.is-paid   { background: var(--green); }
.progress-fill.is-urgent { background: var(--red); }

/* ============================================================
   STATUS BADGES
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 700;
  font-size: 8px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-peach  { background: var(--peach-25);        color: var(--peach);     }
.badge-red    { background: var(--red-25);          color: var(--red);       }
.badge-green  { background: var(--green-50);        color: var(--on-peach);  }
.badge-grey   { background: rgba(136,136,136,0.2);  color: #888888;          }

/* ============================================================
   STAGED REPLY (lost-deal close-out and similar)
   Worker auto-creates Tasks with a pre-drafted reply body in the
   Description. The DETAIL panel renders it in its own block with
   USE IN MAIL + COPY actions; the preview line shows a compact badge.
   ============================================================ */
.staged-reply-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: rgba(232, 117, 117, 0.18);
  color: var(--red);
  padding: 2px 6px;
  border-radius: 2px;
  margin-right: 6px;
}
.staged-reply {
  margin-top: 8px;
  padding: 10px 12px;
  background: rgba(255, 190, 159, 0.04);
  border: 0.5px solid rgba(255, 190, 159, 0.3);
  border-radius: 3px;
}
.staged-reply-head {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--peach);
  margin-bottom: 4px;
}
.staged-reply-meta {
  font-size: 9px;
  color: rgba(255, 190, 159, 0.55);
  margin-bottom: 8px;
}
.staged-reply-body {
  font-size: 10px;
  line-height: 1.45;
  color: var(--peach);
  white-space: pre-wrap;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
  margin-bottom: 10px;
}
.staged-reply-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.staged-reply-actions .btn {
  height: 22px;
  font-size: 9px;
  padding: 0 12px;
}

/* ============================================================
   TASK DETAIL PANEL — enrichment blocks
   Lazy-loaded under each task's DETAIL terminal: linked event,
   related messages (clickable to Gmail), sibling open tasks.
   ============================================================ */
.task-detail-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 0.5px solid rgba(255, 190, 159, 0.18);
}
.task-detail-block .terminal-head {
  display: block;
  margin-bottom: 4px;
  opacity: 0.65;
}
.task-detail-msgs,
.task-detail-sibs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-detail-msg {
  padding: 6px 8px;
  background: rgba(255, 190, 159, 0.04);
  border-left: 1.5px solid rgba(255, 190, 159, 0.35);
  border-radius: 2px;
}
.task-detail-msg-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 9px;
  color: rgba(255, 190, 159, 0.55);
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}
.task-detail-msg-subj {
  font-size: 10px;
  font-weight: 700;
  color: var(--peach);
  margin-bottom: 2px;
}
.task-detail-msg-body {
  font-size: 10px;
  line-height: 1.4;
  color: rgba(255, 190, 159, 0.75);
}
.task-detail-sib {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 10px;
  color: var(--peach);
}
.task-detail-deep {
  border-top: 0.5px solid rgba(255, 190, 159, 0.4);
}
.task-detail-deep-row .query-deep-btn {
  /* Reuse the same dark-circle "D" pill used in the aut\ panel */
}

/* ============================================================
   PRIORITY PILLS (Tasks)
   ============================================================ */

.priority-pill {
  display: inline-flex;
  align-items: center;
  height: 16px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 8px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.priority-high   { background: var(--red-25);   color: var(--red);   }
.priority-medium { background: var(--peach-25);  color: var(--peach); }
.priority-low    { background: rgba(126,121,121,0.2); color: var(--dim-text); }

/* 5px gap between consecutive cards within same sub-section */
.card-wrap + .card-wrap {
  margin-top: 5px;
}

.card-wrap:has(.section-header) {
  margin-bottom: 5px;
}

/* ============================================================
   RESPONSIVE — TABLET / MOBILE
   ============================================================ */

@media (max-width: 768px) {
  :root {
    --section-col: 680px;
    --card-width:  480px;
    --section-col-offset: 100px;
  }
}

/* Collapse nav to hamburger earlier — tablets in portrait get clean menu too */
@media (max-width: 720px) {
  .nav-buttons { display: none; }
  .nav-hamburger { display: flex; }
}

/* ------------------------------------------------------------
   MOBILE (phones) — fit viewport, wrap overflowing rows
   ------------------------------------------------------------ */
@media (max-width: 480px) {
  :root {
    --section-col: calc(100% - 8px);
    --card-width:  100%;
    --section-col-offset: 0px;
    --left-col: 92px;           /* narrower date/sender column */
    --card-pad-l: 10px;
    --card-pad-r: 10px;
    --gap-section: 28px;        /* tighter vertical rhythm */
  }

  /* Section titles align with cards (no desktop offset indent) */
  .section-title { padding-left: 6px; padding-right: 6px; }
  .section-title-text { font-size: 20px; line-height: 28px; letter-spacing: 1.8px; }

  /* Card button row: allow a second line instead of overflowing.
     Right cluster (reactions + Gmail + E) stays grouped via .card-btns-right margin-left:auto. */
  .card-btns {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .card-btns-right { gap: 6px; }

  /* Shrink tab buttons so "FULL MESSAGE / AI SUMMARY / DRAFT REPLY" fit one row */
  .btn {
    font-size: 9px;
    letter-spacing: 0.6px;
    height: 24px;
  }
  .btn-inactive,
  .btn-selected { padding: 0 9px; }

  /* Thread bar: wrap rather than overflow */
  .mail-thread-bar {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  /* Keep terminal inside card bounds on mobile (no negative-margin bleed) */
  .card:has(.terminal.is-open):not(:has(.mail-thread-bar)) .terminal,
  .card .terminal {
    width: 100%;
    margin-left: 0;
  }

  /* Prevent any media/content from breaking horizontal layout */
  .card,
  .card-wrap,
  .mail-thread-rows { max-width: 100%; overflow-x: hidden; }
  .card img,
  .card video { max-width: 100%; height: auto; }

  /* Nav brand/sync sizing */
  .nav-sync-time { display: none; }     /* timestamp eats too much width */
}

/* ============================================================
   MOBILE V2 — Petal OS dashboard, ≤640px
   ------------------------------------------------------------
   Entire block is self-contained. To revert: delete from this
   marker to the matching END marker at the bottom.
   Goals: cards + terminals run viewport-edge-to-edge, card content
          stacks vertically, all pill/action buttons sit above the
          tab buttons with a thin rule (inset by --card-pad-l/r) above.
   Anything outside cards keeps the standard --side-gutter padding.
   ============================================================ */
@media (max-width: 640px) {

  /* --- Cards: break out of section-col gutter to viewport edges --- */
  .card-wrap {
    margin-left:  calc(-1 * var(--side-gutter));
    margin-right: calc(-1 * var(--side-gutter));
    width: calc(100% + 2 * var(--side-gutter));
    max-width: 100vw;
    box-sizing: border-box;
  }
  .card { width: 100%; max-width: 100%; box-sizing: border-box; }

  /* --- Card body: stack name/role on top, content below ---
     Rule lives on .card-btns (below) so it sits between body content
     and the pill/tabs action area. */
  .card-body {
    flex-direction: column;
    padding: var(--card-pad-t) var(--card-pad-r) 0 var(--card-pad-l);
    position: relative;
    gap: 0;
  }
  .card-left {
    width: 100%;
    min-width: 0;
    padding: 0;
    box-sizing: border-box;
  }
  .card-right {
    width: 100%;
    margin-top: 8px;
    padding-top: 0;
    border-top: 0;
  }

  /* Side icons → INLINE in the same flex row as the MAY 1 / WEDDING text.
     Dropped absolute positioning entirely because absolute was being beaten
     somewhere in the cascade. Inline-flex with align-items: flex-start
     guarantees the icons share the exact same top edge as the date text;
     margin-left:auto pushes them to the right edge of the row. */
  .card-icons {
    position: static !important;
    margin: 0 0 0 auto !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: row;
    align-items: flex-start;
    align-self: flex-start;
    gap: 8px;
    line-height: 0;
    flex-shrink: 0;
  }
  .card-icons .icon {
    display: inline-block;
    line-height: 0;
    height: auto;
    margin: 0;
    padding: 0;
  }
  .card-icons .icon svg {
    display: block;
    vertical-align: top;
    margin: 0;
    padding: 0;
  }
  /* Comms X dismiss button lives on the card at right: 8px. Reserve room on
     the right of card-left so the icon trio doesn't slide under the X. */
  .card:has(.comms-dismiss-btn) .card-left {
    padding-right: 28px;
  }

  /* --- EVENT DAY: hide the inline-with-name copy, show the action-row copy.
         Render-events.js emits the same button in both spots; CSS picks
         which is visible per breakpoint. --- */
  .card-right .event-day-pill { display: none !important; }
  .card-btns .event-day-pill  { display: inline-flex; }

  /* --- Action row: pills wrap to their own line above the tabs ---
     Layout strategy:
       • Pills (everything that isn't .btn) get order: 1  → render first
       • A ::after pseudo with order: 2 + flex-basis: 100% forces a new row
       • Tabs (.btn) get order: 3  → render together on the new row
     Rule sits ABOVE the action row, inset by --card-pad-l/r via ::before. */
  .card-btns {
    flex-wrap: wrap;
    align-items: center;
    row-gap: 8px;
    column-gap: 8px;
    padding: var(--card-pad-t) var(--card-pad-r) var(--card-pad-t) var(--card-pad-l);
    margin-top: var(--card-pad-t);
    border-top: 0;             /* the inset rule comes from ::before */
    position: relative;
  }
  /* Tabs sit flush against each other like desktop — cancel column-gap between them. */
  .card-btns > .btn + .btn { margin-left: -8px; }
  .card-btns::before {
    content: '';
    position: absolute;
    top: 0;
    left: var(--card-pad-l);
    right: var(--card-pad-r);
    border-top: 0.5px solid rgba(126, 121, 121, 0.4);
  }
  /* Row break: 100%-wide zero-height flex item between pills (1) and tabs (3) */
  .card-btns::after {
    content: '';
    flex-basis: 100%;
    width: 100%;
    height: 0;
    order: 2;
  }
  .card-btns > .btn { order: 3; }
  .card-btns > .comms-pill-wrap,
  .card-btns > .comms-priority-wrap,
  .card-btns > .event-att-actions,
  .card-btns > .event-tag-pill,
  .card-btns > .event-day-pill,
  .card-btns > .att-count-btn,
  .card-btns > .att-group-marker,
  .card-btns > div[style*="margin-left:auto"],
  .card-btns > div[style*="margin-left: auto"],
  .card-btns-right {
    order: 1;
    margin-left: 0 !important;
  }
  /* Push the event attachment-actions cluster to the right edge of the pill row */
  .card-btns > .event-att-actions {
    margin-left: auto !important;
  }

  /* Mobile: lay card-left as a single flex row holding date + type + icons.
     align-items: flex-start ensures the icons' top edges line up with the
     top of the MAY 1 glyph line (since they're all flex children of the
     same line). column-gap handles the visible spacing between date / type;
     icons get pushed to the right via margin-left: auto on .card-icons. */
  .card-left {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    flex-wrap: nowrap;
    column-gap: 8px;
  }
  .card-date,
  .card-type {
    display: inline-block;
  }
  /* EVENT DAY pill matches the small badge pills (ACTIVE / WEEK OF PREP) */
  .card-btns .event-day-pill {
    height: 18px;
    padding: 0 8px;
    margin-top: 0;
  }

  /* --- Terminal panels: viewport-wide, flush to edges ---
     The bleed JS now bails on mobile (see footer script), so terminals
     follow the standard CSS box model: 100% of card width = 100vw. */
  .card .terminal,
  .card .terminal.is-open {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* --- Section header: tighten line-height to match Figma mobile spec.
         Allow the title to wrap to a 2nd line so right-side toggles never
         overlap the text. Header grows to fit; peach background stays
         vertically centered. --- */
  .section-header {
    height: auto;
    min-height: 54px;
    padding-top: 10px;
    padding-bottom: 10px;
    align-items: center;
  }
  .section-header-inner {
    align-items: center;
    gap: 10px;
  }
  .section-header-title {
    font-size: 18px;
    line-height: 18px;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
    /* Force-fit constraint so "RECENT MESSAGES" wraps to two lines and
       the INBOUND + LATEST toggles get their lane on the right. */
    flex: 0 1 auto;
    max-width: 40%;
    min-width: 0;
  }
  .section-header-right {
    flex-shrink: 0;
  }

  /* --- INBOUND filter: drop out of absolute positioning so it sits inline
         between the section title and the LATEST count column on the right.
         Visual order: RECENT MESSAGES   [INBOUND]   LATEST: 39 +
         translateX(-20px) shifts the whole INBOUND ensemble (button +
         dropdown stack) left by 20px without disturbing the LATEST
         column's position. --- */
  .mail-filter {
    position: static;
    width: auto;
    transform: translateX(-20px);
  }
  .mail-filter-active {
    width: auto;
    height: 22px;
    padding: 0 12px;
  }
  .mail-filter.is-open .mail-filter-active {
    height: 18px;
  }
  .mail-filter-stack {
    bottom: 22px;
  }
  .mail-filter-opt {
    height: 18px;
  }
  .mail-header-right {
    align-items: center;
    gap: 8px;
  }

  /* --- aut\ panel: span edge-to-edge with internal padding preserved --- */
  .query-panel {
    margin-left: var(--side-gutter);
    margin-right: var(--side-gutter);
    width: calc(100% - 2 * var(--side-gutter));
    max-width: 100vw;
    box-sizing: border-box;
  }
  /* Prevent iOS Safari from zooming on input focus while keeping the visual
     font size unchanged. iOS only auto-zooms when the source font-size is
     < 16px, so we set 16px (zoom suppressed) and then transform-scale the
     element back down to its original visual size. transform-origin is left
     center so the cursor and placeholder don't drift. width: 160% combined
     with scale(0.625) keeps the visible box exactly 100% of its parent. */
  .query-input,
  .nav-search-input,
  .event-tag-input,
  .compose-subj-input,
  .ai-rate-feedback,
  .to-pill-input {
    font-size: 16px !important;
    transform: scale(0.625);
    transform-origin: left center;
    width: 160% !important;
  }
  /* Parents need overflow:hidden so the scaled 160%-wide input doesn't push
     past the container before the visual scale brings it back to 100%. */
  .nav-search-pill-inner,
  .query-input-row,
  .compose-subj-bar {
    overflow: hidden;
  }

  /* aut\ compose row — back to the row-scale approach (visual font ~10px,
     matching the rest of the modal). transform-origin: left top so visual
     top = layout top, then a negative margin-bottom soaks up the empty
     layout space below the visual content. Pairs with neighboring margins
     zeroed (compose-addr below, compose-subj-bar above) so the visible gap
     above and below the row lands at exactly 10px. */
  .compose-prompt-row {
    transform: scale(0.625);
    transform-origin: left top;
    width: 160% !important;
    height: 56px !important;
    align-items: stretch;
    margin-top: 10px;
    /* layout 56px × (1 - 0.625) = 21px of empty space below visual content;
       margin-bottom = 10 (target visual gap) - 21 (empty space) = -11px */
    margin-bottom: -11px;
  }
  .compose-prompt {
    font-size: 16px !important;
    padding: 10px 12px !important;
    min-height: 0 !important;
    height: 100% !important;
  }
  .compose-go {
    font-size: 16px !important;
    width: auto !important;
    padding: 0 18px !important;
    min-width: 0;
  }
  .compose-addr {
    margin-bottom: 0 !important;
  }
  .compose-subj-bar {
    margin-top: 0 !important;
  }

  /* Switch compose-addr to a 2-column grid so FROM + pill share row 1 and
     TO + address-pill share row 2. max-content columns + justify-content
     start = each column hugs its content's natural width and the rows
     start at the left edge. column-gap: 10px puts each pill exactly 10px
     to the right of FROM / TO. */
  .compose-addr {
    display: grid !important;
    grid-template-columns: max-content max-content;
    justify-content: start;
    column-gap: 10px;
    row-gap: 6px;
  }
  .compose-addr > .compose-addr-label {
    margin: 0 !important;
  }
  .compose-addr > .compose-pill,
  .compose-addr > .compose-to-pills {
    justify-self: start;
    flex-basis: auto;
    min-width: 0 !important;
    flex: 0 0 auto !important;
    width: auto !important;
  }
  /* Address pill: shrink everything in the chain — the .compose-to-pills
     container, the .to-pill wrapper, and the .to-pill-input itself — so
     the pill hugs the "address here" placeholder. Fixed 90px on the input
     because :is-editing pill bg makes mismeasurement very visible. */
  .compose-to-pills > .to-pill {
    width: auto !important;
    max-width: max-content;
    flex: 0 0 auto !important;
  }
  .compose-to-pills .to-pill-input {
    min-width: 0 !important;
    width: 90px !important;
    max-width: 90px;
  }

  /* --- Nav search dropdown: span viewport edge-to-edge with internal padding.
         Pill itself gets more internal vertical padding and a fully-rounded
         radius so it stays a true pill shape at the larger height. --- */
  .nav-search-wrap {
    position: fixed;
    top: 50px;
    left: var(--side-gutter);
    right: var(--side-gutter);
    width: auto;
  }
  .nav-search-wrap.is-open {
    max-height: 50px;
  }
  .nav-search-pill-inner {
    height: 38px;
    padding: 0 16px;
    border-radius: 999px;
  }

  /* --- Edge-to-edge treatment for trays that aren't already wrapped in
         .card-wrap (Needs Review, GI contacts, Payment Review). The Match
         Review tray already lives inside a .card-wrap so it inherits the
         existing card-wrap bleed. Apply the same negative-margin pattern. --- */
  #needs-review-tray:not(:empty),
  #gi-contacts-tray:not(:empty),
  #payment-review-tray:not(:empty) {
    margin-left:  calc(-1 * var(--side-gutter));
    margin-right: calc(-1 * var(--side-gutter));
    width: calc(100% + 2 * var(--side-gutter));
    max-width: 100vw;
    box-sizing: border-box;
  }

  /* --- Mail thread rows: edge-to-edge + stack date/name on top of body
         (matches the card-body stacking pattern). --- */
  .mail-thread-rows {
    margin-left:  calc(-1 * var(--side-gutter));
    margin-right: calc(-1 * var(--side-gutter));
    width: calc(100% + 2 * var(--side-gutter));
    max-width: 100vw;
    box-sizing: border-box;
  }
  .mail-thread-row {
    flex-direction: column;
    align-items: stretch;
  }
  .thread-row-left {
    width: 100%;
    min-width: 0;
    padding: 10px var(--card-pad-r) 0 var(--card-pad-l);
    flex-direction: row;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
  }
  .thread-row-from {
    margin-top: 0;
  }
  .thread-row-body {
    padding: 6px var(--card-pad-r) 12px var(--card-pad-l);
  }

  /* --- Mail terminal: pull scroll dots inside viewport, respecting padding --- */
  .terminal-rail {
    right: var(--card-pad-r);
  }
  .mail-terminal .scroll-dots {
    right: var(--card-pad-r);
  }

  /* --- Minimize circle: move inside container at top-right with the same
         inset padding as everything else (was hanging off the edge at -7.5px). --- */
  .terminal > .btn-minimize {
    top: var(--card-pad-t);
    right: var(--card-pad-r);
    transform: none;
  }
  .mail-thread-rows > .btn-minimize {
    top: var(--card-pad-t);
    right: var(--card-pad-r);
    bottom: auto;
    left: auto;
    transform: none;
  }

  /* --- Draft Reply: zero out compose-shell padding so the only inset is the
         terminal's own card-pad-* (matches the rest of the card edges).
         !important required because index.html's inline <style> block sets
         padding: 18px 22px on .compose-shell.is-draft and is loaded after
         components.css, so it would otherwise win the cascade. --- */
  .terminal[data-panel="draft"] {
    padding: var(--card-pad-t) var(--card-pad-r) var(--card-pad-t) var(--card-pad-l) !important;
  }
  .compose-shell.is-draft {
    padding: 0 !important;
  }
  .compose-shell.is-draft .compose-minimize {
    top: 0 !important;
    right: 0 !important;
    transform: none !important;
  }

  /* --- New Message modal (.compose-shell, not is-draft): match the same
         internal padding tokens as everything else, and pin the X close
         button to the top-right inside that padding (was floating off the
         middle-right edge). --- */
  .compose-shell:not(.is-draft) {
    padding: var(--card-pad-t) var(--card-pad-r) var(--card-pad-t) var(--card-pad-l) !important;
  }
  .compose-shell:not(.is-draft) .compose-minimize {
    top: var(--card-pad-t) !important;
    right: var(--card-pad-r) !important;
    transform: none !important;
  }

  /* --- Belt-and-suspenders: prevent horizontal scroll --- */
  html, body { max-width: 100vw; overflow-x: hidden; }
}

/* Above the breakpoint, hide the action-row copy of EVENT DAY so the
   inline-with-name copy keeps the existing desktop look. */
@media (min-width: 641px) {
  .card-btns > .event-day-pill { display: none; }
}
/* === END MOBILE V2 === */

