/* ============================================
   AI 邮件管理面板 - 深色主题样式
   Premium dark theme with glassmorphism
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.03);

    --border-color: rgba(255, 255, 255, 0.06);
    --border-glow: rgba(99, 102, 241, 0.3);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.1);

    --sidebar-width: 240px;
    --topbar-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.95) 0%, rgba(10, 14, 26, 0.98) 100%);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(20px);
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 24px;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-light), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all var(--transition);
    position: relative;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-glass);
}

.nav-item.active {
    color: var(--accent-light);
    background: var(--accent-glow);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-icon { font-size: 18px; }

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    animation: pulse-badge 2s infinite;
}

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

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.system-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.running {
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
    animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
    0%, 100% { box-shadow: 0 0 4px rgba(16, 185, 129, 0.3); }
    50% { box-shadow: 0 0 12px rgba(16, 185, 129, 0.6); }
}

/* ---------- Main Content ---------- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
    height: var(--topbar-height);
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(10, 14, 26, 0.6);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-refresh {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 16px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-refresh:hover {
    background: var(--accent-glow);
    border-color: var(--border-glow);
    color: var(--text-primary);
    transform: rotate(180deg);
}

.last-update {
    font-size: 12px;
    color: var(--text-muted);
}

/* ---------- Pages ---------- */
.page {
    display: none;
    padding: 24px 28px;
    flex: 1;
    animation: fadeIn 0.3s ease;
}

.page.active { display: block; }

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

/* ---------- Stats Grid ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0;
    transition: opacity var(--transition);
}

.stat-card:hover {
    border-color: var(--border-glow);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.stat-card:hover::before { opacity: 1; }

.stat-card.accent::before { background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: 1; }
.stat-card.warning::before { background: linear-gradient(90deg, transparent, var(--warning), transparent); opacity: 1; }
.stat-card.success::before { background: linear-gradient(90deg, transparent, var(--success), transparent); opacity: 1; }

.stat-icon {
    font-size: 28px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -1px;
    line-height: 1.1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}

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

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

.card-body { padding: 0; }

/* ---------- Tables ---------- */
.table-container { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tbody tr {
    transition: background var(--transition);
    cursor: pointer;
}

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

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px !important;
    font-style: italic;
}

/* ---------- Status Badges ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.status-badge.auto_replied {
    background: var(--accent-glow);
    color: var(--accent-light);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.status-badge.wait_human {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-badge.manual_replied {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-badge.ignored {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.2);
}

.status-badge.pending, .status-badge.processing {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

/* Urgency */
.urgency-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.urgency-dot.low { background: var(--success); }
.urgency-dot.medium { background: var(--warning); }
.urgency-dot.high { background: #f97316; }
.urgency-dot.critical { background: var(--danger); animation: status-pulse 1s infinite; }

/* ---------- Filter Bar ---------- */
.filter-bar {
    margin-bottom: 16px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.filter-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.filter-btn:hover { color: var(--text-primary); background: var(--bg-glass); }
.filter-btn.active { background: var(--accent); color: white; }

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 16px;
}

.pagination button {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.pagination button:hover { border-color: var(--border-glow); color: var(--text-primary); }
.pagination button.active { background: var(--accent); border-color: var(--accent); color: white; }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* ---------- Pending List ---------- */
.pending-list {
    display: flex;
    flex-direction: column;
}

.pending-item {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 16px;
    align-items: flex-start;
    transition: background var(--transition);
    cursor: pointer;
}

.pending-item:hover { background: var(--bg-card-hover); }
.pending-item:last-child { border-bottom: none; }

.pending-urgency {
    margin-top: 4px;
}

.pending-info { flex: 1; }

.pending-from {
    font-weight: 600;
    margin-bottom: 2px;
}

.pending-subject {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 4px;
}

.pending-reason {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.pending-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.pending-actions {
    display: flex;
    gap: 6px;
}

/* ---------- Buttons ---------- */
.btn {
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    font-family: var(--font);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

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

.btn-primary:hover {
    background: var(--accent-light);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--border-glow);
    color: var(--text-primary);
}

.btn-outline {
    background: transparent;
    color: var(--accent-light);
    border: 1px solid var(--accent);
}

.btn-outline:hover {
    background: var(--accent-glow);
}

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

.badge {
    background: var(--accent-glow);
    color: var(--accent-light);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 90%;
    max-width: 720px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

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

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

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

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

.modal-body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
}

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

/* Email detail inside modal */
.email-meta {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 6px 12px;
    margin-bottom: 18px;
    font-size: 13px;
}

.email-meta .label {
    color: var(--text-muted);
    font-weight: 500;
}

.email-body {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 18px;
    margin-bottom: 18px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 13px;
    max-height: 300px;
    overflow-y: auto;
}

.ai-analysis {
    background: var(--accent-glow);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 18px;
}

.ai-analysis h3 {
    font-size: 14px;
    margin-bottom: 10px;
}

.ai-analysis .ai-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 12px;
}

.ai-analysis .ai-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.ai-analysis .ai-label { color: var(--text-muted); }
.ai-analysis .ai-value { font-weight: 600; }

.email-replies { margin-bottom: 18px; }

.email-replies h3 {
    font-size: 14px;
    margin-bottom: 10px;
}

.reply-item {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 8px;
}

.reply-item .reply-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.reply-item .reply-content {
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* Reply form */
.reply-form h3 {
    font-size: 14px;
    margin-bottom: 10px;
}

.reply-form textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 14px;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition);
}

.reply-form textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.reply-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
}

/* ---------- Charts ---------- */
.stats-charts {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.chart-container {
    padding: 20px;
    min-height: 280px;
}

.intent-chart {
    padding: 20px;
}

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

.intent-label {
    width: 140px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.intent-track {
    flex: 1;
    height: 24px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.intent-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.intent-fill::after {
    content: attr(data-count);
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    font-weight: 600;
    color: white;
}

/* Daily chart bars */
.daily-chart-container {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 200px;
    padding: 10px 0;
}

.daily-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    height: 100%;
    justify-content: flex-end;
}

.daily-bars {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    width: 100%;
    justify-content: center;
}

.daily-bar {
    width: 12px;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.daily-bar.auto { background: var(--accent); }
.daily-bar.manual { background: var(--warning); }

.daily-label {
    font-size: 10px;
    color: var(--text-muted);
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    max-height: 50px;
    overflow: hidden;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.chart-legend span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.legend-dot.auto { background: var(--accent); }
.legend-dot.manual { background: var(--warning); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .menu-toggle {
        display: block;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-charts {
        grid-template-columns: 1fr;
    }

    .modal {
        width: 95%;
        max-height: 90vh;
    }

    .ai-analysis .ai-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .page {
        padding: 16px;
    }

    .filter-group {
        flex-wrap: wrap;
    }
}
