/* TalkTrough Stylesheet */
/* Based on docs/styleguide.md */

/* === Variables === */
:root {
    --color-primary: #5271ff;
    --color-primary-hover: #3d5bd9;
    --color-primary-light: #e8ecff;
    --color-danger: #dc3545;
    --color-danger-hover: #c82333;
    --color-success: #28a745;
    --color-text: #333333;
    --color-text-muted: #6c757d;
    --color-background: #f8f9fa;
    --color-card: #ffffff;
    --color-border: #dee2e6;

    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
}

/* === Reset === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-background);
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* === Layout === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

.page {
    min-height: 100vh;
}

/* === Navigation === */
.navbar {
    background-color: var(--color-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: var(--space-md) 0;
}

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

.navbar-brand {
    color: var(--color-text);
    font-size: 1.5rem;
    font-weight: 600;
    text-decoration: none;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.navbar-text {
    color: var(--color-text-muted);
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.navbar-link {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    text-decoration: none;
    transition: color 0.15s;
}

.navbar-link:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.navbar-link.active {
    color: var(--color-primary);
    font-weight: 500;
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease-in-out;
    text-align: center;
}

.btn:hover {
    text-decoration: none;
}

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

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

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--color-primary);
    color: var(--color-primary);
}

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

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-danger {
    background-color: #f0f0f0;
    color: #555;
    border: 1px solid #ccc;
}

.btn-danger:hover {
    background-color: #e0e0e0;
    border-color: #bbb;
}

.btn-sm {
    padding: var(--space-xs) 0.75rem;
    font-size: 0.8125rem;
}

/* === Cards === */
.card {
    background: var(--color-card);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    padding: var(--space-lg);
}

.card-shadow {
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    border: none;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
}

.card-text {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-bottom: var(--space-md);
}

/* === Grid === */
.grid {
    display: grid;
    gap: var(--space-md);
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* === Alerts === */
.alert {
    padding: 0.75rem var(--space-md);
    border-radius: 4px;
    margin-bottom: var(--space-md);
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

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

.form-label {
    display: block;
    margin-bottom: var(--space-xs);
    font-weight: 500;
    color: var(--color-text);
}

.form-control {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.form-control:focus {
    outline: 2px solid var(--color-primary);
    border-color: var(--color-primary);
}

/* === Utilities === */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-sm); }
.mb-2 { margin-bottom: var(--space-md); }
.mb-3 { margin-bottom: var(--space-lg); }
.mb-4 { margin-bottom: var(--space-xl); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-sm); }
.mt-2 { margin-top: var(--space-md); }

.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }

.d-inline { display: inline; }
.d-flex { display: flex; }
.gap-1 { gap: var(--space-sm); }
.gap-2 { gap: var(--space-md); }

/* === Page specific === */
.main-content {
    padding: var(--space-xl) 0;
}

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

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
}

.page-description {
    color: var(--color-text-muted);
}

/* === Auth Pages === */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.auth-card {
    background: var(--color-card);
    padding: var(--space-xl);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.auth-title {
    text-align: center;
    margin-bottom: var(--space-xl);
    color: var(--color-text);
    font-size: 1.5rem;
}

.auth-link {
    text-align: center;
}

/* === Checkbox === */
.form-check {
    display: flex;
    align-items: center;
    margin-bottom: var(--space-md);
}

.form-check input {
    margin-right: var(--space-sm);
}

/* === Select === */
.form-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background-color: var(--color-card);
}

.form-select:focus {
    outline: 2px solid var(--color-primary);
    border-color: var(--color-primary);
}

/* === Error List === */
.error-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* === Full Width Button === */
.btn-block {
    width: 100%;
}

/* === Project Cards === */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-lg);
    margin-top: var(--space-xl);
}

.project-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: var(--space-lg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s;
}

.project-card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.project-card h3 {
    margin: 0 0 var(--space-sm) 0;
    color: var(--color-text);
}

.project-card p {
    color: var(--color-text-muted);
    margin: var(--space-sm) 0;
}

.project-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: var(--space-xl) var(--space-lg);
    color: var(--color-text-muted);
}

.empty-state h3 {
    margin-bottom: var(--space-md);
    color: var(--color-text);
}

/* === Page Header with Actions === */
.page-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
}

/* Backoffice title row: [submarine] Title [x] */
.backoffice-title-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.submarine-back-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    opacity: 0.6;
    transition: opacity 0.3s, transform 0.3s;
    line-height: 0;
}

.submarine-back-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.submarine-back-btn img {
    height: 36px;
    width: auto;
}

.backoffice-close-btn {
    font-size: 1.6rem;
    line-height: 1;
    color: var(--color-text-muted);
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.3s, color 0.3s;
    padding: 0 var(--space-xs);
}

.backoffice-close-btn:hover {
    opacity: 1;
    color: var(--color-text);
    text-decoration: none;
}

/* === Breadcrumb === */
.breadcrumb {
    margin-bottom: var(--space-md);
}

.breadcrumb a {
    color: var(--color-primary);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* === Narrow Container === */
.container-narrow {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

/* === Form Help Text === */
.form-text {
    display: block;
    margin-top: var(--space-xs);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* === Textarea === */
textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

/* === Form Actions === */
.form-actions {
    display: flex;
    gap: var(--space-md);
    margin-top: var(--space-xl);
}

/* === Section Title === */
.section-title {
    margin-bottom: var(--space-md);
    color: var(--color-text);
    font-size: 1.1rem;
}

/* === Project Meta === */
.project-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
    margin: var(--space-xl) 0;
    padding: var(--space-md);
    background: var(--color-background);
    border-radius: 4px;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-label {
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: var(--space-xs);
}

.meta-value {
    color: var(--color-text-muted);
}

/* === Evaluation Criteria === */
.evaluation-criteria {
    margin-top: var(--space-xl);
    padding: var(--space-md);
    background: var(--color-background);
    border-left: 4px solid var(--color-primary);
}

.evaluation-criteria h4 {
    margin-top: 0;
    margin-bottom: var(--space-sm);
}

/* === Disabled Input === */
.form-control:disabled,
.form-control[disabled] {
    background-color: var(--color-background);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

/* === Versions Grid === */
.versions-grid {
    display: grid;
    gap: var(--space-lg);
}

.version-card {
    background: var(--color-card);
    border-radius: 8px;
    padding: var(--space-lg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-left: 4px solid var(--color-border);
}

.version-card.active {
    border-left-color: var(--color-success);
}

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

.version-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.version-title h3 {
    margin: 0;
    color: var(--color-text);
}

.version-meta {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: var(--space-md);
}

.version-meta div {
    margin-bottom: var(--space-sm);
}

.version-actions {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

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

.badge-muted {
    background-color: var(--color-text-muted);
    color: white;
}

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

/* === Mode Tags === */
.mode-tag {
    display: inline-block;
    background-color: #e9ecef;
    color: #495057;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    margin-right: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.modes-list {
    margin-bottom: var(--space-md);
}

.modes-list h4 {
    margin: 0 0 var(--space-sm) 0;
    color: #495057;
    font-size: 0.9rem;
}

/* === Mode Section (detail view) === */
.modes-section {
    background: var(--color-card);
    padding: var(--space-xl);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

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

.modes-header h3 {
    margin: 0;
    color: var(--color-text);
}

.mode-card {
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    background-color: var(--color-background);
}

.mode-card:last-child {
    margin-bottom: 0;
}

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

.mode-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.mode-title h4 {
    margin: 0;
    color: #495057;
}

.mode-order {
    background-color: var(--color-primary);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.mode-prompt {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: var(--space-md);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* === Mode Editor (create/edit) === */
.modes-editor {
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: var(--space-md);
    background-color: var(--color-background);
}

.mode-item {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    position: relative;
}

.mode-item:last-child {
    margin-bottom: 0;
}

.mode-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.mode-item-header h4 {
    margin: 0;
    color: #495057;
}

/* === Tools Info === */
.tools-info {
    background-color: #e7f3ff;
    border: 1px solid #b3d7ff;
    border-radius: 4px;
    padding: var(--space-md);
    margin-top: var(--space-md);
}

.tools-info h5 {
    margin: 0 0 var(--space-sm) 0;
    color: #0056b3;
}

.tool-tag {
    display: inline-block;
    background-color: var(--color-primary);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    margin-right: var(--space-sm);
    margin-bottom: var(--space-xs);
}

/* === Status Badge === */
.status-badge {
    background-color: var(--color-success);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* === Text Colors === */
.text-danger {
    color: var(--color-danger);
}

.text-success {
    color: var(--color-success);
}

/* === Required Indicator === */
.required {
    color: var(--color-danger);
}

/* === Remove Button === */
.btn-remove {
    background: var(--color-danger);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
}

/* === Success Button === */
.btn-success {
    background-color: var(--color-success);
    color: white;
}

.btn-success:hover {
    background-color: #218838;
}

/* === Scenarios Grid === */
.scenarios-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: var(--space-lg);
    margin-top: var(--space-xl);
}

.scenario-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: var(--space-lg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s;
}

.scenario-card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.scenario-card h3 {
    margin: 0 0 var(--space-md) 0;
    color: var(--color-text);
}

.scenario-meta {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: var(--space-sm) 0;
}

.scenario-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.persona-preview {
    background: var(--color-background);
    padding: 0.75rem;
    border-radius: 4px;
    border-left: 4px solid var(--color-primary);
    margin: var(--space-md) 0;
    font-style: italic;
    font-size: 0.9rem;
}

/* === Scenario Detail === */
.scenario-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-xl);
}

.field-group {
    margin-bottom: var(--space-xl);
}

.field-label {
    font-weight: bold;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
    display: block;
}

.field-content {
    background: var(--color-background);
    padding: var(--space-md);
    border-radius: 4px;
    border: 1px solid #e9ecef;
    line-height: 1.6;
}

/* === Meta Grid === */
.meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.meta-grid-item {
    background: var(--color-background);
    padding: var(--space-md);
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

.meta-grid-label {
    font-weight: bold;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.meta-grid-value {
    color: var(--color-text);
    margin-top: var(--space-xs);
}

/* === Character Counter === */
.char-counter {
    text-align: right;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
}

/* === Playground Chat Interface === */
.playground-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

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

.playground-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas:
        "chat display"
        "footer display";
    gap: var(--space-lg);
    flex: 1;
    min-height: 0;
}

.playground-layout.full-width {
    grid-template-columns: 1fr;
    grid-template-areas:
        "chat"
        "footer";
}

.playground-layout .chat-panel {
    grid-area: chat;
    min-width: 0;
}

.playground-layout .display-panel {
    grid-area: display;
    min-width: 0;
}

.playground-layout .mobile-chat-footer {
    grid-area: footer;
}

/* Chat Panel */
.chat-panel {
    display: flex;
    flex-direction: column;
    background: var(--color-card);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    min-height: 0;
}

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

.chat-header h3 {
    margin: 0;
    font-size: 1rem;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    min-width: 0;
}

/* Messages */
.message {
    max-width: 85%;
    padding: var(--space-md);
    border-radius: 12px;
    line-height: 1.6;
    min-width: 0;
    overflow-wrap: break-word;
}

.message-user {
    align-self: flex-end;
    /* Styling available but kept minimal for clean look */
}

.message-assistant {
    align-self: flex-start;
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.message-content {
    word-wrap: break-word;
}

.message-content p {
    margin: 0 0 var(--space-sm) 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content pre {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    padding: var(--space-sm);
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.9em;
    margin: var(--space-sm) 0;
}

.message-content code {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

.message-user .message-content code {
    /* Same as default code style */
}

.message-content ul, .message-content ol {
    margin: var(--space-sm) 0;
    padding-left: var(--space-lg);
}

.message-content blockquote {
    border-left: 3px solid var(--color-primary);
    margin: var(--space-sm) 0;
    padding-left: var(--space-md);
    color: var(--color-text-muted);
}

/* Chat Input */
.chat-input-container {
    padding: var(--space-md);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
}

/* Legacy textarea (keep for backwards compat during transition) */
textarea.chat-input {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 150px;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: 22px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
}

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

textarea.chat-input:disabled {
    background: var(--color-background);
    cursor: not-allowed;
}

/* Contenteditable chat input wrapper */
.chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 150px;
    overflow-y: auto;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: 22px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    background: white;
    color: #333333;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.chat-input:focus-within {
    border-color: var(--color-primary);
}

.chat-input.disabled {
    background: var(--color-background);
    cursor: not-allowed;
}

.chat-input.disabled .chat-input-final {
    opacity: 0.5;
}

/* Editable text span */
.chat-input-final {
    display: inline;
    outline: none;
    word-wrap: break-word;
    min-width: 1px; /* Ensures cursor is visible when empty */
}

/* Interim transcription span */
.chat-input-interim {
    display: inline;
    color: var(--color-text-muted);
    font-style: italic;
}

/* Hide interim in normal (non-dictation) mode */
#chat-input-area:not(.dictation-enabled) .chat-input-interim {
    display: none;
}

/* Placeholder when empty */
.chat-input:not(:focus-within) .chat-input-final:empty + .chat-input-interim:empty::before,
.chat-input:not(:focus-within).is-empty::before {
    content: attr(data-placeholder);
    color: var(--color-text-muted);
    pointer-events: none;
}

/* Simpler placeholder: show on wrapper when both spans are empty */
.chat-input[data-placeholder]:not(:focus-within):has(.chat-input-final:empty):has(.chat-input-interim:empty)::before {
    content: attr(data-placeholder);
    color: var(--color-text-muted);
    pointer-events: none;
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

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

.chat-send-btn:disabled {
    background: var(--color-text-muted);
    cursor: not-allowed;
}

/* Compact Navbar (for playground) */
.navbar-compact {
    padding: var(--space-sm) 0;
}

.navbar-compact .navbar-content {
    gap: var(--space-sm);
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.btn-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-background);
    color: var(--color-text);
    text-decoration: none;
    font-size: 1.25rem;
    transition: background 0.15s;
}

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

.navbar-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--color-text);
}

/* Playground page - use flexbox to fill viewport height */
.page:has(.playground-main) {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Playground main content - minimal padding, flex to fill space */
.playground-main {
    width: 100%;
    padding-top: var(--space-sm);
    padding-bottom: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Chat header actions */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Status dot */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-text-muted);
    flex-shrink: 0;
}

.status-dot.connected {
    background: #22c55e;
}

.status-dot.error {
    background: #ef4444;
}

/* Chat Footer - in grid layout on desktop, fixed on mobile */
.mobile-chat-footer {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    z-index: 10;
}

.mobile-chat-footer .chat-input-container {
    border-top: none;
}

/* Document Panel */
.document-panel {
    display: flex;
    flex-direction: column;
    background: var(--color-card);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    min-height: 0;
}

/* Mode Bar */
.mode-bar {
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.mode-bar:hover {
    background: var(--color-background);
}

.mode-current {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.mode-indicator {
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
}

.mode-arrow {
    color: var(--color-text-muted);
    transition: transform 0.2s;
}

/* Mode Bar Inline (when no document panel) */
.mode-bar-inline {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-background);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.15s;
}

.mode-bar-inline:hover {
    background: var(--color-border);
}

/* Document Content */
.document-content {
    flex: 1;
    padding: var(--space-lg);
    overflow-y: auto;
}

.document-empty {
    color: var(--color-text-muted);
    text-align: center;
    padding: var(--space-xl);
    font-style: italic;
}

.document-text {
    word-wrap: break-word;
    line-height: 1.5;
}

.document-text p {
    margin: 0 0 var(--space-sm) 0;
}

.document-text p:last-child {
    margin-bottom: 0;
}

.document-text h1, .document-text h2, .document-text h3 {
    margin: var(--space-md) 0 var(--space-sm) 0;
    line-height: 1.3;
}

.document-text h1:first-child, .document-text h2:first-child, .document-text h3:first-child {
    margin-top: 0;
}

.document-text ul, .document-text ol {
    margin: var(--space-sm) 0;
    padding-left: var(--space-lg);
}

.document-text pre {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    padding: var(--space-sm);
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.9em;
    margin: var(--space-sm) 0;
}

.document-text code {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* Mode Overlay */
.mode-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.mode-overlay.active {
    display: flex;
}

.mode-list-container {
    background: var(--color-card);
    border-radius: 12px;
    padding: var(--space-xl);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.mode-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.mode-list-header h3 {
    margin: 0;
}

.mode-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: var(--space-xs);
}

.mode-list-item {
    padding: var(--space-md);
    border-radius: 8px;
    margin-bottom: var(--space-sm);
    border: 2px solid var(--color-border);
    background: var(--color-background);
}

.mode-list-item:last-child {
    margin-bottom: 0;
}

.mode-list-item.active {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.mode-list-item h4 {
    margin: 0 0 var(--space-xs) 0;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.mode-list-item p {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Chat Loading */
.chat-loading {
    display: flex;
    gap: 4px;
    padding: var(--space-md);
    align-self: flex-start;
}

.chat-loading-dot {
    width: 8px;
    height: 8px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: chatBounce 1.4s infinite ease-in-out;
}

.chat-loading-dot:nth-child(1) { animation-delay: -0.32s; }
.chat-loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes chatBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Chat Error */
.chat-error {
    background: #f8d7da;
    color: #721c24;
    padding: var(--space-md);
    border-radius: 8px;
    margin: var(--space-md);
    text-align: center;
}

/* === Diagrams === */
.diagram-container {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin: var(--space-md) 0;
    overflow: hidden;
}

.diagram-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
}

.diagram-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.diagram-open-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 1rem;
    padding: var(--space-xs);
    transition: color 0.15s;
}

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

.diagram-svg {
    padding: var(--space-md);
    overflow: auto;
}

.diagram-svg svg {
    max-width: 100%;
    height: auto;
}

.diagram-missing {
    color: var(--color-text-muted);
    font-style: italic;
    padding: var(--space-md);
    background: var(--color-background);
    border-radius: 4px;
    margin: var(--space-md) 0;
}

.diagram-error {
    color: var(--color-danger);
    padding: var(--space-md);
    background: #f8d7da;
    border-radius: 4px;
    font-size: 0.875rem;
}

/* === Lists in Document === */
.list-container {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin: var(--space-md) 0;
    overflow: hidden;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
}

.list-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.list-progress {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-card);
    padding: 2px 8px;
    border-radius: 10px;
}

.list-items {
    list-style: none;
    margin: 0;
    padding: var(--space-sm);
}

.list-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: 4px;
    transition: background 0.15s;
}

.list-item.current {
    background: var(--color-primary-light);
}

.list-item.completed {
    opacity: 0.7;
}

.list-item-checkbox {
    flex-shrink: 0;
    color: var(--color-text-muted);
}

.list-item.completed .list-item-checkbox {
    color: var(--color-success);
}

.list-item-content {
    flex: 1;
}

.list-item.completed .list-item-content {
    text-decoration: line-through;
}

.list-item-result {
    color: var(--color-primary);
    font-size: 0.875rem;
}

.list-missing {
    color: var(--color-text-muted);
    font-style: italic;
    padding: var(--space-md);
    background: var(--color-background);
    border-radius: 4px;
    margin: var(--space-md) 0;
}

/* === Screenflows === */
.screenflow-container {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin: var(--space-md) 0;
    overflow: hidden;
}

.screenflow-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
}

.screenflow-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.screenflow-open-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 1rem;
    padding: var(--space-xs);
    transition: color 0.15s;
}

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

.screenflow-svg {
    padding: var(--space-md);
    overflow: auto;
    background: #f0f4f8;
}

.screenflow-svg svg {
    max-width: 100%;
    height: auto;
    display: block;
}

.screenflow-missing {
    color: var(--color-text-muted);
    font-style: italic;
    padding: var(--space-md);
    background: var(--color-background);
    border-radius: 4px;
    margin: var(--space-md) 0;
}

/* === Help Button === */
.help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    transition: background 0.15s, transform 0.15s;
}

.help-btn:hover {
    background: var(--color-primary-hover);
    transform: scale(1.1);
    text-decoration: none;
}

/* Mobile dictation toggle - hidden on desktop */
.dictation-btn-mobile {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.dictation-btn-mobile:hover {
    background: var(--color-background);
    transform: scale(1.1);
}

/* === Welcome Page === */
/* === Landing Page (Homepage + Spaces) === */
.landing-page {
    min-height: 100vh;
    background: #f0f4fb;
    display: flex;
    flex-direction: column;
}

.landing-header {
    padding: var(--space-lg) var(--space-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.landing-brand {
    font-size: 1rem;
    font-weight: 600;
    color: #2a6b5a;
    text-decoration: none;
    letter-spacing: 0.05em;
}

.landing-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.landing-header .btn {
    font-size: 0.85rem;
    padding: var(--space-xs) var(--space-md);
    color: #2a6b5a;
    border: 1px solid #b8d8cf;
    background: transparent;
    border-radius: 20px;
    text-decoration: none;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.landing-header .btn:hover {
    color: #1a4d3f;
    border-color: #2a6b5a;
    background: #f0f8f5;
}

.landing-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.landing-text {
    text-align: center;
    padding: 3rem 2rem 0;
    max-width: 820px;
}

.landing-text p {
    font-size: 1.35rem;
    line-height: 2;
    color: #3a3a3a;
    margin: 0 0 1.5rem 0;
    font-weight: 300;
}

.landing-text p:first-child {
    font-size: 1.6rem;
    font-weight: 400;
    color: #1a1a1a;
}

.landing-images {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    width: 100%;
}

.landing-image {
    position: relative;
    overflow: hidden;
}

.landing-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.landing-image-caption {
    display: none;
}

.landing-closing {
    text-align: center;
    padding: 0 2rem;
    max-width: 820px;
}

.landing-closing p {
    font-size: 1.15rem;
    line-height: 1.8;
    color: #555;
    font-weight: 300;
}

.landing-cta {
    text-align: center;
    margin-bottom: 2.5rem;
}

.landing-cta .btn {
    display: inline-block;
    padding: 0.8rem 2.5rem;
    font-size: 1.05rem;
    color: #2a6b5a;
    border: 1.5px solid #b8d8cf;
    background: transparent;
    border-radius: 30px;
    text-decoration: none;
    letter-spacing: 0.03em;
    transition: all 0.3s ease;
}

.landing-cta .btn:hover {
    color: #1a4d3f;
    border-color: #2a6b5a;
    background: #f0f8f5;
}

.landing-footer {
    text-align: center;
    padding: var(--space-lg);
    color: #8aaa9e;
    font-size: 0.8rem;
}

.landing-footer a {
    color: #5a8a7a;
    text-decoration: none;
}

.landing-footer a:hover {
    color: #2a6b5a;
}

/* Landing hero image */
.landing-image-hero {
    width: 100%;
    max-width: 900px;
    margin: 0 auto 3rem;
    border-radius: 8px;
    overflow: hidden;
}

.landing-image-hero img {
    width: 100%;
    height: auto;
    display: block;
}

/* Character row on landing page */
.landing-characters {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
    padding: 0 2rem 3rem;
    max-width: 900px;
    margin: 0 auto;
}

.landing-character {
    text-align: center;
    padding: 1.5rem 2rem;
    border: 1px solid #d5e8e0;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, background 0.2s;
    min-width: 140px;
}

a.landing-character:hover {
    border-color: #2a6b5a;
    background: #f0f8f5;
}

.landing-character-soon {
    opacity: 0.45;
}

.landing-character-name {
    display: block;
    font-size: 1.15rem;
    font-weight: 500;
    color: #1a1a1a;
    margin-bottom: 0.3rem;
}

.landing-character-role {
    display: block;
    font-size: 0.85rem;
    color: #5a8a7a;
    font-weight: 300;
}

.landing-character-img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 0.8rem;
}

/* Bot detail page */
.bot-page {
    text-align: center;
    padding: 2rem 2rem 4rem;
    max-width: 600px;
    margin: 0 auto;
}

.bot-image {
    max-width: 600px;
    margin: 0 auto 2rem;
    border-radius: 12px;
    overflow: hidden;
}

.bot-image img {
    width: 100%;
    height: auto;
    display: block;
}

.bot-coming-soon {
    display: inline-block;
    font-size: 0.95rem;
    color: #8aaa9e;
    font-weight: 300;
    font-style: italic;
}

.bot-name {
    font-size: 2.2rem;
    font-weight: 400;
    color: #1a1a1a;
    margin: 0 0 0.3rem;
}

.bot-role {
    font-size: 1.1rem;
    color: #5a8a7a;
    font-weight: 300;
    margin: 0 0 2.5rem;
}

.bot-description p {
    font-size: 1.15rem;
    line-height: 1.9;
    color: #3a3a3a;
    font-weight: 300;
    margin: 0 0 1.2rem;
}

.bot-cta {
    margin-top: 2.5rem;
}

.bot-cta .btn {
    display: inline-block;
    padding: 0.8rem 2.5rem;
    font-size: 1.05rem;
    color: #2a6b5a;
    border: 1.5px solid #b8d8cf;
    background: transparent;
    border-radius: 30px;
    text-decoration: none;
    letter-spacing: 0.03em;
    transition: all 0.3s ease;
}

.bot-cta .btn:hover {
    color: #1a4d3f;
    border-color: #2a6b5a;
    background: #f0f8f5;
}

/* Spaces page (placeholder) */
.spaces-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem var(--space-xl);
}

.spaces-text {
    text-align: center;
    max-width: 500px;
}

.spaces-text p {
    font-size: 1.35rem;
    line-height: 2;
    color: #444;
    font-weight: 300;
}

/* === Learn Page === */
.learn-page {
    min-height: 100vh;
}

.learn-header {
    padding: var(--space-md) 0;
    background: var(--color-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.learn-content {
    padding: var(--space-xl) 0;
}

.learn-section {
    max-width: 800px;
    margin: 0 auto var(--space-xl);
    padding: 0 var(--space-md);
}

.learn-section h2 {
    font-size: 1.75rem;
    color: var(--color-text);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-primary);
}

.learn-section h3 {
    font-size: 1.25rem;
    color: var(--color-text);
    margin: var(--space-lg) 0 var(--space-sm);
}

.learn-section p {
    color: var(--color-text);
    line-height: 1.7;
    margin-bottom: var(--space-md);
}

.learn-section ul {
    margin: var(--space-md) 0;
    padding-left: var(--space-lg);
}

.learn-section li {
    margin-bottom: var(--space-sm);
    line-height: 1.6;
}

.learn-diagram {
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: var(--space-lg);
    margin: var(--space-lg) 0;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.4;
    overflow-x: auto;
    white-space: pre;
}

.learn-callout {
    background: var(--color-primary-light);
    border-left: 4px solid var(--color-primary);
    padding: var(--space-md) var(--space-lg);
    margin: var(--space-lg) 0;
    border-radius: 0 8px 8px 0;
}

.learn-callout p {
    margin: 0;
    font-style: italic;
}

.learn-glossary {
    background: var(--color-background);
    border-radius: 8px;
    padding: var(--space-lg);
}

.learn-glossary dt {
    font-weight: 600;
    color: var(--color-text);
    margin-top: var(--space-md);
}

.learn-glossary dt:first-child {
    margin-top: 0;
}

.learn-glossary dd {
    color: var(--color-text-muted);
    margin: var(--space-xs) 0 0 0;
}

.learn-cta {
    text-align: center;
    padding: var(--space-xl);
    background: var(--color-card);
    border-radius: 8px;
    margin-top: var(--space-xl);
}

/* Illustrated sections - alternating image left/right */
.learn-section-illustrated {
    display: flex;
    gap: var(--space-xl);
    align-items: center;
    max-width: 1000px;
    margin: 0 auto var(--space-xl);
    padding: 0 var(--space-md);
}

.learn-section-illustrated.image-left {
    flex-direction: row;
}

.learn-section-illustrated.image-right {
    flex-direction: row-reverse;
}

.learn-section-illustrated .learn-section-image {
    flex-shrink: 0;
    width: 45%;
    max-width: 400px;
}

.learn-section-illustrated .learn-section-image img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.learn-section-illustrated .learn-section-text {
    flex: 1;
}

.learn-section-illustrated .learn-section-text h2 {
    font-size: 1.75rem;
    color: var(--color-text);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-primary);
}

.learn-section-illustrated .learn-section-text p {
    color: var(--color-text);
    line-height: 1.7;
    margin-bottom: var(--space-md);
}

.learn-section-illustrated .learn-section-text ul {
    margin: var(--space-md) 0;
    padding-left: var(--space-lg);
}

.learn-section-illustrated .learn-section-text li {
    margin-bottom: var(--space-sm);
    line-height: 1.6;
}

@media (max-width: 768px) {
    .learn-section-illustrated {
        flex-direction: column !important;
    }

    .learn-section-illustrated .learn-section-image {
        width: 100%;
        max-width: none;
    }
}

/* === Help Page === */
.help-page {
    min-height: 100vh;
}

.help-content {
    padding: var(--space-xl) 0;
}

.help-section {
    max-width: 800px;
    margin: 0 auto var(--space-xl);
    padding: 0 var(--space-md);
    scroll-margin-top: 80px;
}

.help-section h2 {
    font-size: 1.5rem;
    color: var(--color-text);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-primary);
}

.help-section h3 {
    font-size: 1.125rem;
    color: var(--color-text);
    margin: var(--space-lg) 0 var(--space-sm);
}

.help-section p {
    color: var(--color-text);
    line-height: 1.7;
    margin-bottom: var(--space-md);
}

.help-section ul, .help-section ol {
    margin: var(--space-md) 0;
    padding-left: var(--space-lg);
}

.help-section li {
    margin-bottom: var(--space-sm);
    line-height: 1.6;
}

/* === Templates Section on Projects === */
.section-divider {
    border: none;
    border-top: 2px solid var(--color-border);
    margin: var(--space-xl) 0;
}

.section-header {
    margin-bottom: var(--space-lg);
}

.section-header h2 {
    font-size: 1.25rem;
    color: var(--color-text);
    margin: 0;
}

.section-header p {
    color: var(--color-text-muted);
    margin: var(--space-xs) 0 0;
    font-size: 0.9rem;
}

.template-card {
    background: var(--color-card);
    border: 2px dashed var(--color-border);
    border-radius: 8px;
    padding: var(--space-lg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.template-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.template-card h3 {
    margin: 0 0 var(--space-sm) 0;
    color: var(--color-text);
}

.template-card p {
    color: var(--color-text-muted);
    margin: var(--space-sm) 0;
    font-size: 0.9rem;
}

.template-badge {
    display: inline-block;
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: var(--space-sm);
}

/* Responsive */
@media (max-width: 900px) {
    .playground-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .chat-panel {
        height: 60vh;
    }

    .document-panel {
        height: 40vh;
    }
}

/* === Modal === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    z-index: 1;
    background: var(--color-card, #ffffff);
    color: var(--color-text, #333333);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-large {
    max-width: 800px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-card, #ffffff);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
}

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

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

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    flex: 1;
    background: var(--color-card, #ffffff);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--color-border);
    background: var(--color-card, #ffffff);
}

/* Modal content elements */
.code-display {
    background: var(--color-background);
    padding: var(--space-md);
    border-radius: 4px;
    overflow: auto;
    max-height: 60vh;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid var(--color-border);
}

.docs-textarea {
    width: 100%;
    min-height: 300px;
    padding: var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    background: var(--color-card, #ffffff);
    color: var(--color-text, inherit);
}

/* Conversation Modal Specific */
.start-option {
    text-align: center;
    padding: var(--space-md) 0;
}

.start-option p {
    margin-top: var(--space-sm);
}

.conversations-list {
    margin-top: var(--space-md);
    max-height: 300px;
    overflow-y: auto;
}

.conversation-item {
    border: 1px solid var(--color-border);
    border-radius: 6px;
    margin-bottom: var(--space-sm);
    overflow: hidden;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-background);
    cursor: pointer;
}

.conversation-header:hover {
    background: var(--color-primary-light);
}

.conversation-date {
    font-weight: 500;
}

.conversation-meta {
    display: flex;
    gap: var(--space-sm);
    font-size: 0.875rem;
}

.conversation-resources {
    display: none;
    padding: var(--space-md);
    background: var(--color-card);
    border-top: 1px solid var(--color-border);
}

.conversation-item.expanded .conversation-resources {
    display: block;
}

.document-preview {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-style: italic;
    margin-bottom: var(--space-sm);
}

.resource-list {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-sm) 0;
}

.resource-item {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-primary-light);
    border-radius: 4px;
    font-size: 0.75rem;
    margin: 2px;
}

.conversation-actions {
    margin-top: var(--space-sm);
    text-align: right;
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Touch target minimum size */
:root {
    --touch-target-min: 44px;
}

/* Mobile breakpoint: 768px and below */
@media (max-width: 768px) {
    /* === GLOBAL MOBILE OVERFLOW FIX === */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
        width: 100%;
    }

    .page {
        overflow-x: hidden;
        max-width: 100vw;
        width: 100%;
    }

    * {
        box-sizing: border-box;
    }

    /* === LANDING PAGE MOBILE === */
    .landing-header {
        padding: var(--space-md) var(--space-md);
    }

    .landing-content {
        padding: 2rem var(--space-md) 2rem;
    }

    .landing-text p {
        font-size: 1.05rem;
        line-height: 1.8;
    }

    .landing-text p:first-child {
        font-size: 1.2rem;
    }

    .landing-images {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-bottom: 2rem;
    }

    .landing-image-caption {
        font-size: 0.75rem;
    }

    .landing-closing p {
        font-size: 1rem;
    }

    .landing-cta .btn {
        padding: 0.7rem 2rem;
        font-size: 0.95rem;
    }

    .landing-footer {
        font-size: 0.75rem;
    }

    /* === AUTH PAGES MOBILE === */
    .auth-page {
        padding: var(--space-md);
        align-items: flex-start;
        padding-top: 10vh;
    }

    .auth-card {
        padding: var(--space-lg);
        width: 100%;
        max-width: 100%;
        box-shadow: none;
        border: 1px solid var(--color-border);
    }

    .auth-title {
        font-size: 1.5rem;
        margin-bottom: var(--space-lg);
    }

    .auth-card .form-control,
    .auth-card .form-select {
        min-height: var(--touch-target-min);
        font-size: 16px; /* Prevent iOS zoom */
    }

    .auth-card .btn {
        min-height: var(--touch-target-min);
        font-size: 1rem;
    }

    .auth-card .form-check {
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
    }

    .auth-card .form-check input {
        width: 20px;
        height: 20px;
    }

    .auth-link {
        margin-top: var(--space-md);
    }

    .auth-link a {
        display: inline-block;
        padding: var(--space-sm) 0;
        min-height: var(--touch-target-min);
    }

    /* === NAVBAR MOBILE === */
    .navbar-content {
        flex-wrap: nowrap;
        gap: var(--space-xs);
    }

    .navbar-left {
        flex: 1;
        min-width: 0; /* Allow shrinking */
    }

    .navbar-title {
        font-size: 0.9rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .navbar-nav {
        flex-shrink: 0;
        gap: var(--space-xs);
    }

    .navbar-text {
        display: none;
    }

    /* Hide profile and logout on mobile playground - use compact nav */
    .navbar-compact .navbar-nav .btn {
        display: none;
    }

    .navbar-compact .navbar-nav .help-btn {
        display: flex;
    }

    /* Show mobile dictation toggle on mobile playground */
    .navbar-compact .dictation-btn-mobile {
        display: flex;
        width: var(--touch-target-min);
        height: var(--touch-target-min);
    }

    .help-btn {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
    }

    /* Chat header mobile */
    .chat-header {
        padding: var(--space-sm);
    }

    .chat-header h3 {
        font-size: 0.9rem;
    }

    .chat-header-actions .btn {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.8rem;
    }

    /* Mode bar compact on mobile */
    .mode-bar-inline {
        font-size: 0.8rem;
        padding: 2px 8px;
    }

    #current-mode-label {
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* === PAGE LAYOUT MOBILE === */
    .container {
        padding: 0 var(--space-sm);
    }

    .main-content {
        padding: var(--space-md) 0;
    }

    .page-title {
        font-size: 1.25rem;
    }

    /* === PROJECTS PAGE MOBILE === */
    .page-header-actions {
        flex-direction: column;
        gap: var(--space-md);
        align-items: stretch;
    }

    .page-header-actions .btn {
        width: 100%;
        min-height: var(--touch-target-min);
        font-size: 1rem;
    }

    .projects-grid {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .project-card,
    .template-card {
        padding: var(--space-md);
    }

    .project-card h3,
    .template-card h3 {
        font-size: 1.1rem;
    }

    .project-card p,
    .template-card p {
        font-size: 0.9rem;
    }

    .project-actions {
        flex-direction: row;
        gap: var(--space-sm);
    }

    .project-actions .btn {
        min-height: var(--touch-target-min);
        justify-content: center;
        padding-left: var(--space-md);
        padding-right: var(--space-md);
    }

    .section-divider {
        margin: var(--space-lg) 0;
    }

    .section-header h2 {
        font-size: 1.1rem;
    }

    /* === PROJECT DETAIL (TILES) MOBILE === */
    .container-narrow {
        padding: 0 var(--space-sm);
    }

    .project-header {
        flex-direction: column;
        gap: var(--space-md);
    }

    .project-header-actions {
        width: 100%;
    }

    .project-header-actions .btn {
        width: 100%;
        min-height: var(--touch-target-min);
    }

    .hub-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-sm);
    }

    .hub-card {
        padding: var(--space-md);
    }

    .hub-card-icon {
        font-size: 1.25rem;
    }

    .hub-card-title {
        font-size: 0.9rem;
    }

    .hub-card-desc {
        font-size: 0.75rem;
        display: none;
    }

    .hub-card-count {
        font-size: 0.7rem;
    }

    .project-settings summary {
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
    }

    /* === PLAYGROUND MOBILE === */
    .playground-header {
        flex-direction: column;
        gap: var(--space-sm);
        align-items: stretch;
    }

    .playground-header .btn {
        width: 100%;
        min-height: var(--touch-target-min);
    }

    .playground-container {
        flex: 1;
        max-width: 100%;
        overflow-x: hidden;
    }

    .playground-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;  /* content + footer */
        grid-template-areas:
            "content"
            "footer";
        height: 100%;
        overflow: hidden;
    }

    /* Mobile: Chat panel takes full height when active */
    .playground-layout .chat-panel {
        grid-area: content;
        height: 100%;
        display: flex;
        flex-direction: column;
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Mobile: Display panel hidden by default, shown via JS */
    .playground-layout .display-panel {
        grid-area: content;
        height: 100%;
        display: none;
        background: var(--color-card);
    }

    .playground-layout .display-panel.mobile-active {
        display: flex;
    }

    /* Mobile screen indicator strip */
    .mobile-screen-indicator {
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-sm);
        padding: var(--space-sm);
        background: var(--color-background);
        border-top: 1px solid var(--color-border);
        touch-action: pan-x;
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
        overflow: hidden;
    }

    .mobile-screen-dots {
        display: flex !important;
        flex-direction: row !important;
        gap: var(--space-sm);
        flex: 1;
        justify-content: center;
        align-items: center;
        min-width: 0; /* Allow shrinking */
        position: relative;
        overflow: visible;
    }

    /* Swipe hint arrows */
    .mobile-screen-dots::before,
    .mobile-screen-dots::after {
        content: '';
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 0;
        height: 0;
        border-style: solid;
        opacity: 0.25;
    }

    .mobile-screen-dots::before {
        left: 8px;
        border-width: 5px 6px 5px 0;
        border-color: transparent #666 transparent transparent;
    }

    .mobile-screen-dots::after {
        right: 8px;
        border-width: 5px 0 5px 6px;
        border-color: transparent transparent transparent #666;
    }

    .mobile-screen-dot {
        width: 6px;
        height: 6px;
        border-radius: 2px;
        background: #333;
        transition: all 0.2s;
        cursor: pointer;
        flex-shrink: 0;
    }

    .mobile-screen-dot.active {
        width: 14px;
        height: 14px;
        background: var(--color-primary);
    }

    /* Icon mode: SVG icons instead of dots (≤4 screens) */
    .mobile-screen-dots.icon-mode {
        gap: var(--space-md);
    }

    .mobile-screen-dots.icon-mode::before,
    .mobile-screen-dots.icon-mode::after {
        display: none;
    }

    .mobile-screen-icon {
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        color: var(--text-muted, #999);
        transition: all 0.2s;
        flex-shrink: 0;
    }

    .mobile-screen-icon svg {
        width: 18px;
        height: 18px;
    }

    .mobile-screen-icon.active {
        color: var(--color-primary);
    }

    .mobile-screen-icon.active svg {
        width: 22px;
        height: 22px;
    }

    .mobile-minimize-btn {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: var(--color-text-muted);
        font-size: 1.25rem;
        cursor: pointer;
    }

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

    /* Mobile screens list overlay */
    .mobile-screens-list {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-card);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 200;
        max-height: 60vh;
        overflow-y: auto;
        display: none; /* Hidden by default */
    }

    .mobile-screens-list.active {
        display: block;
    }

    .mobile-screens-list-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--space-md);
        border-bottom: 1px solid var(--color-border);
        position: sticky;
        top: 0;
        background: var(--color-card);
    }

    .mobile-screens-list-header h4 {
        margin: 0;
        font-size: 1rem;
    }

    .mobile-screens-list-close {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        font-size: 1.5rem;
        color: var(--color-text-muted);
        cursor: pointer;
    }

    .mobile-screens-list-items {
        padding: var(--space-sm);
    }

    .mobile-screen-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--space-md);
        border-radius: 8px;
        cursor: pointer;
        transition: background 0.15s;
        min-height: var(--touch-target-min);
    }

    .mobile-screen-item:hover,
    .mobile-screen-item.active {
        background: var(--color-background);
    }

    .mobile-screen-item.active {
        border-left: 3px solid var(--color-primary);
    }

    .mobile-screen-item-name {
        flex: 1;
        font-weight: 500;
    }

    .mobile-screen-item-close {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        display: flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: var(--color-danger);
        font-size: 1.25rem;
        cursor: pointer;
    }

    /* Mobile chat footer - takes real space in grid */
    .mobile-chat-footer {
        grid-area: footer;
        position: relative;
        width: 100%;
        max-width: 100vw;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        overflow: hidden;
    }

    /* Messages padding on mobile */
    .playground-layout .messages-container {
        padding: var(--space-sm);
    }

    /* Mobile: Full-width messages, distinguish by color not position */
    .playground-layout .message {
        max-width: 100%;
        align-self: stretch;
        padding: var(--space-sm) var(--space-md);
        border-radius: 8px;
        margin-bottom: var(--space-sm);
    }

    .playground-layout .message-user {
        background: var(--color-primary-light, #e8f4ff);
        border-left: 3px solid var(--color-primary);
    }

    .playground-layout .message-assistant {
        background: var(--color-background);
        border-left: 3px solid var(--color-border);
        border-bottom-left-radius: 8px;
    }

    /* Minimized mode - only hide input, strip stays */
    .mobile-chat-footer.minimized .chat-input-container {
        display: none;
    }

    /* New conversation button: show + icon only on mobile */
    #new-chat-btn {
        font-size: 0;
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #new-chat-btn::before {
        content: "+";
        font-size: 1.5rem;
        font-weight: 300;
        line-height: 1;
    }

    /* Chat input adjustments */
    .chat-input-container {
        padding: var(--space-sm);
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        display: flex;
        gap: var(--space-sm);
    }

    .chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
        min-width: 0; /* Allow shrinking in flex */
        flex: 1;
        width: 100%;
        max-width: calc(100% - 52px); /* Leave room for send button */
    }

    .chat-send-btn {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        flex-shrink: 0;
    }

    /* Mode overlay fullscreen on mobile */
    .mode-list-container {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        padding: var(--space-md);
    }

    .mode-list-item {
        min-height: var(--touch-target-min);
        padding: var(--space-md);
    }

    /* === AGENT EDITOR MOBILE === */
    .agent-edit-layout {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .agent-header {
        flex-direction: column;
        gap: var(--space-sm);
    }

    /* Hide table on mobile, show cards */
    .prompts-table .table {
        display: none;
    }

    /* Mobile prompt cards */
    .prompts-mobile-cards {
        display: flex;
        flex-direction: column;
        gap: var(--space-md);
    }

    .prompt-card-mobile {
        background: var(--color-background);
        border: 1px solid var(--color-border);
        border-radius: 8px;
        padding: var(--space-md);
    }

    .prompt-card-mobile.tool-prompt {
        background: #f0f7ff;
        border-color: #b3d7ff;
    }

    .prompt-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: var(--space-sm);
    }

    .prompt-card-title {
        display: flex;
        align-items: center;
        gap: var(--space-xs);
        font-weight: 600;
        flex: 1;
    }

    .prompt-card-title .tool-icon {
        font-size: 1rem;
    }

    .prompt-card-reorder {
        display: flex;
        gap: var(--space-xs);
    }

    .prompt-card-reorder button {
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--color-card);
        border: 1px solid var(--color-border);
        border-radius: 4px;
        font-size: 12px;
        cursor: pointer;
    }

    .prompt-card-preview {
        color: var(--color-text-muted);
        font-size: 0.85rem;
        margin-bottom: var(--space-sm);
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .prompt-card-modes {
        margin-bottom: var(--space-sm);
    }

    .prompt-card-actions {
        display: flex;
        gap: var(--space-sm);
    }

    .prompt-card-actions .btn {
        flex: 1;
        min-height: var(--touch-target-min);
    }

    /* Modes bottom sheet */
    .modes-bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-card);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 200;
        transform: translateY(calc(100% - 50px));
        transition: transform 0.3s ease;
        max-height: 50vh;
    }

    .modes-bottom-sheet.expanded {
        transform: translateY(0);
    }

    .modes-bottom-sheet-handle {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-md);
        cursor: pointer;
        border-bottom: 1px solid var(--color-border);
    }

    .modes-bottom-sheet-handle::before {
        content: '';
        width: 40px;
        height: 4px;
        background: var(--color-border);
        border-radius: 2px;
    }

    .modes-bottom-sheet-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 var(--space-md);
        margin-top: calc(-1 * var(--space-md));
        margin-bottom: var(--space-sm);
    }

    .modes-bottom-sheet-title h4 {
        margin: 0;
    }

    .modes-bottom-sheet-content {
        padding: var(--space-md);
        overflow-y: auto;
        max-height: calc(50vh - 80px);
    }

    /* Hide desktop sidebar on mobile */
    .agent-sidebar {
        display: none;
    }

    /* Modal fullscreen on mobile */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        animation: slideUp 0.3s ease;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .modal-wide {
        max-width: 100%;
    }

    /* Form controls touch-friendly */
    .form-control,
    .form-select {
        min-height: var(--touch-target-min);
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .form-actions {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .form-actions .btn {
        width: 100%;
        min-height: var(--touch-target-min);
    }

    /* === GENERAL MOBILE UTILITIES === */
    .btn {
        min-height: var(--touch-target-min);
    }

    .btn-sm {
        min-height: 36px;
    }

    /* Breadcrumb mobile */
    .breadcrumb {
        font-size: 0.85rem;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: var(--space-xs);
    }

    /* Alert mobile */
    .alert {
        font-size: 0.9rem;
    }
}

/* Extra small screens (< 380px) */
@media (max-width: 380px) {
    .hub-grid {
        grid-template-columns: 1fr;
    }

    .hub-card-desc {
        display: block;
    }

    .navbar-brand {
        font-size: 1.25rem;
    }
}

/* Desktop: Hide mobile-only elements */
@media (min-width: 769px) {
    .mobile-screen-indicator,
    .mobile-screens-list,
    .mobile-screens-backdrop,
    .modes-bottom-sheet,
    .prompts-mobile-cards {
        display: none !important;
    }

}

/* Mobile screens backdrop (base styles) */
.mobile-screens-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    display: none;
}

.mobile-screens-backdrop.active {
    display: block;
}

/* Tablet/iPad: Keep desktop layout but ensure sticky chat input */
@media (min-width: 769px) and (max-width: 1024px) {
    .chat-input-container {
        position: sticky;
        bottom: 0;
        background: var(--color-card);
    }
}

/* === Navbar Profile Dropdown === */
.navbar-dropdown {
    position: relative;
    display: inline-block;
}

.navbar-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    cursor: pointer;
}

.navbar-dropdown-arrow {
    font-size: 0.6rem;
    transition: transform 0.2s;
}

.navbar-dropdown.open .navbar-dropdown-arrow {
    transform: rotate(180deg);
}

.navbar-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: var(--space-xs);
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    z-index: 1000;
    overflow: hidden;
}

.navbar-dropdown.open .navbar-dropdown-menu {
    display: block;
}

.navbar-dropdown-menu a {
    display: block;
    padding: var(--space-sm) var(--space-md);
    color: var(--color-text);
    text-decoration: none;
    transition: background 0.15s;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.navbar-dropdown-menu a:hover {
    background: var(--color-background);
    text-decoration: none;
}

.navbar-dropdown-menu a:first-child {
    border-radius: 7px 7px 0 0;
}

.navbar-dropdown-menu a:last-child {
    border-radius: 0 0 7px 7px;
}

/* Mobile: Dropdown stays functional */
@media (max-width: 768px) {
    .navbar-dropdown-menu {
        min-width: 180px;
    }

    .navbar-dropdown-menu a {
        min-height: var(--touch-target-min);
    }
}

/* === Dictation Controls === */
.dictation-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-background);
    border-top: 1px solid var(--color-border);
}

.dictation-status {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.dictation-status-dot {
    width: 10px;
    height: 10px;
    background: var(--color-text-muted);
    border-radius: 50%;
    transition: background 0.2s;
}

.dictation-status-dot.active {
    background: var(--color-danger);
    animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

.dictation-buttons {
    display: flex;
    gap: var(--space-sm);
}

/* === Navbar Dictation Toggle === */
.dropdown-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-xs) 0;
}

.dictation-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-sm) var(--space-md);
    color: var(--color-text);
    font-size: 0.875rem;
    transition: background 0.15s;
}

.dictation-toggle:hover {
    background: var(--color-background);
}

.dictation-icon {
    font-size: 1.1rem;
}

.dictation-badge {
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    background: var(--color-border);
    color: var(--color-text-muted);
}

.dictation-badge.active {
    background: #dcfce7;
    color: #16a34a;
}

/* Mobile dictation adjustments */
@media (max-width: 768px) {
    .dictation-controls {
        padding: var(--space-xs) var(--space-sm);
    }

    .dictation-status {
        font-size: 0.8rem;
    }

    .dictation-toggle {
        min-height: var(--touch-target-min);
    }
}

/* === Glassmorphism === */
.glass {
    background: var(--color-card-alpha, rgba(255,255,255,0.85));
    backdrop-filter: blur(var(--blur-amount, 12px));
    -webkit-backdrop-filter: blur(var(--blur-amount, 12px));
    border: 1px solid rgba(255,255,255,0.18);
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.glass-matte {
    background: var(--color-card-alpha-matte, rgba(255,255,255,0.92));
    backdrop-filter: blur(var(--blur-amount, 12px));
    -webkit-backdrop-filter: blur(var(--blur-amount, 12px));
    border: 1px solid rgba(255,255,255,0.25);
}

/* === Themed Background === */
.themed-background {
    background-color: var(--color-background);
    background-image: var(--bg-image, none);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
}

@media (max-width: 768px) {
    .themed-background {
        background-image: var(--bg-image-mobile, var(--bg-image, none));
        background-attachment: scroll;
    }
}

/* === Room Layout === */
.navbar-room {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    height: 52px;
}

.room-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--color-text);
    text-decoration: none;
    font-size: 1.2rem;
    transition: background 0.15s;
}

.room-back-btn:hover {
    background: rgba(0,0,0,0.1);
    text-decoration: none;
}

.room-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--color-text);
}

.room-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.room-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    padding: var(--space-md);
    height: calc(100vh - 52px);
}

/* Chat panel in room: NO glass background — messages float on the themed background */
.chat-panel-room {
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
}

.chat-panel-room .chat-header {
    padding: var(--space-sm) var(--space-md);
}

.chat-panel-room .messages-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

/* Messages in room are OPAQUE for readability */
.room .message-user,
.room .message-assistant {
    background: var(--color-card);
    border-radius: 12px;
}

/* Input in room is glass (readable but lets background peek through) */
.chat-input-room {
    background: var(--color-card-alpha, rgba(255,255,255,0.85));
    backdrop-filter: blur(var(--blur-amount, 12px));
    -webkit-backdrop-filter: blur(var(--blur-amount, 12px));
    border-top: 1px solid var(--color-border);
    padding: 0;
    border-radius: 0 0 12px 12px;
}

/* Display panel: transparent when empty, glass-matte when displays are open */
.display-panel-room {
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Only apply glass-matte when displays are actually open (not empty) */
.display-panel-room:not(.empty-displays) {
    background: var(--color-card-alpha-matte, rgba(255,255,255,0.92));
    backdrop-filter: blur(var(--blur-amount, 12px));
    -webkit-backdrop-filter: blur(var(--blur-amount, 12px));
    border: 1px solid rgba(255,255,255,0.25);
}

.display-panel-room .display-tabs {
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

.display-panel-room .display-area {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.display-panel-room .display-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-muted);
    font-style: italic;
    opacity: 0.5;
}

/* === Room Mobile Layout === */
@media (max-width: 768px) {
    .room .navbar-room {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
    }

    .room .room-layout {
        display: flex;
        flex-direction: column;
        height: 100vh;
        padding: 0;
        padding-top: 52px;    /* navbar */
        padding-bottom: 96px; /* input (52px) + screen dots (44px) */
        gap: 0;
    }

    .room .chat-panel-room {
        flex: 1;
        min-height: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .room .chat-panel-room .messages-container {
        flex: 1;
        overflow-y: auto;
    }

    /* Input: fixed above screen indicator */
    .room .chat-input-room {
        position: fixed;
        bottom: 44px; /* above screen dots */
        left: 0;
        right: 0;
        z-index: 100;
        border-radius: 0;
        border-top: 1px solid var(--color-border);
        box-sizing: border-box;
        overflow: hidden;
        max-width: 100vw;
    }

    /* Screen indicator: fixed at bottom */
    .room .mobile-chat-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: var(--color-card-alpha, rgba(255,255,255,0.85));
        backdrop-filter: blur(var(--blur-amount, 12px));
        -webkit-backdrop-filter: blur(var(--blur-amount, 12px));
        border-top: 1px solid var(--color-border);
    }

    .room .mobile-screen-indicator {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--space-xs) var(--space-md);
    }

    .room .mobile-screen-dots {
        display: flex;
        gap: var(--space-sm);
        align-items: center;
    }

    /* Hide empty display panel on mobile */
    .display-panel-room.empty-displays {
        display: none;
    }

    /* When display panel has content on mobile: full screen overlay */
    .display-panel-room.mobile-active {
        position: fixed;
        top: 52px;
        left: 0;
        right: 0;
        bottom: 96px;
        z-index: 50;
        border-radius: 0;
        background: var(--color-card-alpha-matte, rgba(255,255,255,0.92));
        backdrop-filter: blur(var(--blur-amount, 12px));
        -webkit-backdrop-filter: blur(var(--blur-amount, 12px));
    }

    /* New conversation button: + icon only on mobile */
    .room #new-chat-btn {
        font-size: 0;
        width: 44px;
        height: 44px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .room #new-chat-btn::before {
        content: "+";
        font-size: 1.5rem;
        font-weight: 300;
        line-height: 1;
    }
}

/* === Portal Layout === */
.portal {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-xl);
    position: relative;
}

.portal-tiles {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-lg);
    max-width: 800px;
    margin: 0 auto;
}

.portal-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 160px;
    height: 160px;
    border-radius: 16px;
    text-decoration: none;
    color: var(--color-text);
    font-weight: 600;
    font-size: 1rem;
    text-align: center;
    padding: var(--space-md);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.portal-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
    text-decoration: none;
}

.portal-tile-name {
    word-wrap: break-word;
}

/* Marble tile variant */
.portal-tile-marble {
    flex-direction: column;
    background: none;
    backdrop-filter: none;
    border: none;
    box-shadow: none;
    padding: 0;
    gap: var(--space-xs);
    width: 180px;
    height: auto;
    animation: marble-float 4s ease-in-out infinite;
}

/* Subtle variation per marble: different duration, delay and amplitude */
.portal-tile-marble:nth-child(1) { animation-duration: 3.8s; animation-delay: 0s; }
.portal-tile-marble:nth-child(2) { animation-duration: 4.3s; animation-delay: -1.7s; }
.portal-tile-marble:nth-child(3) { animation-duration: 3.5s; animation-delay: -0.8s; }
.portal-tile-marble:nth-child(4) { animation-duration: 4.7s; animation-delay: -2.4s; }
.portal-tile-marble:nth-child(5) { animation-duration: 4.1s; animation-delay: -3.1s; }
.portal-tile-marble:nth-child(6) { animation-duration: 3.6s; animation-delay: -1.2s; }
.portal-tile-marble:nth-child(7) { animation-duration: 4.5s; animation-delay: -2.8s; }
.portal-tile-marble:nth-child(8) { animation-duration: 3.9s; animation-delay: -0.5s; }

.portal-tile-marble:hover {
    box-shadow: none;
    animation-play-state: paused;
    transform: translateY(-4px) scale(1.05);
}

.portal-tile-marble .portal-tile-name {
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.7), 0 0 12px rgba(0,0,0,0.4);
}

.portal-tile-marble-img {
    width: 140px;
    height: 140px;
    object-fit: contain;
}

@keyframes marble-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@media (max-width: 768px) {
    .portal-tile-marble {
        width: 140px;
    }
    .portal-tile-marble-img {
        width: 110px;
        height: 110px;
    }
}

/* Theme switcher trigger */
.theme-switcher-trigger {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--color-card-alpha, rgba(255,255,255,0.85));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    transition: transform 0.2s;
    z-index: 100;
    color: var(--color-text);
}

.theme-switcher-trigger:hover {
    transform: scale(1.1);
}

.theme-switcher-trigger svg {
    width: 22px;
    height: 22px;
}

/* Theme switcher overlay */
.theme-switcher-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-xl);
    flex-wrap: wrap;
    padding: var(--space-xl);
}

.theme-switcher-overlay[hidden] {
    display: none;
}

.theme-circle {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.3);
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    overflow: hidden;
    position: relative;
    background-size: cover;
    background-position: center;
    background-color: var(--color-background);
}

.theme-circle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    border-color: rgba(255,255,255,0.6);
}

.theme-circle-label {
    position: absolute;
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.theme-switcher-close {
    position: absolute;
    top: var(--space-lg);
    right: var(--space-lg);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.theme-switcher-close:hover {
    background: rgba(255,255,255,0.3);
}

@media (max-width: 768px) {
    .theme-circle {
        width: 140px;
        height: 140px;
    }

    .theme-switcher-overlay {
        gap: var(--space-md);
        padding: var(--space-md);
    }

    .portal-tile {
        width: 130px;
        height: 130px;
    }
}

/* Recent conversations */
.portal-recent {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: 100;
}

.portal-recent-trigger {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: var(--color-card-alpha, rgba(255,255,255,0.85));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    transition: transform 0.2s;
    font-size: 1.3rem;
    color: var(--color-text);
}

.portal-recent-trigger:hover {
    transform: scale(1.1);
}

.portal-recent-trigger svg {
    width: 24px;
    height: 24px;
}

.portal-recent-list {
    position: absolute;
    bottom: 60px;
    right: 0;
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    border-radius: 12px;
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.portal-recent-list[hidden] {
    display: none;
}

.portal-recent-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-radius: 8px;
    text-decoration: none;
    color: var(--color-text);
    transition: background 0.15s;
}

.portal-recent-item:hover {
    background: rgba(0,0,0,0.05);
    text-decoration: none;
}

.recent-agent {
    font-weight: 500;
    font-size: 0.9rem;
}

.recent-time {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Underwater link — vertically aligned with the history button (50px tall) */
.portal-underwater {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.7;
    transition: opacity 0.3s, transform 0.3s;
    text-decoration: none;
    height: 50px;
    display: flex;
    align-items: center;
}

.portal-underwater:hover {
    opacity: 1;
    transform: translateX(-50%) translateY(-2px);
}

.portal-underwater img {
    max-width: 200px;
    width: 100%;
    height: auto;
}

@media (max-width: 768px) {
    .portal-underwater img {
        max-width: 150px;
    }
}

/* Sam — fixed guide marble bottom-left */
.portal-sam {
    position: fixed;
    bottom: var(--space-lg);
    left: var(--space-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    transition: transform 0.2s;
    animation: marble-float 4.1s ease-in-out infinite;
}

.portal-sam:hover {
    transform: scale(1.08);
    animation-play-state: paused;
}

.portal-sam-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.portal-sam-label {
    color: var(--color-text);
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 2px;
    opacity: 0.8;
}

@media (max-width: 768px) {
    .portal-sam {
        bottom: var(--space-md);
        left: var(--space-md);
    }

    .portal-sam-img {
        width: 60px;
        height: 60px;
    }
}
