/* =========================================
   PHYSICS QUESTION BANK — EDITORIAL WORKSPACE
   Dark Obsidian Theme v3.0
   ========================================= */

/* ── DESIGN TOKENS ── */
:root {
    --bg:            #0b0d17;
    --surface:       #10131f;
    --surface-2:     #161b2e;
    --surface-3:     #1c2338;
    --surface-4:     #232a42;

    --border:        rgba(255, 255, 255, 0.06);
    --border-mid:    rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --border-active: rgba(99, 102, 241, 0.6);

    --text-hi:       #e8ebf5;
    --text:          #aeb5cc;
    --text-lo:       #636a87;
    --text-xlo:      #393f58;

    --accent:        #6366f1;
    --accent-hi:     #818cf8;
    --accent-lo:     #4f52c9;
    --accent-soft:   rgba(99, 102, 241, 0.14);
    --accent-glow:   0 0 0 3px rgba(99, 102, 241, 0.22);

    --ok:            #34d399;
    --ok-soft:       rgba(52, 211, 153, 0.14);
    --warn:          #fbbf24;
    --warn-soft:     rgba(251, 191, 36, 0.14);
    --err:           #f87171;
    --err-soft:      rgba(248, 113, 113, 0.14);
    --info:          #60a5fa;
    --info-soft:     rgba(96, 165, 250, 0.14);

    --shadow-sm:     0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow:        0 4px 20px rgba(0, 0, 0, 0.55);
    --shadow-lg:     0 12px 48px rgba(0, 0, 0, 0.75);

    --radius:        13px;
    --radius-sm:     8px;
    --radius-xs:     5px;

    --ease:          cubic-bezier(0.4, 0, 0.2, 1);
    --dur:           0.18s;
    --header-h:      58px;
}

/* ── BASE RESET ── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
p, h1, h2, h3, h4, h5, h6 { margin: 0; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-lo); }

/* ── APP SHELL ── */
.app-shell { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }

/* ── AUTH SCREEN ── */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.10) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(96, 165, 250, 0.08) 0%, transparent 50%),
        var(--bg);
}

.auth-card {
    width: min(100%, 400px);
    padding: 36px;
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-badge {
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-lo));
    color: #fff; font-weight: 800; font-size: 18px;
    letter-spacing: 0.04em;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    margin-bottom: 4px;
}

.auth-card h1 { font-size: 22px; font-weight: 700; color: var(--text-hi); }
.auth-card > p, .hint-block { color: var(--text-lo); font-size: 13px; }

.hint-block { margin-top: 10px; }
.hint-block span {
    font-family: 'IBM Plex Mono', monospace;
    background: var(--surface-3); padding: 1px 6px;
    border-radius: 4px; color: var(--text);
}

.auth-button { width: 100%; margin-top: 4px; }

/* ── APP HEADER ── */
.app-header {
    height: var(--header-h);
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 20px;
    align-items: center;
    padding: 0 20px;
    background: rgba(16, 19, 31, 0.88);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
    flex-shrink: 0;
}

.brand-block { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-mark {
    width: 36px; height: 36px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-lo));
    color: #fff; font-weight: 800; font-size: 14px;
    letter-spacing: 0.04em;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}

.brand-block h1 {
    font-size: 15px; font-weight: 700; color: var(--text-hi);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.brand-block p { font-size: 11px; color: var(--text-lo); margin-top: 1px; }

.header-tabs {
    display: flex; align-items: center; gap: 2px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 4px; border-radius: 10px;
}

.header-tab {
    padding: 7px 16px; border: 0; border-radius: 7px;
    background: transparent; color: var(--text-lo);
    font-weight: 600; font-size: 13px;
    transition: all var(--dur) var(--ease);
}

.header-tab:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.header-tab.is-active {
    background: var(--accent); color: #fff;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}

.header-tab:disabled { opacity: 0.35; cursor: not-allowed; }

.session-block { display: flex; align-items: center; gap: 12px; }
.session-meta { text-align: right; }
.session-meta strong { display: block; font-size: 13px; color: var(--text-hi); font-weight: 600; }
.session-meta span { font-size: 11px; color: var(--text-lo); text-transform: capitalize; }

/* ── WORKSPACE ROOT ── */
.workspace-root { flex: 1; padding: 16px; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

/* ── SHARED VIEW HEIGHTS ── */
.library-view,
.curate-view,
.ingest-view {
    flex: 1;
    min-height: 0;
}

/* ── LIBRARY VIEW ── */
.library-view { display: flex; gap: 0; }

.library-main,
.library-side {
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.library-main { flex: 1; min-width: 0; }

/* ── CURATE VIEW ── */
.curate-view { display: flex; flex-direction: column; gap: 0; overflow: hidden; }

.curate-context-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    flex-shrink: 0;
}

.context-path {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.context-book {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-hi);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.context-sep {
    color: var(--text-xlo);
    font-size: 16px;
    font-weight: 300;
    flex-shrink: 0;
}

.context-select {
    padding: 5px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    max-width: 200px;
    cursor: pointer;
    transition: border-color var(--dur) var(--ease);
}

.context-select:focus {
    outline: none;
    border-color: var(--accent);
}

.context-select option {
    background: var(--surface-2);
    color: var(--text);
}

.context-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.curate-layout {
    display: flex;
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.curate-layout > .question-index-panel,
.curate-layout > .question-preview-panel,
.curate-layout > .editor-panel {
    border-radius: 0;
    border-top: 0;
}

.curate-layout > .question-index-panel { border-radius: 0 0 0 var(--radius); }
.curate-layout > .editor-panel { border-radius: 0 0 var(--radius) 0; }

/* ── SHARED PANEL STYLE ── */
.question-index-panel,
.question-preview-panel,
.editor-panel,
.ingest-card,
.jobs-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
}

.question-preview-panel,
.jobs-panel { flex: 1; min-width: 0; }

.question-preview-panel {
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
}

/* ── TOOLBAR ── */
.library-toolbar,
.curate-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.library-toolbar h2,
.curate-toolbar h2 {
    font-size: 18px; font-weight: 700; color: var(--text-hi);
}

.library-toolbar p,
.curate-toolbar p {
    font-size: 12px; color: var(--text-lo); margin-top: 3px;
}

.toolbar-actions {
    display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}

/* ── BUTTONS ── */
.ghost-button,
.primary-button,
.danger-button {
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 13px;
    transition: all var(--dur) var(--ease);
}

.ghost-button {
    background: var(--surface-3);
    border-color: var(--border-mid);
    color: var(--text);
}
.ghost-button:hover { background: var(--surface-4); border-color: var(--border-strong); color: var(--text-hi); }

.ghost-button.small { padding: 6px 10px; font-size: 12px; }
.ghost-button.tiny  { padding: 4px 8px; font-size: 11px; }

.ghost-button.danger { color: var(--err); }
.ghost-button.danger:hover { background: var(--err-soft); border-color: rgba(248, 113, 113, 0.3); }

.primary-button {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.primary-button:hover { background: var(--accent-lo); }

.danger-button {
    background: var(--err);
    color: #fff;
    box-shadow: 0 2px 8px rgba(248, 113, 113, 0.3);
}
.danger-button:hover { background: #dc2626; }

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
    opacity: 0.4; cursor: not-allowed;
}

.icon-button {
    padding: 4px 8px;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-lo);
    font-size: 11px;
    font-weight: 600;
    transition: all var(--dur) var(--ease);
}
.icon-button:hover { background: var(--surface-4); color: var(--text); }
.icon-button.danger { color: var(--err); }
.icon-button.danger:hover { background: var(--err-soft); }
.icon-button.accent { color: var(--accent-hi); }
.icon-button.accent:hover { background: var(--accent-soft); }

/* ── SUBJECT FILTER ── */
.subject-filter-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.filter-pill {
    padding: 6px 13px;
    border: 1px solid var(--border-mid);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-lo);
    font-weight: 600;
    font-size: 12px;
    transition: all var(--dur) var(--ease);
    position: relative;
}
.filter-pill:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-3); }
.filter-pill.is-active {
    background: var(--accent-soft);
    border-color: var(--border-active);
    color: var(--accent-hi);
}

/* ── BOOK GRID ── */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.book-card {
    display: flex; flex-direction: column; gap: 10px;
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}
.book-card:hover {
    border-color: var(--border-mid);
    background: var(--surface-3);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.book-card.is-selected {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: var(--accent-glow);
}

.book-card-top {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

.book-card h3 { font-size: 14px; font-weight: 600; color: var(--text-hi); line-height: 1.4; }
.book-card p { font-size: 12px; color: var(--text-lo); }

.book-card-actions {
    display: flex; gap: 4px; margin-top: auto;
    opacity: 0; transition: opacity var(--dur) var(--ease);
}
.book-card:hover .book-card-actions { opacity: 1; }

/* ── PILLS & BADGES ── */
.pill-accent,
.status-pill,
.compile-pill {
    display: inline-flex; align-items: center;
    padding: 3px 9px; border-radius: 999px;
    font-size: 10px; font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.pill-accent { background: var(--accent-soft); color: var(--accent-hi); }
.muted-mini  { font-size: 11px; color: var(--text-lo); font-weight: 500; }

.status-draft    { background: var(--surface-3);  color: var(--text-lo); }
.status-compiled { background: var(--info-soft);   color: var(--info); }
.status-reviewed { background: var(--warn-soft);   color: var(--warn); }
.status-approved { background: var(--ok-soft);     color: var(--ok); }
.status-rejected { background: var(--err-soft);    color: var(--err); }

.compile-good    { background: var(--ok-soft);     color: var(--ok); }
.compile-bad     { background: var(--err-soft);    color: var(--err); }
.compile-pending { background: var(--surface-3);   color: var(--text-lo); }

/* ── PANEL HEADER ── */
.panel-header {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    margin-bottom: 14px;
}
.panel-header h3 { font-size: 14px; font-weight: 700; color: var(--text-hi); }
.panel-header p  { font-size: 11px; color: var(--text-lo); margin-top: 2px; }
.panel-header.compact { margin-bottom: 10px; }
.panel-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── ANALYTICS ── */
.analytics-panel {
    margin-top: 18px; padding-top: 14px;
    border-top: 1px solid var(--border);
}
.analytics-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
}
.analytics-header h4,
.tree-panel-header h4 {
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-lo);
}

.analytics-summary {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 8px; margin-bottom: 12px;
}

.summary-card,
.status-card {
    padding: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex; flex-direction: column; gap: 4px;
}
.summary-card span,
.status-card span {
    font-size: 10px; color: var(--text-lo);
    font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
}
.summary-card strong { font-size: 20px; font-weight: 800; color: var(--text-hi); line-height: 1; }
.status-card strong  { font-size: 13px; font-weight: 600; color: var(--text); }

.chapter-analytics-list {
    display: flex; flex-direction: column; gap: 8px;
}

.chapter-summary-card {
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.chapter-summary-top {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.chapter-summary-card h5 { font-size: 13px; font-weight: 600; color: var(--text); margin: 0; }
.chapter-summary-card p  { font-size: 11px; color: var(--text-lo); margin-top: 2px; }
.chapter-summary-top strong { font-size: 16px; font-weight: 800; color: var(--accent-hi); }

.section-count-list { margin-top: 8px; display: grid; gap: 4px; }
.section-count-row {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 4px 8px;
    font-size: 12px; color: var(--text-lo);
    border-radius: var(--radius-xs);
}
.section-count-row:hover { background: var(--surface-3); }

/* ── CHAPTER/SECTION TREE ── */
.tree-panel {
    margin-top: 14px; padding-top: 14px;
    border-top: 1px solid var(--border);
}
.tree-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
}
.tree-list { display: flex; flex-direction: column; gap: 5px; }

.tree-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color var(--dur) var(--ease);
}
.tree-card.is-selected { border-color: var(--accent); }

.tree-card-header {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background var(--dur) var(--ease);
}
.tree-card-header:hover { background: var(--surface-3); }
.tree-card-header strong { font-size: 13px; color: var(--text); font-weight: 600; }
.tree-card.is-selected .tree-card-header strong { color: var(--text-hi); }

.tree-card-actions { display: flex; gap: 2px; flex-shrink: 0; }

.tree-section-list {
    padding: 0 6px 6px;
    display: flex; flex-direction: column; gap: 3px;
}
.tree-section-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 6px 6px;
}
.tree-section-toolbar span { font-size: 11px; color: var(--text-lo); font-weight: 600; }

.tree-section-item {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    padding: 8px 10px;
    border-radius: var(--radius-xs);
    background: var(--surface-3);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}
.tree-section-item:hover { background: var(--surface-4); border-color: var(--border-mid); }
.tree-section-item.is-selected { background: var(--accent-soft); border-color: var(--border-active); }

.tree-section-item > span {
    font-size: 12px; color: var(--text); font-weight: 500;
    flex: 1; min-width: 0; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.tree-section-item.is-selected > span { color: var(--accent-hi); }

.section-nav-actions {
    display: flex; gap: 2px; flex-shrink: 0;
    opacity: 0; transition: opacity var(--dur) var(--ease);
}
.tree-section-item:hover .section-nav-actions,
.tree-section-item.is-selected .section-nav-actions { opacity: 1; }

/* ── QUESTION INDEX PANEL ── */
.question-index-list {
    display: flex; flex-direction: column; gap: 4px;
}

.question-index-item {
    display: flex; justify-content: space-between; align-items: center;
    gap: 10px; width: 100%;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: left;
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}
.question-index-item:hover { background: var(--surface-3); border-color: var(--border-mid); }
.question-index-item.is-selected {
    background: var(--accent-soft);
    border-color: var(--border-active);
    box-shadow: var(--accent-glow);
}

.question-index-copy {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
}
.question-index-copy strong { font-size: 13px; color: var(--text-hi); }
.question-index-copy span { font-size: 10px; color: var(--text-lo); }
.question-index-item.is-selected .question-index-copy strong { color: var(--accent-hi); }

.question-index-meta {
    display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}

/* ── PREVIEW CONTROLS (Layout & Theme selectors) ── */
.preview-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-group {
    display: flex;
    background: var(--surface-2);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-xs);
    padding: 2px;
    overflow: hidden;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border: none;
    border-radius: calc(var(--radius-xs) - 2px);
    background: transparent;
    color: var(--text-lo);
    font-size: 11px;
    font-weight: 600;
    transition: all var(--dur) var(--ease);
    user-select: none;
}

.control-btn svg {
    flex-shrink: 0;
    opacity: 0.75;
}

.control-btn:hover {
    color: var(--text);
    background: var(--surface-3);
}

.control-btn.active {
    color: #ffffff;
    background: var(--accent);
}

.control-btn.active svg {
    opacity: 1;
}

/* ── PREVIEW CONTAINER AND LAYOUTS ── */
.preview-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preview-container.preview-layout-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    align-content: start;
    gap: 14px;
}

.preview-container.preview-layout-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.preview-container.preview-layout-list .preview-card {
    width: 100%;
}

.preview-container.preview-layout-list .render-surface {
    min-height: 240px; /* larger card height in list mode */
}

/* Focus Mode Layout styling */
.preview-container.preview-layout-focus {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.preview-container.preview-layout-focus .preview-card.focus-card {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    cursor: default;
}

.preview-container.preview-layout-focus .focus-surface {
    flex: 1;
    min-height: 380px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.preview-container.preview-layout-focus .focus-surface img {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
}

.preview-card {
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.preview-card:hover { border-color: var(--border-mid); background: var(--surface-3); }

/* Highlight styling when selected */
.preview-card.is-selected {
    border: 1px solid var(--accent) !important;
    border-left: 6px solid var(--accent) !important; /* Premium left accent border */
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.25) !important;
    padding-left: 7px !important; /* offset padding to prevent layout shifting */
}
.preview-card.theme-dark.is-selected {
    background: rgba(99, 102, 241, 0.08) !important;
}
.preview-card.theme-light.is-selected {
    background: #f0f3ff !important;
    border-color: var(--accent) !important;
}

.preview-card-header {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.preview-card-header strong { font-size: 15px; color: var(--text-hi); }
.preview-card-header p { font-size: 11px; color: var(--text-lo); margin-top: 1px; }

/* Specifically target header actions to increase font size */
.preview-card-header .icon-button {
    font-size: 13px;
    padding: 4px 10px;
    font-weight: 700;
}

/* Same line layout for Card Number & Question Type */
.card-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Highlight badge for the Question Type */
.card-q-type {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px;
    border-radius: var(--radius-xs);
    background: var(--accent-soft);
    color: var(--accent-hi);
    border: 1px solid rgba(99, 102, 241, 0.25);
    display: inline-block;
    vertical-align: middle;
    transition: all var(--dur) var(--ease);
}

.preview-card.theme-light .card-q-type {
    background: #e0e7ff;
    color: #4338ca;
    border-color: #c7d2fe;
}

/* ── RENDER SURFACE (SVG previews) ── */
.render-surface {
    min-height: 160px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    background: #ffffff;
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-sm);
    padding: 12px;
    overflow: auto;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.render-surface.compact { min-height: 100px; }
.render-surface img {
    max-width: 100%;
    height: auto;
    display: block;
    flex-grow: 1;
    flex-shrink: 1;
    min-width: 0;
}
.render-surface span {
    color: var(--text-lo);
    font-size: 12px;
    align-self: center;
    margin: auto;
}

/* Themes */
.render-surface.theme-dark {
    background: var(--surface-3);
    border-color: var(--border-mid);
}

.render-surface.theme-dark img {
    filter: invert(1) hue-rotate(180deg);
}

.render-surface.theme-light {
    background: #ffffff;
    border-color: var(--border-mid);
}

.render-surface.theme-light img {
    filter: none;
}

/* ── PREVIEW CARD DYNAMIC THEMES ── */
.preview-card.theme-light {
    background: #ffffff !important;
    border-color: #e2e8f0 !important;
    color: #1e293b !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.preview-card.theme-light .preview-card-header strong {
    color: #0f172a !important;
}

.preview-card.theme-light .preview-card-header p {
    color: #64748b !important;
}

.preview-card.theme-light .preview-card-header .icon-button.danger {
    color: #ef4444 !important;
}

.preview-card.theme-light .preview-card-header .icon-button.danger:hover {
    background: #fef2f2 !important;
}

.preview-card.theme-dark {
    background: var(--surface-2) !important;
    border-color: var(--border) !important;
}

/* Remove nested rendering surface container styles inside cards (excluding focus mode) */
.preview-card:not(.focus-card) .render-surface {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    min-height: auto !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

/* Left-align SVG content inside cards */
.preview-card:not(.focus-card) .render-surface img {
    margin-right: auto;
    margin-left: 0;
    max-width: 100%;
}

/* Adjust list layout height to auto since cards wrap content */
.preview-container.preview-layout-list .render-surface {
    min-height: auto !important;
}

/* ── EDITOR PANEL ── */
.editor-panel {
    display: flex; flex-direction: column; gap: 14px;
}

.editor-status-grid {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.editor-status-grid.two-col { margin-top: 12px; }

/* ── FORM ELEMENTS ── */
.form-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.form-grid .full { grid-column: 1 / -1; }

.field-stack { display: flex; flex-direction: column; gap: 6px; }

.field-label {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-lo);
}

.field-input,
.field-textarea {
    width: 100%;
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: var(--surface-2);
    color: var(--text-hi);
    transition: border-color var(--dur) var(--ease);
}

.field-input option { background: var(--surface-2); color: var(--text); }

.field-textarea { min-height: 100px; resize: vertical; }
.field-textarea.small { min-height: 80px; }
.ingest-textarea { min-height: 240px; }

.field-input:focus,
.field-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.12);
}

.inline-error {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--err-soft);
    color: var(--err);
    font-size: 12px;
    border: 1px solid rgba(248, 113, 113, 0.2);
}

/* ── CODE EDITOR ── */
.editor-surface {
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-sm);
    overflow: hidden;
    min-height: 300px;
}

.CodeMirror {
    height: 300px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    background: var(--surface-2) !important;
    color: var(--text) !important;
}

.CodeMirror-gutters {
    background: var(--surface) !important;
    border-right: 1px solid var(--border) !important;
}

.CodeMirror-linenumber { color: var(--text-xlo) !important; }
.CodeMirror-cursor { border-left-color: var(--accent-hi) !important; }
.CodeMirror-selected { background: var(--accent-soft) !important; }
.CodeMirror-matchingbracket { color: var(--accent-hi) !important; text-decoration: underline; }

/* ── CodeMirror Dark Theme Syntax Colors ── */
.cm-s-default .cm-keyword { color: #818cf8 !important; } /* Indigo */
.cm-s-default .cm-builtin { color: #34d399 !important; } /* Green */
.cm-s-default .cm-string { color: #fbbf24 !important; } /* Yellow */
.cm-s-default .cm-variable { color: #e8ebf5 !important; } /* Text High */
.cm-s-default .cm-variable-2 { color: #60a5fa !important; } /* Blue */
.cm-s-default .cm-def { color: #f87171 !important; } /* Red */
.cm-s-default .cm-number { color: #f472b6 !important; } /* Pink */
.cm-s-default .cm-comment { color: #636a87 !important; font-style: italic; } /* Muted */
.cm-s-default .cm-atom { color: #c084fc !important; } /* Purple */
.cm-s-default .cm-atom { color: #34d399 !important; } /* math elements (Emerald) */
.cm-s-default .cm-def { color: #60a5fa !important; } /* definitions (Blue) */
.cm-s-default .cm-variable,
.cm-s-default .cm-variable-2,
.cm-s-default .cm-variable-3 { color: #e8ebf5 !important; } /* normal text */
.cm-s-default .cm-string,
.cm-s-default .cm-string-2 { color: #fbbf24 !important; } /* Math mode and bracket content (Amber) */
.cm-s-default .cm-number { color: #f87171 !important; }
.cm-s-default .cm-comment { color: #636a87 !important; font-style: italic; }
.cm-s-default .cm-bracket { color: #aeb5cc !important; }
.cm-s-default .cm-tag { color: #818cf8 !important; }
.cm-s-default .cm-link { color: #818cf8 !important; }
.cm-s-default .cm-error { color: #ef4444 !important; background: transparent !important; }

/* ── SOLUTION & HISTORY ── */
.solution-panel,
.history-panel { margin-top: 14px; }

.history-list { display: flex; flex-direction: column; gap: 6px; }

.history-item {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.history-item-top {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    margin-bottom: 4px;
}
.history-item-top strong { font-size: 13px; color: var(--text-hi); }
.history-item-top span { font-size: 11px; color: var(--text-lo); }
.history-item p { font-size: 12px; color: var(--text-lo); }
.history-item small { font-size: 11px; color: var(--text-xlo); }

/* ── INGEST VIEW REDESIGN ── */
.ingest-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    gap: 12px;
}

.ingest-workspace-body {
    display: flex;
    gap: 16px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.ingest-workspace-input {
    width: 55%;
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    min-height: 0;
}

.ingest-workspace-monitor {
    width: 45%;
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    min-height: 0;
}

/* Tab Header Navigation */
.ingest-tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.tab-button-group {
    display: flex;
    gap: 4px;
    background: var(--surface-3);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.tab-toggle-btn {
    background: transparent;
    border: none;
    padding: 5px 12px;
    color: var(--text-lo);
    border-radius: var(--radius-xs);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--dur) var(--ease);
}

.tab-toggle-btn:hover {
    color: var(--text-hi);
}

.tab-toggle-btn.is-active {
    color: var(--accent-hi);
    background: var(--surface-1);
    box-shadow: var(--shadow-sm);
}

/* Quick templates ribbon */
.quick-template-ribbon {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.quick-template-ribbon .ribbon-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-lo);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.quick-template-ribbon .ribbon-actions {
    display: flex;
    gap: 8px;
}

/* Workspace Input Controls */
.workspace-input-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.paste-workspace-inner,
.file-workspace-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.input-settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.compact-field-stack {
    display: flex;
    align-items: center;
    gap: 8px;
}

.compact-field-stack .field-label {
    font-size: 11px;
    color: var(--text-lo);
    font-weight: 600;
    text-transform: uppercase;
}

.field-input.compact {
    padding: 3px 8px;
    font-size: 12px;
    min-width: 130px;
    height: 28px;
}

.workspace-tip {
    font-size: 10px;
    color: var(--accent-hi);
}

.textarea-editor-wrapper {
    flex: 1;
    min-height: 0;
    position: relative;
    margin-bottom: 8px;
}

.rich-monospace-textarea {
    width: 100%;
    height: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-hi);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 10px;
    resize: none;
    line-height: 1.5;
    outline: none;
    transition: border var(--dur) var(--ease);
}

.rich-monospace-textarea:focus {
    border-color: var(--accent);
}

.workspace-submit-row {
    flex-shrink: 0;
}

.large-btn {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 700;
    width: 100%;
}

/* Premium Upload File Dropzone */
.premium-dropzone-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    margin-bottom: 8px;
}

.premium-upload-dropzone {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 100%;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    padding: 24px;
    text-align: center;
    transition: all var(--dur) var(--ease);
}

.premium-upload-dropzone:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.premium-upload-dropzone input {
    display: none;
}

.dropzone-icon {
    background: var(--surface-3);
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 4px;
    box-shadow: var(--shadow-sm);
}

.premium-upload-dropzone strong {
    font-size: 13px;
    color: var(--text-hi);
}

.premium-upload-dropzone span {
    font-size: 10px;
    color: var(--text-lo);
}

/* Pipeline Monitoring Styles */
.monitor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.monitor-header h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-hi);
    margin: 0;
}

.badge-tag {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-lo);
    padding: 1px 6px;
    border-radius: 999px;
}

.monitor-panes-stack {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 12px;
}

.monitor-jobs-section {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    padding: 8px;
}

.monitor-jobs-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.monitor-job-card {
    padding: 10px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.monitor-job-card:hover {
    border-color: var(--border-mid);
}

.monitor-job-card.is-active {
    border-color: var(--accent);
    box-shadow: var(--accent-glow);
    background: rgba(99, 102, 241, 0.04);
}

.monitor-job-card.is-processing {
    border-color: var(--info);
}

.job-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.job-source-tag {
    display: flex;
    align-items: center;
    gap: 6px;
}

.source-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.job-source-tag strong {
    font-size: 10px;
    color: var(--text-hi);
    letter-spacing: 0.02em;
}

.job-status-pill {
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    text-transform: uppercase;
}

.job-status-pill.status-completed {
    background: var(--ok-soft);
    color: var(--ok-hi);
}

.job-status-pill.status-completed_with_errors {
    background: var(--warn-soft);
    color: var(--warn-hi);
}

.job-status-pill.status-failed {
    background: var(--err-soft);
    color: var(--err-hi);
}

.job-status-pill.status-processing {
    background: var(--info-soft);
    color: var(--info-hi);
}

.job-status-pill.status-queued {
    background: var(--surface-4);
    color: var(--text-lo);
}

.job-title-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.job-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-hi);
    margin: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    max-width: 180px;
}

.job-time {
    font-size: 9px;
    color: var(--text-lo);
}

.job-progress-container {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: var(--text-lo);
}

.progress-bar-track {
    height: 4px;
    background: var(--surface-4);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hi));
    border-radius: 999px;
    transition: width 0.4s var(--ease);
}

.progress-bar-fill.is-animated {
    background-size: 30px 30px;
    background-image: linear-gradient(135deg, rgba(255,255,255,0.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.15) 50%, rgba(255,255,255,0.15) 75%, transparent 75%, transparent);
    animation: progress-bar-stripes 1s linear infinite;
}

@keyframes progress-bar-stripes {
    from { background-position: 0 0; }
    to { background-position: 30px 0; }
}

.job-actions-row {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* Detail Inspection Section */
.monitor-details-section {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.monitor-job-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
}

.detail-report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

.detail-report-header h4 {
    margin: 0;
    font-size: 12px;
    color: var(--text-hi);
}

.job-uuid {
    font-size: 9px;
    color: var(--text-lo);
    background: var(--surface-3);
    padding: 1px 4px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
}

.detail-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.metric-card {
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 1px;
    text-align: center;
    border: 1px solid var(--border);
}

.metric-card span {
    font-size: 9px;
    color: var(--text-lo);
    font-weight: 600;
    text-transform: uppercase;
}

.metric-card strong {
    font-size: 13px;
}

.metric-card.info {
    background: var(--surface-3);
    color: var(--text-hi);
}

.metric-card.success {
    background: rgba(16, 185, 129, 0.03);
    border-color: rgba(16, 185, 129, 0.15);
    color: var(--ok-hi);
}

.metric-card.danger {
    background: rgba(239, 68, 68, 0.03);
    border-color: rgba(239, 68, 68, 0.15);
    color: var(--err-hi);
}

.detail-console-log {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-console-log h5 {
    margin: 2px 0 0 0;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-lo);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.console-empty-log {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-3);
    border: 1px dashed var(--border);
    border-radius: var(--radius-xs);
    font-size: 11px;
    color: var(--ok-hi);
    padding: 12px;
    text-align: center;
}

.console-error-records {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #08090c;
    border: 1px solid #14151a;
    border-radius: var(--radius-xs);
    padding: 8px;
    font-family: var(--font-mono);
}

.console-error-item {
    border-bottom: 1px solid #14151a;
    padding-bottom: 6px;
    margin-bottom: 4px;
}

.console-error-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.error-item-header {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    font-weight: 700;
    color: #ef4444;
    margin-bottom: 2px;
}

.error-message-box {
    font-size: 10px;
    color: #cbd5e1;
    line-height: 1.4;
    word-break: break-word;
}

.error-code-snippet {
    margin-top: 4px;
    background: #111216;
    border-left: 2px solid #ef4444;
    padding: 4px 6px;
    border-radius: 0 4px 4px 0;
    overflow-x: auto;
}

.error-code-snippet pre {
    margin: 0;
    padding: 0;
}

.error-code-snippet code {
    font-size: 9px;
    color: #fca5a5;
    white-space: pre-wrap;
}

/* ── RESIZE HANDLE ── */
.resize-handle.vertical {
    width: 8px; cursor: col-resize;
    flex-shrink: 0; position: relative;
}
.resize-handle.vertical::after {
    content: '';
    position: absolute;
    top: 40px; bottom: 40px; left: 50%;
    width: 2px; transform: translateX(-50%);
    background: var(--border-mid);
    border-radius: 999px;
    transition: background var(--dur) var(--ease);
}
.resize-handle.vertical:hover::after { background: var(--accent); }

/* ── EMPTY STATE ── */
.empty-state {
    min-height: 180px;
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    gap: 6px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    text-align: center; padding: 20px;
}
.empty-state h3 { font-size: 14px; color: var(--text); font-weight: 600; }
.empty-state p  { font-size: 12px; color: var(--text-lo); max-width: 300px; }
.empty-state.compact { min-height: 100px; }
.empty-state.side { min-height: 100%; }

/* ── TOAST ── */
.toast-stack {
    position: fixed; right: 16px; bottom: 16px;
    display: flex; flex-direction: column; gap: 10px;
    z-index: 60; max-width: 340px;
}

.toast-card {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-mid);
    background: var(--surface);
    animation: toast-in 0.25s var(--ease) both;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.toast-card > span { display: block; margin-bottom: 8px; font-size: 13px; color: var(--text); }
.toast-success { border-color: rgba(52, 211, 153, 0.4); }
.toast-warning { border-color: rgba(251, 191, 36, 0.4); }
.toast-danger  { border-color: rgba(248, 113, 113, 0.4); }

.toast-actions { display: flex; gap: 10px; }
.toast-link,
.toast-close {
    background: transparent; border: 0; padding: 0;
    font-weight: 700; font-size: 12px;
    transition: color var(--dur) var(--ease);
}
.toast-link { color: var(--accent-hi); }
.toast-link:hover { color: var(--accent); }
.toast-close { color: var(--text-lo); }
.toast-close:hover { color: var(--text); }
.toast-danger .toast-link { color: var(--err); }

/* ── MODAL ── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(5, 8, 18, 0.65);
    backdrop-filter: blur(12px);
    display: flex; align-items: center; justify-content: center;
    padding: 24px; z-index: 70;
    animation: fade-in 0.15s var(--ease) both;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
    width: min(100%, 480px);
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 24px;
    display: flex; flex-direction: column; gap: 16px;
    animation: modal-in 0.2s var(--ease) both;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Mobile sheet animation */
@keyframes modal-slide-up {
    from { opacity: 0; transform: translateY(60px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-card h3 { font-size: 17px; font-weight: 700; color: var(--text-hi); }
.modal-card p { font-size: 13px; color: var(--text-lo); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── SPLIT LIBRARY WORKSPACE ── */
.library-workspace {
    display: flex;
    gap: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.workspace-tree-pane {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    flex-shrink: 0;
}

/* ── BOOK HEADER CARD ── */
.tree-book-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background:
        radial-gradient(ellipse at 0% 0%, rgba(99, 102, 241, 0.06) 0%, transparent 60%),
        var(--surface);
}

.tree-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-lo);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: color var(--dur) var(--ease);
    align-self: flex-start;
}
.tree-back-btn:hover { color: var(--accent-hi); }
.tree-back-btn svg { flex-shrink: 0; }

.tree-book-identity {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.tree-book-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--accent-lo));
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.tree-book-meta {
    min-width: 0;
    flex: 1;
}

.tree-book-meta h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-hi);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-book-meta span {
    font-size: 11px;
    color: var(--text-lo);
    display: block;
    margin-top: 2px;
}

.tree-book-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tree-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.tree-badge.exam {
    background: var(--accent-soft);
    color: var(--accent-hi);
}

.tree-badge.count {
    background: var(--surface-3);
    color: var(--text-lo);
    border: 1px solid var(--border);
}

.tree-manage-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 7px 12px;
    border: 1px dashed var(--border-mid);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-lo);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}
.tree-manage-btn:hover {
    border-color: var(--accent);
    color: var(--accent-hi);
    background: var(--accent-soft);
}
.tree-manage-btn svg { flex-shrink: 0; opacity: 0.7; }
.tree-manage-btn:hover svg { opacity: 1; }

/* ── TREE SCROLLABLE CONTENT ── */
.workspace-tree-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px 8px 10px 10px;
}

.tree-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 40px 16px;
    text-align: center;
    color: var(--text-lo);
}
.tree-empty span { font-size: 13px; font-weight: 600; }
.tree-empty .sub { font-size: 11px; font-weight: 400; color: var(--text-xlo); }
.tree-empty .sub strong { color: var(--text-lo); }

.workspace-detail-pane {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding-left: 12px;
}

/* ── NAV TREE ── */
.nav-tree {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-chapter-node {
    display: flex;
    flex-direction: column;
}

/* ── CHAPTER ROW ── */
.nav-chapter-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
    border: 1px solid transparent;
    user-select: none;
    position: relative;
}

.nav-chapter-header:hover {
    background: var(--surface-2);
}

.nav-chapter-header.is-selected {
    background: var(--accent-soft);
    border-color: rgba(99, 102, 241, 0.25);
}

.nav-chapter-header.is-expanded:not(.is-selected) {
    background: var(--surface-2);
    border-color: var(--border);
}

/* Chapter Number Pill */
.ch-index {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-lo);
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    transition: all var(--dur) var(--ease);
}

.nav-chapter-header.is-selected .ch-index {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 1px 6px rgba(99, 102, 241, 0.4);
}

.nav-chapter-header.is-expanded .ch-index {
    background: var(--surface-4);
    color: var(--text);
}

/* SVG Chevron */
.chevron-icon {
    flex-shrink: 0;
    color: var(--text-xlo);
    transition: transform 0.22s var(--ease), color 0.15s var(--ease);
}

.chevron-icon.expanded {
    transform: rotate(90deg);
}

.nav-chapter-header:hover .chevron-icon { color: var(--text-lo); }
.nav-chapter-header.is-selected .chevron-icon { color: var(--accent-hi); }

/* Chapter Title */
.nav-chapter-header .node-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    transition: color var(--dur) var(--ease);
}

.nav-chapter-header:hover .node-title { color: var(--text-hi); }
.nav-chapter-header.is-selected .node-title { color: var(--accent-hi); font-weight: 700; }

/* Chapter Question Count Badge */
.ch-q-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--surface-4);
    color: var(--text-lo);
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
    transition: all var(--dur) var(--ease);
}

.nav-chapter-header:hover .ch-q-badge { background: var(--surface-3); color: var(--text); }
.nav-chapter-header.is-selected .ch-q-badge { background: rgba(99, 102, 241, 0.22); color: var(--accent-hi); }

/* ── SECTIONS LIST ── */
.nav-sections-list {
    margin-left: 21px;
    padding-left: 12px;
    border-left: 2px solid var(--border);
    margin-top: 2px;
    margin-bottom: 6px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}

/* Expansion animation */
.tree-expand-enter-active {
    animation: treeSlideDown 0.22s var(--ease) both;
}
.tree-expand-leave-active {
    animation: treeSlideDown 0.18s var(--ease) reverse both;
}
@keyframes treeSlideDown {
    from { max-height: 0; opacity: 0; }
    to   { max-height: 600px; opacity: 1; }
}

/* ── SECTION ROW ── */
.nav-section-node {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
    user-select: none;
    position: relative;
}

.nav-section-node:hover {
    background: var(--surface-2);
}

.nav-section-node.is-selected {
    background: var(--accent-soft);
}

/* Connection Dot */
.sec-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--surface-4);
    flex-shrink: 0;
    transition: all var(--dur) var(--ease);
    border: 1.5px solid var(--border-mid);
}

.nav-section-node:hover .sec-dot {
    background: var(--text-lo);
    border-color: var(--text-lo);
}

.nav-section-node.is-selected .sec-dot {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 6px rgba(99, 102, 241, 0.5);
}

/* Section Title */
.nav-section-node .node-title {
    font-weight: 500;
    font-size: 12px;
    color: var(--text-lo);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    transition: color var(--dur) var(--ease);
}

.nav-section-node:hover .node-title { color: var(--text); }
.nav-section-node.is-selected .node-title { color: var(--accent-hi); font-weight: 600; }

/* Section Question Count */
.sec-q-count {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-xlo);
    flex-shrink: 0;
    transition: color var(--dur) var(--ease);
}

.nav-section-node:hover .sec-q-count { color: var(--text-lo); }
.nav-section-node.is-selected .sec-q-count { color: var(--accent-hi); }

/* ── DETAIL CARD ── */
.detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--border);
    padding-bottom: 18px;
}

.detail-tag {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    color: var(--accent-hi);
    background: var(--accent-soft);
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.detail-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-hi);
    line-height: 1.3;
}

.breadcrumbs {
    font-size: 11px;
    color: var(--text-lo);
    margin-top: 4px;
}

.detail-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.detail-actions button {
    flex: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.stat-box {
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-box span {
    font-size: 10px;
    color: var(--text-lo);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-box strong {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-hi);
}

.stat-box .text-ok { color: var(--ok); }
.stat-box .text-err { color: var(--err); }
.stat-box .text-info { color: var(--info); }
.stat-box .text-accent { color: var(--accent-hi); }

.chapter-sections-details {
    margin-top: 8px;
}

.chapter-sections-details h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-hi);
    margin-bottom: 12px;
}

.detail-section-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

.detail-section-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}

.detail-section-row:hover {
    background: var(--surface-3);
    border-color: var(--border-mid);
}

.detail-section-row span {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.detail-section-row .muted {
    font-size: 11px;
    color: var(--text-lo);
}

/* ── SPREADSHEET TAXONOMY EDITOR MODAL ── */
.spreadsheet-modal .modal-card.large-card {
    width: min(100%, 920px);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.spreadsheet-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.spreadsheet-modal .modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-hi);
}

.spreadsheet-modal .modal-header p {
    font-size: 12px;
    color: var(--text-lo);
    margin-top: 4px;
}

.spreadsheet-body {
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.spreadsheet-instructions {
    background: var(--accent-soft);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 12px;
    line-height: 1.5;
}

.spreadsheet-instructions strong {
    color: var(--accent-hi);
}

.spreadsheet-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ch-row-group {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ch-row, .sec-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.row-drag-handle {
    font-size: 14px;
    color: var(--text-xlo);
    user-select: none;
    width: 20px;
    text-align: center;
}

.row-drag-handle.indent {
    color: var(--text-xlo);
    font-weight: bold;
}

.row-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-lo);
    width: 90px;
    flex-shrink: 0;
}

.row-label.indent {
    width: 100px;
}

.spreadsheet-input {
    flex: 1;
    background: var(--surface-3);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-sm);
    color: var(--text-hi);
    padding: 8px 12px;
    font-size: 13px;
    transition: all var(--dur) var(--ease);
}

.spreadsheet-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface-4);
    box-shadow: var(--accent-glow);
}

.ch-input {
    font-weight: 600;
}

.sec-input {
    font-weight: 500;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.row-actions .icon-button {
    font-size: 11px;
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-lo);
}

.row-actions .icon-button:hover:not(:disabled) {
    background: var(--surface-4);
    color: var(--text);
}

.row-actions .icon-button.danger {
    color: var(--err);
    border-color: rgba(248, 113, 113, 0.2);
}

.row-actions .icon-button.danger:hover {
    background: var(--err-soft);
}

.sec-rows-container {
    margin-left: 20px;
    padding-left: 14px;
    border-left: 2px dashed var(--border-mid);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sec-add-row {
    margin-top: 4px;
    padding-left: 30px;
}

.ch-add-row {
    display: flex;
    justify-content: center;
    margin-top: 8px;
    padding: 12px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
}

.ch-add-row button {
    width: 200px;
}

/* ── DELETE WARNING MODAL ── */
.warning-modal .modal-card {
    width: min(100%, 520px);
}

.modal-header.warning h3 {
    color: var(--warn);
}

.warning-stats {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin: 12px 0;
}

.warning-stats li {
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.warning-stats li:last-child {
    border-bottom: none;
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE & MOBILE SYSTEM
   ══════════════════════════════════════════════════════ */

/* ── TABLET (1200px and below) ── */
@media (max-width: 1200px) {
    .library-view,
    .library-workspace,
    .curate-layout { flex-direction: column; }

    .workspace-tree-pane,
    .workspace-detail-pane {
        width: 100% !important;
        padding: 0 !important;
        height: auto !important;
        max-height: none !important;
    }
    .workspace-detail-pane { margin-top: 16px; }

    .resize-handle.vertical { display: none; }

    .library-side,
    .question-index-panel,
    .editor-panel { width: 100% !important; min-height: auto; }

    .question-preview-panel,
    .jobs-panel { min-height: auto; }

    .curate-layout > .question-index-panel,
    .curate-layout > .question-preview-panel,
    .curate-layout > .editor-panel { border-radius: 0; border-top: 0; }
    .curate-layout > .question-index-panel { border-radius: 0; }
    .curate-layout > .editor-panel { border-radius: 0 0 var(--radius) var(--radius); }
}

/* ── LARGE MOBILE / SMALL TABLET (860px and below) ── */
@media (max-width: 860px) {
    /* Header restructure */
    .app-header {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        height: auto;
        padding: 10px 14px;
        gap: 8px;
    }
    .header-tabs {
        grid-column: 1 / -1;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .header-tabs::-webkit-scrollbar { display: none; }

    .analytics-summary,
    .editor-status-grid { grid-template-columns: repeat(2, 1fr); }

    .form-grid { grid-template-columns: 1fr; }

    .workspace-root { padding: 10px; }
    .curate-context-bar { flex-wrap: wrap; gap: 8px; }
    .context-path { width: 100%; order: -1; }
    .context-actions { width: 100%; }

    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
        gap: 10px;
    }
}

/* ── MOBILE (640px and below) ── */
@media (max-width: 640px) {
    /* ── Root Shell ── */
    :root { --header-h: 54px; }

    html, body { font-size: 14px; }

    /* Give the workspace breathing room above the mobile nav */
    .app-shell { padding-bottom: 64px; }

    /* ── Header ── */
    .app-header {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        height: var(--header-h);
        padding: 0 14px;
        gap: 0;
    }

    /* Hide the nav tabs in the header – we use mobile bottom nav instead */
    .header-tabs { display: none; }

    /* Compact brand */
    .brand-block { gap: 8px; }
    .brand-block h1 { font-size: 13px; }
    .brand-block p { display: none; }

    /* Compact session block */
    .session-block { gap: 8px; }
    .session-meta { text-align: right; }
    .session-meta strong { font-size: 12px; }

    /* Hide non-essential header buttons on mobile, keep Logout */
    .session-block .ghost-button.small[data-hide-mobile] { display: none; }

    /* ── Workspace ── */
    .workspace-root {
        padding: 8px;
        padding-bottom: 0;
    }

    /* ── Library View ── */
    .library-view { overflow-y: auto; }

    .library-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 14px;
    }
    .library-toolbar .toolbar-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .subject-filter-row {
        gap: 6px;
        margin-bottom: 14px;
    }
    .filter-pill { padding: 5px 11px; font-size: 11px; }

    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
    }
    .book-card { padding: 12px; }
    .book-card h3 { font-size: 13px; }
    /* Always show book actions on mobile (no hover) */
    .book-card-actions { opacity: 1; }

    /* ── Library Workspace (split pane) ── */
    .library-workspace {
        flex-direction: column;
        overflow: visible;
        height: auto;
    }
    .workspace-tree-pane {
        width: 100% !important;
        height: auto !important;
        max-height: 45vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    .workspace-tree-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .workspace-detail-pane {
        width: 100% !important;
        padding-left: 0 !important;
        margin-top: 10px;
    }

    /* Detail card mobile */
    .detail-card { padding: 16px; gap: 14px; }
    .detail-header h2 { font-size: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-box { padding: 12px; }
    .stat-box strong { font-size: 18px; }

    .detail-actions { flex-direction: column; }
    .detail-actions button { width: 100%; }

    /* ── Curate View ── */
    /* Curate-view viewport-bound on mobile, swapping active tabs */
    .curate-view {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .curate-context-bar {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 10px;
        padding: 10px 12px;
        flex-shrink: 0;
    }

    /* Library button (first child) */
    .curate-context-bar > .ghost-button.small {
        grid-column: 1;
        grid-row: 1;
        justify-self: start;
    }

    /* Save actions (third child) */
    .curate-context-bar > .context-actions {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    /* Select path dropdowns (second child) */
    .curate-context-bar > .context-path {
        grid-column: 1 / -1;
        grid-row: 2;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 4px;
        width: 100%;
    }

    .context-select {
        flex: 1;
        min-width: 80px;
        max-width: none;
        font-size: 11px;
        padding: 5px 8px;
    }

    .context-sep {
        font-size: 14px;
        margin: 0 2px;
    }

    /* Globally hide desktop elements on mobile */
    [data-hide-mobile] {
        display: none !important;
    }

    /* Mobile Curate View Panel Selector Tabs */
    .mobile-curate-tabs {
        display: flex;
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        margin: 0 8px 8px 8px;
        flex-shrink: 0;
        overflow: hidden;
    }

    .mobile-curate-tab {
        flex: 1;
        padding: 10px 8px;
        border: none;
        background: transparent;
        color: var(--text-lo);
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        border-bottom: 2px solid transparent;
        transition: all var(--dur) var(--ease);
        text-align: center;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-curate-tab:hover { color: var(--text); }
    .mobile-curate-tab.is-active {
        color: var(--accent);
        border-bottom-color: var(--accent);
        background: var(--accent-soft);
    }

    /* Curate layout: flex column, viewport-locked */
    .curate-layout {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    /* Hide resize handles on mobile */
    .resize-handle {
        display: none !important;
    }

    /* On mobile, all curate panels are hidden by default; data-active-tab displays the active one */
    .curate-layout > .question-index-panel,
    .curate-layout > .question-preview-panel,
    .curate-layout > .editor-panel {
        display: none !important;
        width: 100% !important;
        height: 100% !important;
        max-height: none !important;
        flex: 1 !important;
        min-height: 0 !important;
        border-radius: var(--radius-sm) !important;
        border-top: 1px solid var(--border) !important;
    }

    /* Display active panel as flex column with internal scrolling */
    .curate-view[data-active-tab="index"] .curate-layout > .question-index-panel {
        display: flex !important;
        flex-direction: column !important;
    }
    .curate-view[data-active-tab="preview"] .curate-layout > .question-preview-panel {
        display: flex !important;
        flex-direction: column !important;
    }
    .curate-view[data-active-tab="editor"] .curate-layout > .editor-panel {
        display: flex !important;
        flex-direction: column !important;
    }

    /* Question index: list scrolls internally */
    .question-index-panel {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Preview panel: list/grid container scrolls internally */
    .question-preview-panel {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Editor panel */
    .editor-panel {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Toolbar compact */
    .curate-toolbar, .library-toolbar {
        flex-wrap: wrap;
    }
    .curate-toolbar h2 { font-size: 15px; }
    .toolbar-actions { gap: 6px; }
    .toolbar-actions .ghost-button.small { padding: 6px 10px; }

    /* Maximize viewport area for questions on mobile by collapsing redundant header titles */
    .question-index-panel > .panel-header > div,
    .question-preview-panel > .panel-header > div,
    .editor-panel-content > .panel-header > div {
        display: none !important;
    }

    .question-index-panel > .panel-header,
    .question-preview-panel > .panel-header,
    .editor-panel-content > .panel-header {
        margin-bottom: 6px !important;
        padding-bottom: 0 !important;
        border-bottom: none !important;
        gap: 8px !important;
    }

    /* Stretch layout controls full width on mobile */
    .preview-controls {
        width: 100%;
        display: flex;
        gap: 8px !important;
        margin-top: 2px;
        flex-wrap: nowrap !important;
    }
    .preview-controls .control-group {
        flex: 1;
        justify-content: center;
    }
    .preview-controls .control-btn {
        flex: 1;
        justify-content: center;
        padding: 5px 8px;
        font-size: 11px;
    }

    /* Preview grid → 1 col on mobile */
    .preview-container.preview-layout-grid {
        grid-template-columns: 1fr;
    }

    /* Question index items */
    .question-index-item { padding: 10px; }
    .question-index-copy strong { font-size: 12px; }

    /* Form grid */
    .form-grid { grid-template-columns: 1fr; }
    .editor-status-grid { grid-template-columns: repeat(2, 1fr); }

    /* Analytics */
    .analytics-summary { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .summary-card strong { font-size: 16px; }

    /* ── Ingest View ── */
    .ingest-view { gap: 8px; }

    .ingest-workspace-body {
        flex-direction: column;
        overflow: visible;
        height: auto;
    }
    .ingest-workspace-input,
    .ingest-workspace-monitor {
        width: 100% !important;
        height: auto;
        min-height: auto;
        max-height: none;
    }
    .ingest-workspace-input { min-height: 380px; }
    .ingest-workspace-monitor { min-height: 320px; }

    /* Quick template ribbon mobile */
    .quick-template-ribbon { flex-wrap: wrap; gap: 6px; }
    .quick-template-ribbon .ribbon-actions { flex-wrap: wrap; gap: 6px; }

    /* Input settings row */
    .input-settings-row { flex-direction: column; align-items: flex-start; gap: 8px; }

    /* Pipeline stepper – condense on mobile */
    .pipeline-stepper { padding: 8px 10px; gap: 4px; }
    .step-text { display: none; }
    .step-icon { width: 18px; height: 18px; font-size: 9px; }

    /* Terminal */
    .retro-terminal { min-height: 140px; max-height: 220px; }
    .retro-terminal .terminal-body { font-size: 10px; }

    /* ── Toast mobile ── */
    .toast-stack {
        left: 12px;
        right: 12px;
        bottom: 76px; /* above mobile nav */
        max-width: none;
    }

    /* ── Modal mobile ── */
    .modal-backdrop {
        padding: 16px;
        align-items: flex-end; /* slide up from bottom */
    }
    .modal-card {
        width: 100% !important;
        max-width: none;
        border-radius: 20px 20px 0 0;
        max-height: 90vh;
        overflow-y: auto;
        animation: modal-slide-up 0.25s var(--ease) both;
    }



    /* Large modal */
    .spreadsheet-modal .modal-card.large-card {
        width: 100% !important;
        max-height: 95vh;
        border-radius: 20px 20px 0 0;
    }

    /* ── Buttons touch targets ── */
    .ghost-button,
    .primary-button,
    .danger-button {
        min-height: 38px;
        padding: 8px 14px;
    }
    .ghost-button.small { min-height: 34px; padding: 6px 10px; }
    .ghost-button.tiny  { min-height: 28px; }

    .header-tab {
        padding: 8px 14px;
        min-height: 36px;
    }

    .filter-pill {
        min-height: 32px;
        padding: 6px 12px;
    }

    .tree-section-item { padding: 10px; min-height: 42px; }
    .nav-chapter-header { padding: 10px 12px; min-height: 44px; }
    .nav-section-node { padding: 10px 12px; min-height: 40px; }

    /* ── User table mobile: hide columns ── */
    .user-table th:nth-child(3),
    .user-table td:nth-child(3) { display: none; }

    /* ── Detail section list ── */
    .detail-section-list { max-height: 260px; }

    /* ── Code editor ── */
    .CodeMirror { height: 220px; font-size: 12px; }
    .editor-surface { min-height: 220px; }
}

/* ── SMALL PHONES (480px and below) ── */
@media (max-width: 480px) {
    .book-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .book-card h3 { font-size: 12px; }

    .stats-grid { grid-template-columns: 1fr 1fr; }
    .analytics-summary { grid-template-columns: repeat(2, 1fr); }

    .detail-header h2 { font-size: 15px; }

    .context-path { flex-wrap: wrap; }
    .context-select { max-width: 100%; width: 100%; }

    .modal-card { padding: 18px; }
    .modal-card h3 { font-size: 15px; }

    .detail-metrics-grid { grid-template-columns: repeat(2, 1fr); }

    .session-meta strong { font-size: 11px; }
    .role-badge { font-size: 9px; padding: 1px 4px; }
}

/* ══════════════════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION BAR
   ══════════════════════════════════════════════════════ */

.mobile-bottom-nav {
    display: none; /* shown only on mobile */
}

@media (max-width: 640px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 40;
        background: rgba(16, 19, 31, 0.97);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--border-mid);
        padding: 0 env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
        height: calc(64px + env(safe-area-inset-bottom, 0px));
        align-items: stretch;
        justify-content: space-around;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.45);
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border: none;
        background: transparent;
        color: var(--text-xlo);
        font-size: 10px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        padding: 8px 4px;
        cursor: pointer;
        transition: color var(--dur) var(--ease);
        position: relative;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-nav-btn svg {
        width: 20px;
        height: 20px;
        stroke-width: 1.8;
        flex-shrink: 0;
    }

    .mobile-nav-btn:hover,
    .mobile-nav-btn.is-active {
        color: var(--accent-hi);
    }

    /* Active indicator dot */
    .mobile-nav-btn.is-active::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--accent);
    }

    .mobile-nav-btn.is-active svg {
        filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.6));
    }

    .mobile-nav-btn:disabled {
        opacity: 0.28;
        cursor: not-allowed;
    }
}

/* ══════════════════════════════════════════════════════
   MOBILE TREE DRAWER (slides in from left)
   ══════════════════════════════════════════════════════ */

.mobile-drawer-overlay,
.mobile-tree-drawer {
    display: none;
}

@media (max-width: 640px) {
    /* Drawer overlay backdrop */
    .mobile-drawer-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 50;
        background: rgba(5, 8, 18, 0.7);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s var(--ease);
    }
    .mobile-drawer-overlay.is-open {
        opacity: 1;
        pointer-events: auto;
    }

    /* The drawer panel */
    .mobile-tree-drawer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(88vw, 340px);
        z-index: 55;
        background: var(--surface);
        border-right: 1px solid var(--border-mid);
        box-shadow: 4px 0 32px rgba(0, 0, 0, 0.6);
        display: flex;
        flex-direction: column;
        transform: translateX(-100%);
        transition: transform 0.28s var(--ease);
        overflow: hidden;
    }
    .mobile-tree-drawer.is-open {
        transform: translateX(0);
    }

    /* Drawer header */
    .mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
        background: var(--surface-2);
    }
    .mobile-drawer-header h4 {
        font-size: 13px;
        font-weight: 700;
        color: var(--text-hi);
        margin: 0;
    }
    .mobile-drawer-close {
        width: 30px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        background: var(--surface-3);
        border-radius: var(--radius-xs);
        color: var(--text-lo);
        cursor: pointer;
        transition: all var(--dur) var(--ease);
    }
    .mobile-drawer-close:hover { background: var(--surface-4); color: var(--text); }

    /* Drawer content area */
    .mobile-drawer-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px 8px;
    }
}

/* ══════════════════════════════════════════════════════
   MOBILE HAMBURGER / CONTEXT TRIGGER (header)
   ══════════════════════════════════════════════════════ */

.mobile-menu-trigger {
    display: none;
}

@media (max-width: 640px) {
    .mobile-menu-trigger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: 1px solid var(--border-mid);
        border-radius: var(--radius-sm);
        background: var(--surface-2);
        color: var(--text);
        cursor: pointer;
        transition: all var(--dur) var(--ease);
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-menu-trigger:hover { background: var(--surface-3); }
    .mobile-menu-trigger svg { width: 18px; height: 18px; }
}

/* ══════════════════════════════════════════════════════
   MOBILE CURATE: QUESTION PANEL TABS
   Sheet-style switcher replacing the side-by-side layout
   ══════════════════════════════════════════════════════ */

/* (mobile-curate-tabs removed — pure CSS tab switching
   is replaced by simple vertical stacking of all panels) */

/* ══════════════════════════════════════════════════════
   PULL-TO-REFRESH INDICATOR (visual affordance)
   ══════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .workspace-root {
        overscroll-behavior-y: contain;
    }
}

/* ══════════════════════════════════════════════════════
   TOUCH IMPROVEMENTS
   ══════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
    /* Always show action buttons (no hover on touch) */
    .book-card-actions { opacity: 1 !important; }
    .section-nav-actions { opacity: 1 !important; }
    .tree-card-actions { opacity: 1 !important; }

    /* Increase tap target sizes */
    .icon-button {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .filter-pill { min-height: 34px; }
    .tab-toggle-btn { min-height: 36px; }
    .control-btn { min-height: 32px; padding: 6px 10px; }

    /* Scrollable lists: momentum scrolling */
    .preview-container,
    .question-index-list,
    .workspace-tree-content,
    .workspace-detail-pane,
    .curate-layout,
    .library-view {
        -webkit-overflow-scrolling: touch;
    }
}

/* Ingestion Jobs Monitor Controls */
.monitor-controls-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.search-box-wrapper {
    position: relative;
    flex: 1;
}

.search-icon {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-lo);
    pointer-events: none;
}

.compact-search-input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-hi);
    font-size: 11px;
    padding: 4px 8px 4px 26px;
    height: 28px;
    outline: none;
    transition: all var(--dur) var(--ease);
}

.compact-search-input:focus {
    border-color: var(--accent);
    background: var(--surface-3);
}

.compact-filter-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-hi);
    font-size: 11px;
    padding: 0 8px;
    height: 28px;
    outline: none;
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}

.compact-filter-select:focus {
    border-color: var(--accent);
}

/* Ingestion Pipeline Stepper */
.pipeline-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.step-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
}

.step-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface-3);
    border: 2px solid var(--border-strong);
    color: var(--text-lo);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    transition: all var(--dur) var(--ease);
}

.step-text {
    font-size: 9px;
    font-weight: 600;
    color: var(--text-lo);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.step-node.active .step-icon {
    border-color: var(--info);
    background: var(--info-soft);
    color: var(--info);
    box-shadow: 0 0 8px var(--info-soft);
}

.step-node.active .step-text {
    color: var(--info);
}

.step-node.completed .step-icon {
    border-color: var(--ok);
    background: var(--ok-soft);
    color: var(--ok);
}

.step-node.completed .step-text {
    color: var(--ok);
}

.step-node.failed .step-icon {
    border-color: var(--err);
    background: var(--err-soft);
    color: var(--err);
}

.step-node.failed .step-text {
    color: var(--err);
}

.step-node.cancelled .step-icon {
    border-color: var(--warn);
    background: var(--warn-soft);
    color: var(--warn);
}

.step-node.cancelled .step-text {
    color: var(--warn);
}

.step-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin: 0 8px;
    margin-bottom: 14px; /* Align with icon vertical center */
    transition: background var(--dur) var(--ease);
}

.step-connector.active {
    background: var(--accent);
}

/* Retro Log Terminal */
.retro-terminal {
    display: flex;
    flex-direction: column;
    background: #05060b;
    border: 1px solid #1f2438;
    border-radius: var(--radius-sm);
    flex: 1;
    min-height: 180px;
    max-height: 320px;
    overflow: hidden;
    margin-top: 10px;
}

.retro-terminal .terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0f121d;
    padding: 6px 12px;
    border-bottom: 1px solid #1f2438;
    flex-shrink: 0;
}

.retro-terminal .terminal-dots {
    display: flex;
    gap: 5px;
}

.retro-terminal .terminal-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.retro-terminal .terminal-dot.red { background: #ff5f56; }
.retro-terminal .terminal-dot.yellow { background: #ffbd2e; }
.retro-terminal .terminal-dot.green { background: #27c93f; }

.retro-terminal .terminal-title {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-lo);
}

.retro-terminal .terminal-copy-btn {
    background: transparent;
    border: none;
    color: var(--text-lo);
    font-size: 9px;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    transition: all var(--dur) var(--ease);
}

.retro-terminal .terminal-copy-btn:hover {
    color: var(--text-hi);
    background: var(--surface-4);
}

.retro-terminal .terminal-body {
    padding: 12px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    color: #a0a6b7;
    flex: 1;
    text-align: left;
}

.retro-terminal .terminal-row {
    margin-bottom: 6px;
}

.retro-terminal .terminal-row.cmd {
    color: #e2e8f0;
}

.retro-terminal .terminal-prompt {
    color: var(--accent-hi);
    font-weight: 700;
    margin-right: 6px;
}

.retro-terminal .success-row {
    color: var(--ok);
}

.retro-terminal .error-row {
    color: var(--err);
}

.retro-terminal .terminal-status-ok {
    color: var(--ok);
    display: block;
}

.retro-terminal .terminal-status-err {
    color: var(--err);
    display: block;
    font-weight: 700;
}

.retro-terminal .terminal-log-error-item {
    margin-top: 8px;
    padding-left: 10px;
    border-left: 2px solid var(--err);
}

.retro-terminal .terminal-tag-err {
    color: #f87171;
    font-weight: 700;
}

.retro-terminal .terminal-pre-snippet {
    background: #0d0e15;
    border: 1px solid #1a1b26;
    border-radius: var(--radius-xs);
    padding: 6px;
    margin-top: 4px;
    color: #cfd8f0;
    overflow-x: auto;
}

.retro-terminal .terminal-pre-snippet code {
    font-family: var(--font-mono);
    font-size: 10px;
}

/* ── USER MANAGEMENT STYLES ── */
.user-table {
    width: 100%;
    border-collapse: collapse;
}

.user-table th, 
.user-table td {
    padding: 12px 20px;
    vertical-align: middle;
}

.user-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.role-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: 0.05em;
}

.role-badge.admin {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}

.role-badge.editor {
    background: rgba(14, 165, 233, 0.15);
    color: #38bdf8;
}

.role-badge.reviewer {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.status-label {
    display: inline-block;
    font-size: 9px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 3px;
    letter-spacing: 0.06em;
}

.status-label.active {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.status-label.disabled {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.status-label.expired {
    background: rgba(220, 38, 38, 0.25);
    color: #fca5a5;
    border: 1px solid rgba(220, 38, 38, 0.4);
}

.user-mgmt-modal .modal-card.large-card {
    border: 1px solid var(--border-mid);
}

.user-table th {
    font-weight: 600;
    color: var(--text-lo);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.05em;
}

/* ─── Question Paper Generator Portal Styles ─── */
.generator-view {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    font-size: 9px;
    font-weight: 700;
    margin-left: 6px;
    vertical-align: middle;
}

/* Hide mobile tabs on desktop */
.mobile-curate-tabs {
    display: none !important;
}

/* ── Mobile Generator Rules (max-width: 640px) ── */
@media (max-width: 640px) {
    .mobile-curate-tabs {
        display: flex !important;
    }
    
    .generator-view[data-active-tab="selected"] .curate-layout > .question-index-panel {
        display: flex !important;
        flex-direction: column !important;
    }
    .generator-view[data-active-tab="settings"] .curate-layout > .question-preview-panel {
        display: flex !important;
        flex-direction: column !important;
    }
    .generator-view[data-active-tab="preview"] .curate-layout > .editor-panel {
        display: flex !important;
        flex-direction: column !important;
    }
}


