/* ========================================================================
   MailGenius – Design System
   Light/Dark theme with system default via prefers-color-scheme
   ======================================================================== */

/* --- CSS Custom Properties --- */
:root {
    /* Light theme (default) */
    --bg-primary: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f3f9;
    --bg-glass: rgba(255, 255, 255, 0.72);
    --bg-glass-border: rgba(255, 255, 255, 0.3);
    --text-primary: #1a1d2e;
    --text-secondary: #5a5f7a;
    --text-muted: #8b90a5;
    --border-color: #e2e5f1;
    --border-light: #eef0f7;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: rgba(99, 102, 241, 0.1);
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.1);
    --error: #ef4444;
    --error-light: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --navbar-bg: rgba(255, 255, 255, 0.85);
    --navbar-border: rgba(226, 229, 241, 0.6);
    --input-bg: #f1f3f9;
    --input-border: #e2e5f1;
    --input-focus-border: #6366f1;
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d2e;
    --bg-tertiary: #252840;
    --bg-glass: rgba(26, 29, 46, 0.78);
    --bg-glass-border: rgba(255, 255, 255, 0.06);
    --text-primary: #eef0f7;
    --text-secondary: #a0a4bb;
    --text-muted: #6b6f88;
    --border-color: #2d3150;
    --border-light: #232640;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --accent-light: rgba(129, 140, 248, 0.12);
    --success: #34d399;
    --success-light: rgba(52, 211, 153, 0.12);
    --error: #f87171;
    --error-light: rgba(248, 113, 113, 0.12);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.35);
    --navbar-bg: rgba(15, 17, 23, 0.88);
    --navbar-border: rgba(45, 49, 80, 0.6);
    --input-bg: #252840;
    --input-border: #2d3150;
    --input-focus-border: #818cf8;
}

/* System default: dark */
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --bg-primary: #0f1117;
        --bg-secondary: #1a1d2e;
        --bg-tertiary: #252840;
        --bg-glass: rgba(26, 29, 46, 0.78);
        --bg-glass-border: rgba(255, 255, 255, 0.06);
        --text-primary: #eef0f7;
        --text-secondary: #a0a4bb;
        --text-muted: #6b6f88;
        --border-color: #2d3150;
        --border-light: #232640;
        --accent: #818cf8;
        --accent-hover: #6366f1;
        --accent-light: rgba(129, 140, 248, 0.12);
        --success: #34d399;
        --success-light: rgba(52, 211, 153, 0.12);
        --error: #f87171;
        --error-light: rgba(248, 113, 113, 0.12);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
        --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
        --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.35);
        --navbar-bg: rgba(15, 17, 23, 0.88);
        --navbar-border: rgba(45, 49, 80, 0.6);
        --input-bg: #252840;
        --input-border: #2d3150;
        --input-focus-border: #818cf8;
    }
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    scroll-behavior: smooth;
    color-scheme: light dark;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover { color: var(--accent-hover); }

/* --- Navbar --- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--navbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--navbar-border);
    z-index: 100;
    transition: background 0.3s;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.nav-brand:hover .brand-text {
    background-size: 100% 2px;
}

.brand-text {
    font-weight: 700;
    font-size: 1.2rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Theme Toggle */
.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}
.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: rotate(15deg);
}
.theme-toggle .sun-icon { display: block; }
.theme-toggle .moon-icon { display: none; }
[data-theme="dark"] .theme-toggle .sun-icon { display: none; }
[data-theme="dark"] .theme-toggle .moon-icon { display: block; }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .theme-toggle .sun-icon { display: none; }
    html:not([data-theme="light"]) .theme-toggle .moon-icon { display: block; }
}

/* Avatar / Dropdown */
.nav-user { position: relative; }
.avatar-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: var(--accent-gradient);
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.avatar-btn:hover { transform: scale(1.08); box-shadow: 0 0 0 3px var(--accent-light); }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    z-index: 200;
}
.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-secondary);
    font-size: 0.88rem;
    transition: background 0.15s, color 0.15s;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}
.dropdown-item:hover { background: var(--accent-light); color: var(--accent); }
.dropdown-divider { border: none; border-top: 1px solid var(--border-light); margin: 4px 0; }
.logout-btn:hover { color: var(--error); background: var(--error-light); }

/* --- Main Content --- */
.main-content {
    padding-top: 80px;
    min-height: 100vh;
}

/* --- Glass Card --- */
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

/* --- Forms --- */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color 0.2s;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.93rem;
    transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
    outline: none;
}

.input-wrapper input {
    padding-left: 42px;
}

input:focus, textarea:focus {
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px var(--accent-light);
    background: var(--bg-secondary);
}

input:focus + .input-icon,
.input-wrapper:focus-within .input-icon {
    color: var(--accent);
}

textarea { resize: vertical; }

.error-msg {
    font-size: 0.8rem;
    color: var(--error);
    margin-top: 4px;
    display: block;
    min-height: 1.2em;
}

.field-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: start;
}
.form-group-sm { width: 100px; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 22px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.93rem;
    cursor: pointer;
    border: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
    opacity: 0;
    transition: opacity 0.2s;
}
.btn:hover::after { opacity: 1; }

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}
.btn-primary:active { transform: translateY(0); }

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}
.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

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

.btn-full { width: 100%; }
.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 1.1rem;
    transition: color 0.2s;
}
.btn-icon:hover { color: var(--error); }

/* Loader */
.btn-loader {
    width: 18px; height: 18px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Auth Pages --- */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 80px);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    padding: 40px;
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}
.auth-header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 8px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.auth-form { margin-bottom: 20px; }

.auth-footer {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.link-accent {
    color: var(--accent);
    font-weight: 600;
}
.link-accent:hover { text-decoration: underline; }

/* --- Onboarding --- */
.onboarding-container {
    display: flex;
    justify-content: center;
    padding: 24px;
    min-height: calc(100vh - 80px);
    align-items: flex-start;
    padding-top: 40px;
}

.onboarding-card {
    width: 100%;
    max-width: 560px;
    padding: 40px;
}

.onboarding-header {
    text-align: center;
    margin-bottom: 24px;
}
.onboarding-header h1 {
    font-size: 1.6rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Progress */
.progress-bar { margin-bottom: 32px; }
.progress-track {
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}
.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 4px;
    transition: width 0.4s ease;
}
.progress-steps {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.progress-steps .step.active { color: var(--accent); font-weight: 600; }

/* Steps */
.onboarding-step { display: none; }
.onboarding-step.active { display: block; animation: fadeIn 0.3s ease; }
.step-content h2 { font-size: 1.15rem; margin-bottom: 6px; }
.step-desc { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 20px; }
.step-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.25s, background 0.25s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}
.upload-zone-sm { padding: 20px; }
.upload-icon { color: var(--text-muted); }
.upload-text { color: var(--text-secondary); font-size: 0.93rem; }
.upload-hint { color: var(--text-muted); font-size: 0.8rem; }

.file-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--accent-light);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 0.9rem;
    margin-top: 12px;
}
.file-preview span { flex: 1; }

/* --- Dashboard --- */
.dashboard-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 80px);
}

.panel {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-light);
}
.panel-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
}

.panel-body {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
}

.panel-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.jd-textarea {
    width: 100%;
    height: 100%;
    min-height: 300px;
    resize: none;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    font-size: 0.95rem;
    line-height: 1.7;
    padding: 0 !important;
}
.jd-textarea:focus { box-shadow: none !important; }

.btn-generate { min-width: 180px; }

/* Mail Placeholder */
.mail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
}
.placeholder-icon {
    margin-bottom: 16px;
    opacity: 0.3;
    animation: pulse 3s ease-in-out infinite;
}
.placeholder-hint { font-size: 0.85rem; margin-top: 6px; }

.mail-body-textarea {
    min-height: 200px;
    line-height: 1.7;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-ai {
    background: var(--accent-light);
    color: var(--accent);
}

.send-info {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
    flex: 1;
}

.btn-send { min-width: 160px; }

/* --- Profile --- */
.profile-container {
    display: flex;
    justify-content: center;
    padding: 24px;
    min-height: calc(100vh - 80px);
    align-items: flex-start;
    padding-top: 20px;
}

.profile-card {
    width: 100%;
    max-width: 600px;
    padding: 40px;
}

.profile-header {
    text-align: center;
    margin-bottom: 32px;
}

.profile-avatar {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: white;
    font-size: 1.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.profile-header h1 { font-size: 1.4rem; font-weight: 700; }
.profile-email { color: var(--text-muted); font-size: 0.9rem; }

.profile-section {
    margin-bottom: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}
.profile-section h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.profile-actions { margin-top: 8px; }

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 380px;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}
.toast:hover { transform: translateX(-4px); }
.toast.removing {
    animation: slideOutRight 0.3s ease forwards;
}

.toast-success {
    background: var(--success);
    color: white;
}
.toast-error {
    background: var(--error);
    color: white;
}
.toast-info {
    background: var(--accent);
    color: white;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in { animation: fadeIn 0.4s ease; }

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

.slide-up { animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) both; }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutRight {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100px); }
}

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

/* Smooth page transitions */
.main-content > * {
    transition: opacity 0.3s ease;
}

/* Focus ring */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

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

/* --- Responsive --- */
@media (max-width: 900px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }
    .panel {
        height: auto;
        min-height: 400px;
    }
}

@media (max-width: 600px) {
    .auth-card, .onboarding-card, .profile-card { padding: 24px; }
    .navbar { padding: 0 16px; }
    .form-row { grid-template-columns: 1fr; }
    .form-group-sm { width: 100%; }
}
