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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f8fafc;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --user-msg: #dbeafe;
    --assistant-msg: #f1f5f9;
    --error: #ef4444;
    --success: #22c55e;
    --radius: 12px;
}

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

/* Auth page */
.auth-page {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-container {
    width: 100%;
    max-width: 440px;
    padding: 20px;
}

.auth-card {
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 40px 32px 32px;
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo-accent {
    width: 6px;
    height: 36px;
    border-radius: 3px;
    background: linear-gradient(180deg, #dc2626, #fff, #dc2626);
}

.auth-logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}

.subtitle {
    color: var(--text-light);
    font-size: 0.95rem;
}

.auth-features {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    background: var(--bg);
    border-radius: 12px;
    margin-bottom: 24px;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text);
}

.feature-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}

.tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-light);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

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

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form input,
.auth-form select {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.auth-form input:focus,
.auth-form select:focus {
    border-color: var(--primary);
}

.hidden {
    display: none !important;
}

.error {
    color: var(--error);
    font-size: 0.875rem;
    min-height: 20px;
}

/* Buttons */
.btn-primary {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

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

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

.btn-small {
    padding: 6px 12px;
    background: rgba(255,255,255,0.1);
    color: var(--sidebar-text);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-icon {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--bg);
}

.btn-icon.recording {
    background: var(--error);
    border-color: var(--error);
    animation: pulse 1s infinite;
}

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

.badge {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* App layout */
.app-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 16px;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

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

.sidebar .btn-primary {
    width: 100%;
    margin-bottom: 16px;
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
}

.session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    font-size: 0.9rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    position: relative;
}

.session-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-menu-btn {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.session-item:hover .session-menu-btn {
    opacity: 0.6;
}

.session-menu-btn:hover {
    opacity: 1 !important;
    background: rgba(255,255,255,0.15);
}

.session-menu {
    position: absolute;
    right: 4px;
    top: 100%;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 100;
    min-width: 140px;
    overflow: hidden;
}

.session-menu-item {
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
}

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

.session-menu-item.delete {
    color: var(--error);
}

.session-menu-item.delete:hover {
    background: #fef2f2;
}

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

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.85rem;
}

/* Chat area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    color: var(--text-light);
    margin: auto;
    font-size: 1.1rem;
    line-height: 2;
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--user-msg);
    border-bottom-right-radius: 4px;
}

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

.message.streaming::after {
    content: '▊';
    animation: blink 0.7s infinite;
}

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

/* Voice playback in user messages */
.voice-playback {
    margin-bottom: 6px;
}

.voice-playback audio {
    width: 100%;
    max-width: 250px;
    height: 32px;
}

.btn-play-audio {
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-play-audio:hover {
    background: var(--primary-dark);
}

.btn-play-audio:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* TTS settings */
.tts-settings {
    display: flex;
    gap: 16px;
    padding: 8px 24px;
    background: var(--assistant-msg);
    border-top: 1px solid var(--border);
    align-items: center;
    font-size: 0.85rem;
}

.tts-settings label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-light);
}

.tts-settings select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
    max-width: 200px;
}

.tts-settings input[type="range"] {
    width: 100px;
}

#tts-rate-val {
    min-width: 24px;
    text-align: center;
}

/* Chat input */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: white;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 150px;
    line-height: 1.5;
}

#message-input:focus {
    border-color: var(--primary);
}

/* Sidebar vocabulary button */
.btn-sidebar {
    width: 100%;
    padding: 10px 16px;
    background: rgba(255,255,255,0.05);
    color: var(--sidebar-text);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: left;
    margin-bottom: 12px;
    transition: background 0.2s;
}

.btn-sidebar:hover {
    background: rgba(255,255,255,0.12);
}

/* Onboarding overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.overlay-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px 32px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.overlay-card h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.overlay-card > p {
    color: var(--text-light);
    margin-bottom: 24px;
}

.onboarding-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-block {
    width: 100%;
}

.onboarding-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-light);
    font-size: 0.85rem;
    margin: 4px 0;
}

.onboarding-divider::before,
.onboarding-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.onboarding-manual-label {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

.onboarding-levels {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.onboarding-level-btn {
    width: 60px;
    height: 44px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.onboarding-level-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef2ff;
}

/* Vocabulary panel */
.vocab-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 360px;
    background: var(--card-bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 900;
    box-shadow: -4px 0 20px rgba(0,0,0,0.08);
}

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

.vocab-header h3 {
    font-size: 1.1rem;
}

.btn-icon-sm {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-light);
    border-radius: 6px;
}

.btn-icon-sm:hover {
    background: var(--bg);
}

.vocab-filters {
    display: flex;
    gap: 4px;
    padding: 12px 20px 0;
}

.vocab-filter {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: white;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.vocab-filter.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.vocab-stats {
    padding: 8px 20px;
    font-size: 0.8rem;
    color: var(--text-light);
}

.vocab-search {
    margin: 0 20px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
}

.vocab-search:focus {
    border-color: var(--primary);
}

.vocab-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}

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

.vocab-item-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.vocab-word-text {
    font-weight: 600;
    cursor: pointer;
    color: var(--primary);
}

.vocab-word-text:hover {
    text-decoration: underline;
}

.vocab-translation {
    font-size: 0.85rem;
    color: var(--text-light);
}

.vocab-status-select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

.vocab-empty {
    text-align: center;
    color: var(--text-light);
    padding: 40px 0;
}

/* Vocab word in chat messages */
.vocab-word {
    display: inline;
}

.vocab-word strong {
    color: var(--primary-dark);
}

.vocab-word em {
    color: var(--text-light);
    font-size: 0.9em;
}

.vocab-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 1px solid var(--primary);
    border-radius: 50%;
    background: white;
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    margin-left: 4px;
    vertical-align: middle;
    transition: all 0.2s;
}

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

.vocab-add-btn:disabled {
    border-color: var(--success);
    color: var(--success);
    cursor: default;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
        padding: 8px;
    }
    .sidebar-header h2,
    .session-item,
    .sidebar-footer span,
    .sidebar .btn-primary,
    .btn-sidebar {
        display: none;
    }
    .vocab-panel {
        width: 100%;
    }
    .sidebar-header {
        justify-content: center;
    }
}
