/* Neobrutalism, per https://www.neobrutalism.dev.
   Tokens below are the project's own published values (read from
   src/styling/globals.css in ekmas/neobrutalism-components), not an
   approximation: 2px black borders, a 5px radius, and a hard 4px/4px
   shadow with no blur and no spread.

   The signature is the press: anything you can interact with sits on that
   shadow and, on hover, moves by exactly the shadow's offset while the
   shadow is removed -- so it looks like the element has been pushed down
   onto the page. That mechanic is the one bold thing here; everything else
   stays flat and quiet so it reads. */
:root {
  color-scheme: light;

  --ink: #000;
  --ground: hsl(214, 95%, 93%);
  --card: #fff;
  --main: hsl(217, 100%, 66%);

  /* neobrutalism's chart palette, used semantically rather than as
     decoration -- each of these means one thing in this app and nothing
     else. */
  --go: #05e17a;      /* CARLA pipeline, finished jobs */
  --warn: #facc00;    /* regular (summer2026) pipeline */
  --stop: #ff4d50;    /* destructive actions, errors */
  --live: #7a83ff;    /* a job that is currently running */

  --muted-ink: #5b5b5b;

  --radius: 5px;
  --bw: 2px;
  --sx: 4px;
  --sy: 4px;
  --shadow: var(--sx) var(--sy) 0 0 var(--ink);
  --shadow-sm: 2px 2px 0 0 var(--ink);

  --font-sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Machine data -- frame counts, epoch timestamps, job ids,
     steering/throttle -- keeps a monospace face with tabular numerals.
     That is a property of the content, not of the theme. */
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Without this, any element that also gets an explicit `display` rule below
   (e.g. .modal's `display: flex`) would win the cascade over the browser's
   default `[hidden] { display: none }` at equal specificity, since this
   stylesheet loads after the UA one -- making `hidden` a no-op on it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 500;
  background: var(--ground);
  color: var(--ink);
}

h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.muted { color: var(--muted-ink); font-size: 0.9em; }
.error { color: var(--ink); background: var(--stop); font-size: 0.9em;
         border: var(--bw) solid var(--ink); border-radius: var(--radius);
         padding: 6px 10px; font-weight: 700; }
.success { color: var(--ink); background: var(--go); font-size: 0.9em;
           border: var(--bw) solid var(--ink); border-radius: var(--radius);
           padding: 6px 10px; font-weight: 700; }

/* Black-on-black would disappear against the borders, so the focus ring is
   the one place the accent colour is used purely as signal. */
:focus-visible {
  outline: 3px solid var(--main);
  outline-offset: 2px;
}

button {
  background: var(--main);
  color: var(--ink);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.95em;
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease, background-color 80ms ease;
}
button:hover { transform: translate(var(--sx), var(--sy)); box-shadow: none; }
button:active { transform: translate(var(--sx), var(--sy)); box-shadow: none; }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow);
}
button.ghost { background: var(--card); font-weight: 700; }
button.ghost:hover { background: var(--card); }
button.danger { background: var(--stop); }
button.danger:hover { background: var(--stop); }

input, select {
  background: var(--card);
  border: var(--bw) solid var(--ink);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 7px 9px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.95em;
}
input[type="checkbox"], input[type="range"] { accent-color: var(--main); }
input[type="checkbox"] { width: 16px; height: 16px; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85em;
  font-weight: 700;
  color: var(--ink);
}
label.inline {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.screen { min-height: 100vh; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--ground);
}
.login-card {
  background: var(--card);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 8px 8px 0 0 var(--ink);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.kicker {
  font-family: var(--font-mono);
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--ink);
  background: var(--warn);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  padding: 3px 8px;
  align-self: flex-start;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.5em; }
.login-card input { font-family: var(--font-mono); }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: var(--bw) solid var(--ink);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; }
.brand-mark {
  width: 14px;
  height: 14px;
  background: var(--main);
  border: var(--bw) solid var(--ink);
  flex: none;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
#whoami { color: var(--ink); font-size: 0.88em; font-weight: 700; }

.layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}
#datasets-panel { grid-column: 1 / -1; }

.panel {
  background: var(--card);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-header h2 { margin: 0; font-size: 1.05em; }
.panel-actions { display: flex; align-items: center; gap: 10px; }

.datasets-panel-body {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 20px;
  align-items: start;
}
.datasets-main { min-width: 0; }

.groups-sidebar {
  border-left: var(--bw) solid var(--ink);
  padding-left: 18px;
}
.groups-sidebar h3 { margin: 0 0 6px; font-size: 0.95em; }
.groups-sidebar > p.muted { margin: 0 0 10px; font-size: 0.82em; line-height: 1.4; }

.groups-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.group-item {
  background: var(--card);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease, background-color 80ms ease;
}
.group-item:hover { transform: translate(2px, 2px); box-shadow: none; }
/* The selected group keeps its shadow and takes the accent, so "selected"
   and "hovered" never look like the same state. */
.group-item.active { background: var(--main); box-shadow: var(--shadow-sm); transform: none; }
.group-item-top { display: flex; align-items: center; gap: 6px; }
.group-name-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: var(--bw) solid transparent;
  padding: 2px 4px;
  font-weight: 700;
  font-size: 0.95em;
  border-radius: var(--radius);
  box-shadow: none;
}
.group-name-input:hover, .group-name-input:focus { border-color: var(--ink); background: var(--card); }
.group-delete {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink);
  padding: 2px 6px;
  font-size: 1em;
  line-height: 1;
  flex: none;
}
.group-delete:hover {
  background: var(--stop);
  border-color: var(--ink);
  transform: none;
  box-shadow: none;
}
.group-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  gap: 8px;
}
.group-count { font-size: 0.78em; }
.group-update {
  padding: 3px 8px;
  font-size: 0.78em;
  box-shadow: var(--shadow-sm);
}
.group-update:hover { transform: translate(2px, 2px); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: var(--bw) solid var(--ink);
  font-size: 0.92em;
}
.table th {
  color: var(--ink);
  font-weight: 800;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom-width: var(--bw);
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--ground); }
.table td.actions { display: flex; gap: 8px; justify-content: flex-end; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}
#train-form details { margin: 6px 0 12px; }
#train-form summary { font-weight: 700; cursor: pointer; margin-bottom: 8px; }

.config-fieldset {
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  margin: 0 0 12px;
  padding: 12px 14px 14px;
}
.config-fieldset legend {
  padding: 2px 8px;
  font-size: 0.78em;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--warn);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
}
.config-fieldset > p.muted { margin: 0 0 10px; font-size: 0.82em; }
.config-fieldset .form-grid { margin-bottom: 0; }
#train-adv-reset { margin-bottom: 12px; }

.config-details { margin: 4px 0 12px; }
.config-json {
  margin: 8px 0 0;
  padding: 12px;
  background: var(--ground);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  font-size: 0.8em;
  line-height: 1.5;
  max-height: 320px;
  overflow: auto;
}
#train-config-status { margin: 8px 0 0; }

.job-card {
  background: var(--card);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.job-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.job-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.75em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 9px 3px 7px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--ink);
  background: var(--card);
  color: var(--ink);
}
.job-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border: 1px solid var(--ink);
  background: var(--card);
}
.job-status.running { background: var(--live); }
.job-status.running::before { background: var(--ink); }
.job-status.queued { background: var(--card); }
.job-status.finished { background: var(--go); }
.job-status.finished::before { background: var(--ink); }
.job-status.stopping, .job-status.cancelled { background: var(--stop); }
.job-card .muted.mono { display: block; margin-top: 2px; }
.job-progress-bar {
  height: 12px;
  border-radius: var(--radius);
  background: var(--card);
  border: var(--bw) solid var(--ink);
  margin-top: 8px;
  overflow: hidden;
}
.job-progress-fill {
  height: 100%;
  background: var(--main);
  border-right: var(--bw) solid var(--ink);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.modal-card {
  background: var(--card);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 8px 8px 0 0 var(--ink);
  width: 100%;
  max-width: 720px;
  padding: 18px 20px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-header h3 { margin: 0; }

.player-frame-wrap {
  background: #000;
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 12px;
}
.player-frame-wrap img { max-width: 100%; max-height: 100%; display: block; }
.player-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.player-controls input[type="range"] { flex: 1; }
.control-readout { margin-top: 8px; }

/* A real trim-range readout, not just text: the tick is the current frame,
   the banded region is what "Trim dataset" will keep. */
.trim-timeline {
  position: relative;
  height: 14px;
  margin-top: 6px;
  border-radius: var(--radius);
  background: var(--card);
  border: var(--bw) solid var(--ink);
  overflow: hidden;
}
.trim-timeline-kept {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--go);
  border-left: var(--bw) solid var(--ink);
  border-right: var(--bw) solid var(--ink);
}
.trim-timeline-playhead {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  background: var(--ink);
  transform: translateX(-1px);
}

.trim-bar {
  margin-top: 14px;
  padding-top: 12px;
  border-top: var(--bw) solid var(--ink);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.trim-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#trim-summary { flex: 1; min-width: 160px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .datasets-panel-body { grid-template-columns: 1fr; }
  .groups-sidebar { border-left: none; padding-left: 0; border-top: var(--bw) solid var(--ink); padding-top: 14px; }
}

/* Which training pipeline this session is driving. Deliberately prominent:
   the two pipelines read different dataset roots and publish to different
   models directories, so queueing a run against the wrong one wastes a GPU
   slot and files the result somewhere nobody is looking for it. */
.profile-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius);
  border: var(--bw) solid var(--ink);
  color: var(--ink);
}
.profile-badge[data-profile="carla"] { background: var(--go); }
.profile-badge[data-profile="regular"] { background: var(--warn); }

/* The press is a response to your pointer, so it stays. What goes is the
   easing -- under reduced motion the element simply is pressed, with no
   travel to watch. */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
