/* ADT 客户管理系统 — v3 Professional Design */
:root {
    --brand: #1a5fb4;
    --brand-light: #3584e4;
    --brand-bg: #f0f6ff;
    --accent: #e85d04;
    --success: #2ec27e;
    --success-bg: #dff6e8;
    --warning: #f5a623;
    --warning-bg: #fef6e4;
    --danger: #e01b24;
    --danger-bg: #fde8e9;
    --gray-900: #1a1a2e;
    --gray-700: #4a4a5a;
    --gray-500: #8b8b9e;
    --gray-300: #d1d1e0;
    --gray-100: #f4f4f8;
    --bg: #f7f8fc;
    --card-bg: #ffffff;
    --border: #e2e4ed;
    --radius: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --transition: 0.2s ease;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg); color: var(--gray-900); line-height: 1.6; font-size: 15px;
}
a { color: var(--brand); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--brand-light); }

/* ===== Navbar ===== */
.navbar {
    display: flex; align-items: center; justify-content: space-between;
    background: linear-gradient(135deg, var(--brand) 0%, #1a3f8f 100%);
    padding: 0 2rem; height: 56px; box-shadow: var(--shadow-md);
    position: sticky; top: 0; z-index: 100;
}
.nav-brand {
    font-weight: 700; font-size: 1.1rem; color: #fff;
    display: flex; align-items: center; gap: 0.6rem;
}
.nav-logo { height: 28px; border-radius: 4px; }
.nav-links { display: flex; gap: 0.25rem; align-items: center; }
.nav-item {
    color: rgba(255,255,255,0.75); font-size: 0.88rem; padding: 0.45rem 0.85rem;
    border-radius: 8px; transition: all var(--transition);
    display: flex; align-items: center; gap: 0.4rem; text-decoration: none;
}
.nav-item svg { opacity: 0.8; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.12); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.2); color: #fff; font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-divider { width: 1px; height: 24px; background: rgba(255,255,255,0.2); margin: 0 0.5rem; }
.nav-user { color: rgba(255,255,255,0.7); font-size: 0.85rem; }
.btn-logout {
    background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.85);
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.3rem 0.7rem; border-radius: 6px; font-size: 0.8rem; cursor: pointer;
    transition: all var(--transition); text-decoration: none; margin-left: 0.3rem;
}
.btn-logout:hover { background: rgba(255,255,255,0.22); color: #fff; }

/* ===== Toast / Flash ===== */
#toast-container {
    position: fixed; top: 68px; right: 1.5rem; z-index: 9999;
    display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none;
}
.toast {
    padding: 0.7rem 1.2rem; border-radius: 10px; font-size: 0.9rem; font-weight: 500;
    color: #fff; box-shadow: 0 4px 20px rgba(0,0,0,0.15); pointer-events: auto;
    transform: translateX(120%); transition: transform 0.3s ease, opacity 0.3s ease; opacity: 0;
    max-width: 380px;
}
.toast-show { transform: translateX(0); opacity: 1; }
.toast-success { background: #2ec27e; }
.toast-error { background: #e01b24; }
.toast-info { background: var(--brand); }
.toast-warning { background: #e85d04; }

.flash {
    padding: 0.75rem 1.2rem; border-radius: 10px; font-size: 0.9rem; margin-bottom: 1.2rem;
    transition: opacity 0.3s ease; font-weight: 500;
}
.flash-success { background: var(--success-bg); color: #1a7f4b; border: 1px solid #b8e6cc; }
.flash-error { background: var(--danger-bg); color: #a11; border: 1px solid #f5c6c8; }
.flash-info { background: var(--brand-bg); color: var(--brand); border: 1px solid #c8d9f0; }
.flash-warning { background: var(--warning-bg); color: #8b5e0f; border: 1px solid #f0ddb8; }

/* ===== Container ===== */
.container { max-width: 1320px; margin: 1.5rem auto; padding: 0 1.5rem; }

/* ===== Page Title ===== */
.page-title {
    font-size: 1.4rem; font-weight: 700; color: var(--gray-900);
    margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.5rem;
}
.page-title-icon { font-size: 1.3rem; }
.page-subtitle { font-size: 0.88rem; color: var(--gray-500); font-weight: 400; margin-left: 0.5rem; }

/* ===== Metrics Cards ===== */
.metrics-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 900px) { .metrics-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .metrics-row { grid-template-columns: repeat(2, 1fr); } }
.metric-card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.1rem 1.2rem; text-align: center; box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
    cursor: pointer; position: relative;
}
.metric-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--brand-light); }
.metric-card a { position: absolute; inset: 0; border-radius: var(--radius); }
.metric-icon { font-size: 1.5rem; margin-bottom: 0.2rem; }
.metric-value { display: block; font-size: 1.8rem; font-weight: 800; color: var(--brand); }
.metric-label { font-size: 0.82rem; color: var(--gray-500); margin-top: 0.1rem; display: block; }

/* ===== Card ===== */
.card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.5rem; box-shadow: var(--shadow-sm); margin-bottom: 1.5rem;
}
.card h3 { color: var(--gray-900); font-size: 1rem; margin-bottom: 0.8rem; }

/* ===== Toolbar / Search ===== */
.toolbar {
    display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap;
    background: var(--card-bg); padding: 1rem 1.2rem; border-radius: var(--radius);
    border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.search-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; width: 100%; }
.search-form input[type="text"] {
    flex: 1; min-width: 200px; padding: 0.55rem 1rem; border: 1px solid var(--gray-300);
    border-radius: 8px; font-size: 0.9rem; transition: border-color var(--transition);
}
.search-form input[type="text"]:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(26,95,180,0.1); }
.search-form select {
    padding: 0.55rem 0.8rem; border: 1px solid var(--gray-300); border-radius: 8px;
    font-size: 0.88rem; background: #fff; cursor: pointer;
}

/* ===== Table ===== */
.leads-table {
    width: 100%; border-collapse: separate; border-spacing: 0;
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
    table-layout: auto;
}
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
.leads-table { min-width: 900px; }
.leads-table th, .leads-table td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.leads-table th {
    background: var(--gray-100); font-weight: 600; font-size: 0.8rem;
    color: var(--gray-500); letter-spacing: 0.02em; text-transform: uppercase;
}
.leads-table tbody tr { transition: background 0.15s; }
.leads-table tbody tr:hover { background: var(--brand-bg); }
.leads-table tbody tr:last-child td { border-bottom: none; }
.td-direction { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-name-link { font-weight: 600; color: var(--brand); }

/* ===== Badges ===== */
.badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.2rem 0.65rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
    white-space: nowrap; letter-spacing: 0.01em;
}
.badge-discovered { background: #e8edf5; color: #4a5568; }
.badge-drafted { background: var(--warning-bg); color: #8b5e0f; }
.badge-approved { background: var(--success-bg); color: #1a7f4b; }
.badge-sent { background: #e0ecff; color: #1a4fb8; }
.badge-replied { background: var(--success-bg); color: #1a7f4b; }
.badge-bounced { background: var(--danger-bg); color: #a11; }
.badge-lc-new { background: #f0f0f5; color: #555; }
.badge-lc-contacted { background: #e0ecff; color: #1a4fb8; }
.badge-lc-replied { background: var(--success-bg); color: #1a7f4b; }
.badge-lc-interested { background: #fff3e0; color: #e65100; }
.badge-lc-won { background: #c8f7dc; color: #0d5f2f; }
.badge-lc-lost { background: var(--danger-bg); color: #a11; }
.badge-lc-unsubscribed { background: #f0f0f5; color: #888; }
.badge-aud-research { background: #e8f0fe; color: #1a5fb4; }
.badge-aud-industrial { background: #fff3e0; color: #e65100; }

/* ===== Buttons ===== */
.btn, button[type="submit"] {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.55rem 1.1rem; border: none; border-radius: 8px; cursor: pointer;
    font-size: 0.88rem; font-weight: 600; transition: all var(--transition); text-decoration: none;
    position: relative;
}
.btn-primary, button[type="submit"] { background: var(--brand); color: #fff; }
.btn-primary:hover, button[type="submit"]:hover { background: var(--brand-light); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: #e8e8f0; }
.btn-sm {
    padding: 0.3rem 0.75rem; font-size: 0.8rem; border-radius: 6px;
    background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-300);
    cursor: pointer; transition: all var(--transition); text-decoration: none; white-space: nowrap;
}
.btn-sm:hover { background: var(--brand-bg); color: var(--brand); border-color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c01; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn:disabled, button:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; }

/* Loading state */
.btn-loading { pointer-events: none; opacity: 0.7; }
.btn-loading::after {
    content: ''; display: inline-block; width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
    border-radius: 50%; animation: spin 0.6s linear infinite; margin-left: 0.4rem;
}

/* ===== Spinner ===== */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid #ccc; border-top-color: var(--brand);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}

/* ===== Lead Detail ===== */
.lead-header {
    display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem;
    padding-bottom: 1rem; border-bottom: 2px solid var(--border);
}
.lead-header h1 { font-size: 1.3rem; }
.lead-layout { display: grid; grid-template-columns: 400px 1fr; gap: 1.5rem; }
@media (max-width: 900px) { .lead-layout { grid-template-columns: 1fr; } }

.lead-info {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.5rem; box-shadow: var(--shadow-sm);
}
.lead-info h3 { font-size: 0.95rem; color: var(--brand); margin-bottom: 0.8rem; margin-top: 1.2rem; }
.lead-info h3:first-child { margin-top: 0; }
.lead-info dl { display: grid; grid-template-columns: 90px 1fr; gap: 0.4rem 1rem; margin-bottom: 1rem; }
.lead-info dt { font-weight: 600; font-size: 0.82rem; color: var(--gray-500); }
.lead-info dd { font-size: 0.88rem; word-break: break-word; }
.inline-form { display: inline-flex; gap: 0.5rem; align-items: center; margin-bottom: 0.8rem; }
textarea {
    width: 100%; padding: 0.6rem; border: 1px solid var(--gray-300); border-radius: 8px;
    font-size: 0.88rem; font-family: inherit; resize: vertical; min-height: 80px;
    transition: border-color var(--transition);
}
textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(26,95,180,0.1); }

/* ===== Email Preview ===== */
.email-section { margin-top: 1rem; }
.email-section label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--gray-700); margin-bottom: 0.3rem; }
.email-section input[type="text"] {
    width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--gray-300); border-radius: 6px;
    font-size: 0.88rem; margin-bottom: 0.5rem;
}
.email-section input[type="text"]:focus { border-color: var(--brand); outline: none; }
.email-recipient { font-size: 0.82rem; color: var(--gray-500); margin-bottom: 0.6rem; }
.no-email-warning {
    background: var(--warning-bg); padding: 0.75rem; border-radius: 8px; font-size: 0.88rem;
    border: 1px solid #f0ddb8; margin-bottom: 0.5rem;
}

/* ===== Timeline ===== */
.lead-timeline {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.5rem; box-shadow: var(--shadow-sm); max-height: 80vh; overflow-y: auto;
}
.lead-timeline h3 { font-size: 0.95rem; color: var(--brand); margin-bottom: 1rem; }
.timeline-item {
    border-left: 3px solid var(--gray-300); padding: 0.7rem 1rem; margin-bottom: 0.6rem;
    border-radius: 0 8px 8px 0; background: var(--gray-100); transition: background 0.15s;
}
.timeline-item:hover { background: #eef2f9; }
.timeline-item.timeline-inbound { border-left-color: var(--success); background: #f0faf4; }
.timeline-item.timeline-outbound { border-left-color: var(--brand); background: var(--brand-bg); }
.timeline-time { font-size: 0.72rem; color: var(--gray-500); margin-bottom: 0.2rem; }
.timeline-content strong { font-size: 0.85rem; }
.email-body {
    white-space: pre-wrap; font-size: 0.8rem; background: #fff; padding: 0.7rem;
    border-radius: 6px; margin-top: 0.4rem; max-height: 200px; overflow-y: auto;
    border: 1px solid var(--border); font-family: inherit;
}

/* ===== Pagination ===== */
.pagination { display: flex; gap: 0.75rem; align-items: center; margin-top: 1.5rem; justify-content: center; }
.pagination a { padding: 0.45rem 1rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; font-size: 0.88rem; }
.pagination a:hover { background: var(--brand-bg); border-color: var(--brand); }
.pagination span { font-size: 0.85rem; color: var(--gray-500); }

/* ===== Approval hint ===== */
.approval-hint {
    background: var(--brand-bg); padding: 0.75rem 1rem; border-radius: 8px;
    font-size: 0.88rem; margin-bottom: 1.2rem; border: 1px solid #c8d9f0; color: var(--gray-700);
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center; padding: 3rem 2rem; color: var(--gray-500);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.5; }
.empty-state p { font-size: 0.95rem; }

/* ===== Email preview expandable ===== */
.email-preview-row { display: none; }
.email-preview-row.show { display: table-row; }
.email-preview-cell { padding: 1rem !important; background: var(--gray-100); }
.email-preview-box {
    background: var(--card-bg); padding: 0.85rem; border-radius: 8px;
    border: 1px solid var(--border); margin-bottom: 0.75rem;
}
.email-preview-box .email-preview-subject { font-weight: 600; margin-bottom: 0.4rem; font-size: 0.88rem; }
.email-preview-box .email-preview-body { white-space: pre-wrap; font-size: 0.85rem; line-height: 1.5; color: var(--gray-700); }

/* ===== Settings ===== */
.settings-group {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.5rem 2rem; margin-bottom: 1.2rem; box-shadow: var(--shadow-sm);
}
.settings-group h3 { margin-bottom: 1rem; color: var(--brand); font-size: 1rem; }
.settings-group label { display: block; font-size: 0.88rem; color: var(--gray-700); margin-top: 0.8rem; margin-bottom: 0.3rem; }
.settings-group input[type="number"] {
    padding: 0.5rem 0.8rem; border: 1px solid var(--gray-300); border-radius: 8px; width: 140px; font-size: 0.9rem;
}
.settings-group input[type="number"]:focus { border-color: var(--brand); outline: none; }

/* ===== Login ===== */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #f0f6ff 0%, #e8ecf5 100%);
}
.login-container {
    width: 400px; max-width: 90vw; padding: 2.5rem; background: var(--card-bg);
    border-radius: 16px; box-shadow: 0 8px 32px rgba(26,95,180,0.12);
}
.login-brand { text-align: center; margin-bottom: 2rem; }
.login-brand h1 { font-size: 1.5rem; color: var(--brand); margin-bottom: 0.3rem; }
.login-brand p { font-size: 0.85rem; color: var(--gray-500); }
.login-container label { display: block; font-size: 0.88rem; margin-top: 1rem; color: var(--gray-700); font-weight: 500; }
.login-container input[type="text"],
.login-container input[type="password"] {
    width: 100%; padding: 0.65rem 0.9rem; border: 1px solid var(--gray-300); border-radius: 8px;
    font-size: 0.95rem; margin-top: 0.3rem;
}
.login-container input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(26,95,180,0.1); }
.login-container button { width: 100%; margin-top: 1.5rem; padding: 0.7rem; font-size: 1rem; }
.login-error { background: var(--danger-bg); color: #a11; padding: 0.6rem 0.8rem; border-radius: 8px; font-size: 0.88rem; margin-top: 1rem; }

/* ===== Danger zone ===== */
.danger-zone {
    background: #fef2f2; border: 2px solid #fca5a5; border-radius: var(--radius);
    padding: 1rem 1.2rem; margin-top: 1rem;
}
.danger-zone-title { color: var(--danger); font-weight: 700; font-size: 0.9rem; margin-bottom: 0.5rem; }
.danger-zone p { font-size: 0.82rem; color: #7f1d1d; margin-bottom: 0.5rem; }

/* ===== Runs — two-button layout ===== */
.run-actions { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.run-action-card {
    flex: 1; min-width: 260px; background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow-sm);
}
.run-action-card h4 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.run-action-card p { font-size: 0.82rem; color: var(--gray-500); margin-bottom: 0.8rem; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .navbar { padding: 0 1rem; flex-wrap: wrap; height: auto; }
    .nav-links { flex-wrap: wrap; gap: 0.15rem; }
    .container { padding: 0 1rem; margin: 1rem auto; }
    .metrics-row { gap: 0.5rem; }
}
