
      .main-shell {
        display: grid;
        grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
      }

      .sidebar {
        position: relative;
        z-index: 30;
        display: flex;
        flex-direction: column;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        border-left: 1px solid var(--border);
        background: rgba(23, 23, 23, 0.94);
        backdrop-filter: blur(16px);
      }

      html[data-theme="light"] .sidebar {
        background: rgba(239, 239, 235, 0.97);
      }

      .sidebar-header {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-5);
        border-bottom: 1px solid var(--border);
      }

      .brand-mark {
        flex: 0 0 auto;
        width: 48px;
        height: 48px;
        border: 1px solid var(--border-strong);
        border-radius: 16px;
        overflow: hidden;
        background: var(--surface);
      }

      .brand-title {
        display: grid;
        gap: 1px;
      }

      .brand-title strong {
        font-size: var(--text-sm);
        font-weight: 800;
        line-height: 1.3;
      }

      .brand-title span {
        color: var(--muted);
        font-size: var(--text-xs);
      }

      .sidebar-body {
        display: flex;
        flex: 1;
        flex-direction: column;
        gap: var(--space-5);
        min-height: 0;
        padding: var(--space-5);
      }


      .sidebar-section-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: var(--space-2);
      }

      .sidebar-section-title {
        color: var(--faint);
        font-size: var(--text-xs);
        font-weight: 800;
        margin-bottom: 0;
      }

      .new-chat-icon-button {
        background: none;
        border: none;
        color: var(--faint);
        font-size: 1.25rem;
        line-height: 1;
        cursor: pointer;
        padding: 0 var(--space-1);
        border-radius: var(--radius-sm);
        transition: color 0.15s, background 0.15s;
      }

      .new-chat-icon-button:hover {
        color: var(--text);
        background: rgba(255,255,255,0.08);
      }

      /* sidebar search */
      .sidebar-search-row {
        overflow: hidden;
        max-height: 0;
        opacity: 0;
        padding: 0;
        transition: max-height 0.2s ease, opacity 0.2s ease, padding 0.2s ease;
      }
      .sidebar-search-row.visible {
        max-height: 50px;
        opacity: 1;
        padding: var(--space-1) 0 var(--space-2);
      }
      .sidebar-search-input {
        width: 100%;
        background: var(--surface-soft);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        color: var(--text);
        font-family: inherit;
        font-size: var(--text-xs);
        padding: var(--space-2) var(--space-3);
        outline: none;
        box-sizing: border-box;
      }
      .sidebar-search-input::placeholder { color: var(--faint); }
      .sidebar-search-input:focus { border-color: var(--accent); }

      /* session date-group labels */
      .session-group-label {
        color: var(--faint);
        font-size: 0.68rem;
        font-weight: 800;
        letter-spacing: 0.05em;
        padding: var(--space-3) var(--space-2) var(--space-1);
      }

      /* message action buttons (copy / star / share) */
      .msg-actions-bar {
        display: flex;
        gap: var(--space-1);
        padding-top: var(--space-2);
        opacity: 0;
        transition: opacity 0.15s;
      }
      .bubble:hover .msg-actions-bar,
      .msg-actions-bar:focus-within { opacity: 1; }
      .msg-action-btn {
        background: none;
        border: none;
        color: var(--faint);
        cursor: pointer;
        font-size: 0.85rem;
        padding: 3px var(--space-2);
        border-radius: var(--radius-sm);
        transition: color 0.15s, background 0.15s;
        display: flex;
        align-items: center;
        gap: 3px;
        line-height: 1;
      }
      .msg-action-btn:hover { color: var(--text); background: var(--surface-soft); }
      .msg-action-btn.active { color: var(--accent); }

      /* related follow-up question chips */
      .related-section {
        margin-top: var(--space-4);
        padding-top: var(--space-3);
        border-top: 1px solid var(--border);
      }
      .related-label {
        color: var(--faint);
        font-size: 0.72rem;
        font-weight: 700;
        margin-bottom: var(--space-2);
      }
      .related-chips {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
      }
      .related-chip {
        background: var(--surface-soft);
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        color: var(--muted);
        cursor: pointer;
        font-family: inherit;
        font-size: var(--text-xs);
        padding: var(--space-2) var(--space-3);
        text-align: right;
        transition: background 0.15s, color 0.15s, border-color 0.15s;
      }
      .related-chip:hover {
        background: var(--surface-raised);
        border-color: var(--border-strong);
        color: var(--text);
      }

      /* bookmarks panel in sidebar */
      .bookmarks-section {
        padding-top: var(--space-2);
        border-top: 1px solid var(--border);
        margin-top: var(--space-2);
      }
      .bookmarks-panel {
        display: none;
        flex-direction: column;
        gap: var(--space-1);
        padding: var(--space-1) 0 var(--space-2);
        max-height: 220px;
        overflow-y: auto;
      }
      .bookmarks-panel.visible { display: flex; }
      .bookmark-item {
        background: var(--surface-soft);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        padding: var(--space-2) var(--space-3);
        color: var(--muted);
        display: flex;
        gap: var(--space-2);
        align-items: center;
        font-size: var(--text-xs);
      }
      .bookmark-item-text {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        cursor: pointer;
      }
      .bookmark-item-text:hover { color: var(--text); }
      .bookmark-remove {
        color: var(--faint);
        background: none;
        border: none;
        cursor: pointer;
        font-size: 1rem;
        padding: 0;
        flex-shrink: 0;
        line-height: 1;
      }
      .bookmark-remove:hover { color: var(--error); }
      .bookmarks-empty {
        color: var(--faint);
        font-size: var(--text-xs);
        padding: var(--space-2);
        text-align: center;
      }

      .session-list {
        display: grid;
        gap: var(--space-2);
        align-content: start;
        min-height: 0;
        overflow-y: auto;
        scrollbar-color: var(--surface-raised) transparent;
      }

      .sessions-wrap {
        display: flex;
        flex: 1;
        flex-direction: column;
        min-height: 0;
      }

      .session-button {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        min-height: 44px;
        border-radius: 14px;
        background: transparent;
        color: var(--muted);
        padding: var(--space-2) var(--space-3);
        text-align: right;
      }

      .session-main {
        display: grid;
        min-width: 0;
        gap: 2px;
      }

      .session-title {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .session-time {
        color: var(--faint);
        font-size: 0.74rem;
        font-weight: 600;
      }

      .session-delete {
        display: inline-grid;
        place-items: center;
        flex: 0 0 auto;
        width: 28px;
        min-height: 28px;
        border: 1px solid transparent;
        border-radius: 10px;
        background: transparent;
        color: var(--faint);
        font-size: 1.1rem;
        line-height: 1;
        opacity: 0;
      }

      .session-button:hover .session-delete,
      .session-button:focus-within .session-delete,
      .session-button.active .session-delete {
        opacity: 1;
      }

      .session-delete:hover {
        border-color: rgba(224, 122, 122, 0.28);
        background: rgba(224, 122, 122, 0.12);
        color: var(--error);
      }

      .session-button:hover,
      .session-button.active {
        background: rgba(255, 255, 255, 0.055);
        color: var(--text);
      }

      html[data-theme="light"] .session-button:hover,
      html[data-theme="light"] .session-button.active {
        background: rgba(0, 0, 0, 0.045);
      }

      .session-button.active {
        box-shadow: inset 0 0 0 1px var(--border);
      }

      .session-button span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .empty-sessions {
        border: 1px dashed var(--border);
        border-radius: 16px;
        color: var(--faint);
        font-size: var(--text-sm);
        padding: var(--space-4);
      }

      .sidebar-footer {
        display: grid;
        gap: var(--space-4);
        padding-top: var(--space-4);
        border-top: 1px solid var(--border);
      }

      .user-card {
        display: grid;
        gap: var(--space-3);
      }

      .user-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
      }

      .username {
        overflow: hidden;
        color: var(--text);
        font-size: var(--text-sm);
        font-weight: 800;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .role-badge,
      .subject-pill {
        display: inline-flex;
        align-items: center;
        min-height: 28px;
        border-radius: var(--radius-pill);
        font-size: var(--text-xs);
        font-weight: 800;
        white-space: nowrap;
      }

      .role-badge {
        border: 1px solid rgba(214, 177, 93, 0.28);
        background: rgba(214, 177, 93, 0.12);
        color: #f1d693;
        padding: 0 var(--space-3);
      }

      .role-badge.role-admin {
        border-color: rgba(214, 177, 93, 0.28);
        background: rgba(214, 177, 93, 0.12);
        color: #f1d693;
      }

      .role-badge.role-researcher {
        border-color: rgba(46, 139, 123, 0.36);
        background: rgba(46, 139, 123, 0.15);
        color: #9ee3d8;
      }

      .role-badge.role-user {
        border-color: var(--border);
        background: rgba(255, 255, 255, 0.045);
        color: var(--muted);
      }

      html[data-theme="light"] .role-badge.role-researcher,
      html[data-theme="light"] .badge-researcher {
        color: var(--teal-dark);
      }

      html[data-theme="light"] .role-badge.role-admin,
      html[data-theme="light"] .badge-admin {
        color: #7d5d12;
      }

      .sidebar-actions {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
      }

      .sidebar-actions .ghost-button {
        flex: 1 1 calc(50% - var(--space-2));
        min-width: 0;
        font-size: var(--text-xs);
        padding-inline: var(--space-2);
      }

      .workspace {
        position: relative;
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
      }

      .topbar {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) clamp(var(--space-4), 4vw, var(--space-8)) 0;
        border-bottom: 1px solid var(--border);
        background: rgba(33, 33, 33, 0.82);
        backdrop-filter: blur(18px);
        gap: clamp(var(--space-2), 2vw, var(--space-3));
      }

      html[data-theme="light"] .topbar,
      html[data-theme="light"] .admin-topbar {
        background: rgba(245, 243, 238, 0.90);
      }

      .topbar-actions {
        display: flex;
        align-items: center;
        gap: clamp(var(--space-1), 1.5vw, var(--space-2));
        flex: 0 0 auto;
      }

      .mode-pill {
        flex: 0 0 auto;
        gap: clamp(1px, 0.5vw, 2px);
      }

      .mobile-menu-button {
        flex: 0 0 auto;
      }

      .theme-toggle {
        display: inline-grid;
        place-items: center;
        width: clamp(32px, 8vw, 38px);
        min-height: clamp(32px, 8vw, 38px);
        border: 1px solid var(--border);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.04);
        color: var(--muted);
      }

      .theme-toggle:hover {
        border-color: var(--border-strong);
        background: rgba(255, 255, 255, 0.075);
        color: var(--text);
      }

      html[data-theme="light"] .theme-toggle {
        background: rgba(0, 0, 0, 0.035);
      }

      html[data-theme="light"] .theme-toggle:hover {
        background: rgba(0, 0, 0, 0.06);
      }

      .mobile-menu-button {
        display: none;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 44px;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.04);
      }

      .mobile-menu-lines,
      .mobile-menu-lines::before,
      .mobile-menu-lines::after {
        display: block;
        width: 18px;
        height: 2px;
        border-radius: 999px;
        background: var(--text);
        content: "";
      }

      .mobile-menu-lines {
        position: relative;
        margin: auto;
      }

      .mobile-menu-lines::before,
      .mobile-menu-lines::after {
        position: absolute;
        right: 0;
      }

      .mobile-menu-lines::before {
        top: -6px;
      }

      .mobile-menu-lines::after {
        top: 6px;
      }

      .status-pill {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        min-height: 34px;
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        background: rgba(255, 255, 255, 0.04);
        color: var(--muted);
        font-size: var(--text-xs);
        font-weight: 800;
        padding: 0 var(--space-3);
      }

      html[data-theme="light"] .status-pill {
        background: rgba(0, 0, 0, 0.035);
      }

      .status-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #777;
      }

      .status-pill.online .status-dot {
        background: var(--success);
        box-shadow: 0 0 0 4px rgba(111, 207, 151, 0.12);
      }

      .status-pill.offline .status-dot {
        background: #777;
      }

      .topbar-title {
        color: var(--muted);
        font-size: var(--text-sm);
        font-weight: 700;
      }

      /* ── Mode pill (محادثة / اختبار) ─────────────────────── */
      .mode-pill {
        display: flex;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        padding: 3px;
        gap: 2px;
      }
      .sum-topbar-title {
        display: none !important;
      }

      .mode-pill-btn {
        border: none;
        background: transparent;
        color: var(--muted);
        font-size: clamp(0.65rem, 2vw, var(--text-xs));
        font-weight: 700;
        padding: clamp(2px, 1vh, 4px) clamp(8px, 3vw, 16px);
        border-radius: var(--radius-pill);
        cursor: pointer;
        transition: background 0.15s, color 0.15s;
        white-space: nowrap;
      }
      .mode-pill-btn.active {
        background: var(--surface-raised);
        color: var(--text);
      }
      .mode-pill-btn:hover:not(.active) {
        color: var(--text);
      }

      .content {
        position: relative;
        flex: 1;
        min-height: 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
      }

      .welcome-view {
        display: grid;
        height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-top, 0px));
        min-height: 0;
        overflow: auto;
        place-items: center;
        padding: var(--space-8) clamp(var(--space-4), 5vw, var(--space-12));
      }

      .welcome-panel {
        display: grid;
        justify-items: center;
        width: min(100%, 860px);
        gap: var(--space-5);
        text-align: center;
      }

      .welcome-logo {
        width: 112px;
        height: 112px;
        border: 1px solid var(--border-strong);
        border-radius: 32px;
        overflow: hidden;
        background: var(--surface-raised);
        box-shadow: var(--shadow-raised);
      }

      .welcome-panel h2 {
        max-width: 18ch;
        color: var(--text);
        font-size: var(--text-xl);
        font-weight: 800;
        line-height: 1.2;
      }

      .welcome-panel p {
        color: var(--muted);
        font-size: var(--text-lg);
        max-width: 34ch;
        line-height: 1.4;
        transition: font-size 0.2s;
      }

      .welcome-composer-wrap {
        width: min(100%, 760px);
        margin-top: var(--space-2);
      }

      .suggestions {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-2);
        width: min(100%, 760px);
      }

      .suggestion-chip {
        min-height: 40px;
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        background: rgba(255, 255, 255, 0.035);
        color: var(--muted);
        font-size: var(--text-sm);
        padding: 0 var(--space-4);
      }

      html[data-theme="light"] .suggestion-chip {
        background: rgba(255, 255, 255, 0.66);
      }

      .suggestion-chip:hover {
        border-color: rgba(214, 177, 93, 0.32);
        background: rgba(214, 177, 93, 0.08);
        color: var(--text);
      }

      .chat-view {
        position: relative;
        display: flex;
        height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-top, 0px));
        min-height: 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        flex-direction: column;
        overflow: hidden;
      }

      .messages {
        flex: 1;
        min-height: 0;
        min-width: 0;
        overflow-y: auto;
        padding: var(--space-8) clamp(var(--space-4), 5vw, var(--space-12))
          calc(var(--composer-height) + var(--space-8));
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
      }

      .message-list {
        display: grid;
        width: min(100%, 900px);
        max-width: 100%;
        gap: var(--space-5);
        margin: 0 auto;
      }

      .empty-chat {
        text-align: center;
        color: var(--muted);
        font-size: var(--text-base);
        padding: var(--space-8) var(--space-4);
        grid-column: 1 / -1;
      }

      .message {
        display: grid;
        grid-template-columns: 52px minmax(0, 1fr);
        min-width: 0;
        max-width: 100%;
        gap: var(--space-4);
        align-items: start;
      }

      .message.user {
        grid-template-columns: minmax(0, 1fr) 52px;
      }

      .message.user .avatar {
        grid-column: 2;
      }

      .message.user .bubble-wrap {
        grid-column: 1;
        grid-row: 1;
        justify-items: end;
      }

      .avatar {
        display: grid;
        width: 52px;
        height: 52px;
        place-items: center;
        border: 1px solid var(--border);
        border-radius: 18px;
        overflow: hidden;
        background: var(--surface);
        color: var(--text);
        font-size: var(--text-xs);
        font-weight: 800;
      }

      .avatar-logo {
        width: 100%;
        height: 100%;
      }

      .bubble-wrap {
        display: grid;
        min-width: 0;
        max-width: 100%;
        gap: var(--space-2);
      }

      .role-label {
        color: var(--faint);
        font-size: var(--text-xs);
        font-weight: 800;
      }

      .bubble {
        max-width: min(100%, 760px);
        min-width: 0;
        border: 1px solid var(--border);
        border-radius: var(--radius-card);
        background: rgba(42, 42, 42, 0.9);
        box-shadow: var(--shadow-soft);
        padding: var(--space-5);
      }

      html[data-theme="light"] .bubble {
        background: rgba(255, 255, 255, 0.94);
      }

      .message.user .bubble {
        background: rgba(46, 139, 123, 0.16);
        border-color: rgba(46, 139, 123, 0.28);
      }

      .answer-text,
      .user-text {
        overflow-wrap: anywhere;
        word-break: break-word;
        white-space: pre-wrap;
      }

      .answer-text p,
      .user-text p {
        max-width: 72ch;
      }

      .answer-text p + p,
      .user-text p + p {
        margin-top: var(--space-3);
      }

      .answer-text h1, .answer-text h2, .answer-text h3,
      .answer-text h4, .answer-text h5, .answer-text h6 {
        margin: var(--space-4) 0 var(--space-2);
        font-weight: 700;
        line-height: 1.3;
      }
      .answer-text h1 { font-size: 1.35em; }
      .answer-text h2 { font-size: 1.2em; }
      .answer-text h3 { font-size: 1.05em; }

      .answer-text table {
        border-collapse: collapse;
        width: 100%;
        margin: var(--space-3) 0;
        font-size: var(--text-sm);
      }
      .answer-text th, .answer-text td {
        border: 1px solid var(--border-strong);
        padding: .4rem .75rem;
        text-align: start;
      }
      .answer-text th {
        background: var(--surface-raised);
        font-weight: 700;
      }
      .answer-text tr:nth-child(even) td {
        background: var(--surface-soft);
      }

      .sources-line {
        margin-top: var(--space-4);
        border-top: 1px solid var(--border);
        padding-top: var(--space-3);
        color: var(--muted);
        font-size: var(--text-sm);
      }

      .chunks-toggle {
        display: inline-flex;
        align-items: center;
        min-height: 36px;
        margin-top: var(--space-3);
        border-radius: var(--radius-pill);
        background: rgba(255, 255, 255, 0.045);
        color: var(--gold);
        font-size: var(--text-xs);
        font-weight: 800;
        padding: 0 var(--space-3);
        border: 1px solid rgba(214, 177, 93, 0.3);
      }

      html[data-theme="light"] .chunks-toggle {
        background: rgba(214, 177, 93, 0.15);
        color: #8b6f47;
        border-color: rgba(214, 177, 93, 0.5);
      }

      .chunks-toggle:hover {
        background: rgba(214, 177, 93, 0.12);
      }

      html[data-theme="light"] .chunks-toggle:hover {
        background: rgba(214, 177, 93, 0.25);
      }

      .sources-panel {
        display: grid;
        gap: var(--space-3);
        margin-top: var(--space-3);
      }

      .source-card {
        border: 1px solid var(--border);
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.035);
        padding: var(--space-4);
      }

      .source-meta {
        display: grid;
        gap: var(--space-2);
        color: var(--muted);
        font-size: var(--text-sm);
      }

      .source-meta-row {
        display: grid;
        grid-template-columns: 110px minmax(0, 1fr);
        gap: var(--space-2);
      }

      .source-meta-row strong {
        color: var(--text);
        font-weight: 800;
      }

      .sources-model-row {
        display: grid;
        grid-template-columns: 110px minmax(0, 1fr);
        gap: var(--space-2);
        font-size: var(--text-sm);
        color: var(--muted);
        padding: var(--space-2) 0 var(--space-3);
        border-bottom: 1px solid var(--border);
        margin-bottom: var(--space-2);
      }

      .sources-model-row strong {
        color: var(--text);
        font-weight: 800;
      }

      .source-text {
        margin-top: var(--space-4);
        border-top: 1px solid var(--border);
        padding-top: var(--space-4);
        color: var(--text);
        font-size: var(--text-sm);
        overflow-wrap: anywhere;
        word-break: break-word;
        white-space: pre-wrap;
      }

      .source-copy-btn {
        display: flex;
        align-items: center;
        gap: 4px;
        margin-top: var(--space-3);
        background: rgba(255, 255, 255, 0.045);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        color: var(--gold);
        font-size: 0.85rem;
        font-weight: 600;
        padding: 6px var(--space-3);
        cursor: pointer;
        transition: background 0.15s, color 0.15s, border-color 0.15s;
      }

      .source-copy-btn:hover {
        background: rgba(214, 177, 93, 0.12);
        border-color: rgba(214, 177, 93, 0.3);
        color: rgba(214, 177, 93, 1);
      }

      html[data-theme="light"] .source-copy-btn {
        background: rgba(214, 177, 93, 0.08);
        border-color: rgba(214, 177, 93, 0.28);
        color: #8b6f47;
      }

      html[data-theme="light"] .source-copy-btn:hover {
        background: rgba(214, 177, 93, 0.18);
        color: #6b5535;
      }

      .typing {
        display: inline-flex;
        align-items: center;
        gap: var(--space-3);
        color: var(--muted);
        font-weight: 700;
      }

      .typing-dots {
        display: inline-flex;
        gap: 5px;
        direction: ltr;
      }

      .typing-dots span {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        animation: typing-dot 1s ease-in-out infinite;
        background: var(--gold);
      }

      .typing-dots span:nth-child(2) {
        animation-delay: 120ms;
      }

      .typing-dots span:nth-child(3) {
        animation-delay: 240ms;
      }

      @keyframes typing-dot {
        0%,
        80%,
        100% {
          opacity: 0.35;
          transform: translateY(0);
        }
        40% {
          opacity: 1;
          transform: translateY(-4px);
        }
      }

      .error-type-badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 3px 10px;
        margin-bottom: var(--space-3);
        border-radius: 20px;
        font-size: var(--text-xs);
        font-weight: 700;
        background: rgba(224, 122, 122, 0.15);
        color: var(--error);
        border: 1px solid rgba(224, 122, 122, 0.3);
      }

      html[data-theme="light"] .error-type-badge {
        background: rgba(200, 60, 60, 0.08);
        color: #b33333;
        border-color: rgba(200, 60, 60, 0.25);
      }

      .no-context-warning {
        display: flex;
        align-items: flex-start;
        gap: 6px;
        padding: 6px 11px;
        margin-bottom: var(--space-3);
        border-radius: 10px;
        font-size: var(--text-xs);
        font-weight: 600;
        line-height: 1.5;
        background: rgba(232, 168, 73, 0.14);
        color: #d99020;
        border: 1px solid rgba(232, 168, 73, 0.32);
      }

      .no-context-warning .no-context-icon {
        font-size: 1rem;
        line-height: 1.3;
        flex-shrink: 0;
      }

      html[data-theme="light"] .no-context-warning {
        background: rgba(180, 120, 20, 0.08);
        color: #9a6a10;
        border-color: rgba(180, 120, 20, 0.28);
      }

      .composer-fixed {
        position: absolute;
        right: 0;
        bottom: 0;
        left: 0;
        display: grid;
        place-items: center;
        padding: var(--space-4) clamp(var(--space-4), 5vw, var(--space-12));
        background: linear-gradient(to top, rgba(33, 33, 33, 0.98), rgba(33, 33, 33, 0.76), transparent);
        pointer-events: none;
      }

      html[data-theme="light"] .composer-fixed {
        background: linear-gradient(to top, rgba(247, 251, 255, 0.98), rgba(247, 251, 255, 0.76), transparent);
      }

      .composer {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: end;
        width: min(100%, 900px);
        gap: var(--space-3);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-composer);
        background: rgba(13, 33, 56, 0.96);
        box-shadow: var(--shadow-raised);
        padding: var(--space-2);
        pointer-events: auto;
      }

      .settings-panel {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) var(--space-2) var(--space-1);
        border-bottom: 1px solid rgba(255, 255, 255, 0.07);
        margin-bottom: var(--space-1);
      }

      .settings-panel[hidden] { display: none; }

      html[data-theme="light"] .settings-panel {
        border-bottom-color: rgba(0, 0, 0, 0.06);
      }

      .settings-item {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        flex-wrap: wrap;
      }


      .settings-label {
        font-size: var(--text-xs);
        font-weight: 800;
        color: var(--faint);
        white-space: nowrap;
      }

      .composer-actions {
        display: flex;
        align-items: flex-end;
        gap: var(--space-2);
      }

      .settings-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 52px;
        font-size: 1.1rem;
        border-radius: var(--radius-pill);
      }


      html[data-theme="light"] .composer {
        background: rgba(255, 255, 255, 0.94);
      }

      .composer-textarea {
        min-height: 52px;
        max-height: 220px;
        resize: none;
        overflow-y: hidden;
        border: 0;
        border-radius: 22px;
        background: transparent;
        padding: 14px var(--space-4);
        line-height: 1.65;
      }

      .composer-textarea:focus {
        box-shadow: none;
      }

      .send-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 96px;
        min-height: 52px;
      }

      .attach-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 52px;
        font-size: 1.1rem;
        border-radius: var(--radius-pill);
      }

      .file-chips-area {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-2) 0;
      }

      .file-chips-area[hidden] { display: none; }

      .file-chip {
        display: inline-flex;
        align-items: center;
        gap: var(--space-1);
        padding: 3px 6px 3px var(--space-3);
        border-radius: var(--radius-pill);
        background: var(--surface-raised);
        border: 1px solid var(--border-strong);
        font-size: var(--text-xs);
        color: var(--muted);
        max-width: 220px;
      }

      .file-chip-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .file-chip-remove {
        min-height: auto;
        background: none;
        border: none;
        padding: 0 2px;
        color: var(--faint);
        font-size: 14px;
        line-height: 1;
        cursor: pointer;
        border-radius: 50%;
      }

      .file-chip-remove:hover {
        color: var(--error);
        background: none;
      }

      @media (max-width: 640px) {
        .settings-panel {
          gap: var(--space-2);
        }
      }

      .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 24;
        display: none;
        background: rgba(0, 0, 0, 0.5);
      }

      .sidebar-dismiss-btn {
        display: none;
      }

      /* ── Global popup ─────────────────────────────────────────────────── */
      .global-popup-overlay {
        position: fixed;
        inset: 0;
        z-index: 9990;
        background: rgba(0,0,0,0.55);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-4);
      }
      .global-popup-overlay.hidden { display: none; }

      .global-popup-card {
        background: var(--surface-raised, var(--surface));
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        padding: var(--space-6) var(--space-5);
        max-width: 420px;
        width: 100%;
        text-align: center;
        box-shadow: 0 8px 32px rgba(0,0,0,0.35);
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
      }

      .global-popup-icon { font-size: 2rem; }

      .global-popup-title {
        font-size: var(--text-base);
        font-weight: 700;
        margin: 0;
      }

      .global-popup-msg {
        font-size: var(--text-sm);
        line-height: 1.7;
        color: var(--muted);
        margin: 0;
      }

      .global-popup-actions {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
        margin-top: var(--space-1);
      }

      /* ── Trial mode ───────────────────────────────────────────────────── */
      .trial-banner {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-3);
        background: var(--accent);
        color: #fff;
        font-size: var(--text-xs);
        font-weight: 700;
        padding: 6px var(--space-4);
        flex-wrap: wrap;
        text-align: center;
      }

      .trial-banner a, .trial-banner button {
        color: #fff;
        text-decoration: underline;
        background: none;
        border: none;
        padding: 0;
        font: inherit;
        cursor: pointer;
        font-size: var(--text-xs);
      }

      .trial-main-shell .sidebar { display: none !important; }
      .trial-main-shell .main-shell { grid-template-columns: 1fr; }

      .trial-limit-msg {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        padding: var(--space-5);
        text-align: center;
        margin: var(--space-4) auto;
        max-width: 480px;
        line-height: 1.8;
      }

      /* ── QA history view ──────────────────────────────────────────────── */
      .qa-history-item {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        padding: var(--space-3) var(--space-4);
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
      }

      .qa-history-row {
        display: flex;
        gap: var(--space-2);
        align-items: baseline;
        flex-wrap: wrap;
        font-size: var(--text-xs);
        color: var(--muted);
      }

      .qa-history-subject {
        font-weight: 700;
        font-size: var(--text-sm);
        color: var(--text);
      }

      .qa-history-badge {
        background: var(--surface-raised, var(--surface));
        border: 1px solid var(--border);
        border-radius: 999px;
        padding: 1px 8px;
        font-size: 11px;
      }

      .qa-history-incomplete {
        color: var(--warning, #f59e0b);
        font-size: 11px;
        font-weight: 600;
      }

      .qa-history-settings {
        font-size: var(--text-xs);
        color: var(--faint);
        font-style: italic;
        padding: 6px 0 2px 0;
        border-top: 1px solid var(--border);
        margin-top: 4px;
      }

      /* ── Admin QA sessions table ──────────────────────────────────────── */
      .qa-admin-session-block {
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        overflow: hidden;
        margin-bottom: var(--space-2);
        font-size: var(--text-xs);
      }

      .qa-admin-session-row {
        display: flex;
        gap: var(--space-3);
        align-items: center;
        padding: var(--space-2) var(--space-3);
        flex-wrap: wrap;
      }

      .qa-admin-session-row + .qa-admin-session-row {
        border-top: 1px solid var(--border);
      }

      .qa-admin-session-row.user-row { background: var(--surface-2, var(--surface)); font-weight: 600; }
      .qa-admin-session-row.settings-row { background: var(--surface); color: var(--muted); }
      .qa-admin-session-row.results-row { background: var(--surface); }

      /* ── Locked subject/model badge ───────────────────────────────────── */
      .upgrade-hint {
        font-size: var(--text-xs);
        color: var(--accent);
        margin-inline-start: 4px;
      }

      #iosInstallInstructions {
        position: fixed;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
        inset-inline: var(--space-4);
        background: var(--surface-2, #2a2a2a);
        color: var(--text-1, #f0f0f0);
        border: 1px solid var(--border, #444);
        border-radius: var(--radius-lg, 12px);
        padding: var(--space-4);
        font-size: var(--text-sm);
        line-height: 1.6;
        text-align: center;
        z-index: 9999;
        box-shadow: 0 4px 24px rgba(0,0,0,.4);
        animation: fadeInUp .25s ease;
      }

      @keyframes fadeInUp {
        from { opacity: 0; transform: translateY(12px); }
        to   { opacity: 1; transform: translateY(0); }
      }
