:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e5eaf2;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --healthy: #10b981;
  --healthy-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --critical: #ef4444;
  --critical-bg: #fef2f2;
  --pending: #6366f1;
  --pending-bg: #eef2ff;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 15px;
}
.brand h1 { margin: 0; font-size: 18px; }
.subtitle { margin: 0; font-size: 12px; color: var(--muted); }

.status-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: #f8fafc; color: var(--text);
  display: inline-flex; align-items: center; gap: 6px;
}
.pill-ok { background: var(--healthy-bg); border-color: #a7f3d0; color: #065f46; }
.pill-warn { background: var(--warning-bg); border-color: #fde68a; color: #92400e; }
.pill-err { background: var(--critical-bg); border-color: #fecaca; color: #991b1b; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

.topbar-actions { display: flex; gap: 10px; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--critical-bg); color: #b91c1c; border-color: #fecaca; }
.btn-success { background: var(--healthy-bg); color: #047857; border-color: #a7f3d0; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }

.nav-tabs {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 28px; display: flex; gap: 24px;
}
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 12px 4px; font-size: 14px; font-weight: 600; color: var(--muted);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.badge {
  background: var(--critical); color: #fff; font-size: 11px;
  padding: 1px 7px; border-radius: 999px; font-weight: 700;
}
.badge.zero { background: #cbd5e1; color: #334155; }

.main-container { padding: 22px 28px; max-width: 1480px; width: 100%; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.kpi-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.kpi-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val { font-size: 24px; font-weight: 800; margin-top: 4px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.dashboard-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(410px, 1fr));
  gap: 16px;
}
.dash-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform .15s, border-color .15s;
  border-top: 4px solid #cbd5e1;
}
.dash-card:hover { transform: translateY(-2px); border-color: #93c5fd; }
.dash-card.status-HEALTHY { border-top-color: var(--healthy); }
.dash-card.status-WARNING { border-top-color: var(--warning); }
.dash-card.status-CRITICAL { border-top-color: var(--critical); }
.dash-card.status-PENDING { border-top-color: var(--pending); }

.dash-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.dash-domain { font-size: 11px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; }
.dash-name { margin: 2px 0 0; font-size: 16px; font-weight: 700; }

.status-tag {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.tag-HEALTHY { background: var(--healthy-bg); color: #047857; }
.tag-WARNING { background: var(--warning-bg); color: #b45309; }
.tag-CRITICAL { background: var(--critical-bg); color: #b91c1c; }
.tag-PENDING { background: var(--pending-bg); color: #4338ca; }

.dash-meta {
  display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0;
  font-size: 12px; color: var(--muted); background: #f8fafc;
  padding: 8px 10px; border-radius: 8px;
}
.dash-meta strong { color: var(--text); }

.metrics-mini {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px;
}
.metric-cell {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.metric-label { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.metric-num { font-size: 15px; font-weight: 700; margin-top: 2px; }
.delta-up { color: #059669; font-weight: 600; }
.delta-down { color: #dc2626; font-weight: 600; }

.finding-banner {
  margin-top: 12px; padding: 8px 10px; border-radius: 8px; font-size: 12px;
  background: var(--critical-bg); color: #991b1b; border: 1px solid #fecaca;
}
.finding-banner.warn { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
}
.panel-header h2 { margin: 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

.filter-group { display: flex; gap: 8px; }
.chip {
  background: #fff; border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; cursor: pointer; font-weight: 600; color: var(--muted);
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.incident-list { display: flex; flex-direction: column; gap: 12px; }
.incident-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  border-left: 4px solid var(--critical);
}
.incident-card.sev-P1 { border-left-color: var(--warning); }
.incident-card.st-RESOLVED { border-left-color: var(--healthy); opacity: .82; }
.incident-card.st-FALSE_POSITIVE { border-left-color: #94a3b8; opacity: .72; }

.inc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.inc-title { font-size: 15px; font-weight: 700; margin: 4px 0; }
.inc-body { font-size: 13px; color: #334155; margin: 6px 0; }
.inc-guide {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 12px; color: #1e293b; margin: 8px 0;
}
.inc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }

.tuning-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card.span-2 { grid-column: span 2; }
.card-head { margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 15px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; background: #f8fafc; }

.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: #334155; }
.form-stack input, .form-stack textarea, .inline-form input {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 13px; font-family: inherit;
}
.inline-form { display: grid; grid-template-columns: 1.4fr 1.5fr 0.8fr 0.7fr 0.8fr auto; gap: 8px; margin-bottom: 14px; }
.form-actions { display: flex; align-items: center; gap: 12px; }

/* Drawer */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 95vw);
  background: var(--surface); z-index: 50; box-shadow: -8px 0 30px rgba(15,23,42,.15);
  display: flex; flex-direction: column;
}
.drawer-header {
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.drawer-header h2 { margin: 0; font-size: 17px; }
.drawer-actions { display: flex; gap: 8px; align-items: center; }
.drawer-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.section-block { margin-bottom: 20px; }
.section-block h4 { margin: 0 0 8px; font-size: 14px; color: #1e293b; }

.hidden { display: none !important; }
.empty-state {
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 36px; text-align: center; color: var(--muted);
}

.toast {
  position: fixed; bottom: 24px; right: 24px; background: #0f172a; color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}

@media (max-width: 960px) {
  .tuning-grid { grid-template-columns: 1fr; }
  .card.span-2 { grid-column: span 1; }
  .inline-form { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
}
