/**
 * Desmos-Grade Layout Architecture
 */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* 1. Desmos Top Bar */
.app-header {
    height: 44px;
    flex-shrink: 0;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    z-index: 20;
    color: var(--header-text);
    box-sizing: border-box;
    overflow: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.header-folder-btn {
    background: transparent;
    border: none;
    color: var(--header-text);
    font-size: 15px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.header-folder-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.graph-title-input {
    background: transparent;
    border: 1px solid transparent;
    outline: none;
    color: var(--header-text);
    font-size: 13px;
    font-weight: 500;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    width: 110px;
    transition: all 0.15s;
}

.graph-title-input:hover, .graph-title-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-save-pill {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--header-text);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-save-pill:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* Center Logo: Authentic Desmos Style */
.header-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.desmos-logo {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: #ffffff;
    user-select: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.desmos-logo span {
    color: #ffffff;
    opacity: 0.95;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-header {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-header:hover {
    background: rgba(255, 255, 255, 0.18);
}

.btn-header-admin {
    background: #7c3aed !important;
    border-color: #9333ea !important;
    color: #ffffff !important;
    font-weight: 700 !important;
}

.btn-header-admin:hover {
    background: #6d28d9 !important;
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #388c46;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

/* 2. Workspace Body */
.workspace-body {
    display: flex;
    flex: 1;
    height: calc(100vh - 44px);
    position: relative;
    overflow: hidden;
}

/* Sidebar Panel */
.sidebar-panel {
    width: 380px;
    min-width: 320px;
    max-width: 480px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-medium);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-panel.collapsed {
    transform: translateX(-100%);
    position: absolute;
}

.sidebar-top-bar {
    height: 38px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    background: var(--bg-surface);
}

.sidebar-top-left, .sidebar-top-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.tool-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Viewport Area */
.canvas-wrapper {
    flex: 1;
    position: relative;
    height: 100%;
    background: var(--bg-base);
    overflow: hidden;
}

#graphCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

/* Desmos Top-Right Viewport Controls (Wrench, +, -, Home) */
.viewport-controls {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    padding: 3px;
    box-shadow: var(--shadow-sm);
    z-index: 5;
}

.btn-icon {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.15s;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-icon:active {
    transform: scale(0.95);
}

.btn-icon.active-audio {
    background: #ec4899 !important;
    color: #ffffff !important;
    animation: audioPulse 1.2s infinite ease-in-out;
}

@keyframes audioPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.4); }
    50% { transform: scale(1.08); box-shadow: 0 0 0 6px rgba(236, 72, 153, 0); }
}

/* Desmos Bottom-Left Keypad Toggle Pill */
.keypad-toggle-btn {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    z-index: 5;
    transition: all 0.15s;
}

.keypad-toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Suite Modal (Image 1) */
.desmos-suite-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.45);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.desmos-suite-modal-backdrop.hidden-suite {
    display: none !important;
}

.suite-box {
    width: 620px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.suite-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.suite-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: #1d2939;
}

.suite-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 12px;
}

.suite-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    position: relative;
    padding: 8px 4px;
    border-radius: 6px;
    transition: background 0.15s;
}

.suite-item:hover {
    background: #f2f4f7;
}

.suite-item.active {
    background: rgba(45, 112, 179, 0.08);
}

.suite-icon-box {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
    transition: transform 0.15s, box-shadow 0.15s;
}

.suite-item:hover .suite-icon-box {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

.bg-graphing { background: linear-gradient(135deg, #22c55e 0%, #15803d 100%); }
.bg-scientific { background: linear-gradient(135deg, #14b8a6 0%, #0f766e 100%); }
.bg-fourfunction { background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%); }
.bg-notebook { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); }
.bg-matrix { background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%); }
.bg-geometry { background: linear-gradient(135deg, #a855f7 0%, #7e22ce 100%); }
.bg-3d { background: linear-gradient(135deg, #ec4899 0%, #be185d 100%); }
.bg-calculus { background: linear-gradient(135deg, #14b8a6 0%, #0f766e 100%); }
.bg-mathematica { background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%); }
.bg-matlab { background: linear-gradient(135deg, #f97316 0%, #c2410c 100%); }

.suite-math-icon {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
}

.suite-name {
    font-size: 11.5px;
    font-weight: 600;
    color: #344054;
    text-align: center;
}

.suite-beta-badge {
    position: absolute;
    top: -4px;
    right: 8px;
    font-size: 8.5px;
    font-weight: 800;
    background: #e0e7ff;
    color: #3730a3;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #c7d2fe;
}

/* Featured Card (Image 8 Exact Match) */
.suite-featured-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    gap: 20px;
    align-items: center;
}

.featured-preview {
    flex: 0 0 170px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
}

.mini-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    font-weight: 600;
    color: #475467;
    margin-bottom: 4px;
}

.featured-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.featured-info h3 {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.featured-info p {
    font-size: 12.5px;
    color: #475467;
    margin: 0;
    line-height: 1.4;
}

.featured-btns {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

.btn-primary-suite {
    background: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary-suite:hover {
    background: #1d4ed8;
}

.btn-secondary-suite {
    background: #ffffff;
    color: #334155;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-secondary-suite:hover {
    background: #f1f5f9;
}

/* =========================================================
   WORKSTATION VIEW CARDS (SCIENTIFIC, FOUR FN, MATRIX, 3D, ETC)
   ========================================================= */

.workstation-container {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 20px 48px;
    background: #f8fafc;
    overflow-y: auto;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.workstation-container.hidden-workstation {
    display: none !important;
}

.tool-view-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    padding: 24px 28px;
    width: 100%;
    max-width: 960px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.tool-view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 14px;
}

.tool-view-header h2 {
    font-size: 19px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.btn-tool-back {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-tool-back:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.tool-active-tag {
    font-size: 11px;
    font-weight: 700;
    background: #0284c7;
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 3px;
    vertical-align: middle;
    margin: 0 4px;
}

/* Scientific Calculator Styles */
.scientific-workstation {
    max-width: 600px;
}

.sci-display-box {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: right;
}

.sci-expr-row {
    font-size: 20px;
    font-family: "Times New Roman", Times, serif;
    color: #1e293b;
    min-height: 28px;
}

.sci-result-row {
    font-size: 26px;
    font-weight: 700;
    color: #0284c7;
}

.sci-keypad-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.sci-btn {
    height: 44px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #f1f5f9;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: all 0.1s;
}

.sci-btn:hover { background: #e2e8f0; }
.sci-btn.num { background: #ffffff; font-size: 16px; font-weight: 700; }
.sci-btn.num:hover { background: #f8fafc; }
.sci-btn.op-enter { background: #0284c7; color: #ffffff; border-color: #0284c7; font-weight: 700; }
.sci-btn.op-enter:hover { background: #0369a1; }

/* Four Function Styles */
.four-function-workstation {
    max-width: 420px;
}

.four-display-box {
    background: #0f172a;
    color: #ffffff;
    border-radius: 8px;
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.four-history { font-size: 13px; color: #94a3b8; min-height: 18px; }
.four-current { font-size: 34px; font-weight: 700; font-family: -apple-system, sans-serif; }

.four-keypad-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.four-btn {
    height: 54px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    cursor: pointer;
    transition: all 0.1s;
}

.four-btn:hover { background: #f1f5f9; }
.four-btn.op-arith { background: #f8fafc; color: #0284c7; font-size: 20px; }
.four-btn.op-equals { background: #0284c7; color: #ffffff; border-color: #0284c7; }
.four-btn.op-equals:hover { background: #0369a1; }

/* Matrix Styles */
.matrix-setup-row {
    display: flex;
    gap: 20px;
}

.matrix-box {
    flex: 1;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.matrix-box-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.matrix-dim-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11.5px;
    color: #475467;
}

.btn-dim {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    cursor: pointer;
}

.matrix-grid-cells {
    display: grid;
    gap: 6px;
    margin: 8px 0;
}

.matrix-cell-input {
    height: 38px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    outline: none;
    background: #ffffff;
}

.matrix-cell-input:focus { border-color: #2563eb; }

.matrix-actions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn-matrix-op {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    font-size: 13px;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-matrix-op:hover { background: #2563eb; color: #ffffff; border-color: #2563eb; }

.matrix-result-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
}

.mat-bracket-box {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    border-left: 2px solid #0f172a;
    border-right: 2px solid #0f172a;
    padding: 2px 10px;
    margin-left: 10px;
}

.mat-row { display: flex; gap: 14px; }
.mat-cell { font-weight: 700; min-width: 24px; text-align: center; }

/* =========================================================
   CUSTOM SCREEN-BOUNDED DROPDOWNS (ZERO VIEWPORT BLEED)
   ========================================================= */

.custom-select-native-hidden {
    display: none !important;
}

.custom-select-container {
    position: relative;
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    user-select: none;
}

.custom-select-container.custom-select-sm {
    display: inline-block;
    width: auto;
    min-width: 140px;
    max-width: 100%;
}

.custom-select-container {
    min-width: 0;
    max-width: 100%;
}

.custom-select-trigger {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 14px;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
    box-sizing: border-box;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.15s ease;
    text-align: left;
    outline: none;
}

.custom-select-container.custom-select-sm .custom-select-trigger {
    padding: 6px 10px;
    font-size: 12px;
}

.custom-select-trigger:hover {
    border-color: #94a3b8;
    background-color: #f8fafc;
}

.custom-select-container.open .custom-select-trigger,
.custom-select-trigger:focus {
    border-color: #ec4899;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.18);
    background-color: #ffffff;
}

.custom-select-label {
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.custom-select-chevron {
    flex: 0 0 auto;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.custom-select-container.open .custom-select-chevron {
    transform: rotate(180deg);
    color: #ec4899;
}

.custom-select-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 12px 28px -4px rgba(0, 0, 0, 0.18), 0 8px 12px -6px rgba(0, 0, 0, 0.1);
    max-height: 250px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 9999;
    display: none;
    box-sizing: border-box;
    padding: 4px 0;
}

.custom-select-container.open .custom-select-menu {
    display: block;
    animation: customSelectFadeIn 0.12s ease-out;
}

@keyframes customSelectFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.custom-select-option {
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.12s, color 0.12s;
    display: flex;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.custom-select-option:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.custom-select-option.selected {
    background: #fdf2f8;
    color: #db2777;
    font-weight: 700;
}

.d3-custom-dropdown, .geom-select-preset, .nb-select-template {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #ffffff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px 14px;
    padding: 8px 36px 8px 12px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.15s ease;
    outline: none;
}

.d3-custom-dropdown:hover, .geom-select-preset:hover, .nb-select-template:hover {
    border-color: #94a3b8;
    background-color: #f8fafc;
}

.d3-custom-dropdown:focus, .geom-select-preset:focus, .nb-select-template:focus {
    border-color: #ec4899;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.15);
}

.geom-select-preset:focus {
    border-color: #9333ea;
    box-shadow: 0 0 0 3px rgba(147, 51, 234, 0.15);
}

.nb-select-template:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.d3-custom-dropdown option, .geom-select-preset option, .nb-select-template option {
    background: #ffffff;
    color: #0f172a;
    padding: 8px 12px;
    font-size: 13px;
}

/* =========================================================
   GEOMETRY WORKSTATION (FULL PRO EUCLIDEAN STUDIO)
   ========================================================= */

.geometry-workstation {
    max-width: 1040px;
}

.geom-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.geom-badge-pro {
    background: #9333ea;
    color: #ffffff;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    padding: 3px 8px;
    border-radius: 12px;
    text-transform: uppercase;
}

.geom-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.geometry-pro-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 12px;
}

.geom-tool-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.geom-tool-btn {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.geom-tool-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #0f172a;
}

.geom-tool-btn.active {
    background: #9333ea;
    color: #ffffff;
    border-color: #9333ea;
    box-shadow: 0 2px 6px rgba(147, 51, 234, 0.25);
}

.geom-tool-btn.btn-construct {
    background: #faf5ff;
    border-color: #e9d5ff;
    color: #7e22ce;
}

.geom-tool-btn.btn-construct:hover {
    background: #f3e8ff;
    border-color: #c084fc;
}

.geom-tool-btn.btn-construct.active {
    background: #7e22ce;
    color: #ffffff;
    border-color: #7e22ce;
}

.geom-toolbar-separator {
    width: 1px;
    height: 22px;
    background: #cbd5e1;
    margin: 0 4px;
}

.geom-action-btn {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #475569;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.geom-action-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.geom-action-btn.btn-clear-geom {
    color: #dc2626;
    border-color: #fecaca;
    background: #fff5f5;
}

.geom-action-btn.btn-clear-geom:hover {
    background: #dc2626;
    color: #ffffff;
    border-color: #dc2626;
}

.geom-inspector-hud {
    background: #0f172a;
    color: #f8fafc;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 12.5px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    min-height: 20px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.hud-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.hud-item .hud-label {
    color: #94a3b8;
    font-weight: 500;
}

.hud-item .hud-val {
    color: #38bdf8;
    font-weight: 700;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.hud-prompt {
    color: #cbd5e1;
}

.geometry-canvas-wrapper {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    width: 100%;
    height: 540px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

#geometryCanvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

/* =========================================================
   3D WORKSTATION (FULL PRO SUITE)
   ========================================================= */

.d3-workstation {
    max-width: 1040px;
}

.d3-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.d3-controls-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.d3-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 340px;
}

.d3-label-z {
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

.d3-input {
    flex: 1;
    min-width: 160px;
    height: 42px;
    min-height: 42px;
    max-height: 42px;
    box-sizing: border-box;
    padding: 0 14px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-family: "Times New Roman", Times, serif;
    font-size: 15px;
    background: #ffffff;
    color: #0f172a;
    outline: none;
    transition: all 0.15s ease;
}

.d3-input:focus {
    border-color: #ec4899;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.15);
}

.btn-d3-plot {
    background: #ec4899;
    color: #ffffff;
    border: none;
    font-size: 13px;
    font-weight: 700;
    padding: 9px 18px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
    box-shadow: 0 2px 6px rgba(236, 72, 153, 0.25);
}

.btn-d3-plot:hover {
    background: #db2777;
}

.d3-preset-wrapper {
    flex: 0 0 auto;
}

.d3-toolbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.d3-selectors-group {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.d3-tool-group {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: #475569;
}

.d3-select-sm {
    padding: 6px 28px 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 12px;
    color: #1e293b;
    background: #ffffff;
    cursor: pointer;
}

.d3-btn-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.d3-btn-action {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s;
}

.d3-btn-action:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.d3-btn-action.active {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
}

.d3-canvas-wrapper {
    background: #0b1120;
    border: 1px solid #1e293b;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    width: 100%;
    height: 540px;
    max-height: 65vh;
}

#d3Canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.d3-hint-overlay {
    position: absolute;
    bottom: 12px;
    right: 14px;
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    font-size: 11px;
    padding: 5px 12px;
    border-radius: 6px;
    pointer-events: none;
    backdrop-filter: blur(4px);
}

/* =========================================================
   NOTEBOOK WORKSTATION (FULL PRO MULTI-CELL LABS STUDIO)
   ========================================================= */

.notebook-workstation {
    max-width: 980px;
}

.nb-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nb-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.nb-action-btn {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.nb-action-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.notebook-content-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.notebook-doc-title {
    font-size: 24px;
    font-weight: 800;
    border: 1px solid transparent;
    padding: 4px 8px;
    border-radius: 6px;
    outline: none;
    width: 100%;
    color: #0f172a;
    transition: all 0.15s;
}

.notebook-doc-title:hover, .notebook-doc-title:focus {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.nb-doc-meta {
    font-size: 12px;
    color: #64748b;
    margin: -10px 0 10px 8px;
}

.notebook-blocks-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.notebook-cell {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.15s;
}

.notebook-cell:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.nb-cell-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
    margin-bottom: 10px;
}

.nb-cell-badge {
    font-size: 10.5px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}

.notebook-cell.cell-text .nb-cell-badge { background: #e0f2fe; color: #0284c7; }
.notebook-cell.cell-math .nb-cell-badge { background: #dcfce7; color: #16a34a; }
.notebook-cell.cell-graph .nb-cell-badge { background: #fef3c7; color: #d97706; }
.notebook-cell.cell-table .nb-cell-badge { background: #f3e8ff; color: #9333ea; }

.nb-cell-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nb-icon-btn {
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 12px;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    transition: all 0.1s;
}

.nb-icon-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.nb-icon-btn.btn-del:hover {
    background: #fee2e2;
    color: #dc2626;
}

.nb-text-editor {
    width: 100%;
    border: 1px solid transparent;
    padding: 8px;
    font-size: 14px;
    line-height: 1.5;
    color: #334155;
    outline: none;
    border-radius: 6px;
    font-family: inherit;
    resize: vertical;
    min-height: 50px;
    transition: all 0.15s;
}

.nb-text-editor:hover, .nb-text-editor:focus {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.nb-math-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.nb-math-prefix {
    font-family: "Times New Roman", Times, serif;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.nb-math-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    font-family: "Times New Roman", Times, serif;
    font-size: 15px;
    outline: none;
}

.nb-math-input:focus {
    border-color: #16a34a;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

.btn-nb-eval {
    background: #16a34a;
    color: #ffffff;
    border: none;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-nb-eval:hover {
    background: #15803d;
}

.btn-nb-steps {
    background: #f59e0b;
    color: #ffffff;
    border: none;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-nb-steps:hover {
    background: #d97706;
}

.nb-math-output {
    margin-top: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nb-output-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
}

.nb-output-result {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.nb-graph-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.nb-graph-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: "Times New Roman", Times, serif;
    font-size: 14px;
}

.nb-canvas-container {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    height: 240px;
    overflow: hidden;
}

.nb-graph-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.nb-table-layout {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.nb-data-table {
    border-collapse: collapse;
}

.nb-data-table th, .nb-data-table td {
    border: 1px solid #cbd5e1;
    padding: 4px 6px;
    text-align: center;
}

.nb-data-table th {
    background: #f8fafc;
    font-size: 12px;
    font-weight: 700;
    color: #475569;
}

.nb-tbl-input {
    width: 60px;
    padding: 4px;
    border: none;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
    outline: none;
}

.nb-tbl-input:focus {
    background: #f0fdf4;
}

.nb-table-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.btn-nb-tbl {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.nb-fit-info {
    flex: 1;
    min-width: 220px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nb-fit-line {
    font-size: 12px;
    font-weight: 700;
    color: #475569;
}

.nb-fit-eq {
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

.notebook-add-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 10px;
}

.btn-nb-add {
    background: #ffffff;
    border: 1.5px dashed #cbd5e1;
    color: #334155;
    font-size: 12.5px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-nb-add:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: #0f172a;
}

/* =========================================================
   100% COMPLETE MOBILE RESPONSIVENESS (< 768px)
   ========================================================= */

/* Persistent Desmos Unhide Sidebar Chevron Tab */
.sidebar-expand-tab {
    position: absolute;
    top: 10px;
    left: 0;
    z-index: 28;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-left: none;
    border-radius: 0 6px 6px 0;
    width: 28px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: #475467;
    cursor: pointer;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.12);
    transition: all 0.15s ease;
}

.sidebar-expand-tab:hover {
    background: #f8fafc;
    color: #0f172a;
    width: 32px;
}

.sidebar-expand-tab.hidden-tab {
    display: none !important;
}

@media (max-width: 768px) {
    /* 1. Header Bar Mobile Clean Margins & Paddings */
    .app-header {
        height: 42px;
        padding: 0 6px;
        position: relative;
        gap: 2px;
        box-sizing: border-box;
    }

    .header-center {
        position: static !important;
        transform: none !important;
        flex: 1 1 auto;
        display: flex;
        justify-content: center;
        overflow: hidden;
    }

    .header-left {
        gap: 3px;
        flex: 0 0 auto;
        display: flex;
        align-items: center;
    }

    .header-folder-btn {
        width: 24px !important;
        height: 24px !important;
        font-size: 13px !important;
        padding: 0 !important;
        margin: 0 !important;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 4px !important;
    }

    .graph-title-input {
        width: 62px !important;
        max-width: 62px !important;
        height: 24px !important;
        font-size: 11px !important;
        padding: 2px 5px !important;
        border-radius: 4px !important;
        border: 1px solid #cbd5e1 !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        overflow: hidden !important;
    }

    .btn-save-pill {
        padding: 2px 8px !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        height: 24px !important;
        line-height: 20px !important;
        border-radius: 12px !important;
        margin: 0 !important;
    }

    .desmos-logo {
        font-size: 11.5px !important;
        letter-spacing: -0.02em !important;
        padding: 2px 4px !important;
        white-space: nowrap !important;
    }

    .header-right {
        gap: 3px;
        flex: 0 0 auto;
        display: flex;
        align-items: center;
    }

    #themeToggleBtn {
        display: none !important; /* Hide on mobile header to prevent overlapping */
    }

    #shareBtn, #examplesBtn, #exportBtn, #hearGraphBtn, #aiCopilotBtn {
        padding: 2px 6px !important;
        font-size: 11px !important;
        height: 24px !important;
        line-height: 20px !important;
        border-radius: 4px !important;
        margin: 0 !important;
        white-space: nowrap !important;
    }

    @media (max-width: 540px) {
        #homeNavBtn .btn-text, #examplesBtn .btn-text, #exportBtn .btn-text, #shareBtn .btn-text, #hearGraphBtn .btn-text, #aiCopilotBtn .btn-text {
            display: none !important;
        }
    }

    .user-account-btn {
        padding: 2px 7px !important;
        font-size: 11px !important;
        height: 24px !important;
        line-height: 20px !important;
        border-radius: 12px !important;
        margin: 0 !important;
        max-width: 64px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    /* 2. Workspace Body */
    .workspace-body {
        flex-direction: column-reverse;
        position: relative;
        height: calc(100vh - 42px);
    }

    /* 3. Left Sidebar transforms into a Mobile Bottom Tray */
    .sidebar-panel {
        width: 100% !important;
        position: fixed;
        bottom: 0;
        left: 0;
        max-height: 45vh;
        z-index: 25;
        border-right: none;
        border-top: 2px solid #cbd5e1;
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
        border-radius: 16px 16px 0 0;
        background: #ffffff;
        transition: transform 0.22s ease, bottom 0.22s ease, max-height 0.22s ease;
    }

    .sidebar-panel.collapsed {
        transform: translateY(calc(100% - 40px));
    }

    /* CRITICAL MOBILE FIX: When virtual keypad is OPEN, lift the sidebar tray above the keypad dock so the active expression cell is 100% visible! */
    body.keypad-open .sidebar-panel,
    .app-container:has(.keypad-dock:not(.hidden-keypad)) .sidebar-panel {
        bottom: 244px !important;
        max-height: 28vh !important;
        z-index: 45 !important;
        border-radius: 12px 12px 0 0 !important;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15) !important;
    }

    body.keypad-open .sidebar-panel.collapsed,
    .app-container:has(.keypad-dock:not(.hidden-keypad)) .sidebar-panel.collapsed {
        transform: translateY(calc(100% - 36px)) !important;
    }

    .sidebar-expand-tab {
        display: none !important; /* On mobile, tray has its own top bar drag handle */
    }

    .sidebar-top-bar {
        padding: 6px 12px;
        cursor: pointer;
        height: 36px;
    }

    /* Canvas scales to viewable screen height */
    .canvas-wrapper {
        flex: 1;
        height: calc(100vh - 42px);
    }

    body.keypad-open .canvas-wrapper,
    .app-container:has(.keypad-dock:not(.hidden-keypad)) .canvas-wrapper {
        height: calc(100vh - 42px - 244px) !important;
    }

    body.keypad-open .keypad-toggle-btn,
    .app-container:has(.keypad-dock:not(.hidden-keypad)) .keypad-toggle-btn {
        display: none !important;
    }

    /* Floating Navigation Controls */
    .viewport-controls {
        top: 8px;
        right: 8px;
        gap: 4px;
    }

    .btn-icon {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    /* Mobile Keypad Dock */
    .keypad-dock {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 244px !important;
        z-index: 40 !important;
        padding: 5px 6px !important;
        box-sizing: border-box !important;
        border-radius: 12px 12px 0 0 !important;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.18) !important;
        overflow: hidden !important;
    }

    .keypad-toggle-btn {
        bottom: 12px;
        left: 12px;
        z-index: 28;
        padding: 6px 12px;
        font-size: 12px;
    }

    /* Workstations Mobile View (< 768px) */
    .workstation-container {
        padding: 8px 4px !important;
    }

    .tool-view-card {
        padding: 12px 10px !important;
        border-radius: 8px !important;
        gap: 12px !important;
    }

    .tool-view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .tool-view-header h2 {
        font-size: 16px !important;
    }

    .btn-tool-back {
        width: 100%;
        text-align: center;
        padding: 8px !important;
    }

    /* 3D Mobile Responsiveness */
    .d3-controls-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .d3-input-group {
        width: 100% !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 6px !important;
    }

    .d3-input {
        width: 100% !important;
        height: 42px !important;
        min-height: 42px !important;
        max-height: 42px !important;
        flex: none !important;
        box-sizing: border-box !important;
    }

    .btn-d3-plot {
        width: 100% !important;
        height: 42px !important;
        padding: 0 16px !important;
        box-sizing: border-box !important;
    }

    .d3-preset-wrapper {
        width: 100% !important;
        max-width: 100% !important;
    }

    .custom-select-container {
        width: 100% !important;
        max-width: 100% !important;
    }

    .custom-select-trigger {
        width: 100% !important;
        max-width: 100% !important;
    }

    .custom-select-menu {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        box-sizing: border-box !important;
    }

    .custom-select-option {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .d3-custom-dropdown, .d3-select {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .d3-toolbar-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .d3-selectors-group {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .d3-tool-group {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
    }

    .d3-tool-group .d3-custom-dropdown {
        flex: 1 !important;
        margin-left: 8px;
    }

    .d3-btn-group {
        width: 100% !important;
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
    }

    .d3-btn-action {
        width: 100% !important;
        text-align: center !important;
        padding: 8px 4px !important;
    }

    .d3-canvas-wrapper {
        height: 380px !important;
        max-height: 52vh !important;
    }

    /* Geometry Mobile Responsiveness */
    .geom-header-actions {
        width: 100% !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    .geom-select-preset {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .geometry-pro-toolbar {
        padding: 6px 8px !important;
        gap: 6px !important;
    }

    .geom-tool-row {
        gap: 4px !important;
    }

    .geom-tool-btn {
        font-size: 11px !important;
        padding: 5px 8px !important;
        flex: 1 1 auto;
        justify-content: center;
    }

    .geom-action-btn {
        font-size: 11px !important;
        padding: 5px 8px !important;
        flex: 1 1 auto;
        text-align: center;
    }

    .geom-toolbar-separator {
        display: none !important;
    }

    .geom-inspector-hud {
        font-size: 11px !important;
        padding: 6px 10px !important;
        gap: 8px !important;
    }

    .geometry-canvas-wrapper {
        height: 380px !important;
        max-height: 52vh !important;
    }

    /* Notebook Mobile Responsiveness */
    .nb-header-actions {
        width: 100% !important;
        flex-direction: column !important;
        gap: 6px !important;
    }

    .nb-select-template {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .nb-action-btn {
        width: 100% !important;
        text-align: center !important;
        padding: 8px !important;
    }

    .notebook-doc-title {
        font-size: 18px !important;
    }

    .notebook-cell {
        padding: 10px 12px !important;
    }

    .nb-math-row {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .nb-math-input {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .btn-nb-eval, .btn-nb-steps {
        width: 100% !important;
        padding: 9px !important;
    }

    .nb-table-layout {
        flex-direction: column !important;
    }

    .nb-fit-info {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .notebook-add-bar {
        flex-direction: column !important;
    }

    .btn-nb-add {
        width: 100% !important;
        text-align: center !important;
        padding: 10px !important;
    }

    /* Mobile Centered Popovers & Settings */
    .desmos-wrench-panel {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 90vw !important;
        max-width: 340px !important;
        max-height: 85vh;
        overflow-y: auto;
    }

    .desmos-style-popover {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 88vw !important;
        max-width: 320px !important;
    }

    /* Suite Modal & Dashboard on Mobile */
    .suite-box {
        width: 92vw !important;
        max-height: 90vh;
        overflow-y: auto;
        padding: 18px;
    }

    .suite-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px;
    }

    .suite-featured-card {
        flex-direction: column;
        padding: 14px;
    }

    .dashboard-header {
        padding: 0 12px !important;
        height: 52px !important;
        gap: 8px;
    }

    .dash-user-pill {
        padding: 3px 8px 3px 4px !important;
    }

    .dash-user-email {
        display: none !important;
    }

    .dashboard-hero {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px 20px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .hero-text h1 {
        font-size: 20px !important;
    }

    .hero-text p {
        font-size: 12.5px !important;
    }

    .dashboard-stats-row {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .dashboard-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px 14px !important;
    }

    .dash-search-input {
        max-width: 100% !important;
    }

    .projects-cards-grid {
        grid-template-columns: 1fr !important;
    }

    .matrix-setup-row {
        flex-direction: column;
    }
}

/* =========================================================
   CUSTOM MODALS (EXAMPLE GALLERY & 4K EXPORT STUDIO)
   ========================================================= */

.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.custom-modal-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.custom-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 4px 0;
}

.modal-subtitle {
    font-size: 12.5px;
    color: #64748b;
    margin: 0;
}

.btn-close-modal {
    background: transparent;
    border: none;
    font-size: 18px;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s;
}

.btn-close-modal:hover {
    color: #0f172a;
}

/* Gallery Modal Specific */
.gallery-modal-card {
    max-width: 900px;
}

.gallery-category-tabs {
    display: flex;
    gap: 6px;
    padding: 12px 24px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    overflow-x: auto;
}

.gallery-tab {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.gallery-tab:hover {
    color: #0f172a;
    background: #f1f5f9;
}

.gallery-tab.active {
    background: #2d70b3;
    color: #ffffff;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.gallery-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.15s;
}

.gallery-card:hover {
    border-color: #2d70b3;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(45, 112, 179, 0.12);
}

.gallery-card-badge {
    font-size: 10px;
    font-weight: 700;
    color: #ffffff;
    padding: 2px 7px;
    border-radius: 12px;
    display: inline-block;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.gallery-card-title {
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.gallery-card-desc {
    font-size: 12px;
    color: #64748b;
    line-height: 1.4;
    margin: 0;
    flex: 1;
}

.btn-load-preset {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #2d70b3;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.15s;
}

.btn-load-preset:hover {
    background: #2d70b3;
    color: #ffffff;
    border-color: #2d70b3;
}

/* Export Modal Specific */
.export-modal-card {
    max-width: 580px;
}

.export-form-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.export-option-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.export-label {
    font-size: 12.5px;
    font-weight: 600;
    color: #334155;
}

.export-radio-row {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: #1e293b;
}

.export-select {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    font-size: 13px;
    color: #1e293b;
    background: #ffffff;
    outline: none;
}

.export-checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 12px;
    color: #475569;
    line-height: 1.4;
    cursor: pointer;
}

.custom-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 24px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}


/* =========================================================================
   CALCULUS STUDIO WORKBENCH (Derivatives, Integrals, 3D Solids & ODEs)
   ========================================================================= */
.calc-studio-workstation,
.mathematica-workstation,
.matlab-workstation {
    max-width: 1240px;
    width: 100%;
    margin: 0 auto;
}

.calc-studio-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 18px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 10px;
}

.cs-tab-btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #334155;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.cs-tab-btn.active {
    background: #0d9488;
    color: #ffffff;
    border-color: #0d9488;
}

.calc-studio-body {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
    align-items: start;
}

.cs-controls-col {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cs-form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.cs-form-group label {
    font-size: 12px;
    font-weight: 700;
    color: #475569;
}

.cs-input, .cs-select {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    border-radius: 7px;
    border: 1px solid #cbd5e1;
    font-size: 13px;
    font-family: "JetBrains Mono", Consolas, monospace;
    background: #ffffff;
    color: #0f172a;
}

.cs-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.cs-preset-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cs-pill {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 14px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f766e;
    cursor: pointer;
}

.cs-pill:hover {
    background: #ccfbf1;
}

.cs-action-row {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.btn-cs-compute {
    flex: 1;
    padding: 10px 14px;
    border-radius: 8px;
    border: none;
    background: #0d9488;
    color: #ffffff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}

.btn-cs-compute:hover {
    background: #0f766e;
}

.btn-cs-steps {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #2563eb;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
}

.cs-visual-col {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cs-result-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
}

.cs-res-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 6px;
}

.cs-res-math {
    font-size: 18px;
    color: #0f172a;
    overflow-x: auto;
    padding: 6px 0;
}

.cs-res-sub {
    font-size: 12.5px;
    color: #475569;
    margin-top: 6px;
    line-height: 1.5;
}

.cs-steps-mini {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

.cs-step-chip {
    background: #f8fafc;
    border-left: 3px solid #0d9488;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
}

.cs-canvas-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px;
    overflow: hidden;
}

.cs-canvas-card canvas {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}

/* =========================================================================
   MATHEMATICA WOLFRAM CAS LAB
   ========================================================================= */
.wolfram-palette-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    margin: 10px 0 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
}

.palette-label {
    font-size: 12px;
    font-weight: 700;
    color: #991b1b;
    margin-right: 4px;
}

.wolfram-chip {
    background: #ffffff;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 6px;
    cursor: pointer;
    font-family: monospace;
}

.wolfram-chip:hover {
    background: #dc2626;
    color: #ffffff;
}

.wolfram-cells-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.wolfram-cell-card {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    background: #ffffff;
}

.wolfram-in-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background: #f8fafc;
}

.wolfram-label-in,
.wolfram-label-out {
    font-family: Consolas, monospace;
    font-size: 12px;
    font-weight: 700;
    min-width: 68px;
    padding-top: 6px;
}

.wolfram-label-in { color: #2563eb; }
.wolfram-label-out { color: #dc2626; }

.wolfram-cell-input {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 7px 10px;
    font-family: Consolas, monospace;
    font-size: 13px;
    resize: vertical;
    min-height: 36px;
    background: #ffffff;
    color: #0f172a;
}

.wolfram-cell-actions {
    display: flex;
    gap: 6px;
}

.btn-wolfram-run, .btn-wolfram-del, .btn-cell-steps {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.btn-wolfram-run {
    background: #dc2626;
    color: #ffffff;
    border-color: #dc2626;
}

.btn-cell-steps {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #93c5fd;
}

.wolfram-out-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid #f1f5f9;
}

.wolfram-out-content {
    flex: 1;
    min-width: 0;
}

.wolfram-out-math {
    font-size: 16px;
    overflow-x: auto;
}

.wolfram-out-error {
    color: #dc2626;
    font-size: 13px;
    font-weight: 600;
}

.w-matrix-bracket {
    display: inline-flex;
    flex-direction: column;
    border-left: 2px solid #0f172a;
    border-right: 2px solid #0f172a;
    border-radius: 6px;
    padding: 4px 10px;
    gap: 4px;
}

.w-mat-row {
    display: flex;
    gap: 18px;
    justify-content: center;
}

.w-plot2d-canvas {
    width: 100%;
    max-width: 680px;
    height: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.wolfram-manipulate-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.w-manip-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    background: #f8fafc;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.w-manipulate-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-family: monospace;
}

.wolfram-add-bar {
    margin-top: 14px;
}

/* =========================================================================
   MATLAB 4-PANE ENGINEERING IDE
   ========================================================================= */
.matlab-mobile-tabs {
    display: none;
    gap: 6px;
    margin: 10px 0;
}

.ml-mob-tab {
    flex: 1;
    padding: 8px 6px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    border-radius: 7px;
    cursor: pointer;
}

.ml-mob-tab.active {
    background: #ea580c;
    color: #ffffff;
    border-color: #ea580c;
}

.matlab-ide-grid {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    grid-template-rows: 340px 260px;
    gap: 12px;
    margin-top: 14px;
}

.matlab-pane {
    display: flex;
    flex-direction: column;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    overflow: hidden;
    background: #ffffff;
}

.matlab-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 700;
    color: #334155;
}

.matlab-hint {
    font-size: 11px;
    font-weight: 500;
    color: #64748b;
}

.ml-mini-btn {
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    cursor: pointer;
}

.matlab-script-editor {
    flex: 1;
    border: none;
    padding: 10px 12px;
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    resize: none;
    outline: none;
    background: #0f172a;
    color: #f8fafc;
}

.matlab-figure-wrap {
    flex: 1;
    position: relative;
    background: #ffffff;
    overflow: hidden;
}

.matlab-figure-wrap canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.matlab-console-log {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    background: #fafafa;
    font-family: Consolas, monospace;
    font-size: 12px;
}

.matlab-console-log pre {
    margin: 2px 0 6px;
    white-space: pre-wrap;
    word-break: break-word;
}

.ml-line-cmd { color: #2563eb; font-weight: 700; }
.ml-line-err { color: #dc2626; font-weight: 600; }
.ml-line-out { color: #0f172a; }

.matlab-prompt-row {
    display: flex;
    align-items: center;
    gap: 6px;
    border-top: 1px solid #e2e8f0;
    padding: 6px 10px;
    background: #ffffff;
}

.ml-prompt-prefix {
    font-family: Consolas, monospace;
    font-weight: 800;
    color: #ea580c;
}

.matlab-cmd-input {
    flex: 1;
    border: none;
    outline: none;
    font-family: Consolas, monospace;
    font-size: 12.5px;
    color: #0f172a;
}

.matlab-workspace-table-wrap {
    flex: 1;
    overflow-y: auto;
}

.matlab-ws-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.matlab-ws-table th, .matlab-ws-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
}

.matlab-ws-table th {
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
    position: sticky;
    top: 0;
}

.ml-ws-size {
    font-size: 11px;
    color: #64748b;
    font-family: monospace;
}

/* Mobile Responsive Adjustments for Calculus Studio, Mathematica & MATLAB IDE */
@media (max-width: 900px) {
    .calc-studio-body {
        grid-template-columns: 1fr;
    }
    .matlab-mobile-tabs {
        display: flex;
    }
    .matlab-ide-grid {
        display: block;
    }
    .matlab-pane {
        display: none;
        height: 420px;
    }
    .matlab-pane.active-mob-pane {
        display: flex;
    }
}

/* Dark Theme Support for Advanced Workstations */
[data-theme="dark"] .cs-controls-col,
[data-theme="dark"] .cs-result-card,
[data-theme="dark"] .cs-canvas-card,
[data-theme="dark"] .wolfram-cell-card,
[data-theme="dark"] .matlab-pane {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

[data-theme="dark"] .cs-input,
[data-theme="dark"] .wolfram-cell-input,
[data-theme="dark"] .matlab-cmd-input,
[data-theme="dark"] .matlab-prompt-row {
    background: #0f172a;
    border-color: #334155;
    color: #f8fafc;
}

[data-theme="dark"] .wolfram-in-row,
[data-theme="dark"] .matlab-pane-header,
[data-theme="dark"] .matlab-ws-table th {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

[data-theme="dark"] .matlab-console-log {
    background: #0f172a;
}

[data-theme="dark"] .ml-line-out,
[data-theme="dark"] .cs-res-math,
[data-theme="dark"] .cs-form-group label {
    color: #f1f5f9;
}


/* =========================================================================
   EASY VISUAL MODE TOGGLES, SYMBOL BAR & MATRIX GRID BUILDERS
   ========================================================================= */
.ux-mode-switch {
    display: inline-flex;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}

.ux-mode-btn {
    border: none;
    background: transparent;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.ux-mode-btn.active {
    background: #0f172a;
    color: #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.ux-symbol-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    padding: 6px 8px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.ux-sym-title {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    margin-right: 2px;
}

.ux-sym-btn {
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #0f172a;
    border-radius: 5px;
    cursor: pointer;
}

.ux-sym-btn:hover {
    background: #e0f2fe;
    border-color: #38bdf8;
}

.ml-vis-grid, .ml-vis-vec {
    display: grid;
    gap: 6px;
}

.ml-grid-cell, .ml-vec-cell {
    text-align: center;
    padding: 7px 6px !important;
    font-weight: 600;
}

.ml-vis-pre {
    margin: 0;
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 12.5px;
    color: #0f172a;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 220px;
    overflow-y: auto;
}

[data-theme="dark"] .ux-mode-switch,
[data-theme="dark"] .ux-symbol-bar {
    background: #0f172a;
    border-color: #334155;
}

[data-theme="dark"] .ux-sym-btn {
    background: #1e293b;
    border-color: #475569;
    color: #f1f5f9;
}

[data-theme="dark"] .ml-vis-pre {
    color: #e2e8f0;
}


/* =========================================================================
   THEME ISOLATION, CLEAN MATRIX CARDS & STEP FORMULAS
   ========================================================================= */
.mathematica-theme .cs-tab-btn.active {
    background: #dc2626;
    border-color: #dc2626;
    color: #ffffff;
}

.matlab-theme .cs-tab-btn.active {
    background: #ea580c;
    border-color: #ea580c;
    color: #ffffff;
}

.cs-step-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 3px;
}

.cs-step-formula {
    background: #e2e8f0;
    color: #0f172a;
    padding: 2px 8px;
    border-radius: 5px;
    font-size: 11.5px;
}

.cs-step-expr {
    font-size: 13px;
    color: #1e293b;
}

.ml-mat-cards-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-start;
}

.ml-stat-chip {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ml-stat-chip span {
    font-size: 11px;
    font-weight: 700;
    color: #9a3412;
}

.ml-stat-chip b {
    font-size: 16px;
    color: #0f172a;
    font-family: "JetBrains Mono", Consolas, monospace;
}

.ml-mat-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 14px;
}

.ml-mat-card-title {
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 8px;
}

.ml-mat-bracket {
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    border-left: 2.5px solid #0f172a;
    border-right: 2.5px solid #0f172a;
    border-radius: 5px;
    padding: 6px 12px;
    background: #ffffff;
}

.ml-mat-row {
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.ml-mat-cell {
    min-width: 48px;
    text-align: right;
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
}

[data-theme="dark"] .ml-mat-card { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .ml-mat-bracket { background: #1e293b; border-color: #e2e8f0; }
[data-theme="dark"] .ml-mat-cell { color: #f8fafc; }
[data-theme="dark"] .cs-step-formula { background: #334155; color: #f1f5f9; }
[data-theme="dark"] .cs-step-expr { color: #e2e8f0; }

/* =========================================================
   AI MATH COPILOT CHATBOX & INLINE GRAPH STYLES
   ========================================================= */
.btn-ai-copilot {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%) !important;
    color: #ffffff !important;
    border: 1px solid #6366f1 !important;
    font-weight: 700 !important;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.28);
}

.btn-ai-copilot:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.btn-landing-ai {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 13px 22px;
    border-radius: 10px;
    border: 1.5px solid #6366f1;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.25);
    transition: transform 0.15s ease, filter 0.15s ease;
}

.btn-landing-ai:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
}

/* Full-Page AI Copilot Workspace (/ai) */
.ai-page-view {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1350;
    background: #ffffff;
    display: flex;
    flex-direction: column;
}

.ai-page-view.hidden-ai-page {
    display: none !important;
}

.ai-workspace-shell {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.ai-sidebar {
    width: 280px;
    flex: 0 0 280px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: margin-left 0.2s ease, transform 0.2s ease;
}

.ai-page-view.ai-sidebar-collapsed .ai-sidebar {
    margin-left: -280px;
}

.ai-sidebar-top {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px;
    border-bottom: 1px solid #e2e8f0;
}

.ai-new-chat-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #ffffff;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

.ai-new-chat-btn:hover {
    filter: brightness(1.08);
}

.ai-sidebar-close-mobile {
    display: none;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    border-radius: 8px;
    padding: 7px 10px;
    cursor: pointer;
}

.ai-sidebar-search-wrap {
    padding: 10px 14px 6px;
}

.ai-chat-search {
    width: 100%;
    padding: 8px 11px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-size: 13px;
    color: #0f172a;
    outline: none;
    box-sizing: border-box;
}

.ai-chat-search:focus {
    border-color: #6366f1;
}

.ai-chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-chat-empty {
    text-align: center;
    padding: 24px 12px;
    font-size: 12.5px;
    color: #94a3b8;
}

.ai-chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 9px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.14s, border-color 0.14s;
}

.ai-chat-item:hover {
    background: #eef2ff;
}

.ai-chat-item.active {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.ai-chat-item-main {
    min-width: 0;
    flex: 1;
}

.ai-chat-item-title {
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-item-meta {
    font-size: 11px;
    color: #64748b;
    margin-top: 2px;
}

.ai-chat-item-actions {
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.14s;
}

.ai-chat-item:hover .ai-chat-item-actions,
.ai-chat-item.active .ai-chat-item-actions {
    opacity: 1;
}

.ai-chat-act-btn {
    border: none;
    background: transparent;
    color: #64748b;
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 12px;
    cursor: pointer;
}

.ai-chat-act-btn:hover {
    background: #ffffff;
    color: #0f172a;
}

.ai-delete-item-btn:hover {
    color: #dc2626;
}

.ai-sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid #e2e8f0;
}

.ai-clear-all-btn {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #475569;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

.ai-clear-all-btn:hover {
    border-color: #fca5a5;
    color: #dc2626;
    background: #fef2f2;
}

.ai-main-pane {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #ffffff;
}

.ai-page-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
}

.ai-topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.ai-toggle-sidebar-btn {
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #334155;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
}

.ai-active-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.ai-active-title-wrap h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.ai-title-rename-btn {
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    font-size: 13px;
    padding: 3px 5px;
    border-radius: 6px;
}

.ai-title-rename-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

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

.ai-nav-pill {
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #1e293b;
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.ai-nav-pill:hover {
    background: #e2e8f0;
}

.ai-messages-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 24px 18px;
}

.ai-messages-inner {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.ai-welcome-card {
    margin: 20px auto 0;
    max-width: 720px;
    text-align: center;
    padding: 28px 20px;
}

.ai-welcome-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    border-radius: 14px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #ffffff;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.25);
}

.ai-welcome-card h2 {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 800;
    color: #0f172a;
}

.ai-welcome-card p {
    margin: 0 auto 22px;
    max-width: 560px;
    font-size: 14px;
    line-height: 1.6;
    color: #475569;
}

.ai-sample-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
    text-align: left;
}

.ai-sample-card {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-sample-card:hover {
    border-color: #6366f1;
    background: #eef2ff;
    transform: translateY(-1px);
}

.ai-sample-tag {
    font-size: 11px;
    font-weight: 800;
    color: #4f46e5;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ai-sample-text {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}

.ai-composer-dock {
    padding: 10px 16px 14px;
    background: linear-gradient(180deg, rgba(255,255,255,0) 0%, #ffffff 28%);
}

.ai-page-composer {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 8px 10px 8px 16px;
    border-radius: 24px;
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    box-shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.ai-page-composer:focus-within {
    border-color: #6366f1;
    box-shadow: 0 8px 26px rgba(99, 102, 241, 0.16);
}

.ai-page-composer textarea {
    flex: 1;
    resize: none;
    min-height: 38px;
    max-height: 140px;
    overflow-y: hidden;
    padding: 7px 4px;
    border: none;
    font-family: inherit;
    font-size: 14.5px;
    line-height: 1.45;
    color: #0f172a;
    background: transparent;
    outline: none;
    box-sizing: border-box;
}

.ai-composer-hint {
    max-width: 780px;
    margin: 6px auto 0;
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
}

.ai-copilot-badge {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #ffffff;
    font-size: 10.5px;
    font-weight: 800;
    padding: 4px 9px;
    border-radius: 999px;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.ai-mobile-backdrop {
    display: none;
}

.ai-chat-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    padding: 10px 8px 4px;
}

@media (max-width: 900px) {
    .ai-page-view.ai-sidebar-mobile-open .ai-mobile-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1390;
        background: rgba(15, 23, 42, 0.45);
        backdrop-filter: blur(2px);
    }
    .ai-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1400;
        width: min(82vw, 300px);
        transform: translateX(-100%);
        margin-left: 0 !important;
        box-shadow: 12px 0 32px rgba(15, 23, 42, 0.22);
    }
    .ai-page-view.ai-sidebar-mobile-open .ai-sidebar {
        transform: translateX(0);
    }
    .ai-sidebar-close-mobile {
        display: inline-flex;
    }
    .ai-chat-item-actions {
        opacity: 1;
    }
    .ai-page-topbar {
        padding: 10px 12px;
    }
    .ai-copilot-badge {
        display: none;
    }
}

@media (max-width: 600px) {
    .ai-messages-scroll {
        padding: 14px 10px;
    }
    .ai-messages-inner {
        gap: 16px;
    }
    .ai-nav-pill .ai-pill-text {
        display: none;
    }
    .ai-nav-pill {
        padding: 6px 10px;
    }
    .ai-active-title-wrap h2 {
        font-size: 14px;
        max-width: 145px;
    }
    .ai-composer-dock {
        padding: 8px 10px 10px;
    }
    .ai-page-composer {
        padding: 6px 8px 6px 14px;
        border-radius: 20px;
    }
    .ai-page-composer textarea {
        font-size: 14px;
    }
    .ai-send-btn .ai-send-label {
        display: none;
    }
    .ai-send-btn {
        width: 38px;
        height: 38px;
        padding: 0;
        justify-content: center;
        border-radius: 999px;
    }
    .ai-composer-hint {
        display: none;
    }
    .ai-welcome-card {
        padding: 14px 6px;
        margin-top: 6px;
    }
    .ai-welcome-card h2 {
        font-size: 18px;
    }
    .ai-sample-grid {
        grid-template-columns: 1fr;
    }
}

.ai-copilot-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-icon-btn,
.ai-close-btn {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.ai-close-btn {
    font-size: 15px;
    padding: 4px 10px;
}

.ai-icon-btn:hover,
.ai-close-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.ai-copilot-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px 18px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.ai-chip {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.ai-chip:hover {
    border-color: #6366f1;
    color: #4f46e5;
    background: #eef2ff;
}

.ai-copilot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #ffffff;
}

.ai-msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.ai-msg-user {
    justify-content: flex-end;
}

.ai-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 999px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    margin-top: 2px;
}

.ai-bubble {
    max-width: min(680px, 90%);
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-bubble-user {
    background: linear-gradient(135deg, #2563eb, #4f46e5);
    color: #ffffff;
    border-color: transparent;
    font-size: 14px;
    line-height: 1.5;
    border-bottom-right-radius: 4px;
}

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

.ai-verified-pill {
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #0f766e;
    background: #ccfbf1;
    padding: 3px 8px;
    border-radius: 999px;
}

.ai-model-tag {
    font-size: 11px;
    color: #64748b;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

.ai-bubble-text {
    font-size: 14px;
    line-height: 1.55;
    color: #1e293b;
}

.ai-inline-math {
    display: inline-block;
    padding: 1px 4px;
    background: #eef2ff;
    border-radius: 4px;
    color: #1e1b4b;
}

.ai-result-math {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-left: 4px solid #4f46e5;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 18px;
    overflow-x: auto;
    color: #0f172a;
}

.ai-cas-note {
    font-size: 12px;
    color: #b45309;
    background: #fef3c7;
    padding: 6px 10px;
    border-radius: 6px;
}

.ai-inline-graph-card {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    overflow: hidden;
}

.ai-inline-graph-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12px;
    font-weight: 700;
    color: #334155;
}

.ai-open-calc-btn {
    background: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
}

.ai-open-calc-btn:hover {
    background: #1d4ed8;
}

.ai-inline-canvas {
    width: 100%;
    height: 260px;
    display: block;
    touch-action: none;
}

.ai-steps-details {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
}

.ai-steps-details summary {
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 700;
    color: #334155;
    user-select: none;
}

.ai-steps-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.ai-typing {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #64748b;
}

.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #6366f1;
    animation: aiBounce 1.1s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aiBounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40% { transform: scale(1.1); opacity: 1; }
}

.ai-copilot-composer {
    display: flex;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    align-items: flex-end;
}

.ai-copilot-composer textarea {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 110px;
    padding: 10px 13px;
    border-radius: 10px;
    border: 1.5px solid #cbd5e1;
    font-family: inherit;
    font-size: 14px;
    color: #0f172a;
    background: #ffffff;
    outline: none;
}

.ai-copilot-composer textarea:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.ai-send-btn {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #ffffff;
    border: none;
    border-radius: 10px;
    height: 42px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.ai-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

[data-theme="dark"] .ai-page-view,
[data-theme="dark"] .ai-main-pane,
[data-theme="dark"] .ai-page-topbar { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .ai-sidebar { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .ai-sidebar-top,
[data-theme="dark"] .ai-sidebar-footer,
[data-theme="dark"] .ai-composer-dock { border-color: #334155; background: #1e293b; }
[data-theme="dark"] .ai-active-title-wrap h2,
[data-theme="dark"] .ai-welcome-card h2,
[data-theme="dark"] .ai-chat-item-title,
[data-theme="dark"] .ai-sample-text { color: #f8fafc; }
[data-theme="dark"] .ai-chat-item:hover,
[data-theme="dark"] .ai-chat-item.active { background: #312e81; border-color: #4f46e5; }
[data-theme="dark"] .ai-chat-search,
[data-theme="dark"] .ai-clear-all-btn,
[data-theme="dark"] .ai-nav-pill,
[data-theme="dark"] .ai-toggle-sidebar-btn,
[data-theme="dark"] .ai-sample-card,
[data-theme="dark"] .ai-page-composer textarea { background: #0f172a; border-color: #334155; color: #f8fafc; }
[data-theme="dark"] .ai-bubble { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .ai-bubble-text { color: #e2e8f0; }
[data-theme="dark"] .ai-result-math { background: #0f172a; border-color: #334155; color: #f8fafc; }
[data-theme="dark"] .ai-inline-math { background: #312e81; color: #e0e7ff; }
[data-theme="dark"] .ai-inline-graph-card,
[data-theme="dark"] .ai-steps-details { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .ai-inline-graph-head { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .ai-steps-details summary { color: #e2e8f0; }
[data-theme="dark"] .ai-chip { background: #0f172a; border-color: #334155; color: #cbd5e1; }

/* Claude / ChatGPT Editorial Turns & Interactive Graph Card */
.ai-turn {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-turn-user {
    align-items: flex-end;
}

.ai-user-pill {
    max-width: min(78%, 580px);
    background: #eef2ff;
    color: #1e1b4b;
    border: 1px solid #e0e7ff;
    padding: 10px 15px;
    border-radius: 18px 18px 4px 18px;
    font-size: 14.5px;
    line-height: 1.5;
    word-break: break-word;
}

.ai-turn-assistant {
    align-items: stretch;
}

.ai-assistant-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-assistant-name {
    font-size: 13.5px;
    font-weight: 700;
    color: #0f172a;
}

.ai-subtle-badge {
    font-size: 11px;
    font-weight: 600;
    color: #4f46e5;
    background: #eef2ff;
    padding: 2px 8px;
    border-radius: 999px;
}

.ai-assistant-body {
    padding-left: 38px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-prose-text {
    font-size: 15px;
    line-height: 1.65;
    color: #1e293b;
}

.ai-reveal-blocks {
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: opacity 0.2s ease;
}

.ai-reveal-blocks.ai-reveal-hidden {
    opacity: 0;
    pointer-events: none;
    height: 0;
    overflow: hidden;
}

.ai-graph-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.ai-graph-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.ai-graph-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    color: #334155;
}

.ai-hover-readout {
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 11.5px;
    font-weight: 600;
    color: #4f46e5;
}

.ai-graph-btns {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.ai-g-btn,
.ai-g-select {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}

.ai-g-play-btn {
    border-color: #c7d2fe;
    background: #eef2ff;
    color: #4338ca;
}

.ai-g-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.ai-g-open-btn {
    border: none;
    background: #2563eb;
    color: #ffffff;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
}

.ai-g-open-btn:hover {
    background: #1d4ed8;
}

.ai-graph-canvas-wrap {
    width: 100%;
    position: relative;
}

.ai-graph-canvas {
    width: 100%;
    height: 270px;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

.ai-ode-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    padding: 8px 12px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 12px;
    color: #334155;
}

.ai-ode-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 160px;
}

.ai-ode-controls input[type="range"] {
    flex: 1;
    accent-color: #4f46e5;
}

.ai-turn-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 2px;
}

.ai-action-chip {
    border: 1px solid #e2e8f0;
    background: transparent;
    color: #64748b;
    border-radius: 6px;
    padding: 4px 9px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}

.ai-action-chip:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.ai-foot-model {
    margin-left: auto;
    font-size: 11px;
    color: #94a3b8;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

@media (max-width: 600px) {
    .ai-assistant-body {
        padding-left: 0;
    }
    .ai-user-pill {
        max-width: 88%;
        font-size: 14px;
    }
    .ai-prose-text {
        font-size: 14.5px;
    }
    .ai-result-math {
        font-size: 15.5px;
        padding: 10px 12px;
    }
    .ai-graph-canvas {
        height: 220px;
    }
}

[data-theme="dark"] .ai-composer-dock { background: linear-gradient(180deg, rgba(15,23,42,0) 0%, #0f172a 28%); }
[data-theme="dark"] .ai-page-composer { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .ai-page-composer textarea { color: #f8fafc; background: transparent; }
[data-theme="dark"] .ai-user-pill { background: #312e81; border-color: #4338ca; color: #e0e7ff; }
[data-theme="dark"] .ai-assistant-name,
[data-theme="dark"] .ai-prose-text { color: #e2e8f0; }
[data-theme="dark"] .ai-subtle-badge { background: #312e81; color: #c7d2fe; }
[data-theme="dark"] .ai-graph-card { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .ai-graph-toolbar,
[data-theme="dark"] .ai-ode-controls { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .ai-g-btn,
[data-theme="dark"] .ai-g-select,
[data-theme="dark"] .ai-action-chip { background: #0f172a; border-color: #334155; color: #cbd5e1; }
[data-theme="dark"] .ai-g-play-btn { background: #312e81; border-color: #4f46e5; color: #e0e7ff; }
