/* app-shell.css
 * Extracted from the original inline <style> block.
 * Load order matters: see the <link> order in index.html.
 */
  /* ================= ROOT VIEWPORT (dvh — survives mobile address bars) ================= */
    html, body {
      height: 100%;
      height: 100dvh;
      margin: 0;
      padding: 0;
      overflow: hidden;
      overscroll-behavior: none;
    }

    /* ================= APP SHELL: strict flex column ================= */
    #appShell {
      display: flex !important;
      flex-direction: column !important;
      height: 100%;
      height: 100dvh;
      width: 100%;
      width: 100vw;
      min-height: 0 !important;
      overflow: hidden;
    }
    /* main is the only scroll region for the non-chat tabs */
    main {
      flex: 1 1 auto;
      min-height: 0;
      overflow-y: auto;
      overflow-x: hidden;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: contain;
    }
    main > div { min-height: 0; }

    /* ================= CHAT TAB: history scrolls, input bar never shrinks ================= */
    body:has([data-panel="chat"]:not(.hidden)) main {
      display: flex !important;
      flex-direction: column !important;
      overflow: hidden !important;
      height: 100%;
    }
    body:has([data-panel="chat"]:not(.hidden)) main > div {
      flex: 1 1 auto;
      display: flex;
      flex-direction: column;
      min-height: 0;
      height: auto;
      max-height: none;
      padding-bottom: 0 !important;
    }
    [data-panel="chat"] {
      flex: 1 1 auto;
      min-height: 0;
      display: flex;
      flex-direction: column;
    }
    #chatPanel {
      flex: 1 1 auto;
      min-height: 0;
      height: auto;
      max-height: 100%;
      overflow: hidden;
    }
    #chatHeader { flex: 0 0 auto; }

    /* ---- chat history: the ONLY growing / scrolling area ---- */
    #chatMessages {
      flex: 1 1 auto !important;
      min-height: 0 !important;
      max-height: none !important;
      overflow-y: auto !important;
      overflow-x: hidden !important;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: contain;
      padding-bottom: 10px !important;
    }

    /* ---- chat input bar: pinned by flexbox, protected from shrinking ---- */
    #chatMessages + div {
      position: relative !important;
      top: auto !important;
      right: auto !important;
      bottom: auto !important;
      left: auto !important;
      flex: 0 0 auto !important;
      width: 100%;
      background: var(--chat-input-bg, #1e1e2e);
      backdrop-filter: blur(14px);
      -webkit-backdrop-filter: blur(14px);
      border-top: 1px solid var(--chat-border, rgba(255, 255, 255, 0.1));
      z-index: 100;
      padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important;
    }
    #chatInput { max-height: 32dvh; }

    @media (max-width: 768px) {
      body:has([data-panel="chat"]:not(.hidden)) #pageHeader { flex: 0 0 auto; margin-bottom: 0.5rem; }
      #chatMessages + div { padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px)) !important; }
    }

    /* ================= CLOSE (X) BUTTON — pinned inside its container ================= */
    .modal-card { position: relative; }
    .modal-head {
      position: sticky;
      top: 0;
      padding-right: 4rem; /* reserve space so the X never overlaps the title */
    }
    .modal-close {
      position: absolute;
      top: 15px;
      right: 15px;
      left: auto;
      bottom: auto;
      z-index: 50;
      margin: 0 !important;
      transform: none !important;
      flex: 0 0 auto;
    }
    /* legacy modal close buttons (Character Studio / Chat Settings) */
    [data-close] {
      position: static;
      margin: 0 !important;
      transform: none !important;
      flex: 0 0 auto;
    }
    [data-close]:not(.absolute) { top: auto; right: auto; }
  /* ================= BETA / نسخة تجريبية BADGE ================= */
    .app-title { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0 2px; }
    .beta-badge {
      display: inline-block;
      font-size: 0.45em;
      vertical-align: super;
      background: linear-gradient(45deg, #ff007a, #7a00ff);
      color: #ffffff;
      padding: 3px 8px;
      border-radius: 6px;
      margin-left: 8px;
      font-weight: 800;
      text-transform: uppercase;
      letter-spacing: 1px;
      line-height: 1.15;
      white-space: nowrap;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
      -webkit-user-select: none;
      user-select: none;
    }
    /* Readability on the light theme */
    body[data-theme="light"] .beta-badge {
      background: linear-gradient(45deg, #db2777, #6d28d9);
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    }
