
/* ==================== ChatGPT-style phone UI (phones only) ==================== */
/* New phone-only elements stay hidden on larger screens. */
.tb-model, .tb-pill, .tb-menu { display: none; }
.menu-btn .ic-burger { display: none; }

@media (max-width: 640px) {
  :root {
    --ios-spring: cubic-bezier(0.32, 0.72, 0, 1);
    --ios-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
    --phone-blue: #2f7cf6;
  }
  body { -webkit-tap-highlight-color: transparent; }
  html[data-theme="dark"] body, html[data-theme="amoled"] body { background: #000; }

  /* ---------- topbar: (≡)  model  (✎ ⋮) ---------- */
  .topbar {
    background: transparent; border: 0;
    padding: calc(10px + env(safe-area-inset-top)) 14px 6px;
    position: relative;
  }
  .topbar .tb-group { gap: 0; }
  .topbar .menu-btn {
    width: 46px; height: 46px; border-radius: 50%;
    background: #262626; color: #fff;
    display: grid; place-items: center;
    transition: transform .3s var(--ios-spring), background .2s;
  }
  .topbar .menu-btn:active { transform: scale(.88); background: #333; }
  .topbar .menu-btn .ic-panel { display: none; }
  .topbar .menu-btn .ic-burger { display: block; }
  html[data-theme="light"] .topbar .menu-btn { background: #eceae7; color: #111; }
  html[data-theme="light"] .topbar .menu-btn:active { background: #e0ddd9; }

  .topbar .search-btn, .topbar .logo, .topbar .avatar,
  .topbar .tb-title, .topbar .btn-dark { display: none; }

  .tb-model {
    display: inline-flex; align-items: center; gap: 4px;
    position: absolute; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translateX(-50%);
    height: 46px; background: none; border: 0; padding: 0 8px;
    color: #fff; font-size: 16px; font-weight: 600; font-family: inherit;
    transition: transform .3s var(--ios-spring), opacity .2s;
  }
  .tb-model:active { transform: translateX(-50%) scale(.93); opacity: .7; }
  html[data-theme="light"] .tb-model { color: #111; }

  .tb-pill {
    display: flex; align-items: center; gap: 2px;
    background: #262626; border-radius: 999px; padding: 4px;
    animation: pill-in .45s var(--ios-pop) both;
  }
  @keyframes pill-in { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
  html[data-theme="light"] .tb-pill { background: #eceae7; }
  .tb-icon {
    width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center;
    background: none; border: 0; color: #fff;
    transition: transform .3s var(--ios-pop), background .2s;
  }
  .tb-icon:active { transform: scale(.85); background: rgba(255,255,255,.1); }
  html[data-theme="light"] .tb-icon { color: #111; }
  html[data-theme="light"] .tb-icon:active { background: rgba(0,0,0,.06); }

  /* ⋮ dropdown menu */
  .tb-menu {
    display: block;
    position: fixed; z-index: 320;
    top: calc(66px + env(safe-area-inset-top)); right: 12px;
    min-width: 190px;
    background: #1c1c1e; border-radius: 16px; padding: 6px;
    box-shadow: 0 18px 50px rgba(0,0,0,.5);
    transform-origin: top right;
    animation: tbmenu-in .35s var(--ios-pop) both;
  }
  .tb-menu[hidden] { display: none; }
  @keyframes tbmenu-in { from { opacity: 0; transform: scale(.85) translateY(-6px); } to { opacity: 1; transform: none; } }
  html[data-theme="light"] .tb-menu { background: #fff; box-shadow: 0 18px 50px rgba(0,0,0,.18); }
  .tb-menu-item {
    display: flex; align-items: center; gap: 12px; width: 100%;
    background: none; border: 0; border-radius: 10px;
    padding: 12px 12px; font: inherit; font-size: 15px;
    color: #fff; text-align: left; cursor: pointer;
    transition: background .15s;
  }
  .tb-menu-item:active { background: rgba(255,255,255,.08); }
  html[data-theme="light"] .tb-menu-item { color: #111; }
  html[data-theme="light"] .tb-menu-item:active { background: rgba(0,0,0,.05); }
  .tb-menu-item.danger { color: #ff6b6b; }
  html[data-theme="light"] .tb-menu-item.danger { color: #d92d20; }

  /* ---------- thread: edge-to-edge messages ---------- */
  .thread { padding: 12px 0 8px; }
  .ai-msg { margin: 16px 0 4px; gap: 0; padding: 0 16px; }
  .ai-mark { display: none; }
  /* body takes the full line so the action row wraps below it
     (with the mark hidden, 0% + 100% basis fit one line -> body collapsed) */
  .ai-body { font-size: 15px; line-height: 1.65; color: #f2f2f2; flex-basis: 100%; }
  html[data-theme="light"] .ai-body { color: #1d1d1f; }

  /* user bubble: rounded, right-aligned */
  .msg-row { margin: 8px 0; padding: 0 16px; }
  .bubble {
    background: var(--phone-blue); color: #fff;
    border-radius: 18px;
    padding: 10px 14px; font-size: 15px; line-height: 1.5;
    max-width: 85%; width: auto;
    animation: bubble-in .4s var(--ios-pop) both;
  }
  @keyframes bubble-in { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }

  /* AI action row: original phone look (36px round buttons, no indent) */
  .ai-msg > .ai-actions {
    margin: 8px 0 12px; padding: 0 8px;
  }
  .ai-act {
    width: 36px; height: 36px; border-radius: 50%;
    color: #9d9d9d;
    transition: transform .3s var(--ios-pop), color .2s, background .2s;
  }
  .ai-act:active { transform: scale(.8); }
  .ai-act .ic-sm { width: 15px; height: 15px; }
  html[data-theme="light"] .ai-act { color: #8a8a8a; }

  /* ---------- composer pill ---------- */  .composer-wrap {
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
    background: transparent;
  }
  .composer {
    display: flex; align-items: center; flex-wrap: wrap;
    background: #262626; border: 0; border-radius: 999px;
    padding: 6px 6px 6px 8px; box-shadow: none;
    max-width: 720px;
    transition: background .25s var(--ios-spring), transform .25s var(--ios-spring);
  }
  .composer:focus-within { background: #2e2e30; }
  html[data-theme="light"] .composer { background: #eceae7; }
  html[data-theme="light"] .composer:focus-within { background: #e2dfdb; }
  .composer-row, .composer-left, .composer-tools { display: contents; }
  .composer .attach-tray {
    flex-basis: 100%; flex-wrap: nowrap;
    overflow-x: auto; overflow-y: hidden;
    margin: 2px 4px 6px;
  }
  .composer-input {
    order: 2; flex: 1; min-width: 0;
    background: transparent; border: 0; outline: none;
    color: #fff; font-size: 16px; padding: 10px 6px; font-family: inherit;
  }
  .composer-input::placeholder { color: #8e8e8e; }
  html[data-theme="light"] .composer-input { color: #111; }
  .composer .plus-btn {
    order: 1; width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center; background: none; border: 0; color: #fff; flex: none;
    transition: transform .3s var(--ios-pop);
  }
  .composer .plus-btn:active { transform: scale(.85) rotate(45deg); }
  html[data-theme="light"] .composer .plus-btn { color: #111; }
  .composer .imagine-pill, .composer .model { display: none; }
  .composer .mic-btn {
    order: 3; width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center; background: none; border: 0; color: #b5b5b5; flex: none;
    transition: transform .3s var(--ios-pop), color .2s;
  }
  .composer .mic-btn:active { transform: scale(.85); }
  html[data-theme="light"] .composer .mic-btn { color: #6f6f6f; }
  .composer .send-btn {
    order: 4; width: 42px; height: 42px; border-radius: 50%; flex: none;
    background: var(--phone-blue); color: #fff;
    display: grid; place-items: center; border: 0; cursor: pointer;
    box-shadow: 0 4px 14px rgba(47, 124, 246, .4);
    transition: transform .3s var(--ios-pop), background .2s, box-shadow .2s;
  }
  .composer .send-btn:active { transform: scale(.87); }
  .composer .send-btn.is-voice { animation: voice-glow 2.4s ease-in-out infinite; }
  @keyframes voice-glow {
    0%, 100% { box-shadow: 0 4px 14px rgba(47, 124, 246, .4); }
    50% { box-shadow: 0 4px 22px rgba(47, 124, 246, .75); }
  }
  .disclaimer { display: none; }

  /* toast: constrain width on phones so the text wraps normally */
  .toast {
    left: 12px; right: 12px;
    transform: translateY(12px);
    max-width: 480px; margin-left: auto; margin-right: auto;
  }
  .toast.show { transform: translateY(0); }
  .toast > span:first-child { flex: 1 1 auto; min-width: 0; }
  .toast .toast-btn { flex: none; }

  /* ---------- home view ---------- */
  .view-home { padding: 12px 16px; }
  .hero h1 { font-size: 26px; margin-bottom: 20px; }
  html[data-theme="dark"] .hero h1, html[data-theme="amoled"] .hero h1 { color: #fff; }

  /* ---------- drawer + modals with iOS springs ---------- */
  .sidebar { transition: transform .5s var(--ios-spring); }
  .scrim { transition: opacity .35s var(--ios-spring); }
  .modal { animation: modal-in-phone .45s var(--ios-pop) both; }
  @keyframes modal-in-phone { from { opacity: 0; transform: scale(.9) translateY(14px); } to { opacity: 1; transform: none; } }
  .model-menu { animation: mmin-phone .35s var(--ios-pop) both; transform-origin: top center; }
  @keyframes mmin-phone { from { opacity: 0; transform: translateY(8px) scale(.95); } to { opacity: 1; transform: none; } }

  /* message entry */
  .msg-anim { animation: msg-in-phone .5s var(--ios-spring) both; }
  @keyframes msg-in-phone { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

  /* sheet + pill popups spring in */
  #msgSheet { transition: transform .45s var(--ios-spring); }
}

/* respect reduced motion on phones too */
@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
  .tb-pill, .tb-menu, .bubble, .msg-anim, .modal, .model-menu { animation: none; }
  .composer .send-btn.is-voice, .ai-act.speaking { animation: none; }
}

/* attachments: pill composer becomes a rounded rectangle like PC */
.composer.has-files { border-radius: 20px; }
.composer.has-files .attach-tray {
  flex-basis: 100%; order: 0;
  margin: 4px 4px 8px; padding: 2px;
  overflow-x: auto; overflow-y: hidden;
}
.composer.has-files .att-chip { flex: none; max-width: 200px; }
