/* Phone layout (mobile.mjs): list → conversation → client card, one screen at a time, like Telegram.
   Everything sits under max-width:700px; the desktop never sees these rules. */
.mobile-back,.mobile-history{display:none}
@media (max-width:700px){
  body{height:100dvh}

  /* list screen */
  .app-header{display:grid;grid-template-columns:auto minmax(0,1fr);grid-template-rows:auto auto;gap:8px;padding:8px 10px 8px;height:auto}
  .app-header .brand{grid-column:1;grid-row:1;text-align:left;align-self:center}
  .app-header .header-right{grid-column:2;grid-row:1;justify-self:end;gap:6px;flex-wrap:nowrap;min-width:0}
  .app-header .header-tabs{grid-column:1/-1;grid-row:2;justify-self:start;max-width:100%;overflow-x:auto;scrollbar-width:none}
  .app-header .header-tabs.more-right{-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 28px),transparent);mask-image:linear-gradient(90deg,#000 calc(100% - 28px),transparent)}
  .header-tabs::-webkit-scrollbar{display:none}
  .header-tabs .tab-btn{flex-shrink:0}
  .header-status{padding-left:0;border-left:0;gap:6px}
  .header-tools{padding-left:0;border-left:0}
  .header-tools .icon-btn{width:36px;height:36px}
  .app-main{padding:0;gap:0}
  .sidebar{width:100%;border:0;border-radius:0;box-shadow:none;border-top:1px solid var(--border)}
  .search-box{padding:10px 10px 8px}
  /* search as a pill with a magnifier ; the stage filter becomes a round icon, dotted when a stage is picked */
  .search-input{height:40px;font-size:16px;border-radius:999px;padding-left:38px;background:var(--bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") 13px center/17px no-repeat}
  .stage-filter{width:40px}
  .stage-filter .stage-select{position:relative;width:40px;height:40px;padding:0;justify-content:center;border-radius:50%}
  .stage-filter .stage-select>*{display:none}
  .stage-filter .stage-select::before{content:"";width:18px;height:18px;background:currentColor;-webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 5h18l-7 8.5V19l-4 2v-7.5z'/%3E%3C/svg%3E") center/contain no-repeat;mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 5h18l-7 8.5V19l-4 2v-7.5z'/%3E%3C/svg%3E") center/contain no-repeat}
  .stage-filter.filtered .stage-select{color:var(--accent);border-color:color-mix(in srgb,var(--accent) 45%,var(--border))}
  .stage-filter.filtered .stage-select::after{content:"";position:absolute;top:6px;right:6px;width:8px;height:8px;border-radius:50%;background:var(--accent);box-shadow:0 0 0 2px var(--bg-sidebar)}
  .stage-option{min-height:44px}
  .conv-list{padding:0 0 calc(8px + env(safe-area-inset-bottom))}
  .conv-item{padding:12px 14px 12px 18px;border-radius:0}
  .conv-item+.conv-item::after{left:18px;right:0}
  /* conversation screen: always laid out off-screen to the right and slid in (transform only, run by
     the GPU), so the tap never waits for a layout; it lies over the list, a swipe right uncovers it */
  .chat-panel{display:flex;position:fixed;inset:0;z-index:40;border:0;border-radius:0;box-shadow:none;transform:translateX(100%);visibility:hidden;will-change:transform;transition:transform .3s cubic-bezier(.2,.8,.2,1),visibility 0s .3s}
  body.mobile-chat .chat-panel{transform:none;visibility:visible;box-shadow:-8px 0 24px #00000026;transition:transform .3s cubic-bezier(.2,.8,.2,1)}
  /* header, Telegram-like: ← · name + ACCOUNT · @username · last seen · card ; status and stage as pills */
  .chat-header{display:grid;grid-template-columns:38px minmax(0,1fr) 38px;align-items:center;gap:6px 10px;margin:0;border:0;border-bottom:1px solid color-mix(in srgb,var(--border) 70%,transparent);border-radius:0;padding:8px 10px 10px;min-height:0;background:color-mix(in srgb,var(--bg-sidebar) 92%,transparent);backdrop-filter:saturate(1.4) blur(14px)}
  .chat-header-info{display:contents;cursor:pointer}
  .mobile-back,.chat-tools .icon-btn{display:inline-grid;place-items:center;width:38px;height:38px;border:0;border-radius:50%;background:color-mix(in srgb,var(--text-main) 7%,transparent);color:var(--text-main)}
  .mobile-back:active,.chat-tools .icon-btn:active{background:color-mix(in srgb,var(--text-main) 14%,transparent)}
  .mobile-back{grid-column:1;grid-row:1}
  .mobile-back svg.i{width:20px;height:20px;stroke-width:2.2}
  .chat-tools svg.i{width:18px;height:18px}
  .chat-title{grid-column:2;grid-row:1;display:flex;flex-wrap:wrap;align-items:center;gap:2px 8px;min-width:0;line-height:1.25;cursor:pointer}
  .chat-title::before{content:"";order:2;flex-basis:100%;height:0}
  .chat-title #chat-client-name{max-width:calc(100% - 90px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:17px;font-weight:700;letter-spacing:-.2px}
  .chat-title #chat-account{order:1;display:inline-flex;align-items:center;height:20px;padding:0 8px;border-radius:999px;background:var(--acc,var(--accent));color:#fff;font-size:10.5px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}
  .chat-title #chat-account .account-dot{display:none}
  .chat-title #chat-account:empty{display:none}
  .chat-title .user{order:3;font-size:12.5px;color:var(--text-muted)}
  .chat-title .peer-presence{order:4;font-size:12.5px;font-weight:450}
  .chat-title .user:not(:empty)+.peer-presence:not(:empty)::before{content:"·";margin-right:6px;color:var(--text-dim)}
  .chat-tools{grid-column:3;grid-row:1;gap:6px}
  .chat-meta{grid-column:2/-1;grid-row:2;flex-wrap:wrap;gap:6px;font-size:11.5px}
  .chat-meta .status-pill{display:inline-flex;align-items:center;height:24px;padding:0 10px;border-radius:999px;font-size:11.5px}
  .stage-pill{height:26px}
  /* « Older messages · ↻ » floats over the top of the thread, like the date pill */
  .mobile-history{display:flex;align-items:center;align-self:center;position:relative;z-index:5;height:32px;margin:8px auto -40px;padding:0 4px 0 6px;border-radius:999px;background:color-mix(in srgb,var(--bg-card) 88%,transparent);backdrop-filter:blur(10px);box-shadow:0 2px 10px #0000001f,0 0 0 1px color-mix(in srgb,var(--border) 60%,transparent);font-size:12px}
  .mobile-history .link-btn{height:28px;padding:0 8px;border-radius:999px;font-size:12px;font-weight:600;color:var(--text-main)}
  .mobile-history .link-btn:disabled{display:none}
  .mobile-history #history-state{padding:0 6px;font-size:11.5px}
  .mobile-history #history-refresh{width:28px;height:28px;border-radius:50%}
  .mobile-history #history-refresh svg.i{width:15px;height:15px}
  .chat-thread{padding:48px 10px 10px}
  .msg{max-width:86%}

  /* composer: tools row, then the text with the round send button beside it, then preview/checks */
  .copilot-zone{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:end;gap:6px 8px;margin:0;border-width:1px 0 0;border-radius:0;box-shadow:none;padding:8px 8px calc(8px + env(safe-area-inset-bottom));max-height:62dvh}
  .copilot-zone>*{grid-column:1/-1}
  .composer-bottom,.composer-support{display:contents}
  .composer-attachments{order:-1;grid-column:1/-1;flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;gap:6px}
  .composer-attachments::-webkit-scrollbar{display:none}
  .composer-attachments>*{flex-shrink:0}
  .copilot-zone .composer-box{grid-column:1}
  .copilot-textarea{min-height:44px;max-height:34dvh;field-sizing:content;resize:none;border-radius:20px;padding:10px 14px;font-size:16px}
  .copilot-zone .btn-send{grid-column:2;width:44px;height:44px;padding:0;border-radius:50%;justify-content:center;align-self:end}
  .btn-send>span{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}
  .btn-send svg.i{width:20px;height:20px}
  .composer-foot{grid-column:1/-1;order:1}
  .draft-switch{height:36px}
  .btn-tool,.btn-regen{height:36px}
  #ai-menu-btn{margin-left:0}
  /* ⋯ and Ask AI: a bubble just above their button (index.html places it) */
  .composer-menu:popover-open{right:8px!important;width:min(320px,calc(100vw - 16px));max-height:60dvh;overflow-y:auto;padding:6px;border-radius:16px;gap:4px;box-shadow:0 12px 36px #00000038,0 2px 8px #00000014;animation:np-pop .16s ease-out;transform-origin:bottom right}
  .composer-menu>button,.composer-menu .btn-tool,.composer-menu .btn-regen{border:0;border-radius:11px;background:transparent;font-size:14px}
  .composer-menu>button:active,.composer-menu .btn-tool:active,.composer-menu .btn-regen:active{background:var(--bg-card-hover)}
  /* emojis and media float just above the composer (its height: --composer-h, mobile.mjs), over a light veil that leaves the composer clear */
  .emoji-picker:popover-open{inset:auto 8px calc(var(--composer-h,120px) + 8px) 8px!important;top:auto!important;width:auto!important;max-height:min(46dvh,360px);overflow-y:auto;border-radius:18px;box-shadow:0 12px 36px #00000038,0 2px 8px #00000014;animation:np-pop .16s ease-out;transform-origin:bottom center}
  .emoji-picker::backdrop{background:linear-gradient(#00000038 calc(100% - var(--composer-h,120px)),transparent 0)}
  .emoji-grid button{min-height:42px}
  .composer-menu>button,.composer-menu .btn-tool,.composer-menu .btn-regen{min-height:44px}

  /* client card screen */
  .client-profile:not([hidden]){position:fixed;inset:0;z-index:60;width:auto;border:0;border-radius:0;box-shadow:none;font-size:13px;animation:np-push .22s ease-out;padding-bottom:env(safe-area-inset-bottom)}
  .client-profile .profile-identity{position:sticky;top:0;z-index:2;background:var(--bg-sidebar);padding:14px 16px 12px 56px;border-bottom:1px solid var(--border);margin-bottom:12px}
  .client-profile .profile-identity::before{content:"Client card";display:block;font-size:12px;font-weight:600;color:var(--text-muted);margin-bottom:2px}
  .client-profile .close-profile{left:8px;right:auto;top:10px;width:40px;height:40px;font-size:0}
  .client-profile .close-profile::before{content:"";width:10px;height:10px;border-left:2px solid currentColor;border-bottom:2px solid currentColor;transform:translateX(2px) rotate(45deg)}
  .client-profile .dossier-card dl>div{font-size:13px}
  .client-profile .link-btn{min-height:36px;font-size:13px}
  .card-form input,.card-form textarea{font-size:16px;min-height:40px}

  /* media library: a sheet from the bottom, medias side by side in a swipeable carousel */
  dialog.media-library{width:calc(100vw - 16px);max-width:none;max-height:calc(100dvh - var(--composer-h,120px) - 72px);margin:auto 8px calc(var(--composer-h,120px) + 8px);padding:16px 14px;border-radius:20px;box-shadow:0 12px 36px #00000038}
  dialog.media-library::backdrop{background:linear-gradient(#00000059 calc(100% - var(--composer-h,120px)),transparent 0)}
  dialog.media-library .media-items{display:flex;grid-template-columns:none;gap:12px;overflow-x:auto;scroll-snap-type:x mandatory;margin:0 -14px;padding:2px 14px 10px;scrollbar-width:none}
  dialog.media-library .media-items::-webkit-scrollbar{display:none}
  dialog.media-library .media-items>article{flex:0 0 82%;scroll-snap-align:center}
  dialog.media-library .media-items img,dialog.media-library .media-items video{max-height:42dvh}
  dialog.media-library button,dialog.media-library select{min-height:40px}
}
@keyframes np-pop{from{transform:scale(.92) translateY(6px);opacity:0}to{transform:none;opacity:1}}
@keyframes np-push{from{transform:translateX(28px);opacity:.4}to{transform:none;opacity:1}}
@media (max-width:700px) and (prefers-reduced-motion:reduce){.chat-panel{transition:none!important}.client-profile:not([hidden]),.composer-menu:popover-open{animation:none}}
