/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg-primary: #0a0c10;
  --bg-secondary: #0d1117;
  --bg-card: #161b22;
  --bg-elevated: #1c2128;
  --bg-hover: #1f2937;
  --border: #21262d;
  --border-light: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, 0.12);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.12);
  --yellow: #d29922;
  --yellow-bg: rgba(210, 153, 34, 0.12);
  --orange: #db6d28;
  --orange-bg: rgba(219, 109, 40, 0.12);
  --purple: #bc8cff;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --transition: 150ms ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}
html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg-primary); color: var(--text-primary); line-height: 1.5; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
button { font-family: var(--font); cursor: pointer; transition: all var(--transition); }
input, select, textarea { font-family: var(--font); }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; }
.main { flex: 1; margin-left: 220px; min-height: 100vh; }
.content { padding: 32px; max-width: 1400px; }

/* ===== Sidebar ===== */
.sidebar-brand { padding: 20px 16px; border-bottom: 1px solid var(--border); }
.sidebar-brand h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }
.sidebar-brand span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 16px; color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer; transition: all var(--transition); border-left: 2px solid transparent; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { color: var(--text-primary); background: rgba(88, 166, 255, 0.08); border-left-color: var(--accent); }
.nav-item .icon { width: 18px; text-align: center; font-size: 15px; opacity: 0.7; }
.nav-item.active .icon { opacity: 1; }
.nav-section { padding: 16px 16px 6px; font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1.2px; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }

/* ===== Page Header ===== */
.page-header { margin-bottom: 28px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.page-header p { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.header-actions { display: flex; gap: 8px; }

/* ===== KPI Grid ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.kpi-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: border-color var(--transition); }
.kpi-card:hover { border-color: var(--border-light); }
.kpi-value { font-size: 32px; font-weight: 700; line-height: 1.1; letter-spacing: -1px; }
.kpi-value.accent { color: var(--accent); }
.kpi-value.green { color: var(--green); }
.kpi-value.yellow { color: var(--yellow); }
.kpi-value.cost { font-family: var(--font-mono); color: var(--green); font-size: 26px; }
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; margin-top: 6px; font-weight: 600; }
.kpi-sublabel { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== Cards / Panels ===== */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-body { padding: 0; }
.card-body.padded { padding: 20px; }
.card + .card { margin-top: 20px; }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; background: var(--bg-elevated); border-bottom: 1px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
.cell-primary { font-weight: 600; color: var(--text-primary); }
.cell-secondary { color: var(--text-secondary); }
.cell-mono { font-family: var(--font-mono); font-size: 12px; }
.cell-truncate { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap; }
.badge-critical { background: var(--red-bg); color: var(--red); }
.badge-high { background: var(--orange-bg); color: var(--orange); }
.badge-medium { background: var(--yellow-bg); color: var(--yellow); }
.badge-low { background: var(--green-bg); color: var(--green); }
.badge-success { background: var(--green-bg); color: var(--green); }
.badge-error { background: var(--red-bg); color: var(--red); }
.badge-pending { background: var(--yellow-bg); color: var(--yellow); }
.badge-done { background: var(--green-bg); color: var(--green); }
.badge-enriching { background: rgba(188, 140, 255, 0.12); color: var(--purple); }
.badge-failed { background: var(--red-bg); color: var(--red); }
.badge-active { background: var(--green-bg); color: var(--green); }
.badge-inactive { background: rgba(139, 148, 158, 0.12); color: var(--text-secondary); }
.badge-exported { background: var(--green-bg); color: var(--green); }
.badge-not_exported { background: rgba(139, 148, 158, 0.12); color: var(--text-secondary); }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-yellow { background: var(--yellow); }
.dot-gray { background: var(--text-muted); }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; border: 1px solid transparent; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success { background: #238636; color: #fff; }
.btn-success:hover { background: #2ea043; }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border-light); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--text-muted); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--border-light); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 9px 12px; background: var(--bg-primary); border: 1px solid var(--border-light); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; transition: border-color var(--transition); }
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15); }
.form-input::placeholder { color: var(--text-muted); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding-top: 10vh; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; width: 90%; max-width: 600px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4); }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; padding: 4px 8px; border-radius: 4px; }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ===== Detail Panel ===== */
.detail-panel { position: fixed; top: 0; right: -500px; bottom: 0; width: 480px; background: var(--bg-card); border-left: 1px solid var(--border); z-index: 150; transition: right 200ms ease; overflow-y: auto; box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3); }
.detail-panel.open { right: 0; }
.detail-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; position: sticky; top: 0; background: var(--bg-card); z-index: 1; }
.detail-header h3 { font-size: 18px; font-weight: 700; line-height: 1.3; }
.detail-body { padding: 24px; }
.detail-section { margin-bottom: 24px; }
.detail-section h4 { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.detail-field { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.detail-field .label { color: var(--text-secondary); }
.detail-field .value { color: var(--text-primary); font-weight: 500; text-align: right; max-width: 60%; }
.contact-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 10px; }
.contact-card .name { font-weight: 600; font-size: 14px; }
.contact-card .role { font-size: 12px; color: var(--accent); margin-top: 2px; }
.contact-card .meta { font-size: 12px; color: var(--text-secondary); margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.contact-card .meta a { color: var(--accent); }
.signal-item { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; }
.signal-item .title { font-weight: 500; font-size: 13px; }
.signal-item .meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: flex; gap: 12px; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 36px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 13px; max-width: 320px; margin: 0 auto 16px; }

/* ===== Loading ===== */
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-muted); }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border-light); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; margin-right: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toast ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; box-shadow: var(--shadow); animation: slideIn 200ms ease; }
.toast-success { background: #238636; color: #fff; }
.toast-error { background: #da3633; color: #fff; }
.toast-info { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border-light); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar .nav-item span, .sidebar-brand span, .sidebar-footer, .nav-section { display: none; }
  .sidebar-brand h1 { font-size: 14px; }
  .main { margin-left: 60px; }
  .content { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .detail-panel { width: 100%; right: -100%; }
}
