/* ===== CARDS ===== */
.card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border-light);
}
.card-header h3 { font-size: 0.92rem; font-weight: 700; color: var(--text-primary); }
.card-flush { padding: 0; }
.card-flush .card-header { padding: 20px 24px 14px; margin-bottom: 0; }

/* ===== KPI CARDS ===== */
.kpi-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all 0.22s;
}
.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}
.kpi-corner {
    position: absolute; top: 0; right: 0;
    width: 64px; height: 64px;
    border-bottom-left-radius: 100%;
}
.kpi-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
}
.kpi-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}
.kpi-icon {
    width: 34px; height: 34px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
}
.kpi-icon svg { width: 15px; height: 15px; }
.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.03em;
}
.kpi-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* KPI color variants */
.kpi-corner-indigo { background: #eef2ff; }
.kpi-corner-emerald { background: #ecfdf5; }
.kpi-corner-amber { background: #fffbeb; }
.kpi-corner-red { background: #fef2f2; }
.kpi-corner-purple { background: #faf5ff; }
.kpi-corner-sky { background: #f0f9ff; }

.kpi-icon-indigo { background: #e0e7ff; }
.kpi-icon-indigo svg { stroke: #6366f1; }
.kpi-icon-emerald { background: #d1fae5; }
.kpi-icon-emerald svg { stroke: #10b981; }
.kpi-icon-amber { background: #fef3c7; }
.kpi-icon-amber svg { stroke: #f59e0b; }
.kpi-icon-red { background: #fee2e2; }
.kpi-icon-red svg { stroke: #ef4444; }
.kpi-icon-purple { background: #ede9fe; }
.kpi-icon-purple svg { stroke: #8b5cf6; }
.kpi-icon-sky { background: #e0f2fe; }
.kpi-icon-sky svg { stroke: #0ea5e9; }

.text-indigo { color: #6366f1; }
.text-emerald { color: #10b981; }
.text-amber { color: #f59e0b; }
.text-red { color: #ef4444; }
.text-purple { color: #8b5cf6; }
.text-sky { color: #0ea5e9; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius);
    font-weight: 600; font-size: 0.88rem;
    border: 1px solid transparent; cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn-primary {
    background: var(--accent); color: white;
    box-shadow: 0 1px 2px rgba(99,102,241,0.3);
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
    transform: translateY(-1px);
    color: white;
}
.btn-secondary { background: var(--bg-primary); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-tertiary); border-color: var(--border-light); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(239,68,68,0.2); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-icon { width: 38px; height: 38px; padding: 0; justify-content: center; border-radius: var(--radius); }

/* ===== BADGES ===== */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: var(--radius-full);
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: #b45309; }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-accent { background: var(--accent-subtle); color: var(--accent); }
.badge-muted { background: var(--bg-tertiary); color: var(--text-secondary); font-weight: 500; }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%; border-collapse: collapse;
    font-size: 0.88rem;
}
.table th {
    text-align: left; padding: 12px 16px;
    font-size: 0.72rem; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.05em; border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    position: sticky; top: 0;
}
.table td {
    padding: 14px 16px; border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--bg-tertiary); }
.table tbody tr.clickable { cursor: pointer; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 20px; }
.form-label {
    display: block; margin-bottom: 6px;
    font-size: 0.85rem; font-weight: 500; color: var(--text-secondary);
}
.form-input, .form-textarea, .form-select {
    width: 100%; padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text-primary);
    transition: all var(--transition);
    outline: none;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-input::placeholder { color: var(--text-muted); }
.form-check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.form-check input[type="checkbox"] {
    width: 18px; height: 18px; accent-color: var(--accent);
    border-radius: 4px; cursor: pointer;
}

/* ===== AVATAR ===== */
.avatar {
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-full); font-weight: 600;
    font-size: 0.8rem; flex-shrink: 0;
    background: var(--accent-light); color: var(--accent);
}
.avatar-sm { width: 34px; height: 34px; font-size: 0.72rem; }
.avatar-md { width: 42px; height: 42px; }
.avatar-lg { width: 52px; height: 52px; font-size: 1rem; }

/* ===== TOAST ===== */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
    padding: 14px 20px; border-radius: var(--radius);
    background: var(--bg-primary); border: 1px solid var(--border);
    color: var(--text-primary); font-size: 0.88rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease-out;
    max-width: 380px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }

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

/* ===== EMPTY STATE ===== */
.empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 60px 20px;
    color: var(--text-secondary); text-align: center;
}
.empty-state-icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.3; }
.empty-state-text { font-size: 0.95rem; }

/* ===== TABS ===== */
.tabs {
    display: flex; gap: 4px; margin-bottom: 24px;
    border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.tab {
    padding: 10px 20px; font-size: 0.88rem; font-weight: 500;
    color: var(--text-secondary); background: none; border: none;
    cursor: pointer; border-bottom: 2px solid transparent;
    transition: all var(--transition); margin-bottom: -1px;
    text-decoration: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ===== LOADING ===== */
.spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    display: flex; align-items: center; justify-content: center;
    padding: 60px; width: 100%;
}

/* ===== DETAIL PANEL ===== */
.detail-panel {
    position: fixed; top: 0; right: -480px; width: 480px;
    height: 100vh; background: var(--bg-primary);
    border-left: 1px solid var(--border);
    z-index: 100; transition: right var(--transition-slow);
    overflow-y: auto; box-shadow: var(--shadow-lg);
}
.detail-panel.open { right: 0; }
.detail-panel-header {
    position: sticky; top: 0; background: var(--bg-primary);
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    z-index: 1;
}
.detail-panel-header h3 { font-size: 1rem; font-weight: 700; }
.detail-panel-body { padding: 24px; }
.detail-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.3); z-index: 99;
    opacity: 0; visibility: hidden; transition: all var(--transition-slow);
    backdrop-filter: blur(2px);
}
.detail-overlay.open { opacity: 1; visibility: visible; }

.detail-section { margin-bottom: 20px; }
.detail-label {
    font-size: 0.72rem; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;
}
.detail-value { font-size: 0.92rem; line-height: 1.6; color: var(--text-primary); }
.detail-message {
    white-space: pre-wrap; background: var(--bg-tertiary);
    padding: 12px 16px; border-radius: var(--radius);
    font-size: 0.85rem; line-height: 1.6;
}
.detail-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}

/* ===== ESCALATION CLIENT ===== */
.escalation-client { display: flex; align-items: center; gap: 10px; }
.escalation-msg { font-size: 0.85rem; }

/* ===== DASHBOARD LIVE ENGINE ===== */
.live-control {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-secondary, #f8fafc);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 6px 12px;
    font-size: 0.75rem;
    user-select: none;
}

.live-indicator {
    position: relative;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.live-ring {
    width: 28px;
    height: 28px;
    transition: opacity 0.3s;
}

.live-indicator.paused .live-ring { opacity: 0.3; }

.live-ring-progress {
    transition: stroke-dashoffset 0.3s ease;
}

.live-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6366f1;
    transition: background 0.3s;
}

.live-indicator:not(.paused) .live-dot {
    animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(99, 102, 241, 0); }
}

.live-indicator.fetching .live-ring {
    animation: live-spin 0.8s linear infinite;
}

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

.live-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 48px;
}

.live-label {
    font-weight: 700;
    color: #6366f1;
    text-transform: uppercase;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    line-height: 1;
}

.live-timer {
    color: var(--text-muted, #94a3b8);
    font-variant-numeric: tabular-nums;
    font-size: 0.7rem;
    line-height: 1;
}

.live-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
    padding-left: 10px;
    border-left: 1px solid var(--border, #e2e8f0);
}

.live-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    transition: all 0.15s;
}

.live-btn:hover {
    background: var(--bg-hover, #f1f5f9);
    color: #6366f1;
}

.live-btn.spinning svg {
    animation: live-spin 0.6s linear infinite;
}

.live-select {
    appearance: none;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    padding: 3px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
    background: transparent;
    cursor: pointer;
    outline: none;
    width: 48px;
    text-align: center;
}

.live-select:focus {
    border-color: #6366f1;
}

/* KPI animations */
@keyframes kpi-pulse-anim {
    0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.2); }
    50% { box-shadow: 0 0 0 8px rgba(99, 102, 241, 0); }
    100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

.kpi-pulse {
    animation: kpi-pulse-anim 1.5s ease-out;
}

.kpi-delta {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 6px;
    margin-left: 6px;
    vertical-align: middle;
    animation: kpi-delta-in 0.3s ease-out;
    transition: opacity 0.5s;
}

@keyframes kpi-delta-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.8); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.kpi-delta-fade { opacity: 0; }

.kpi-delta-up {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.kpi-delta-down {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Responsive */
@media (max-width: 640px) {
    .live-control { padding: 4px 8px; gap: 6px; }
    .live-meta { display: none; }
    .live-actions { border-left: none; padding-left: 0; margin-left: 0; }
}

/* ===== KPI CLICKABLE ===== */
.kpi-clickable { cursor: pointer; }
.kpi-clickable:hover { border-color: #c7d2fe; }

/* ===== CHART PERIOD SELECTOR ===== */
.chart-period-selector {
    display: flex;
    gap: 2px;
    background: var(--bg-secondary, #f1f5f9);
    border-radius: 8px;
    padding: 2px;
}

.chart-period-btn {
    padding: 4px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted, #94a3b8);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.chart-period-btn:hover { color: var(--text-primary, #1e293b); }

.chart-period-btn.active {
    background: var(--bg-primary, #fff);
    color: #6366f1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ===== CHART COMPARATIVE ===== */
.chart-comparative {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 24px;
    font-size: 0.75rem;
    border-bottom: 1px solid var(--border, #f1f5f9);
}

.chart-comp-total {
    font-weight: 700;
    color: var(--text-primary, #1e293b);
}

.chart-comp-change {
    font-weight: 600;
}

.chart-comp-prev {
    color: var(--text-muted, #94a3b8);
    margin-left: auto;
}

/* ===== DRILL-DOWN MODAL ===== */
.drill-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
    animation: drill-fade 0.2s ease;
}

@keyframes drill-fade { from { opacity: 0; } to { opacity: 1; } }

.drill-modal {
    background: var(--bg-primary, #fff);
    border-radius: 16px;
    width: 520px;
    max-width: 95vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    animation: drill-slide 0.25s ease-out;
    overflow: hidden;
}

@keyframes drill-slide {
    from { transform: translateY(16px) scale(0.98); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

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

.drill-header h3 { font-size: 1rem; font-weight: 700; margin: 0; }

.drill-close {
    width: 32px; height: 32px;
    border: none; border-radius: 8px;
    background: transparent;
    font-size: 1.3rem;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

.drill-close:hover { background: var(--bg-hover, #f1f5f9); }

.drill-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.drill-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.drill-table th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border, #e2e8f0);
}

.drill-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border, #f1f5f9);
    color: var(--text-primary, #1e293b);
}

.drill-total-row td {
    border-top: 2px solid var(--border, #e2e8f0);
    border-bottom: none;
    font-weight: 700;
}

.drill-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.8rem;
}

.drill-pill-blue { background: rgba(99,102,241,0.1); color: #6366f1; }
.drill-pill-green { background: rgba(16,185,129,0.1); color: #10b981; }

.drill-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.drill-stat {
    text-align: center;
    padding: 16px;
    background: var(--bg-secondary, #f8fafc);
    border-radius: 12px;
}

.drill-stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}

.drill-stat-label {
    font-size: 0.72rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 4px;
    font-weight: 600;
}

.drill-gauge-wrap { margin-top: 16px; }

.drill-gauge-bar {
    height: 10px;
    background: var(--bg-secondary, #f1f5f9);
    border-radius: 99px;
    overflow: hidden;
}

.drill-gauge-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.6s ease;
}

.drill-gauge-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 6px;
    font-weight: 600;
}

.drill-link {
    display: block;
    text-align: center;
    margin-top: 16px;
    padding: 10px;
    color: #6366f1;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.15s;
}

.drill-link:hover { background: rgba(99,102,241,0.04); }

.drill-empty {
    text-align: center;
    color: var(--text-muted, #94a3b8);
    padding: 40px 20px;
}

.drill-lead-list { display: flex; flex-direction: column; gap: 8px; }

.drill-lead-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-secondary, #f8fafc);
    border-radius: 10px;
}

.drill-lead-days {
    font-size: 0.8rem;
    font-weight: 700;
    min-width: 32px;
    text-align: center;
}

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

.drill-lead-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary, #1e293b);
}

.drill-lead-meta {
    font-size: 0.72rem;
    color: var(--text-muted, #94a3b8);
}

.drill-lead-score {
    font-size: 0.72rem;
    font-weight: 700;
    color: #6366f1;
    background: rgba(99,102,241,0.08);
    padding: 2px 8px;
    border-radius: 6px;
}

.drill-lead-item-link {
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.drill-lead-item-link:hover {
    background: #eef2ff;
}

.drill-status-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.drill-status-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-secondary, #f8fafc);
    border-radius: 10px;
    font-size: 0.85rem;
}

.drill-status-item strong {
    margin-left: auto;
}

.drill-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
