/* Autonomous Engineering console.
   Dense, fast, monochrome-first. Colour carries state, never decoration. */

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f1f1f3;
  --surface-3: #e8e8ec;
  --line: #dcdce2;
  --line-strong: #c3c3cc;
  --text: #16161a;
  --text-2: #55555f;
  --text-3: #85858f;
  --accent: #2f5fe0;
  --ok: #157f4a;
  --warn: #9a6400;
  --err: #b3261e;
  --crit: #7c1d17;
  --info: #4b4b8f;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  --r: 6px;
  --rail-w: 208px;
}

:root[data-theme="dark"] {
  --bg: #0d0d10;
  --surface: #141419;
  --surface-2: #1b1b22;
  --surface-3: #23232c;
  --line: #2a2a33;
  --line-strong: #3a3a46;
  --text: #ececf0;
  --text-2: #a4a4b0;
  --text-3: #70707d;
  --accent: #6d92ff;
  --ok: #3fbd7a;
  --warn: #e0a33c;
  --err: #ff6b60;
  --crit: #ff8a80;
  --info: #9a9aff;
}

* { box-sizing: border-box; }

/* #app and .login-shell set display, which outranks the UA [hidden] rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--sans);
  font-size: 13px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------------------------------------------------------------- login */
.login-shell { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 28px; display: grid; gap: 10px;
}
.login-mark { font-size: 26px; color: var(--accent); }
.login-card h1 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.login-card label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-top: 8px; }
.login-card input {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px;
  padding: 9px 10px; width: 100%;
}
.login-card button {
  margin-top: 10px; background: var(--accent); color: #fff; border: 0;
  border-radius: 4px; padding: 9px; cursor: pointer; font-weight: 600;
}
.error { color: var(--err); font-size: 12px; margin: 4px 0 0; }
.muted { color: var(--text-3); }

/* ---------------------------------------------------------------- shell */
#app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }
/* Grid/flex children default to min-width:auto, which lets wide content push the page. */
#app > main { min-width: 0; overflow-x: hidden; }

.rail {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.rail-head { display: flex; gap: 9px; align-items: center; padding: 14px 14px 10px; }
.rail-head .mark { color: var(--accent); font-size: 17px; }
.rail-head strong { display: block; font-size: 12.5px; letter-spacing: -.01em; }
.rail-head .muted { font-size: 11px; }

#nav { flex: 1; overflow-y: auto; padding: 6px 8px; display: grid; gap: 1px; align-content: start; }
#nav button {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 6px 9px; border-radius: 4px; color: var(--text-2); font-size: 12.5px;
}
#nav button:hover { background: var(--surface-2); color: var(--text); }
#nav button[aria-current="page"] { background: var(--surface-3); color: var(--text); font-weight: 600; }
#nav .count {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-3);
  background: var(--surface-2); padding: 1px 5px; border-radius: 999px;
}
#nav button[aria-current="page"] .count { background: var(--surface); }
#nav .count.hot { color: var(--err); }

.rail-foot { padding: 10px; border-top: 1px solid var(--line); display: flex; gap: 6px; }
.rail-foot button { flex: 1; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  padding: 9px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.mode-strip { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }

button.ghost {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2);
  padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 12px;
}
button.ghost:hover { color: var(--text); border-color: var(--line-strong); }
button.danger {
  background: transparent; border: 1px solid var(--err); color: var(--err);
  padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 600;
}
button.danger:hover { background: var(--err); color: #fff; }
button.primary {
  background: var(--accent); border: 1px solid var(--accent); color: #fff;
  padding: 5px 11px; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 600;
}
button[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------------------------------------------------------------- pills */
.pill {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line-strong);
  color: var(--text-2); white-space: nowrap;
}
.pill-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill-err { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); }
.pill-muted { color: var(--text-3); }
.pill-accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

/* ---------------------------------------------------------------- views */
.view { padding: 18px; max-width: 1500px; min-width: 0; }
.view h2 { margin: 0 0 3px; font-size: 15px; letter-spacing: -.01em; }
.view .sub { color: var(--text-3); font-size: 12px; margin: 0 0 16px; }

.grid { display: grid; gap: 12px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(min(215px, 100%), 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 13px 14px; min-width: 0;
}
.card h3 {
  margin: 0 0 9px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-3); font-weight: 600;
}
.stat { font-size: 25px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat.sm { font-size: 17px; }
.stat-note { color: var(--text-3); font-size: 11.5px; margin-top: 3px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 11.5px; overflow-wrap: anywhere; min-width: 0; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 7px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); font-weight: 600; position: sticky; top: 0; background: var(--surface-2);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.mono, .mono { font-family: var(--mono); font-size: 11.5px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }

.empty {
  padding: 34px 18px; text-align: center; color: var(--text-3);
  border: 1px dashed var(--line); border-radius: var(--r); background: var(--surface);
}
.empty strong { display: block; color: var(--text-2); margin-bottom: 3px; font-size: 13px; }

/* ---------------------------------------------------------------- director */
.director { display: grid; grid-template-rows: 1fr auto; gap: 12px; height: calc(100vh - 108px); }
.thread {
  overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px;
}
.msg { display: grid; gap: 5px; max-width: 860px; }
.msg .who {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3);
  display: flex; gap: 8px; align-items: center;
}
.msg .body {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 11px 13px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.operator { justify-self: end; }
.msg.operator .body { background: var(--surface-3); }
.msg.system .body { border-style: dashed; color: var(--text-2); }
.msg .refs { display: flex; gap: 5px; flex-wrap: wrap; }

.composer { display: grid; gap: 7px; }
.composer textarea {
  width: 100%; min-height: 76px; resize: vertical; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px;
  font-family: var(--sans);
}
.composer textarea:focus { border-color: var(--accent); }
.composer-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---------------------------------------------------------------- activity */
.feed { font-family: var(--mono); font-size: 11.5px; display: grid; gap: 0; }
.feed .row {
  display: grid; grid-template-columns: 62px 78px 1fr; gap: 10px;
  padding: 4px 9px; border-bottom: 1px solid var(--line); align-items: baseline;
}
.feed .row:hover { background: var(--surface-2); }
.feed .t { color: var(--text-3); }
.feed .ch { color: var(--text-3); }
.feed .row.warn .m { color: var(--warn); }
.feed .row.error .m { color: var(--err); }
.feed .m { overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- misc */
pre.code {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 11px; overflow-x: auto; font-family: var(--mono); font-size: 11.5px;
  white-space: pre; margin: 0; max-height: 480px;
}
.diff .add { color: var(--ok); }
.diff .del { color: var(--err); }
.diff .hunk { color: var(--info); }

.bar { height: 5px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.warn > i { background: var(--warn); }
.bar.err > i { background: var(--err); }

.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: 10px; }
.shots figure { margin: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.shots img { width: 100%; display: block; background: var(--surface-2); }
.shots figcaption { padding: 5px 8px; font-size: 11px; color: var(--text-3); font-family: var(--mono); }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.back { background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 0 0 6px; font-size: 12px; }
.back:hover { color: var(--text); }

.section-gap { margin-top: 18px; }
.toolbar { display: flex; gap: 7px; align-items: center; margin-bottom: 11px; flex-wrap: wrap; }
.toolbar select, .toolbar input {
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; font-size: 12px;
}

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  background: var(--surface); border: 1px solid var(--line-strong); border-left: 3px solid var(--accent);
  border-radius: var(--r); padding: 10px 14px; max-width: 380px; font-size: 12px;
  box-shadow: 0 6px 22px rgb(0 0 0 / .22);
}
.toast.err { border-left-color: var(--err); }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  #nav { display: flex; gap: 4px; }
  #nav button { white-space: nowrap; }
  .rail-foot { border-top: 0; border-left: 1px solid var(--line); }
  .director { height: auto; }
  .thread { max-height: 60vh; }
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .16s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(5px); } }
}
