:root, [data-theme="dark"] {
    --bg-primary: #0d0d0d;
    --bg-secondary: #171717;
    --bg-tertiary: #262626;
    --bg-hover: #2a2a2a;
    --text-primary: #e5e5e5;
    --text-secondary: #a3a3a3;
    --text-muted: #737373;
    --accent: #10b981;
    --border: #2e2e2e;
    --user-bg: #2e2e2e;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e5e5e5;
    --bg-hover: #d9d9d9;
    --text-primary: #1a1a1a;
    --text-secondary: #525252;
    --text-muted: #a3a3a3;
    --accent: #059669;
    --border: #d4d4d4;
    --user-bg: #e5e5e5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
button {
    all: unset;
    cursor: pointer;
    color: inherit;
    font: inherit;
}

/* Inline SVG icons */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.icon svg, .lucide-icon {
    display: block;
    color: inherit;
    stroke: currentColor;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar wrapper — desktop collapse/expand */
.sidebar-wrapper {
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    position: relative;
}
@media (min-width: 769px) {
    .sidebar-wrapper {
        transition: width 0.25s ease, min-width 0.25s ease;
    }
}
.sidebar-wrapper.collapsed {
    width: 0px !important;
    min-width: 0px !important;
    overflow: hidden;
}
.sidebar-wrapper.collapsed .sidebar-header,
.sidebar-wrapper.collapsed .domain-name,
.sidebar-wrapper.collapsed .convo-title,
.sidebar-wrapper.collapsed .convo-icon,
.sidebar-wrapper.collapsed .domain-agents,
.sidebar-wrapper.collapsed .domain-convo-list,
.sidebar-wrapper.collapsed .convo-menu-trigger,
.sidebar-wrapper.collapsed .sidebar-footer,
.sidebar-wrapper.collapsed .domain-toggle,
.sidebar-wrapper.collapsed .section-label,
.sidebar-wrapper.collapsed .date-group-label,
.sidebar-wrapper.collapsed .agents-label,
.sidebar-wrapper.collapsed .convo-list {
    display: none;
}
.sidebar-wrapper.collapsed .sidebar {
    width: 50px;
    min-width: 50px;
    align-items: center;
}
.sidebar-wrapper.collapsed .domains-section {
    padding: 8px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}
.sidebar-wrapper.collapsed .domain-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.sidebar-wrapper.collapsed .domain-header {
    justify-content: center;
    padding: 8px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    margin: 2px 0;
}
.sidebar-wrapper.collapsed .domain-icon {
    margin: 0;
    font-size: 16px;
}
.sidebar-wrapper.collapsed .convo-item {
    display: none;
}

/* Desktop sidebar toggle button (hamburger) */
.sidebar-toggle-btn {
    z-index: 50;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.15s;
}
.sidebar-toggle-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
/* Inside sidebar — top-right */
.sidebar-toggle-btn.sidebar-inside {
    position: absolute;
    top: 4px;
    right: 4px;
}
/* In chat area when sidebar collapsed — top-left */
.sidebar-toggle-btn.chat-inside {
    position: absolute;
    top: 4px;
    left: 4px;
}

/* Sidebar */
.sidebar {
    width: 100%;
    min-width: 0;
    background: transparent;
    border-right: none;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-header { padding: 14px 16px 8px; display: flex; align-items: baseline; gap: 0; }
.sidebar-brand-name {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.3px;
}
.sidebar-brand-sub {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
}

/* Domains section */
.domains-section {
    padding: 4px 8px 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.domains-section .convo-item-wrapper {
    position: relative;
}
.domains-section .convo-context-menu {
    position: fixed;
    z-index: 200;
}
.domain-group {
    margin-bottom: 2px;
}
.domain-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: background 0.1s;
    user-select: none;
}
.domain-header:hover { background: var(--bg-tertiary); }
.domain-icon { font-size: 14px; }
.domain-name { flex: 1; font-weight: 500; }
.domain-toggle {
    font-size: 10px;
    color: var(--text-muted);
}
.domain-agents {
    padding: 0 8px 4px 20px;
}
.agents-label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 4px 12px 2px;
    text-transform: uppercase;
}
.agent-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 13px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.1s;
}
.agent-item:hover { background: var(--bg-tertiary); }
.agent-selected { background: var(--bg-tertiary); color: var(--text-primary); }
.agent-item-icon { font-size: 14px; }
.agent-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-status {
    width: 7px;
    height: 7px;
    min-width: 7px;
    border-radius: 50%;
    background: var(--text-muted);
}
.agent-status.active {
    background: #22c55e;
}
.tutor-badge {
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    white-space: nowrap;
}
.tutor-badge.new { background: #3b82f6; color: white; }
.tutor-badge.progress { background: #f59e0b; color: white; }
.tutor-badge.done { background: #22c55e; color: white; }

/* Section label divider */
.section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 10px 20px 4px;
}

/* Domain header drag-over highlight */
.domain-header.drag-over {
    background: var(--bg-tertiary);
    outline: 1.5px dashed var(--accent);
    outline-offset: -1.5px;
}

/* Date group labels inside domains */
.date-group {
    margin-bottom: 2px;
}
.date-group-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 6px 12px 2px 20px;
    text-transform: uppercase;
}

/* Domain convo list (nested inside domain-group) */
.domain-convo-list {
    padding: 0 4px 4px 8px;
}

/* Conversation item dragging state */
.convo-item.dragging {
    opacity: 0.4;
}
.convo-item-wrapper {
    cursor: grab;
}
.convo-item-wrapper:active {
    cursor: grabbing;
}

.convo-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.convo-item {
    padding: 10px 12px;
    border-radius: 13px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.1s;
}
.convo-item:hover { background: var(--bg-tertiary); }
.convo-item.active { background: var(--bg-tertiary); color: var(--text-primary); }

.convo-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.convo-icon {
    font-size: 14px;
    margin-right: 6px;
    flex-shrink: 0;
}
.convo-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Context menu trigger (three dots) */
.convo-menu-trigger {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
    letter-spacing: 1px;
    border-radius: 4px;
    transition: background 0.1s, color 0.1s;
}
.convo-menu-trigger:hover { color: var(--text-primary); background: var(--bg-hover); }
.convo-item:hover .convo-menu-trigger,
.convo-item .convo-menu-trigger.active,
.agent-item:hover .convo-menu-trigger,
.agent-item .convo-menu-trigger.active { display: block; }

/* Context menu dropdown */
.convo-item-wrapper {
    position: relative;
}
.convo-context-menu {
    position: fixed;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 4px;
    min-width: 150px;
    width: max-content;
    z-index: 300;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.convo-context-menu-item {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.1s, color 0.1s;
}
.convo-context-menu-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.menu-item-icon { margin-right: 8px; flex-shrink: 0; }
.user-menu-item-row {
    display: flex;
    align-items: center;
}
.user-menu-refresh {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
.user-menu-refresh:hover { color: var(--text-primary); background: var(--bg-hover); }
.convo-context-menu-item.danger:hover { color: #ef4444; }

.convo-working-dot, .agent-working-ring {
    width: 14px;
    height: 14px;
    min-width: 14px;
    border-radius: 50%;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    animation: spin 0.7s linear infinite;
    margin-right: 4px;
    background: none;
}

/* Blinking eye — agent needs user attention */
.convo-attention-eye {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    min-width: 18px;
    margin-right: 4px;
    color: var(--accent);
    animation: eye-blink 2.5s ease-in-out infinite;
}
.convo-attention-eye svg {
    width: 14px;
    height: 14px;
}
@keyframes eye-blink {
    0%, 100% { opacity: 1; transform: scaleY(1); }
    45% { opacity: 1; transform: scaleY(1); }
    50% { opacity: 0.3; transform: scaleY(0.1); }
    55% { opacity: 1; transform: scaleY(1); }
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: none;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.footer-user {
    flex: 1;
    min-width: 0;
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
}
.footer-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px;
    flex: 1;
    min-width: 0;
    border-radius: 13px;
    transition: background 0.15s;
}
.footer-user-btn:hover { background: var(--bg-tertiary); }
.avatar-with-status {
    position: relative;
    width: 28px;
    height: 28px;
    min-width: 28px;
}
.user-avatar-small {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: #6366f1;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}
.ws-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}
.ws-online { background: #22c55e; }
.ws-offline { background: #ef4444; animation: pulse-red 1.5s ease-in-out infinite; }
@keyframes pulse-red { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.user-name {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}
.user-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 0;
    padding-bottom: 6px; /* visual gap via padding (stays in hover area) */
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 4px;
    min-width: 220px;
    z-index: 50;
    overflow: hidden;
}
.user-menu-item { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.1s;
}
.user-menu-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.user-menu-danger:hover { color: #ef4444; }

.footer-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.footer-icon-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.footer-icon-btn.voice-recording { color: #ef4444; animation: voice-pulse 1s ease-in-out infinite; }
@keyframes voice-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@media (max-width: 768px) {
    .desktop-only-btn { display: none !important; }
}
.version-label {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.6;
    line-height: 1.2;
}

/* Sidebar resizer */
.sidebar-resizer {
    width: 16px;
    cursor: col-resize;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}
.sidebar-resizer::after {
    content: '';
    width: 2px;
    height: 5%;
    background: var(--border);
    border-radius: 2px;
    transition: height 0.2s, background 0.15s;
}
.sidebar-resizer:hover::after {
    height: 15%;
    background: var(--text-muted);
}

/* Chat area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    height: 100vh;
}
.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    position: relative;
}

.chat-readonly {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    border-top: 1px solid var(--bg-tertiary);
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0 16px;
}

.message {
    max-width: 800px;
    margin: 0 auto;
    padding: 8px 24px;
}

.message-user {
    display: flex;
    justify-content: flex-end;
    padding: 8px 24px;
    max-width: 800px;
    margin: 0 auto;
}

.message-user .bubble {
    background: rgba(255,255,255,0.05);
    border-radius: 13px;
    padding: 10px 16px;
    max-width: 70%;
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    text-align: left;
}
.bubble-text {
    text-align: left;
    overflow-x: auto;
}

.message-assistant {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 24px;
    max-width: 800px;
    margin: 0 auto;
    overflow: hidden;
}

.avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    color: white;
    margin-top: 2px;
}

.content {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

/* Thinking dot */
.thinking-dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: dotPulse 1.2s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.05); opacity: 1; }
}

.agent-working {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
}
.agent-working-label {
    font-size: 13px;
    color: var(--text-muted);
    animation: labelPulse 2s ease-in-out infinite;
}
@keyframes labelPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* Assistant body */
.assistant-body {
    flex: 1;
    min-width: 0;
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: 13px;
}

/* Message action buttons */
.assistant-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}
.assistant-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}
.message-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}
.assistant-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}
.assistant-meta-left {
    display: flex;
    align-items: center;
    gap: 6px;
}
.message-actions-user {
    justify-content: flex-end;
}
.message-actions {
    display: flex;
    gap: 2px;
    opacity: 0.3;
    transition: opacity 0.15s;
}
.message:hover .message-actions { opacity: 1; }
.message-time {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.4;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.message:hover .message-time { opacity: 1; }
.bubble-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    gap: 8px;
}
.bubble-actions-left {
    display: flex;
    flex-direction: row;
    gap: 2px;
    opacity: 0.25;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.message:hover .bubble-actions-left { opacity: 1; }
.bubble-time {
    display: block;
    text-align: right;
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.4;
    margin-top: 2px;
    line-height: 1;
}
.message:hover .bubble-time { opacity: 0.7; }
.message-actions-user {
    justify-content: flex-end;
}
.action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
}
.action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* TTS button: toggle play/stop icon */
.tts-btn .tts-icon-stop { display: none; }
.tts-btn.tts-active .tts-icon-play { display: none; }
.tts-btn.tts-active .tts-icon-stop { display: inline; }

/* TTS button wrapper for long-press ring + menu */
.tts-btn-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Long-press ring animation */
.longpress-ring-wrap {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    color: var(--accent);
}
.longpress-ring-circle {
    stroke-dasharray: 100.53;
    stroke-dashoffset: 100.53;
    animation: ring-fill 1.5s linear forwards;
    transform: rotate(-90deg);
    transform-origin: center;
}
@keyframes ring-fill {
    from { stroke-dashoffset: 100.53; }
    to   { stroke-dashoffset: 0; }
}

/* TTS settings menu */
.tts-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(0,0,0,0.3);
}
.tts-menu {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    min-width: 200px;
    max-width: calc(100vw - 32px);
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.tts-menu-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.tts-menu-radio {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
}
.tts-menu-radio label {
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}
.tts-speed-slider {
    width: 100%;
    accent-color: var(--accent);
}

/* Edit message inline */
.edit-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}
.edit-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--accent);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 8px 10px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    resize: vertical;
    min-height: 40px;
    max-height: 300px;
    line-height: 1.4;
    box-sizing: border-box;
}
.edit-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}
.edit-btns {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}
.edit-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    display: flex;
}
.edit-btn:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
}

/* Chips */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    padding: 1px 6px;
    font-size: 10px;
    line-height: 16px;
    color: var(--text-muted);
    opacity: 0.8;
    margin: 2px 2px;
    white-space: nowrap;
}
.chip:hover { opacity: 1; }
.chip-done { color: #4ade80; }
.chip-error { color: #f87171; }
.chip-running { color: #facc15; }
.chip-email { display: block; margin: 6px 0; padding: 6px 10px; font-size: 12px; }

/* Tool chip tooltip */
.tool-chip-wrapper {
    position: relative;
    cursor: pointer;
}
.tool-tooltip {
    position: fixed;
    z-index: 10000;
    background: #1e1e2e;
    border: 1px solid #313244;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    min-width: 300px;
    max-width: 500px;
    max-height: 250px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: tooltip-fade-in 0.15s ease;
    font-size: 11px;
    line-height: 1.4;
}
@keyframes tooltip-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.tool-tooltip-header {
    display: none; /* hidden — chip already shows tool name */
}
.tool-tooltip-body {
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
}
.tool-tooltip-body::-webkit-scrollbar { width: 4px; }
.tool-tooltip-body::-webkit-scrollbar-thumb { background: #45475a; border-radius: 2px; }
.tool-tooltip-section {
    padding: 6px 10px;
    border-bottom: 1px solid #313244;
}
.tool-tooltip-section:last-child { border-bottom: none; }
.tool-tooltip-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c7086;
    margin-bottom: 3px;
}
.tool-tooltip-pre {
    margin: 0;
    padding: 3px 0;
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 10px;
    line-height: 1.4;
    color: #e0e0e0;
    white-space: pre;
    word-break: normal;
    overflow-x: auto;
}
.tool-tooltip-loading {
    padding: 6px;
    font-size: 9px;
    color: #6c7086;
    text-align: center;
}
.tool-tooltip-empty {
    padding: 12px 10px;
    font-size: 11px;
    color: #6c7086;
    text-align: center;
    font-style: italic;
}
.tool-tooltip-error {
    padding: 12px 10px;
    font-size: 11px;
    color: #f87171;
    text-align: center;
}
.tool-tooltip-close {
    background: none;
    border: none;
    color: #6c7086;
    font-size: 16px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    margin-left: auto;
}
.tool-tooltip-close:hover { color: #cdd6f4; }
.tool-tooltip-backdrop {
    display: none;
}
/* Mobile only: visible backdrop to catch taps */
@media (max-width: 600px) {
    .tool-tooltip-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 9999;
        background: rgba(0,0,0,0.3);
    }
    .tool-tooltip {
        max-width: calc(100vw - 32px);
        max-height: 60vh;
    }
}

/* Elapsed */
.elapsed {
    display: inline-block;
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.5;
    margin-top: 4px;
}

/* Suggestions */
.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 800px;
    margin: 0 auto;
    padding: 4px 64px;
}
.suggestions-answers { padding-top: 4px; }
.suggestions-followups { padding-top: 8px; }

.suggestion-answer, .suggestion-followup {
    border-radius: 13px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border: none;
    font-family: inherit;
}
.suggestion-answer {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.suggestion-answer:hover { background: var(--bg-hover); }

.suggestion-followup {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.suggestion-followup:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

/* Ask User card — rounded card design */
.ask-user-card {
    background: var(--bg-secondary);
    border: 1px solid var(--accent-dim, rgba(99, 102, 241, 0.25));
    border-radius: 16px;
    padding: 18px;
    margin: 10px 0;
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.08);
}
.ask-user-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.ask-user-icon {
    width: 20px; height: 20px;
    color: var(--accent);
    flex-shrink: 0;
}
.ask-user-question {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0 0 14px;
    line-height: 1.4;
}
.ask-user-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ask-user-option {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
}
.ask-user-option:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.ask-user-option:active {
    transform: translateY(0);
}
.ask-user-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}
.ask-user-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    opacity: 0.3;
    gap: 8px;
}
.empty-state h2 { font-size: 24px; font-weight: 500; }
.empty-state p { font-size: 15px; }

/* Loading spinner */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}
.chat-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Fade in */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Input */
.chat-input-area {
    padding: 12px 24px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: transparent;
    border: none;
    flex: 1;
    min-width: 0;
    border-radius: 13px;
    padding: 10px 14px;
    transition: border-color 0.15s;
}
.input-wrapper:focus-within { border-color: #555; }

.chat-text-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    line-height: 1.5;
    font-family: inherit;
    padding: 6px 0;
}
.chat-text-input::placeholder { color: var(--text-muted); }

/* Input buttons container */
.input-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
}

.send-btn, .mic-btn, .stop-btn-input {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}
.send-btn { background: var(--accent); color: white; }
.send-btn:disabled { opacity: 0.2; cursor: default; }
.send-btn:hover:not(:disabled) { opacity: 0.85; }
.mic-btn { background: var(--bg-tertiary); color: var(--text-secondary); }
.mic-btn:hover { opacity: 0.85; }
.stop-btn-input { background: #ef4444; color: white; }
.stop-btn-input:hover { opacity: 0.85; }

/* Push-to-talk recording state */
.mic-btn.recording {
    background: #ef4444;
    color: white;
    animation: pulse 1s ease-in-out infinite;
}
.mic-btn.transcribing {
    background: var(--bg-tertiary);
    color: var(--accent);
    opacity: 0.7;
    pointer-events: none;
}
.mic-spinner {
    animation: spin 1s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Voice recording overlay — push-to-talk visual indicator */
.voice-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    pointer-events: none;
}
.voice-overlay-icon {
    color: white;
    opacity: 0.8;
    animation: pulse 1s ease-in-out infinite;
}
.voice-overlay-hint {
    color: rgba(255,255,255,0.7);
    font-size: 1.1rem;
    margin: 0;
}

/* STT error toast */
.stt-error-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: #ef4444;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 300;
    pointer-events: none;
    animation: fadeInOut 4s ease-in-out forwards;
}
@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
    10% { opacity: 1; transform: translateX(-50%) translateY(0); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg-primary);
}

.login-card {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 40px 32px;
    width: 380px;
}

.login-card h1 {
    font-size: 28px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 28px;
    color: var(--text-primary);
}

.login-card input {
    width: 100%;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    color: var(--text-primary);
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.15s, background 0.2s;
}
.login-card input:focus { border-bottom-color: var(--accent); }
.login-card input:not(:placeholder-shown) {
    background: transparent;
    border-bottom-color: var(--text-muted);
}
.login-card input::placeholder { color: var(--text-muted); }
input, input:focus, input:active {
    background-color: transparent !important;
    color: var(--text-primary) !important;
    color-scheme: dark;
}
[data-theme="light"] input { color-scheme: light; }
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
input:-internal-autofill-selected {
    -webkit-box-shadow: 0 0 0 9999px var(--bg-primary) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    caret-color: var(--text-primary) !important;
    transition: background-color 5000s ease-in-out 0s !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
}

.login-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    border: none;
    border-radius: 13px;
    color: white;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 4px;
    transition: opacity 0.15s;
}
.login-btn:hover { opacity: 0.9; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}
.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 32px;
    width: 380px;
    max-width: 90vw;
}
.modal-card input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 13px;
    color: var(--text-primary);
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
}
.modal-card input:focus { border-color: var(--accent); }
.login-btn:disabled { opacity: 0.4; cursor: default; }

/* Login logo */
.login-logo-img {
    width: 48px;
    height: 48px;
    display: block;
    margin: 0 auto 16px;
}
.login-error { color: #ef4444; font-size: 13px; margin-top: 8px; text-align: center; }

.login-footer {
    position: fixed;
    bottom: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.login-footer .footer-theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-footer .footer-theme-toggle:hover {
    background: var(--bg-hover);
}
.login-footer .theme-icon {
    font-size: 20px;
}
.login-footer .version-label {
    font-size: 12px;
    opacity: 0.5;
}

/* Markdown */
.content p { margin: 6px 0; }
.content ul, .content ol { padding-left: 24px; margin: 6px 0; }
.content li { margin: 3px 0; }
.content a { color: var(--accent); text-decoration: none; }
.content a:hover { text-decoration: underline; }

.content pre {
    background: var(--bg-tertiary);
    border-radius: 13px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
    line-height: 1.5;
}

.content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: "SF Mono", "Fira Code", monospace;
}
.content pre code { background: none; padding: 0; }

.content blockquote {
    border-left: 3px solid var(--border);
    padding-left: 14px;
    color: var(--text-secondary);
    margin: 8px 0;
}

.content {
    overflow-x: auto;
    max-width: 100%;
}
.content table {
    border-collapse: separate;
    border-spacing: 0;
    margin: 6px 0;
    font-size: 13px;
    line-height: 1.3;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.content td, .content th {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}
/* Mobile table scroll wrapper — parser wraps tables in .table-scroll */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 6px 0;
    border-radius: 10px;
}
.table-scroll table {
    margin: 0;
}
.content th, .content td {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    padding: 3px 10px;
    text-align: left;
}
.content th:last-child, .content td:last-child { border-right: none; }
.content tr:last-child td { border-bottom: none; }
.content th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 4px 10px;
}
.content tbody tr { transition: background 0.1s; }
.content tbody tr:hover { background: var(--bg-hover); }

.content h1 { font-size: 22px; margin: 16px 0 8px; }
.content h2 { font-size: 18px; margin: 14px 0 6px; }
.content h3 { font-size: 16px; margin: 12px 0 6px; }
.content strong { font-weight: 600; }
.content em { font-style: italic; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* Mobile */
@media (max-width: 768px) {
    html, body { height: 100dvh; overflow: hidden; }
    .app-shell { height: 100dvh; }

    .sidebar-wrapper {
        position: fixed;
        left: 0;
        top: 0;
        width: 85vw !important;
        min-width: 0 !important;
        height: 100dvh;
        z-index: 100;
        transform: translateX(-85vw);
        display: flex !important;
        overflow: hidden;
    }
    .sidebar-wrapper .sidebar {
        background: var(--bg-primary);
        width: 100%;
        height: 100dvh;
    }
    .sidebar-wrapper.mobile-open {
        transform: translateX(0);
    }
    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: black;
        opacity: 0;
        z-index: 99;
        display: none;
        pointer-events: auto;
    }
    .sidebar-wrapper.mobile-open ~ .mobile-overlay {
        display: block;
        opacity: 0.5;
    }

    .sidebar-resizer { display: none !important; }
    .mobile-input-topbar { display: flex !important; }
    .mobile-hamburger-bottom { display: flex !important; }
    .desktop-only-btn { display: none !important; }

    .chat-area { height: 100dvh; }
    .messages { flex: 1; min-height: 0; }
    .message, .message-user, .message-assistant { padding: 8px 16px; }
    .chat-input-area { padding: 8px 12px env(safe-area-inset-bottom, 12px); }
    .convo-context-menu {
        min-width: 150px;
        width: auto;
        transform: translateY(-100%);
    }
}

/* Mobile overlay (hidden on desktop) */
.mobile-overlay {
    display: none;
}

.mobile-header {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    height: 44px;
}
.mobile-hamburger {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.mobile-hamburger:hover { background: var(--bg-tertiary); }

/* Mobile top bar above input: hamburger + new chat */
.mobile-input-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 2px 12px;
    background: transparent;
    z-index: 10;
    margin-top: -40px;
    pointer-events: none;
    flex-shrink: 0;
}
.mobile-input-topbar > * {
    pointer-events: auto;
}
.mobile-input-topbar .mobile-hamburger-bottom,
.mobile-new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
}
.mobile-input-topbar .mobile-hamburger-bottom:active,
.mobile-new-chat-btn:active { opacity: 0.5; }

.mobile-hamburger-bottom {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 13px;
    flex-shrink: 0;
}
.mobile-hamburger-bottom:hover { color: var(--text-primary); background: var(--bg-tertiary); }

/* Dashboard */
.dashboard {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 32px 24px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
}
.dashboard-greeting {
    margin-bottom: 32px;
}
.dashboard-greeting h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.dashboard-subtitle {
    font-size: 15px;
    color: var(--text-muted);
}
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--bg-secondary);
    border-radius: 13px;
    padding: 16px;
    text-align: center;
}
.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}
.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}
.dashboard-section {
    margin-bottom: 12px;
}
.dashboard-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.dashboard-agents {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.dashboard-agent-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border-radius: 13px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background 0.15s;
}
.dashboard-agent-card:hover { background: var(--bg-tertiary); }
.dashboard-agent-info {
    display: flex;
    flex-direction: column;
}
.dashboard-agent-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}
.dashboard-agent-status {
    font-size: 11px;
    color: var(--accent);
}
.dashboard-recent {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.dashboard-recent-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 13px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.dashboard-recent-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.dashboard-footer {
    margin-top: auto;
    padding-top: 24px;
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.5;
}
.dashboard-bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: transparent;
    margin-top: auto;
    position: sticky;
    bottom: 0;
    margin-left: -24px;
    margin-right: -24px;
    padding-left: 24px;
    padding-right: 24px;
}
.dashboard-bottom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 10px;
    border-radius: 13px;
    transition: color 0.15s, background 0.15s;
}
.dashboard-bottom-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.dashboard-version {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.5;
    flex: 1;
    text-align: center;
}
.mobile-only-btn { display: none; }
@media (max-width: 768px) {
    .mobile-only-btn { display: flex; }
}

/* МЭШ CTA card */
.dashboard-mesh-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 32px 24px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.08), rgba(59, 130, 246, 0.08));
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 16px;
    gap: 12px;
}
.dashboard-mesh-icon { color: #22C55E; opacity: 0.9; }
.dashboard-mesh-title { margin: 0; font-size: 20px; font-weight: 600; color: var(--text-primary); }
.dashboard-mesh-desc { margin: 0; font-size: 14px; color: var(--text-secondary); max-width: 320px; }
.dashboard-mesh-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 12px 28px;
    background: #22C55E;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.dashboard-mesh-btn:hover { background: #16A34A; transform: scale(1.02); }
.dashboard-mesh-btn:active { transform: scale(0.98); }

@media (max-width: 768px) {
    .dashboard { padding: 20px 16px; }
    .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
    .dashboard-greeting h1 { font-size: 22px; }
    .dashboard-mesh-cta { padding: 24px 16px; }
}

/* Email Panel — rounded card design */
.email-panel {
    margin: 10px 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    font-size: 13px;
}
.email-panel.loading {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
}
.email-panel.error {
    padding: 14px 16px;
    color: #ef4444;
    border-radius: 16px;
}
.email-panel-spinner {
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.email-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}
.email-panel-folder {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.email-panel-new-badge {
    background: var(--accent);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}
.email-panel-count {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 12px;
}
.email-panel-list {
    max-height: 400px;
    overflow-y: auto;
}
.email-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
    cursor: pointer;
}
.email-row:last-child { border-bottom: none; }
.email-row:hover { background: var(--bg-hover); }
.email-row-header {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-tertiary);
    padding: 6px 16px;
    cursor: default;
}
.email-unread { font-weight: 600; }
.email-unread-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
    margin-right: 6px;
    flex-shrink: 0;
}
.email-col-from {
    width: 140px;
    min-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.email-col-subject {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}
.email-col-date {
    color: var(--text-secondary);
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
}
.email-attach-icon { margin-left: 4px; font-size: 12px; opacity: 0.7; }

@media (max-width: 600px) {
    .email-col-from { width: 100px; min-width: 70px; font-size: 12px; }
    .email-col-date { font-size: 11px; }
    .email-row { padding: 8px 12px; gap: 6px; }
    .email-panel-header { padding: 8px 12px; }
}

/* MeshAuth Panel */
.mesh-auth-inline-hint {
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: 13px;
    opacity: 0.7;
}
.mesh-auth-panel {
    margin: 0 auto 8px;
    background: #1e293b;
    border-radius: 16px;
    overflow: hidden;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.mesh-auth-header {
    padding: 20px 24px 0;
}
.mesh-auth-title {
    display: block;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 2px;
}
.mesh-auth-agent {
    display: block;
    font-size: 13px;
    color: #94a3b8;
    margin-bottom: 16px;
}
.mesh-auth-form {
    padding: 0 24px 20px;
}
.mesh-auth-label {
    display: block;
    font-size: 12px;
    color: #94a3b8;
    margin-bottom: 4px;
}
.mesh-auth-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 14px;
    outline: none;
    margin-bottom: 12px;
    transition: border-color 0.15s;
}
.mesh-auth-input:focus { border-color: #3b82f6; }
.mesh-auth-btn {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: none;
    background: #3b82f6;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    text-align: center;
    margin-top: 4px;
}
.mesh-auth-btn:hover { background: #2563eb; }
.mesh-auth-btn:disabled { background: #475569; cursor: not-allowed; }
.mesh-auth-info {
    background: #1e3a5f;
    color: #93c5fd;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 14px;
}
.mesh-auth-message {
    padding: 0 24px 8px;
    font-size: 13px;
    color: #f87171;
}
.mesh-auth-children {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
}
.mesh-auth-child {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #334155;
    background: #0f172a;
    cursor: pointer;
    transition: all 0.15s;
}
.mesh-auth-child.selected {
    border-color: #3b82f6;
    background: #1e3a5f;
}
.mesh-auth-child-name { font-size: 14px; font-weight: 500; color: #fff; }
.mesh-auth-child-class { font-size: 12px; color: #94a3b8; }
.mesh-auth-done {
    padding: 14px 24px 20px;
    font-size: 14px;
    font-weight: 500;
    color: #6ee7b7;
    background: #065f46;
    margin: 0 24px 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.mesh-auth-error {
    padding: 12px 24px 20px;
    font-size: 13px;
    color: #f87171;
}
.mesh-auth-loading {
    padding: 16px 24px 20px;
    font-size: 13px;
    color: #94a3b8;
}

/* ─── AskUser Floating Panel ──────────────────────────────────── */
.ask-user-floating {
    margin: 0 12px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    animation: askSlideUp 0.2s ease-out;
}
@keyframes askSlideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dismiss button */
.ask-user-dismiss {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    z-index: 1;
}
.ask-user-dismiss:hover { background: var(--bg-hover); color: var(--text-primary); }
.ask-user-floating { position: relative; }

/* Tabs bar */
.ask-user-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    overflow-x: auto;
}
.ask-user-tab {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
}
.ask-user-tab:hover { color: var(--text-secondary); background: var(--bg-hover); }
.ask-user-tab.active { color: #60a5fa; border-bottom-color: #3b82f6; background: rgba(59,130,246,0.05); }
.ask-user-tab.confirmed { color: #34d399; }
.ask-user-tab-dot { width: 6px; height: 6px; border-radius: 50%; background: #3b82f6; flex-shrink: 0; }
.ask-user-tab-check { color: #10b981; flex-shrink: 0; }

/* Content area */
.ask-user-content {
    padding: 10px 14px;
}
.ask-user-question-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.4;
}

/* Options list */
.ask-user-opts {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Single option row (radio or checkbox) */
.ask-user-opt {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    user-select: none;
}
.ask-user-opt:hover {
    border-color: rgba(59,130,246,0.3);
    background: rgba(59,130,246,0.05);
}
.ask-user-opt.selected {
    border-color: rgba(59,130,246,0.5);
    background: rgba(59,130,246,0.1);
    color: #60a5fa;
}
.ask-user-opt.submitted { cursor: default; opacity: 0.5; }
.ask-user-opt.submitted.selected { opacity: 1; border-color: rgba(16,185,129,0.5); background: rgba(16,185,129,0.1); color: #34d399; }

/* Radio / Checkbox indicator */
.ask-user-indicator {
    width: 16px; height: 16px;
    border: 2px solid var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 1px;
    transition: all 0.15s;
}
.ask-user-indicator.radio { border-radius: 50%; }
.ask-user-indicator.checkbox { border-radius: 3px; }
.ask-user-indicator.selected { border-color: #3b82f6; background: #3b82f6; }
.ask-user-indicator.submitted.selected { border-color: #10b981; background: #10b981; }
.ask-user-indicator-dot { width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.ask-user-indicator-check { color: #fff; }

.ask-user-opt-label { font-weight: 500; }
.ask-user-opt-desc { font-size: 11px; opacity: 0.7; margin-top: 1px; }

/* Custom input option */
.ask-user-custom-input {
    width: 100%;
    background: transparent;
    border: none;
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
}
.ask-user-custom-input::placeholder { color: var(--text-muted); }

/* Comment input */
.ask-user-comment {
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    font-size: 12px;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    resize: none;
}
.ask-user-comment::placeholder { color: var(--text-muted); }
.ask-user-comment:focus { border-color: rgba(59,130,246,0.4); }

/* Action buttons */
.ask-user-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}
.ask-user-btn-back {
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.ask-user-btn-back:hover { background: var(--bg-hover); }
.ask-user-btn-next {
    flex: 1;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    border: none;
    color: #fff;
    background: #3b82f6;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}
.ask-user-btn-next:hover { background: #2563eb; }
.ask-user-btn-next.submit { background: #10b981; }
.ask-user-btn-next.submit:hover { background: #059669; }
.ask-user-btn-next:disabled { opacity: 0.4; cursor: not-allowed; }

/* AskUser inline (in chat history) */
.ask-user-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    margin: 4px 0;
}
.ask-user-inline-icon {
    display: flex;
    color: var(--accent);
    flex-shrink: 0;
}
.ask-user-inline-q {
    color: var(--text-primary);
    font-weight: 500;
}
.ask-user-inline-opts {
    color: var(--text-tertiary);
    font-style: italic;
}

/* AskUser Answers block (inside agent bubble) */
.ask-user-answers {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    margin: 6px 0;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    font-size: 13px;
}
.ask-user-answer-row {
    line-height: 1.5;
}
.ask-user-answer-q {
    color: var(--text-muted);
}
.ask-user-answer-a {
    color: var(--text-primary);
    font-weight: 500;
}

/* Invite page */
.invite-page {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: var(--bg-primary);
}
.invite-spinner {
    text-align: center;
    color: var(--text-secondary);
}
.invite-loader {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: #22C55E;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}
.invite-error {
    text-align: center;
    color: var(--text-secondary);
    max-width: 400px;
    padding: 40px;
}
.invite-error h2 { color: #ef4444; margin-bottom: 12px; }

/* ── Child Dashboard ── */
.child-greeting {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}
.child-class-badge {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 4px 10px;
    border-radius: 8px;
    white-space: nowrap;
}
.child-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 8px 0 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.child-section-title svg { flex-shrink: 0; }
/* Assignments table */
.child-assignments-group-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 16px 0 8px;
}
.child-assignments-group-title.completed {
    color: var(--text-muted);
    margin-top: 24px;
}
.child-assignments-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.child-assignments-table thead th {
    text-align: left;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
.child-assignment-row {
    cursor: pointer;
    transition: background 0.15s;
}
.child-assignment-row:hover {
    background: var(--bg-tertiary);
}
.child-assignment-row.completed {
    opacity: 0.6;
}
.child-assignment-row td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
/* Assignment card */
.child-asgn-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.12s;
}
.child-asgn-card:hover { background: var(--bg-tertiary); }
.child-asgn-subject {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.child-asgn-topic {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
/* Status chips row */
.child-asgn-chips {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.child-asgn-chip {
    font-size: 10px;
    font-weight: 500;
    padding: 1px 8px;
    border-radius: 10px;
    white-space: nowrap;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
}
.child-asgn-chip.active {
    background: #3B82F6;
    color: #fff;
}
.child-asgn-chip.done {
    background: #22C55E40;
    color: #22C55E;
}
.child-progress-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    margin-top: 4px;
    overflow: hidden;
}
.child-progress-bar.small {
    height: 4px;
    margin-top: 4px;
}
.child-progress-fill {
    height: 100%;
    background: #22C55E;
    border-radius: 3px;
    transition: width 0.3s;
}
.child-progress-done {
    background: #22C55E;
}
.child-loading,
.child-empty {
    font-size: 14px;
    color: var(--text-muted);
    text-align: center;
    padding: 24px 0;
}

/* Child dashboard: schedule, grades, problems */
.child-schedule { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.child-schedule-day { min-width: 110px; background: var(--bg-secondary); border-radius: 10px; padding: 10px; flex-shrink: 0; }
.child-schedule-day.today { border: 2px solid #22C55E; }
.child-schedule-date { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.child-schedule-item { font-size: 12px; color: var(--text-secondary); padding: 2px 0; }
.child-avg-grade { font-size: 48px; font-weight: 700; text-align: center; padding: 16px 0; }
.child-avg-grade.good { color: #22C55E; }
.child-avg-grade.medium { color: #EAB308; }
.child-avg-grade.bad { color: #EF4444; }
.child-stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.child-problems { background: rgba(239,68,68,0.08); border-radius: 12px; padding: 12px; }
.child-problem-item { padding: 4px 0; color: var(--text-secondary); font-size: 13px; }
.child-problem-subject { color: #EF4444; font-weight: 600; }
.child-problem-btn { background: #EF4444; color: white; border: none; border-radius: 8px; padding: 6px 12px; font-size: 12px; cursor: pointer; margin-top: 4px; }
.child-problem-btn:hover { background: #DC2626; }
@media (max-width: 768px) { .child-stats-row { grid-template-columns: 1fr; } }

/* Child schedule table (5 weeks) */
.child-schedule-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; background: var(--bg-secondary); }
.child-schedule-table { border-collapse: collapse; min-width: 100%; }
.child-schedule-table th, .child-schedule-table td { padding: 4px 6px; font-size: 11px; white-space: nowrap; border: 1px solid var(--bg-tertiary); }
.child-sched-corner { position: sticky; left: 0; z-index: 2; background: var(--bg-secondary); width: 30px; text-align: center; font-weight: 600; color: var(--text-muted); }
.child-sched-th { text-align: center; min-width: 65px; background: var(--bg-secondary); }
.child-sched-th.today { background: #22C55E20; border-bottom: 2px solid #22C55E; }
.child-sched-th.weekend { color: var(--text-muted); background: rgba(255,255,255,0.04); }
td.child-sched-cell.weekend { background: rgba(255,255,255,0.04); }
.child-sched-wd { font-weight: 600; font-size: 11px; color: var(--text-secondary); }
.child-sched-dm { font-size: 10px; color: var(--text-muted); }
.child-sched-num { position: sticky; left: 0; z-index: 1; background: var(--bg-secondary); text-align: center; font-weight: 600; color: var(--text-muted); width: 30px; }
.child-sched-cell { min-width: 65px; min-height: 28px; vertical-align: top; }
.child-sched-subject { font-size: 10px; font-weight: 500; color: var(--text-primary); display: inline; }
.child-sched-note { font-size: 9px; color: var(--text-muted); }
.child-sched-grade { display: inline; font-size: 10px; font-weight: 700; padding: 1px 3px; border-radius: 3px; margin-left: 2px; }
.child-sched-grade.good { background: #22C55E20; color: #22C55E; }
.child-sched-grade.medium { background: #F59E0B20; color: #F59E0B; }
.child-sched-grade.bad { background: #EF444420; color: #EF4444; }
.child-sched-hw { font-size: 9px; color: var(--text-muted); margin-left: 1px; display: inline; }
.child-sched-hw.done { color: #22C55E; }
/* Filled cell with tooltip */
.child-sched-filled { position: relative; cursor: pointer; }
/* Custom rich tooltip — hidden by default */
/* Tooltip: managed entirely via JS (click/tap to pin, hide on timer/mouseout) */
.child-sched-tip {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--bg-tertiary);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 180px;
    max-width: 280px;
    white-space: normal;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-primary);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 9999;
    display: none;
}
/* Hover zoom */
.child-sched-filled:hover { z-index: 20; background: var(--bg-secondary); box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
/* Tooltip formatting */
.child-sched-tip strong { font-size: 13px; color: var(--text-primary); }
.child-sched-tip .tip-time { color: var(--text-secondary); font-size: 11px; }
.child-sched-tip .tip-room { color: var(--text-muted); font-size: 11px; }
.child-sched-tip em { color: var(--text-secondary); font-size: 11px; }
.child-sched-tip .tip-mark-5, .child-sched-tip .tip-mark-4 { color: #22C55E; font-weight: 700; }
.child-sched-tip .tip-mark-3 { color: #F59E0B; font-weight: 700; }
.child-sched-tip .tip-mark-2 { color: #EF4444; font-weight: 700; }
.child-sched-tip .tip-hw { color: var(--text-secondary); font-size: 11px; font-style: italic; }
.child-sched-tip .tip-link { color: #60A5FA; text-decoration: underline; word-break: break-all; }
/* Touch: tooltip managed via JS touchstart/touchend */

/* Sidebar assignments */
.sidebar-asgn-section { padding: 4px 0; }
.sidebar-asgn-header {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 16px; font-size: 12px; font-weight: 600;
    color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px;
}
.sidebar-asgn-count { font-weight: 400; color: var(--text-muted); }
.sidebar-asgn-item {
    padding: 6px 16px; cursor: pointer; transition: background 0.12s;
}
.sidebar-asgn-item:hover { background: var(--bg-tertiary); }
.sidebar-asgn-item.completed { opacity: 0.5; }
.sidebar-asgn-top {
    display: flex; align-items: center; justify-content: space-between; gap: 4px;
}
.sidebar-asgn-subject { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.sidebar-asgn-done-icon { font-size: 12px; flex-shrink: 0; }
.sidebar-asgn-topic {
    font-size: 11px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 1px;
}
.sidebar-asgn-stages {
    display: flex; gap: 4px; margin-top: 4px;
}
.sidebar-stage { flex: 1; min-width: 0; }
.sidebar-stage-bar {
    height: 3px; border-radius: 2px;
    background: var(--bg-tertiary);
}
.sidebar-stage.done .sidebar-stage-bar { background: #3B82F6; }
.sidebar-stage.current .sidebar-stage-bar {
    background: linear-gradient(90deg, #3B82F6 50%, var(--bg-tertiary) 50%);
}
.sidebar-stage-label {
    font-size: 9px; color: var(--text-muted);
    display: block; margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-asgn-group-label {
    padding: 8px 16px 4px; font-size: 10px; font-weight: 600;
    color: var(--text-muted); letter-spacing: 0.5px;
}

/* Chat links — smaller, truncated display */
.chat-link { font-size: 0.9em; color: #7aa2f7; word-break: break-all; }
.chat-link:hover { color: #89b4fa; text-decoration: underline; }
