      :root {
        --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
        --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
        --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
        --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
        --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
        --space-1: 0.25rem;
        --space-2: 0.5rem;
        --space-3: 0.75rem;
        --space-4: 1rem;
        --space-5: 1.25rem;
        --space-6: 1.5rem;
        --space-8: 2rem;
        --space-10: 2.5rem;
        --space-12: 3rem;
        --space-16: 4rem;
        --bg: #071526;
        --sidebar: #06111f;
        --surface: #0d2138;
        --surface-raised: #12304f;
        --surface-soft: rgba(255, 255, 255, 0.055);
        --surface-dynamic: #18395d;
        --border: rgba(255, 255, 255, 0.10);
        --border-strong: rgba(255, 255, 255, 0.18);
        --text: #f7fbff;
        --muted: #bfd0e2;
        --faint: #82a0bd;
        --gold: #ffffff;
        --gold-dark: #d9e8f7;
        --teal: #56b6d6;
        --teal-dark: #2d7da4;
        --error: #e07a7a;
        --success: #6fcf97;
        --radius-card: 18px;
        --radius-composer: 28px;
        --radius-pill: 999px;
        --shadow-raised: 0 18px 48px rgba(0, 0, 0, 0.22);
        --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.18);
        --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
        --font-body: "Noto Sans Arabic", Tahoma, Arial, sans-serif;
        --sidebar-width: 318px;
        --topbar-height: 72px;
        --composer-height: 122px;
      }

      html[data-theme="light"] {
        --bg: #f7fbff;
        --surface: #ffffff;
        --sidebar: #edf5fc;
        --text: #0b1f35;
        --muted: #54708c;
        --faint: #5e7791;
        --gold: #1a6fa8;
        --gold-dark: #c4ddf0;
        --border: rgba(7, 21, 38, 0.11);
        --border-strong: rgba(7, 21, 38, 0.20);
        --surface-raised: #e3eef8;
        --surface-soft: rgba(7, 21, 38, 0.035);
        --surface-dynamic: #d7e7f5;
        --shadow-raised: 0 18px 48px rgba(0, 0, 0, 0.10);
        --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.07);
      }

      html[data-amoled]:not([data-theme="light"]) {
        --bg: #000000;
        --sidebar: #000000;
        --surface: #0a0a0a;
        --surface-raised: #161616;
        --surface-soft: rgba(255, 255, 255, 0.04);
        --surface-dynamic: #1f1f1f;
        --border: rgba(255, 255, 255, 0.09);
        --border-strong: rgba(255, 255, 255, 0.16);
        --shadow-raised: 0 18px 48px rgba(0, 0, 0, 0.6);
        --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.5);
      }

      html[data-amoled]:not([data-theme="light"]) body {
        background: var(--bg);
      }

      *,
      *::before,
      *::after {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      html {
        -moz-text-size-adjust: none;
        -webkit-text-size-adjust: none;
        text-size-adjust: none;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
      }

      body {
        width: 100%;
        max-width: 100%;
        min-height: 100dvh;
        overflow: hidden;
        overflow-x: hidden;
        overscroll-behavior-x: none;
        background:
          radial-gradient(circle at 76% -8%, rgba(86, 182, 214, 0.20), transparent 34rem),
          radial-gradient(circle at 7% 89%, rgba(255, 255, 255, 0.08), transparent 32rem),
          var(--bg);
        color: var(--text);
        font-family: var(--font-body);
        font-size: var(--text-base);
        line-height: 1.65;
      }

      html[data-theme="light"] body {
        background:
          radial-gradient(circle at 76% -8%, rgba(86, 182, 214, 0.18), transparent 34rem),
          radial-gradient(circle at 7% 89%, rgba(7, 21, 38, 0.08), transparent 32rem),
          var(--bg);
      }

      img,
      svg {
        display: block;
        max-width: 100%;
      }

      button,
      input,
      textarea,
      select {
        max-width: 100%;
        min-width: 0;
        font: inherit;
        color: inherit;
      }

      button,
      input,
      textarea,
      [role="button"] {
        transition:
          background var(--transition),
          border-color var(--transition),
          color var(--transition),
          box-shadow var(--transition),
          opacity var(--transition),
          transform var(--transition);
      }

      button {
        min-height: 44px;
        border: 0;
        cursor: pointer;
      }

      button:disabled {
        cursor: not-allowed;
        opacity: 0.55;
      }

      :focus-visible {
        outline: 2px solid var(--gold);
        outline-offset: 3px;
        border-radius: 12px;
      }

      .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
      }

      .app-shell {
        position: relative;
        min-height: 100vh;
        min-height: 100dvh;
      }

      .screen {
        min-height: 100vh;
        min-height: 100dvh;
      }

      .hidden {
        display: none !important;
      }

      .skip-link {
        position: fixed;
        top: var(--space-4);
        right: var(--space-4);
        z-index: 1000;
        transform: translateY(-160%);
        border-radius: var(--radius-pill);
        background: var(--gold);
        color: #171717;
        padding: var(--space-2) var(--space-4);
        font-weight: 800;
        text-decoration: none;
      }

      .skip-link:focus {
        transform: translateY(0);
      }

      /* ── Display preferences: font size ────────────────────────────────── */
      body.font-sm {
        --text-xs:   0.7rem;
        --text-sm:   0.8rem;
        --text-base: 0.9rem;
        --text-lg:   1.1rem;
        --text-xl:   1.4rem;
      }
      body.font-lg {
        --text-xs:   0.85rem;
        --text-sm:   1rem;
        --text-base: 1.2rem;
        --text-lg:   1.5rem;
        --text-xl:   2rem;
      }

      /* ── Display preferences: density ──────────────────────────────────── */
      body.density-compact {
        --space-3: 0.4rem;
        --space-4: 0.6rem;
        --space-6: 0.9rem;
        --space-8: 1.2rem;
      }

/* Noto Sans Arabic — self-hosted (variable font, arabic + latin subsets) */
@font-face {
  font-family: 'Noto Sans Arabic';
  font-style: normal;
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('/css/fonts/noto-sans-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF,
    U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4,
    U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24,
    U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42,
    U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54,
    U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64,
    U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E,
    U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9,
    U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'Noto Sans Arabic';
  font-style: normal;
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('/css/fonts/noto-sans-arabic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


      .main-shell {
        display: grid;
        grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
        width: 100%;
        max-width: 100%;
        height: 100vh;          /* fallback for browsers without dvh (iOS <15.4) */
        height: 100dvh;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: hidden;
      }

      .sidebar {
        position: relative;
        z-index: 30;
        display: flex;
        flex-direction: column;
        height: 100vh;          /* fallback for browsers without dvh */
        height: 100dvh;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: hidden;
        border-left: 1px solid var(--border);
        background: rgba(23, 23, 23, 0.94);
        -webkit-backdrop-filter: blur(16px);
        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;
      }

      /* Drag-to-reorder pinned conversations (feature #17). */
      .pinned-group {
        display: grid;
        gap: var(--space-1);
      }
      .session-button[data-pinned-item] {
        cursor: grab;
      }
      .session-button.dragging {
        opacity: 0.5;
        cursor: grabbing;
      }

      /* Inline title rename input (feature #16). */
      .session-rename-input {
        width: 100%;
        min-width: 0;
        border: 1px solid var(--accent, #2f9e7a);
        border-radius: 8px;
        background: var(--surface, #fff);
        color: var(--text, #111);
        padding: 2px 6px;
        font: inherit;
      }

      /* Skeleton loaders (feature #19). */
      .skeleton {
        position: relative;
        overflow: hidden;
        background: var(--surface-2, rgba(255,255,255,0.06));
        border-radius: 10px;
      }
      .skeleton::after {
        content: "";
        position: absolute;
        inset: 0;
        transform: translateX(-100%);
        background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
        animation: skeleton-shimmer 1.3s infinite;
      }
      @keyframes skeleton-shimmer {
        100% { transform: translateX(100%); }
      }
      .session-skeleton {
        height: 40px;
        margin-bottom: var(--space-2);
      }
      .msg-skeleton {
        height: 56px;
        margin: var(--space-3) 0;
        max-width: 75%;
      }
      .msg-skeleton--user {
        margin-inline-start: auto;
        max-width: 55%;
      }
      @media (prefers-reduced-motion: reduce) {
        .skeleton::after { animation: none; }
      }

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

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

      .session-actions {
        display: flex;
        align-items: center;
        gap: 2px;
        flex: 0 0 auto;
      }

      .session-delete,
      .session-pin {
        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: 0.85rem;
        line-height: 1;
        opacity: 0;
        cursor: pointer;
      }

      .session-pin--active {
        opacity: 0.6;
      }

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

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

      .session-pin:hover {
        background: rgba(255, 255, 255, 0.08);
      }

      .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);
        -webkit-backdrop-filter: blur(18px);
        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);
      }

      .continue-reading-card {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        width: min(100%, 760px);
        margin-top: var(--space-4);
        padding: var(--space-3) var(--space-4);
        border: 1px solid rgba(214, 177, 93, 0.32);
        border-radius: var(--radius-md);
        background: rgba(214, 177, 93, 0.06);
        color: var(--text);
        text-align: start;
        cursor: pointer;
        transition: background 0.15s ease, border-color 0.15s ease;
      }

      .continue-reading-card:hover {
        background: rgba(214, 177, 93, 0.12);
        border-color: rgba(214, 177, 93, 0.5);
      }

      .continue-reading-icon {
        font-size: 1.5rem;
        flex-shrink: 0;
      }

      .continue-reading-text {
        display: flex;
        flex-direction: column;
        gap: 2px;
        flex: 1 1 auto;
        min-width: 0;
      }

      .continue-reading-label {
        font-size: var(--text-xs);
        color: var(--muted);
      }

      .continue-reading-title {
        font-size: var(--text-sm);
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .continue-reading-arrow {
        color: var(--accent);
        font-size: 1.2rem;
        flex-shrink: 0;
      }

      .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);
        transition: box-shadow 0.3s ease, border-color 0.3s ease;
      }

      .source-card.source-flash {
        border-color: var(--accent, #2f9e7a);
        box-shadow: 0 0 0 2px var(--accent, #2f9e7a);
      }

      /* Inline footnote refs under an answer (feature #11). */
      .footnote-bar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2);
        margin-top: var(--space-2);
      }
      .footnote-bar-label {
        font-size: var(--text-xs);
        color: var(--muted);
      }
      .footnote-ref {
        border: 1px solid var(--border);
        background: var(--surface-2, rgba(255,255,255,0.05));
        color: var(--accent, #2f9e7a);
        border-radius: 999px;
        min-width: 1.6em;
        height: 1.6em;
        padding: 0 0.4em;
        font-size: var(--text-sm);
        cursor: pointer;
        line-height: 1;
      }
      .footnote-ref:hover {
        border-color: var(--accent, #2f9e7a);
      }

      .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);
      }

      .reasoning-block {
        margin-bottom: var(--space-3);
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--surface-2);
        padding: 6px 11px;
        font-size: var(--text-xs);
      }
      .reasoning-block > summary {
        cursor: pointer;
        font-weight: 600;
        color: var(--muted);
        list-style: none;
      }
      .reasoning-block > summary::-webkit-details-marker { display: none; }
      .reasoning-block .reasoning-body {
        margin-top: var(--space-2);
        padding-top: var(--space-2);
        border-top: 1px dashed var(--border);
        color: var(--text-secondary, var(--muted));
        line-height: 1.7;
        white-space: pre-wrap;
      }

      .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;
      }

      /* Action buttons inside the settings panel (attach / voice): full-width row, paperclip-style. */
      .settings-action-btn {
        flex: 1 1 100%;
        display: flex;
        align-items: center;
        gap: var(--space-2);
        min-height: 36px;
        padding: var(--space-1) var(--space-3);
        font-size: var(--text-xs);
        font-weight: 600;
        text-align: start;
        color: var(--text);
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        cursor: pointer;
      }
      .settings-action-btn:hover { background: var(--surface-3, var(--surface-2)); }
      .settings-action-btn[hidden] { display: none; }

      .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); }
      }

      /* rewrite / classification info panel on user messages */
      .rewrite-info-panel {
        margin-top: var(--space-2);
        padding: var(--space-2) var(--space-3);
        background: var(--surface-soft);
        border: 1px solid var(--border);
        border-radius: 8px;
        display: grid;
        gap: var(--space-1);
      }
      .rewrite-info-row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: baseline; }
      .rewrite-info-label { font-size: var(--text-xs); font-weight: 800; color: var(--faint); white-space: nowrap; }
      .rewrite-info-value { font-size: var(--text-xs); color: var(--muted); direction: rtl; }

      .login-screen {
        display: grid;
        place-items: center;
        align-content: start;
        padding: calc(var(--space-6) + env(safe-area-inset-top, 0px)) var(--space-6) var(--space-6);
        height: 100dvh;
        min-height: unset;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
      }

      .login-card {
        width: min(100%, 430px);
        border: 1px solid var(--border);
        border-radius: 24px;
        background: rgba(42, 42, 42, 0.82);
        box-shadow: var(--shadow-raised);
        padding: clamp(var(--space-6), 5vw, var(--space-10));
        -webkit-backdrop-filter: blur(18px);
        backdrop-filter: blur(18px);
      }

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

      @media (min-width: 1024px) {
        .login-screen {
          display: grid;
          grid-template-columns: 1fr 1fr;
          align-items: start;
          justify-items: center;
          gap: var(--space-8);
          padding: var(--space-8) var(--space-6);
          min-height: 100dvh;
          background: linear-gradient(90deg,
            var(--surface) 0%,
            var(--surface-dynamic) 50%,
            var(--bg) 100%);
        }

        .login-card {
          width: min(100%, 480px);
          margin: 0;
          grid-column: 2;
          grid-row: 1;
          position: relative;
          z-index: 2;
        }

        #aboutPanel {
          display: flex !important;
          flex-direction: column;
          grid-column: 1;
          grid-row: 1;
          width: min(100%, 480px);
          max-height: calc(100dvh - 4rem);
          overflow-y: auto;
          margin: 0;
        }

        #aboutPanel .login-tabs {
          display: none;
        }

        #aboutPanel .about-content {
          max-height: none;
          overflow-y: visible;
        }

        #showAboutTabFromLogin,
        #showAboutTabFromRegister {
          display: none;
        }
      }

      @media (min-width: 1024px) and (max-width: 1280px) {
        .login-card,
        #aboutPanel {
          width: min(100%, 420px);
        }
      }

      @media (min-width: 1280px) {
        .login-card,
        #aboutPanel {
          width: min(100%, 520px);
        }
      }

      .login-mark {
        width: 76px;
        height: 76px;
        margin: 0 auto var(--space-5);
        border: 1px solid var(--border-strong);
        border-radius: 24px;
        overflow: hidden;
        background: var(--surface-raised);
        box-shadow: var(--shadow-soft);
      }

      @media (min-width: 1024px) {
        .login-card .login-mark {
          width: 88px;
          height: 88px;
          border-radius: 28px;
          box-shadow: var(--shadow-raised);
        }
      }

      .login-mark img,
      .brand-mark img,
      .welcome-logo img,
      .avatar-logo img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      .image-failed {
        display: grid;
        place-items: center;
      }

      .fallback-mark {
        display: inline-grid;
        width: 100%;
        height: 100%;
        place-items: center;
        background: rgba(214, 177, 93, 0.1);
        color: #f1d693;
        font-size: var(--text-sm);
        font-weight: 800;
      }

      .login-card h1,
      .login-card .login-card-title {
        color: var(--text);
        font-size: var(--text-xl);
        font-weight: 800;
        letter-spacing: -0.02em;
        line-height: 1.25;
        text-align: center;
      }

      .login-subtitle {
        margin-top: var(--space-2);
        color: var(--muted);
        font-size: var(--text-sm);
        text-align: center;
      }

      .login-form {
        display: grid;
        gap: var(--space-4);
        margin-top: var(--space-8);
      }

      .login-tabs {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-2);
        margin-top: var(--space-6);
      }

      .login-tab {
        flex: 1 1 auto;
        min-width: 4.5rem;
        min-height: 38px;
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        background: var(--surface-soft);
        color: var(--muted);
        font-weight: 800;
        font-size: var(--text-xs);
        padding-inline: var(--space-2);
      }

      .login-tab.active {
        background: var(--surface-raised);
        color: var(--text);
        border-color: var(--border-strong);
      }

      .about-content {
        display: grid;
        gap: var(--space-3);
        margin-top: var(--space-5);
        max-height: calc(100dvh - 340px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: max(var(--space-4), env(safe-area-inset-bottom, 20px));
      }

      .about-section {
        border: 1px solid var(--border);
        border-radius: 16px;
        padding: var(--space-4);
        background: var(--surface-soft);
      }

      .about-heading {
        font-size: var(--text-sm);
        font-weight: 800;
        color: var(--text);
        margin-bottom: var(--space-3);
      }

      .about-body {
        color: var(--muted);
        font-size: var(--text-sm);
        line-height: 1.75;
      }

      .about-steps {
        list-style: none;
        padding: 0;
        display: grid;
        gap: var(--space-2);
        margin-top: var(--space-3);
      }

      .about-steps li {
        display: flex;
        align-items: flex-start;
        gap: var(--space-2);
        color: var(--muted);
        font-size: var(--text-sm);
      }

      .step-num {
        min-width: 22px;
        height: 22px;
        border-radius: 50%;
        background: rgba(214,177,93,.15);
        color: #d6b15d;
        font-size: 11px;
        font-weight: 800;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        margin-top: 1px;
      }

      .about-examples {
        list-style: none;
        padding: 0;
        display: grid;
        gap: var(--space-2);
        margin-top: var(--space-2);
      }

      .about-examples li {
        font-size: var(--text-sm);
        color: var(--muted);
        background: var(--surface-raised);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: var(--space-2) var(--space-3);
        line-height: 1.6;
      }

      .about-tags {
        list-style: none;
        padding: 0;
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
        margin-top: var(--space-2);
      }

      .about-tags li {
        font-size: 12px;
        color: var(--muted);
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        padding: 2px var(--space-3);
        background: var(--surface-raised);
      }

      .about-models {
        list-style: none;
        padding: 0;
        display: grid;
        gap: var(--space-3);
        margin-top: var(--space-2);
      }

      .about-models li {
        padding-bottom: var(--space-3);
        border-bottom: 1px solid var(--border);
      }

      .about-models li:last-child {
        border-bottom: none;
        padding-bottom: 0;
      }

      .model-label {
        font-size: var(--text-sm);
        font-weight: 800;
        color: var(--text);
      }

      .model-desc {
        font-size: var(--text-sm);
        color: var(--muted);
        margin-top: 2px;
        line-height: 1.6;
      }

      .about-premium {
        border-color: rgba(214,177,93,.35);
        background: rgba(214,177,93,.05);
      }

      .about-premium .about-heading {
        color: #d6b15d;
      }

      .about-premium ul {
        list-style: none;
        padding: 0;
        display: grid;
        gap: var(--space-2);
        margin-top: var(--space-2);
      }

      .about-premium ul li {
        font-size: var(--text-sm);
        color: var(--muted);
        display: flex;
        gap: var(--space-2);
        align-items: flex-start;
      }

      .about-premium ul li::before {
        content: "✦";
        color: #d6b15d;
        flex-shrink: 0;
        font-size: 10px;
        margin-top: 3px;
      }

      .about-cta {
        text-align: center;
        border-color: rgba(214,177,93,.25);
        background: rgba(214,177,93,.07);
      }

      .about-cta .about-heading { color: var(--text); }

      .about-cta p {
        font-size: var(--text-sm);
        color: var(--muted);
        margin-bottom: var(--space-4);
        line-height: 1.7;
      }

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

      html[data-theme="light"] .about-examples li,
      html[data-theme="light"] .about-tags li {
        background: #fff;
      }

      html[data-theme="light"] .about-premium {
        background: rgba(214,177,93,.08);
      }

      html[data-theme="light"] .about-cta {
        background: rgba(214,177,93,.1);
      }

      .register-form {
        display: grid;
        gap: var(--space-4);
        margin-top: var(--space-6);
        max-height: calc(100dvh - 380px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: max(var(--space-4), env(safe-area-inset-bottom, 20px));
      }

      .model-select-wrap {
        display: grid;
        gap: var(--space-1);
        align-self: center;
        min-width: 150px;
      }

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

      .model-select {
        min-height: 42px;
        border: 1px solid var(--border);
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.035);
        color: var(--text);
        padding: 0 var(--space-3);
        font: inherit;
        font-size: var(--text-sm);
        font-weight: 800;
      }

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

      .field {
        display: grid;
        gap: var(--space-2);
      }

      .field label {
        color: var(--text);
        font-size: var(--text-sm);
        font-weight: 700;
      }

      .field-hint {
        font-size: var(--text-xs);
        color: var(--faint);
        margin: 0;
        line-height: 1.5;
      }
      .field-warn {
        color: var(--error);
        font-size: var(--text-xs);
        margin: 0;
        line-height: 1.5;
      }

      .text-input,
      .composer-textarea {
        width: 100%;
        border: 1px solid var(--border);
        background: rgba(255, 255, 255, 0.035);
        color: var(--text);
      }

      html[data-theme="light"] .text-input,
      html[data-theme="light"] .composer-textarea {
        background: rgba(0, 0, 0, 0.025);
      }

      .text-input {
        min-height: 52px;
        border-radius: 16px;
        padding: 0 var(--space-4);
      }

      .text-input::placeholder,
      .composer-textarea::placeholder {
        color: var(--faint);
      }

      .text-input:hover,
      .composer-textarea:hover {
        border-color: var(--border-strong);
      }

      .text-input:focus,
      .composer-textarea:focus {
        border-color: rgba(214, 177, 93, 0.9);
        box-shadow: 0 0 0 4px rgba(214, 177, 93, 0.35);
        outline: 0;
      }

      .primary-button {
        border-radius: var(--radius-pill);
        background: var(--gold);
        color: #171717;
        font-weight: 800;
        padding: 0 var(--space-6);
      }

      .primary-button:hover:not(:disabled) {
        background: #e1bd6a;
        box-shadow: 0 8px 24px rgba(214, 177, 93, 0.18);
      }

      .primary-button:active:not(:disabled) {
        transform: translateY(1px);
        background: var(--gold-dark);
      }

      .secondary-button {
        border: 1px solid var(--border);
        border-radius: var(--radius-pill);
        background: rgba(255, 255, 255, 0.04);
        color: var(--text);
        font-weight: 700;
        padding: 0 var(--space-5);
        min-height: 44px;
        cursor: pointer;
        transition: background 0.15s, border-color 0.15s, opacity 0.15s;
      }

      .secondary-button:hover:not(:disabled) {
        border-color: var(--border-strong);
        background: rgba(255, 255, 255, 0.07);
      }

      .secondary-button:disabled {
        opacity: 0.45;
        cursor: not-allowed;
      }

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

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

      /* Inline OTP-sent confirmation under the code field. */
      .otp-status {
        margin-top: var(--space-2);
        font-size: var(--text-sm);
        color: var(--text-secondary);
      }
      .otp-status.ok {
        color: var(--success, #16a085);
        font-weight: 600;
      }

      /* 10-second deprecation splash shown after a password-only login. */
      .deprecation-splash .splash-modal {
        border-color: #d97706;        /* amber-600 */
        box-shadow: 0 12px 40px rgba(217, 119, 6, 0.25);
      }
      .deprecation-splash .splash-title {
        color: #d97706;
      }
      .deprecation-splash .splash-body p {
        margin: 0 0 var(--space-2);
        line-height: 1.7;
      }
      .deprecation-splash #deprecationCountdown {
        display: inline-block;
        min-width: 2ch;
        text-align: center;
        font-variant-numeric: tabular-nums;
        color: #d97706;
      }

      .ghost-button {
        border-radius: var(--radius-pill);
        background: transparent;
        color: var(--muted);
        font-weight: 700;
        padding: 0 var(--space-4);
      }

      .ghost-button:hover {
        background: rgba(255, 255, 255, 0.06);
        color: var(--text);
      }

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

      .error-area {
        min-height: 1.55em;
        color: var(--error);
        font-size: var(--text-sm);
        font-weight: 700;
        text-align: center;
      }


      @media (max-width: 767px) {
        :root {
          --topbar-height: 60px;
          --composer-height: 148px;
        }

        html,
        body {
          width: 100%;
          max-width: 100%;
          height: 100%;
          overflow: hidden;
        }

        .app-shell,
        .screen,
        .main-screen,
        .main-shell,
        .workspace,
        .content,
        .chat-view {
          width: 100%;
          max-width: 100%;
          min-width: 0;
        }

        .main-shell {
          display: block;
        }

        .sidebar {
          position: fixed;
          top: 0;
          right: 0;
          bottom: 0;
          width: min(86vw, var(--sidebar-width));
          transform: translateX(105%);
          transition: transform var(--transition);
        }

        body.sidebar-open .sidebar {
          transform: translateX(0);
        }

        body.sidebar-open .sidebar-backdrop {
          display: block;
        }

        .sidebar-dismiss-btn {
          position: fixed;
          z-index: 31;
          top: calc(var(--space-5) + 24px);
          right: calc(min(86vw, var(--sidebar-width)) + var(--space-2));
          transform: translateY(-50%);
          width: 34px;
          height: 34px;
          border-radius: 50%;
          border: 1px solid var(--border);
          background: var(--surface-raised, var(--surface));
          color: var(--text);
          font-size: 1rem;
          line-height: 1;
          cursor: pointer;
          box-shadow: 0 2px 8px rgba(0,0,0,0.25);
        }

        body.sidebar-open .sidebar-dismiss-btn {
          display: grid;
          place-items: center;
        }

        .mobile-menu-button {
          display: grid;
          place-items: center;
        }

        .welcome-view {
          padding: var(--space-6) var(--space-4);
        }

        .welcome-logo {
          width: 88px;
          height: 88px;
          border-radius: 26px;
        }

        .suggestions {
          justify-content: flex-start;
        }

        .suggestion-chip {
          width: 100%;
          white-space: normal;
        }

        .messages {
          flex: 1 1 auto;
          height: auto;
          min-height: 0;
          overflow-y: auto;
          padding: var(--space-5) var(--space-3) var(--space-5);
          padding-bottom: var(--space-5);
        }

        .message,
        .message.user {
          grid-template-columns: 42px minmax(0, 1fr);
          gap: var(--space-3);
        }

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

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

        .avatar {
          width: 42px;
          height: 42px;
          border-radius: 14px;
        }

        .bubble {
          max-width: 100%;
          overflow: hidden;
          padding: var(--space-4);
        }

        .composer-fixed {
          position: relative;
          right: auto;
          bottom: auto;
          left: auto;
          flex: 0 0 auto;
          width: 100%;
          max-width: 100%;
          padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom));
          background: rgba(7, 21, 38, 0.96);
          border-top: 1px solid var(--border);
          pointer-events: auto;
        }

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

        .composer {
          grid-template-columns: minmax(0, 1fr) auto;
          width: 100%;
          max-width: 100%;
          border-radius: 22px;
          box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
        }

        .composer-textarea {
          max-height: 132px;
        }

        .send-button {
          width: auto;
          min-width: 82px;
        }

        .source-meta-row {
          grid-template-columns: 1fr;
          gap: 0;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
          animation-duration: 0.01ms !important;
          animation-iteration-count: 1 !important;
          scroll-behavior: auto !important;
          transition-duration: 0.01ms !important;
        }
      }

      /* ── Sidebar actions ── */
      .sidebar-actions {
        border: 1px solid var(--border);
        border-radius: var(--radius-card);
        padding: var(--space-2);
        gap: var(--space-2);
      }
      .sidebar-actions .ghost-button {
        padding-inline: var(--space-3);
        min-height: 36px;
        font-size: var(--text-xs);
      }
      @media (min-width: 768px) {
        .sidebar-actions.is-admin {
          display: grid;
          grid-template-columns: 1fr 1fr;
        }
      }
      .sidebar-logout {
        width: 100%;
        color: #e07a7a;
        border-color: rgba(224, 122, 122, 0.25);
        background: rgba(224, 122, 122, 0.07);
        font-size: var(--text-xs);
        min-height: 36px;
        border-radius: var(--radius-pill);
        border-width: 1px;
        border-style: solid;
        cursor: pointer;
        font-weight: 800;
        transition: background var(--transition), border-color var(--transition);
      }
      .sidebar-logout:hover {
        background: rgba(224, 122, 122, 0.16);
        border-color: rgba(224, 122, 122, 0.45);
      }
      @media (max-height: 580px) {
        .sidebar-logout {
          position: sticky;
          bottom: 0;
          background: var(--surface);
        }
      }

      /* ── Splash screen ── */
      .splash-overlay {
        position: fixed;
        inset: 0;
        z-index: 200;
        background: rgba(0, 0, 0, 0.65);
        display: grid;
        place-items: center;
        padding: var(--space-4);
        -webkit-backdrop-filter: blur(4px);
        backdrop-filter: blur(4px);
      }
      .splash-overlay[hidden] { display: none; }
      .splash-modal {
        background: var(--surface);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-card);
        width: min(100%, 460px);
        max-height: min(80dvh, 580px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        box-shadow: var(--shadow-raised);
      }
      .splash-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--space-4) var(--space-5);
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
      }
      .splash-title {
        font-size: var(--text-lg);
        font-weight: 800;
        color: var(--text);
      }
      .splash-close {
        background: none;
        border: none;
        color: var(--muted);
        cursor: pointer;
        font-size: 1rem;
        padding: var(--space-1) var(--space-2);
        border-radius: 8px;
        line-height: 1;
        transition: color var(--transition), background var(--transition);
      }
      .splash-close:hover { color: var(--text); background: rgba(255,255,255,0.08); }
      .splash-body {
        flex: 1;
        overflow-y: auto;
        padding: var(--space-4) var(--space-5);
        display: grid;
        gap: var(--space-5);
        align-content: start;
      }
      .splash-version-block { display: grid; gap: var(--space-2); }
      .splash-version-tag {
        font-size: var(--text-xs);
        font-weight: 800;
        color: var(--teal);
        letter-spacing: 0.04em;
        padding-bottom: var(--space-1);
        border-bottom: 1px solid var(--border);
      }
      .splash-version-list {
        list-style: disc;
        padding-inline-start: 1.4em;
        display: grid;
        gap: 6px;
        color: var(--text);
        font-size: var(--text-sm);
        line-height: 1.5;
      }
      .splash-footer {
        padding: var(--space-3) var(--space-5);
        border-top: 1px solid var(--border);
        flex-shrink: 0;
        display: flex;
        justify-content: center;
      }
      .splash-footer .primary-button { min-width: 140px; }

      /* ── Onboarding spotlight tour ── */
      .onboarding-overlay {
        position: fixed;
        inset: 0;
        z-index: 299;
        background: transparent;
      }
      .onboarding-overlay[hidden] { display: none; }
      .onboarding-overlay.no-target {
        background: rgba(0, 0, 0, 0.72);
      }
      .onboarding-spotlight {
        position: fixed;
        z-index: 300;
        pointer-events: none;
        border-radius: 10px;
        outline: 2px solid var(--teal);
        outline-offset: 4px;
        box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.68);
        transition: top 0.22s ease, left 0.22s ease, width 0.22s ease, height 0.22s ease;
        animation: tourPulse 2.4s ease-in-out infinite;
      }
      .onboarding-spotlight[hidden] { display: none; }
      @keyframes tourPulse {
        0%, 100% { outline-color: var(--teal); box-shadow: 0 0 0 9999px rgba(0,0,0,0.68), 0 0 0 0 rgba(86,182,214,0.5); }
        50% { outline-color: rgba(86,182,214,0.6); box-shadow: 0 0 0 9999px rgba(0,0,0,0.68), 0 0 0 6px rgba(86,182,214,0.2); }
      }
      .onboarding-card {
        position: fixed;
        z-index: 301;
        background: var(--surface);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-card);
        width: min(90vw, 320px);
        padding: var(--space-4) var(--space-5);
        box-shadow: var(--shadow-raised), 0 8px 40px rgba(0, 0, 0, 0.5);
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
      }
      .onboarding-header {
        display: flex;
        align-items: flex-start;
        gap: var(--space-3);
      }
      .onboarding-icon {
        font-size: 2rem;
        flex-shrink: 0;
        line-height: 1.2;
      }
      .onboarding-title {
        font-size: var(--text-base);
        font-weight: 800;
        color: var(--text);
        line-height: 1.3;
        flex: 1;
        padding-top: 0.3rem;
      }
      .onboarding-desc {
        font-size: var(--text-sm);
        color: var(--muted);
        line-height: 1.65;
        margin: 0;
      }
      .onboarding-progress {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-2);
      }
      .onboarding-dots {
        display: flex;
        gap: 5px;
        flex-wrap: wrap;
        max-width: 120px;
      }
      .onboarding-dot {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: var(--border-strong);
        transition: background var(--transition), transform var(--transition);
        flex-shrink: 0;
      }
      .onboarding-dot.active {
        background: var(--teal);
        transform: scale(1.3);
      }
      .onboarding-actions {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        flex-shrink: 0;
      }
      .onboarding-actions .primary-button {
        min-width: 80px;
        font-size: var(--text-sm);
        padding: var(--space-1) var(--space-3);
      }
      .onboarding-skip {
        font-size: var(--text-sm);
        color: var(--muted);
        padding: var(--space-1) var(--space-2);
      }
      @media (max-width: 400px) {
        .onboarding-card {
          width: calc(100vw - 20px);
          padding: var(--space-3) var(--space-4);
        }
      }

      /* ── FAQ sidebar icon button ── */
      .faq-icon-button {
        margin-inline-start: auto;
        flex-shrink: 0;
        width: clamp(28px, 7vw, 32px);
        height: clamp(28px, 7vw, 32px);
        min-height: unset;
        border: 1px solid var(--border-strong);
        border-radius: 50%;
        background: var(--surface-raised);
        color: var(--text);
        font-size: clamp(0.75rem, 2vw, var(--text-sm));
        font-weight: 800;
        display: grid;
        place-items: center;
        cursor: pointer;
        transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
      }
      .faq-icon-button:hover {
        background: var(--surface-dynamic);
        color: var(--gold);
        border-color: var(--gold-dark);
        box-shadow: 0 0 8px rgba(86, 182, 214, 0.2);
      }

      /* ── FAQ modal ── */
      .faq-modal {
        background: var(--surface);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-card);
        width: min(100%, 580px);
        max-height: min(88dvh, 640px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        box-shadow: var(--shadow-raised);
        outline: none;
      }
      .faq-categories {
        display: flex;
        gap: var(--space-3);
        padding: var(--space-4) var(--space-5);
        border-bottom: 1px solid var(--border-strong);
        overflow-x: auto;
        flex-shrink: 0;
        scrollbar-width: none;
        background: var(--surface);
      }
      .faq-categories::-webkit-scrollbar { display: none; }
      .faq-cat-tab {
        flex-shrink: 0;
        min-height: 36px;
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-pill);
        background: var(--surface-dynamic);
        color: var(--muted);
        font-size: var(--text-xs);
        font-weight: 800;
        padding: var(--space-2) var(--space-5);
        cursor: pointer;
        transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
        white-space: nowrap;
      }
      .faq-cat-tab:hover {
        background: var(--surface-raised);
        color: var(--text);
        border-color: var(--teal);
      }
      .faq-cat-tab.active {
        background: var(--teal);
        border-color: var(--teal);
        color: #fff;
        box-shadow: 0 0 12px rgba(86, 182, 214, 0.3);
      }
      .faq-cat-tab--tour {
        border-color: #c9993c;
        color: #c9993c;
      }
      .faq-cat-tab--tour:hover {
        background: rgba(201, 153, 60, 0.1);
        border-color: #c9993c;
        color: #c9993c;
        box-shadow: 0 0 10px rgba(201, 153, 60, 0.25);
      }
      .faq-body {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: var(--space-4) var(--space-5);
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
        padding-bottom: var(--space-6);
      }
      .faq-item {
        border: 1px solid var(--border);
        border-radius: 12px;
        overflow: visible;
        background: var(--surface-raised);
        flex-shrink: 0;
      }
      .faq-question {
        width: 100%;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-4);
        background: transparent;
        color: var(--text);
        font-size: var(--text-sm);
        font-weight: 700;
        text-align: right;
        cursor: pointer;
        border: none;
        border-radius: 12px;
        transition: background var(--transition);
      }
      .faq-question[aria-expanded="true"] { border-radius: 12px 12px 0 0; }
      .faq-question:hover { background: rgba(255,255,255,0.05); }
      .faq-chevron {
        color: var(--faint);
        font-size: 1.1rem;
        line-height: 1;
        transition: transform var(--transition);
        flex-shrink: 0;
      }
      .faq-answer {
        padding: var(--space-4);
        color: var(--text);
        font-size: var(--text-sm);
        line-height: 1.85;
        border-top: 1px solid var(--border);
        direction: rtl;
      }

      /* ── Mobile topbar overrides ── */
      @media (max-width: 767px) {
        .topbar {
          display: grid;
          grid-template-columns: auto 1fr auto;
          align-items: center;
          gap: var(--space-2);
          padding-inline: var(--space-3);
          min-height: var(--topbar-height);
          justify-content: unset;
        }
        .mobile-menu-button { grid-column: 1; }
        .mode-pill { grid-column: 2; justify-self: center; }
        .topbar-title {
          display: block;
          grid-column: 2;
          text-align: center;
          font-size: 11px;
          line-height: 1.35;
          color: var(--muted);
          font-weight: 700;
          padding: 0 var(--space-1);
        }
        .topbar-actions {
          order: unset;
          grid-column: 3;
          gap: var(--space-1);
        }
        #serverStatus { display: none; }
        .theme-toggle,
        .changelog-toggle {
          width: 30px;
          min-height: 30px;
          border-radius: 10px;
          font-size: 13px;
        }
      }

/* qa.css — QA FlashCard styles for Albayyan (v0.0.9)
   All values reference tokens.css variables. No overrides to existing rules.
*/

/* ── Screen layout ────────────────────────────────────────────────────── */
#qaScreen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    overflow: hidden;
    z-index: 10;
}

/* ── Shell + workspace (sidebar + content two-column) ─────────────────── */
.qa-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.qa-workspace {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

/* ── Topbar ───────────────────────────────────────────────────────────── */
/* Uses default .topbar styling from layout.css - no overrides needed */

#qaScreen .topbar h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    flex: 1;
    text-align: center;
}

#qaScreen .mode-pill {
    display: flex;
    gap: 6px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 4px;
    flex: 0 0 auto;
}

#qaScreen .mode-pill-btn {
    padding: 6px 12px;
    font-size: var(--text-sm);
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: calc(var(--radius-pill) - 2px);
    cursor: pointer;
    transition: color var(--transition), background-color var(--transition);
}

#qaScreen .mode-pill-btn:hover {
    color: var(--text);
}

#qaScreen .mode-pill-btn.active {
    background: var(--surface-dynamic);
    color: var(--text);
    font-weight: 500;
}

#qaScreen .topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

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

#qaScreen .mobile-menu-button:hover {
    background: rgba(255, 255, 255, 0.08);
}

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

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

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

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

#qaScreen .mobile-menu-lines::after {
    bottom: -6px;
}

/* ── QA Sidebar mobile behaviour ─────────────────────────────────────────── */
@media (max-width: 767px) {
    #qaMobileMenuButton {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .qa-shell {
        display: block;
        position: relative;
    }

    #qaSidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(86vw, var(--sidebar-width));
        transform: translateX(105%);
        transition: transform var(--transition);
        z-index: 50;
    }

    #qaScreen.qa-sidebar-open #qaSidebar {
        transform: translateX(0);
    }

    #qaSidebarBackdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 25;
        cursor: pointer;
        pointer-events: auto;
    }

    #qaScreen.qa-sidebar-open #qaSidebarBackdrop {
        display: block;
    }

    #qaSidebarDismissBtn {
        position: fixed;
        z-index: 51;
        top: calc(var(--space-5) + 24px);
        right: calc(min(86vw, var(--sidebar-width)) + var(--space-2));
        transform: translateY(-50%);
        width: 34px;
        height: 34px;
        border-radius: 50%;
        border: 1px solid var(--border);
        background: var(--surface-raised, var(--surface));
        color: var(--text);
        font-size: 1rem;
        line-height: 1;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    }

    #qaScreen.qa-sidebar-open #qaSidebarDismissBtn {
        display: grid;
        place-items: center;
    }

    .qa-workspace {
        height: 100dvh;
    }
}

/* ── Scrollable body ──────────────────────────────────────────────────── */
.qa-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* ── Setup view ───────────────────────────────────────────────────────── */
.qa-dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

@media (max-width: 600px) {
    .qa-dashboard-grid {
        grid-template-columns: 1fr;
    }
}

.qa-dashboard-stat-main {
    background: var(--surface-2);
    padding: var(--space-4);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.qa-dashboard-stat-main .stat-label {
    font-size: var(--text-sm);
    color: var(--muted);
}

.qa-dashboard-stat-main .stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
    margin: var(--space-2) 0;
}

.qa-dashboard-forecast {
    background: var(--surface-2);
    padding: var(--space-4);
    border-radius: var(--radius);
}

.forecast-chart {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    height: 120px;
    padding-top: var(--space-4);
}

.forecast-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    height: 100%;
}

.forecast-bar {
    width: 100%;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
    opacity: 0.8;
}

.forecast-bar-wrap:first-child .forecast-bar {
    background: var(--warning);
    opacity: 1;
}

.forecast-label {
    font-size: 10px;
    color: var(--faint);
    white-space: nowrap;
}

.dash-subject-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.dash-subject-item {
    background: var(--surface-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.dash-subject-name {
    font-weight: 600;
    font-size: var(--text-sm);
    flex: 1;
}

.dash-subject-counts {
    display: flex;
    gap: var(--space-3);
    font-size: var(--text-xs);
}

.dash-count-pill {
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--surface-3);
}

.dash-count-pill.due {
    color: var(--warning);
    background: rgba(255, 193, 7, 0.1);
}

.dash-count-pill.new {
    color: var(--primary);
    background: rgba(var(--primary-rgb), 0.1);
}

.dash-retention-pill {
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-weight: 600;
}
.dash-retention-pill.good { color: #16a34a; background: rgba(34, 197, 94, 0.15); }
.dash-retention-pill.mid  { color: #b45309; background: rgba(234, 179, 8, 0.15); }
.dash-retention-pill.low  { color: #dc2626; background: rgba(239, 68, 68, 0.15); }

#qaDashboardView .ghost-button {
    padding: 4px 12px;
    height: auto;
    min-height: unset;
}
    width: 100%;
    max-width: 560px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow-soft);
}

.qa-setup-card label {
    font-size: 0.88rem;
    color: var(--muted);
    margin-bottom: 4px;
    display: block;
}

.qa-setup-card select {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    transition: border var(--transition);
}

.qa-setup-card select:focus {
    border-color: var(--teal);
}

/* ── Progress bar ─────────────────────────────────────────────────────── */
.qa-progress-wrap {
    width: 100%;
    max-width: 680px;
    height: 6px;
    background: var(--surface-raised);
    border-radius: var(--radius-pill);
    overflow: hidden;
    flex-shrink: 0;
}

.qa-progress-fill {
    height: 100%;
    background: var(--teal);
    border-radius: var(--radius-pill);
    transition: width 400ms ease;
}

.qa-progress-label {
    font-size: 0.82rem;
    color: var(--faint);
    text-align: center;
    width: 100%;
}

/* ── Card view ────────────────────────────────────────────────────────── */
.qa-card {
    width: 100%;
    max-width: 680px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 32px 28px;
    box-shadow: var(--shadow-raised);
    display: flex;
    flex-direction: column;
    gap: 18px;
    transition: var(--transition);
}

.qa-card-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.qa-badge {
    font-size: 0.78rem;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    background: var(--surface-raised);
    color: var(--muted);
    border: 1px solid var(--border);
}

.qa-question-text {
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.7;
    color: var(--text);
    text-align: center;
}

/* ── Answer section ───────────────────────────────────────────────────── */
.qa-answer-divider {
    height: 1px;
    background: var(--border);
    width: 100%;
}

.qa-answer-label {
    font-size: 0.82rem;
    color: var(--faint);
    text-align: center;
}

.qa-answer-text {
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
    background: var(--surface-raised);
    border-radius: 12px;
    padding: 16px 18px;
    border: 1px solid var(--border-strong);
    white-space: pre-wrap;
}

/* ── Typing mode ──────────────────────────────────────────────────────── */
.qa-typing-area {
    width: 100%;
    padding: 12px 14px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    resize: vertical;
    min-height: 80px;
    outline: none;
    transition: border var(--transition);
}

.qa-typing-area:focus {
    border-color: var(--teal);
}

/* ── Result buttons ───────────────────────────────────────────────────── */
.qa-result-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.qa-btn-correct {
    background: transparent;
    border: 2px solid var(--success);
    color: var(--success);
    border-radius: var(--radius-pill);
    padding: 10px 24px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background var(--transition), color var(--transition);
}
.qa-btn-correct:hover { background: var(--success); color: var(--bg); }

.qa-btn-hard {
    background: transparent;
    border: 2px solid var(--gold);
    color: var(--gold);
    border-radius: var(--radius-pill);
    padding: 10px 24px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background var(--transition), color var(--transition);
}
.qa-btn-hard:hover { background: var(--gold); color: var(--bg); }

.qa-btn-wrong {
    background: transparent;
    border: 2px solid var(--error);
    color: var(--error);
    border-radius: var(--radius-pill);
    padding: 10px 24px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background var(--transition), color var(--transition);
}
.qa-btn-wrong:hover { background: var(--error); color: var(--bg); }

/* ── FSRS scheduled-review rating buttons ─────────────────────────── */
.qa-review-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}
.qa-review-row button {
    background: transparent;
    border: 2px solid var(--muted);
    color: var(--muted);
    border-radius: var(--radius-pill);
    padding: 10px 20px;
    font-family: var(--font-body);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background var(--transition), color var(--transition);
}
.qa-rate-again { border-color: var(--error)   !important; color: var(--error)   !important; }
.qa-rate-hard  { border-color: var(--gold)    !important; color: var(--gold)    !important; }
.qa-rate-good  { border-color: var(--success) !important; color: var(--success) !important; }
.qa-rate-easy  { border-color: var(--accent, var(--success)) !important; color: var(--accent, var(--success)) !important; }
.qa-rate-again:hover { background: var(--error)   !important; color: var(--bg) !important; }
.qa-rate-hard:hover  { background: var(--gold)    !important; color: var(--bg) !important; }
.qa-rate-good:hover  { background: var(--success) !important; color: var(--bg) !important; }
.qa-rate-easy:hover  { background: var(--accent, var(--success)) !important; color: var(--bg) !important; }

/* ── Summary view ─────────────────────────────────────────────────────── */
.qa-summary-card {
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 32px 28px;
    box-shadow: var(--shadow-raised);
    display: flex;
    flex-direction: column;
    gap: 20px;
    text-align: center;
}

.qa-summary-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
}

.qa-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.qa-stat-box {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.qa-stat-label {
    font-size: 0.8rem;
    color: var(--faint);
}

.qa-stat-value {
    font-size: 1.1rem;
    font-weight: 700;
}

.qa-stat-box.correct .qa-stat-value { color: var(--success); }
.qa-stat-box.hard    .qa-stat-value { color: var(--gold); }
.qa-stat-box.wrong   .qa-stat-value { color: var(--error); }
.qa-stat-box.total   .qa-stat-value { color: var(--teal); }

/* ── FSRS review: accumulated-card breakdown for the chosen subject ── */
.qa-review-counts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.qa-rev-stat {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: center;
}
.qa-rev-stat-label {
    font-size: 0.8rem;
    color: var(--faint);
}
.qa-rev-stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--teal);
}

/* ── Error toast ──────────────────────────────────────────────────────── */
.qa-error-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--error);
    color: #fff;
    padding: 10px 22px;
    border-radius: var(--radius-pill);
    font-size: 0.9rem;
    box-shadow: var(--shadow-raised);
    z-index: 999;
    pointer-events: none;
}

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .qa-card        { padding: 22px 16px; }
    .qa-setup-card  { padding: 20px 16px; }
    .qa-result-row  { gap: 8px; }
    .qa-btn-correct,
    .qa-btn-hard,
    .qa-btn-wrong   { padding: 10px 16px; font-size: 0.88rem; }
    .qa-stats-grid  { grid-template-columns: 1fr 1fr; }
}

/* ── Timer display ────────────────────────────────────────────────────── */
.qa-timer-display {
    font-size: var(--text-sm);
    font-weight: 700;
    min-width: 40px;
    text-align: center;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    transition: background 0.3s, color 0.3s;
}
.qa-timer-display.qa-timer-warning {
    background: var(--error);
    color: #fff;
    border-color: var(--error);
    animation: qa-timer-pulse 0.5s ease-in-out infinite alternate;
}
@keyframes qa-timer-pulse {
    from { opacity: 1; }
    to   { opacity: 0.6; }
}

/* ── Forecast stats (مستحقة غدًا / ٧ أيام) ──────────────────────────── */
.qa-rev-stat--forecast {
    opacity: 0.65;
    font-size: 0.88em;
}

/* ── F4: Retention probability badge ─────────────────────────────────── */
.retention-badge { font-weight: 600; }
.retention-high  { background: rgba(34,197,94,.15); color: #16a34a; border-color: rgba(34,197,94,.3); }
.retention-mid   { background: rgba(234,179,8,.15);  color: #b45309; border-color: rgba(234,179,8,.3); }
.retention-low   { background: rgba(239,68,68,.15);  color: #dc2626; border-color: rgba(239,68,68,.3); }

/* ── F1: MCQ option buttons ──────────────────────────────────────────── */
.mcq-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  text-align: start;
  transition: background 0.12s, border-color 0.12s;
}
.mcq-option:hover:not(:disabled) { background: var(--surface-soft); border-color: var(--accent); }
.mcq-label {
  font-weight: 700;
  min-width: 1.2em;
  color: var(--accent);
  flex-shrink: 0;
}
.mcq-selected-correct { background: rgba(34,197,94,.15) !important; border-color: #16a34a !important; }
.mcq-selected-wrong   { background: rgba(239,68,68,.15)  !important; border-color: #dc2626 !important; }

/* summaries.css — Albayyan Summaries mode styles
 * Uses only existing CSS custom properties from tokens.css.
 * All layouts are RTL-first.
 */

/* ── Screen layout ──────────────────────────────────────────────────────────── */
#summariesScreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  direction: rtl;
}

.sum-shell {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar / TOC ──────────────────────────────────────────────────────────── */
.sum-sidebar {
  width: var(--sidebar-width);
  border-left: 1px solid var(--border);
  background: rgba(23, 23, 23, 0.94);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform 0.22s ease;
}

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

.sum-sidebar-header {
  padding: var(--space-4) var(--space-5) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ── Sidebar view tabs ──────────────────────────────────────────────────────── */
.sum-sidebar-tab-row {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sum-sidebar-tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  border: none;
  min-height: 36px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.sum-sidebar-tab:hover:not(.active) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
}

html[data-theme="light"] .sum-sidebar-tab:hover:not(.active) {
  background: rgba(0, 0, 0, 0.045);
}

.sum-sidebar-tab.active {
  background: var(--accent);
  color: #fff;
}

.sum-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: inherit;
  direction: rtl;
}
.sum-search-input:focus { outline: 2px solid var(--accent); }

.sum-tree {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--space-2) 0;
}

.sum-semester-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--faint);
  padding: var(--space-2) var(--space-3) var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.sum-semester-label:hover { color: var(--muted); }
.sum-semester-arrow { transition: transform 0.18s; font-size: 1.2em; }
.sum-semester-label.collapsed .sum-semester-arrow { transform: rotate(90deg); }

.sum-semester-subjects {
  overflow: hidden;
  transition: max-height 0.24s ease;
}
.sum-semester-subjects.collapsed { max-height: 0 !important; }

.sum-subject-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  padding: var(--space-1) var(--space-4) var(--space-1) var(--space-4);
  padding-inline-start: var(--space-6);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.sum-subject-label:hover { color: var(--text); }
.sum-subject-arrow { transition: transform 0.18s; font-size: 1.1em; }
.sum-subject-label.collapsed .sum-subject-arrow { transform: rotate(90deg); }

.sum-pages-list {
  overflow: hidden;
  transition: max-height 0.22s ease;
}
.sum-pages-list.collapsed { max-height: 0 !important; }

.sum-page-link {
  display: block;
  padding: 5px var(--space-5) 5px var(--space-6);
  padding-inline-start: var(--space-10);
  font-size: var(--text-sm);
  color: var(--muted);
  cursor: pointer;
  border-right: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sum-page-link:hover { color: var(--text); background: var(--surface-raised); }
.sum-page-link.active {
  color: var(--accent);
  border-right-color: var(--accent);
  background: var(--surface-raised);
  font-weight: 600;
}

/* ── Main content area ───────────────────────────────────────────────────────── */
.sum-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}


.sum-viewer {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--space-5) var(--space-6);
  position: relative;
}

/* ── In-page sticky TOC (feature #20) ───────────────────────────────────────── */
.sum-toc {
  position: fixed;
  bottom: var(--space-5);
  left: var(--space-4);
  max-width: 230px;
  max-height: 45vh;
  overflow-y: auto;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-3);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  z-index: 40;
  font-size: var(--text-sm);
}
.sum-toc-item {
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sum-toc-item:hover {
  background: var(--surface-2, rgba(0, 0, 0, 0.04));
}
.sum-toc-item.active {
  color: var(--accent, #2f9e7a);
  font-weight: 700;
  background: var(--surface-2, rgba(0, 0, 0, 0.04));
}
@media (max-width: 1100px) {
  .sum-toc { display: none !important; }
}
/* The fixed TOC sits bottom-left, exactly over the comment panel's send button
   (RTL pushes the submit button to the left edge). Hide it while commenting. */
main:has(#sumCommentPanel.open) .sum-toc { display: none !important; }

/* ── Progress bar ────────────────────────────────────────────────────────────── */
.sum-progress-bar {
  position: sticky;
  top: 0;
  height: 3px;
  background: var(--border);
  z-index: 10;
  flex-shrink: 0;
}
.sum-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
}

/* ── DRM overlay canvas ──────────────────────────────────────────────────────── */
#sumWatermarkCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.14;
  mix-blend-mode: multiply;
}

/* ── Rendered Markdown content ───────────────────────────────────────────────── */
.sum-content-wrapper {
  font-family: 'Noto Sans Arabic', 'Segoe UI', sans-serif;
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--text);
  direction: rtl;
  text-align: right;

  /* DRM: disable text selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  /* DRM: kill iOS Safari long-press callout (image preview, share menu) and tap flash */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* DRM: decoy DOM noise injected server-side (#9) — never visible */
.sum-decoy { display: none !important; }

.sum-content-wrapper h1,
.sum-content-wrapper .sum-h1 { font-size: 1.6rem; font-weight: 800; margin: 1.4em 0 0.5em; color: var(--accent); border-bottom: 2px solid var(--border); padding-bottom: 0.3em; }
.sum-content-wrapper h2,
.sum-content-wrapper .sum-h2 { font-size: 1.3rem; font-weight: 700; margin: 1.2em 0 0.4em; color: var(--text); }
.sum-content-wrapper h3,
.sum-content-wrapper .sum-h3 { font-size: 1.1rem; font-weight: 600; margin: 1em 0 0.3em; }
.sum-content-wrapper h4,
.sum-content-wrapper .sum-h4 { font-size: 1rem; font-weight: 600; margin: 0.9em 0 0.3em; }

.sum-content-wrapper p { margin: 0.6em 0; }
.sum-content-wrapper strong { font-weight: 700; }
.sum-content-wrapper em { font-style: italic; }
.sum-content-wrapper u { text-decoration: underline; text-underline-offset: 2px; }
.sum-content-wrapper del { text-decoration: line-through; color: var(--muted); }

.sum-content-wrapper ul,
.sum-content-wrapper ol { padding-right: 1.5em; padding-left: 0; margin: 0.5em 0; }
.sum-content-wrapper li { margin: 0.25em 0; }

.sum-content-wrapper blockquote {
  border-right: 4px solid var(--accent);
  padding-right: var(--space-4);
  margin: 0.8em 0;
  color: var(--muted);
  font-style: italic;
}

.sum-content-wrapper code {
  background: var(--surface-raised);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: monospace;
}

.sum-content-wrapper pre {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  margin: 0.8em 0;
}

.sum-content-wrapper table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: var(--text-sm);
}
.sum-content-wrapper th,
.sum-content-wrapper td {
  border: 1px solid var(--border);
  padding: 6px var(--space-3);
  text-align: right;
}
.sum-content-wrapper th {
  background: var(--surface-raised);
  font-weight: 700;
}

/* footnotes */
.sum-content-wrapper .footnotes {
  margin-top: 2em;
  border-top: 1px solid var(--border);
  padding-top: 1em;
  font-size: var(--text-sm);
  color: var(--muted);
}
.sum-content-wrapper sup a { color: var(--accent); text-decoration: none; }

/* ── Page meta (read time below title) ───────────────────────────────────────── */
.sum-page-meta {
  font-size: var(--text-sm);
  color: var(--faint);
  margin: 0.2em 0 1em;
  font-style: italic;
}

/* ── Collapsible headings ────────────────────────────────────────────────────── */
.sum-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  margin-left: 6px;
  line-height: 1;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  vertical-align: middle;
  transition: color 0.12s, transform 0.18s;
  /* Triangle via border trick */
  position: relative;
  top: -0.05em;
}
.sum-collapse-btn::after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-top: 0.32em solid transparent;
  border-bottom: 0.32em solid transparent;
  border-left: 0.5em solid currentColor;
  transform: rotate(-90deg);
  transition: transform 0.18s;
}
.sum-collapse-btn.collapsed::after {
  transform: rotate(0deg);
}
.sum-collapse-btn:hover { color: var(--accent); }

.sum-collapsible-section {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.22s ease;
}
.sum-collapsible-section.collapsed {
  grid-template-rows: 0fr;
}
.sum-collapsible-inner {
  overflow: hidden;
}

/* wikilinks */
.sum-wikilink {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* ── Empty / loading states ──────────────────────────────────────────────────── */
.sum-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-3);
  color: var(--faint);
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-6);
}

/* ── First-time hint arrow ───────────────────────────────────────────────────── */
.sum-first-hint {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: 600;
}
.sum-first-hint.hidden { display: none; }

.sum-hint-arrow {
  font-size: 1.6rem;
  line-height: 1;
  animation: sumHintBounce 0.8s ease-in-out infinite alternate;
  display: inline-block;
}
@keyframes sumHintBounce {
  from { transform: translate(0, 0); }
  to   { transform: translate(6px, -6px); }
}

.sum-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: sumSpin 0.7s linear infinite;
}
@keyframes sumSpin { to { transform: rotate(360deg); } }

/* ── Comment panel ───────────────────────────────────────────────────────────── */
.sum-comment-panel {
  border-top: 1px solid var(--border);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  flex-shrink: 0;
  display: none;
}
.sum-comment-panel.open { display: block; }

.sum-comment-title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.sum-comment-list {
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: var(--space-2);
}

.sum-comment-item {
  padding: var(--space-2) var(--space-3);
  border-radius: 12px;
  background: var(--surface-raised);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}
.sum-comment-meta {
  font-size: var(--text-xs);
  color: var(--faint);
  margin-top: 2px;
}

.sum-comment-form {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}
.sum-comment-textarea {
  flex: 1;
  min-height: 56px;
  resize: vertical;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: inherit;
  direction: rtl;
}
.sum-comment-textarea:focus { outline: 2px solid var(--accent); }

/* ── Search results panel (sits between search row and tree, slides tree down) ── */
.sum-search-results {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
  border-bottom: 1px solid var(--border);
}
.sum-search-results.open {
  max-height: 420px;
  overflow-y: auto;
}
.sum-search-result-item {
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.sum-search-result-item:last-child { border-bottom: none; }
.sum-search-result-item:hover { background: var(--surface-raised); }
.sum-search-result-title { font-size: var(--text-sm); font-weight: 600; }
.sum-search-result-sub {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: 2px;
}

/* ── Bookmarks badge ─────────────────────────────────────────────────────────── */
/* ── Bookmarks toggle button active state ────────────────────────────────────── */
#sumTabBookmarks.active {
  background: rgba(245, 158, 11, 0.10);
  border-color: rgba(245, 158, 11, 0.35) !important;
  color: #f59e0b !important;
}

/* ── Page footer bookmark button ─────────────────────────────────────────────── */
.sum-page-bm-btn {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  min-height: 32px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.sum-page-bm-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-raised);
}
.sum-page-bm-btn.bookmarked {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
}

/* ── Mobile sidebar toggle ───────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .sum-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    height: 100dvh;
    z-index: 200;
    transform: translateX(100%);
    box-shadow: -4px 0 20px rgba(0,0,0,0.2);
  }
  #summariesScreen.sum-sidebar-open .sum-sidebar {
    transform: translateX(0);
  }
  .sum-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 199;
  }
  #summariesScreen.sum-sidebar-open .sum-sidebar-backdrop { display: block; }

  #sumSidebarDismissBtn {
    position: fixed;
    z-index: 201;
    top: calc(var(--space-5) + 24px);
    right: calc(var(--sidebar-width) + var(--space-2));
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-raised, var(--surface));
    color: var(--text);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  }

  #summariesScreen.sum-sidebar-open #sumSidebarDismissBtn {
    display: grid;
    place-items: center;
  }
}

/* ── DRM: print kill ─────────────────────────────────────────────────────────── */
@media print {
  #summariesScreen,
  .sum-content-wrapper,
  body { display: none !important; }
}

/* ── Admin summaries panel ───────────────────────────────────────────────────── */
.sum-admin-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
}
@media (max-width: 900px) {
  .sum-admin-editor-grid { grid-template-columns: 1fr; }
}

.sum-admin-md-editor {
  width: 100%;
  box-sizing: border-box;
  min-height: 420px;
  resize: vertical;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: 'Noto Sans Arabic', monospace;
  direction: rtl;
  line-height: 1.7;
}
.sum-admin-md-editor:focus { outline: 2px solid var(--accent); }

.sum-admin-preview {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  min-height: 420px;
  overflow-y: auto;
  font-size: var(--text-sm);
  direction: rtl;
}

.sum-version-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-xs);
}
.sum-version-item:last-child { border-bottom: none; }

/* ── Floating action button (FAB) ────────────────────────────────────────────── */
.sum-fab {
  position: absolute;
  bottom: 1.5rem;
  left: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  border: none;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, box-shadow 0.15s;
}
.sum-fab:hover  { transform: scale(1.07); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }
.sum-fab:active { transform: scale(0.97); }
.sum-fab.hidden { display: none; }

/* ── PDF Attachments ───────────────────────────────────────────────────────── */
.sum-page-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
  margin-bottom: var(--space-4);
}

.sum-attachment-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-base);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sum-attachment-link:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}

.sum-attachment-link .icon {
  font-size: 1.1em;
  color: var(--accent);
}

/* admin.css — Admin Panel styles for Albayyan (v0.0.10) */
/* ── Admin Panel ────────────────────────────────────── */
.admin-screen{position:fixed;inset:0;z-index:300;background:var(--bg);display:flex;flex-direction:column;overflow:hidden;height:100dvh;max-height:100dvh}
.admin-topbar{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,.82);-webkit-backdrop-filter:blur(18px);backdrop-filter:blur(18px);flex-shrink:0}
.admin-topbar h1{font-size:var(--text-lg);font-weight:800}
.admin-body{flex:1 1 auto;min-height:0;height:100%;overflow-y:auto!important;overflow-x:hidden;-webkit-overflow-scrolling:touch;overscroll-behavior:contain;padding:var(--space-6) clamp(var(--space-4),4vw,var(--space-8));display:grid;gap:var(--space-6);align-content:start}
.admin-section{border:1px solid var(--border);border-radius:18px;background:var(--surface);overflow:hidden;align-self:start}
#adminUsersList,#adminStatsList,#messageLogsList{max-height:55vh;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
#generalStatsSection{overflow-x:auto}
#createUserSection .create-form{max-height:60vh;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
.admin-section-header{display:flex;align-items:center;justify-content:space-between;padding:var(--space-4) var(--space-5);border-bottom:1px solid var(--border)}
.admin-section-header h2{font-size:var(--text-xs);font-weight:800;color:var(--faint);text-transform:uppercase;letter-spacing:.06em}
.admin-user-filters{display:flex;gap:var(--space-3);padding:var(--space-3) var(--space-5);border-bottom:1px solid var(--border);background:var(--surface-alt,var(--surface))}
.user-item{display:grid;grid-template-columns:1fr auto;gap:var(--space-3);align-items:start;padding:var(--space-4) var(--space-5);border-bottom:1px solid var(--border)}
.user-item:last-child{border-bottom:0}
.user-item-info{display:grid;gap:var(--space-2)}
.user-item-name{font-size:var(--text-sm);font-weight:800}
.user-item-meta{display:flex;flex-wrap:wrap;gap:var(--space-2);align-items:center}
.user-item-actions{display:flex;flex-direction:column;gap:var(--space-2);align-items:flex-end}
.badge-admin{border:1px solid rgba(214,177,93,.28);background:rgba(214,177,93,.12);color:#f1d693;padding:0 var(--space-2);min-height:24px;display:inline-flex;align-items:center;border-radius:var(--radius-pill);font-size:var(--text-xs);font-weight:800}
.badge-researcher{border:1px solid rgba(46,139,123,.36);background:rgba(46,139,123,.15);color:#9ee3d8;padding:0 var(--space-2);min-height:24px;display:inline-flex;align-items:center;border-radius:var(--radius-pill);font-size:var(--text-xs);font-weight:800}
.badge-user{border:1px solid var(--border);background:rgba(255,255,255,.04);color:var(--muted);padding:0 var(--space-2);min-height:24px;display:inline-flex;align-items:center;border-radius:var(--radius-pill);font-size:var(--text-xs);font-weight:800}
html[data-theme="light"] .badge-user{background:rgba(0,0,0,.05)}
.badge-inactive{border:1px solid rgba(224,122,122,.28);background:rgba(224,122,122,.1);color:#e07a7a;padding:0 var(--space-2);min-height:24px;display:inline-flex;align-items:center;border-radius:var(--radius-pill);font-size:var(--text-xs);font-weight:800}
.danger-button{border-radius:var(--radius-pill);background:rgba(224,122,122,.12);color:#e07a7a;border:1px solid rgba(224,122,122,.25);font-weight:800;padding:0 var(--space-3);min-height:32px;font-size:var(--text-xs)}
.danger-button:hover:not(:disabled){background:rgba(224,122,122,.22)}
.admin-tabs{display:flex;gap:var(--space-2);flex-wrap:wrap}
.admin-tab{border:1px solid var(--border);border-radius:var(--radius-pill);background:var(--surface-soft);color:var(--muted);font-weight:800;min-height:36px;padding:0 var(--space-4)}
.admin-tab.active{background:var(--surface-raised);color:var(--text);border-color:var(--border-strong)}
.admin-burger{display:none;font-size:1.2rem;min-width:36px;min-height:36px;align-items:center;justify-content:center}
.admin-tab-menu{display:none;flex-direction:column;background:var(--bg);border-bottom:1px solid var(--border);z-index:2;flex-shrink:0}
.admin-tab-menu-item{text-align:start;padding:var(--space-3) var(--space-5);font-size:var(--text-sm);font-weight:800;color:var(--muted);background:none;border:none;border-bottom:1px solid var(--border);cursor:pointer;transition:background var(--transition),color var(--transition)}
.admin-tab-menu-item:last-child{border-bottom:0}
.admin-tab-menu-item:hover{background:var(--surface-soft);color:var(--text)}
.admin-tab-menu-item.active{color:var(--text);background:var(--surface-soft)}
.create-form{display:grid;gap:var(--space-4);padding:var(--space-5)}
.form-row{display:grid;grid-template-columns:1fr 1fr;gap:var(--space-4)}
.subjects-input{min-height:36px;font-size:var(--text-xs);padding:0 var(--space-3)}
.checkbox-row{display:flex;align-items:center;gap:var(--space-2);color:var(--text);font-size:var(--text-sm);font-weight:700}
.checkbox-row input{width:18px;height:18px;accent-color:var(--teal)}
.user-item-save-row{display:flex;gap:var(--space-2);margin-top:var(--space-1)}
.user-edit-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:var(--space-2);margin-top:var(--space-2)}
.user-edit-section{overflow:hidden;transition:opacity .15s}
.user-edit-toggle{background:none;border:1px solid var(--border);border-radius:var(--radius-pill);color:var(--muted);font-size:var(--text-xs);font-weight:700;padding:2px var(--space-3);cursor:pointer;margin-top:var(--space-1);transition:border-color .15s,color .15s}
.user-edit-toggle:hover{border-color:var(--border-strong);color:var(--text)}
.profile-screen{position:fixed;inset:0;z-index:300;background:var(--bg);display:flex;flex-direction:column;overflow:hidden}
.profile-topbar{display:flex;align-items:center;justify-content:space-between;padding:var(--space-4) var(--space-6);border-bottom:1px solid var(--border);gap:var(--space-4);min-height:64px}
.profile-body{flex:1;overflow-y:auto;padding:var(--space-6);max-width:520px;width:100%;margin:0 auto}
.profile-field-group{display:grid;gap:var(--space-4)}
.profile-section-title{font-weight:800;font-size:var(--text-sm);color:var(--muted);margin-bottom:var(--space-2)}

/* Collapsible settings sections on the profile screen */
.settings-section{
  background:var(--surface-soft);
  border:1px solid var(--border);
  border-radius:var(--radius-card);
  margin-bottom:var(--space-3);
  overflow:hidden;
}
.settings-section > summary{
  list-style:none;
  cursor:pointer;
  padding:var(--space-3) var(--space-4);
  font-weight:700;
  font-size:var(--text-sm);
  display:flex;
  align-items:center;
  justify-content:space-between;
  user-select:none;
}
.settings-section > summary::-webkit-details-marker{display:none}
.settings-section > summary::after{
  content:'▾';
  margin-inline-start:var(--space-3);
  color:var(--muted);
  transition:transform .15s ease;
}
.settings-section[open] > summary::after{transform:rotate(180deg)}
.settings-section > summary:hover{background:rgba(255,255,255,0.03)}
html[data-theme="light"] .settings-section > summary:hover{background:rgba(0,0,0,0.03)}
.settings-section-body{
  padding:var(--space-4);
  border-top:1px solid var(--border);
}
.amoled-toggle-row{display:flex;align-items:center;justify-content:space-between;gap:var(--space-4);cursor:pointer;background:var(--surface-soft);border:1px solid var(--border);border-radius:var(--radius-card);padding:var(--space-3) var(--space-4)}
.amoled-toggle-row>span:first-child{display:grid;gap:2px;font-weight:700}
.amoled-toggle-hint{font-weight:500;font-size:var(--text-xs);color:var(--faint)}
.amoled-toggle-row input[type=checkbox]{flex:none;width:20px;height:20px;min-height:0;accent-color:var(--teal);cursor:pointer}
.admin-log-item{border-bottom:1px solid var(--border);padding:var(--space-4);display:grid;gap:var(--space-2)}
.log-feedback-badge{margin-inline-start:6px;font-size:.95em;cursor:help;vertical-align:middle}
.admin-log-item:last-child{border-bottom:0}
.admin-log-meta{display:flex;gap:var(--space-2);flex-wrap:wrap;color:var(--faint);font-size:var(--text-xs);font-weight:800}
.chunks-panel{margin-top:var(--space-2);border:1px solid var(--border);border-radius:10px;overflow:hidden;background:var(--surface-soft,var(--surface))}
.chunk-item{padding:var(--space-3) var(--space-4);display:grid;gap:var(--space-1)}
.chunk-item-border{border-bottom:1px solid var(--border)}
.log-rewrite-row{display:flex;flex-wrap:wrap;gap:var(--space-1) var(--space-2);align-items:baseline;padding:2px 0}
.log-rewrite-label{font-size:var(--text-xs);font-weight:800;color:var(--faint);white-space:nowrap}
.log-rewrite-value{font-size:var(--text-xs);color:var(--accent);direction:rtl}
.subjects-grid{display:grid;grid-template-columns:1fr 1fr;gap:var(--space-5);margin-top:var(--space-2)}
.subjects-column{display:grid;gap:var(--space-3)}
.subject-checkbox{display:flex;align-items:center;gap:var(--space-2);padding:var(--space-2) var(--space-3);border-radius:8px;background:rgba(255,255,255,.035);color:var(--text);font-size:var(--text-sm);cursor:pointer;transition:background var(--transition);border:1px solid rgba(255,255,255,.05)}
.subject-checkbox:hover{background:rgba(255,255,255,.07);border-color:rgba(255,255,255,.1)}
.subject-checkbox input{width:16px;height:16px;accent-color:var(--teal);cursor:pointer;flex-shrink:0}
.subject-checkbox label{cursor:pointer;flex:1;margin:0}
html[data-theme="light"] .subject-checkbox{background:rgba(0,0,0,.025);border-color:rgba(0,0,0,.05)}
html[data-theme="light"] .subject-checkbox:hover{background:rgba(0,0,0,.05);border-color:rgba(0,0,0,.1)}
.phone-input{min-height:52px;border-radius:16px;padding:0 var(--space-4);width:100%;border:1px solid var(--border);background:rgba(255,255,255,.035);color:var(--text)}
.phone-input::placeholder{color:var(--faint)}
.phone-input:hover{border-color:var(--border-strong)}
.phone-input:focus{border-color:rgba(214,177,93,.9);box-shadow:0 0 0 4px rgba(214,177,93,.35);outline:0}
html[data-theme="light"] .phone-input{background:rgba(0,0,0,.025)}
.phone-wrap{display:flex;align-items:stretch;border:1px solid var(--border);border-radius:16px;overflow:hidden;background:rgba(255,255,255,.035);direction:ltr}
.phone-wrap:hover{border-color:var(--border-strong)}
.phone-wrap:focus-within{border-color:rgba(214,177,93,.9);box-shadow:0 0 0 4px rgba(214,177,93,.35)}
.phone-cc{min-height:52px;border:none;border-right:1px solid var(--border);background:transparent;color:var(--text);padding:0 var(--space-3);font:inherit;font-size:var(--text-sm);font-weight:700;cursor:pointer;flex-shrink:0;outline:none}
.phone-wrap .phone-input{border:none;border-radius:0;background:transparent;box-shadow:none!important;outline:none;flex:1;min-width:0;width:auto}
.phone-wrap .phone-input:hover,.phone-wrap .phone-input:focus{border:none;box-shadow:none!important}
html[data-theme="light"] .phone-wrap{background:rgba(0,0,0,.025)}
.stat-card{background:var(--surface-soft);border:1px solid var(--border);border-radius:12px;padding:var(--space-4);display:flex;flex-direction:column;gap:var(--space-1)}
.stat-card-label{font-size:var(--text-xs);color:var(--faint);font-weight:700}
.stat-card-value{font-size:var(--text-lg);font-weight:800;color:var(--text)}
.upgrade-dropdown{margin-top:var(--space-3);background:var(--surface-soft);border:1px solid var(--border);border-radius:16px;padding:var(--space-4);display:grid;gap:var(--space-3)}
.upgrade-type-btns{display:flex;gap:var(--space-2);flex-wrap:wrap}
.upgrade-type-btn{flex:1;min-width:80px;padding:var(--space-2) var(--space-3);border-radius:10px;border:1px solid var(--border);background:var(--surface);color:var(--text);font:inherit;font-size:var(--text-sm);cursor:pointer;transition:background var(--transition),border-color var(--transition)}
.upgrade-type-btn:hover{background:var(--surface-2);border-color:var(--border-strong)}
.upgrade-type-btn.selected{background:var(--accent);color:#fff;border-color:var(--accent)}
.upgrade-req-subsection{border-bottom:1px solid var(--border);padding-bottom:var(--space-4);margin-bottom:var(--space-4)}
.upgrade-req-subsection:last-child{border-bottom:0;padding-bottom:0;margin-bottom:0}
.upgrade-req-subsection-title{font-weight:800;font-size:var(--text-sm);color:var(--muted);padding:var(--space-4) var(--space-4) var(--space-2);border-top:1px solid var(--border)}
.upgrade-req-subsection-title:first-child{border-top:0}
.registrations-scroll{max-height:40vh;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
.bulk-action-bar{display:flex;align-items:center;gap:var(--space-3);flex-wrap:wrap;padding:var(--space-2) var(--space-4);background:var(--surface-soft);border-radius:var(--radius-md);margin:0 var(--space-4) var(--space-2)}
.bulk-action-bar[hidden]{display:none}
.bulk-action-bar .bulk-select-all{display:flex;align-items:center;gap:var(--space-2);font-size:var(--text-xs);color:var(--muted);cursor:pointer}
.bulk-action-bar .bulk-selected-count{font-size:var(--text-xs);color:var(--faint);margin-inline-end:auto}
.bulk-action-bar .primary-button,.bulk-action-bar .danger-button{min-height:30px;font-size:var(--text-xs);padding:0 var(--space-3)}
.bulk-action-bar button:disabled{opacity:.5;cursor:not-allowed}
.admin-log-item .bulk-check{vertical-align:middle;cursor:pointer}
#gsErrorTable th,#gsErrorTable td{border-bottom:1px solid var(--border);padding:var(--space-2) var(--space-3);vertical-align:top}
#gsErrorTable tr:last-child td{border-bottom:0}
#gsErrorTable tbody tr:hover{background:var(--surface-soft)}
.admin-spinner{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:var(--space-6);gap:var(--space-3);color:var(--faint);font-size:var(--text-sm)}
.spinner{width:32px;height:32px;border:3px solid var(--border);border-top-color:var(--accent);border-radius:50%;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.skeleton-item{padding:var(--space-4);margin-bottom:var(--space-2);border-radius:8px;background:var(--surface-soft);animation:pulse 1.5s ease-in-out infinite}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.6}}
@media(max-width:767px){
  html,body{width:100%;max-width:100%;overflow-x:hidden}
  .screen,.main-screen,.admin-screen,.login-screen{width:100vw;max-width:100vw;overflow-x:hidden}
  .admin-topbar{position:sticky;top:0;z-index:3;min-width:0;padding-inline:var(--space-4)}
  .admin-body{padding:var(--space-4);padding-bottom:calc(var(--space-16) + env(safe-area-inset-bottom))}
  .admin-tabs{display:none!important}
  .admin-burger{display:flex}
  .admin-tab-menu{display:none;z-index:2;-webkit-backdrop-filter:blur(18px);backdrop-filter:blur(18px);background:rgba(33,33,33,.92);max-height:calc(100dvh - var(--topbar-height) - env(safe-area-inset-top,0px));overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
  .admin-tab-menu.open{display:flex}
  html[data-theme="light"] .admin-tab-menu{background:rgba(255,255,255,.92)}
  .admin-section{margin-bottom:var(--space-4);max-width:100%;overflow:visible}
  .admin-section-header{padding:var(--space-3) var(--space-4)}
  .form-row{grid-template-columns:1fr}
  .user-item{grid-template-columns:minmax(0,1fr);padding:var(--space-4);max-width:100%;overflow:visible;word-break:break-word}
  .user-item-info,.user-item-meta{min-width:0;max-width:100%;word-break:break-word}
  .user-edit-grid{grid-template-columns:minmax(0,1fr)}
  .user-item-save-row{flex-wrap:wrap}
  .user-item-save-row .subjects-input{flex:1 1 100%;width:100%}
  .profile-body{padding:var(--space-4)}
  .user-item-actions{flex-direction:row;flex-wrap:wrap;align-items:center}
  #feedbackList{max-height:calc(100dvh - var(--topbar-height) - 160px)!important;overflow-y:auto!important}
  #adminStatsList{max-width:100%;overflow-x:auto}
  .stat-card{min-width:160px;flex-shrink:0}
  table{font-size:var(--text-xs)}
  [style*="overflow-x:auto"]{-webkit-overflow-scrolling:touch;scrollbar-width:thin}
}

/* ── Lesson-order drag-and-drop list ───────────────────────────────────────── */
.lesson-order-row{
  display:flex;align-items:center;gap:var(--space-3);
  padding:var(--space-2) var(--space-3);
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  margin-bottom:var(--space-2);
  cursor:grab;user-select:none;
}
.lesson-order-row.dragging{opacity:.5;cursor:grabbing}
.lesson-order-row.drag-over{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent) inset}
.lesson-order-handle{color:var(--faint);font-size:1.1rem;line-height:1;flex-shrink:0}
.lesson-order-num{
  flex-shrink:0;min-width:1.6em;text-align:center;
  font-size:var(--text-xs);font-weight:700;color:var(--muted);
}
.lesson-order-name{flex:1;min-width:0;font-size:var(--text-sm);overflow-wrap:anywhere}

/* New feature components (loaded last so it can layer over base styles). */

/* ── Chat: source deep-link button (feature 7) ───────────────────────────── */
.source-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}
.source-open-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-xs);
  padding: 4px 10px;
}
.source-open-btn:hover { background: var(--surface-soft); }

/* ── QA: per-card tools (features 14, 15) ────────────────────────────────── */
.qa-card-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.qa-card-tools .ghost-button { font-size: var(--text-xs); }
.qa-note-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.qa-note-box textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  resize: vertical;
  box-sizing: border-box;
}
.qa-note-box .primary-button { align-self: flex-end; min-height: 32px; font-size: var(--text-xs); }

/* ── QA: setup quick tools + weak areas (features 11, 12) ─────────────────── */
.qa-setup-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: var(--space-3);
}
.qa-setup-tools .ghost-button { flex: 1; font-size: var(--text-sm); }
#qaCreateCardView textarea,
#qaCreateCardView select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  box-sizing: border-box;
  resize: vertical;
}
.qa-weak-list { display: flex; flex-direction: column; gap: var(--space-3); }
.qa-weak-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: var(--surface-soft);
}
.qa-weak-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.qa-weak-topic { font-weight: 700; }
.qa-weak-subject { color: var(--muted); font-size: var(--text-xs); }
.qa-weak-bar {
  height: 8px;
  border-radius: 99px;
  background: var(--surface-raised);
  overflow: hidden;
}
.qa-weak-bar-fill { height: 100%; background: var(--error); }
.qa-weak-meta { font-size: var(--text-xs); color: var(--muted); margin-top: 6px; }

/* ── Summaries: reading progress (feature 16) ────────────────────────────── */
.sum-page-read-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  padding: 6px 12px;
}
.sum-page-read-btn.is-read {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.sum-subj-progress {
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--surface-soft);
  border-radius: 99px;
  padding: 1px 7px;
  margin-inline-start: auto;
  margin-inline-end: 6px;
}
.sum-subj-progress.complete { color: var(--success); }
.sum-page-link.is-read::after {
  content: "✓";
  color: var(--success);
  margin-inline-start: 6px;
  font-size: 0.8rem;
}

/* ── Summaries: highlights & annotations (feature 17) ────────────────────── */
mark.sum-hl { border-radius: 3px; padding: 0 1px; cursor: pointer; color: inherit; }
mark.sum-hl-yellow { background: rgba(255, 214, 0, 0.45); }
mark.sum-hl-green  { background: rgba(70, 200, 120, 0.40); }
mark.sum-hl-blue   { background: rgba(80, 160, 255, 0.38); }
mark.sum-hl-pink   { background: rgba(255, 110, 170, 0.38); }
mark.sum-hl.has-note { border-bottom: 2px dotted currentColor; }
.sum-sel-toolbar,
.sum-hl-popup {
  position: absolute;
  z-index: 400;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  padding: 6px;
}
.sum-sel-toolbar { display: flex; gap: 6px; }
.sum-sel-color {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.sum-sel-color.active { border-color: var(--text); }
.sum-sel-color.sum-hl-yellow { background: #ffd600; }
.sum-sel-color.sum-hl-green  { background: #46c878; }
.sum-sel-color.sum-hl-blue   { background: #50a0ff; }
.sum-sel-color.sum-hl-pink   { background: #ff6eaa; }
.sum-hl-popup { width: 240px; display: flex; flex-direction: column; gap: 8px; }
.sum-hl-popup-colors { display: flex; gap: 6px; }
.sum-hl-popup textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  padding: 6px;
  box-sizing: border-box;
  resize: vertical;
}
.sum-hl-popup-actions { display: flex; gap: 6px; justify-content: flex-end; }
.sum-hl-popup-actions .primary-button,
.sum-hl-popup-actions .ghost-button { min-height: 30px; font-size: var(--text-xs); padding: 0 12px; }

/* ── Admin: AI-generated cards (feature 25) ──────────────────────────────── */
.sum-gen-cards-list { display: flex; flex-direction: column; gap: var(--space-2); }
.sum-gen-card {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2);
  background: var(--surface-soft);
}
.sum-gen-card-body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.sum-gen-card-body textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  padding: 6px;
  box-sizing: border-box;
  resize: vertical;
}

/* ── Profile: study panel — stats, goals, dashboard ── */
.study-panel { margin-top: var(--space-5); }
.study-next-action {
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  margin-bottom: var(--space-3);
}
.study-today-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}
.study-today-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2);
  text-align: center;
  background: var(--surface-soft);
}
.study-today-box.met { border-color: var(--success); }
.study-today-label { font-size: var(--text-xs); color: var(--muted); }
.study-today-value { font-weight: 700; margin: 4px 0; }
.study-today-bar {
  height: 6px;
  border-radius: 99px;
  background: var(--surface-raised);
  overflow: hidden;
}
.study-today-fill { height: 100%; background: var(--accent); }
.study-goals-editor { display: flex; flex-direction: column; gap: var(--space-2); }
.study-goal-row { display: flex; align-items: center; gap: var(--space-2); }
.study-goal-row label { flex: 1; font-size: var(--text-sm); }
.study-goal-row input { width: 96px; }
.study-stats-box {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
}
.study-stat {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: var(--text-sm);
}
.study-stat-value { font-weight: 700; }
.study-stat-subjects { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; }
.study-subj-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--muted);
  padding: 2px 4px;
}
.study-week-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
  padding-top: var(--space-2);
}
.study-week-col { flex: 1; display: flex; align-items: flex-end; height: 100%; }
.study-week-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
}

/* ── F5: Study plan ──────────────────────────────────────────────────────── */
.study-plan-row { display: flex; gap: var(--space-2); align-items: center; margin-bottom: var(--space-2); }
.study-plan-result {
  font-size: var(--text-sm);
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  line-height: 1.6;
}

/* ── F10: Daily insight widget ───────────────────────────────────────────── */
.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.insight-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}
.insight-text {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--text);
}
.insight-source {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ── F11: Pomodoro timer ─────────────────────────────────────────────────── */
.pomo-widget { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.pomo-summary {
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  list-style: none;
  user-select: none;
}
.pomo-summary::-webkit-details-marker { display: none; }
.pomo-body {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  border-top: 1px solid var(--border);
}
.pomo-phase { font-size: var(--text-sm); color: var(--text-muted); }
.pomo-display { font-size: 2.4rem; font-weight: 700; letter-spacing: 0.05em; font-variant-numeric: tabular-nums; }
.pomo-btns { display: flex; gap: var(--space-2); }
.pomo-cycles { font-size: var(--text-xs); color: var(--text-muted); }

/* ── F15: Font size selector ─────────────────────────────────────────────── */
.font-size-btns {
  display: flex;
  gap: var(--space-2);
}
.font-size-btn {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-sm);
  transition: background 0.15s, border-color 0.15s;
}
.font-size-btn:hover { background: var(--surface-soft); }
.font-size-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Toast notifications (4.1) ───────────────────────────────────────────── */
.app-toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-4));
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(12px);
  background: var(--surface-2, #2a2a2e);
  color: var(--text-primary, #f1f1f1);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-lg, 10px);
  font-size: 0.9rem;
  max-width: min(90vw, 420px);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  text-align: center;
  direction: rtl;
}
[dir="ltr"] .app-toast {
  transform: translateX(-50%) translateY(12px);
}
.app-toast--visible {
  opacity: 1;
  transform: translateX(50%) translateY(0);
}
[dir="ltr"] .app-toast--visible {
  transform: translateX(-50%) translateY(0);
}
.app-toast--error   { border-inline-start: 3px solid #e55; }
.app-toast--success { border-inline-start: 3px solid #5a5; }
.app-toast--warning { border-inline-start: 3px solid #fa0; }

/* ── PWA install banner (0.7 — surfaces the captured beforeinstallprompt) ─── */
.pwa-install-banner {
  position: fixed;
  inset-inline: var(--space-4);
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--composer-height) + var(--space-3));
  margin-inline: auto;
  max-width: 440px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-raised);
  direction: rtl;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.pwa-install-banner--visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.pwa-install-banner-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}
.pwa-install-banner-text {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
}
.pwa-install-banner-action {
  flex-shrink: 0;
  background: var(--teal);
  color: #04202c;
  border: none;
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s;
}
.pwa-install-banner-action:hover { filter: brightness(1.08); }
.pwa-install-banner-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 6px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.pwa-install-banner-dismiss:hover { color: var(--text); background: var(--surface-soft); }

@media (max-width: 480px) {
  .pwa-install-banner {
    inset-inline: var(--space-3);
    max-width: none;
  }
  .pwa-install-banner-text { font-size: var(--text-xs); }
}

/* ── Feature-flag gating — body.feat-off-{key} hides the feature's UI ─────── */
body.feat-off-voice_input          #voiceToggle              { display: none !important; }
body.feat-off-file_upload          #attachToggle             { display: none !important; }
body.feat-off-summaries_mode       #modeSummaries            { display: none !important; }
body.feat-off-qa_mode              #modeTest                 { display: none !important; }
body.feat-off-study_panel          #studyPanelSection        { display: none !important; }
body.feat-off-pomodoro             #pomoWidget               { display: none !important; }
body.feat-off-rewriter             #rewriterItem             { display: none !important; }
body.feat-off-confidence_score     #confidenceItem           { display: none !important; }
body.feat-off-chain_of_thought     #reasoningItem            { display: none !important; }
body.feat-off-model_selector       #modelSelectItem          { display: none !important; }
body.feat-off-conversation_search  #searchToggleButton       { display: none !important; }
body.feat-off-otp_login            #sendLoginOtpButton       { display: none !important; }
body.feat-off-otp_login            #sendRegisterOtpButton    { display: none !important; }
body.feat-off-otp_login            #registerOtpField         { display: none !important; }
/* In OTP mode the password field is hidden — the user never sets one. In
   password mode (otp_login off) the field is the primary credential, so show. */
#registerPasswordField              { display: none; }
body.feat-off-otp_login #registerPasswordField { display: block; }
/* Reset link/subtitle wording is handled in JS; this just visually trims the
   register subtitle's mention of WhatsApp when OTP is off. */
body.feat-off-otp_login .register-otp-only { display: none !important; }
body.feat-off-chat_organize        #chatOrganizeButton       { display: none !important; }
body.feat-off-chat_summarize       #chatSummarizeButton      { display: none !important; }
body.feat-off-chat_consensus       #chatConsensusButton      { display: none !important; }
body.feat-off-shared_conversations .feat-shared_conversations { display: none !important; }
body.feat-off-tts                  .feat-tts                 { display: none !important; }
body.feat-off-export_chat          .feat-export_chat         { display: none !important; }
body.feat-off-save_as_card         .feat-save_as_card        { display: none !important; }
body.feat-off-bookmarks            .feat-bookmarks           { display: none !important; }
body.feat-off-exam_mode            #examModeItem             { display: none !important; }
body.feat-off-ask_teacher          .feat-ask_teacher         { display: none !important; }

/* FEAT-N1: answer-grounding notice */
.grounding-notice { margin-top:.5em; font-size:var(--text-xs); border:1px solid var(--border); border-radius:8px; padding:.3em .6em; background:var(--surface-2); }
.grounding-notice summary { cursor:pointer; color:var(--warning, #b8860b); }
.grounding-notice ul { margin:.4em 0 0; padding-inline-start:1.2em; color:var(--muted); }
.grounding-notice li { margin:.2em 0; line-height:1.5; }
body.feat-off-bookmarks            #bookmarksToggleButton    { display: none !important; }
body.feat-off-feedback_buttons     .feat-feedback_buttons    { display: none !important; }
body.feat-off-regenerate           .feat-regenerate          { display: none !important; }
body.feat-off-faq                  .faq-icon-button          { display: none !important; }
body.feat-off-changelog            #changelogToggle          { display: none !important; }
body.feat-off-conversation_pin     .session-pin              { display: none !important; }
body.feat-off-trial_mode           #trialBanner              { display: none !important; }

