/* ==========================================================================
   Phones, tablets and the installed app. Loaded LAST so it can override.

   Breakpoints
     <= 1100px  tablet landscape: compact top bar (in shell.css)
     <= 860px   tablet portrait: sidebar becomes a slide-in drawer (in shell.css)
     <= 760px   PHONE: everything below. A bottom tab bar replaces the sidebar,
                tables become cards, forms and menus slide up as sheets,
                detail panels go full screen.

   Nothing outside a media query changes how the desktop looks, except the
   harmless touch niceties at the top.
   ========================================================================== */

/* ---------- Touch niceties (all sizes) ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* The app is an app, not a web page: no pinch-zoom, no sideways drift. Scrolling still works. */
html, body { touch-action: pan-x pan-y; overscroll-behavior-x: none; }
.app, .main { max-width: 100%; overflow-x: clip; }
button, a, [role="button"], .clickable, .chip, .seg button, .tcard, .lcard {
  touch-action: manipulation;                  /* no 300ms double-tap-zoom delay */
  -webkit-tap-highlight-color: transparent;
}
/* Installed from the home screen: stop the page rubber-banding / pull-to-refresh by accident. */
html.standalone body { overscroll-behavior-y: none; }

/* A bigger invisible tap area around the small checkboxes, without changing how they look. */
.check::after { content: ''; position: absolute; inset: -10px; }

/* One-tap "move to next stage" on task cards. Drag & drop is fiddly on a phone. */
.tk-advance {
  display: none; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-strong);
  border: 1px solid var(--primary-ring); font: 650 11.5px var(--font); cursor: pointer; white-space: nowrap;
}
.tk-advance svg { width: 12px; height: 12px; }
@media (hover: none), (max-width: 760px) { .tk-advance { display: inline-flex; } }

/* Hover effects stay "stuck" after a tap on touch screens; switch them off there. */
@media (hover: none) {
  .card.hoverable:hover, .hs:hover, .acct:hover, .tl-row:hover, .tier-pick:hover { transform: none; }
}

/* The tab bar and "More" sheet only exist on phones. */
.bnav { display: none; }

/* ---------- "More" sheet (opened from the tab bar) ---------- */
.sheet {
  position: fixed; z-index: 71; left: 0; right: 0; bottom: 0;
  max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border: 1px solid var(--border-strong); border-bottom: 0;
  border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  animation: sheetUp 380ms var(--ease-out);
}
.sheet.closing { transform: translateY(105%); transition: transform 260ms var(--ease); }
@keyframes sheetUp { from { transform: translateY(100%); } }
.sheet button:focus, .sheet a:focus { outline: none; }
.sheet-grip { width: 38px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 4px auto 14px; }
.sheet-user { display: flex; align-items: center; gap: 12px; padding: 12px; margin-bottom: 14px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
.sheet-user > div { flex: 1; min-width: 0; }
.sheet-user b { display: block; font-size: 15px; font-weight: 650; }
.sheet-user span { font-size: 12.5px; color: var(--text-3); }
.sheet-user > svg { width: 18px; height: 18px; color: var(--text-3); }
.sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.sheet-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 4px;
  border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11.5px; font-weight: 600; color: var(--text-2); text-align: center;
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast);
}
.sheet-tile:active { transform: scale(.95); }
.sheet-tile .st-ic { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--primary-soft); color: var(--primary-strong); }
.sheet-tile .st-ic svg { width: 21px; height: 21px; }
.sheet-tile.on { border-color: var(--primary-ring); color: var(--text); }
.sheet-list { display: grid; gap: 2px; }
.sheet-row { display: flex; align-items: center; gap: 14px; width: 100%; height: 52px; padding: 0 12px; border-radius: 14px; font-size: 15px; font-weight: 550; color: var(--text); text-align: left; }
.sheet-row svg { width: 20px; height: 20px; color: var(--text-3); }
.sheet-row:active { background: var(--surface-3); }
.sheet-row.danger, .sheet-row.danger svg { color: var(--danger); }

/* ==========================================================================
   PHONE
   ========================================================================== */
@media (max-width: 760px) {

  /* ----- Shell: no sidebar, a bottom tab bar instead ----- */
  .sidebar, .sb-scrim, #sbToggle { display: none !important; }

  .topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 35;
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 10px 0 16px;
    gap: 4px;
  }
  .tb-title { flex: 1; }
  /* The page already has its own big heading just below: repeating it up here only made the bar tall. Show the logo instead. */
  .tb-title h1, .tb-title p { display: none; }
  .tb-title::before { content: ''; display: block; width: 30px; height: 30px; background: url(../assets/evexa-mark.png) center / contain no-repeat; }
  .tb-search { margin-left: 0; width: 42px; height: 42px; border-color: transparent; background: transparent; border-radius: 12px; }
  .tb-search svg { width: 20px; height: 20px; }
  .tb-actions { gap: 2px; }
  .icon-btn { width: 42px; height: 42px; }
  #quickAddBtn { width: 38px; height: 38px; padding: 0; justify-content: center; border-radius: 12px; }

  .main { padding-top: calc(52px + env(safe-area-inset-top, 0px)); }
  .content { padding: 16px 14px calc(92px + env(safe-area-inset-bottom, 0px)); }

  .bnav {
    display: flex; align-items: stretch; justify-content: space-around;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(160%) blur(18px); -webkit-backdrop-filter: saturate(160%) blur(18px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -12px 32px -14px rgba(0, 0, 0, .4);
    transition: transform var(--t) var(--ease);
  }
  body.auth-mode .bnav { display: none; }
  body.kbd-open .bnav { transform: translateY(110%); }       /* tuck away while the keyboard is up */

  .bn-item {
    position: relative; flex: 1; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 5px 2px 3px; border-radius: 14px;
    color: var(--text-3); font: 600 10.5px var(--font);
  }
  .bn-ic { position: relative; display: grid; place-items: center; width: 48px; height: 28px; border-radius: 14px; transition: background var(--t) var(--ease), transform var(--t) var(--spring); }
  .bn-ic svg { width: 21px; height: 21px; }
  .bn-item.active { color: var(--primary-strong); }
  .bn-item.active .bn-ic { background: var(--primary-soft); }
  .bn-item:active .bn-ic { transform: scale(.9); }
  .bn-dot { position: absolute; top: 1px; right: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--surface); }

  /* Toasts sit above the tab bar, never under it */
  .toasts { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); width: max-content; max-width: calc(100vw - 24px); }
  .toast { max-width: 100%; }

  /* ----- Page furniture ----- */
  .page-head { margin-bottom: 14px; gap: 12px; }
  .page-head h2 { font-size: 22px; }
  .page-head p { font-size: 13px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; justify-content: center; }

  .card-head { padding: 14px 16px 0; }
  .card-body { padding: 12px 16px 16px; }
  .card-pad { padding: 16px; }

  /* ----- Forms: 16px text stops iOS zooming the page when you tap a field ----- */
  .input, .select, .textarea, .search-in input, .tl-add input, .auth-in input, .cmdk-in input { font-size: 16px; }
  .input, .select { height: 46px; }
  .select-sm { height: 40px; }
  .search-in { height: 44px; }
  .btn { min-height: 42px; }
  .btn-sm { height: 38px; }
  .btn-xs { height: 32px; }

  /* Filter chips become one swipeable row instead of wrapping into a tall block */
  .toolbar { gap: 8px; }
  .toolbar .chips {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    width: calc(100% + 28px); margin: 0 -14px; padding: 2px 14px;
  }
  .toolbar .chips::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; height: 36px; }
  .toolbar .select-sm { flex: 1 1 calc(50% - 4px); min-width: 0; }

  /* ----- Numbers ----- */
  .kpis, .kpis.five { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpis.five > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 20px; }
  .fx-bar { gap: 8px 12px; padding: 10px 12px; }
  .fx-pick { width: 100%; }
  .fx-pick .select { min-width: 0; flex: 1; }
  .fx-bar .link-btn { margin-left: 0; }

  /* ----- Tables become cards ----- */
  .table-wrap { overflow: visible; }
  .table, .table tbody { display: block; }
  .table thead { display: none; }
  .table tr {
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; row-gap: 8px;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
  }
  .table tr:last-child { border-bottom: 1px solid var(--border); }
  .table tr.grp { display: block; padding: 14px 16px 4px; border-bottom: 0; }
  .table td { display: block; padding: 0; border: 0; min-width: 0; text-align: left !important; }
  .table td:first-child { grid-column: 1 / -1; }
  .table td[data-label]:not(:first-child)::before {
    content: attr(data-label); display: block; margin-bottom: 3px;
    font: 600 10px var(--font); letter-spacing: .09em; text-transform: uppercase; color: var(--text-3);
  }
  /* task list: [tick] title on top, the details in two columns below */
  .task-table tr { grid-template-columns: 34px 1fr 1fr; }
  .task-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .task-table td:nth-child(2) { grid-column: 2 / -1; grid-row: 1; }
  .task-table td:nth-child(2)::before { display: none; }
  .task-table td:nth-child(3) { grid-column: 2; grid-row: 2; }
  .task-table td:nth-child(4) { grid-column: 3; grid-row: 2; }
  .task-table td:nth-child(5) { grid-column: 2; grid-row: 3; }
  .task-table td:nth-child(6) { grid-column: 3; grid-row: 3; }

  /* ----- Boards: swipe between columns, edge to edge ----- */
  .board { margin: 0 -14px; padding: 0 14px 10px; scroll-padding-left: 14px; -webkit-overflow-scrolling: touch; }
  .board .col { min-height: 260px; }
  .pipeline .col { min-height: 320px; }

  /* ----- Calendar: scroll sideways rather than squash seven days into 360px ----- */
  .cal-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal-grid { min-width: 640px; }

  /* ----- Overlays ----- */
  /* Forms slide up from the bottom like a native sheet */
  .modal {
    left: 0; right: 0; top: auto; bottom: 0; width: 100%;
    max-height: 92vh; max-height: 92dvh;
    border-radius: 22px 22px 0 0; border-bottom: 0;
    transform: none;
    animation: sheetUp 380ms var(--ease-out);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .modal.closing { opacity: 1; transform: translateY(100%); transition: transform 240ms var(--ease); }
  .modal-head { padding: 18px 18px 4px; }
  .modal-body { padding: 14px 18px; }
  .modal-foot { padding: 12px 18px 16px; }
  .modal-foot .btn:not(.btn-ghost), .modal-foot .btn.btn-ghost:not(.btn-danger) { flex: 1; justify-content: center; }

  /* Detail panels fill the screen */
  .drawer {
    top: 0; right: 0; bottom: 0; left: 0; width: 100%;
    border: 0; border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .drawer-head { padding: 12px 14px; }
  .drawer-body { padding: 16px 16px 28px; }

  .popover { max-width: calc(100vw - 24px); }
  .cmdk { top: calc(env(safe-area-inset-top, 0px) + 10px); width: calc(100vw - 20px); }
  .cmdk-list { max-height: 62vh; }
  .cmdk-foot { display: none; }

  /* ----- Settings ----- */
  .set-hero { padding: 18px 16px; }
  .sh-inner { gap: 14px; }
  .sh-stats { width: 100%; margin-left: 0; display: grid; grid-template-columns: repeat(3, 1fr); }
  .sh-stats > div { min-width: 0; padding: 10px; }
  .set-tabs { display: flex; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .set-tabs::-webkit-scrollbar { display: none; }
  .set-tabs button { flex-shrink: 0; }
  .set-card { padding: 16px; }
  .set-row { flex-wrap: wrap; }
  .acct { flex-wrap: wrap; }

  /* ----- Sign-in: layout lives in auth.css; only the card's inner spacing here ----- */
  .auth-card { padding: 24px 20px 20px; }

  /* ----- Smoothness: drop the effects a phone GPU struggles with ----- */
  /* Frosted-glass blur re-computes on every scroll frame. Solid colours look the same here and cost nothing. */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .bnav { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--surface); }
  .hs, .sh-stats > div { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .overlay { backdrop-filter: none; -webkit-backdrop-filter: none; }
  /* Big blurred glows that drift forever: keep the glow, stop the motion and the blur. */
  .hero-glow, .sh-orbs i, .tc-orbs i { animation: none; filter: none; }
}

/* A very small phone: tighten the tab bar labels a touch */
@media (max-width: 360px) {
  .bn-label { font-size: 9.5px; }
  .sheet-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Landscape phone: the tab bar would eat half the screen */
@media (max-width: 900px) and (max-height: 480px) {
  .bnav { padding-top: 2px; padding-bottom: calc(2px + env(safe-area-inset-bottom, 0px)); }
  .bn-label { display: none; }
  .bn-ic { height: 32px; }
}

/* ==========================================================================
   PHONE: the Routine page's "today" timeline
   The desktop row is [tick][time range][icon][title][NOW][edit][delete] in one
   line, which leaves the title a sliver. On a phone it becomes two lines:
   time on top, title below, with the actions on the right.
   ========================================================================== */
@media (max-width: 760px) {
  .today-card { padding: 16px 14px 6px; border-radius: 20px; }
  .tc-head { gap: 14px; padding-bottom: 14px; }
  .tc-when h3 { font-size: 20px; }
  .tc-ring { margin-left: auto; }
  .tc-next { margin-left: 0; width: 100%; min-width: 0; }
  .tc-bell { width: 100%; justify-content: center; height: 40px; }

  .tl-block-head { padding-left: 22px; }
  .tl-block::before { left: 8px; }
  .tl-row {
    display: grid; grid-template-columns: 26px minmax(0, 1fr) auto auto; column-gap: 10px; row-gap: 3px;
    align-items: start; margin-left: 22px; padding: 12px 6px 12px 10px;
  }
  .tl-row::before { left: -18px; }
  .tl-row .check { grid-column: 1; grid-row: 1 / 3; align-self: center; }
  .tl-row .tl-time { grid-column: 2; grid-row: 1; min-width: 0; font-size: 11.5px; }
  .tl-badge { grid-column: 3; grid-row: 1; justify-self: end; }
  .tl-pip { display: none; }
  .tl-main { grid-column: 2 / 4; grid-row: 2; }
  .tl-acts { grid-column: 4; grid-row: 1 / 3; align-self: center; }
  .tl-act { width: 36px; height: 36px; }
  .tl-add, .tl-newblock, .tl-now { margin-left: 22px; }
  .tl-hint { padding-left: 22px; }
}
/* The "this month vs budget" card has a ring plus three lines of text: give it a whole row. */
@media (max-width: 760px) {
  .kpi.exp-budget { grid-column: 1 / -1; }
}
/* Client panel: the "charged - cost = kept" table. Four number columns do not fit in 360px,
   so each row becomes: the label (with its margin) on top, then three captioned figures. */
@media (max-width: 760px) {
  .pf-head { display: none; }
  .pf-row { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 6px; padding: 12px; }
  .pf-label { grid-column: 1 / 3; font-weight: 600; color: var(--text); }
  .pf-pct { grid-column: 3; grid-row: 1; text-align: right; }
  .pf-rev, .pf-cost, .pf-net { display: block; font-size: 13px; min-width: 0; }
  .pf-rev::before, .pf-cost::before, .pf-net::before {
    display: block; margin-bottom: 2px; font: 600 9.5px var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
  }
  .pf-rev::before { content: 'Charged'; }
  .pf-cost::before { content: 'Cost'; }
  .pf-net::before { content: 'Kept'; }
  .pf-total { padding: 12px; }
  .pf-actual { font-size: 12px; }
}
/* Invoice meta ("Collected Aug 15 · due Aug 13"): wrap as whole pieces, never one word per line. */
.pay-meta { flex-wrap: wrap; row-gap: 2px; }
.pay-meta .faint, .pay-meta .pill { white-space: nowrap; }