/* MOSS Mobile/Tablet — Minimal: sidebar + logo + CAD only */

@media (max-width: 1024px) {
  /* App layout — use dynamic viewport on iOS so URL bar collapse doesn't hide bottom UI */
  html body #app {
    flex-direction: column !important;
    height: 100dvh !important;
    height: -webkit-fill-available;
  }
  html body #app #left-pane {
    min-width: 0 !important; width: 100% !important;
    flex: 1 1 100% !important;
    height: 100dvh !important;
    height: -webkit-fill-available;
  }
  html, body {
    height: 100dvh;
    height: -webkit-fill-available;
    overflow: hidden;
  }

  /* Header — ChatGPT-style: clean, balanced, subtle bottom border */
  html body #left-pane > header,
  html body header {
    height: 56px !important;
    min-height: 56px !important;
    max-height: 56px !important;
    padding: 8px 10px !important;
    gap: 4px !important;
    overflow: visible !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    background: var(--bg-hdr, rgba(14,14,17,0.85)) !important;
    backdrop-filter: saturate(180%) blur(14px) !important;
    -webkit-backdrop-filter: saturate(180%) blur(14px) !important;
    border-bottom: 1px solid var(--border) !important;
  }

  /* HIDE all original items by default */
  html body header > * {
    display: none !important;
  }

  /* SHOW only: sidebar toggle (ChatGPT-style minimal header) */
  html body header > #sb-toggle {
    display: flex !important;
    flex-shrink: 0 !important;
  }

  /* Mode picker (Chat / Real-time) — absolutely centered, replaces model picker */
  html body header > .mode-picker {
    display: inline-flex !important;
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    flex: 0 0 auto !important;
    min-width: 0 !important;
    max-width: 60vw !important;
    gap: 0 !important;
    z-index: 5 !important;
  }
  /* Hide search button (eyeglass) inside mode-picker on mobile — keep header clean */
  html body header > .mode-picker > #search-btn {
    display: none !important;
  }
  /* Mode-btn — pill style like ChatGPT model selector */
  html body header > .mode-picker .mode-btn {
    padding: 7px 12px 7px 11px !important;
    border-radius: 999px !important;
    gap: 7px !important;
    background: transparent !important;
    border: none !important;
    transition: background .15s !important;
    color: rgba(255,255,255,0.95) !important;
  }
  html body header > .mode-picker .mode-btn:hover,
  html body header > .mode-picker .mode-btn.open {
    background: rgba(255,255,255,0.06) !important;
    border: none !important;
  }
  html body header > .mode-picker .mode-btn .mode-btn-icon {
    width: 16px !important;
    height: 16px !important;
    flex-shrink: 0 !important;
  }
  html body header > .mode-picker .mode-btn .mode-btn-label {
    font-size: 15.5px !important;
    font-weight: 600 !important;
    letter-spacing: -0.01em !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    max-width: 42vw !important;
  }
  html body header > .mode-picker .mode-chevron {
    width: 14px !important;
    height: 14px !important;
    color: rgba(255,255,255,0.42) !important;
    transition: transform .18s, color .15s !important;
  }
  html body header > .mode-picker .mode-btn:hover .mode-chevron,
  html body header > .mode-picker .mode-btn.open .mode-chevron {
    color: rgba(255,255,255,0.85) !important;
  }
  html body header > .mode-picker .mode-btn.open .mode-chevron {
    transform: rotate(180deg) !important;
  }
  /* Real-time pulse indicator stays compact */
  html body header > .mode-picker .mode-btn.realtime-active .mode-btn-icon {
    color: #ef4444 !important;
  }
  /* Re-center mode dropdown to viewport so it doesn't clip */
  html body header > .mode-picker .mode-dropdown {
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: min(320px, 92vw) !important;
    max-width: 92vw !important;
  }

  /* Custom CAD + More buttons (always show, on the right) */
  html body header > #moss-spacer,
  html body header > #moss-cad-toggle,
  html body header > #moss-mobile-more-btn {
    display: flex !important;
    flex-shrink: 0 !important;
  }

  html body header > #moss-spacer {
    flex: 1 !important;
  }

  /* Sidebar toggle — circle, balanced with right side */
  html body header .sb-toggle {
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    color: rgba(255,255,255,0.78) !important;
    transition: background .15s, color .15s, transform .1s !important;
  }
  html body header .sb-toggle:hover {
    background: rgba(255,255,255,0.06) !important;
    color: #fff !important;
  }
  html body header .sb-toggle:active {
    background: rgba(255,255,255,0.10) !important;
    transform: scale(0.94);
  }
  html body header .sb-toggle svg {
    width: 20px !important;
    height: 20px !important;
  }

  /* Header right-side icon buttons — ChatGPT-style minimal/ghost circles */
  #moss-cad-toggle,
  #moss-mobile-more-btn {
    width: 40px !important;
    height: 40px !important;
    background: transparent !important;
    border: none !important;
    color: rgba(255,255,255,0.78) !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 20px !important;
    line-height: 1 !important;
    box-shadow: none !important;
    transition: background .15s, color .15s, transform .1s !important;
    padding: 0 !important;
  }
  #moss-cad-toggle i.ti,
  #moss-mobile-more-btn i.ti {
    font-size: 20px !important;
    line-height: 1 !important;
  }
  #moss-cad-toggle:hover,
  #moss-mobile-more-btn:hover {
    background: rgba(255,255,255,0.06) !important;
    color: #fff !important;
  }
  #moss-cad-toggle:active,
  #moss-mobile-more-btn:active {
    transform: scale(0.94);
    background: rgba(255,255,255,0.10) !important;
  }

  /* CAD toggle active state — subtle neutral fill */
  #moss-cad-toggle.active {
    background: rgba(255,255,255,0.10) !important;
    color: #fff !important;
  }

  /* Icon sizing inside header circle buttons */
  #moss-cad-toggle svg,
  #moss-mobile-more-btn svg {
    width: 20px !important;
    height: 20px !important;
  }

  /* Popup menu — contains all hidden items */
  #moss-mobile-popup {
    display: none;
    position: fixed !important;
    top: 60px !important;
    right: 8px !important;
    width: 240px !important;
    max-height: calc(100vh - 70px) !important;
    background: #161616 !important;
    border: 1px solid rgba(255,255,255,0.15) !important;
    border-radius: 12px !important;
    padding: 6px !important;
    z-index: 10001 !important;
    box-shadow: 0 16px 48px rgba(0,0,0,0.7) !important;
    overflow-y: auto !important;
    flex-direction: column !important;
    gap: 2px !important;
  }
  #moss-mobile-popup.open { display: flex !important; }

  #moss-mobile-popup .mp-item {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 10px 12px !important;
    background: transparent !important;
    border: none !important;
    color: #ddd !important;
    border-radius: 8px !important;
    font-size: 13px !important;
    cursor: pointer !important;
    width: 100% !important;
    text-align: left !important;
    box-sizing: border-box !important;
  }
  #moss-mobile-popup .mp-item:active { background: rgba(255,255,255,0.10) !important; }
  #moss-mobile-popup .mp-item:hover { background: rgba(255,255,255,0.06) !important; }
  #moss-mobile-popup .mp-item.active {
    background: rgba(255,255,255,0.06) !important;
    color: #fff !important;
  }
  #moss-mobile-popup .mp-item .icon {
    width: 20px !important; height: 20px !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
    flex-shrink: 0 !important;
    color: rgba(255,255,255,0.7) !important;
  }
  #moss-mobile-popup .mp-item.active .icon { color: #fff !important; }
  #moss-mobile-popup .mp-item-label {
    flex: 1 !important;
    font-size: 13.5px !important;
    text-align: left !important;
  }
  #moss-mobile-popup .mp-item-check {
    width: 16px !important; height: 16px !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
    flex-shrink: 0 !important;
    color: rgba(255,255,255,0.85) !important;
  }
  #moss-mobile-popup .mp-group {
    padding: 8px 12px 4px !important;
    font-size: 10.5px !important;
    font-weight: 600 !important;
    letter-spacing: .07em !important;
    text-transform: uppercase !important;
    color: rgba(255,255,255,0.42) !important;
  }
  #moss-mobile-popup .mp-sep {
    height: 1px !important;
    margin: 4px 8px !important;
    background: rgba(255,255,255,0.06) !important;
  }

  /* Two-line items (label + desc) — used by Model selector */
  #moss-mobile-popup .mp-item-text {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    min-width: 0 !important;
    line-height: 1.25 !important;
  }
  #moss-mobile-popup .mp-item-text .mp-item-label {
    font-size: 13.5px !important;
    color: rgba(255,255,255,0.95) !important;
  }
  #moss-mobile-popup .mp-item-text .mp-item-desc {
    font-size: 11.5px !important;
    color: rgba(255,255,255,0.45) !important;
    margin-top: 1px !important;
  }
  #moss-mobile-popup .mp-item.disabled {
    opacity: 0.45 !important;
    cursor: not-allowed !important;
  }
  #moss-mobile-popup .mp-item.disabled:hover,
  #moss-mobile-popup .mp-item.disabled:active {
    background: transparent !important;
  }

  /* Sidebar slide — ChatGPT-style mobile sidebar */
  html body aside#sidebar {
    position: fixed !important;
    top: 0 !important; bottom: 0 !important; left: 0 !important;
    width: min(86vw, 320px) !important;
    max-width: min(86vw, 320px) !important;
    min-width: 0 !important;
    z-index: 9996 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s ease-out, box-shadow 0.2s ease !important;
    box-shadow: none !important;
    background: linear-gradient(180deg, #0e0e11 0%, #0a0a0c 100%) !important;
    overflow-y: auto !important;
    border-right: 1px solid rgba(255,255,255,0.04) !important;
  }
  html body aside#sidebar.mobile-open {
    transform: translateX(0) !important;
    box-shadow: 4px 0 24px rgba(0,0,0,0.55) !important;
  }
  html[data-theme="light"] body aside#sidebar.mobile-open {
    box-shadow: 4px 0 24px rgba(0,0,0,0.18) !important;
  }

  /* Subtle scrollbar inside mobile sidebar */
  html body aside#sidebar::-webkit-scrollbar { width: 0 !important; }
  html body aside#sidebar { scrollbar-width: none !important; }

  /* Hide header items that would peek through next to the open sidebar */
  body.sidebar-open header > .model-picker,
  body.sidebar-open #moss-cad-toggle,
  body.sidebar-open #moss-mobile-more-btn {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* When mobile-open: force EXPANDED layout regardless of .collapsed state */
  html body aside#sidebar.mobile-open .sb-hdr {
    padding: 14px 12px 6px !important;
    gap: 8px !important;
    flex-direction: row !important;
  }
  html body aside#sidebar.mobile-open .sb-actions {
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
  }

  /* New Chat button — refined accent pill, theme-aware */
  html body aside#sidebar.mobile-open #new-chat-btn {
    flex: 1 1 auto !important;
    width: auto !important;
    height: 44px !important;
    padding: 0 14px !important;
    border-radius: 12px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    gap: 10px !important;
    justify-content: flex-start !important;
    background: var(--ac10) !important;
    border: 1px solid var(--ac22) !important;
    color: var(--text) !important;
    letter-spacing: -0.01em !important;
    transition: background .15s, border-color .15s, transform .1s !important;
  }
  html body aside#sidebar.mobile-open #new-chat-btn:hover {
    background: var(--ac18) !important;
    border-color: var(--ac40) !important;
  }
  html body aside#sidebar.mobile-open #new-chat-btn:active {
    transform: scale(0.98);
  }
  html body aside#sidebar.mobile-open #new-chat-btn svg {
    width: 20px !important;
    height: 20px !important;
    color: #eb3826 !important;
    stroke-width: 2.4 !important;
  }
  html body aside#sidebar.mobile-open #new-chat-btn .sb-btn-label {
    display: inline !important;
  }

  /* Icon buttons — ghost ChatGPT-style, larger touch */
  html body aside#sidebar.mobile-open #new-proj-btn,
  html body aside#sidebar.mobile-open #sess-mgr-btn {
    width: 44px !important;
    height: 44px !important;
    border-radius: 12px !important;
    flex-shrink: 0 !important;
    background: transparent !important;
    border: 1px solid rgba(255,255,255,0.07) !important;
    color: rgba(255,255,255,0.88) !important;
    transition: background .15s, border-color .15s, color .15s, transform .1s !important;
  }
  html body aside#sidebar.mobile-open #new-proj-btn:hover,
  html body aside#sidebar.mobile-open #sess-mgr-btn:hover {
    background: rgba(255,255,255,0.06) !important;
    border-color: rgba(255,255,255,0.14) !important;
    color: #fff !important;
  }
  html body aside#sidebar.mobile-open #new-proj-btn:active,
  html body aside#sidebar.mobile-open #sess-mgr-btn:active {
    transform: scale(0.94);
    background: rgba(255,255,255,0.10) !important;
  }
  html body aside#sidebar.mobile-open #new-proj-btn svg,
  html body aside#sidebar.mobile-open #sess-mgr-btn svg {
    width: 20px !important;
    height: 20px !important;
    stroke-width: 1.9 !important;
  }


  /* Show expanded content (override .collapsed display:none) */
  html body aside#sidebar.mobile-open .side-group-label,
  html body aside#sidebar.mobile-open #session-list,
  html body aside#sidebar.mobile-open .sb-acc-text,
  html body aside#sidebar.mobile-open .sb-acc-caret {
    display: block !important;
  }
  html body aside#sidebar.mobile-open #sb-sessions-rail {
    display: none !important;
  }
  html body aside#sidebar.mobile-open .sb-acc-row {
    justify-content: flex-start !important;
    padding: 10px !important;
  }

  /* Section label — bright and clear */
  html body aside#sidebar .side-group-label {
    padding: 20px 14px 8px !important;
    font-size: 11.5px !important;
    font-weight: 700 !important;
    color: rgba(255,255,255,0.70) !important;
    letter-spacing: .08em !important;
    text-transform: uppercase !important;
  }

  /* Session list — wider hit area + padding */
  html body aside#sidebar #session-list {
    padding: 2px 8px 12px !important;
  }
  html body aside#sidebar .sess-item {
    padding: 8px 10px !important;
    border-radius: 9px !important;
    min-height: 40px !important;
    margin-bottom: 1px !important;
  }
  html body aside#sidebar .sess-item .sess-title {
    font-size: 14px !important;
    line-height: 1.3 !important;
  }
  html body aside#sidebar .sess-item .sess-time {
    font-size: 12px !important;
  }
  html body aside#sidebar .sess-item:active {
    background: rgba(255,255,255,0.10) !important;
  }

  /* iOS safe-area: keep chat input above the home indicator */
  html body #bottom {
    padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
  }
  html body #input-card {
    padding-bottom: 0 !important;
  }
  html body #cad-panel .moss-cad-close-btn {
    top: max(12px, env(safe-area-inset-top)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
  }

  /* ── ChatGPT-style composer (input-card + input-row) ─────────────── */
  html body #input-card {
    border-radius: 100px !important;
    border: 1px solid rgba(255,255,255,0.10) !important;
    background: rgba(255,255,255,0.04) !important;
    box-shadow: 0 1px 6px rgba(0,0,0,0.20) !important;
    transition: border-color .2s, box-shadow .2s, background .2s !important;
  }
  html body #input-card:focus-within {
    border-color: rgba(255,255,255,0.20) !important;
    background: rgba(255,255,255,0.06) !important;
    box-shadow: 0 1px 12px rgba(0,0,0,0.30) !important;
  }

  html body #input-row {
    padding: 8px 8px 8px 8px !important;
    gap: 4px !important;
    align-items: flex-end !important;
  }

  /* Attach (+) button — left, ghost circle */
  html body #attach-btn {
    width: 38px !important; height: 38px !important;
    border-radius: 50% !important;
    background: transparent !important;
    color: rgba(255,255,255,0.70) !important;
    transition: background .15s, color .15s, transform .25s !important;
  }
  html body #attach-btn:hover,
  html body #attach-btn:active {
    background: rgba(255,255,255,0.08) !important;
    color: #fff !important;
  }
  html body #input-card.open #attach-btn {
    background: rgba(255,255,255,0.10) !important;
    color: #fff !important;
  }
  html body #attach-btn svg {
    width: 18px !important; height: 18px !important;
    stroke-width: 2.4 !important;
  }

  /* Textarea — fills middle */
  html body #txt {
    padding: 9px 8px !important;
    min-height: 38px !important;
    line-height: 1.5 !important;
    font-size: 16px !important;
    color: #f0f0f0 !important;
  }
  html body #txt::placeholder {
    color: rgba(255,255,255,0.38) !important;
  }

  /* Right group — mic + send */
  html body #input-btns {
    gap: 4px !important;
    align-self: flex-end !important;
  }

  /* Mic — ghost circle */
  html body #mic-btn {
    width: 38px !important; height: 38px !important;
    border-radius: 50% !important;
    background: transparent !important;
    transition: background .15s !important;
  }
  html body #mic-btn:hover,
  html body #mic-btn:active {
    background: rgba(255,255,255,0.08) !important;
  }
  html body #mic-btn svg {
    width: 17px !important; height: 17px !important;
    fill: rgba(255,255,255,0.70) !important;
  }
  html body #mic-btn.listening svg { fill: #ef4444 !important; }

  /* Send — accent-filled circle when enabled */
  html body #send-btn {
    width: 38px !important; height: 38px !important;
    border-radius: 50% !important;
    background: var(--accent, #eb3826) !important;
    transition: background .15s, opacity .15s, transform .12s !important;
  }
  html body #send-btn svg {
    stroke: #fff !important;
    width: 18px !important; height: 18px !important;
    stroke-width: 2.6 !important;
  }
  html body #send-btn:disabled {
    background: rgba(255,255,255,0.12) !important;
    opacity: 1 !important;
  }
  html body #send-btn:disabled svg {
    stroke: rgba(255,255,255,0.40) !important;
  }
  html body #send-btn:not(:disabled):active {
    transform: scale(0.94);
  }

  /* Attach toolbar — bigger touch targets, ChatGPT-like */
  html body #attach-toolbar {
    border-radius: 18px !important;
    padding: 8px !important;
    gap: 4px !important;
    background: #161618 !important;
    border-color: rgba(255,255,255,0.10) !important;
    box-shadow: 0 12px 32px rgba(0,0,0,0.55) !important;
  }
  html body #attach-toolbar .upload-btn {
    padding: 12px 14px !important;
    border-radius: 12px !important;
    background: transparent !important;
    color: rgba(255,255,255,0.78) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    gap: 11px !important;
  }
  html body #attach-toolbar .upload-btn svg {
    width: 18px !important; height: 18px !important;
    color: rgba(255,255,255,0.55) !important;
  }
  html body #attach-toolbar .upload-btn:hover,
  html body #attach-toolbar .upload-btn:active {
    background: rgba(255,255,255,0.08) !important;
    color: #fff !important;
  }
  html body #attach-toolbar .upload-btn:hover svg,
  html body #attach-toolbar .upload-btn:active svg {
    color: #fff !important;
  }

  /* Ctx badge — softer */
  html body #ctx-badge {
    padding: 8px 14px 0 !important;
    font-size: 12px !important;
  }

  /* Larger font sizes on mobile — ChatGPT-style readability */
  html body .bubble {
    font-size: 16px !important;
    line-height: 1.65 !important;
    padding: 10px 15px !important;
  }
  html body #txt {
    font-size: 16px !important;
    line-height: 1.45 !important;
  }
  html body #chat {
    padding: 16px 14px !important;
    gap: 10px !important;
  }
  html body .wc-title {
    font-size: 28px !important;
    line-height: 1.2 !important;
  }
  html body .wc-badge {
    font-size: 13px !important;
    padding: 4px 12px !important;
  }
  html body .wc-desc {
    font-size: 15px !important;
  }

  /* Welcome card — center vertically in visible chat area (ChatGPT-style empty state) */
  html body #chat:has(> #welcome-card) {
    justify-content: center !important;
  }
  html body #welcome-card {
    margin-top: auto !important;
    margin-bottom: auto !important;
  }

  /* Empty state — centered with subtle icon above text */
  html body aside#sidebar .sess-empty-hint {
    padding: 32px 14px 24px !important;
    font-size: 14px !important;
    color: rgba(255,255,255,0.68) !important;
    text-align: center !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 12px !important;
  }
  html body aside#sidebar .sess-empty-hint::before {
    content: '';
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: 1px dashed rgba(255,255,255,0.20);
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.65)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
  }

  /* Sidebar footer — bigger account row, ChatGPT-style card */
  html body aside#sidebar #sidebar-footer {
    padding: 10px !important;
    border-top: 1px solid rgba(255,255,255,0.04) !important;
    background: rgba(0,0,0,0.18) !important;
  }
  html body aside#sidebar .sb-acc-row {
    padding: 10px 10px !important;
    border-radius: 12px !important;
    gap: 11px !important;
    transition: background .15s !important;
  }
  html body aside#sidebar .sb-acc-row:hover {
    background: rgba(255,255,255,0.05) !important;
  }
  html body aside#sidebar .sb-acc-row:active {
    background: rgba(255,255,255,0.08) !important;
  }
  html body aside#sidebar .sb-acc-avatar {
    width: 38px !important;
    height: 38px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    border-radius: 10px !important;
    box-shadow: none !important;
  }
  html body aside#sidebar .sb-acc-name {
    font-size: 15px !important;
    font-weight: 600 !important;
    color: #fff !important;
    letter-spacing: -0.01em !important;
  }
  html body aside#sidebar .sb-acc-sub {
    font-size: 12.5px !important;
    color: rgba(255,255,255,0.72) !important;
    margin-top: 2px !important;
  }
  html body aside#sidebar .sb-acc-caret {
    color: rgba(255,255,255,0.62) !important;
    width: 16px !important;
    height: 16px !important;
  }

  html body #sb-sessions-popup {
    position: fixed !important;
    top: 0 !important; left: 280px !important; bottom: 0 !important;
    width: calc(100vw - 280px) !important; max-width: 280px !important;
    z-index: 9997 !important;
  }

  /* CAD slide — IMPORTANT - visible + transform-only */
  html body #cad-panel {
    position: fixed !important;
    top: 0 !important; right: 0 !important; bottom: 0 !important; left: auto !important;
    width: 100vw !important; max-width: 100vw !important;
    height: 100dvh !important;
    z-index: 9998 !important;
    transform: translateX(100%) !important;
    transition: transform 0.3s ease-out !important;
    box-shadow: -4px 0 24px rgba(0,0,0,0.7) !important;
    flex: none !important; min-width: 0 !important;
    border-left: none !important; border-top: none !important;
    display: flex !important; flex-direction: column !important;
    visibility: visible !important; opacity: 1 !important;
  }
  html body #cad-panel.mobile-open {
    transform: translateX(0) !important;
  }

  html body #split-handle { display: none !important; }

  /* Terminal / Tasks / Plugin panels — slide-in like CAD on mobile */
  html body #terminal-panel,
  html body #tasks-panel,
  html body #plugin-panel {
    position: fixed !important;
    top: 0 !important; right: 0 !important; bottom: 0 !important; left: auto !important;
    width: 100vw !important; max-width: 100vw !important;
    height: 100dvh !important;
    z-index: 9998 !important;
    transform: translateX(100%) !important;
    transition: transform 0.3s ease-out !important;
    box-shadow: -4px 0 24px rgba(0,0,0,0.55) !important;
    flex: none !important; min-width: 0 !important;
    border-left: none !important; border-top: none !important;
    display: none !important;
    flex-direction: column !important;
    visibility: hidden !important;
    pointer-events: none !important;
    background: var(--bg, #0a0a0a) !important;
    overflow: hidden !important;
  }
  html body #terminal-panel.mobile-open,
  html body #tasks-panel.mobile-open,
  html body #plugin-panel.mobile-open {
    transform: translateX(0) !important;
    display: flex !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  /* Light theme — softer shadow */
  html[data-theme="light"] body #terminal-panel,
  html[data-theme="light"] body #tasks-panel,
  html[data-theme="light"] body #plugin-panel {
    background: var(--bg, #ffffff) !important;
    box-shadow: -4px 0 24px rgba(0,0,0,0.18) !important;
  }

  /* Mobile panel close button — theme-aware ghost style */
  .mobile-panel-close-btn {
    background: rgba(255,255,255,0.06) !important;
    border: 1px solid rgba(255,255,255,0.12) !important;
    color: rgba(255,255,255,0.85) !important;
    transition: background .15s, border-color .15s, color .15s !important;
  }
  .mobile-panel-close-btn:hover {
    background: rgba(255,255,255,0.10) !important;
    border-color: rgba(255,255,255,0.20) !important;
    color: #fff !important;
  }
  .mobile-panel-close-btn:active {
    transform: scale(0.94);
  }
  /* Light theme — flip to black-alpha */
  html[data-theme="light"] .mobile-panel-close-btn {
    background: rgba(0,0,0,0.06) !important;
    border-color: rgba(0,0,0,0.12) !important;
    color: rgba(0,0,0,0.85) !important;
  }
  html[data-theme="light"] .mobile-panel-close-btn:hover {
    background: rgba(0,0,0,0.10) !important;
    border-color: rgba(0,0,0,0.20) !important;
    color: #000 !important;
  }

  /* Floating panels */
  #moss-capability-status, #moss-compressor,
  #moss-dxf-samples, #moss-perfmap {
    position: fixed !important;
    inset: 10px !important;
    width: auto !important; max-width: none !important;
    max-height: calc(100vh - 20px) !important;
    overflow-y: auto !important;
    z-index: 9999 !important;
  }

  /* Backdrop — covers only area NOT occupied by the open panel.
     Sidebar opens from left at min(86vw, 320px) → backdrop starts at that edge.
     CAD opens full-screen on mobile → backdrop hidden (covered anyway). */
  body.sidebar-open::before {
    content: '';
    position: fixed;
    top: 0; bottom: 0; right: 0;
    left: min(86vw, 320px);
    background: var(--ov40, rgba(0,0,0,0.40));
    z-index: 9989;
    pointer-events: none;
    transition: background .2s ease;
  }
  body.cad-open::before {
    content: '';
    position: fixed; inset: 0;
    background: var(--ov40, rgba(0,0,0,0.40));
    z-index: 9989;
    pointer-events: none;
    transition: background .2s ease;
  }
  /* Light theme — softer, less saturated backdrop so it doesn't look like an artifact */
  html[data-theme="light"] body.sidebar-open::before,
  html[data-theme="light"] body.cad-open::before {
    background: rgba(15,15,20,0.18) !important;
  }
}

@media (max-width: 480px) {
  html body header { padding: 4px 6px !important; gap: 4px !important; }
  html body aside#sidebar.mobile-open {
    width: 85vw !important; max-width: 320px !important; min-width: 0 !important;
  }
  html body #sb-sessions-popup {
    left: 0 !important; width: 100vw !important; max-width: 100vw !important;
  }
  button, .btn { min-height: 40px !important; }
  input, textarea, select { font-size: 16px !important; }
}

@media (hover: none) and (pointer: coarse) {
  .btn:active { transform: scale(0.96); }
  canvas { touch-action: pan-x pan-y pinch-zoom; }
}

#moss-cad-toggle, #moss-mobile-more-btn, #moss-mobile-popup, #moss-spacer { display: none; }

/* ── Fix chat input + send button on mobile ── */
@media (max-width: 1024px) {
  /* Make sure chat input area is fully clickable */
  html body .chat-input,
  html body #chat-input,
  html body [class*="chat-input"],
  html body [id*="composer"],
  html body .composer {
    position: relative !important;
    z-index: 100 !important;
  }

  /* Send button — touch-friendly */
  html body #send-btn,
  html body .send-btn,
  html body [id*="send"],
  html body button[class*="send"] {
    min-width: 44px !important;
    min-height: 44px !important;
    z-index: 101 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
    position: relative !important;
  }

  /* Input field — full functional */
  html body #txt,
  html body .chat-input textarea,
  html body .chat-input input,
  html body [class*="composer"] textarea,
  html body [class*="composer"] input {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    font-size: 16px !important;
    touch-action: manipulation !important;
  }

  /* Make sure input area not blocked by header */
  html body footer,
  html body .chat-bottom,
  html body .input-area {
    z-index: 100 !important;
    position: relative !important;
  }
}

/* ── Fix chat input + send button on mobile ── */
@media (max-width: 1024px) {
  /* Make sure chat input area is fully clickable */
  html body .chat-input,
  html body #chat-input,
  html body [class*="chat-input"],
  html body [id*="composer"],
  html body .composer {
    position: relative !important;
    z-index: 100 !important;
  }

  /* Send button — touch-friendly */
  html body #send-btn,
  html body .send-btn,
  html body [id*="send"],
  html body button[class*="send"] {
    min-width: 44px !important;
    min-height: 44px !important;
    z-index: 101 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
    position: relative !important;
  }

  /* Input field — full functional */
  html body #txt,
  html body .chat-input textarea,
  html body .chat-input input,
  html body [class*="composer"] textarea,
  html body [class*="composer"] input {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    font-size: 16px !important;
    touch-action: manipulation !important;
  }

  /* Make sure input area not blocked by header */
  html body footer,
  html body .chat-bottom,
  html body .input-area {
    z-index: 100 !important;
    position: relative !important;
  }
}

/* ── Fix chat input + send button on mobile ── */
@media (max-width: 1024px) {
  /* Make sure chat input area is fully clickable */
  html body .chat-input,
  html body #chat-input,
  html body [class*="chat-input"],
  html body [id*="composer"],
  html body .composer {
    position: relative !important;
    z-index: 100 !important;
  }

  /* Send button — touch-friendly */
  html body #send-btn,
  html body .send-btn,
  html body [id*="send"],
  html body button[class*="send"] {
    min-width: 44px !important;
    min-height: 44px !important;
    z-index: 101 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
    position: relative !important;
  }

  /* Input field — full functional */
  html body #txt,
  html body .chat-input textarea,
  html body .chat-input input,
  html body [class*="composer"] textarea,
  html body [class*="composer"] input {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    font-size: 16px !important;
    touch-action: manipulation !important;
  }

  /* Make sure input area not blocked by header */
  html body footer,
  html body .chat-bottom,
  html body .input-area {
    z-index: 100 !important;
    position: relative !important;
  }
}

/* ── Fix chat input + send button on mobile ── */
@media (max-width: 1024px) {
  /* Make sure chat input area is fully clickable */
  html body .chat-input,
  html body #chat-input,
  html body [class*="chat-input"],
  html body [id*="composer"],
  html body .composer {
    position: relative !important;
    z-index: 100 !important;
  }

  /* Send button — touch-friendly */
  html body #send-btn,
  html body .send-btn,
  html body [id*="send"],
  html body button[class*="send"] {
    min-width: 44px !important;
    min-height: 44px !important;
    z-index: 101 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
    position: relative !important;
  }

  /* Input field — full functional */
  html body #txt,
  html body .chat-input textarea,
  html body .chat-input input,
  html body [class*="composer"] textarea,
  html body [class*="composer"] input {
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    font-size: 16px !important;
    touch-action: manipulation !important;
  }

  /* Make sure input area not blocked by header */
  html body footer,
  html body .chat-bottom,
  html body .input-area {
    z-index: 100 !important;
    position: relative !important;
  }
}

/* ── Force send button always clickable on mobile ── */
@media (max-width: 1024px) {
  html body #send-btn,
  html body .send-btn,
  html body button[id*="send"]:not([id*="sent"]) {
    pointer-events: auto !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
    z-index: 999 !important;
    position: relative !important;
    min-width: 44px !important;
    min-height: 44px !important;
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Make sure footer/composer is on top */
  html body footer,
  html body .composer,
  html body .chat-input-area,
  html body [class*="composer"],
  html body [class*="input-area"] {
    z-index: 100 !important;
    position: relative !important;
    pointer-events: auto !important;
  }

  /* Ensure no overlay blocks input area */
  html body main,
  html body #main {
    pointer-events: auto !important;
  }
}


/* ── Light theme — mobile icon/button color overrides ─────────────────
   Most mobile rules above use rgba(255,255,255,X) for icons/text which
   look invisible on white. These overrides flip them to dark equivalents
   when light theme is active. */
@media (max-width: 1024px) {
  html[data-theme="light"] body header .sb-toggle,
  html[data-theme="light"] body #moss-cad-toggle,
  html[data-theme="light"] body #moss-mobile-more-btn {
    color: rgba(0,0,0,0.72) !important;
  }
  html[data-theme="light"] body header .sb-toggle:hover,
  html[data-theme="light"] body #moss-cad-toggle:hover,
  html[data-theme="light"] body #moss-mobile-more-btn:hover {
    background: rgba(0,0,0,0.06) !important;
    color: #000 !important;
  }
  html[data-theme="light"] body #moss-cad-toggle.active {
    background: rgba(0,0,0,0.08) !important;
    color: #000 !important;
  }

  /* Mode picker (Chat ▾) */
  html[data-theme="light"] body header > .mode-picker .mode-btn {
    color: rgba(0,0,0,0.92) !important;
  }
  html[data-theme="light"] body header > .mode-picker .mode-btn:hover,
  html[data-theme="light"] body header > .mode-picker .mode-btn.open {
    background: rgba(0,0,0,0.05) !important;
  }
  html[data-theme="light"] body header > .mode-picker .mode-chevron {
    color: rgba(0,0,0,0.45) !important;
  }

  /* Composer (input pill) */
  html[data-theme="light"] body #input-card {
    background: rgba(0,0,0,0.03) !important;
    border-color: rgba(0,0,0,0.10) !important;
  }
  html[data-theme="light"] body #input-card:focus-within {
    background: rgba(0,0,0,0.05) !important;
    border-color: rgba(0,0,0,0.20) !important;
  }
  html[data-theme="light"] body #attach-btn,
  html[data-theme="light"] body #mic-btn {
    color: rgba(0,0,0,0.62) !important;
  }
  html[data-theme="light"] body #attach-btn:hover,
  html[data-theme="light"] body #mic-btn:hover {
    background: rgba(0,0,0,0.06) !important;
    color: #000 !important;
  }
  html[data-theme="light"] body #txt {
    color: #18181b !important;
  }
  html[data-theme="light"] body #txt::placeholder {
    color: rgba(0,0,0,0.42) !important;
  }
  html[data-theme="light"] body #send-btn:disabled {
    background: rgba(0,0,0,0.10) !important;
  }
  html[data-theme="light"] body #send-btn:disabled svg {
    stroke: rgba(0,0,0,0.40) !important;
  }

  /* Sidebar */
  html[data-theme="light"] body aside#sidebar {
    background: linear-gradient(180deg, #fafafa 0%, #f4f4f6 100%) !important;
    border-right: 1px solid rgba(0,0,0,0.08) !important;
  }
  html[data-theme="light"] body aside#sidebar .side-group-label {
    color: rgba(0,0,0,0.55) !important;
  }
  html[data-theme="light"] body aside#sidebar .sess-empty-hint {
    color: rgba(0,0,0,0.55) !important;
  }
  html[data-theme="light"] body aside#sidebar .sess-empty-hint::before {
    background: rgba(0,0,0,0.04);
    border-color: rgba(0,0,0,0.18);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='rgba(0,0,0,0.55)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/%3E%3C/svg%3E");
  }
  html[data-theme="light"] body aside#sidebar #new-proj-btn,
  html[data-theme="light"] body aside#sidebar #sess-mgr-btn {
    border-color: rgba(0,0,0,0.10) !important;
    color: rgba(0,0,0,0.72) !important;
  }
  html[data-theme="light"] body aside#sidebar #new-proj-btn:hover,
  html[data-theme="light"] body aside#sidebar #sess-mgr-btn:hover {
    background: rgba(0,0,0,0.05) !important;
    border-color: rgba(0,0,0,0.20) !important;
    color: #000 !important;
  }
  html[data-theme="light"] body aside#sidebar #sidebar-footer {
    background: rgba(0,0,0,0.02) !important;
    border-top: 1px solid rgba(0,0,0,0.06) !important;
  }
  html[data-theme="light"] body aside#sidebar .sb-acc-name {
    color: #18181b !important;
  }
  html[data-theme="light"] body aside#sidebar .sb-acc-sub {
    color: rgba(0,0,0,0.55) !important;
  }
  html[data-theme="light"] body aside#sidebar .sb-acc-row:hover {
    background: rgba(0,0,0,0.05) !important;
  }

  /* More-menu popup */
  html[data-theme="light"] body #moss-mobile-popup {
    background: #ffffff !important;
    border-color: rgba(0,0,0,0.10) !important;
    box-shadow: 0 12px 32px rgba(0,0,0,0.20) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-item {
    color: rgba(0,0,0,0.85) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-item .icon {
    color: rgba(0,0,0,0.62) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-item:hover {
    background: rgba(0,0,0,0.05) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-item.active {
    background: rgba(0,0,0,0.05) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-item.active .icon {
    color: #000 !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-group {
    color: rgba(0,0,0,0.50) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-sep {
    background: rgba(0,0,0,0.08) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-item-text .mp-item-label {
    color: rgba(0,0,0,0.92) !important;
  }
  html[data-theme="light"] body #moss-mobile-popup .mp-item-text .mp-item-desc {
    color: rgba(0,0,0,0.50) !important;
  }

  /* Attach toolbar (composer + popup) — light theme */
  html[data-theme="light"] body #attach-toolbar {
    background: #ffffff !important;
    border-color: rgba(0,0,0,0.10) !important;
    box-shadow: 0 12px 32px rgba(0,0,0,0.18) !important;
  }
  html[data-theme="light"] body #attach-toolbar .upload-btn {
    background: transparent !important;
    color: rgba(0,0,0,0.78) !important;
  }
  html[data-theme="light"] body #attach-toolbar .upload-btn svg {
    color: rgba(0,0,0,0.55) !important;
  }
  html[data-theme="light"] body #attach-toolbar .upload-btn:hover,
  html[data-theme="light"] body #attach-toolbar .upload-btn:active {
    background: rgba(0,0,0,0.06) !important;
    color: #000 !important;
  }
  html[data-theme="light"] body #attach-toolbar .upload-btn:hover svg,
  html[data-theme="light"] body #attach-toolbar .upload-btn:active svg {
    color: #000 !important;
  }

  /* Ctx badge — light */
  html[data-theme="light"] body #ctx-badge {
    color: var(--accent) !important;
  }
  html[data-theme="light"] body #ctx-badge button {
    color: rgba(0,0,0,0.42) !important;
  }
}
