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

:root {
    /* Font */
    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Light Mode Colors */
    --primary-color: #4f46e5; /* Indigo 600 */
    --primary-hover: #4338ca; /* Indigo 700 */
    --primary-light: #818cf8;
    --primary-soft: rgba(79, 70, 229, 0.1);
    
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-secondary: #f1f5f9;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] {
    --bg-body: #0f172a; /* Slate 900 */
    --bg-surface: #1e293b; /* Slate 800 */
    --bg-surface-secondary: #334155; /* Slate 700 */
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    
    --border-color: #334155;
    --border-hover: #475569;
    
    --primary-color: #6366f1; /* Indigo 500 */
    --primary-hover: #818cf8;
    --primary-soft: rgba(99, 102, 241, 0.15);
    
    --glass-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3);
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

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

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

/* Splash Screen */
.splash-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

.splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.splash-content {
    text-align: center;
}

.splash-logo {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    margin: 1.5rem auto;
    animation: spin 1s linear infinite;
}

/* Layout */
.container {
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 1rem 0;
    position: relative;
    padding-top: 3.5rem; /* Add padding to avoid overlap with theme toggle */
}

.brand h1 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.brand h1 .emoji-icon {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    font-size: 2rem;
    display: inline-block;
    filter: none;
}

.brand h1 .text-gradient {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    z-index: 100;
}

.theme-toggle .theme-toggle-text {
    display: none;
}

.theme-toggle:hover {
    background: var(--bg-surface-secondary);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Cards */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.generator-card {
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.generator-card h2 {
    margin-bottom: 2rem;
    font-size: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
    position: relative;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 2px solid var(--border-color);
    background: var(--bg-surface-secondary);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 1rem;
    transition: var(--transition);
    appearance: none; /* Remove default arrow for select */
}

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1rem;
    cursor: pointer;
    /* Increase specificity to prevent browser default styling issues */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 2.5rem; /* Ensure text doesn't overlap with arrow */
    line-height: 1.5; /* Improve vertical alignment */
}

[data-theme="dark"] select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-surface);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

select.form-control::-webkit-scrollbar {
    width: 8px;
}

select.form-control::-webkit-scrollbar-track {
    background: var(--bg-surface-secondary);
}

select.form-control::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

/* Improved List Styling */
select.form-control option {
    padding: 12px;
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

/* Dropdown specific improvements */
select.form-control:hover {
    border-color: var(--border-hover);
}

select.form-control:active {
    border-color: var(--primary-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 2rem;
    border-radius: var(--radius-lg);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-family: var(--font-main);
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.3);
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
    background: var(--bg-surface-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
}

.btn-secondary:hover {
    background: var(--bg-surface);
    border-color: var(--text-tertiary);
    transform: translateY(-1px);
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 50%;
    font-size: 1.25rem;
}

.btn-icon:hover {
    background: var(--bg-surface-secondary);
    color: var(--primary-color);
    transform: rotate(15deg);
}

.btn.loading {
    pointer-events: none;
    opacity: 0.8;
}

.btn.loading::after {
    content: "";
    position: absolute;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    right: 1rem;
}

/* Email Display */
.email-display {
    animation: fadeIn 0.5s ease-out;
}

.email-header-card {
    background: linear-gradient(135deg, var(--primary-soft), transparent);
    border: 1px solid var(--primary-color);
    padding: 2rem;
    border-radius: var(--radius-xl);
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.current-email {
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 1rem 0;
    word-break: break-all;
    text-align: center;
    padding: 1rem;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border-color);
    transition: var(--transition);
    cursor: pointer;
}

.current-email:hover {
    border-color: var(--primary-color);
    background: var(--bg-surface-secondary);
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 1.5rem;
}

/* Inbox */
.inbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.75rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.inbox-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
}

.badge {
    background: var(--primary-color);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
}

.email-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 600px;
    overflow-y: auto;
    padding-right: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Custom Scrollbar */
.email-list::-webkit-scrollbar {
    width: 6px;
}

.email-list::-webkit-scrollbar-track {
    background: transparent;
}

.email-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.email-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.email-item {
    background: var(--bg-surface);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
    animation: slideIn 0.3s ease-out backwards;
    position: relative;
    overflow: visible;
    gap: 1rem;
}

.email-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary-color);
    opacity: 0;
    transition: opacity 0.2s;
}

.email-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
    background: var(--bg-surface);
}

.email-item:hover::before {
    opacity: 1;
}

.email-content {
    flex: 1;
    min-width: 0;
    padding-right: 1rem;
    cursor: pointer;
}

.email-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
    gap: 1rem;
}

.email-sender {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.email-time {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}

.email-subject {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.email-preview {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
    line-height: 1.4;
}


.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-tertiary);
    background: var(--bg-surface-secondary);
    border-radius: var(--radius-xl);
    border: 2px dashed var(--border-color);
}

.empty-icon {
    font-size: 4rem;
    margin: 0 auto 1rem;
    opacity: 0.5;
    animation: float 3s ease-in-out infinite;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    z-index: 1000;
    padding: 2rem;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--bg-surface);
    width: 100%;
    max-width: 800px;
    max-height: 85vh;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: var(--bg-surface-secondary);
}

.modal-title h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.close-btn:hover {
    background: rgba(0,0,0,0.05);
    color: var(--danger-color);
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
    font-size: 1rem;
    line-height: 1.7;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    pointer-events: none;
}

.toast {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 300px;
    max-width: 400px;
    pointer-events: auto;
    animation: slideInRight 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    position: relative;
    overflow: hidden;
}

.toast.success { border-left: 4px solid var(--success-color); }
.toast.error { border-left: 4px solid var(--danger-color); }
.toast.info { border-left: 4px solid var(--primary-color); }

.toast-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.1rem;
}

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

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast-close:hover {
    color: var(--text-primary);
}

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

@keyframes slideOutRight {
    to { transform: translateX(100%); opacity: 0; }
}

/* Saved Emails */
.saved-emails-section {
    margin-top: 2rem;
}

.saved-email-item {
    background: var(--bg-surface-secondary);
    padding: 1rem;
    border-radius: var(--radius-lg);
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
    border: 1px solid transparent;
}

.saved-email-item:hover {
    background: var(--bg-surface);
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.saved-email-info {
    cursor: pointer;
    flex: 1;
}

.btn-delete {
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    flex-shrink: 0;
    line-height: 1;
}

.btn-delete:hover {
    opacity: 1;
    color: var(--danger-color);
    background: transparent;
}

.btn-delete svg {
    width: 14px;
    height: 14px;
    display: block;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 3rem;
}

footer p {
    margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
    body { padding: 1rem; }
    .card { padding: 1.5rem; }
    header { margin-bottom: 2rem; flex-direction: column; gap: 1rem; text-align: center; }
    .theme-toggle { width: 100%; justify-content: center; }
    .action-buttons { flex-direction: column; width: 100%; }
    .btn { width: 100%; }
    .toast-container { bottom: 1rem; right: 1rem; left: 1rem; }
    .toast { width: 100%; min-width: auto; }
}
