/* SONIQ AI — phone layout (≤760px). Desktop is unaffected: everything here is inside the media query
   except the elements that only exist for phones (scrim, ⋯ button), which are hidden by default. */

.scrim { display: none; }
.more-btn { display: none; position: relative; }
.more-btn .more-dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; box-shadow: 0 0 0 2px var(--panel); }
.topbar-actions { display: contents; }

@media (max-width: 760px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  /* soniq.css sets a 280px sidebar column after app.css's phone rule — on phones it's one column, always */
  .app, .app.team-open { grid-template-columns: minmax(0, 1fr) !important; height: 100dvh; width: 100%; }
  .main { grid-column: 1; }
  .main { height: 100dvh; }

  /* Top bar: menu · space name · ⋯ */
  .topbar { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); gap: 6px; min-height: 52px; }
  .menu, .more-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; font-size: 20px; flex: none; border-radius: 10px; }
  .space-title { font-size: 15px; overflow: hidden; }
  .space-title #space-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .space-title .pill { display: none; }
  .topbar-actions {
    display: none; position: fixed; z-index: 45; top: calc(max(8px, env(safe-area-inset-top)) + 48px); right: 8px; left: auto;
    width: min(260px, calc(100vw - 16px)); flex-direction: column; gap: 2px; padding: 6px;
    background: var(--bg); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  }
  .app.more-open .topbar { z-index: 46; } /* the menu lives inside the top bar, so lift it above its backdrop */
  .app.more-open .topbar-actions { display: flex; }
  .topbar-actions .btn { justify-content: flex-start; width: 100%; padding: 12px 14px; font-size: 15px; border-radius: 10px; text-align: left; border: 0; box-shadow: none; }
  .topbar-actions .btn.ghost { background: transparent; color: var(--text); }
  .topbar-actions .btn.ghost:active { background: var(--soft); }
  .topbar-actions .btn.primary { margin-top: 4px; }
  .topbar-actions .btn.hidden { display: none; }

  /* Dimmed backdrop behind the drawer / ⋯ menu / team panel — tap to close */
  .scrim { position: fixed; inset: 0; z-index: 19; background: rgba(0,0,0,.38); }
  .app.nav-open .scrim, .app.more-open .scrim, .app.team-open .scrim { display: block; }
  .app.more-open .scrim { z-index: 44; background: rgba(0,0,0,.18); }
  .sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .team-panel { width: 100vw !important; z-index: 30; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

  /* Chat */
  .messages { padding: 14px 10px 8px; -webkit-overflow-scrolling: touch; }
  .content { font-size: 15px; overflow-wrap: break-word; }
  .content th, .content td { white-space: nowrap; overflow-wrap: normal; } /* tables scroll sideways instead of breaking words */
  .content table { max-width: 100%; -webkit-overflow-scrolling: touch; }
  .content pre, .content table, .content .mermaid, .content svg { max-width: 100%; }
  .content .mermaid, .content .diagram { overflow-x: auto; }
  .change-card, .vault-card { margin-left: 0; margin-right: 0; border-radius: 14px; }
  .change-card .btn, .vault-card .btn { min-height: 40px; }
  .step .d { max-width: 62vw; }

  /* Composer: 16px stops iOS zooming on focus; clear of the home indicator */
  .composer-wrap { width: calc(100% - 16px); }
  .composer { border-radius: 18px; padding: 6px; }
  .composer textarea, .composer input, input, select, textarea { font-size: 16px; }
  .composer-tools .mode { font-size: 14px; max-width: 46vw; }
  .send { width: 42px; height: 42px; }
  .composer-note { padding: 4px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); font-size: 11.5px; }
  .composer-note:empty { padding-top: 0; }

  /* Dialogs become bottom sheets */
  dialog, dialog.wide {
    width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0 0; padding: 18px 14px;
    padding-bottom: max(18px, env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; border-left: 0; border-right: 0; border-bottom: 0;
    overflow-y: auto;
  }
  dialog .row-end { position: sticky; bottom: 0; background: var(--panel); padding-top: 10px; }
  dialog .row-end .btn { flex: 1; min-height: 42px; }
  .files-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; }
  .fcard .acts { flex-wrap: wrap; gap: 8px; }

  /* Floating cards */
  .call-brief { top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; width: auto; max-height: 70dvh; }
  .office-fallback { top: auto; bottom: max(90px, calc(env(safe-area-inset-bottom) + 80px)); }
  .lily-dock { right: 10px; bottom: calc(128px + env(safe-area-inset-bottom)); }
  .lily-fab { padding: 8px 14px 8px 10px; font-size: 14px; }
  /* Lily: full screen on phones, with a ✕ that's always on screen (top-right of her video) */
  .lily-card:not(.hidden) {
    position: fixed; inset: 0; z-index: 60; width: 100vw; max-width: 100vw; height: 100dvh; border-radius: 0; border: 0;
    display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  .lily-card .vs-frame { flex: none; aspect-ratio: auto; height: 38dvh; max-height: none; }
  .lily-card .lc-log { flex: 1; max-height: none; min-height: 0; font-size: 15px; }
  .lily-card .lc-log:empty { display: block; }
  .lily-card .lc-form input { font-size: 16px; }
  .lily-card .vs-bar { flex-wrap: wrap; gap: 6px; }
  .lily-card .vs-bar select { flex: 1 1 40%; }
  .lily-card #vs-close {
    position: absolute; z-index: 5; top: calc(env(safe-area-inset-top) + 10px); right: 10px; margin: 0;
    width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,.5); color: #fff; font-size: 18px; border: 0;
  }
  .lily-card:not(.hidden) ~ .lily-fab { display: none; }
  .app.nav-open ~ .lily-dock, .app.more-open ~ .lily-dock, .app.team-open ~ .lily-dock { display: none; }

  /* Shared browser */
  .bv-bar { flex-wrap: wrap; padding: 8px 10px; }
  .bv-bar input { flex: 1 1 100%; order: -1; }

  /* Touch targets */
  .space-list a, .thread-list a, .space-list button, .thread-list button { min-height: 40px; }
  .icon-btn { min-width: 36px; min-height: 36px; }
}

/* Installed as an app (Add to Home Screen) */
@media (display-mode: standalone) {
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
}
