:root {
  --bg: #0f1419; --panel: #1a2029; --panel2: #222b36; --line: #2c3540;
  --text: #e6edf3; --muted: #8b98a5; --accent: #3b82f6; --accent2: #2563eb;
  --ok: #22c55e; --warn: #f59e0b; --err: #ef4444; --radius: 8px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); margin-top: 8px; min-height: 18px; font-size: 13px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 32px; width: 340px; display: flex; flex-direction: column; gap: 6px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.login-card input, input, select {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 9px 10px; font-size: 14px;
}
.login-card button {
  margin-top: 18px; background: var(--accent2); color: #fff; border: 1px solid var(--accent2);
  border-radius: 6px; padding: 10px; cursor: pointer; font-size: 14px;
}
.login-card button:hover { background: var(--accent); }

/* App shell */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { font-weight: 700; padding: 18px 20px; border-bottom: 1px solid var(--line); letter-spacing: .3px; }
#nav { flex: 1; padding: 10px 0; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: var(--muted);
  text-decoration: none; border-left: 3px solid transparent; cursor: pointer;
}
#nav a:hover { background: var(--panel2); color: var(--text); }
#nav a.active { color: var(--text); border-left-color: var(--accent); background: var(--panel2); }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid var(--line); font-size: 13px; }
.who { color: var(--muted); margin-bottom: 8px; }
.who b { color: var(--text); }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }

.content { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 0; font-size: 18px; }
.view { padding: 24px; overflow: auto; }

/* Cards / metrics */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card .n { font-size: 28px; font-weight: 700; }
.card .l { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; background: var(--panel2); }
tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
code.devid { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; white-space: nowrap; user-select: all; }

/* Buttons + badges */
.btn { background: var(--accent2); border: 1px solid var(--accent2); color: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.btn:hover { background: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.sm { padding: 4px 9px; font-size: 12px; margin-left: 6px; }
.btn.danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn.danger:hover { background: var(--err); color: #fff; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.err { color: var(--err); border-color: var(--err); }
.badge.info { color: var(--accent); border-color: var(--accent); }

/* Forms / toolbar */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.check-label { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.check-label input { margin: 0; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.metadata-upload {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.metadata-tools { margin-top: 12px; }
.metadata-tools textarea { min-height: 120px; }
.wide-label { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-size: 12px; color: var(--muted); }
textarea {
  width: 100%; min-height: 300px; resize: vertical; background: #10161d; border: 1px solid var(--line);
  color: var(--text); border-radius: 6px; padding: 10px; font: 13px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.section-title { margin: 24px 0 10px; font-size: 15px; }
.diag-workbench, .param-workbench, .inspection-workbench, .dtc-gap-workbench, .param-failure-workbench { display: flex; flex-direction: column; gap: 12px; }
.diag-toolbar { margin-bottom: 4px; }
.diag-toolbar input { min-width: min(420px, 100%); }
.diag-cards { margin-bottom: 0; }
.diag-cards .card .n { font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.diag-cards .card .l { font-size: 12px; }
.dtc-gap-cards, .param-failure-cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.diag-detail { display: flex; flex-direction: column; gap: 10px; }
.compact-toolbar { margin-bottom: 2px; }
.diag-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.diag-stat {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px;
}
.diag-stat span { display: block; color: var(--muted); font-size: 11px; }
.diag-stat b { display: block; margin-top: 2px; font-size: 13px; overflow-wrap: anywhere; }
.diag-match-strip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
.diag-notes {
  margin: 0; padding: 10px 10px 10px 28px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 6px; color: var(--text);
}
.diag-notes li { margin: 4px 0; }
.diag-group { margin-top: 10px; }
.diag-group-head { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.empty.compact { padding: 12px; text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; }
.inspection-cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ecu-identity { display: flex; flex-direction: column; gap: 2px; min-width: 150px; }
.ecu-identity b { font-size: 13px; }
.ecu-identity span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.stacked-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.inspection-detail { padding: 2px 0 6px; }
.inspection-split { display: grid; grid-template-columns: minmax(280px, 1.2fr) minmax(260px, .8fr); gap: 14px; align-items: start; }
@media (max-width: 980px) {
  .inspection-split { grid-template-columns: 1fr; }
}

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); max-width: 380px; }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }
.empty { color: var(--muted); padding: 24px; text-align: center; }
