/* === Base Reset & Variables === */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-surface: #0f3460;
    --bg-input: #1a1a3e;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0b8;
    --text-muted: #6b6b80;
    --accent: #4f8ff7;
    --accent-hover: #3a7be0;
    --error: #e74c3c;
    --error-bg: rgba(231, 76, 60, 0.15);
    --success: #2ecc71;
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(79, 143, 247, 0.5);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-lg: 12px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

.app-container {
    height: 100%;
    overflow-y: auto;
}

/* === Auth Pages === */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-form h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.25rem;
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.form-group-inline label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.form-group-inline input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
    cursor: pointer;
}

.form-input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font);
    transition: border-color 0.2s;
}

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

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

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

.auth-card .btn-primary {
    width: 100%;
    margin-top: 0.5rem;
}

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

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--accent);
    text-decoration: none;
    margin-left: 0.3rem;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.validation-message {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 0.3rem;
}

/* === Chat Layout === */
.chat-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease, transform 0.25s ease;
}

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

/* Backdrop for mobile overlay */
.sidebar-backdrop {
    display: none;
}

/* Hamburger toggle */
.btn-hamburger {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 5;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius);
    padding: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

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

.sidebar-header h3 {
    color: var(--accent);
    font-size: 1.1rem;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius);
    padding: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.sidebar-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.session-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}

.session-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.session-item.active {
    background: var(--bg-surface);
}

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

.session-rename-input {
    font-size: 0.9rem;
    width: 100%;
    padding: 0.15rem 0.3rem;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text);
    outline: none;
}

/* Context menu */
.context-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999;
}

.context-menu {
    position: fixed;
    z-index: 1000;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.25rem;
    min-width: 140px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 6px;
}

.context-menu-item:hover {
    background: var(--bg-tertiary);
}

.context-menu-danger {
    color: #ef4444;
}

.context-menu-danger:hover {
    background: rgba(239, 68, 68, 0.15);
}

.session-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.sidebar-footer {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.3rem 0.75rem;
    margin-top: 0.25rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-family: var(--font);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.btn-logout svg {
    width: 14px;
    height: 14px;
}

.btn-logout:hover {
    background: rgba(231, 76, 60, 0.1);
    color: var(--error);
}

.nav-menu-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.3rem 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.nav-menu-toggle svg:first-child {
    width: 13px;
    height: 13px;
}

.nav-menu-toggle:hover {
    background: var(--hover);
    color: var(--text);
}

.nav-menu-toggle .chevron {
    margin-left: auto;
    transition: transform 0.2s;
    transform: rotate(0deg);
}

.nav-menu-toggle .chevron.expanded {
    transform: rotate(90deg);
}

.btn-nav {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.3rem 0.75rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: var(--font);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.2s;
    text-decoration: none;
}

.btn-nav svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.nav-accordion-items .btn-nav {
    padding-left: 1.5rem;
    font-size: 0.78rem;
}

.nav-accordion-items .btn-nav svg {
    width: 13px;
    height: 13px;
}

.btn-nav:hover {
    background: rgba(79, 143, 247, 0.1);
    color: var(--accent);
}

/* === Project Tree === */
.project-section {
    margin-bottom: 2px;
}

.project-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.project-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.project-header .chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

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

.project-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.project-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.project-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    flex-shrink: 0;
}

.project-section .session-item {
    padding-left: 2.5rem;
}

.project-nested {
    padding-left: 1rem;
}

.project-nested .session-item {
    padding-left: 2.5rem;
}

.sidebar-empty-project {
    padding: 0.4rem 1rem 0.4rem 2.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.btn-add-project {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: calc(100% - 1rem);
    margin: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: none;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: var(--font);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.btn-add-project:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(79, 143, 247, 0.05);
}

.project-create-form {
    padding: 0.5rem;
}

.project-create-input {
    font-size: 0.85rem;
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text);
    outline: none;
    font-family: var(--font);
}

.project-rename-input {
    font-size: 0.85rem;
    flex: 1;
    padding: 0.15rem 0.3rem;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text);
    outline: none;
    font-family: var(--font);
}

.context-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 0.25rem 0;
}

.context-menu-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0.25rem 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Project Viewer Page === */
.project-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
}

.project-card-new {
    border-color: var(--accent);
    border-style: dashed;
}

.project-card-inbox {
    border-style: dashed;
    opacity: 0.85;
}

.project-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    user-select: none;
}

.project-card-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.project-card-header h3 {
    font-size: 0.95rem;
    font-weight: 500;
    margin: 0;
    flex: 1;
}

.project-card-header .chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.project-card-header .chevron.expanded {
    transform: rotate(90deg);
}

.project-session-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.project-card-toolbar {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.project-card-header:hover .project-card-toolbar {
    opacity: 1;
}

.btn-icon-sm {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.25rem;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.btn-icon-sm:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.btn-danger-sm:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.project-card-body {
    padding: 0 1rem 1rem;
}

.project-card-desc {
    padding: 0 1rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.4;
}

.project-card-desc h1, .project-card-desc h2, .project-card-desc h3 {
    font-size: 0.9rem;
    margin: 0.5rem 0 0.25rem;
    color: var(--text-primary);
}

.project-card-desc h1:first-child, .project-card-desc h2:first-child, .project-card-desc h3:first-child {
    margin-top: 0;
}

.project-card-desc p {
    margin: 0 0 0.4em;
}

.project-card-desc ul, .project-card-desc ol {
    margin: 0 0 0.4em;
    padding-left: 1.2rem;
}

.project-card-desc table {
    font-size: 0.75rem;
    border-collapse: collapse;
    width: 100%;
    margin: 0.4em 0;
}

.project-card-desc th, .project-card-desc td {
    border: 1px solid rgba(255,255,255,0.1);
    padding: 0.2rem 0.4rem;
    text-align: left;
}

.project-card-desc th {
    background: rgba(255,255,255,0.05);
}

.project-card-desc code {
    font-size: 0.75rem;
    background: rgba(0,0,0,0.3);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

.project-card-desc pre {
    font-size: 0.75rem;
    background: rgba(0,0,0,0.3);
    padding: 0.5rem;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.4em 0;
}

.project-card-desc strong {
    color: var(--text-primary);
}

.project-card-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

.project-sessions-list {
    padding: 0 1rem 0.75rem;
}

.project-session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 2px;
}

.project-session-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.project-session-title {
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.project-session-title:hover {
    color: var(--accent);
}

.project-session-move {
    font-size: 0.7rem;
    padding: 0.15rem 0.3rem;
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
    font-family: var(--font);
}

.project-session-item:hover .project-session-move {
    opacity: 1;
}

.project-session-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    margin-left: 0.5rem;
}

/* === Chat Main === */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    position: relative;
}

/* === Drop Zone Overlay === */
.drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 100;
    background: rgba(79, 143, 247, 0.08);
    backdrop-filter: blur(4px);
    border: 3px dashed var(--accent);
    border-radius: var(--radius-lg);
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.chat-main.drag-over .drop-overlay {
    display: flex;
}

.drop-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--accent);
}

.drop-overlay-content p {
    font-size: 1.1rem;
    font-weight: 500;
}

.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.chat-welcome h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* === Date Separator === */
.date-separator {
    align-self: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.25rem 0.75rem;
    background: var(--bg-surface);
    border-radius: var(--radius);
    text-align: center;
    user-select: none;
}

.date-separator:empty {
    display: none;
}

/* === Messages === */
.message {
    max-width: 75%;
    animation: fadeIn 0.2s ease;
    position: relative;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 0.1rem;
    padding: 0 0.25rem;
    min-height: 16px;
    gap: 0.5rem;
}

.message-time {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.25);
    margin-left: auto;
    user-select: none;
    line-height: 1;
    flex-shrink: 0;
}

.message-time:empty {
    display: none;
}

.message-user .message-time {
    color: rgba(255, 255, 255, 0.2);
}

.message-user {
    align-self: flex-end;
}

.message-assistant, .message-system {
    align-self: flex-start;
}

.message-content {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.message-user .message-content {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-assistant .message-content {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-system .message-content {
    background: var(--error-bg);
    color: var(--error);
    font-size: 0.85rem;
}

.message-content.streaming::after {
    content: '\25CF';
    animation: blink 1s infinite;
    margin-left: 2px;
    color: var(--accent);
}

/* === Markdown in Messages === */
.message-content.markdown-body {
    white-space: normal;
}

.markdown-body p {
    margin: 0 0 0.5em;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: 0.75em 0 0.4em;
    font-weight: 600;
    line-height: 1.3;
}

.markdown-body h1 { font-size: 1.3em; }
.markdown-body h2 { font-size: 1.15em; }
.markdown-body h3 { font-size: 1.05em; }

.markdown-body ul, .markdown-body ol {
    margin: 0.4em 0;
    padding-left: 1.5em;
}

.markdown-body li {
    margin-bottom: 0.2em;
}

.markdown-body code {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.15em 0.35em;
    border-radius: 3px;
    font-size: 0.88em;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

.markdown-body pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.5em 0;
    position: relative;
}

.code-copy-btn {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.markdown-body pre:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.code-copy-btn.copied {
    color: var(--success);
    opacity: 1;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    white-space: pre;
}

.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 0.5em 0;
    padding: 0.25em 0.75em;
    color: var(--text-secondary);
}

.markdown-body table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
    display: block;
    overflow-x: auto;
}

.markdown-body th, .markdown-body td {
    border: 1px solid var(--border);
    padding: 0.4em 0.6em;
    text-align: left;
}

.markdown-body th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.75em 0;
}

.markdown-body a {
    color: #f87171;
    text-decoration: underline;
    word-break: break-all;
}

.message-user .markdown-body a {
    color: #fca5a5;
}

.markdown-body strong {
    font-weight: 600;
}

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

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* === Chat Error Toast === */
.chat-error-toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0 1.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(220, 53, 69, 0.15);
    border: 1px solid rgba(220, 53, 69, 0.3);
    border-radius: var(--radius);
    color: #f08080;
    font-size: 0.85rem;
}

.chat-error-toast button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 2px;
    opacity: 0.7;
}

.chat-error-toast button:hover {
    opacity: 1;
}

/* === Chat Input === */
.chat-input-area {
    padding: 1rem 1.5rem 1.5rem;
    border-top: 1px solid var(--border);
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
    transition: border-color 0.2s;
}

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

.chat-textarea {
    flex: 1;
    resize: none;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font);
    padding: 0.5rem;
    min-height: 1.4em;
    max-height: 30vh;
    line-height: 1.4;
    overflow-y: auto;
    field-sizing: content;
}

.chat-textarea:focus {
    outline: none;
}

.chat-textarea::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: var(--accent);
    border: none;
    color: white;
    border-radius: var(--radius);
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
}

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

.btn-stop {
    background: var(--danger, #e74c3c);
    border: none;
    color: white;
    border-radius: var(--radius);
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
    animation: pulse-stop 1.5s ease-in-out infinite;
}

.btn-stop:hover {
    background: #c0392b;
}

@keyframes pulse-stop {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* === Scroll to bottom FAB === */
.btn-scroll-bottom {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    z-index: 10;
    opacity: 0.85;
}

.btn-scroll-bottom:hover {
    opacity: 1;
    background: var(--accent-hover);
    color: white;
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* === Routines Layout === */
.routines-layout {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    min-height: 100vh;
}

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

.routines-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.routines-title h2 {
    font-size: 1.4rem;
}

.btn-back {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius);
    padding: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.btn-accent {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--accent);
    color: white;
}

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

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-secondary);
}

.btn-danger-outline {
    background: none;
    color: var(--error);
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.btn-danger-outline:hover:not(:disabled) {
    background: var(--error-bg);
}

.routines-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.routines-empty.small {
    padding: 1.5rem 1rem;
}

.routines-empty p {
    margin-bottom: 0.5rem;
}

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

/* === Routine Cards === */
.routines-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.routine-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.routine-card:hover {
    border-color: var(--border-focus);
    background: rgba(22, 33, 62, 0.8);
}

.routine-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.routine-name {
    font-size: 1.05rem;
    font-weight: 600;
}

.routine-description {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.routine-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.routine-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-trigger {
    background: rgba(79, 143, 247, 0.15);
    color: var(--accent);
}

.badge-autonomy {
    border: 1px solid;
}

.badge-autonomy.autonomy-inform {
    background: rgba(155, 89, 182, 0.15);
    color: #b39ddb;
    border-color: rgba(155, 89, 182, 0.3);
}

.badge-autonomy.autonomy-offer {
    background: rgba(241, 196, 15, 0.15);
    color: #f1c40f;
    border-color: rgba(241, 196, 15, 0.3);
}

.badge-autonomy.autonomy-confirm {
    background: rgba(230, 126, 34, 0.15);
    color: #e67e22;
    border-color: rgba(230, 126, 34, 0.3);
}

.badge-autonomy.autonomy-autonomous {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
    border-color: rgba(46, 204, 113, 0.3);
}

.badge-priority {
    border: 1px solid;
}

.badge-priority.priority-low {
    background: rgba(149, 165, 166, 0.15);
    color: #95a5a6;
    border-color: rgba(149, 165, 166, 0.3);
}

.badge-priority.priority-medium {
    background: rgba(79, 143, 247, 0.15);
    color: var(--accent);
    border-color: rgba(79, 143, 247, 0.3);
}

.badge-priority.priority-high {
    background: rgba(230, 126, 34, 0.15);
    color: #e67e22;
    border-color: rgba(230, 126, 34, 0.3);
}

.badge-priority.priority-critical {
    background: var(--error-bg);
    color: var(--error);
    border-color: rgba(231, 76, 60, 0.3);
}

.routine-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

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

/* === Toggle Switch === */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 22px;
    transition: 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: rgba(46, 204, 113, 0.25);
    border-color: rgba(46, 204, 113, 0.5);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
    background: var(--success);
}

.routine-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* === Routine Detail === */
.detail-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.detail-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.section-title {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.detail-row {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 100px;
    padding-top: 0.1rem;
}

.detail-value {
    font-size: 0.9rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.trigger-config {
    font-size: 0.8rem;
    background: var(--bg-input);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    color: var(--text-secondary);
}

.detail-prompt {
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 0.75rem;
    border-radius: var(--radius);
    line-height: 1.5;
    white-space: pre-wrap;
}

/* === Autonomy Control === */
.autonomy-levels {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.autonomy-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.autonomy-btn:hover {
    border-color: var(--border-focus);
}

.autonomy-btn.active {
    background: rgba(79, 143, 247, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

.autonomy-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.autonomy-desc {
    font-size: 0.7rem;
    text-align: center;
    line-height: 1.3;
}

.autonomy-info {
    text-align: center;
}

/* === Execution History === */
.execution-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.execution-item {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 0.75rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    border: 1px solid transparent;
}

.execution-item:hover {
    background: var(--bg-hover);
}

.execution-item.selected {
    border-color: var(--accent);
    background: var(--bg-hover);
}

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

.execution-outcome {
    font-size: 0.85rem;
    font-weight: 500;
}

.execution-outcome.outcome-success {
    color: var(--success);
}

.execution-outcome.outcome-failed {
    color: var(--error);
}

.execution-outcome.outcome-useroverride {
    color: #f1c40f;
}

.execution-outcome.outcome-skipped {
    color: var(--text-muted);
}

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

.execution-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.execution-history-header .section-title {
    margin: 0;
}

.execution-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.execution-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.execution-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

.btn-page {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
}

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

.btn-page:disabled {
    opacity: 0.4;
    cursor: default;
}

.page-info {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.execution-duration {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-mono, monospace);
}

/* Execution Accordion */
.execution-chevron {
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
    display: inline-block;
}

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

.execution-accordion-body {
    border-top: 1px solid var(--border);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
}

.execution-detail-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

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

.execution-detail-duration {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--font-mono, monospace);
}

/* Execution Context Panel */
.exec-context-panel {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.exec-context-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary, rgba(255,255,255,0.03));
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}

.exec-context-toggle:hover {
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
}

.exec-context-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-top: 1px solid var(--border);
}

.exec-context-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.exec-context-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.exec-context-details summary {
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.exec-context-prompt {
    font-size: 0.75rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg-secondary, rgba(0,0,0,0.2));
    border-radius: var(--radius);
    margin-top: 0.25rem;
}

/* Execution Conversation */
.execution-conversation {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.exec-msg {
    border-radius: var(--radius);
    padding: 0.75rem;
}

.exec-msg-user {
    background: var(--bg-hover);
}

.exec-msg-assistant {
    background: transparent;
}

.exec-msg-role {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.exec-msg-content {
    font-size: 0.85rem;
    line-height: 1.6;
}

.exec-segment-text {
    margin-bottom: 0.5rem;
}

/* === Create Routine Form === */
.create-form {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.form-textarea {
    resize: vertical;
    min-height: 60px;
    line-height: 1.5;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-half {
    flex: 1;
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.tool-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.tool-checkbox {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.tool-checkbox:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.tool-checkbox input[type="checkbox"] {
    accent-color: var(--accent);
}

.tool-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

/* === Tutorial Overlay === */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 50000;
    background: rgba(0, 0, 0, 0.7);
    animation: tutorialFadeIn 0.3s ease;
}

.tutorial-overlay.tutorial-fade-out {
    animation: tutorialFadeOut 0.3s ease forwards;
}

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

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

.tutorial-spotlight {
    position: absolute;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
    border: 2px solid var(--accent);
    border-radius: 12px;
    transition: all 0.35s ease;
    z-index: 50001;
}

.tutorial-tooltip {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    max-width: min(360px, calc(100vw - 2rem));
    min-width: 0;
    width: calc(100vw - 2rem);
    z-index: 50002;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    transition: top 0.35s ease, left 0.35s ease;
}

@media (min-width: 420px) {
    .tutorial-tooltip {
        min-width: 280px;
        width: auto;
    }
}

.tutorial-step-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.tutorial-step-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.tutorial-tooltip-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tutorial-progress {
    display: flex;
    gap: 6px;
    align-items: center;
}

.tutorial-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    transition: background 0.2s;
}

.tutorial-dot.active {
    background: var(--accent);
    transform: scale(1.2);
}

.tutorial-dot.done {
    background: rgba(79, 143, 247, 0.5);
}

.tutorial-actions {
    display: flex;
    gap: 0.5rem;
}

.tutorial-btn-skip,
.tutorial-btn-back,
.tutorial-btn-next {
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
}

.tutorial-btn-skip {
    background: transparent;
    color: var(--text-muted);
}

.tutorial-btn-skip:hover {
    color: var(--text-secondary);
}

.tutorial-btn-back {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.tutorial-btn-back:hover {
    background: rgba(255, 255, 255, 0.08);
}

.tutorial-btn-next {
    background: var(--accent);
    color: white;
}

.tutorial-btn-next:hover {
    background: var(--accent-hover);
}

/* === Feature Checkboxes === */
.feature-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
}

.feature-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.4rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.feature-checkbox:hover {
    background: rgba(255, 255, 255, 0.05);
}

.feature-checkbox input[type="checkbox"] {
    accent-color: var(--accent);
}

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

.feature-desc {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

.tool-picker-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.btn-tool-action {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
}

.btn-tool-action:hover {
    border-color: var(--accent);
    background: var(--bg-secondary);
}

.tool-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
}

.tool-picker-grouped {
    margin-top: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 300px;
    overflow-y: auto;
}

.tool-group {
    border-bottom: 1px solid var(--border);
}

.tool-group:last-child {
    border-bottom: none;
}

.tool-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}

.tool-group-header:hover {
    background: var(--bg-secondary);
}

.tool-group-chevron {
    font-size: 0.65rem;
    transition: transform 0.2s;
    color: var(--text-muted);
}

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

.tool-group-name {
    flex: 1;
    text-align: left;
}

.tool-group-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.tool-group-icon {
    font-size: 0.85rem;
    flex-shrink: 0;
}

.tool-group-toggle {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
    margin-right: 0.5rem;
}

.btn-group-select {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    font-size: 0.65rem;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    cursor: pointer;
    font-weight: 500;
}

.btn-group-select:hover {
    border-color: var(--accent);
    background: var(--bg-secondary);
}

.tool-picker-grouped.compact {
    max-height: 350px;
}

.tool-picker-grouped.compact .tool-group-items {
    padding: 0.2rem 0.5rem 0.4rem 1.2rem;
}

.tool-picker-grouped.compact .tool-checkbox {
    padding: 0.25rem 0.4rem;
    font-size: 0.8rem;
    border: none;
    background: transparent;
}

.tool-picker-grouped.compact .tool-checkbox:hover {
    background: var(--bg-surface);
}

.tool-group-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.25rem 0.75rem 0.5rem 1.5rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* === Settings - Success Alert === */
.alert-success {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
    border: 1px solid rgba(46, 204, 113, 0.3);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* === Settings - Devices === */
.devices-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.device-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

.device-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.device-icon {
    font-size: 1.25rem;
}

.device-type {
    font-size: 0.9rem;
    font-weight: 500;
}

.device-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.device-status.connected {
    color: var(--success);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

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

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

/* === Admin Dashboard === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-align: center;
}

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

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.stat-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.admin-table-wrapper {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-table th {
    text-align: left;
    padding: 0.75rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.admin-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.admin-table .row-inactive {
    opacity: 0.5;
}

.user-cell {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 500;
}

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

.action-buttons {
    display: flex;
    gap: 0.5rem;
}

/* === Admin Navigation Cards === */
.admin-nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.admin-nav-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: border-color 0.2s, background 0.2s;
}

.admin-nav-card:hover {
    border-color: var(--border-focus);
    background: rgba(22, 33, 62, 0.8);
}

.admin-nav-card svg {
    color: var(--accent);
    flex-shrink: 0;
}

.admin-nav-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.admin-nav-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* === Tool Trust === */
.tool-trust-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.tool-trust-actions .form-control-sm {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
    width: auto;
    min-width: 160px;
}

.tool-trust-actions select.form-control-sm {
    min-width: 180px;
}

.tool-name-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tool-name-cell code {
    font-size: 0.85rem;
    color: var(--text-primary);
    background: var(--bg-input);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.tool-trust-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tool-trust-indicator.trust-open { background: var(--success); }
.tool-trust-indicator.trust-low { background: var(--success); }
.tool-trust-indicator.trust-medium { background: #f39c12; }
.tool-trust-indicator.trust-high { background: var(--error); }

.trust-edit-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.trust-slider {
    width: 100px;
    accent-color: var(--accent);
}

.trust-value {
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 2rem;
    text-align: center;
}

.trust-value.trust-open,
.trust-value.trust-low { color: var(--success); }
.trust-value.trust-medium { color: #f39c12; }
.trust-value.trust-high { color: var(--error); }

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

/* === Model Configuration === */
.assignments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.assignment-card {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
}

.assignment-role {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.btn-clear {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.btn-clear:hover {
    color: var(--error);
}

.form-select {
    appearance: auto;
    cursor: pointer;
}

.section-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: -0.5rem;
    margin-bottom: 0.75rem;
}

.models-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.model-card {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 1rem;
    transition: opacity 0.2s;
}

.model-card.model-inactive {
    opacity: 0.5;
}

.model-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.model-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.model-id {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
    margin-top: 0.1rem;
}

.model-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.model-details {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.model-endpoint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: monospace;
}

.model-caps {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.model-edit-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.model-edit-form label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.capability-checkboxes {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.capability-check {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.capability-check input[type="checkbox"] {
    accent-color: var(--accent);
}

/* === Prompt Management === */
.purpose-tabs {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
}

.purpose-tab {
    padding: 0.4rem 0.75rem;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.purpose-tab:hover {
    background: rgba(255, 255, 255, 0.05);
}

.purpose-tab.active {
    background: var(--bg-surface);
    color: var(--accent);
    border-color: var(--accent);
}

.prompts-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.prompt-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.prompt-card.prompt-active {
    border-color: rgba(46, 204, 113, 0.3);
}

.prompt-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.prompt-card-header > div:first-child {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.prompt-version {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.prompt-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 0.75rem;
    border-radius: var(--radius);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

.prompt-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.prompt-textarea {
    min-height: 120px;
}

.prompt-edit {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.prompt-edit label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

/* === Attachment Styles === */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.attachment-image {
    max-width: 240px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-input);
    border: 1px solid var(--border);
}

.attachment-image img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    display: block;
}

.attachment-image .attachment-name {
    display: block;
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Image Lightbox === */
.lightbox-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    cursor: pointer;
    transition: background 0.2s ease;
}

.lightbox-backdrop.lightbox-visible {
    background: rgba(0, 0, 0, 0.9);
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.75rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.lightbox-visible .lightbox-close {
    opacity: 0.8;
}

.lightbox-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-image {
    max-width: 90vw;
    max-height: 82vh;
    object-fit: contain;
    border-radius: var(--radius);
    cursor: default;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.lightbox-visible .lightbox-image {
    opacity: 1;
    transform: scale(1);
}

.lightbox-caption {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
    margin-top: 0.75rem;
    text-align: center;
    opacity: 0;
    transition: opacity 0.2s ease 0.1s;
}

.lightbox-visible .lightbox-caption {
    opacity: 1;
}

.lightbox-audio-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    min-width: 320px;
    max-width: 90vw;
    cursor: default;
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.lightbox-visible .lightbox-audio-card {
    opacity: 1;
    transform: scale(1);
}

.lightbox-audio-icon {
    color: var(--accent);
    opacity: 0.7;
}

.lightbox-audio-title {
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: center;
    word-break: break-all;
}

.lightbox-audio-player {
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius);
    outline: none;
}

.attachment-audio {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
    transition: border-color 0.15s;
}

.attachment-audio:hover {
    border-color: var(--accent);
}

.attachment-audio svg {
    color: var(--accent);
    flex-shrink: 0;
}

.attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
}

.attachment-file svg {
    color: var(--accent);
    flex-shrink: 0;
}

.attachment-link {
    color: var(--accent);
    text-decoration: none;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-link:hover {
    text-decoration: underline;
}

.attachment-size {
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* === Staged Attachments === */
.staged-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.5rem 0;
}

.staged-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.25rem 0.5rem 0.25rem 0.6rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    animation: fadeIn 0.2s ease;
}

.staged-chip svg {
    color: var(--accent);
    flex-shrink: 0;
}

.staged-name {
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.staged-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.15rem;
    border-radius: 50%;
    transition: all 0.2s;
}

.staged-remove:hover {
    background: rgba(231, 76, 60, 0.2);
    color: var(--error);
}

/* === Mic Button === */
.btn-mic {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-mic:hover:not(:disabled) {
    color: var(--accent);
    background: rgba(79, 143, 247, 0.1);
}

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

.btn-mic.recording {
    color: var(--error);
    background: var(--error-bg);
    animation: pulse-mic 1.5s ease-in-out infinite;
}

@keyframes pulse-mic {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50% { opacity: 0.85; box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
}

/* === Voice Mode Toggle === */
.btn-mode-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.btn-mode-toggle:hover:not(:disabled) {
    color: var(--accent);
    background: rgba(79, 143, 247, 0.1);
}
.btn-mode-toggle.meeting {
    color: #e67e22;
    background: rgba(230, 126, 34, 0.1);
}
.btn-mode-toggle:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* === Meeting Status Bar === */
.meeting-status-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(230, 126, 34, 0.1);
    border: 1px solid rgba(230, 126, 34, 0.3);
    border-radius: var(--radius);
    margin: 0 1rem 0.5rem;
    font-size: 0.85rem;
    color: var(--text-primary);
}
.meeting-status-icon {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}
.meeting-status-icon.recording-pulse {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--error);
    animation: pulse-mic 1.5s ease-in-out infinite;
}
.meeting-stats {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-left: auto;
}
.btn-meeting-stop {
    background: var(--error);
    color: white;
    border: none;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: background 0.2s;
}
.btn-meeting-stop:hover {
    background: #c0392b;
}

/* === Meeting Preview === */
.meeting-preview {
    margin: 0 1rem 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 120px;
    overflow-y: auto;
}
.meeting-preview-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}
.meeting-preview-text {
    font-size: 0.8rem;
    color: var(--text-primary);
    line-height: 1.4;
}
.meeting-preview-text p {
    margin: 0.2rem 0;
    padding-left: 0.5rem;
    border-left: 2px solid rgba(230, 126, 34, 0.3);
}

/* === Message Actions (TTS) === */
.message-actions {
    display: flex;
    gap: 0.2rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions,
.message-actions:has(.speaking) {
    opacity: 1;
}

.btn-speak {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-speak:hover:not(:disabled) {
    color: var(--accent);
    background: rgba(79, 143, 247, 0.1);
}

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

.btn-speak.speaking {
    color: var(--accent);
    animation: pulse-stop 1.5s ease-in-out infinite;
}

.btn-copy {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-copy:hover {
    color: var(--accent);
    background: rgba(79, 143, 247, 0.1);
}

/* === Context Menu === */
.context-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999;
}

.context-menu {
    position: fixed;
    z-index: 1000;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.3rem;
    min-width: 160px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.context-menu button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.7rem;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.15s;
}

.context-menu button:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* === Attach Button === */
.btn-attach {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-attach:hover:not(:disabled) {
    color: var(--accent);
    background: rgba(79, 143, 247, 0.1);
}

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

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

.spin {
    animation: spin 1s linear infinite;
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

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

    /* Mobile sidebar as overlay */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        margin-left: 0;
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    }

    .sidebar-collapsed .sidebar {
        margin-left: 0;
        transform: translateX(-100%);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }

    /* Mobile chat messages */
    .message {
        max-width: 90%;
    }

    .chat-messages {
        padding: 0.75rem;
    }

    .message-content {
        font-size: 0.9rem;
        padding: 0.6rem 0.75rem;
    }

    .attachment-image {
        max-width: 180px;
    }
}

/* === Self-Management Page === */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header .section-title {
    margin-bottom: 0;
}

.health-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.health-healthy {
    background: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
}

.health-degraded {
    background: rgba(241, 196, 15, 0.2);
    color: #f1c40f;
}

.health-offline {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
}

.stat-healthy { border-left: 3px solid #2ecc71; }
.stat-degraded { border-left: 3px solid #f1c40f; }
.stat-offline { border-left: 3px solid #e74c3c; }

.error-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.suggestion-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

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

.suggestion-reason {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.suggestion-action {
    color: var(--accent);
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.suggestion-stats {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* === Create User Form === */
.create-user-form {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.form-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 150px;
}

.form-group-btn {
    flex: 0 !important;
    min-width: auto !important;
}

.alert-success {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

/* === Voice Config Page === */
.voice-print-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.voice-print-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.voice-print-label {
    font-size: 0.9rem;
    font-weight: 500;
}

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

.voice-print-upload {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.config-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.test-section {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.test-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.test-result {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

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

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

/* Chat toolbar */
.chat-toolbar {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 5;
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.chat-toolbar .btn-hamburger {
    position: static;
}

.btn-debug-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius);
    padding: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.btn-debug-toggle.active {
    background: rgba(96, 165, 250, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

/* Chat toolbar tool picker */
.tool-picker-wrapper {
    position: relative;
}

.tool-count-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.tool-picker-dropdown {
    position: fixed;
    top: auto;
    left: 8px;
    right: 8px;
    max-width: 360px;
    max-height: 60vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (min-width: 769px) {
    .tool-picker-dropdown {
        position: absolute;
        top: calc(100% + 6px);
        left: auto;
        right: 0;
        width: 320px;
        max-height: 420px;
    }
}

.tool-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.tool-picker-count {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.tool-picker-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.tool-picker-dropdown .tool-picker-actions {
    padding: 0.3rem 0.8rem;
    margin: 0;
    border-bottom: 1px solid var(--border);
}

.tool-picker-dropdown .tool-picker-actions .btn-link {
    font-size: 0.8rem;
}

.tool-picker-list {
    overflow-y: auto;
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tool-picker-list .tool-checkbox {
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
    border: none;
    background: transparent;
}

.tool-picker-list .tool-checkbox:hover {
    background: var(--bg-surface);
}

/* Tool call inline display (inside message bubble) */
.tool-calls-inline {
    margin-bottom: 0.5rem;
}

.tool-call-entry {
    display: flex;
    width: fit-content;
    align-items: center;
    gap: 0.4rem;
    background: rgba(79, 143, 247, 0.1);
    border: 1px solid rgba(79, 143, 247, 0.2);
    border-radius: 6px;
    padding: 0.3rem 0.7rem;
    margin: 0.5rem 0;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.tool-call-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.tool-call-entry.pending {
    background: rgba(79, 143, 247, 0.15);
    border-color: rgba(79, 143, 247, 0.3);
    color: var(--accent);
}

.tool-call-entry.pending .tool-call-header {
    color: var(--accent);
}

.tool-call-entry.complete {
    background: rgba(52, 211, 153, 0.08);
    border-color: rgba(52, 211, 153, 0.15);
}

.tool-call-entry.complete .tool-call-header {
    color: var(--text-secondary);
}

.tool-call-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.tool-call-done {
    color: #34d399;
    font-size: 0.7rem;
}

.tool-call-error {
    color: #f87171;
    font-size: 0.7rem;
}

.tool-call-entry.error .tool-call-name {
    color: #f87171;
}

.tool-call-details {
    margin: 0.25rem 0 0.5rem 1.2rem;
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-left: 2px solid var(--border);
    border-radius: 0 4px 4px 0;
    font-size: 0.8rem;
}

.tool-detail-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.tool-detail-label:first-child {
    margin-top: 0;
}

.tool-detail-label code {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.75rem;
}

.tool-detail-content {
    color: var(--text-primary);
    font-size: 0.7rem;
    line-height: 1.4;
    max-height: 200px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    background: rgba(0, 0, 0, 0.15);
    padding: 0.4rem;
    border-radius: 3px;
    margin: 0.15rem 0 0.25rem;
}

.tool-call-name {
    font-size: 0.85rem;
}

.tool-call-duration {
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-left: 0.25rem;
}

.tool-call-status {
    color: var(--accent);
    font-weight: 400;
}

/* Detail view (admin toggle) */
.tool-call-args, .tool-call-result {
    margin: 0.3rem 0 0 0;
    padding: 0.4rem 0.6rem;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    color: var(--text-secondary);
    max-height: 150px;
    overflow-y: auto;
}

.tool-call-result {
    color: var(--text-muted);
    border-left: 2px solid rgba(74, 222, 128, 0.3);
}

/* === Memory Page === */
.memory-search-bar {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem;
    margin-bottom: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.memory-search-bar .form-input {
    flex: 1;
    min-width: 150px;
}

.memory-category-filter {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 140px;
}

.memory-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.memory-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

.memory-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    flex-wrap: wrap;
}

.memory-category-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    letter-spacing: 0.03em;
}

.category-fact { background: rgba(79, 143, 247, 0.2); color: #6baaff; }
.category-preference { background: rgba(168, 85, 247, 0.2); color: #c084fc; }
.category-decision { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
.category-pattern { background: rgba(52, 211, 153, 0.2); color: #34d399; }
.category-context { background: rgba(251, 146, 60, 0.2); color: #fb923c; }

.memory-relevance {
    font-size: 0.7rem;
    color: var(--accent);
}

.memory-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: auto;
}

.memory-card-content {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.5;
    white-space: pre-wrap;
}

.memory-pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    padding: 1rem 0;
}

/* === Task Management Page === */
.task-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.btn-breadcrumb {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

.btn-breadcrumb:hover {
    background: rgba(79, 143, 247, 0.15);
}

.btn-breadcrumb-back {
    display: flex;
    align-items: center;
    margin-right: 0.25rem;
    color: var(--text-secondary);
}

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

.task-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.task-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 1rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.task-card:hover {
    border-color: var(--accent);
}

.task-card-leaf {
    cursor: default;
}

.task-card-leaf:hover {
    border-color: var(--border);
}

.task-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.task-card-name {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.task-completed {
    text-decoration: line-through;
    color: var(--text-muted);
}

.task-card-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
    line-height: 1.4;
}

.task-drill-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.task-status-badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.15rem 0.45rem;
    border-radius: 10px;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.status-active, .status-in_progress, .status-in-progress { background: rgba(79, 143, 247, 0.2); color: #6baaff; }
.status-completed, .status-done { background: rgba(52, 211, 153, 0.2); color: #34d399; }
.status-pending, .status-todo, .status-backlog { background: rgba(161, 161, 170, 0.2); color: #a1a1aa; }
.status-blocked { background: rgba(244, 67, 54, 0.2); color: #f44336; }

.task-priority {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}

.task-status-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.task-status-toggle.status-completed,
.task-status-toggle.status-done {
    color: #34d399;
}

.task-status-toggle.status-pending,
.task-status-toggle.status-todo,
.task-status-toggle.status-in_progress,
.task-status-toggle.status-in-progress,
.task-status-toggle.status-active {
    color: var(--text-muted);
}

.task-status-toggle:hover {
    color: var(--accent);
}

/* Modal dialog */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary, #16213e);
    border: 1px solid var(--border-color, #2a2a4a);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 480px;
    width: 90%;
}

.confirm-message {
    color: var(--text-secondary);
    margin: 0.5rem 0 1.25rem;
    line-height: 1.5;
}

/* Nav badge for pending count */
.nav-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    background: var(--error, #e74c3c);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 4px;
}

/* === Error Logs === */
.stat-critical { color: #e74c3c !important; }

.row-critical { background: rgba(231, 76, 60, 0.15) !important; }
.row-error { background: rgba(231, 76, 60, 0.07) !important; }
.row-warning { background: rgba(241, 196, 15, 0.07) !important; }

.badge-error { background: rgba(231, 76, 60, 0.2); color: #e74c3c; }
.badge-info { background: rgba(52, 152, 219, 0.2); color: #3498db; }

.error-message-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-nowrap { white-space: nowrap; }
.text-muted { color: var(--text-muted, #888); }

.error-detail-row td { padding: 0 !important; }

.error-detail-panel {
    padding: 12px 16px;
    background: var(--bg-primary, #1a1a2e);
    border-top: 1px solid var(--border, #333);
}

.error-detail-field { margin-bottom: 8px; }
.error-detail-field strong { color: var(--text-secondary, #ccc); }

.error-pre {
    background: rgba(0,0,0,0.3);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 4px 0 0;
    max-height: 300px;
    overflow-y: auto;
}

.error-stacktrace { font-size: 0.75rem; max-height: 400px; }

.admin-table tbody tr { cursor: pointer; }
.admin-table tbody tr:hover { background: rgba(255,255,255,0.03); }
