/* Tec Parquet control room — dense operator UI, light and dark.
 *
 * Layout intent: the bucket browser and the right-hand working column fill
 * the viewport, the log is a fixed-height tail at the bottom, and only the
 * scrollable regions (tree, tables, log) ever scroll. The page itself never
 * scrolls on a desktop, so the operator's tables stay put while data updates
 * stream in underneath them.
 */
:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --panel-head: #f6f7f9;
  --ink: #1b1f24;
  --ink-soft: #454c55;
  --muted: #6b7280;
  --line: #dde1e6;
  --accent: #b4181f;
  --accent-ink: #ffffff;
  --ok: #10703a;
  --ok-bg: #e4f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf0d8;
  --err: #b3261e;
  --err-bg: #fbe6e4;
  --run: #14539a;
  --run-bg: #e2edfb;
  --idle-bg: #ebeef2;
  --row-hover: #f3f6fa;
  --shadow: 0 1px 2px rgba(16, 20, 26, .06), 0 2px 8px rgba(16, 20, 26, .04);
  --mono: ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101317;
    --panel: #191d22;
    --panel-head: #20252b;
    --ink: #e7eaed;
    --ink-soft: #c2c8cf;
    --muted: #8d97a3;
    --line: #2d343c;
    --accent: #e0424a;
    --ok: #5ccb7f;
    --ok-bg: #12301f;
    --warn: #e0ad51;
    --warn-bg: #33270e;
    --err: #ff7b72;
    --err-bg: #3a1c1a;
    --run: #6fb0f5;
    --run-bg: #12283f;
    --idle-bg: #23282f;
    --row-hover: #20262d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 10px rgba(0, 0, 0, .22);
  }
}
:root[data-theme="dark"] {
  --bg: #101317; --panel: #191d22; --panel-head: #20252b; --ink: #e7eaed;
  --ink-soft: #c2c8cf; --muted: #8d97a3; --line: #2d343c; --accent: #e0424a;
  --ok: #5ccb7f; --ok-bg: #12301f; --warn: #e0ad51; --warn-bg: #33270e;
  --err: #ff7b72; --err-bg: #3a1c1a; --run: #6fb0f5; --run-bg: #12283f;
  --idle-bg: #23282f; --row-hover: #20262d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 13px/1.45 var(--sans);
  display: flex; flex-direction: column;
  /* Scroll only when the window is too short for the minimum layout below;
     at normal desktop heights nothing scrolls but the panels themselves. */
  overflow: auto;
}
h1, h2, h3 { font-weight: 600; }

/* ---------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
/* Source is 500x206, so even at 46px tall there are ~4.5 device pixels per
   CSS pixel -- it downscales cleanly and stays legible. */
.brand {
  height: 46px; width: auto; display: block;
  margin-right: 4px;
  image-rendering: -webkit-optimize-contrast;
}
/* The logo is dark ink on transparent, so it disappears against a dark
   header. Give it a light chip to sit on rather than recolouring the mark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand,
  :root:not([data-theme="light"]) .login-logo {
    background: #fff; padding: 5px 10px; border-radius: 7px;
  }
}
:root[data-theme="dark"] .brand,
:root[data-theme="dark"] .login-logo {
  background: #fff; padding: 5px 10px; border-radius: 7px;
}
.spacer { flex: 1 1 auto; }
.status-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill {
  padding: 4px 11px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); font-size: 12px; white-space: nowrap; color: var(--ink-soft);
}
.pill.dim { color: var(--muted); }
.pill.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); background: var(--ok-bg); }
.pill.dead { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); background: var(--err-bg); }

button {
  font: inherit; padding: 6px 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); border-radius: 6px; cursor: pointer;
  transition: background .12s, border-color .12s, filter .12s;
}
button:hover:not(:disabled) { background: var(--row-hover); }
button:active:not(:disabled) { transform: translateY(.5px); }
button:focus-visible { outline: 2px solid var(--run); outline-offset: 1px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--accent); }
button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
button.danger:hover:not(:disabled) { background: var(--err-bg); }
button.link {
  border: none; background: none; color: var(--run); padding: 2px 5px;
  border-radius: 4px; font-size: 12px;
}
button.link:hover { background: var(--run-bg); }
button.link.kill { color: var(--err); }
button.link.kill:hover { background: var(--err-bg); }

input, select {
  font: inherit; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel); color: var(--ink); min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--run); outline-offset: -1px; border-color: var(--run); }
input::placeholder { color: var(--muted); }

.banner {
  margin: 8px 14px 0; padding: 10px 13px; border-radius: var(--r);
  background: var(--err-bg); border: 1px solid color-mix(in srgb, var(--err) 40%, var(--line));
  color: var(--err); flex: 0 0 auto;
}

/* ---------------------------------------------------------- layout */
main {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: minmax(250px, 1fr) minmax(560px, 2.4fr);
  gap: 10px; padding: 10px 14px;
}
/* Below this the three right-hand panels cannot all fit, and the fixed-height
   log would sit on top of the machines table. Force the page to scroll
   instead of hiding a table the operator needs to see. */
@media (min-width: 1001px) {
  main { min-height: 540px; }
}
.right { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 7px 11px; background: var(--panel-head);
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.panel-head h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  margin: 0; color: var(--muted);
}
.panel-head h2 .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.panel-head .row { margin-left: auto; }
.panel-foot { padding: 9px 11px; border-top: 1px solid var(--line); flex: 0 0 auto; }
.panel-foot.actions { display: flex; gap: 7px; flex-wrap: wrap; }
.row { display: flex; gap: 6px; align-items: center; }
.muted { color: var(--muted); }
.pad { padding: 14px; }

/* the form sizes to its content; the two tables share what is left */
.job-form { flex: 0 0 auto; }
.queue { flex: 1 1 58%; min-height: 150px; }
.machines { flex: 1 1 42%; min-height: 128px; }

/* ---------------------------------------------------------- bucket tree */
.bucket { min-height: 200px; }
.bucket .panel-head .row { flex: 1 1 auto; justify-content: flex-end; }
.bucket .panel-head input { flex: 0 1 190px; }
.tree {
  overflow: auto; flex: 1 1 auto; padding: 5px 0;
  font-family: var(--mono); font-size: 12px;
}
.node {
  display: flex; align-items: center; gap: 5px; padding: 3px 12px; cursor: pointer;
  white-space: nowrap; border-left: 2px solid transparent;
}
.node:hover { background: var(--row-hover); }
.node.selected {
  background: var(--run-bg); border-left-color: var(--run); color: var(--run);
  font-weight: 600;
}
.node .twisty { width: 12px; color: var(--muted); flex: 0 0 auto; font-size: 10px; }
.node .name { overflow: hidden; text-overflow: ellipsis; }
.node .size { margin-left: auto; color: var(--muted); padding-left: 14px; font-size: 11px; }
.node.folder .name { color: var(--ink-soft); }

/* ---------------------------------------------------------- job form */
.form-grid {
  display: grid; grid-template-columns: 150px 1fr; gap: 9px 12px;
  padding: 12px; align-items: center;
}
.form-grid > label { color: var(--muted); font-size: 12px; }
.form-grid .row > input[type="text"] { flex: 1 1 auto; }
.form-grid > input[type="text"], .form-grid > select { width: 100%; }
.radios { flex-wrap: wrap; gap: 18px; }
.radio { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
#estimate { font-variant-numeric: tabular-nums; font-size: 12px; }

/* ---------------------------------------------------------- tables */
.table-wrap { overflow: auto; flex: 1 1 auto; min-height: 0; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12px; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--panel-head);
  text-align: left; font-weight: 600; padding: 7px 9px; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: nowrap;
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
}
tbody td {
  padding: 5px 9px; border-bottom: 1px solid var(--line); white-space: nowrap;
  color: var(--ink-soft);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }
td.jobid, td.mono { font-family: var(--mono); font-size: 11.5px; color: var(--ink); }
th.tick, td.tick { width: 30px; text-align: center; }
td.actions { text-align: right; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* state badges */
.state {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.state-queued { background: var(--idle-bg); color: var(--muted); }
.state-claimed { background: var(--warn-bg); color: var(--warn); }
.state-running { background: var(--run-bg); color: var(--run); }
.state-done { background: var(--ok-bg); color: var(--ok); }
.state-failed { background: var(--err-bg); color: var(--err); cursor: pointer; }
.state-failed:hover { filter: brightness(.96); text-decoration: underline; }

.bar {
  height: 5px; width: 70px; background: var(--idle-bg);
  border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle;
}
.bar > span { display: block; height: 100%; background: var(--run); transition: width .3s; }

.dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; vertical-align: baseline; background: var(--muted);
}
.dot.up { background: var(--ok); }
.dot.busy { background: var(--run); }
.dot.pending { background: var(--warn); }

/* ---------------------------------------------------------- log */
.log-panel { margin: 0 14px 10px; height: 180px; min-height: 120px; flex: 0 0 auto; }
#log {
  margin: 0; padding: 8px 11px; overflow: auto; flex: 1 1 auto;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; color: var(--ink-soft);
}

/* ---------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 13, 17, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 50; backdrop-filter: blur(2px);
}
/* [hidden] must beat the display:flex above, or the dialog shows on load. */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  width: min(920px, 100%); max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.modal-head, .modal-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 13px; font-family: var(--mono); }
.modal-head button { margin-left: auto; }
.modal-foot { border-top: 1px solid var(--line); }
#modal-body {
  margin: 0; padding: 14px; overflow: auto; flex: 1 1 auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}

/* ---------------------------------------------------------- login */
.login-body { display: flex; align-items: center; justify-content: center; overflow: auto; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 30px; width: min(370px, 92vw); display: flex; flex-direction: column;
  gap: 4px; box-shadow: var(--shadow);
}
.login-logo {
  height: 64px; width: auto; align-self: center; margin-bottom: 16px;
  image-rendering: -webkit-optimize-contrast;
}
.login-card h1 { font-size: 16px; margin: 0; text-align: center; }
.login-card p { margin: 2px 0 0; text-align: center; font-size: 12px; }
.login-card label { margin-top: 16px; color: var(--muted); font-size: 12px; }
.login-card button {
  margin-top: 16px; padding: 9px; background: var(--accent);
  border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.error { color: var(--err); margin-top: 10px; font-size: 12px; }

@media (max-width: 1000px) {
  body { overflow: auto; }
  main { grid-template-columns: 1fr; }
  .bucket { max-height: 260px; }
}

/* ---------------------------------------------------------- admin */
.admin-modal { width: min(760px, 100%); }
.admin-body { overflow: auto; flex: 1 1 auto; padding: 14px 16px; }
.admin-body h4 {
  margin: 18px 0 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted);
}
.admin-body h4:first-child { margin-top: 0; }
.admin-grid {
  display: grid; grid-template-columns: 170px 1fr; gap: 8px 12px;
  align-items: center; margin-top: 8px;
}
.admin-grid > label { color: var(--muted); font-size: 12px; }
.admin-grid .row { flex-wrap: wrap; }
.admin-grid input[type="password"] { flex: 1 1 220px; }
.admin-grid input[type="number"] { width: 110px; }
.small { font-size: 11.5px; }
.admin-body code {
  font-family: var(--mono); font-size: 11.5px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px;
}
.src {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--idle-bg); color: var(--muted); white-space: nowrap;
}
.src.admin { background: var(--run-bg); color: var(--run); }
.src.environment { background: var(--warn-bg); color: var(--warn); }
.src.unset { background: var(--err-bg); color: var(--err); }
.admin-status {
  margin: 0 0 4px; padding: 8px 11px; border-radius: 6px;
  background: var(--idle-bg); font-size: 12px;
}
.admin-status.ok { background: var(--ok-bg); color: var(--ok); }
.admin-status.bad { background: var(--err-bg); color: var(--err); }
.test-out {
  margin: 10px 0 0; padding: 9px 11px; border-radius: 6px; background: var(--bg);
  border: 1px solid var(--line); font-family: var(--mono); font-size: 11.5px;
  white-space: pre-wrap; word-break: break-word;
}
.modal-foot .spacer { flex: 1 1 auto; }
.banner button {
  margin-left: 10px; border-color: currentColor; color: inherit;
  background: transparent;
}

/* login: the password row is wrapped in a div so it can be hidden when the
   deployment has no password, which would otherwise break the column flow. */
#password-row { display: flex; flex-direction: column; }
/* display:flex would otherwise beat [hidden], the same way it did to
   the modal backdrop -- the box would show on a passwordless install. */
#password-row[hidden] { display: none; }
#password-row label { margin-top: 16px; }
.login-card input[type="file"] {
  padding: 8px; background: var(--bg); cursor: pointer;
}
.login-card .hint { margin-top: 8px; font-size: 11.5px; line-height: 1.5; }
.login-card code {
  font-family: var(--mono); font-size: 11px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 3px; padding: 0 3px;
}
