/* ============================================
   Agent Portal — Component Styles
   All colors reference design-system.css tokens
   ============================================ */

/* --- Navbar --- */
.navbar {
    background: var(--surface-primary);
    border-bottom: 1px solid var(--border-default);
    padding: 0 var(--space-6);
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    font-weight: 700;
    font-size: var(--text-lg);
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.navbar-brand-icon {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
}

.navbar-brand-text {
    letter-spacing: -0.02em;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    list-style: none;
}

.navbar-nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: 500;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.navbar-nav a:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.navbar-nav a.active {
    color: var(--accent-primary);
    background: var(--accent-primary-light);
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* --- Theme Toggle --- */
.theme-toggle {
    background: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-1) var(--space-2);
    cursor: pointer;
    font-size: var(--text-base);
    line-height: 1;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.theme-toggle:hover {
    background: var(--surface-hover);
    border-color: var(--border-default);
}

/* --- Usage Pill --- */
.usage-pill {
    display: inline-block;
    padding: 2px var(--space-2);
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.usage-pill:empty { display: none; }
.usage-green { background: var(--accent-success-light); color: var(--accent-success); }
.usage-yellow { background: var(--accent-warning-light); color: var(--accent-warning); }
.usage-red { background: var(--accent-danger-light); color: var(--accent-danger); }

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
    animation: pageIn 0.2s ease;
}

.container-narrow {
    max-width: 600px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
    animation: pageIn 0.2s ease;
}

.page-header {
    margin-bottom: var(--space-8);
}

.page-header h1 {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-header p {
    color: var(--text-secondary);
    margin-top: var(--space-1);
    font-size: var(--text-sm);
}

/* --- Cards --- */
.card {
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
}

.card-hover {
    transition: all var(--transition-normal);
}

.card-hover:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    font-family: var(--font-sans);
    line-height: 1.5;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-primary-hover); }

.btn-success {
    background: var(--accent-success);
    color: white;
}
.btn-success:hover:not(:disabled) { opacity: 0.9; }

.btn-danger {
    background: var(--accent-danger);
    color: white;
}
.btn-danger:hover:not(:disabled) { opacity: 0.9; }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-default);
}
.btn-outline:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--surface-hover);
    border-color: var(--border-default);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: var(--space-1) var(--space-2);
}
.btn-ghost:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); }
.btn-block { width: 100%; }

/* --- Forms --- */
.form-group {
    margin-bottom: var(--space-5);
}

.form-group label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.form-group .hint {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-primary);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

input::placeholder, textarea::placeholder {
    color: var(--text-tertiary);
}

textarea {
    resize: vertical;
    min-height: 100px;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    line-height: 1.6;
}

/* --- Checkbox/Toggle --- */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm);
}

.checkbox-item input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent-primary);
}

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--text-sm);
}

th {
    font-weight: 600;
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:hover td { background: var(--surface-hover); }

/* --- Alerts --- */
.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    margin-bottom: var(--space-4);
}

.alert-error {
    background: var(--accent-danger-light);
    color: var(--accent-danger);
    border: 1px solid var(--accent-danger-light);
}

.alert-success {
    background: var(--accent-success-light);
    color: var(--accent-success);
    border: 1px solid var(--accent-success-light);
}

.alert-warning {
    background: var(--accent-warning-light);
    color: var(--accent-warning);
    border: 1px solid var(--accent-warning-light);
}

/* --- Badge --- */
.badge {
    display: inline-block;
    padding: 2px var(--space-2);
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: var(--radius-full);
}

.badge-admin { background: var(--accent-primary-light); color: var(--accent-primary); }
.badge-user { background: var(--surface-secondary); color: var(--text-secondary); border: 1px solid var(--border-default); }
.badge-active { background: var(--accent-success-light); color: var(--accent-success); }
.badge-inactive { background: var(--accent-danger-light); color: var(--accent-danger); }
.badge-superadmin { background: var(--accent-warning-light); color: var(--accent-warning); }

/* --- Admin Page Enhancements --- */
.add-user-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto auto auto;
    gap: var(--space-3);
    align-items: end;
}

.btn-outline-sm {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
}

.btn-outline-sm:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.btn-danger-sm {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--accent-danger-light);
    background: var(--accent-danger-light);
    color: var(--accent-danger);
    font-size: var(--text-xs);
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
}

.btn-danger-sm:hover {
    background: var(--accent-danger);
    color: white;
}

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

/* Mobile card view for admin tables */
.mobile-cards { display: none; }

.user-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
}

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

.user-card-name { font-weight: 600; }

.user-card-meta {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-bottom: var(--space-3);
}

.user-card-actions {
    display: flex;
    gap: var(--space-2);
}

/* --- Login Page --- */
/* === Login Page: Two-panel layout === */
.login-scene {
    display: flex;
    min-height: 100vh;
}

/* Left panel — brand storytelling */
.login-brand-panel {
    flex: 1;
    background: linear-gradient(135deg, #0F172A 0%, #1E293B 40%, #312E81 100%);
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 4rem;
    overflow: hidden;
}

.login-brand-panel::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 30%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(99,102,241,0.12) 0%, transparent 70%);
    pointer-events: none;
}

.login-brand-panel::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
}

.brand-content {
    position: relative;
    z-index: 1;
    max-width: 480px;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 3rem;
}

.brand-logo svg { width: 40px; height: 40px; }

.brand-logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.03em;
}

.brand-headline {
    font-size: 2.5rem;
    font-weight: 800;
    color: white;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin-bottom: 1.25rem;
}

.brand-headline .accent {
    background: linear-gradient(135deg, #818cf8, #a5b4fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-subtext {
    font-size: 1.0625rem;
    color: #94a3b8;
    line-height: 1.7;
    margin-bottom: 2.5rem;
}

.brand-proof {
    display: flex;
    gap: 2rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.proof-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.proof-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    font-variant-numeric: tabular-nums;
}

.proof-label {
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

/* Right panel — form */
.login-form-panel {
    width: 480px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    background: var(--surface-primary);
    position: relative;
}

.login-form-container {
    width: 100%;
    max-width: 360px;
    animation: formIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.login-form-header {
    margin-bottom: 2rem;
}

.login-form-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.375rem;
}

.login-form-header p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-field {
    margin-bottom: 1.25rem;
}

.form-field label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

.form-field .input-wrapper {
    position: relative;
}

.form-field input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    transition: border-color 0.15s, box-shadow 0.15s;
    line-height: 1.5;
}

.form-field input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-field input::placeholder {
    color: var(--text-tertiary);
}

.password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.15s;
}

.password-toggle:hover { color: var(--text-primary); }

.btn-login {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: var(--font-sans);
    color: white;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    margin-top: 0.5rem;
    position: relative;
    overflow: hidden;
}

.btn-login:hover {
    background: var(--accent-primary-hover);
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
    transform: translateY(-1px);
}

.btn-login:active {
    transform: translateY(0);
}

.btn-login.loading .btn-text { opacity: 0; }
.btn-login.loading .btn-spinner { display: block; }

.btn-spinner {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes loginSpin { to { transform: translate(-50%, -50%) rotate(360deg); } }

.alert-error {
    padding: 0.75rem 1rem;
    background: var(--accent-danger-light);
    color: var(--accent-danger);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    margin-bottom: 1.25rem;
    border: 1px solid rgba(239,68,68,0.15);
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.login-footer {
    text-align: center;
    margin-top: 2rem;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.login-controls {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    gap: 0.5rem;
}

.control-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.15s;
}

.control-btn:hover {
    background: var(--accent-primary-light);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Dark mode — login/signup panels */
[data-theme="dark"] .login-form-panel {
    background: #1e293b;
    border-left: 1px solid #334155;
}
[data-theme="dark"] .form-field input {
    background: #0f172a;
    border-color: #475569;
}
[data-theme="dark"] .form-field input:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(129,140,248,0.2);
}
[data-theme="dark"] .btn-login {
    background: #6366f1;
}
[data-theme="dark"] .btn-login:hover {
    background: #818cf8;
    box-shadow: 0 4px 12px rgba(99,102,241,0.4);
}
[data-theme="dark"] .control-btn {
    border-color: #475569;
}

@media (max-width: 900px) {
    .login-scene { flex-direction: column; }
    .login-brand-panel {
        min-height: 40vh;
        padding: 2rem;
    }
    .brand-headline { font-size: 1.75rem; }
    .login-form-panel {
        width: 100%;
        flex: 1;
    }
    .brand-proof { gap: 1.5rem; }
    .proof-value { font-size: 1.25rem; }
    [data-theme="dark"] .login-form-panel { border-left: none; border-top: 1px solid #334155; }
}

@media (max-width: 480px) {
    .login-brand-panel { padding: 1.5rem; min-height: 35vh; }
    .brand-headline { font-size: 1.5rem; }
    .brand-subtext { display: none; }
    .login-form-panel { padding: 1.5rem; }
}

/* --- Template Gallery --- */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-5);
}

.template-card {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.template-icon {
    font-size: 2rem;
    margin-bottom: var(--space-3);
}

.template-card h3 {
    font-size: var(--text-base);
    font-weight: 600;
    margin-bottom: var(--space-1);
}

.template-card .category {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.template-card p {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
}

/* --- Chat Layout --- */
.chat-layout {
    display: flex;
    height: calc(100vh - 52px);
    overflow: hidden;
}

.chat-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--surface-sidebar);
    border-right: 1px solid var(--border-default);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-spring);
}

.chat-sidebar-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
}

.chat-sidebar-group-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-3) var(--space-3) var(--space-1) var(--space-3);
}

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--text-primary);
    text-decoration: none;
    margin-bottom: 1px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.session-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.session-item:hover { background: var(--surface-hover); }
.session-item.active {
    background: var(--surface-active);
    font-weight: 500;
}

.session-item-actions {
    display: none;
    gap: var(--space-1);
    margin-left: var(--space-2);
    flex-shrink: 0;
}

.session-item:hover .session-item-actions {
    display: flex;
}

.session-action-btn {
    background: none;
    border: none;
    padding: 2px;
    cursor: pointer;
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    line-height: 1;
    transition: all var(--transition-fast);
}

.session-action-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.session-action-btn.danger:hover {
    color: var(--accent-danger);
}

.chat-sidebar-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.chat-sidebar-footer kbd {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    padding: 1px 4px;
    border-radius: 3px;
    background: var(--surface-hover);
    border: 1px solid var(--border-default);
    color: var(--text-tertiary);
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface-primary);
    position: relative;
}

.chat-header {
    padding: var(--space-3) var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--surface-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
}

.chat-header-info h2 {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
}

.chat-header-info p {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.mobile-sidebar-toggle {
    display: none;
    background: none;
    border: none;
    padding: var(--space-2);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.25rem;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.mobile-sidebar-toggle:hover {
    background: var(--surface-hover);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* --- Messages (Claude.ai-style) --- */
.message {
    max-width: 48rem;
    font-size: var(--text-base);
    line-height: 1.7;
    word-wrap: break-word;
    animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@keyframes pageIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.message-user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: var(--user-bubble-text);
    padding: var(--space-3) var(--space-4);
    border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
    max-width: 70%;
}

.message-assistant {
    align-self: flex-start;
    padding: var(--space-2) 0;
    padding-left: 40px;
    position: relative;
    width: 100%;
    max-width: 48rem;
}

/* AI avatar indicator */
.message-assistant::before {
    content: '';
    position: absolute;
    left: 0;
    top: var(--space-2);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background-color: #6366f1;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5'/%3E%3C/svg%3E");
    background-size: 14px 14px;
    background-position: center;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.message-system {
    align-self: center;
    background: var(--accent-warning-light);
    color: var(--accent-warning);
    font-size: var(--text-sm);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
}

/* --- Markdown in AI messages --- */
.message-assistant p {
    margin-bottom: 0.75em;
}
.message-assistant p:last-child {
    margin-bottom: 0;
}

.message-assistant h2,
.message-assistant h3,
.message-assistant h4 {
    margin-top: 1.25em;
    margin-bottom: 0.5em;
    font-weight: 600;
    color: var(--text-primary);
}
.message-assistant h2 { font-size: 1.3em; }
.message-assistant h3 { font-size: 1.15em; }
.message-assistant h4 { font-size: 1.05em; }

.message-assistant ul,
.message-assistant ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-assistant li {
    margin-bottom: 0.25em;
}

.message-assistant a {
    color: var(--accent-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message-assistant blockquote {
    border-left: 3px solid var(--border-default);
    padding-left: var(--space-4);
    color: var(--text-secondary);
    margin: 0.75em 0;
}

.message-assistant hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 1em 0;
}

.message-assistant table {
    border-collapse: collapse;
    margin: 0.75em 0;
    font-size: var(--text-sm);
    width: auto;
}

.message-assistant table th,
.message-assistant table td {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-default);
}

.message-assistant table th {
    background: var(--surface-secondary);
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-primary);
}

/* --- Code blocks --- */
.code-block-wrapper {
    margin: 0.75em 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-default);
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    background: var(--code-header);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.code-block-header .code-lang {
    font-weight: 500;
    text-transform: lowercase;
}

.code-copy-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: var(--text-xs);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.code-copy-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.message-assistant pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: var(--space-4);
    overflow-x: auto;
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    line-height: 1.6;
    margin: 0;
}

.message-assistant pre code {
    background: none;
    padding: 0;
    font-size: inherit;
    color: inherit;
    border-radius: 0;
}

.message-assistant code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--code-inline-bg);
    color: var(--code-inline-text);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
}

/* Streaming cursor — appended to last child for accurate placement */
.streaming .message-content > *:last-child::after {
    content: '\u258B';
    animation: blink 1s step-end infinite;
    color: var(--accent-primary);
    margin-left: 1px;
}

/* Fallback when message-content has no children yet */
.streaming .message-content:empty::after {
    content: '\u258B';
    animation: blink 1s step-end infinite;
    color: var(--accent-primary);
}

@keyframes blink {
    50% { opacity: 0; }
}

/* --- Tool status (pill) --- */
.tool-status {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    padding: var(--space-2) var(--space-3);
    background: var(--surface-secondary);
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    align-self: flex-start;
}

.tool-status .spinner {
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* --- Tool indicator (expanded card) --- */
.tool-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--surface-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin: var(--space-2) 0;
    animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.tool-indicator-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.tool-indicator-icon.search { background: rgba(99,102,241,0.12); }
.tool-indicator-icon.code { background: rgba(52,211,153,0.12); }
.tool-indicator-icon.file { background: rgba(251,191,36,0.12); }

.tool-info { flex: 1; }
.tool-name { font-weight: 600; color: var(--text-primary); display: block; }
.tool-detail { color: var(--text-tertiary); margin-top: 1px; }

.tool-duration {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.tool-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}

.tool-check {
    color: var(--accent-success);
    font-weight: bold;
    flex-shrink: 0;
}

/* --- Sidebar agent dot --- */
.sidebar-agent-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-success);
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(52,211,153,0.4);
    animation: agentPulse 2s ease infinite;
}

@keyframes agentPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Typing indicator --- */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: var(--space-3) var(--space-4);
    align-self: flex-start;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* --- Chat Input --- */
.chat-input-area {
    padding: var(--space-4) var(--space-6);
    background: var(--surface-primary);
    position: relative;
}

.chat-input-fade {
    position: absolute;
    top: -40px;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(transparent, var(--surface-primary));
    pointer-events: none;
}

.chat-input-container {
    max-width: 48rem;
    margin: 0 auto;
    border: 1px solid var(--border-default);
    border-radius: 1rem;
    background: var(--surface-primary);
    box-shadow: var(--shadow-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    overflow: hidden;
}

.chat-input-container:focus-within {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md), 0 0 0 3px var(--focus-ring);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
}

.chat-input-wrapper textarea {
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    resize: none;
    padding: 0;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    border: none;
    background: transparent;
    color: var(--text-primary);
    line-height: 1.5;
}

.chat-input-wrapper textarea:focus {
    outline: none;
    box-shadow: none;
}

.chat-input-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-shrink: 0;
}

.chat-send-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--accent-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) { background: var(--accent-primary-hover); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-send-btn svg {
    width: 16px;
    height: 16px;
}

.attach-btn {
    background: none;
    border: none;
    padding: var(--space-1);
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 1.1rem;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover { color: var(--text-primary); background: var(--surface-hover); }

.chat-input-hint {
    text-align: center;
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    padding-top: var(--space-2);
}

/* File upload */
.file-upload-area {
    padding: var(--space-2) var(--space-4) 0;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: var(--surface-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.file-chip button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    margin-left: var(--space-1);
}
.file-chip button:hover { color: var(--accent-danger); }

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-16) var(--space-6);
    color: var(--text-secondary);
    flex: 1;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-4);
    opacity: 0.8;
}

.empty-state h3 {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    font-size: var(--text-xl);
}

.empty-state p {
    max-width: 400px;
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--text-secondary);
}

.suggestion-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    margin-top: var(--space-6);
    max-width: 500px;
    width: 100%;
}

.suggestion-card {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    background: var(--surface-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.4;
    font-family: var(--font-sans);
}

.suggestion-card:hover {
    background: var(--surface-hover);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

/* --- File Cards (agent output) --- */
.file-cards {
    align-self: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    max-width: min(480px, 90%);
    margin: var(--space-2) 0;
}

.file-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--surface-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text-primary);
    font-size: var(--text-sm);
    transition: all var(--transition-fast);
    cursor: pointer;
    min-width: 240px;
}

.file-card:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.file-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    font-size: 1.25rem;
    flex-shrink: 0;
}
.file-card-icon.icon-image { background: rgba(139, 92, 246, 0.12); }
.file-card-icon.icon-document { background: rgba(37, 99, 235, 0.12); }
.file-card-icon.icon-spreadsheet { background: rgba(5, 150, 105, 0.12); }
.file-card-icon.icon-file { background: rgba(107, 114, 128, 0.12); }

.file-card-info {
    flex: 1;
    min-width: 0;
}

.file-card-name {
    font-weight: 600;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-card-meta {
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    display: flex;
    gap: var(--space-2);
    margin-top: 2px;
}

.file-card-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--surface-hover);
    color: var(--accent-primary);
    font-size: 0.875rem;
    flex-shrink: 0;
    transition: background var(--transition-fast);
}
.file-card:hover .file-card-action {
    background: var(--accent-primary);
    color: white;
}

/* Image preview */
.file-preview {
    align-self: flex-start;
    max-width: min(480px, 90%);
    margin: var(--space-2) 0;
}

.file-preview img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-default);
    cursor: pointer;
    transition: box-shadow var(--transition-fast);
}

.file-preview img:hover {
    box-shadow: var(--shadow-lg);
}

/* User message file attachments */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-top: var(--space-2);
    justify-content: flex-end;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    color: var(--user-bubble-text);
    opacity: 0.85;
    text-decoration: none;
    transition: opacity var(--transition-fast);
    cursor: pointer;
}
.attachment-chip:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.25);
}
.attachment-chip-icon { font-size: 0.75rem; }

/* Upload success indicator */
.upload-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.upload-status .check-icon {
    color: var(--accent-success);
    font-weight: bold;
}

/* --- File list --- */
.file-list {
    list-style: none;
}

.file-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--text-sm);
}

/* Language toggle (now inside .login-controls) */

/* --- Scroll-to-bottom button --- */
.scroll-bottom-btn {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-2) var(--space-4);
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    display: none;
    align-items: center;
    gap: var(--space-1);
    z-index: 10;
    transition: all var(--transition-fast);
}

.scroll-bottom-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.scroll-bottom-btn.visible { display: flex; }

/* --- Toast System --- */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    color: var(--text-primary);
    pointer-events: auto;
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 380px;
}

.toast.removing {
    animation: toastOut 0.2s ease forwards;
}

.toast-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.toast-success .toast-icon { color: var(--accent-success); }
.toast-error .toast-icon { color: var(--accent-danger); }
.toast-warning .toast-icon { color: var(--accent-warning); }
.toast-info .toast-icon { color: var(--accent-primary); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    to { opacity: 0; transform: translateY(8px) scale(0.95); }
}

/* --- Skeleton Screens --- */
.skeleton {
    background: linear-gradient(90deg,
        var(--surface-secondary) 25%,
        var(--surface-hover) 50%,
        var(--surface-secondary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
    margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-card {
    height: 80px;
    margin-bottom: var(--space-3);
}

/* --- Command Palette --- */
.cmd-palette-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
    display: none;
    animation: fadeIn 0.15s ease;
}

.cmd-palette-backdrop.open { display: block; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cmd-palette {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 520px;
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    display: none;
    overflow: hidden;
    animation: cmdIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.cmd-palette.open { display: block; }

@keyframes cmdIn {
    from { opacity: 0; transform: translateX(-50%) scale(0.95); }
    to { opacity: 1; transform: translateX(-50%) scale(1); }
}

.cmd-palette-search {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.cmd-palette-search input {
    border: none;
    background: none;
    width: 100%;
    font-size: var(--text-base);
    color: var(--text-primary);
    padding: 0;
}

.cmd-palette-search input:focus {
    outline: none;
    box-shadow: none;
}

.cmd-palette-search input::placeholder {
    color: var(--text-tertiary);
}

.cmd-palette-results {
    max-height: 320px;
    overflow-y: auto;
    padding: var(--space-2);
}

.cmd-palette-group-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2) var(--space-3);
}

.cmd-palette-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.cmd-palette-item:hover,
.cmd-palette-item.selected {
    background: var(--surface-hover);
}

.cmd-palette-item-icon {
    font-size: 1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.cmd-palette-item-label { flex: 1; }

.cmd-palette-item-shortcut {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

/* --- Drag & Drop visual --- */
.chat-main.dragover {
    outline: 2px dashed var(--accent-primary);
    outline-offset: -4px;
    background: var(--accent-primary-light);
}

/* --- Builder Wizard --- */
.builder-layout {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
    animation: pageIn 0.3s ease;
}

.builder-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: var(--space-8);
}

.builder-step {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    font-weight: 500;
}

.builder-step.active {
    color: var(--text-primary);
}

.builder-step.completed {
    color: var(--accent-success);
}

.builder-step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: 600;
    border: 2px solid var(--border-default);
    color: var(--text-tertiary);
    transition: all var(--transition-normal);
}

.builder-step.active .builder-step-number {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: white;
    box-shadow: 0 0 0 4px var(--accent-primary-light);
}

.builder-step.completed .builder-step-number {
    border-color: var(--accent-success);
    background: var(--accent-success-light);
    color: var(--accent-success);
}

.builder-step-divider {
    width: 60px;
    height: 2px;
    background: var(--border-default);
    margin: 0 var(--space-3);
    transition: background var(--transition-normal);
}

.builder-step-divider.completed {
    background: var(--accent-success);
}

/* Builder — Describe Step */
.builder-describe {
    text-align: center;
}

.builder-describe h1 {
    font-size: var(--text-3xl);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.builder-describe > p {
    color: var(--text-secondary);
    font-size: var(--text-base);
    margin-bottom: var(--space-8);
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.builder-textarea-wrapper {
    position: relative;
    max-width: 640px;
    margin: 0 auto var(--space-6);
}

.builder-textarea {
    width: 100%;
    min-height: 140px;
    padding: var(--space-5) var(--space-5);
    font-family: var(--font-sans) !important;
    font-size: var(--text-base) !important;
    line-height: 1.6;
    border: 2px solid var(--border-default);
    border-radius: var(--radius-xl);
    background: var(--surface-primary);
    color: var(--text-primary);
    resize: vertical;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.builder-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px var(--focus-ring);
}

.builder-textarea::placeholder {
    color: var(--text-tertiary);
}

.builder-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-8);
}

.builder-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-4);
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
    white-space: nowrap;
}

.builder-chip:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-primary-light);
}

.builder-chip.selected {
    border-color: var(--accent-primary);
    color: white;
    background: var(--accent-primary);
}

.builder-generate-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-8);
    font-size: var(--text-base);
    font-weight: 600;
    border-radius: var(--radius-xl);
    background: var(--accent-primary);
    color: white;
    border: none;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: var(--font-sans);
}

.builder-generate-btn:hover:not(:disabled) {
    background: var(--accent-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.builder-generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.builder-generate-btn .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Builder — Configure Step */
.builder-configure {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: var(--space-6);
    align-items: start;
}

.builder-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.builder-form .form-group {
    margin-bottom: 0;
    animation: fadeInUp 0.4s ease both;
}

.builder-form .form-group:nth-child(1) { animation-delay: 0.05s; }
.builder-form .form-group:nth-child(2) { animation-delay: 0.1s; }
.builder-form .form-group:nth-child(3) { animation-delay: 0.15s; }
.builder-form .form-group:nth-child(4) { animation-delay: 0.2s; }
.builder-form .form-group:nth-child(5) { animation-delay: 0.25s; }
.builder-form .form-group:nth-child(6) { animation-delay: 0.3s; }
.builder-form .form-group:nth-child(7) { animation-delay: 0.35s; }

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

.builder-form .form-group label {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.builder-ai-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px 8px;
    font-size: var(--text-xs);
    color: var(--accent-primary);
    background: var(--accent-primary-light);
    border: 1px solid var(--accent-primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 500;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.builder-ai-btn:hover {
    background: var(--accent-primary);
    color: white;
}

.builder-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--surface-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    min-height: 44px;
}

.builder-tag {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    background: var(--accent-primary-light);
    color: var(--accent-primary);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 500;
}

.builder-tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--accent-primary);
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.6;
}

.builder-tag-remove:hover {
    opacity: 1;
}

.builder-tag-input {
    border: none !important;
    background: transparent !important;
    color: var(--text-primary) !important;
    font-size: var(--text-sm) !important;
    font-family: var(--font-sans) !important;
    outline: none !important;
    flex: 1;
    min-width: 150px;
    padding: var(--space-1) 0 !important;
}

.builder-tag-input:focus {
    box-shadow: none !important;
}

/* Builder preview panel */
.builder-preview {
    position: sticky;
    top: 72px;
}

.builder-preview-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.builder-preview-header {
    padding: var(--space-3) var(--space-4);
    background: var(--surface-secondary);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--text-sm);
    font-weight: 600;
}

.builder-preview-header .live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-success);
    display: inline-block;
    margin-right: 4px;
    animation: agentPulse 2s infinite;
}

.builder-preview-chat {
    height: 320px;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    font-size: var(--text-sm);
}

.builder-preview-input {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: var(--space-2);
}

.builder-preview-input input {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    background: var(--surface-primary);
    color: var(--text-primary);
}

/* Builder — Inline validation hints */
.field-hint {
    font-size: var(--text-xs);
    margin-top: var(--space-1);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.field-hint.warning {
    color: var(--accent-warning);
}

.field-hint.error {
    color: var(--accent-danger);
}

.field-hint.success {
    color: var(--accent-success);
}

/* Builder — Tools Step */
.builder-tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-4);
}

.tool-group-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    transition: all var(--transition-fast);
}

.tool-group-card.enabled {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

.tool-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
}

.tool-group-header h3 {
    font-size: var(--text-base);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.tool-group-header .tool-icon {
    font-size: 1.25rem;
}

.tool-group-desc {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border-default);
    border-radius: var(--radius-full);
    transition: background var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* Tool safety panel */
.tool-safety {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tool-safety-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* Builder — Knowledge section */
.builder-knowledge {
    margin-top: var(--space-8);
}

.knowledge-sources {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.knowledge-source-card {
    background: var(--surface-primary);
    border: 2px dashed var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.knowledge-source-card:hover {
    border-color: var(--accent-primary);
    background: var(--accent-primary-light);
}

.knowledge-source-card .source-icon {
    font-size: 2rem;
    margin-bottom: var(--space-2);
}

.knowledge-source-card h4 {
    font-size: var(--text-sm);
    font-weight: 600;
    margin-bottom: var(--space-1);
}

.knowledge-source-card p {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* Builder action bar */
.builder-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-8);
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-subtle);
}

/* Gallery page */
.gallery-header {
    text-align: center;
    margin-bottom: var(--space-8);
}

.gallery-header h1 {
    font-size: var(--text-3xl);
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: var(--space-2);
}

.gallery-header p {
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-5);
}

.gallery-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    transition: all var(--transition-normal);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
}

.gallery-card:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.gallery-card-icon {
    font-size: 2rem;
    margin-bottom: var(--space-3);
}

.gallery-card-category {
    font-size: var(--text-xs);
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.gallery-card h3 {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.gallery-card p {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
}

.gallery-card-tools {
    display: flex;
    gap: var(--space-1);
    margin-top: var(--space-4);
    flex-wrap: wrap;
}

.gallery-card-tool {
    padding: 2px var(--space-2);
    font-size: var(--text-xs);
    background: var(--surface-secondary);
    border-radius: var(--radius-full);
    color: var(--text-tertiary);
}

.gallery-card-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

/* Staggered entrance animation */
@keyframes staggerIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.stagger-in > * {
    animation: staggerIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.stagger-in > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-in > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-in > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-in > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-in > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-in > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-in > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-in > *:nth-child(8) { animation-delay: 0.4s; }
.stagger-in > *:nth-child(9) { animation-delay: 0.45s; }
.stagger-in > *:nth-child(10) { animation-delay: 0.5s; }
.stagger-in > *:nth-child(11) { animation-delay: 0.55s; }
.stagger-in > *:nth-child(12) { animation-delay: 0.6s; }

/* Spec generation animation */
@keyframes specReveal {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.spec-reveal {
    animation: specReveal 0.3s ease backwards;
}

/* --- Playground (3-panel testing) --- */

.playground-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px); /* subtract navbar */
    overflow: hidden;
}

.playground-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    background: var(--surface-secondary);
    flex-shrink: 0;
}

.playground-panels {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.playground-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.playground-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    font-size: var(--text-sm);
    font-weight: 600;
    flex-shrink: 0;
    background: var(--surface-secondary);
}

.playground-divider {
    width: 4px;
    cursor: col-resize;
    background: var(--border-default);
    flex-shrink: 0;
    transition: background 0.15s;
}

.playground-divider:hover,
.playground-divider.dragging {
    background: var(--accent-primary);
}

/* Chat panel */

.playground-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.playground-messages .message {
    max-width: 100%;
}

.playground-input {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--border-default);
    background: var(--surface-secondary);
}

.playground-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-2);
    font-size: var(--text-sm);
    font-family: inherit;
    background: var(--surface-primary);
    color: var(--text-primary);
    min-height: 36px;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s;
}

.playground-input textarea:focus {
    border-color: var(--accent-primary);
}

.playground-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8) var(--space-4);
    color: var(--text-tertiary);
    text-align: center;
    flex: 1;
}

.playground-empty-icon {
    font-size: 2rem;
    margin-bottom: var(--space-2);
    opacity: 0.4;
}

.playground-empty p {
    margin: 0;
    font-size: var(--text-sm);
}

/* Trace panel */

.playground-trace {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
}

.trace-timer {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--accent-success);
    font-weight: 500;
}

.trace-step {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--accent-primary);
    background: var(--surface-secondary);
    transition: background 0.15s, opacity 0.2s, transform 0.2s;
    animation: traceSlideIn 0.3s ease backwards;
}

@keyframes traceSlideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

.trace-step:hover {
    background: var(--surface-secondary);
}

.trace-step-time {
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    min-width: 40px;
    text-align: right;
    flex-shrink: 0;
}

.trace-step-icon {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

.trace-step-content {
    flex: 1;
    min-width: 0;
}

.trace-step-name {
    font-weight: 600;
    color: var(--text-primary);
}

.trace-step-detail {
    color: var(--text-secondary);
    word-break: break-all;
    margin-top: 1px;
}

.trace-step-expanded {
    display: none;
    margin-top: var(--space-1);
    padding: var(--space-2);
    background: var(--surface-primary);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
    max-height: 200px;
    overflow-y: auto;
}

.trace-step.expanded .trace-step-expanded {
    display: block;
}

.trace-step-duration {
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    flex-shrink: 0;
    min-width: 40px;
    text-align: right;
}

.trace-step.running .trace-step-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.trace-step.error {
    border-left-color: var(--accent-danger);
}

.trace-step.error .trace-step-name {
    color: var(--accent-danger);
}

.trace-step.done,
.trace-step.ok {
    border-left-color: var(--accent-success);
}

.trace-step.done .trace-step-name,
.trace-step.ok .trace-step-name {
    color: var(--accent-success);
}

.trace-step.running {
    border-left-color: var(--accent-warning);
}

/* Explain panel */

.playground-explain {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.explain-section {
    margin-bottom: var(--space-4);
}

.explain-section h4 {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin: 0 0 var(--space-2);
}

.explain-code {
    font-family: var(--font-mono);
    font-size: 10px;
    line-height: 1.5;
    background: var(--code-bg, var(--surface-primary));
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 120px;
    overflow-y: auto;
    color: var(--code-text, var(--text-secondary));
    margin: 0;
}

.explain-tools {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.tool-badge {
    font-size: 10px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--accent-primary-light);
    color: var(--accent-primary);
}

.cost-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
}

.cost-item {
    padding: var(--space-2) var(--space-3);
    background: var(--surface-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.cost-item-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cost-item-value {
    font-size: var(--text-sm);
    font-weight: 600;
    font-family: var(--font-mono);
    margin-top: 2px;
}

.cost-item-value.green {
    color: var(--accent-success);
}

.explain-cost {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}

/* Footer: Test Cases & Versions */

.playground-footer {
    border-top: 1px solid var(--border-default);
    background: var(--surface-secondary);
    flex-shrink: 0;
    max-height: 200px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.playground-tabs {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    border-bottom: 1px solid var(--border-default);
}

.playground-tab {
    background: none;
    border: none;
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.playground-tab:hover {
    color: var(--text-primary);
}

.playground-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.playground-tab-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2) var(--space-3);
}

/* Test case items */

.test-case-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--text-xs);
    transition: opacity 0.2s, transform 0.2s;
}

.test-case-item:last-child {
    border-bottom: none;
}

.test-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.test-status.pass { background: var(--accent-success); }
.test-status.fail { background: var(--accent-danger); }
.test-status.pending { background: var(--text-tertiary); }

.test-name {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
}

.test-time {
    font-family: var(--font-mono);
    color: var(--text-tertiary);
}

.test-action {
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--surface-hover);
    border: none;
    color: var(--text-secondary);
    font-size: 10px;
    cursor: pointer;
}

.test-action:hover {
    background: var(--accent-primary-light);
    color: var(--accent-primary);
}

.test-case-result {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-tertiary);
}

.test-case-result.pass { background: var(--accent-success, #22c55e); }
.test-case-result.fail { background: var(--accent-danger); }
.test-case-result.pending { background: var(--text-tertiary); opacity: 0.5; }

.test-case-name {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    margin-right: var(--space-2);
}

.test-case-prompt {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.test-case-actions {
    display: flex;
    gap: var(--space-1);
    flex-shrink: 0;
}

/* Version items */

.version-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-1) 0;
    border-bottom: 1px solid var(--border-light, var(--border-default));
    font-size: var(--text-xs);
}

.version-item:last-child {
    border-bottom: none;
}

.version-number {
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.version-date {
    color: var(--text-tertiary);
}

.version-item.active {
    background: rgba(99, 102, 241, 0.05);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    margin: 0 calc(-1 * var(--space-2));
}


/* --- Mobile Hamburger + Nav Drawer --- */
.mobile-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.mobile-hamburger:hover {
    background: var(--surface-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.mobile-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 52px;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.mobile-nav-backdrop.open {
    display: block;
    opacity: 1;
}

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

/* --- Responsive --- */
@media (max-width: 768px) {
    .mobile-hamburger {
        display: flex;
    }

    .navbar-nav {
        position: fixed;
        top: 52px;
        right: 0;
        bottom: 0;
        width: 280px;
        background: var(--surface-primary);
        border-left: 1px solid var(--border-default);
        flex-direction: column;
        padding: var(--space-4);
        gap: var(--space-1);
        z-index: 100;
        transform: translateX(100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
        overflow-y: auto;
    }

    .navbar-nav.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .navbar-nav li a {
        display: block;
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-md);
        font-size: var(--text-base);
    }

    .navbar-nav li a:hover,
    .navbar-nav li a.active {
        background: var(--accent-primary-light);
    }

    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 52px;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        box-shadow: none;
    }

    .chat-sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        top: 52px;
        background: rgba(0, 0, 0, 0.3);
        z-index: 49;
        display: none;
    }

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

    .mobile-sidebar-toggle {
        display: flex;
    }

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

    .builder-configure {
        grid-template-columns: 1fr;
    }

    .builder-preview {
        position: static;
    }

    .builder-steps {
        gap: 0;
    }

    .builder-step span:not(.builder-step-number) {
        display: none;
    }

    .builder-step-divider {
        width: 32px;
    }

    .builder-tools-grid {
        grid-template-columns: 1fr;
    }

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

    .builder-layout {
        padding: var(--space-4);
    }

    .container { padding: var(--space-4); }

    .chat-input-area { padding: var(--space-3); }

    .chat-messages { padding: var(--space-4); }

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

    .navbar-nav { display: none; }

    .navbar-user span:not(.usage-pill) { display: none; }

    /* Users page responsive */
    .users-add-grid {
        grid-template-columns: 1fr !important;
    }

    /* Playground: stack panels vertically on mobile */
    .playground-panels {
        flex-direction: column;
    }

    .playground-panel {
        flex: none !important;
        width: 100% !important;
        max-height: 40vh;
    }

    .playground-divider {
        width: 100%;
        height: 4px;
        cursor: row-resize;
    }

    #panel-trace,
    #panel-explain {
        max-height: 25vh;
    }

    /* Admin: table → cards on mobile */
    .desktop-table { display: none; }
    .mobile-cards { display: block; }

    .add-user-grid {
        grid-template-columns: 1fr 1fr;
    }

    .add-user-grid .form-group:nth-child(3) {
        grid-column: 1 / -1;
    }
}

@media (max-width: 480px) {
    .chat-input-hint { display: none; }
    .add-user-grid { grid-template-columns: 1fr; }
}
