/* The single phone breakpoint lives in phone.js / the boot script. Every layout rule
   is gated by that same .phone class, including APK and screenshot forced mode. */
.phone-only, .phone-backdrop { display: none !important; }

html.phone { min-width: 0; overscroll-behavior: none; }
html.phone body { min-width: 0; width: 100%; overscroll-behavior: none; }
html.phone .phone-only { display: flex !important; }
html.phone .shell {
  position: fixed; left: 0; right: 0; top: var(--phone-top, 0px);
  height: var(--phone-height, 100dvh); min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  padding-top: env(safe-area-inset-top);
  contain: layout paint;
}
html.phone .view-enter { animation: none; }
html.phone .stage { min-width: 0; min-height: 0; }
html.phone .stage.flush { grid-template-rows: auto minmax(0, 1fr); }
html.phone .shell.full-page .stage.flush { grid-template-rows: minmax(0, 1fr); }
html.phone .shell.full-page .rail { display: none; }
html.phone :is(input, textarea, select) { font-size: 16px !important; }
html.phone button, html.phone summary, html.phone [role="button"] { min-height: 44px; min-width: 44px; }
html.phone button { touch-action: manipulation; }
html.phone :is(.m-field, .pick-btn, .pick-opt) { min-height: 44px; }
html.phone .m-switch-wrap { min-width: 44px; min-height: 44px; }
html.phone :is(.copybtn, .forkbtn, .rail-agent-config, .session-tab-close, .usage-resize) { opacity: 1; pointer-events: auto; }
html.phone :is(.msgs, .agents, .rpanel-body, .page, .usage-page, .agents-view) { overscroll-behavior: contain; }

/* One app bar: drawer, the current tab (tap for the tab list, swipe sideways for the next tab), tab count, plan. */
html.phone .topbar { display: flex; align-items: center; height: 52px; min-height: 52px; gap: 0; padding: 0 4px; border-bottom: 1px solid var(--border); touch-action: pan-y; }
html.phone #phoneRailButton { flex: none; padding: 0; font-size: 20px; }
html.phone .topbar > :is(.session-tabs, .link-meter, #usagesButton, button:not(.phone-only)) { display: none !important; }
html.phone .phone-tab-title { flex: 1 1 auto; min-width: 0; align-items: center; gap: 6px; padding: 0 8px; border: 0; background: none; color: var(--fg); font: inherit; text-align: left; }
html.phone .phone-tab-text { display: grid; min-width: 0; line-height: 1.25; }
html.phone .phone-tab-name { overflow: hidden; font-size: 15px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
html.phone .phone-tab-sub { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
html.phone .phone-tab-sub:empty { display: none; }
html.phone .phone-tab-caret { flex: none; color: var(--muted); font-size: 11px; }
/* The count square: a 44 px target with a 24 px outlined box, accent when a background tab finished. */
html.phone .phone-tab-count { flex: none; align-items: center; justify-content: center; padding: 0; border: 0; background: none; color: var(--fg); font: 600 12px var(--mono); box-shadow: inset 0 0 0 10px var(--bg), inset 0 0 0 11.5px currentColor; }
html.phone .phone-tab-count.busy { color: var(--accent); }
html.phone #phonePlanButton { flex: none; gap: 6px; padding-inline: 8px; }
html.phone .phone-plan-count { display: grid; place-items: center; min-width: 22px; padding: 1px 5px; color: var(--accentInk); background: var(--accent); font-size: 11px; }
html.phone .view { grid-template-rows: minmax(0, 1fr); }
html.phone .view.phone-swiping { transition: none; will-change: transform; }
html.phone .view.phone-in-right { animation: phone-in-right 240ms var(--ease); }
html.phone .view.phone-in-left { animation: phone-in-left 240ms var(--ease); }
@keyframes phone-in-right { from { transform: translateX(40%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes phone-in-left { from { transform: translateX(-40%); opacity: 0; } to { transform: none; opacity: 1; } }

/* The tab list: a full-height sheet of big rows. */
html.phone .overlay.phone-tabs-sheet { place-items: stretch; padding: 0; }
html.phone .phone-tabs-sheet .sheet { width: 100%; height: 100%; max-height: none; border: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
html.phone .phone-tabs-sheet .sheet-body { padding: 8px 0 16px; gap: 0; align-content: start; }
html.phone .phone-tabs-list { display: grid; }
html.phone .phone-tabs-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
html.phone .phone-tabs-row.on { box-shadow: inset 3px 0 0 var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
html.phone .phone-tabs-pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 16px; border: 0; background: none; color: var(--fg); font: inherit; text-align: left; }
html.phone .phone-tabs-icon { flex: none; display: grid; place-items: center; width: 24px; }
html.phone .phone-tabs-text { display: grid; min-width: 0; gap: 2px; }
html.phone .phone-tabs-text b { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
html.phone .phone-tabs-text small { color: var(--muted); font-size: 12px; }
html.phone .phone-tabs-close { flex: none; width: 56px; border: 0; background: none; color: var(--muted); font-size: 20px; }
html.phone .phone-tabs-new { margin: 16px 16px 0; width: auto; }

html.phone .chat-stage { overflow: hidden; }
/* The AI's header is one row: who, main or not, state, and ⋯ for Terminal, Edits, Shell and tokens. */
html.phone .chat-head { height: 48px; min-height: 48px; flex-wrap: nowrap; gap: 8px; padding: 0 4px 0 12px; }
html.phone .ch-who { flex: 0 1 auto; min-width: 0; }
html.phone .ch-who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html.phone .ch-who small { display: none; }
html.phone .chat-head .grow { display: block; flex: 1; }
html.phone .chat-head > :is(.ch-task, .ch-tokens, .context-meter-wrap, .pane-switch, .m-btn.compact) { display: none !important; }
html.phone .chat-head .status-pill { flex: none; }
html.phone .ch-more { flex: none; padding: 0; font-size: 20px; letter-spacing: 1px; }
html.phone .chat-stage .rpanel-zero-btn { display: none; }
html.phone .chat-stage > .chat > .msgs { padding: 12px; gap: 14px; }
/* Rows off screen skip layout and paint: switching to a long chat lays out only what shows. */
html.phone .msgs > * { content-visibility: auto; contain-intrinsic-size: auto 160px; }
html.phone :is(.bubble, .txt, .sender, .tool, .tool-body) { max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
html.phone .bubble { max-width: 92%; overflow-x: auto; }
html.phone :is(.txt pre:not(.code-block), .txt table, .tablewrap, .md-table, .rich-table) { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
html.phone .txt table { display: block; }
html.phone pre.code-block { padding-top: 62px !important; }
html.phone .code-copy { top: 8px !important; opacity: 1; pointer-events: auto; }
html.phone .composer-wrap { padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--bg); }
html.phone.phone-keyboard .composer-wrap { padding-bottom: 8px; }
html.phone .chat-stage .composer { width: calc(100% - 24px); margin-inline: 12px; padding: 6px; gap: 6px; }
html.phone .composer textarea { max-height: min(140px, 25dvh); }
html.phone .chat-stage :is(.composer-foot, .attach-strip) { margin-inline: 12px; }
html.phone .composer-agent-label { display: none; }
html.phone .composer-foot { flex-wrap: wrap; gap: 4px; }
html.phone .composer-toolbar { flex-wrap: wrap; justify-content: flex-start; gap: 4px; margin-left: 0; max-width: 100%; }
html.phone .quiet-chip { max-width: 100%; white-space: normal; text-align: left; font-size: 11px; }
html.phone .model-effort-menu { width: min(360px, calc(100vw - 24px)); max-height: calc(var(--phone-height, 100dvh) - 160px); }
html.phone .work-indicator { width: calc(100% - 24px); margin-inline: 12px; padding: 2px 8px; max-height: 64px; overflow-y: auto; font-size: 12px; }
html.phone .work-indicator .work-line { min-height: 28px; }

/* Typing: the keyboard takes half the screen, so only the bar, the conversation and the composer stay. */
html.phone.phone-keyboard .chat-head,
html.phone.phone-keyboard .work-indicator,
html.phone.phone-keyboard .composer-foot { display: none !important; }
html.phone.phone-keyboard .topbar { height: 44px; min-height: 44px; }
html.phone.phone-keyboard .phone-tab-sub { display: none; }

/* A drag writes only a progress value; both drawers and the scrim follow the finger. */
html.phone .phone-backdrop { display: block !important; position: fixed; inset: 0; z-index: 14; border: 0; padding: 0; background: color-mix(in srgb, var(--bg) 70%, transparent); opacity: 0; visibility: hidden; transition: opacity 180ms var(--ease), visibility 180ms; }
html.phone :is(.rail, .rpanel) { position: fixed; top: 0; bottom: auto; height: 100%; width: min(336px, calc(100vw - 48px)) !important; z-index: 15; visibility: hidden; transition: transform 180ms var(--ease), visibility 180ms; padding-top: env(safe-area-inset-top); padding-bottom: max(12px, env(safe-area-inset-bottom)); background: var(--surface); }
html.phone .rail { left: 0; transform: translateX(-100%); }
html.phone .rpanel { right: 0; transform: translateX(100%); box-shadow: none; }
html.phone[data-phone-drawer="left"] .rail { visibility: visible; transform: translateX(calc((var(--phone-drawer-progress, 1) - 1) * 100%)); }
html.phone[data-phone-drawer="right"] .rpanel { visibility: visible; transform: translateX(calc((1 - var(--phone-drawer-progress, 1)) * 100%)); }
html.phone:is([data-phone-drawer="left"], [data-phone-drawer="right"]) .phone-backdrop { visibility: visible; opacity: var(--phone-drawer-progress, 1); }
html.phone.phone-dragging :is(.rail, .rpanel, .phone-backdrop) { transition: none; }
html.phone .phone-rail-close { flex: none; align-self: flex-end; margin: 8px 12px; }
html.phone .brand { padding: 8px 20px 20px; }
html.phone .agents { flex: 1; overflow-y: auto; }
html.phone .agent { padding: 10px 52px 10px 12px; min-height: 64px; gap: 8px; font-size: 13px; }
html.phone .agent-text b { font-size: 13px; }
html.phone .lvls { display: flex; }
html.phone .rail-agent-config { width: 44px; }
html.phone .phone-navigation { flex: none; flex-direction: column; padding: 8px; border-top: 1px solid var(--border); }
html.phone .phone-navigation button { justify-content: flex-start; }
html.phone .rail-foot { flex: none; margin-top: 0; }
html.phone .rpanel :is(.rpanel-resizer, .rpanel-toggle, .rpanel-rail-btn) { display: none; }
html.phone .rpanel-head { flex: none; height: 60px; padding-inline: 16px 8px; }
html.phone .rpanel-head b { font-size: 14px; }
html.phone .rpanel .rpanel-body { display: grid; }
html.phone .rp-section:has(.rp-empty) { display: none; }

html.phone :is(.page, .usage-page, .agents-view, .term-page) { padding: 16px 12px max(16px, env(safe-area-inset-bottom)); overflow-x: hidden; }
html.phone .phone-agents-back { margin-bottom: 16px; }
html.phone .page-back { flex-wrap: wrap; }
html.phone :is(.settings-title, .section-head, .usage-title) { flex-direction: column; align-items: stretch; }
html.phone :is(.tasks-fields, .provider-grid, .about-card, .account-card, .ag-grid, .usage-grid, .usage-periods, .usage-peak-card, .edits-workspace) { grid-template-columns: minmax(0, 1fr) !important; }
html.phone .about-motto { grid-column: 1; grid-row: auto; }
html.phone :is(.account-actions, .account-head, .settings-section .section-head, .skill-title, .usage-total, .usage-toolbar) { flex-wrap: wrap; }
html.phone .account-actions { justify-content: flex-start; }
html.phone :is(.settings-section, .usage-account) { padding: 12px; }
html.phone .skill-row { grid-template-columns: minmax(0, 1fr); }
html.phone .skill-actions { justify-content: flex-start; }
html.phone .usage-grid .usage-account { grid-column: auto !important; grid-row: auto !important; width: auto !important; height: auto !important; max-width: none; }
html.phone .usage-grid { display: grid; }
html.phone .usage-grid .usage-token-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
html.phone .usage-resize { position: static; justify-self: end; width: auto; height: auto; padding: 0 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: 11px var(--mono); }
html.phone .usage-tool-table { display: block; max-width: 100%; overflow-x: auto; }
html.phone .overlay { padding: 12px; }
html.phone :is(.sheet, .palette, .pick-list) { max-width: 100%; }
html.phone .sheet header { padding: 10px 12px; }
html.phone .sheet-body { padding: 12px; }
html.phone .term-pane { margin-inline: 12px; }
html.phone .phone-terminal-page { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px; }
html.phone .phone-terminal-page .term-pane { margin: 0; }
html.phone .term-bar { height: auto; min-height: 44px; flex-wrap: wrap; padding-block: 4px; }
html.phone .page.edits-page { padding: 16px 12px; }
html.phone .edits-workspace { min-height: 0; }
html.phone .diff-head { flex-wrap: wrap; gap: 8px; }
html.phone .diff-actions { margin-left: 0; flex-wrap: wrap; width: 100%; }
html.phone .diff-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(88px, 30%) minmax(0, 1fr); min-height: 0; }
html.phone .diff-files { border-right: 0; border-bottom: 1px solid var(--border); }
html.phone .toasts { bottom: max(12px, env(safe-area-inset-bottom)); }
html.phone .asks, html.phone body:has(.rpanel:not(.collapsed)) .asks { right: 12px; width: calc(100vw - 24px); bottom: max(12px, env(safe-area-inset-bottom)); max-height: calc(var(--phone-height, 100dvh) - 24px); }
html.phone:is([data-phone-drawer="left"], [data-phone-drawer="right"]) .asks { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  html.phone :is(.rail, .rpanel, .phone-backdrop) { transition: none; }
}

/* Pages keep their Back bar on screen while the page scrolls, like a phone app's top bar. */
html.phone .page-back { position: sticky; top: -16px; z-index: 3; margin: -16px -12px 12px; padding: 4px 8px; background: var(--bg); border-bottom: 1px solid var(--border); }

/* Signed out (phone app, Metro in a browser): the whole window is the sign-in, laid out like Hourglass's (pages.css
   .login*) in Metro's purple (ui/signin-screen.js). Google's reCAPTCHA badge stays hidden; the card carries its line. */
.grecaptcha-badge { visibility: hidden !important; }
.login-wrap { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: grid; place-items: center; overflow-y: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); animation: fade-in 200ms var(--ease) both; }
.login { width: min(400px, calc(100vw - 48px)); display: grid; justify-items: center; gap: 10px; padding: 40px 0; text-align: center; }
.login-logo { width: 84px; height: 84px; image-rendering: pixelated; }
.login h1 { margin: 10px 0 0; font-size: 26px; }
.login h1 + .login-card { margin-top: 12px; }
.login-card { width: 100%; display: grid; gap: 14px; padding: 20px; text-align: left; background: var(--surface); border: 1px solid var(--border); }
.login-wrap [hidden] { display: none !important; }
.login-label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.login-label > span { font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: 11px; }
.login-field { width: 100%; height: 42px; font-size: 15px; }
.login-field:focus { border-color: var(--accent); }
.login-error { color: color-mix(in srgb, var(--accent) 62%, var(--fg)); font-size: 13px; }
.login-notice { color: var(--teal); font-size: 13px; line-height: 1.5; }
.login-submit { width: 100%; height: 44px; font-size: 14px; }
.login-rc-note { margin: 0; font-size: 11px; line-height: 1.4; text-align: center; color: var(--faint); }
.login-rc-note a { color: inherit; text-decoration: underline; }
.login-forgot-text { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.login-link { justify-self: center; padding: 4px; font-size: 13px; text-decoration: none; }
.login-link:hover { text-decoration: underline; text-decoration-color: var(--accent); }
