.phone {
  container: phone-screen / size;
  --app-tab-row: 50px;
  --app-dock-overlap: 46px;
  --app-safe-bottom: max(8px, env(safe-area-inset-bottom));
}

.dialogue-view {
  --voice-controls-bottom: 36px;
  --voice-footer-inset: calc(var(--voice-controls-bottom) + 4px + var(--app-safe-bottom));
  --voice-heading-lift: 10px;
}

.phone[data-dialogue-page="home"] .dialogue-view {
  --voice-footer-inset: calc(var(--voice-controls-bottom) + var(--app-dock-overlap));
}

.dialogue-view,
.messages-view,
.workbench-frame {
  flex: 1 1 auto;
  min-height: 0;
}

.dialogue-view,
.messages-view {
  display: flex;
  flex-direction: column;
}

.dialogue-view .voice-footer { padding-bottom: var(--voice-footer-inset); }
.voice-footer .home-indicator { position: absolute; inset: auto 0 var(--app-safe-bottom); margin: 0 auto; }
.phone[data-dialogue-page="home"] .voice-footer .home-indicator { display: none; }
.dialogue-view .welcome-copy { top: calc(var(--home-heading-top) - var(--voice-heading-lift)); }

.workbench-frame {
  --app-task-frame-extension: 0px;
  display: block;
  width: 100%;
  border: 0;
  /* On the task tab, the workbench handles the clearance inside the frame. */
  padding-block-end: calc(var(--app-dock-overlap) - 6px - var(--app-task-frame-extension));
  background: transparent;
}

.phone[data-tab="tasks"] > .workbench-frame { --app-task-frame-extension: 32px; }

.phone:has(> .workbench-frame:not([hidden])):not([data-directory]) > .statusbar { display: none; }
.phone:not([data-tab="conversation"]):not([data-directory]) {
  background:
    radial-gradient(ellipse 80% 108px at 4% 100%, var(--ai-blue), transparent),
    radial-gradient(ellipse 75% 94px at 98% 100%, color-mix(in srgb, var(--ai-brand) 24%, transparent), transparent),
    var(--ai-canvas);
}
.phone[data-tab="messages"][data-message-view="home"]:not([data-directory]) { background: var(--ai-white); }
.phone[data-tab="profile"]:not([data-directory]) { background: #f5f5f5; }
.phone[data-tab="messages"]:not([data-message-view="home"]) > .app-tabs-dock { display: none; }

.app-tabs-dock {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  margin-block-start: calc(-1 * var(--app-dock-overlap));
  padding: 0 0 var(--app-safe-bottom);
  border-radius: 16px 16px 0 0;
  background: linear-gradient(165deg, #fff 20%, #f9faff);
  box-shadow: inset 0 0 0 1px white, 0 -5px 22px rgb(40 43 56 / 8%);
}

.app-dock-optics { position: absolute; width: 0; height: 0; pointer-events: none; }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .app-tabs-dock {
    --app-dock-base-filter: blur(16px) saturate(85%);
    --app-dock-filter: var(--app-dock-refraction, var(--app-dock-base-filter));
    background: linear-gradient(165deg, rgb(255 255 255 / 97%) 20%, rgb(249 250 255 / 95%));
    -webkit-backdrop-filter: var(--app-dock-filter);
    backdrop-filter: var(--app-dock-filter);
  }

  .app-tabs-dock[data-dock-refraction] {
    --app-dock-refraction: var(--app-dock-base-filter) url("#app-dock-refraction");
  }
}

.app-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.app-tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--app-tab-row);
  padding-inline: 4px;
  border-radius: 14px;
  color: var(--ai-ink);
  font-size: 12px;
  line-height: 16px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.app-tabs a:focus-visible { outline: 2px solid var(--ai-link); outline-offset: -2px; }

.app-tab-icon {
  position: relative;
  width: 24px;
  height: 24px;
  flex: none;
}

.app-tab-icon::before,
.app-tab-icon::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--tab-icon) center / contain no-repeat;
}

.app-tab-icon::after {
  --tab-icon: var(--tab-icon-active);
  opacity: 0;
}

.app-tabs a[aria-current="page"] .app-tab-icon::before { opacity: 0; }
.app-tabs a[aria-current="page"] .app-tab-icon::after { opacity: 1; }

[data-tab-link="tasks"] {
  --tab-icon: url("icons/tab-task.svg?v=2");
  --tab-icon-active: url("icons/tab-task-active.svg?v=2");
}

[data-tab-link="messages"] {
  --tab-icon: url("icons/tab-messages.svg?v=2");
  --tab-icon-active: url("icons/tab-messages-active.svg?v=2");
}

[data-tab-link="ai"] {
  --tab-icon: url("icons/tab-chat.svg?v=2");
  --tab-icon-active: url("icons/tab-chat-active.svg?v=2");
}

[data-tab-link="profile"] {
  --tab-icon: url("icons/tab-profile.svg?v=2");
  --tab-icon-active: url("icons/tab-profile-active.svg?v=2");
}

.app-tabs .app-tab-center { padding-inline: 0; }

.app-tab-center-button {
  flex: none;
  width: min(100%, 40px);
  height: auto;
  border-radius: 50%;
}

.app-tab-center[aria-current="page"] .app-tab-center-button { transform: scale(1.05); }

@media (prefers-reduced-motion: no-preference) {
  .app-tabs[data-animate-selection] .app-tab-icon::before,
  .app-tabs[data-animate-selection] .app-tab-icon::after {
    transition: opacity 120ms ease-out;
  }
  .app-tabs[data-animate-selection] a[aria-current="page"] :is(.app-tab-icon, .app-tab-center-button) {
    animation: app-tab-select 440ms ease-in-out;
  }
  .app-tab-center-button { --tab-peak-scale: 1.14; }
  @keyframes app-tab-select {
    0% { transform: translateY(2px) scale(.88); }
    38% { transform: translateY(-3px) scale(var(--tab-peak-scale, 1.22)); }
    72% { transform: translateY(0) scale(.97); }
  }
}

.app-tabs .app-tab-center:focus-visible { outline: 0; }
.app-tab-center:focus-visible .app-tab-center-button { outline: 2px solid var(--ai-brand-ink); outline-offset: 3px; }

.app-tabs-dock .home-indicator { margin: 22px auto 0; }

@media (prefers-reduced-transparency: reduce) {
  .phone { --app-dock-overlap: 0px; }
  .workbench-frame { padding-block-end: 0; }
  .app-tabs-dock {
    --app-dock-filter: none;
    background: var(--ai-white);
  }
}

.directory-order-card:focus-visible { outline: 2px solid var(--ai-link); outline-offset: -2px; }

.messages-view { color: var(--ai-ink); }

.messages-view .app-header h1 { font-size: 18px; }
.phone:is([data-message-view="system"], [data-message-view="orders"]) .messages-view .app-header h1 { font-weight: 500; line-height: 1.3; }
.messages-view .app-header .icon-button,
#dialogue-back { margin-inline-start: -5px; }

#message-sections {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 16px calc(20px + var(--app-dock-overlap));
}

.phone[data-tab="messages"]:not([data-message-view="home"]) #message-sections {
  padding-block-end: calc(20px + var(--app-safe-bottom));
}

.message-list {
  --message-avatar-size: 54px;
  --message-avatar-gap: 12px;
  margin: 0;
  padding: 0 4px;
  list-style: none;
  display: grid;
  gap: 8px;
}

.message-row {
  position: relative;
  display: grid;
  grid-template-columns: var(--message-avatar-size) minmax(0, 1fr);
  align-items: center;
  gap: var(--message-avatar-gap);
  width: 100%;
  min-height: 74px;
  padding: 10px 0;
  text-align: start;
}

.message-row:focus-visible { outline-offset: -3px; border-radius: 8px; }
.message-row-copy { display: grid; gap: 5px; min-width: 0; }
.message-row-copy strong { font-size: 16px; font-weight: 400; }
.message-row-heading { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.message-row-heading strong { flex: none; white-space: nowrap; }
.message-person-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; }
.message-person-tag {
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--ai-brand);
  background: var(--ai-lavender);
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
}
.message-row-summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; color: #999999; }
.message-row-summary small { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.messages-view time { color: var(--ai-muted); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.message-row-date { margin-inline-start: auto; flex: none; }
.message-row-date time { color: #858892; }
.message-row-date:empty { display: none; }
.message-unread {
  display: inline-grid;
  place-items: center;
  flex: none;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  border-radius: 999px;
  background: #FF4F42;
  color: white;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.message-avatar,
.message-symbol {
  width: var(--message-avatar-size);
  height: var(--message-avatar-size);
  border-radius: 50%;
}

.message-avatar { object-fit: cover; }

.message-empty { padding: 28px 12px; color: var(--ai-muted); font-size: 14px; text-align: center; }
.message-history { display: grid; gap: 10px; padding: 0; margin: 0; list-style: none; }

.message-history-card {
  display: grid;
  gap: 9px;
  width: 100%;
  padding: 15px 16px;
  border-radius: var(--ai-radius-card);
  background: var(--ai-white);
  box-shadow: var(--ai-shadow-card);
  text-align: start;
}

.message-history-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.message-history-heading strong { font-size: 15px; font-weight: 600; }
.message-history-card :is(p, .message-history-title) { color: var(--ai-muted); font-size: 14px; line-height: 1.6; }
.message-history-card small { color: var(--ai-brand); font-size: 12px; }

@container phone-screen (max-width: 360px) {
  .message-list { --message-avatar-size: 48px; --message-avatar-gap: 10px; padding-inline: 0; }
  .message-row-heading { gap: 4px; }
  .message-person-tags { gap: 3px; }
  .message-person-tag { font-size: 10px; }
  .message-person-tag { padding-inline: 4px; }
}

@container phone-screen (max-height: 800px) {
  /* Let the idle orb fit between the heading and examples on shorter screens. */
  .phone[data-phase="idle"] .voice-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-block: clamp(0px, calc(12cqh - 68px), 28px) 8px;
    gap: 8px;
  }
  .phone[data-phase="idle"] .welcome-copy { position: static; flex: none; }
  .phone[data-phase="idle"] .orb-button {
    position: relative;
    inset: auto;
    transform: none;
    flex-shrink: 1;
    min-height: 0;
    width: auto;
    aspect-ratio: 1;
    margin-block: auto;
  }
}

@container phone-screen (max-height: 760px) {
  .home-example { min-height: 36px; }
}

@container phone-screen (max-height: 720px) {
  .dialogue-view,
  .app-tabs-dock { --app-tab-row: 46px; }
  .dialogue-view { --voice-controls-bottom: 28px; --voice-heading-lift: 8px; }
  .phone[data-phase="idle"] .dialogue-view { --orb-display-size: min(152px, var(--idle-orb-size)); }
}

@container phone-screen (max-height: 680px) {
  .dialogue-view { --home-heading-top: clamp(82px, 15%, 96px); }
  .phone[data-phase="idle"] .dialogue-view {
    --orb-display-size: 112px;
  }
  .welcome-copy h2 { line-height: 1.35; }
  .home-examples { gap: 6px; }
  .home-example { min-height: 34px; padding-block: 5px; }
}

@container phone-screen (max-height: 640px) {
  .dialogue-view { --voice-controls-bottom: 26px; }
  .voice-controls { --voice-control-size: 56px; }
}

@container phone-screen (max-height: 600px) {
  .home-examples { gap: 4px; }
  .home-example { min-height: 32px; padding-block: 4px; }
}

@container phone-screen (max-height: 565px) {
  .dialogue-view { --voice-controls-bottom: 22px; }
  .home-example { min-height: 30px; padding-block: 3px; }
}

@container phone-screen (max-height: 545px) {
  .phone[data-phase="idle"] .dialogue-view { --orb-display-size: 80px; }
}
