/* Dark mode — VS Code / Microsoft Fluent inspired */
:root {
    --bg-base: #1E1E1E;
    --bg-surface: #252526;
    --bg-elevated: #2D2D2D;
    --bg-input: #3C3C3C;
    --border: #3C3C3C;
    --border-light: #4D4D4D;
    --text-primary: #CCCCCC;
    --text-secondary: #969696;
    --text-muted: #6D6D6D;
    --ms-blue: #0078D4;
    --ms-blue-dark: #005A9E;
    --ms-blue-hover: #1A8AD4;
    --ms-blue-subtle: rgba(0, 120, 212, 0.15);
    --ms-red: #F85149;
    --ms-green: #3FB950;
    --ms-yellow: #D29922;
    --accent: #569CD6;
}

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

html, body {
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    overflow: hidden;
}

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 16px;
    background: #181818;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-logo {
    height: 40px;
    width: auto;
    border-radius: 4px;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--ms-blue);
}

.topbar-right {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* Connection status indicator */
.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-right: 8px;
    transition: all 0.3s;
}

.connection-status .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    transition: background 0.3s, box-shadow 0.3s;
}

.connection-status.connected {
    background: rgba(63, 185, 80, 0.15);
    color: var(--ms-green);
}

.connection-status.connected .status-dot {
    background: var(--ms-green);
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.5);
}

.connection-status.disconnected {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

.connection-status.disconnected .status-dot {
    background: var(--text-muted);
}

.connection-status.validating {
    background: rgba(210, 153, 34, 0.15);
    color: var(--ms-yellow);
}

.connection-status.validating .status-dot {
    background: var(--ms-yellow);
    animation: pulse 1s infinite;
}

.connection-status.error {
    background: rgba(248, 81, 73, 0.15);
    color: var(--ms-red);
}

.connection-status.error .status-dot {
    background: var(--ms-red);
}

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

.topbar-btn {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.topbar-btn:hover {
    background: var(--bg-input);
    border-color: var(--border-light);
}

/* Main layout */
.main {
    display: flex;
    height: calc(100% - 48px);
}

.panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    height: 36px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}

.copy-btn {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.copy-btn:hover {
    background: var(--ms-blue);
    color: white;
    border-color: var(--ms-blue);
}

.copy-btn.copied {
    background: var(--ms-green);
    color: white;
    border-color: var(--ms-green);
}

/* Chat panel */
.chat-panel {
    width: 40%;
    min-width: 280px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-base);
}

.chat-msg {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--ms-blue);
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-msg.assistant {
    align-self: flex-start;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}

.chat-msg.error {
    align-self: center;
    background: rgba(248, 81, 73, 0.1);
    color: var(--ms-red);
    border: 1px solid rgba(248, 81, 73, 0.3);
    font-size: 13px;
}

/* TTS indicators */
.chat-msg.tts-loading {
    position: relative;
    border-color: var(--ms-yellow);
    animation: tts-pulse 1.2s ease-in-out infinite;
}

.chat-msg.tts-loading::after {
    content: "Generating speech...";
    display: block;
    font-size: 11px;
    color: var(--ms-yellow);
    margin-top: 6px;
    animation: tts-dots 1.5s steps(3, end) infinite;
}

.chat-msg.tts-speaking {
    position: relative;
    border-color: var(--ms-blue);
}

.chat-msg.tts-speaking::after {
    content: "";
    display: inline-flex;
    gap: 3px;
    margin-top: 8px;
    height: 16px;
    align-items: flex-end;
}

.chat-msg.tts-speaking::after {
    content: "Playing...";
    display: block;
    font-size: 11px;
    color: var(--ms-blue);
}

.chat-msg.tts-speaking::before {
    content: "";
    position: absolute;
    bottom: 6px;
    right: 10px;
    width: 24px;
    height: 16px;
    background:
        linear-gradient(var(--ms-blue), var(--ms-blue)) 0px 0/3px 100% no-repeat,
        linear-gradient(var(--ms-blue), var(--ms-blue)) 5px 0/3px 100% no-repeat,
        linear-gradient(var(--ms-blue), var(--ms-blue)) 10px 0/3px 100% no-repeat,
        linear-gradient(var(--ms-blue), var(--ms-blue)) 15px 0/3px 100% no-repeat,
        linear-gradient(var(--ms-blue), var(--ms-blue)) 20px 0/3px 100% no-repeat;
    animation: tts-bars 0.8s ease-in-out infinite alternate;
    border-radius: 2px;
    opacity: 0.8;
}

@keyframes tts-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(210, 153, 34, 0.3); }
    50% { box-shadow: 0 0 0 4px rgba(210, 153, 34, 0.1); }
}

@keyframes tts-bars {
    0%   { height: 6px; }
    25%  { height: 14px; }
    50%  { height: 8px; }
    75%  { height: 16px; }
    100% { height: 10px; }
}

/* Ollama setup info */
.ollama-info {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    margin-top: 10px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.ollama-info strong {
    color: var(--text-primary);
    font-size: 13px;
}

.ollama-info ol {
    margin: 6px 0 8px 18px;
}

.ollama-info ol li {
    margin-bottom: 4px;
}

.ollama-info code {
    background: var(--bg-elevated);
    color: var(--ms-blue);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

.ollama-info p {
    margin-top: 8px;
    color: var(--ms-yellow);
    font-size: 11px;
}

/* Progress panel */
.progress-panel {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 12px;
    overflow-y: auto;
    max-height: 180px;
    transition: max-height 0.3s;
}

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

.progress-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.progress-count {
    font-size: 11px;
    color: var(--ms-blue);
    font-weight: 700;
}

.progress-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.progress-badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-base);
    color: var(--text-muted);
    transition: all 0.3s;
    cursor: default;
    white-space: nowrap;
}

.progress-badge.learned {
    background: rgba(63, 185, 80, 0.15);
    border-color: rgba(63, 185, 80, 0.4);
    color: var(--ms-green);
}

.progress-badge.learned::before {
    content: "\2714 ";
}

/* Clickable coding terms */
.coding-term {
    color: #569CD6;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    border-radius: 2px;
    padding: 0 2px;
}

.coding-term:hover {
    color: white;
    background: var(--ms-blue);
    text-decoration: none;
}

/* Code in chat messages — VS Code dark theme */
.chat-code-block {
    background: #1A1A1A;
    color: #D4D4D4;
    font-family: 'Monaco', 'Menlo', 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    padding: 12px 16px;
    border-radius: 6px;
    margin: 8px 0;
    overflow-x: auto;
    white-space: pre;
    border: 1px solid #333333;
}

.chat-code-block code {
    font-family: inherit;
    font-size: inherit;
}

.chat-code-inline {
    background: #1A1A1A;
    color: #CE9178;
    font-family: 'Monaco', 'Menlo', 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid #333333;
}

.chat-msg.user .chat-code-inline {
    background: rgba(0, 0, 0, 0.3);
    color: #CE9178;
    border-color: rgba(255, 255, 255, 0.15);
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}

#chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

#chat-input:focus {
    border-color: var(--ms-blue);
}

#chat-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    align-self: flex-end;
    background: var(--ms-blue);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    transition: background 0.15s;
}

.send-btn:hover {
    background: var(--ms-blue-hover);
}

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

/* Resizer */
.resizer {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    transition: background 0.15s;
}

.resizer:hover, .resizer.active {
    background: var(--ms-blue);
}

/* Editor panel */
.editor-panel {
    flex: 1;
    min-width: 300px;
    background: var(--bg-base);
}

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

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

.modal.hidden {
    display: none;
}

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

.modal-content {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    width: 440px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.modal-content label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 12px;
    margin-bottom: 4px;
}

.modal-content input,
.modal-content select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

.modal-content input:focus,
.modal-content select:focus {
    border-color: var(--ms-blue);
}

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

.modal-content select option {
    background: var(--bg-input);
    color: var(--text-primary);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

.btn-primary {
    background: var(--ms-blue);
    color: white;
    border: none;
    padding: 8px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
}

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

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-test {
    background: transparent;
    color: var(--ms-blue);
    border: 2px solid var(--ms-blue);
    padding: 6px 18px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    margin-right: auto;
    transition: background 0.15s;
}

.btn-test:hover {
    background: var(--ms-blue-subtle);
}

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

.validation-result {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.4;
}

.validation-result.hidden {
    display: none;
}

.validation-result.success {
    background: rgba(63, 185, 80, 0.1);
    color: var(--ms-green);
    border: 1px solid rgba(63, 185, 80, 0.3);
}

.validation-result.failure {
    background: rgba(248, 81, 73, 0.1);
    color: var(--ms-red);
    border: 1px solid rgba(248, 81, 73, 0.3);
}

.validation-result.testing {
    background: rgba(210, 153, 34, 0.1);
    color: var(--ms-yellow);
    border: 1px solid rgba(210, 153, 34, 0.3);
}

/* Settings — tutor section */
.settings-divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0 16px;
}

.settings-section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ms-blue);
    margin-bottom: 8px;
}

.age-slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.age-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
}

.age-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--ms-blue);
    cursor: pointer;
    border: 2px solid var(--bg-surface);
    box-shadow: 0 0 4px rgba(0, 120, 212, 0.4);
}

.age-display {
    font-size: 16px;
    font-weight: 700;
    color: var(--ms-blue);
    min-width: 30px;
    text-align: center;
}

.age-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    margin-bottom: 8px;
}

.font-size-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.font-size-display {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 40px;
    text-align: center;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding: 8px 0;
}

.toggle-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.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(--border-light);
    border-radius: 24px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.2s;
}

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

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

/* File browser modal */
.modal-content-wide {
    width: 560px;
}

.path-bar {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 10px;
}

.btn-icon {
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

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

.path-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    background: var(--bg-input);
    color: var(--text-secondary);
}

.file-list {
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-base);
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
    font-size: 14px;
    color: var(--text-primary);
}

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

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

.file-item.selected {
    background: var(--ms-blue);
    color: white;
}

.file-item-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.file-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item-dir .file-item-name {
    font-weight: 600;
}

.save-bar {
    margin-top: 12px;
}

.save-bar.hidden {
    display: none;
}

.empty-msg {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 14px;
}

/* Provider fields toggling */
.provider-fields.hidden {
    display: none;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Terms acceptance */
.terms-box {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    margin-top: 8px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-secondary);
    max-height: 250px;
    overflow-y: auto;
}

.terms-accept-area {
    display: flex;
    justify-content: center;
    padding: 16px 0 8px;
}

.btn-accept-terms {
    background: var(--ms-blue);
    color: white;
    border: none;
    padding: 10px 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-family: inherit;
    font-weight: 600;
    transition: background 0.15s;
}

.btn-accept-terms:hover {
    background: var(--ms-blue-hover);
}

/* AI disclaimer */
.ai-disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 12px 6px;
    background: var(--bg-surface);
}

/* About modal */
.modal-content-about {
    width: 600px;
    max-height: 85vh;
}

.about-body {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.about-body h3 {
    font-size: 16px;
    margin-top: 20px;
    margin-bottom: 8px;
    color: var(--ms-blue);
}

.about-body h4 {
    font-size: 14px;
    margin-top: 6px;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.about-body p {
    margin-bottom: 8px;
}

.about-provider {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 10px;
}

.about-provider ol {
    margin: 4px 0 0 18px;
    font-size: 13px;
    color: var(--text-secondary);
}

.about-provider ol li {
    margin-bottom: 3px;
}

.about-provider code {
    background: var(--bg-input);
    color: var(--accent);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}

.about-legal {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px;
    margin-top: 8px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-muted);
}

.about-legal p {
    margin-bottom: 8px;
}

.about-legal p:last-child {
    margin-bottom: 0;
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    border-bottom-left-radius: 2px;
}

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

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}
