:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --line: #dce6f2;
  --line-strong: #c2d4ea;
  --text: #172437;
  --muted: #526378;
  --brand: #185fa5;
  --brand-hover: #134e89;
  --brand-soft: #edf4fb;
  --ok-bg: #ecfdf5;
  --ok-fg: #047857;
  --ok-border: #a7f3d0;
  --danger-bg: #fef2f2;
  --danger-fg: #b91c1c;
  --danger-border: #fecaca;
  --warn-bg: #fffbeb;
  --warn-fg: #b45309;
  --warn-border: #fde68a;
  --radius: 14px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 262px;
  flex: 0 0 262px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--line);
}
.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #185fa5, #2563eb);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-name { font-size: 15.5px; font-weight: 700; color: var(--text); }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.nav-section-label {
  font-size: 11.5px;
  font-weight: 600;
  color: #7c8da3;
  padding: 10px 10px 4px;
  letter-spacing: 0.02em;
}
.nav-list { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav-item {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 9px 11px;
  font: 550 13.5px/1.3 var(--font);
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-item:hover { background: var(--surface-soft); color: var(--text); }
.nav-item.active {
  background: var(--brand-soft);
  border-color: #cde0f5;
  color: var(--brand);
  font-weight: 650;
}
.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #c5d4e6;
  flex-shrink: 0;
}
.nav-item.active .nav-dot { background: var(--brand); }
.nav-tag {
  margin-left: auto;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef3f9;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-item.active .nav-tag { background: #d8e9fa; color: var(--brand); }

.sidebar-footer { padding-top: 8px; border-top: 1px solid var(--line); }
.status-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.status-meta { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pill-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  background: var(--ok-bg);
  color: var(--ok-fg);
}
.pill-status.warn { background: var(--warn-bg); color: var(--warn-fg); }
.pill-status.danger { background: var(--danger-bg); color: var(--danger-fg); }

.main-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title h1 { margin: 0 0 2px; font-size: 18px; font-weight: 700; }
.topbar-title p { margin: 0; font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.content-area {
  padding: 16px 18px 32px;
  max-width: none;
  width: 100%;
  margin: 0;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 9px;
  padding: 7px 13px;
  font: 600 13px/1.25 var(--font);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover { background: var(--brand-soft); border-color: #b7d0eb; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.ok { background: var(--ok-fg); border-color: var(--ok-fg); color: #fff; }
.btn.danger { background: #fff; border-color: var(--danger-border); color: var(--danger-fg); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

.btn-icon {
  appearance: none;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 4px 16px rgba(23, 36, 55, 0.03);
}
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-header h2, .card-header h3 { margin: 0; font-size: 15.5px; font-weight: 700; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 550; }
.kpi-value { font-size: 28px; font-weight: 750; color: var(--brand); line-height: 1.15; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.85fr); gap: 16px; }
.grid-equal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.split-layout { display: grid; grid-template-columns: 390px minmax(0, 1fr); gap: 18px; align-items: start; }

@media (max-width: 1100px) {
  .split-layout, .grid-2, .grid-equal { grid-template-columns: 1fr; }
  .sidebar { width: 210px; flex-basis: 210px; }
}

.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  background: #e9f0f8;
  padding: 4px;
  border-radius: 11px;
  gap: 4px;
  margin-bottom: 16px;
}
.tab-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 7px 14px;
  border-radius: 8px;
  font: 600 13px/1.3 var(--font);
  color: var(--muted);
  cursor: pointer;
}
.tab-btn.active {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 2px 6px rgba(23, 36, 55, 0.08);
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 11px; }
.form-row.full { grid-column: 1 / -1; }
.form-row label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 10px;
  font: 13px/1.45 var(--font);
  color: var(--text);
  background: #fff;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(24, 95, 165, 0.12);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid var(--ok-border); }
.badge.danger { background: var(--danger-bg); color: var(--danger-fg); border: 1px solid var(--danger-border); }
.badge.brand { background: var(--brand-soft); color: var(--brand); border: 1px solid #c9dff5; }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-border); }

.decision-banner {
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.decision-banner.ok { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-fg); }
.decision-banner.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-fg); }
.decision-banner.danger { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-fg); }
.decision-verdict { font-size: 20px; font-weight: 800; }

.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th,
table.data-table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
table.data-table th {
  background: var(--surface-soft);
  color: var(--brand);
  font-weight: 650;
  white-space: nowrap;
}
table.data-table tr:hover td { background: #fafcff; }
.cell-nowrap { white-space: nowrap; }
.table-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; white-space: nowrap; }

.report-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 14px;
  background: #fff;
}
.report-section h4 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--brand);
  border-bottom: 1px solid #edf2f8;
  padding-bottom: 6px;
}
.report-kv {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 8px 14px;
  font-size: 13px;
  margin-top: 8px;
}
.report-kv .k { font-weight: 650; color: var(--muted); }

.chart-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  padding: 12px 14px;
  margin-top: 10px;
}
.chart-title { font-size: 13px; font-weight: 650; color: var(--text); margin-bottom: 8px; }
.chart-box svg { width: 100%; height: auto; display: block; }

.graph-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.graph-canvas-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: radial-gradient(circle at 1px 1px, #d9e4f2 1px, transparent 0) 0 0 / 22px 22px #fbfdff;
  height: 520px;
  overflow: hidden;
  user-select: none;
}
.graph-canvas-wrap svg { width: 100%; height: 100%; cursor: grab; }
.graph-canvas-wrap svg:active { cursor: grabbing; }
.graph-zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  padding: 5px;
  border-radius: 9px;
  border: 1px solid var(--line);
}

.upload-zone {
  border: 1.5px dashed #9ec2e8;
  background: var(--surface-soft);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover { border-color: var(--brand); background: var(--brand-soft); }

.history-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.history-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fff;
}
.history-item:hover { border-color: #9ec2e8; }
.history-item.active { border-color: var(--brand); background: var(--brand-soft); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal-dialog {
  width: min(760px, 100%);
  max-height: 88vh;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-dialog.wide {
  width: min(1060px, 94vw);
  height: 88vh;
}
.modal-dialog.wide .modal-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.pdf-preview-frame {
  width: 100%;
  flex: 1;
  min-height: 540px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f1f5f9;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: radial-gradient(circle at 20% 20%, #e0edff 0%, #f4f7fb 45%, #e8effa 100%);
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-screen[hidden] { display: none; }
.login-card {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 26px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.login-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}
.login-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.badge.agent {
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
}
.artifact-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  margin-bottom: 12px;
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: #172437;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
}
.toast.ok { background: #047857; }
.toast.danger { background: #b91c1c; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.flex-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spacer { flex: 1; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .content-area { padding: 0; max-width: none; }
  .split-layout { grid-template-columns: 1fr; }
  .card, .report-section { box-shadow: none; break-inside: avoid; }
}
