:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #312e81;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.16);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* Login Screen */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1e1b4b, #0f172a 60%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 18px;
}
.login-brand h1 { font-size: 19px; font-weight: 700; }
.login-brand p { font-size: 12px; color: var(--text-muted); }
.login-hint {
  margin-top: 16px; padding: 10px 12px; background: var(--surface-subtle);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-muted);
}

/* Main App Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--sidebar-bg); color: #e2e8f0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-header {
  padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 11px;
}
.sidebar-title { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.25; }
.sidebar-sub { font-size: 11px; color: #94a3b8; }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #64748b; padding: 12px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: none; background: transparent; color: #cbd5e1;
  border-radius: 8px; cursor: pointer; font-size: 13.5px; text-align: left;
  transition: background 0.15s, color 0.15s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 14px; }
.sidebar-footer {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: space-between; font-size: 12.5px;
}

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content { padding: 22px 24px 48px; max-width: 1600px; width: 100%; }

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.card-title { font-size: 15px; font-weight: 700; }
.card-body { padding: 18px; }
.two-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
@media (max-width: 1024px) { .two-col { grid-template-columns: 1fr; } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-subtle); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-danger { background: var(--red-soft); border-color: #fecaca; color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-subtle); color: var(--text); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-xs { padding: 3px 7px; font-size: 11.5px; }

/* Inputs & Forms */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin-bottom: 5px; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.input, .select, .textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text); background: var(--surface); outline: none; transition: border-color 0.15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.12); }
.textarea { font-family: var(--mono); font-size: 12.5px; min-height: 110px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Filters & Tabs */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-subtle); }
.tabs { display: inline-flex; background: #e2e8f0; padding: 3px; border-radius: 8px; gap: 2px; }
.tab-btn {
  border: none; background: transparent; padding: 5px 12px; border-radius: 6px;
  font-size: 12.5px; font-weight: 600; color: #475569; cursor: pointer;
}
.tab-btn.active { background: #fff; color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; font-weight: 700; color: var(--text-muted);
  background: var(--surface-subtle); padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 13px; }
tr:hover td { background: #fafbff; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }

/* Badges & Pills */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); border: 1px solid #a7f3d0; }
.badge-amber { background: var(--amber-soft); color: var(--amber); border: 1px solid #fde68a; }
.badge-red { background: var(--red-soft); color: var(--red); border: 1px solid #fecaca; }
.badge-blue { background: var(--blue-soft); color: var(--blue); border: 1px solid #bfdbfe; }
.badge-indigo { background: var(--primary-soft); color: var(--primary); border: 1px solid #c7d2fe; }
.badge-gray { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

.fraud-pills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.score-chip {
  font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #f1f5f9; color: #334155;
  font-family: var(--mono); border: 1px solid #e2e8f0;
}
.score-chip.low { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.score-chip.mid { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.score-chip.high { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

/* Progress Bar */
.progress { height: 6px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-top: 4px; width: 110px; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.25s; }
.progress-bar.warn { background: var(--amber); }
.progress-bar.danger { background: var(--red); }

/* Code Box */
.code-box {
  background: #0f172a; color: #e2e8f0; font-family: var(--mono); font-size: 12px;
  padding: 14px; border-radius: 8px; overflow: auto; max-height: 440px;
  white-space: pre; line-height: 1.55;
}

/* Modal & Slide-over Drawer */
.backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-lg { max-width: 720px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-subtle); }

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.42); z-index: 100;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: 100%; max-width: 560px; background: var(--surface); height: 100vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kv-item { background: var(--surface-subtle); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.kv-k { font-size: 11.5px; color: var(--text-muted); }
.kv-v { font-size: 13.5px; font-weight: 600; margin-top: 2px; word-break: break-all; }

/* Toast */
.toast-container { position: fixed; top: 18px; right: 18px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 16px; border-radius: 8px; color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg); min-width: 220px; max-width: 420px;
}
.toast.ok { background: #059669; }
.toast.err { background: #dc2626; }
.toast.info { background: #1e293b; }

/* Customer Portal Specific */
.portal-wrap { max-width: 1120px; margin: 0 auto; padding: 28px 20px 60px; }
.portal-hero {
  background: linear-gradient(135deg, #1e1b4b, #312e81 55%, #0f172a);
  color: #fff; border-radius: 16px; padding: 28px 30px; margin-bottom: 24px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 20px;
}
.portal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.portal-node-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
