/* Duonexia Phone System — phone layout (mobile.js adds `layout-phone` on <html>).
   Every rule is scoped under .layout-phone so the desktop layout stays exactly as it was.
   One screen at a time (html[data-tab]) between a compact top bar and a bottom tab bar;
   incoming and in-call screens cover everything. Same tokens as style.css. */

.layout-phone {
  --tabbar-h: 64px;
  --gutter: 16px;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}
.layout-phone body {
  display: flex; flex-direction: column;
  height: var(--app-h, 100dvh); min-height: 0; padding: 0; overflow: hidden;
  background:
    radial-gradient(520px 300px at 0% -10%, rgb(255 90 31 / 0.10), transparent 60%),
    radial-gradient(480px 280px at 100% -12%, rgb(47 107 255 / 0.07), transparent 60%),
    var(--void);
}
.layout-phone button,
.layout-phone label,
.layout-phone select { touch-action: manipulation; }

/* ---------- compact top bar ---------- */
.layout-phone .topbar {
  flex: none; max-width: none; margin: 0; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) var(--gutter) 6px;
  border-bottom: 1px solid var(--line);
}
.layout-phone .brand { gap: 8px; flex: none; }
.layout-phone .brand-mark { width: 22px; height: 22px; }
.layout-phone .brand .word,
.layout-phone .brand .dot { font-size: 18px; }
.layout-phone .brand .product,
.layout-phone .line-number,
.layout-phone .profile-label { display: none; }
.layout-phone .topbar-right { flex: 1; min-width: 0; justify-content: flex-end; gap: 6px; }
.layout-phone .profile-switch { min-height: 48px; padding: 0 14px; font-size: 15px; flex: none; }
.layout-phone .profile-switch:active { border-color: var(--accent); background: var(--surface-2); }
/* The status reads as a dot beside the profile; its text only shows when something is off. */
.layout-phone .status-pill { order: -1; min-width: 0; padding: 0 4px; border: 0; background: none; }
.layout-phone #status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout-phone .status-pill[data-state="ready"] #status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- screens ---------- */
.layout-phone .layout { flex: 1; min-height: 0; display: block; max-width: none; margin: 0; position: relative; }
.layout-phone .side {
  height: 100%; gap: 14px; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px var(--gutter) 24px;
}
.layout-phone[data-tab="dialer"] .side,
.layout-phone:not([data-tab="dialer"]) #phone[data-view="dialer"],
.layout-phone:not([data-tab="recents"]) .history-card,
.layout-phone:not([data-tab="messages"]) .chat-card,
.layout-phone:not([data-tab="team"]) .team-card,
.layout-phone:not([data-tab="settings"]) :is(.settings-card, .forwarding-card, .sound-card, .app-version) { display: none; }

.layout-phone .side > *,
.layout-phone #phone[data-view="dialer"] { animation: tab-in 0.24s var(--ease); }
@keyframes tab-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Full-screen lists: no card chrome, a large title like a native app bar. */
.layout-phone :is(.history-card, .chat-card, .team-card) { background: none; border: 0; border-radius: 0; padding: 0; }
.layout-phone :is(.history-card, .chat-card, .team-card) .card-head { margin-bottom: 16px; }
.layout-phone :is(.history-card, .chat-card, .team-card, .settings-card) h2 {
  font: 800 30px/1.05 var(--font-display); letter-spacing: -0.04em; text-transform: none; color: var(--text);
}
.layout-phone :is(.history-card, .chat-card, .team-card, .settings-card) h2::after { content: "."; color: var(--accent); }

/* ---------- dialer tab ---------- */
.layout-phone #phone {
  height: 100%; min-height: 0; padding: 12px var(--gutter) 18px;
  background: none; border: 0; border-radius: 0; overflow: hidden;
}
.layout-phone #phone[data-view="dialer"]::before { display: none; }
.layout-phone .view { min-height: 100%; }
.layout-phone .view-dialer { gap: 0; }
/* The number sits right above the keypad, in the thumb's zone, like a native dialer. */
.layout-phone .display { flex: 1; align-items: flex-end; padding: 8px 0 14px; margin-bottom: clamp(12px, 2dvh, 20px); }
.layout-phone #number-input { font-size: clamp(30px, 9vw, 38px); padding-left: 48px; caret-color: var(--accent); }
.layout-phone #number-input::placeholder { font-size: 16px; }
.layout-phone .icon-btn { width: 48px; height: 48px; }
.layout-phone .icon-btn:active { background: var(--surface-2); color: var(--text); }

.layout-phone .keypad {
  width: 100%; max-width: 420px; margin-top: auto;
  grid-template-columns: repeat(3, 1fr); gap: clamp(10px, 1.6dvh, 16px) 14px;
}
.layout-phone .key { height: clamp(72px, 9.4dvh, 88px); }
.layout-phone .key .digit { font-size: 30px; }
.layout-phone .key .letters { font-size: 10px; margin-top: 6px; }
.layout-phone .key:hover { border-color: var(--line-2); }
.layout-phone .view-dialer .action-btn { width: 100%; max-width: 420px; height: 64px; margin-top: clamp(14px, 2.4dvh, 24px); font-size: 16px; }
.layout-phone .action-btn svg { width: 26px; height: 26px; }

/* Outgoing number: a full-width row above the number, big enough for a thumb. */
.layout-phone .outgoing-number {
  flex: none; max-width: 420px; min-height: 56px; padding: 8px 16px; border-radius: var(--radius-lg);
}
.layout-phone .outgoing-value b { font-size: 15px; }
.layout-phone .outgoing-digits { font-size: 14px; }
.layout-phone .call-via { font-size: 13px; }

/* ---------- incoming & in-call: over everything, tab bar included ---------- */
.layout-phone #phone:not([data-view="dialer"]) {
  position: fixed; inset: 0; z-index: 35; height: auto; overflow-y: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 28px) 24px calc(env(safe-area-inset-bottom, 0px) + 28px);
}
.layout-phone #phone[data-view="incoming"] {
  background: radial-gradient(130% 55% at 50% 0%, rgb(255 90 31 / 0.16), transparent 70%), var(--void);
}
.layout-phone #phone[data-view="incall"] {
  background: radial-gradient(130% 55% at 50% 0%, rgb(47 107 255 / 0.10), transparent 70%), var(--void);
}
.layout-phone #phone::before { left: 24px; top: env(safe-area-inset-top, 0px); }
.layout-phone .caller { width: 100%; padding-top: clamp(16px, 7dvh, 72px); }
.layout-phone .avatar { width: 112px; height: 112px; margin-bottom: 24px; }
.layout-phone .avatar svg { width: 44px; height: 44px; }
.layout-phone .caller-number { font-size: clamp(30px, 9.5vw, 42px); overflow-wrap: anywhere; }
.layout-phone .timer { font-size: 17px; margin-top: 12px; }

.layout-phone .incoming-actions { width: 100%; margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.layout-phone .view-incall > .action-btn,
.layout-phone .incoming-actions .action-btn { width: 100%; min-width: 0; height: 72px; font-size: 16px; }
.layout-phone .view-incall > .action-btn { margin-top: 20px; }

.layout-phone .controls { width: 100%; margin-top: auto; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.layout-phone .controls:has(#speaker-button:not([hidden])) { grid-template-columns: repeat(2, 1fr); }
.layout-phone .control { height: 76px; font-size: 11px; }
.layout-phone .control svg { width: 26px; height: 26px; }
.layout-phone .control:hover { border-color: var(--line-2); }
.layout-phone .control:not(:disabled):active { background: var(--line-2); }
#speaker-button[aria-pressed="true"] { border-color: var(--cold); background: rgb(47 107 255 / 0.14); color: #9db8ff; }
#speaker-button[aria-pressed="true"] svg { color: var(--cold); }

/* In-call keypad: the caller shrinks to name + timer to make room. */
.layout-phone .keypad.compact { margin-top: 20px; max-width: 360px; gap: 10px; }
.layout-phone .keypad.compact .key { height: 60px; }
.layout-phone .keypad.compact .digit { font-size: 24px; }
.layout-phone .view-incall:has(#dtmf-keypad:not([hidden])) .avatar { display: none; }
.layout-phone .view-incall:has(#dtmf-keypad:not([hidden])) .caller { padding-top: 8px; }

/* ---------- recents ---------- */
.layout-phone .history-card .tabs button { min-height: 48px; padding: 0 14px; }
.layout-phone .history { max-height: none; overflow: visible; margin: 0 calc(var(--gutter) * -1); }
.layout-phone .history li { grid-template-columns: 40px 1fr auto; min-height: 64px; padding: 10px var(--gutter); border-radius: 0; }
.layout-phone .history li:hover { background: none; }
.layout-phone .history li:active { background: var(--surface-2); }
.layout-phone .history .dir { width: 40px; height: 40px; }
.layout-phone .history .num { font-size: 17px; }

/* ---------- messages ---------- */
.layout-phone[data-tab="messages"] .side { overflow: hidden; display: flex; padding-bottom: 12px; }
.layout-phone .chat-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.layout-phone .chat-thread { flex: 1; min-height: 0; max-height: none; margin: 0 calc(var(--gutter) * -1); padding: 2px var(--gutter); }
.layout-phone .chat-with { font-size: 17px; }
.layout-phone .chat-tabs button { min-height: 48px; }
.layout-phone .chat-msg { max-width: 86%; }
.layout-phone .chat-text { font-size: 15px; }
.layout-phone .chat-photo { max-width: min(240px, 62vw); }
.layout-phone .chat-composer { flex: none; }
.layout-phone .chat-composer textarea { min-height: 48px; font-size: 16px; padding: 12px 14px; }
.layout-phone .chat-send { width: 48px; height: 48px; }

/* ---------- team ---------- */
.layout-phone .team { gap: 10px; }
.layout-phone .team li { padding: 14px; }
.layout-phone .team .who { min-width: 0; }
.layout-phone .team .who b { font-size: 17px; }
.layout-phone .team .action-btn { height: 48px; padding: 0 16px; }

/* ---------- settings ---------- */
.layout-phone .settings-card h2 { margin: 0 0 4px; }
.layout-phone .settings-profile { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.layout-phone .settings-profile .who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.layout-phone .settings-profile b { font: 700 20px/1.1 var(--font-display); letter-spacing: -0.03em; }
.layout-phone .settings-profile small { color: var(--text-3); font: 400 12.5px var(--font-mono); }
.layout-phone .field-label { color: var(--text-3); font: 500 10px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; }
.layout-phone .chip { min-height: 48px; padding: 0 16px; }
.layout-phone .chip:active { border-color: var(--accent); color: var(--accent-2); }
.layout-phone .switch { min-height: 48px; }
.layout-phone .segmented span { padding: 14px; }
.layout-phone .fields { grid-template-columns: 1fr; }
.layout-phone .field select { min-height: 48px; font-size: 15px; }
.layout-phone .field input[type="range"] { height: 32px; }
/* On Android the call audio route belongs to the system (speaker button), not to a device list. */
.platform-android .field:has(#speaker-select),
.platform-android .field:has(#ringer-select) { display: none; }
.layout-phone .app-version { margin: 4px 0 0; text-align: center; color: var(--text-3); font: 400 11px var(--font-mono); letter-spacing: 0.04em; }

/* ---------- bottom tab bar ---------- */
.layout-phone .tabbar {
  flex: none; display: flex; z-index: 20;
  padding: 0 4px env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--void-2) 94%, transparent);
  border-top: 1px solid var(--line);
}
.layout-phone.kb-open .tabbar { display: none; }
.tabbar button {
  flex: 1; min-width: 0; min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--text-3);
}
.tabbar .tab-icon {
  position: relative; width: 56px; height: 30px; border-radius: var(--radius-lg);
  display: grid; place-items: center; transition: background 0.2s, transform 0.15s var(--ease);
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar .tab-label { font: 500 10px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
.tabbar button[aria-selected="true"] { color: var(--text); }
.tabbar button[aria-selected="true"] .tab-icon { background: var(--accent-soft); color: var(--accent); }
.tabbar button:active .tab-icon { transform: scale(0.92); background: var(--surface-2); }
.tabbar .badge { position: absolute; top: -3px; right: 6px; box-shadow: 0 0 0 2px var(--void-2); }
@media (max-width: 370px) { .tabbar .tab-label { letter-spacing: 0.02em; font-size: 9.5px; } }
