/* =============================================
   MailPilot — Main Stylesheet
   ============================================= */

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --primary-dark: #4338ca;

    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #dc2626;

    --bg: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-tertiary: #e2e8f0;
    --surface: #ffffff;
    --surface-hover: #f8fafc;

    --text: #0f172a;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;

    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --border-focus: #6366f1;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --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: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    --sidebar-width: 240px;
    --topbar-height: 56px;
    --email-list-width: 360px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;

    --transition: 150ms ease;
    --transition-md: 250ms ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --surface: #1e293b;
    --surface-hover: #334155;

    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;

    --border: #334155;
    --border-light: #1e293b;

    --primary-light: #312e81;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

::selection {
    background: var(--primary);
    color: white;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

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

/* Typography */
h1, h2, h3, h4, h5 {
    font-weight: 600;
    line-height: 1.3;
}

/* Auth Screen */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-xl);
}

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

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

.auth-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

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

.auth-tab {
    flex: 1;
    padding: 10px 16px;
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
}

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

.auth-tab:hover:not(.active) {
    color: var(--text);
}

.auth-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 12px;
    padding: 8px 12px;
    background: #fef2f2;
    border-radius: var(--radius-sm);
    text-align: center;
}

[data-theme="dark"] .auth-error {
    background: rgba(239, 68, 68, 0.1);
}

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

/* Top Bar */
.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 16px;
    flex-shrink: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.app-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 6px 14px;
    flex: 1;
    max-width: 480px;
    transition: all var(--transition);
}

.search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-box .icon {
    color: var(--text-tertiary);
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.search-box input {
    border: none;
    background: none;
    outline: none;
    font-size: 0.9rem;
    color: var(--text);
    flex: 1;
    min-width: 0;
}

.search-box input::placeholder {
    color: var(--text-tertiary);
}

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

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-section {
    padding: 12px;
}

.sidebar-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
}

.sidebar-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin: 1px 6px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    transition: all var(--transition);
    text-decoration: none;
    position: relative;
}

.sidebar-item:hover {
    background: var(--surface-hover);
}

.sidebar-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.sidebar-item .folder-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    opacity: 0.8;
}

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

.sidebar-item .folder-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
}

.sidebar-item.active .folder-count {
    background: rgba(99,102,241,0.15);
    color: var(--primary);
}

.sidebar-item .unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
}

.sidebar-mailbox-item {
    padding: 6px 12px;
    margin: 1px 6px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-mailbox-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.sidebar-mailbox-item .mailbox-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-radius: var(--radius);
    transition: all var(--transition);
}

.sidebar-footer-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.storage-info {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.storage-bar {
    flex: 1;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.storage-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* Email List Panel */
.email-list-panel {
    width: var(--email-list-width);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    flex-shrink: 0;
}

.panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.panel-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.email-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

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

.email-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}

.email-item:hover {
    background: var(--surface-hover);
}

.email-item.active {
    background: var(--primary-light);
}

.email-item.unread {
    background: var(--surface);
}

.email-item.unread .email-item-subject {
    font-weight: 700;
}

.email-item.unread .email-item-preview {
    color: var(--text);
}

.email-item.selected {
    background: var(--primary-light);
}

.email-item-check {
    flex-shrink: 0;
    margin-top: 2px;
}

.email-item-content {
    flex: 1;
    min-width: 0;
}

.email-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 3px;
}

.email-item-from {
    font-size: 0.9rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.email-item-date {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.email-item-subject {
    font-size: 0.875rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

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

.email-item-flags {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-top: 2px;
}

.email-item-flags svg {
    width: 14px;
    height: 14px;
}

.star-active {
    color: #f59e0b;
    fill: #f59e0b;
}

.email-pagination {
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#pagination-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Email View Panel */
.email-view-panel {
    flex: 1;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    gap: 12px;
}

.empty-state svg {
    opacity: 0.2;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.empty-state p {
    font-size: 0.9rem;
}

.email-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.email-detail-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.email-subject-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.email-subject {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    flex: 1;
    line-height: 1.3;
    word-break: break-word;
}

.email-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.email-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.email-from-avatar {
    flex-shrink: 0;
}

.email-from-info {
    flex: 1;
    min-width: 0;
}

.email-from-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.email-from-email {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.email-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
}

.email-recipients {
    font-size: 0.8rem;
}

.email-to-row, .email-cc-row {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.email-to-label {
    font-weight: 600;
    flex-shrink: 0;
}

.email-to-value {
    color: var(--text);
}

.email-detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.email-body-content {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text);
    max-width: 720px;
}

.email-body-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 8px 0;
}

.email-body-content a {
    color: var(--primary);
}

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

.email-attachments {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.attachments-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.attachments-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    color: var(--text);
}

.attachment-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.attachment-item svg {
    flex-shrink: 0;
    color: var(--primary);
}

.attachment-info {
    min-width: 0;
}

.attachment-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.attachment-size {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.email-reply-bar {
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Avatar */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    text-transform: uppercase;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
}

.avatar-lg {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
}

/* User Menu */
.user-menu {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition);
}

.dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.dropdown-user-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.dropdown-user-email {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    font-size: 0.875rem;
    color: var(--text);
    cursor: pointer;
    transition: background var(--transition);
    text-align: left;
}

.dropdown-item:hover {
    background: var(--surface-hover);
}

.dropdown-item.danger:hover {
    background: #fef2f2;
    color: var(--danger);
}

[data-theme="dark"] .dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}
