/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent iOS Safari from auto-zooming on focused inputs (requires font-size >= 16px) */
input, textarea, select {
    font-size: 16px;
}



/* Dark mode overrides */
[data-theme="dark"] {
    --color-primary: #818cf8;
    --color-primary-hover: #6366f1;
    --color-primary-light: rgba(129, 140, 248, 0.12);
    --color-text-secondary: #64748b;
    --color-success: #6ee7b7;
    --color-success-light: rgba(110, 231, 183, 0.1);
    --color-warning: #fcd34d;
    --color-warning-light: rgba(252, 211, 77, 0.1);
    --color-danger: #fda4af;
    --color-danger-light: rgba(251, 113, 133, 0.1);
    --color-bg-secondary: #0f172a;
    --color-bg-surface: #293548;
    --color-bg-primary: #1e293b;
    --color-text-primary: #e2e8f0;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    /* accent-color is dashboard-specific */
    --accent-color: #22d3ee;
}

[data-theme="dark"] img[src*="logo.svg"] {
    filter: brightness(0) invert(0.9);
}

[data-theme="dark"] .modal {
    background: var(--color-bg-primary);
}

[data-theme="dark"] .logs-content {
    background: #0f172a;
    color: #c7d2fe;
    border: 1px solid var(--color-border);
}

[data-theme="dark"] .log-entry {
    border-bottom-color: #1e293b;
}

[data-theme="dark"] .diff-modal {
    background: var(--color-bg-primary);
}

[data-theme="dark"] .nav {
    background: #1e293b;
    border-bottom-color: var(--color-border);
}

[data-theme="dark"] .header {
    background: #0f172a;
    border-bottom-color: var(--color-border);
}

[data-theme="dark"] select,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] textarea {
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

[data-theme="dark"] code {
    background: #0f172a;
    color: #c7d2fe;
}

[data-theme="dark"] .board-setup-banner--success {
    color: var(--color-success);
}
[data-theme="dark"] .board-setup-item--step {
    color: var(--color-success);
}
[data-theme="dark"] .board-setup-item--warning {
    color: var(--color-warning);
}
[data-theme="dark"] .board-setup-item--error {
    color: var(--color-danger);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    line-height: 1.6;
    transition: background-color 0.2s, color 0.2s;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Fixed Control Panel */
.control-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 260px;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 900;
    max-height: calc(100vh - 100px);
    display: flex;
    flex-direction: column-reverse;
}

.control-panel.hidden {
    display: none;
}

.control-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--color-primary);
    color: white;
    border-radius: 0 0 0.5rem 0.5rem;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.control-panel-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: white;
}

.control-panel-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.control-panel-toggle:hover {
    opacity: 0.8;
}

.control-panel-content {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.control-panel.collapsed .control-panel-content {
    display: none;
}

.control-panel.collapsed {
    flex-direction: row;
}

.control-panel.collapsed .control-panel-header {
    border-radius: 0.5rem;
    width: 100%;
}

.control-section {
    margin-bottom: 1.5rem;
}

.control-section:last-child {
    margin-bottom: 0;
}

.control-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-block {
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-block:last-child {
    margin-bottom: 0;
}

.status-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--color-bg-secondary);
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
}

.scheduler-status-display {
    padding: 0.75rem;
    background: var(--color-bg-secondary);
    border-radius: 0.25rem;
    font-size: 0.875rem;
    text-align: center;
    margin-bottom: 0.75rem;
}

.scheduler-controls {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex: 1;
    padding: 0.5rem 0.75rem;
}

.btn-icon .icon {
    font-size: 1rem;
    line-height: 1;
}

/* Header */
.header {
    background: var(--color-bg-primary);
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 0;
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 600;
}

.header .container {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* User profile + org switcher pinned to the far right of the header on all screen sizes */
.header-user-area {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
}

.status-indicator {
    font-size: 1.5rem;
    animation: pulse 2s ease-in-out infinite;
}

.status-indicator.online {
    color: var(--color-success);
}

.status-indicator.offline {
    color: var(--color-danger);
}

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

/* Global Queue Banner */
.global-queue-banner {
    background: var(--color-warning-light);
    border-bottom: 2px solid var(--color-warning);
    padding: 1rem 0;
}

.global-queue-banner .container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.global-queue-banner .queue-banner-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.global-queue-banner .queue-banner-content {
    flex: 1;
}

.global-queue-banner .queue-banner-content strong {
    display: block;
    font-size: 1rem;
    color: var(--color-text-primary);
    margin-bottom: 0.25rem;
}

.global-queue-banner .queue-banner-content p {
    margin: 0;
    color: var(--color-text-primary);
    font-size: var(--text-base);
}

.global-queue-banner .queue-banner-content code {
    background: rgba(245, 158, 11, 0.2);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    border: 1px solid var(--color-warning);
}

/* Navigation */
.nav {
    background: var(--color-bg-primary);
    border-bottom: 1px solid var(--color-border);
    padding: 0.5rem 0;
    position: relative;
    z-index: 20; /* sit above the fixed chat panel (z-index:10) */
}

.nav .container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn {
    background: none;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 0.5rem;
    transition: all 0.2s;
    color: var(--color-text-muted);
    position: relative;
}

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

.nav-btn.active {
    background: var(--color-primary);
    color: white;
}

.nav-badge {
    display: inline-block;
    background: var(--color-danger);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    margin-left: 0.5rem;
    min-width: 20px;
    text-align: center;
}

.nav-btn.active .nav-badge {
    background: white;
    color: var(--color-primary);
}

.nav-signout {
    background: none;
    border: 1px solid transparent;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--radius-md);
    transition: color 0.2s, border-color 0.2s;
}
.nav-signout:hover {
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

/* Main Content */
.main {
    padding: 2rem 0;
    min-height: calc(100vh - 200px);
}

.page {
    display: none;
}

/* Chat page fills full height below nav -- no outer scroll */
/*
 * Chat page layout: fixed position covering the viewport below the nav.
 * This breaks out of the normal page flow entirely so nothing above
 * (main padding, banners, container) can push it or cause scrolling.
 * The flex column (header -> scrollable messages -> fixed input) is
 * self-contained and does not depend on parent height calculations.
 */
.page-chat-fullheight {
    display: none;
}
.page-chat-fullheight.active {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background: var(--color-bg-secondary);
    padding: 1rem;
    overflow: hidden;
    /* top is set dynamically by JS to sit below the nav bar */
}
.page-chat-fullheight #chat-content {
    flex: 1 1 0;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
/* The messages area is the ONLY scrollable thing on the chat page */
.page-chat-fullheight .chat-messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page.active {
    display: block;
}

/* Sections */
section {
    background: var(--color-bg-primary);
    border-radius: 0.5rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}

h2 {
    font-size: var(--text-2xl);
    margin-bottom: 1rem;
    color: var(--color-text-primary);
}

h3 {
    font-size: var(--text-xl);
    margin-bottom: 1rem;
    color: var(--color-text-primary);
}

h4 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
    color: var(--color-text-primary);
}

.page-description {
    color: var(--color-text-muted);
    margin-bottom: 2rem;
}

.page-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.metric-card {
    background: var(--color-bg-secondary);
    padding: 1.5rem;
    border-radius: 0.5rem;
    border: 1px solid var(--color-border);
}

.metric-label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
}

/* Activity Info */
.activity-info {
    background: var(--color-bg-secondary);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.activity-info p {
    margin-bottom: 0.5rem;
}

/* Actions */
.actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

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

.btn-secondary {
    background: var(--color-text-secondary);
    color: white;
}

.btn-secondary:hover {
    background: #64748b;
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

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

.btn-danger:hover {
    background: #e11d48;
}

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

.scheduler-status {
    font-weight: 600;
}

.scheduler-status.running {
    color: var(--color-success);
}

.scheduler-status.stopped {
    color: var(--color-danger);
}

/* ============================================================================
   MODAL STYLES
   ============================================================================ */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease-in-out;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    animation: slideIn 0.3s ease-out;
}

.modal--wide {
    max-width: 680px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--color-text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body > div {
    margin: 0;
    color: var(--color-text-primary);
    line-height: 1.6;
}

.modal-detail {
    margin-top: 1rem;
    width: 100%;
    min-height: 160px;
    max-height: 320px;
    resize: vertical;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.75rem;
    font-family: monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    box-sizing: border-box;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Board Setup Result Modal */
.board-setup-result {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.board-setup-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
}

.board-setup-banner--success {
    background: var(--color-success-light);
    color: #065f46;
    border: 1px solid var(--color-success);
}

.board-setup-banner--warning {
    background: var(--color-warning-light);
    color: #92400e;
    border: 1px solid var(--color-warning);
}

.board-setup-banner--error {
    background: var(--color-danger-light);
    color: #991b1b;
    border: 1px solid var(--color-danger);
}

.board-setup-banner-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.board-setup-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.board-setup-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.board-setup-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.45rem 0.6rem;
    border-radius: 5px;
    font-size: 0.855rem;
    line-height: 1.45;
}

.board-setup-item--step {
    background: var(--color-success-light);
    color: #166534;
}

.board-setup-item--warning {
    background: var(--color-warning-light);
    color: #92400e;
}

.board-setup-item--error {
    background: var(--color-danger-light);
    color: #991b1b;
}

.board-setup-item-icon {
    flex-shrink: 0;
    font-size: 0.85rem;
    margin-top: 1px;
}

.board-setup-scroll {
    max-height: 340px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 2px;
}

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

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

/* Agents List */
.agents-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.pipeline-group {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.pipeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.pipeline-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.pipeline-summary {
    display: flex;
    gap: 1rem;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.agents-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.agents-table thead th {
    padding: 0.6rem 1rem;
    text-align: left;
    font-weight: 500;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--color-border);
}

.agents-table thead th:nth-child(n+2) {
    text-align: center;
}

.agents-table tbody td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.agents-table tbody td:nth-child(n+2) {
    text-align: center;
}

.agents-table tbody tr:last-child td {
    border-bottom: none;
}

.agent-name-cell {
    font-weight: 500;
    color: var(--color-text-primary);
}

.agent-lastrun {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.brain-row td {
    padding: 0 !important;
    background: var(--color-bg-secondary);
}

.brain-row .brain-content {
    padding: 1rem 1.25rem;
    font-family: monospace;
    font-size: var(--text-xs);
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
    color: var(--color-text-muted);
}

.brain-toggle {
    background: none;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-xs);
    transition: color 0.2s, border-color 0.2s;
}

.brain-toggle:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.agents-pipeline-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    margin: 24px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--color-border);
}

.agents-pipeline-header:first-child {
    margin-top: 0;
}

.agent-card {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.agent-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.agent-name {
    font-size: 1.25rem;
    font-weight: 600;
}

.agent-status {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    background: var(--color-success);
    color: white;
}

.agent-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.agent-metric {
    text-align: center;
}

.agent-metric-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.agent-metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
}

.agent-brain {
    margin-top: 1rem;
}

.brain-toggle {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-size: 1rem;
}

.brain-content {
    display: none;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--color-bg-secondary);
    border-radius: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

.brain-content.show {
    display: block;
}

/* Settings */
.settings-content {
    display: grid;
    gap: 2rem;
}

.setting-group {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}

.setting-group h3 {
    margin-bottom: 1rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
}

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

.setting-label {
    font-weight: 500;
}

.project-card:hover {
    border-color: var(--color-primary);
}

.setting-value {
    color: var(--color-text-muted);
    font-family: 'Courier New', monospace;
}

/* Logs */
.logs-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.form-select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    font-size: 1rem;
    background: var(--color-bg-primary);
}

.logs-content {
    background: #1e1b4b;
    color: #e0e7ff;
    padding: 1.5rem;
    border-radius: var(--radius-md);
    max-height: 600px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: var(--text-sm);
}

.log-entry {
    padding: 0.25rem 0;
    border-bottom: 1px solid #312e81;
}

.log-entry:last-child {
    border-bottom: none;
}
.log-entry.log-error {
    color: var(--color-danger);
}
.log-entry.log-warn {
    color: var(--color-warning);
}
.log-ts {
    color: var(--color-text-muted);
}
.log-lvl-info {
    color: var(--color-primary);
}
.log-lvl-error {
    color: var(--color-danger);
    font-weight: 600;
}
.log-lvl-warn {
    color: var(--color-warning);
    font-weight: 600;
}
.log-agent {
    color: var(--color-success);
}
.log-json {
    color: var(--color-text-muted);
    font-size: 0.85em;
}

/* Footer */
.footer {
    background: var(--color-bg-primary);
    border-top: 1px solid var(--color-border);
    padding: 2rem 0;
    text-align: center;
    color: var(--color-text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    /* Nav is tabs-only; keep as a row and tighten padding to fit on small screens */
    .nav .container {
        flex-wrap: wrap;
        gap: 0;
    }

    /* Tighten nav button padding so all 4 tabs fit on a 390px screen */
    .nav-btn {
        padding: 0.5rem 0.6rem;
        font-size: 0.72rem;
    }

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

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

    /* Settings page: reduce outer padding so content has more room */
    .main {
        padding: 1rem 0;
    }

    /* Setting items: allow the label+value pair to wrap so neither overflows */
    .setting-item {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Setting group: tighten padding on narrow screens */
    .setting-group {
        padding: 1rem;
    }

    /* Control panel: cap width so it never overflows the viewport */
    .control-panel {
        width: min(260px, calc(100vw - 40px));
    }
}

/* Phone-specific settings page rules (375px - 480px) */
@media (max-width: 480px) {
    /* Required-setup rows: wrap the "Go to setting" link below the label on
       very narrow screens so nothing gets clipped */
    #required-setup-section > div {
        flex-wrap: wrap;
    }

    /* Soft-gate notice: allow text and dismiss button to stack vertically */
    #settings-soft-gate {
        flex-wrap: wrap;
    }

    /* Reduce container side padding slightly to reclaim space */
    .container {
        padding: 0 12px;
    }
}

/* ── Settings page mobile fixes ── */

/* All inputs, selects, and textareas must never exceed their parent width */
.settings-content input,
.settings-content select,
.settings-content textarea {
    max-width: 100%;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    /* Selects fill the available space and wrap below the label */
    .setting-item select,
    .setting-value select,
    .settings-content select {
        width: 100%;
        font-size: 0.82rem;
    }

    /* Setting value cell: shrink and let its content wrap */
    .setting-value {
        min-width: 0;
        flex-shrink: 1;
        max-width: 100%;
    }

    /* The label side should also shrink gracefully */
    .setting-item > div:first-child {
        min-width: 0;
        flex: 1 1 0;
    }

    /* Collapse any 2-column grid inside integration cards to a single column */
    .integration-card-body [style*="grid-template-columns: 1fr 1fr"],
    .integration-card-body [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Any inline-styled 2-column grid anywhere in settings */
    .settings-content [style*="grid-template-columns: 1fr 1fr"],
    .settings-content [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Make the model-selection table scroll horizontally */
    .setting-item table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    /* Provider selector cards: allow text to wrap */
    .provider-option {
        flex-wrap: wrap;
    }

    /* Ensure setting groups don't overflow */
    .setting-group {
        overflow: hidden;
    }
}

/* Intro Section */
.intro-text {
    font-size: 1.125rem;
    line-height: 1.8;
    color: var(--color-text-muted);
}

/* Workflow Steps */
.workflow-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.step {
    text-align: center;
    padding: 1.5rem;
    border: 2px solid var(--color-border);
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.step:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-lg);
}

.step-number {
    width: 3rem;
    height: 3rem;
    background: var(--color-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 auto 1rem;
}

/* LLM Provider Selector */
.provider-selector {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.provider-option {
    background: var(--color-bg-primary);
    border: 2px solid var(--color-border);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.provider-option:hover:not(.disabled) {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.provider-option.selected {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.provider-option.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--color-bg-secondary);
}

.provider-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.provider-header input[type="radio"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
}

.provider-header strong {
    flex: 1;
    font-size: 1.1rem;
    color: var(--color-text-primary);
}

.provider-status {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-weight: normal;
}

.provider-description {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-left: 2rem;
    line-height: 1.5;
}

.auth-warning {
    margin-top: 1rem;
    margin-left: 2rem;
    padding: 1rem;
    background: var(--color-warning-light);
    border: 1px solid var(--color-warning);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.auth-warning strong {
    display: block;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
    font-size: var(--text-base);
}

.auth-warning p {
    color: var(--color-text-primary);
    margin: 0.5rem 0;
}

.auth-error {
    margin-top: 1rem;
    margin-left: 2rem;
    padding: 1rem;
    background: var(--color-danger-light);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.auth-error strong {
    display: block;
    color: var(--color-danger);
    margin-bottom: 0.5rem;
    font-size: var(--text-base);
}

.auth-error p {
    color: var(--color-text-primary);
    margin: 0.5rem 0;
}

.auth-error .error-detail {
    font-family: 'Courier New', monospace;
    font-size: var(--text-xs);
    background: var(--color-bg-primary);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    margin-top: 0.5rem;
}

.auth-instructions {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--color-bg-primary);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    line-height: 1.6;
}

.auth-instructions div {
    margin: 0.25rem 0;
}

.auth-success {
    margin-top: 1rem;
    margin-left: 2rem;
    padding: 0.75rem 1rem;
    background: var(--color-success-light);
    border: 1px solid var(--color-success);
    border-radius: var(--radius-md);
    color: #065f46;
    font-size: var(--text-sm);
    font-weight: 500;
}

.setting-description {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

/* Loading Spinner */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    min-height: 300px;
}

.loading-container p {
    margin-top: 1.5rem;
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}


/* Chat messages */
.chat-messages {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    padding: 12px 8px;
    text-align: left;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md, 8px);
}

.chat-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
    text-align: left;
}

.chat-msg .chat-label {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    margin-bottom: 2px;
}

.chat-time {
    font-weight: 400;
    opacity: 0.7;
    margin-left: 4px;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--color-primary-light);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-bottom-right-radius: 4px;
    text-align: left;
}

.chat-msg.user.private {
    border: 1px dashed rgba(59, 130, 246, 0.3);
}

.chat-msg.agent {
    align-self: flex-start;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
    text-align: left;
}

.chat-status {
    align-self: center;
    padding: 3px 10px;
    background: var(--color-bg-surface);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.chat-question {
    max-width: 80%;
    padding: 8px 12px;
    border-left: 3px solid #f59e0b;
    border-radius: 0 8px 8px 0;
    background: var(--color-bg-primary);
    font-size: 0.9rem;
}

.chat-question.answered {
    border-left-color: #10b981;
}

.chat-question .chat-answer {
    margin-top: 6px;
    padding: 6px 8px;
    background: rgba(59, 130, 246, 0.05);
    border-radius: 6px;
    font-size: 0.85rem;
}

.chat-typing {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--color-bg-surface);
    border-radius: 12px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Chat typing indicator */
.typing-dots::after {
    content: '';
    animation: typingDots 1.4s steps(4, end) infinite;
}

@keyframes typingDots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}

/* Queue Page Styles */
.queue-info {
    margin-bottom: 2rem;
}

.info-box {
    background: var(--color-primary-light);
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.info-box h3 {
    margin-bottom: 0.5rem;
    color: var(--color-primary);
}

.info-box p {
    color: var(--color-text-primary);
    margin: 0;
}

.queue-banner {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    background: var(--color-warning-light);
    border: 2px solid var(--color-warning);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15);
}

.queue-banner-icon {
    font-size: 2rem;
    line-height: 1;
}

.queue-banner-content {
    flex: 1;
}

.queue-banner-content strong {
    display: block;
    font-size: var(--text-lg);
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
}

.queue-banner-content p {
    margin: 0;
    color: var(--color-text-primary);
    line-height: 1.5;
}

.queue-banner-content code {
    background: rgba(245, 158, 11, 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    border: 1px solid var(--color-warning);
}

.queue-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-bg-primary);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    gap: 0.75rem;
    flex-wrap: wrap;
}

.queue-count {
    font-size: 1rem;
    color: var(--color-text-muted);
    flex: 0 0 auto;
}

.queue-count strong {
    color: var(--color-primary);
    font-size: 1.25rem;
}

.queue-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex: 1;
    justify-content: flex-end;
}

.queue-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.queue-item {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.queue-item-header {
    padding: 1rem;
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
}

.queue-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.queue-item-id {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.queue-item-agent {
    font-weight: 600;
    color: var(--color-primary);
}

.queue-item-time {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.queue-item-body {
    padding: 1rem;
}

.queue-item-prompt pre {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.queue-item-context {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    padding: 0.25rem 0.5rem;
    background: var(--color-warning-light);
    border-radius: var(--radius-sm);
    display: inline-block;
}

.queue-item-details {
    border-top: 1px solid var(--color-border);
}

.queue-item-summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    user-select: none;
    background: var(--color-bg-secondary);
    font-weight: 500;
    color: var(--color-primary);
    transition: background-color 0.2s ease;
    list-style: none;
}

.queue-item-summary::-webkit-details-marker {
    display: none;
}

.queue-item-summary::before {
    content: '▶';
    display: inline-block;
    margin-right: 0.5rem;
    transition: transform 0.2s ease;
    font-size: 0.75rem;
}

.queue-item-details[open] .queue-item-summary::before {
    transform: rotate(90deg);
}

.queue-item-summary:hover {
    background: var(--color-border);
}

.queue-item-details .queue-item-body {
    padding: 1rem;
    background: var(--color-bg-primary);
}

.queue-item-details .queue-item-prompt {
    margin-bottom: 0;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    background: var(--color-bg-primary);
    border: 2px dashed var(--color-border);
    border-radius: 8px;
}

.empty-state p {
    margin: 0.5rem 0;
    color: var(--color-text-muted);
}

.empty-state-hint {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

/* ============================================================
   Project Context Setup Wizard
   ============================================================ */

/* ── Diff / Merge Modal ─────────────────────────────────────────────────── */

.diff-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.diff-overlay.show {
    display: flex;
}

.diff-modal {
    background: var(--color-bg-primary);
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    width: 100%;
    max-width: 1100px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diff-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 18px 20px 12px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.diff-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 2px;
}

.diff-subtitle {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin: 0;
}

.diff-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--color-text-muted);
    line-height: 1;
    padding: 0 4px;
}

.diff-pane-labels {
    display: flex;
    justify-content: space-around;
    padding: 6px 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

#diff-editor {
    flex: 1;
    overflow: hidden;
}

/* Mergely fills its container */
#diff-editor .mergely-container {
    height: 100% !important;
}

.diff-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

/* ── Wizard Overlay ─────────────────────────────────────────────────────── */

.wizard-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.wizard-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.wizard {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    width: 680px;
    max-width: 96vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

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

.wizard-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-text-primary);
}

.wizard-subtitle {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 3px;
}

.wizard-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}

.wizard-close:hover { color: var(--color-text-primary); }

.wizard-progress-track {
    height: 3px;
    background: var(--color-border);
    flex-shrink: 0;
}

.wizard-progress-fill {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.3s ease;
}

.wizard-body {
    overflow-y: auto;
    padding: 24px;
    flex: 1;
}

.wizard-body p.wiz-lead {
    margin: 0 0 18px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.wiz-field {
    margin-bottom: 14px;
}

.wiz-label {
    display: block;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.wiz-input {
    width: 100%;
    padding: 8px 10px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-primary);
    font-size: 16px; /* Prevents iOS zoom on focus */
}

.wiz-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.wiz-hint {
    margin: 4px 0 0;
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

.wiz-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.wiz-step-count {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin-right: 10px;
}

.wiz-env-grid {
    display: grid;
    grid-template-columns: 120px 1fr 1fr;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.wiz-env-grid-header {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.wiz-int-row {
    display: grid;
    grid-template-columns: 1fr 2fr auto;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.wiz-compliance-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 24px;
}

.wiz-compliance-grid label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.wiz-review-md {
    width: 100%;
    height: 360px;
    padding: 12px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-primary);
    font-family: monospace;
    font-size: 0.82rem;
    resize: vertical;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 26px;
    cursor: pointer;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--color-primary);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}
.toggle-switch.toggle-danger input:checked + .toggle-slider {
    background: var(--color-danger, #dc2626);
}

/* Integration cards */
.integration-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 10px;
}

.active-integration {
    border-color: var(--color-primary);
}

.coming-soon-card {
    opacity: 0.55;
}

.integration-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--color-bg-primary);
    gap: 8px;
}

.integration-card-body {
    padding: 12px 14px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Coming-soon provider option */
.provider-option.provider-coming-soon {
    opacity: 0.55;
    pointer-events: none;
}

/* Advanced expander for Project Context */
.advanced-expander {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0;
    overflow: hidden;
}

.advanced-expander-summary {
    padding: 8px 12px;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    user-select: none;
    background: var(--color-bg-secondary);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.advanced-expander-summary::-webkit-details-marker { display: none; }

.advanced-expander-summary::before {
    content: '›';
    font-size: 1rem;
    transition: transform 0.2s;
    display: inline-block;
}

.advanced-expander[open] .advanced-expander-summary::before {
    transform: rotate(90deg);
}

.advanced-expander[open] .advanced-expander-summary {
    border-bottom: 1px solid var(--color-border);
}

.advanced-expander > div {
    padding: 12px;
    background: var(--color-bg-primary);
}

/* ============================================================================
   DOCS PAGE
   ============================================================================ */

.docs-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
}

.docs-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Sidebar nav */
.docs-sidebar {
    position: sticky;
    top: 80px;
}

.docs-search-wrap {
    margin-bottom: 0.75rem;
}

.docs-search {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-size: 16px; /* Prevents iOS zoom on focus */
}

.docs-search:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.docs-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.docs-nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    font-size: var(--text-sm);
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.docs-nav-item:hover {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.docs-nav-item.active {
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 600;
}

.docs-match-count {
    background: var(--color-primary);
    color: #fff;
    border-radius: 9999px;
    font-size: 0.7rem;
    padding: 0 0.4em;
    min-width: 1.4em;
    text-align: center;
    line-height: 1.6;
}

.docs-no-results {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    padding: 0.5rem 0.75rem;
}

/* Content area */
.docs-content {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem 2.25rem;
    min-height: 500px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    line-height: 1.7;
    font-size: var(--text-base);
}

.docs-content h1 { font-size: 1.6rem; color: var(--color-text-primary); margin: 0 0 1rem; border-bottom: 2px solid var(--color-primary); padding-bottom: 0.4rem; }
.docs-content h2 { font-size: 1.2rem; color: var(--color-text-primary); margin: 1.75rem 0 0.6rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.25rem; }
.docs-content h3 { font-size: 1rem; color: var(--color-text-primary); margin: 1.25rem 0 0.4rem; }
.docs-content p  { margin: 0.6rem 0; color: var(--color-text-primary); }
.docs-content ul, .docs-content ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.docs-content li { margin: 0.25rem 0; }
.docs-content code {
    background: var(--color-primary-light);
    color: var(--color-primary);
    border-radius: 3px;
    padding: 0.1em 0.35em;
    font-size: 0.875em;
    font-family: ui-monospace, monospace;
}
.docs-content pre {
    background: var(--color-bg-secondary);
    border-left: 3px solid var(--color-primary);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}
.docs-content pre code {
    background: none;
    color: var(--color-text-primary);
    padding: 0;
    font-size: 0.875rem;
}
.docs-content table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: var(--text-sm); }
.docs-content th { background: var(--color-primary-light); color: var(--color-text-primary); text-align: left; padding: 0.5rem 0.75rem; border: 1px solid var(--color-border); font-weight: 600; }
.docs-content td { padding: 0.45rem 0.75rem; border: 1px solid var(--color-border); }
.docs-content tr:nth-child(even) td { background: var(--color-bg-secondary); }
.docs-content blockquote {
    border-left: 3px solid var(--color-primary);
    margin: 0.75rem 0;
    padding: 0.5rem 1rem;
    background: var(--color-primary-light);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--color-text-muted);
}
.docs-content blockquote p { margin: 0; color: inherit; }
.docs-content hr { border: none; border-top: 1px solid var(--color-border); margin: 1.5rem 0; }
.docs-content a { color: var(--color-primary); }

/* Search highlight */
mark.docs-highlight {
    background: #fde68a;
    color: #92400e;
    border-radius: 2px;
    padding: 0 1px;
}
[data-theme="dark"] mark.docs-highlight {
    background: #78350f;
    color: #fde68a;
}

/* Responsive */
@media (max-width: 768px) {
    .docs-layout {
        grid-template-columns: 1fr;
    }
    .docs-sidebar {
        position: static;
    }
    .docs-content {
        max-height: none;
        padding: 1.25rem;
    }
}

/* Feed item link - used in catch-up home feed */
.feed-item-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem;
    margin-bottom: 6px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
    color: inherit;
}
.feed-item-link:hover {
    background: var(--color-bg-surface);
}

/* User menu org switcher item */
.user-menu-org-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    text-decoration: none;
    transition: background 0.1s;
}
.user-menu-org-item:hover {
    background: var(--color-bg-surface);
}
.user-menu-org-item.is-current {
    font-weight: 600;
}

/* Typing indicator wrapper */
.typing-indicator-wrapper {
    text-align: center;
    padding: 4px 0;
}

/* Disabled option state */
.option-disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Growth Level badge shown over the bottom-right of the user avatar in the header */
.growth-level-badge {
    position: absolute;
    bottom: -6px;
    right: -2px;
    z-index: 1;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: 99px;
    padding: 1px 6px;
    white-space: nowrap;
    line-height: 1.4;
    cursor: pointer;
}
