:root {
  /* Same PowerPanne / ModuloTech palette as the main Disbatch app (app/src/statics/css/style.css) */
  --brand: #F97316;
  --brand-dark: #EA6C0A;
  --bg: #0C0E13;
  --bg-card: #141720;
  --bg-input: #0C0E13;
  --border: #252A36;
  --border-focus: #F97316;
  --text: #F0F2F7;
  --text-dim: #8A91A8;
  --text-muted: #6B7186;
  --accent: #F97316;
  --green: #34D399;
  --red: #F87171;
  --amber: #FBBF24;
  --radius: 8px;
  --radius-sm: 4px;
  --font: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  padding: 1.5rem 2rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  border-left: 3px solid var(--brand); /* orange accent stripe, as in the main app header */
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0 0 .3rem;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -.5px;
}

.nav {
  display: flex;
  align-items: center;
  gap: .4rem;
}

.btn-small {
  padding: .3rem .65rem;
  font-size: .74rem;
  font-family: var(--font-mono);
}

.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: .82rem;
  font-weight: 500;
  padding: .35rem .8rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.nav-link:hover { color: var(--brand); border-color: var(--brand); background: rgba(249, 115, 22, .06); }

.nav-link.is-active {
  color: var(--brand);
  background: rgba(249, 115, 22, .08);
  border-color: var(--brand);
}

.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: .85rem;
}

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
}

.panel-header h2 {
  margin: 0 0 .9rem;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
}

.panel-hint {
  margin: -.5rem 0 1rem;
  font-size: .78rem;
  color: var(--text-muted);
}

.field-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.field-row label {
  font-size: .78rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.field-label {
  display: block;
  font-size: .78rem;
  color: var(--text-dim);
  margin-bottom: .4rem;
}

select, textarea, input[type="date"], input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .82rem;
  padding: .45rem .6rem;
  outline: none;
}

select { flex: 0 0 auto; min-width: 220px; }
input[type="date"] { flex: 0 0 auto; color-scheme: dark; }
input[type="number"] { flex: 0 0 auto; width: 160px; color-scheme: dark; }

textarea {
  width: 100%;
  resize: vertical;
  font-size: .76rem;
  line-height: 1.5;
}

select:focus, textarea:focus, input[type="date"]:focus, input[type="number"]:focus { border-color: var(--border-focus); }

.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .45rem 1rem;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: filter .15s;
}

.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-secondary { background: var(--bg-input); color: var(--text); }

.actions {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: .9rem;
}

.status-text {
  font-size: .8rem;
  color: var(--text-dim);
}

.status-text[data-kind="error"] { color: var(--red); }
.status-text[data-kind="success"] { color: var(--green); }

.empty-panel {
  color: var(--text-muted);
  text-align: center;
  padding: 3rem 1.5rem;
  font-size: .88rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem;
  margin-bottom: 1.1rem;
}

.summary-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .75rem;
}

.summary-item .label {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .2rem;
}

.summary-item .value {
  font-size: .92rem;
  font-family: var(--font-mono);
  color: var(--text);
}

.notice {
  border-radius: var(--radius-sm);
  padding: .6rem .8rem;
  font-size: .8rem;
  margin-bottom: .9rem;
  border: 1px solid;
}

.notice--warn {
  background: rgba(251, 191, 36, .1);
  border-color: rgba(251, 191, 36, .35);
  color: var(--amber);
}

.notice--info {
  background: rgba(249, 115, 22, .1);
  border-color: rgba(249, 115, 22, .35);
  color: var(--accent);
}

.candidates-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

.candidates-table th {
  text-align: left;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border);
}

.candidates-table td {
  padding: .55rem .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.candidates-table tr.is-decision {
  background: rgba(52, 211, 153, .08);
}

.candidates-table tr.is-skipped {
  opacity: .65;
}

.badge {
  display: inline-block;
  font-size: .68rem;
  font-weight: 600;
  padding: .12rem .5rem;
  border-radius: 99px;
  margin-left: .4rem;
}

.badge--decision { background: rgba(52, 211, 153, .18); color: var(--green); }
.badge--skipped { background: rgba(251, 191, 36, .18); color: var(--amber); }

.driver-name { font-weight: 500; }
.driver-id { color: var(--text-muted); font-family: var(--font-mono); font-size: .74rem; }
.note-text { color: var(--text-dim); font-size: .76rem; }

@media (max-width: 640px) {
  .shell { padding: 1rem; }
  select { min-width: 0; flex: 1 1 100%; }
}

/* ── History page: filters, breakdown, pager, detail rows ─────────────── */
.filters { display: flex; flex-wrap: wrap; gap: .7rem 1rem; align-items: flex-end; margin-bottom: 1rem; }
.filter { display: flex; flex-direction: column; gap: .25rem; font-size: .72rem; color: var(--text-dim); }
.filter select, .filter input { min-width: 0; width: 100%; }
.filter select { min-width: 130px; }
.filter input[type="text"], .filter input[type="number"], .filter input[type="date"] { width: 150px; }
.filters input[type="text"] {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--font-mono); font-size: .82rem; padding: .45rem .6rem; outline: none;
}
.filters input[type="text"]:focus { border-color: var(--border-focus); }
.breakdown-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.breakdown-head h2 { margin: 0; font-size: .95rem; font-weight: 600; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.pager { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-top: .9rem; font-size: .8rem; color: var(--text-dim); flex-wrap: wrap; }
.pager-controls { display: flex; align-items: flex-end; gap: .6rem; }
.history-row { cursor: pointer; }
.history-row:hover { background: rgba(249, 115, 22, .06); }
.detail-row > td { background: var(--bg-input); padding: .9rem 1rem; }
.candidates-table.nested { margin: .4rem 0 .8rem; }
.row-decision td { background: rgba(52, 211, 153, .08); }
.row-human td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.json-view {
  max-height: 360px; overflow: auto; margin: .6rem 0 0; padding: .7rem .8rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: .72rem;
}

/* ── login / user admin ─────────────────────────────────────────────────── */
.nav-user { color: var(--text-dim); font-size: .8rem; margin: 0 .4rem; }
.auth-form { display: flex; flex-direction: column; gap: .8rem; max-width: 420px; }
.auth-form label { display: flex; flex-direction: column; gap: .25rem; color: var(--text-dim); font-size: .8rem; }
.auth-form input, .auth-form select {
  background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .5rem .6rem; font-size: .9rem;
}
.auth-form input:focus, .auth-form select:focus { outline: none; border-color: var(--border-focus); }
.auth-error { color: var(--red); min-height: 1.2em; margin: 0; font-size: .82rem; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--border); }
.users-table th { color: var(--text-muted); font-weight: 500; font-size: .75rem; }

/* ── Polish: buttons, inputs, panels, tables ────────────────────────────── */
:root { --shadow: 0 4px 24px rgba(0, 0, 0, .35); --ring: 0 0 0 3px rgba(249, 115, 22, .22); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-family: var(--font); font-weight: 600; letter-spacing: .01em;
  padding: .55rem 1.15rem; border-radius: var(--radius);
  transition: background .15s, border-color .15s, color .15s, transform .08s, box-shadow .15s;
}
.btn:hover { filter: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-dark));
  border-color: var(--brand-dark); color: #fff;
  box-shadow: 0 2px 10px rgba(249, 115, 22, .28);
}
.btn-primary:hover:not(:disabled) { background: var(--brand); box-shadow: 0 4px 16px rgba(249, 115, 22, .4); }
.btn-secondary { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { color: var(--brand); border-color: var(--brand); background: rgba(249, 115, 22, .06); }
.btn-small { padding: .28rem .7rem; font-size: .75rem; font-family: var(--font); font-weight: 500; border-radius: var(--radius-sm); }
.btn:disabled { opacity: .45; }

select, textarea, input[type="date"], input[type="number"], .filters input[type="text"],
.auth-form input, .auth-form select {
  border-radius: var(--radius); transition: border-color .15s, box-shadow .15s;
}
select:hover, input:hover, textarea:hover { border-color: #3a4152; }
select:focus, textarea:focus, input:focus { border-color: var(--border-focus); box-shadow: var(--ring); outline: none; }
select { appearance: none; padding-right: 1.9rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238A91A8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; }

.panel { box-shadow: var(--shadow); padding: 1.4rem 1.6rem; }
.panel-header h2 { font-size: 1rem; font-weight: 700; letter-spacing: -.2px; }
.summary-item { border-radius: var(--radius); transition: border-color .15s; }
.summary-item:hover { border-color: #3a4152; }

.candidates-table th, .users-table th { position: sticky; top: 0; background: var(--bg-card); }
.candidates-table tbody tr, .users-table tbody tr { transition: background .12s; }
.candidates-table tbody tr:hover:not(.is-decision):not(.detail-row), .users-table tbody tr:hover { background: rgba(255, 255, 255, .025); }
.candidates-table tr:last-child td { border-bottom: none; }
.badge { letter-spacing: .02em; }
.notice { border-radius: var(--radius); }
.nav-link { transition: color .15s, border-color .15s, background .15s; }
.link { font-weight: 500; }
.link:hover { text-decoration: none; color: var(--brand-dark); }
::selection { background: rgba(249, 115, 22, .35); }

/* ── LLM step ───────────────────────────────────────────────────────────── */
.llm-panel { padding-top: 1rem; padding-bottom: .4rem; }
.panel-hint-inline { color: var(--text-muted); font-size: .76rem; }
.llm-result { margin-top: 1.4rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.llm-result h3 { margin: 0 0 .6rem; font-size: .92rem; font-weight: 700; }
.llm-meta { color: var(--text-muted); font-size: .72rem; font-weight: 500; margin-left: .5rem; font-family: var(--font-mono); }
.llm-summary { margin: .4rem 0 .8rem; line-height: 1.55; }
.llm-scores { margin: 0; padding-left: 1.1rem; color: var(--text-dim); font-size: .8rem; line-height: 1.6; }

/* ── History: decision popup (explanation left, vehicle right) ──────────── */
.history-row { outline-offset: -2px; }
.history-row:focus-visible { outline: 2px solid var(--brand); }
.decision-popup {
  position: fixed; z-index: 50; display: flex; gap: 0; width: min(760px, calc(100vw - 16px)); max-height: calc(100vh - 16px);
  overflow: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .55); pointer-events: none; font-size: .8rem; line-height: 1.5;
}
.decision-popup[hidden] { display: none; }
.popup-col { padding: .9rem 1.1rem; }
.popup-explain { flex: 1.5 1 0; min-width: 0; }
.popup-vehicle { flex: 1 1 0; min-width: 0; border-left: 1px solid var(--border); background: rgba(255, 255, 255, .02); }
.decision-popup h4 { margin: 0 0 .15rem; font-size: .92rem; font-weight: 700; }
.decision-popup h5 { margin: .7rem 0 .2rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.decision-popup ul { margin: .15rem 0; padding-left: 1.05rem; color: var(--text-dim); }
.decision-popup li { margin: .12rem 0; }
.popup-sub { margin: 0 0 .3rem; color: var(--text-dim); }
.popup-meta { margin-top: .8rem; }
.effect { font-family: var(--font-mono); font-size: .72rem; }
.effect--up { color: var(--green); }
.effect--down { color: var(--red); }
.badge--human { background: rgba(249, 115, 22, .18); color: var(--brand); }
.vehicle-info { display: grid; grid-template-columns: auto 1fr; gap: .15rem .8rem; margin: .4rem 0 0; }
.vehicle-info dt { color: var(--text-muted); }
.vehicle-info dd { margin: 0; color: var(--text); word-break: break-word; }
@media (max-width: 760px) {
  .decision-popup { flex-direction: column; }
  .popup-vehicle { border-left: 0; border-top: 1px solid var(--border); }
}
.artefact-tag { margin-left: .35rem; padding: .02rem .4rem; border-radius: 99px; font-size: .65rem; color: var(--amber); background: rgba(251, 191, 36, .14); border: 1px solid rgba(251, 191, 36, .35); }
.popup-warn { color: var(--amber); }

/* LLM analysis (popup + expanded row) */
.popup-headline { font-weight: 600; margin: .2rem 0; }
.badge--conf-high { background: var(--success-bg, rgba(34,197,94,.15)); color: var(--success, #16a34a); }
.badge--conf-medium { background: rgba(234,179,8,.15); color: #ca8a04; }
.badge--conf-low { background: rgba(239,68,68,.15); color: #dc2626; }
.rating { font-size: .7rem; padding: .05rem .4rem; border-radius: 999px; border: 1px solid var(--border); text-transform: uppercase; letter-spacing: .03em; }
.rating--excellent { color: #16a34a; border-color: #16a34a; }
.rating--good { color: #65a30d; border-color: #65a30d; }
.rating--fair { color: #ca8a04; border-color: #ca8a04; }
.rating--poor { color: #dc2626; border-color: #dc2626; }
.llm-analysis { display: grid; gap: .6rem; margin: .6rem 0; }
.llm-card { border: 1px solid var(--border); border-radius: 8px; padding: .65rem .85rem; background: var(--surface, transparent); }
.llm-card p, .llm-card ul { margin: .25rem 0; }
.llm-card--decision { border-left: 4px solid var(--accent, #2563eb); }
.llm-card--warn { border-left: 4px solid #ca8a04; }
.llm-card-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: .3rem; }
.llm-headline { font-weight: 600; }
.factor { padding: .3rem 0; border-top: 1px solid var(--border); }
.factor:first-of-type { border-top: 0; }
.factor--primary { border-left: 3px solid var(--accent, #2563eb); padding-left: .5rem; }
.factor--minor { opacity: .8; }
.breakdown-sub td { background: var(--surface-2, rgba(127,127,127,.06)); }
.sub-label { padding-left: 2.2rem !important; }
.day-toggle { padding: 0 .4rem; }
