/* 全局样式 */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --radius: 8px;
    --radius-sm: 4px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* 登录页 */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 28px;
    color: var(--primary);
    margin-bottom: 8px;
}

.login-logo p {
    color: var(--text-light);
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text);
}

.login-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

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

.login-hint {
    margin-top: 20px;
    text-align: center;
    color: var(--text-light);
    font-size: 12px;
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
    text-align: center;
    min-height: 18px;
}

/* 主布局 */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 240px;
    background: white;
    border-right: 1px solid var(--border);
    padding: 20px 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.sidebar-logo h2 {
    font-size: 18px;
    color: var(--primary);
}

.sidebar-logo p {
    font-size: 12px;
    color: var(--text-light);
}

.sidebar-nav {
    list-style: none;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--bg);
}

.sidebar-nav a.active {
    background: var(--primary-light);
    border-left-color: var(--primary);
    color: var(--primary);
    font-weight: 500;
}

.sidebar-nav .icon {
    margin-right: 10px;
    font-size: 16px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    margin-top: auto;
    position: absolute;
    bottom: 0;
    width: 100%;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    background: var(--bg);
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-weight: 500;
    font-size: 13px;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-light);
}

.sidebar-logout {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.sidebar-logout:hover {
    background: var(--border);
    color: var(--danger);
}

/* 主内容 */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 24px 32px;
}

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

.page-title {
    font-size: 22px;
    font-weight: 600;
}

.page-actions {
    display: flex;
    gap: 8px;
}

/* 卡片 */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

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

.card-title {
    font-size: 16px;
    font-weight: 600;
}

/* 按钮 */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    background: var(--bg);
    border-color: var(--text-muted);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-success:hover {
    background: #059669;
    border-color: #059669;
}

.btn-warning {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

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

/* 表单 */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text);
    font-size: 13px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-help {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-light);
}

/* 表格 */
.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table tr:hover {
    background: var(--bg);
}

.table tr:last-child td {
    border-bottom: none;
}

/* 标签 */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 12px;
    background: var(--bg);
    color: var(--text-light);
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* 优先级标签 */
.priority-urgent { background: #fee2e2; color: #991b1b; }
.priority-high { background: #fef3c7; color: #92400e; }
.priority-normal { background: #dbeafe; color: #1e40af; }
.priority-low { background: #f1f5f9; color: #475569; }

/* 分类标签 */
.category-spam { background: #fee2e2; color: #991b1b; }
.category-ad { background: #fef3c7; color: #92400e; }
.category-finance { background: #fef9c3; color: #854d0e; }
.category-inquiry { background: #dbeafe; color: #1e40af; }
.category-meeting { background: #ede9fe; color: #5b21b6; }
.category-notification { background: #d1fae5; color: #065f46; }
.category-work { background: #cffafe; color: #155e75; }
.category-personal { background: #fce7f3; color: #9d174d; }
.category-uncategorized { background: #f1f5f9; color: #475569; }

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}

.stat-card.warning { border-left-color: var(--warning); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.info { border-left-color: var(--info); }

.stat-label {
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
}

.stat-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* 邮件列表 */
.email-list {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.email-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.email-item.unread {
    background: #f0f4ff;
}

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

.email-checkbox {
    width: 16px;
    height: 16px;
}

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

.email-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.email-from {
    font-weight: 500;
    color: var(--text);
}

.email-date {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
}

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

.email-preview {
    font-size: 12px;
    color: var(--text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-meta {
    display: flex;
    gap: 6px;
    align-items: center;
}

.email-flag {
    color: var(--warning);
    font-size: 16px;
}

/* 邮件详情 */
.email-detail {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.email-detail-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    margin-bottom: 20px;
}

.email-detail-subject {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
}

.email-detail-meta {
    display: flex;
    gap: 16px;
    color: var(--text-light);
    font-size: 13px;
}

.email-detail-body {
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

.email-detail-body img {
    max-width: 100%;
    height: auto;
}

.email-detail-actions {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* 模态框 */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal.lg {
    max-width: 800px;
}

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

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-light);
    padding: 0;
    line-height: 1;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* 提示信息 */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

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

.toast {
    background: white;
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    padding: 12px 20px;
    min-width: 250px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
}

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

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

/* 快捷过滤器 */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

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

.filter-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.view-tabs {
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
}

.view-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.view-tab:hover {
    color: var(--primary);
}

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

/* 加载状态 */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

.spinner {
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

/* 空状态 */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 14px;
    margin-bottom: 16px;
}

/* 响应式 */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }
    .sidebar-logo h2,
    .sidebar-logo p,
    .sidebar-nav a span,
    .sidebar-user-info {
        display: none;
    }
    .sidebar-nav a {
        justify-content: center;
        padding: 12px;
    }
    .sidebar-nav .icon {
        margin-right: 0;
    }
    .main-content {
        margin-left: 60px;
        padding: 16px;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* 联系人自动补全 */
.contact-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 240px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.contact-suggestion-item {
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

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

.contact-suggestion-item:hover {
    background: var(--primary-light);
}

.contact-suggestion-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.contact-suggestion-email {
    font-size: 12px;
    color: var(--text-light);
}

/* 联系人页面 */
.contact-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.contact-card:hover {
    background: var(--bg);
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
}

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

.contact-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-email {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-source {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* 文本颜色 */
.text-gray { color: var(--text-light); }
.text-muted { color: var(--text-muted); }

/* 响应式设计 - 手机端适配 */
@media (max-width: 768px) {
    /* 布局调整 */
    .app-layout {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateY(0);
    }
    
    .main-content {
        margin-left: 0;
        padding-top: 56px;
    }
    
    /* 移动端菜单按钮 */
    .mobile-menu-btn {
        display: flex !important;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 101;
        width: 40px;
        height: 40px;
        background: var(--bg-card);
        border-radius: 8px;
        align-items: center;
        justify-content: center;
        box-shadow: var(--shadow);
        cursor: pointer;
    }
    
    /* 邮件列表 */
    .email-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .email-sender {
        font-size: 14px;
    }
    
    .email-subject {
        font-size: 13px;
    }
    
    .email-meta {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    
    .email-meta .badge {
        flex-shrink: 0;
    }
    
    /* 模态框 */
    .modal {
        width: 95%;
        max-width: 95%;
        margin: 10px auto;
    }
    
    /* 筛选栏 */
    .filter-bar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 12px;
    }
    
    .filter-bar > * {
        flex-shrink: 0;
    }
    
    .filter-bar .form-input {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-top: 6px;
    }
    
    .filter-chip {
        font-size: 11px;
        padding: 4px 8px;
        white-space: nowrap;
    }
    
    /* 顶部操作栏 */
    .card[style*="gap:12px"] {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    .card[style*="gap:12px"] .btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    /* 批量操作 */
    .batch-actions {
        flex-wrap: wrap;
    }
    
    .batch-actions .btn {
        font-size: 11px;
        padding: 6px 10px;
    }
    
    /* 表单 */
    .form-group {
        margin-bottom: 12px;
    }
    
    .form-input, .form-select, .form-textarea {
        font-size: 14px;
    }
    
    /* 分页 */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    /* 联系人卡片 */
    .contact-card {
        padding: 12px;
    }
    
    .contact-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    /* 隐藏桌面端元素 */
    .hide-mobile {
        display: none !important;
    }
}

/* 移动端菜单按钮默认隐藏 */
.mobile-menu-btn {
    display: none;
}

/* 触摸优化 */
@media (hover: none) and (pointer: coarse) {
    .btn, .filter-chip, .nav-item {
        min-height: 44px;
        min-width: 44px;
    }
    
    .email-item {
        padding: 14px 16px;
    }
}
