:root {
  --bg: #f1f5f9;
  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
  --accent: #4f46e5;
  --accent-2: #4338ca;
  --accent-soft: #eef2ff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --card: #ffffff;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --high: #ea580c;
  --high-soft: #fff7ed;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }

/* ---------------------------------------------------------------- layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.sidebar .brand { padding: 18px 16px; border-bottom: 1px solid #1e293b; }
.sidebar .brand .logo { font-size: 16px; font-weight: 700; color: #fff; display: flex; align-items: center; gap: 8px; }
.sidebar .brand .logo .mark {
  width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #6366f1, #4f46e5);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 15px; font-weight: 800;
}
.sidebar .brand .sub { font-size: 11px; color: #64748b; margin-top: 2px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.sidebar nav .nav-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #475569; padding: 10px 10px 4px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #cbd5e1; font-size: 13px; font-weight: 500; text-decoration: none; margin-bottom: 2px;
}
.sidebar nav a:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar nav a .ic { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .foot { padding: 12px 16px; border-top: 1px solid #1e293b; font-size: 10.5px; color: #64748b; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line); padding: 0 24px;
  height: 56px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { font-size: 13px; color: var(--muted); }
.topbar .crumb b { color: var(--ink); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 8px; }
.topbar .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.content { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------------------------------------------------------------- cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card .card-head h2 { margin: 0; font-size: 14px; }
.card .card-body { padding: 18px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-2 { grid-template-columns: 1fr; } }

.stat { padding: 16px 18px; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 13px;
  font-weight: 550; cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { background: #15803d; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; padding: 9px 12px; background: #f8fafc; border-bottom: 1px solid var(--line);
  font-weight: 600; color: #475569; font-size: 12px; white-space: nowrap;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
table.tbl tr:hover td { background: #fafbfc; }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl tr.row-danger td { background: var(--danger-soft); }
table.tbl tr.row-warn td { background: var(--warn-soft); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 650;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.low, .badge.OK, .badge.APPROVED, .badge.ACTIVE, .badge.COMPLETE, .badge.READY, .badge.BALANCED { background: var(--ok-soft); color: #15803d; border-color: #bbf7d0; }
.badge.medium, .badge.MEDIUM, .badge.UNDER_REVIEW, .badge.RESPONDED, .badge.SUCCESS { background: var(--warn-soft); color: #b45309; border-color: #fde68a; }
.badge.high, .badge.HIGH { background: var(--high-soft); color: #c2410c; border-color: #fed7aa; }
.badge.critical, .badge.CRITICAL { background: var(--danger-soft); color: #b91c1c; border-color: #fecaca; }
.badge.info, .badge.REVIEWED, .badge.RUNNING, .badge.PENDING { background: var(--info-soft); color: #0369a1; border-color: #bae6fd; }
.badge.neutral, .badge.OPEN, .badge.UPLOADED, .badge.FAILED, .badge.ERROR, .badge.REJECTED, .badge.NEEDS_MAPPING, .badge.PROCESSING, .badge.UNBALANCED { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.badge.MANUAL { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.badge.AUTO, .badge.CHANGED { background: #ecfeff; color: #0e7490; border-color: #a5f3fc; }
.badge.WP_READY { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }

/* stage pill list */
.stages { display: flex; gap: 6px; flex-wrap: wrap; }
.stage-pill { font-size: 12px; padding: 4px 11px; border-radius: 999px; background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.stage-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.stage-pill.done { background: var(--ok-soft); border-color: #bbf7d0; color: #15803d; }

/* ---------------------------------------------------------------- forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin-bottom: 5px; }
.field input, .field select, .field textarea, .form-input {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
  font-family: inherit; background: #fff; color: var(--ink); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus, .form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { min-height: 84px; resize: vertical; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* ---------------------------------------------------------------- progress */
.progress { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.progress.ok > div { background: var(--ok); }
.progress.warn > div { background: var(--warn); }

/* ---------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal { background: #fff; border-radius: 14px; max-width: 680px; width: 100%; box-shadow: 0 20px 50px rgba(15,23,42,.3); }
.modal .modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .modal-head h2 { margin: 0; font-size: 15px; }
.modal .modal-body { padding: 20px; }
.modal .modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal.wide { max-width: 900px; }

/* ---------------------------------------------------------------- toast */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(15,23,42,.3); max-width: 360px; display: flex; gap: 10px; align-items: flex-start;
  animation: slidein .18s ease;
}
.toast.ok { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.warn { background: #b45309; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- misc */
.dropzone {
  border: 2px dashed #cbd5e1; border-radius: var(--radius); padding: 34px; text-align: center;
  color: var(--muted); background: #fbfcfe; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone b { color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; flex-wrap: nowrap; }
.tabs button {
  border: none; background: none; padding: 10px 14px; font-size: 13px; font-weight: 550; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; font-family: inherit;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel { display: none; }
.panel.active { display: block; }
.panel > .pad { padding: 20px 2px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }

.spin {
  width: 18px; height: 18px; border: 2.5px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: rot .7s linear infinite; display: inline-block;
}
@keyframes rot { to { transform: rotate(360deg); } }

.alert { padding: 10px 14px; border-radius: 10px; font-size: 13px; border: 1px solid; margin-bottom: 14px; }
.alert.warn { background: var(--warn-soft); border-color: #fde68a; color: #92400e; }
.alert.ok { background: var(--ok-soft); border-color: #bbf7d0; color: #166534; }
.alert.error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.alert.info { background: var(--info-soft); border-color: #bae6fd; color: #075985; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 16px; width: 380px; max-width: 100%; padding: 34px 32px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.login-card .logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-card .brand-mark { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #4f46e5); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 20px; font-weight: 800; }
.login-card h1 { font-size: 19px; margin: 0; }
.login-card .sub { font-size: 12.5px; color: var(--muted); }
.login-card .foot { text-align: center; font-size: 11px; color: #94a3b8; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }

.detail-list { display: flex; flex-direction: column; gap: 0; }
.detail-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f1f5f9; }
.detail-row:last-child { border-bottom: none; }
.detail-row .k { width: 130px; flex-shrink: 0; color: var(--muted); font-size: 12.5px; }

.flex { display: flex; gap: 10px; align-items: center; }
.flex.wrap { flex-wrap: wrap; }
.flex.between { justify-content: space-between; }
.flex.col { flex-direction: column; align-items: stretch; }
.jobbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.mono-scroll { max-height: 340px; overflow: auto; font-size: 12.5px; }
.kv-scroll { max-height: 400px; overflow: auto; padding: 4px 0; }
.ai-panel { background: linear-gradient(135deg, #f5f3ff, #eef2ff); border: 1px solid #ddd6fe; border-radius: 12px; padding: 16px; }
