/* Barad — control-tower interface.
   Dark industrial console: warm ink surfaces, hairline borders,
   phosphor-amber accent, monospace data, serif wordmark. */

:root {
  color-scheme: dark;
  --ink-0: #0c0b09;
  --ink-1: #121110;
  --ink-2: #191715;
  --ink-3: #211e1b;
  --line: #2e2a25;
  --line-strong: #45403a;
  --bone: #e8e2d6;
  --bone-dim: #a89f90;
  --bone-faint: #6f685c;
  --amber: #f0a33c;
  --amber-dim: #8a6224;
  --amber-glow: rgba(240, 163, 60, 0.14);
  --green: #8fce76;
  --red: #e06c5a;
  --blue: #7fb3d3;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--ink-0);
  color: var(--bone);
  font: 13px/1.5 var(--font-mono);
}

body {
  background-image:
    radial-gradient(ellipse 90% 55% at 50% -10%, rgba(240, 163, 60, 0.05), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(255, 255, 255, 0.008) 2px 4px);
}

.hidden { display: none !important; }

::selection { background: var(--amber-dim); color: var(--bone); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid var(--ink-0); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--ink-2);
  color: var(--bone);
  padding: 0.5rem 0.9rem;
  border-radius: 3px;
  letter-spacing: 0.02em;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
.btn:hover { border-color: var(--amber); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { border-color: var(--line-strong); }

.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #16120a;
  font-weight: 600;
}
.btn-primary:hover { background: #ffb95a; border-color: #ffb95a; }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--bone-dim); }
.btn-ghost:hover { color: var(--bone); }

.btn-danger-ghost { background: transparent; border-color: var(--line); color: var(--bone-dim); }
.btn-danger-ghost:hover { border-color: var(--red); color: var(--red); }
.btn-danger-ghost.is-armed { border-color: var(--red); background: rgba(224, 108, 90, 0.12); color: var(--red); }

.btn-sm { padding: 0.25rem 0.6rem; font-size: 12px; }
.btn-lg { padding: 0.8rem 2.6rem; font-size: 15px; }

/* ---------- LEDs / status ---------- */

.led {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--bone-faint);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4) inset;
  flex: none;
}
.led-green { background: var(--green); box-shadow: 0 0 6px rgba(143, 206, 118, 0.5); }
.led-amber { background: var(--amber); box-shadow: 0 0 6px rgba(240, 163, 60, 0.55); }
.led-red { background: var(--red); box-shadow: 0 0 6px rgba(224, 108, 90, 0.55); }
.led-gray { background: var(--bone-faint); }
.led-pulse { animation: led-pulse 1.2s ease-in-out infinite; }

@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.status-word {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--bone-dim);
}
.status-word.is-green { color: var(--green); }
.status-word.is-amber { color: var(--amber); }
.status-word.is-red { color: var(--red); }

/* ---------- Toasts ---------- */

.toast-host {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: grid;
  gap: 6px;
  justify-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 640px;
  background: var(--ink-3);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--amber);
  padding: 0.55rem 0.9rem;
  border-radius: 3px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 160ms ease-out;
  white-space: pre-wrap;
  word-break: break-word;
}
.toast.is-error { border-left-color: var(--red); }
.toast.is-ok { border-left-color: var(--green); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Gate (signed out) ---------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.gate-frame {
  text-align: center;
  max-width: 560px;
  border: 1px solid var(--line);
  padding: 4rem 3rem 3rem;
  background: linear-gradient(180deg, var(--ink-1), var(--ink-0));
  position: relative;
}
.gate-frame::before, .gate-frame::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--amber);
}
.gate-frame::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.gate-frame::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.gate-coords {
  margin: 0 0 2.5rem;
  font-size: 10px;
  letter-spacing: 0.35em;
  color: var(--bone-faint);
}
.gate-mark {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(3.5rem, 10vw, 5.5rem);
  font-weight: 400;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: var(--bone);
}
.gate-sub {
  margin: 1.2rem auto 0;
  max-width: 40ch;
  color: var(--bone-dim);
}
.gate-rule {
  width: 60px;
  height: 1px;
  background: var(--amber);
  margin: 2.2rem auto;
}
.gate-foot {
  margin: 2.5rem 0 0;
  font-size: 11px;
  color: var(--bone-faint);
}

.auth-form {
  display: grid;
  gap: 0.8rem;
  text-align: left;
  max-width: 340px;
  margin: 0 auto;
}
.auth-form .field { margin: 0; }
.auth-submit { margin-top: 0.4rem; }
.auth-link {
  font: inherit;
  font-size: 12px;
  background: transparent;
  border: none;
  color: var(--bone-dim);
  cursor: pointer;
  justify-self: center;
  padding: 0.2rem 0.4rem;
}
.auth-link:hover { color: var(--amber); text-decoration: underline; }
.auth-note {
  margin: 0;
  font-size: 11px;
  color: var(--bone-faint);
  text-align: center;
}
.auth-error {
  margin: 1rem auto 0;
  max-width: 340px;
  font-size: 12px;
  color: var(--red);
  border: 1px solid rgba(224, 108, 90, 0.35);
  border-left: 3px solid var(--red);
  border-radius: 3px;
  padding: 0.5rem 0.8rem;
  text-align: left;
  word-break: break-word;
}

/* ---------- Shell layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Rail ---------- */

.rail {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--ink-1);
  min-height: 0;
}
.brand {
  padding: 1.1rem 1.2rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 400;
  letter-spacing: 0.3em;
  color: var(--bone);
}
.brand-sub {
  margin: 0.1rem 0 0;
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--amber);
}
.rail-actions { padding: 1rem 1.2rem 0.4rem; }
.rail-actions .btn { width: 100%; }
.rail-label {
  margin: 0.9rem 1.2rem 0.4rem;
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--bone-faint);
}
.session-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0 0.6rem 0.6rem;
  display: grid;
  gap: 3px;
  align-content: start;
}
.session-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 0.55rem 0.6rem;
  cursor: pointer;
}
.session-item:hover { background: var(--ink-2); }
.session-item.is-active {
  background: var(--ink-3);
  border-color: var(--line-strong);
}
.session-item-top {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.session-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.session-item-meta {
  margin-top: 2px;
  padding-left: 15px;
  font-size: 11px;
  color: var(--bone-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-list-empty {
  padding: 1rem 0.6rem;
  color: var(--bone-faint);
  font-size: 12px;
}
.rail-foot {
  border-top: 1px solid var(--line);
  padding: 0.8rem 1.2rem 1rem;
  display: grid;
  gap: 0.6rem;
}
.account-line {
  margin: 0;
  font-size: 11px;
  color: var(--bone-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-foot-buttons { display: flex; gap: 6px; }
.rail-foot-buttons .btn { flex: 1; padding: 0.35rem 0.5rem; font-size: 12px; }

/* ---------- Stage ---------- */

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.empty-stage {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.4rem;
}
.empty-mark {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: var(--bone-dim);
}
.empty-sub { margin: 0; color: var(--bone-faint); max-width: 44ch; }

.session-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Session header ---------- */

.session-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  padding: 0.9rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: var(--ink-1);
}
.session-head-id { min-width: 0; }
.session-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.session-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-meta {
  margin: 0.2rem 0 0;
  padding-left: 18px;
  font-size: 11px;
  color: var(--bone-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-head-side {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex: none;
}
.gauge-block { width: 170px; }
.gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bone-faint);
  margin-bottom: 4px;
}
.gauge {
  height: 4px;
  background: var(--ink-3);
  border: 1px solid var(--line);
}
.gauge-fill {
  height: 100%;
  width: 0;
  background: var(--amber);
  transition: width 400ms ease;
}
.gauge-fill.is-hot { background: var(--red); }
.head-buttons { display: flex; gap: 6px; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 1.4rem;
  border-bottom: 1px solid var(--line);
  background: var(--ink-1);
}
.tab {
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--bone-faint);
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--bone-dim); }
.tab.is-active { color: var(--amber); border-bottom-color: var(--amber); }

/* ---------- Panels ---------- */

.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Transcript ---------- */

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.4rem 1.4rem 0.6rem;
  display: grid;
  gap: 0.9rem;
  align-content: start;
}
.transcript > * { max-width: 860px; width: 100%; margin: 0 auto; }

.msg { display: grid; gap: 4px; }
.msg-tag {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bone-faint);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.msg-tag time { letter-spacing: 0.04em; }
.msg-user .msg-tag { color: var(--blue); }
.msg-agent .msg-tag { color: var(--amber); }

.msg-body {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.7rem 0.9rem;
  background: var(--ink-1);
  overflow-wrap: break-word;
}
.msg-user .msg-body { border-left: 3px solid var(--blue); }
.msg-agent .msg-body { border-left: 3px solid var(--amber); background: var(--ink-2); }
.msg-live .msg-body { border-style: dashed; }

.cursor-blink {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--amber);
  vertical-align: text-bottom;
  margin-left: 3px;
  animation: led-pulse 0.9s step-end infinite;
}

/* prose inside assistant messages */
.prose p { margin: 0 0 0.6rem; }
.prose p:last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--amber);
  margin: 1rem 0 0.4rem;
}
.prose h1:first-child, .prose h2:first-child, .prose h3:first-child { margin-top: 0; }
.prose ul, .prose ol { margin: 0 0 0.6rem; padding-left: 1.4rem; }
.prose li { margin: 0.15rem 0; }
.prose code {
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 0 4px;
  font-size: 12px;
}
.prose pre {
  background: var(--ink-0);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.7rem 0.9rem;
  overflow-x: auto;
  margin: 0.6rem 0;
}
.prose pre code { background: none; border: none; padding: 0; }
.prose a { color: var(--blue); }
.prose blockquote {
  margin: 0.6rem 0;
  padding: 0.2rem 0.9rem;
  border-left: 2px solid var(--line-strong);
  color: var(--bone-dim);
}

/* tool cards */
.tool-card {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--ink-1);
}
.tool-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-size: 12px;
  color: var(--bone-dim);
  background: transparent;
  border: none;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.tool-head:hover { color: var(--bone); }
.tool-kind {
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
  flex: none;
}
.tool-summary {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-state { flex: none; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; }
.tool-state.is-ok { color: var(--green); }
.tool-state.is-err { color: var(--red); }
.tool-state.is-run { color: var(--amber); }
.tool-detail {
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 0.7rem 0.9rem;
  background: var(--ink-0);
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  color: var(--bone-dim);
}

/* divider rows: turn status, compaction */
.turn-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--bone-faint);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.turn-divider::before, .turn-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.turn-divider.is-failed { color: var(--red); }
.turn-divider.is-cancelled { color: var(--bone-dim); }
.turn-divider.is-compaction { color: var(--blue); }

.transcript-empty {
  text-align: center;
  color: var(--bone-faint);
  padding: 3rem 0;
}

/* ---------- Composer ---------- */

.composer {
  border-top: 1px solid var(--line);
  background: var(--ink-1);
  padding: 0.8rem 1.4rem 1rem;
}
.turn-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--amber);
  padding: 0 0 0.6rem;
}
.turn-banner .btn { margin-left: auto; }
.composer-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  max-width: 860px;
  margin: 0 auto;
}
.composer textarea {
  flex: 1;
  font: inherit;
  color: var(--bone);
  background: var(--ink-0);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0.6rem 0.8rem;
  resize: vertical;
  min-height: 3.2rem;
  max-height: 16rem;
}
.composer textarea:focus { outline: none; border-color: var(--amber); }
.composer-send { align-self: flex-end; }

/* ---------- Browser (files / changes) ---------- */

.browser-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: var(--ink-1);
  min-height: 44px;
}
.browser-bar-actions { display: flex; gap: 6px; flex: none; }
.browser-title { margin: 0; font-size: 12px; color: var(--bone-dim); }
.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  min-width: 0;
  font-size: 12px;
}
.crumb {
  font: inherit;
  background: transparent;
  border: none;
  color: var(--blue);
  cursor: pointer;
  padding: 2px 4px;
}
.crumb:hover { text-decoration: underline; }
.crumb-sep { color: var(--bone-faint); }
.crumb-current { color: var(--bone); padding: 2px 4px; }

.browser-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.6rem 1.4rem 1.4rem;
}
.browser-note { color: var(--bone-faint); padding: 1rem 0; }

.entry-table { width: 100%; border-collapse: collapse; max-width: 860px; }
.entry-table td {
  border-bottom: 1px solid var(--ink-3);
  padding: 0.35rem 0.6rem;
  vertical-align: baseline;
}
.entry-row { cursor: pointer; }
.entry-row:hover td { background: var(--ink-2); }
.entry-name { color: var(--bone); }
.entry-name.is-dir { color: var(--blue); font-weight: 600; }
.entry-type { color: var(--bone-faint); font-size: 11px; width: 5rem; }
.entry-size { color: var(--bone-faint); text-align: right; width: 7rem; font-size: 11px; }
.entry-status { width: 5rem; letter-spacing: 0.1em; }
.entry-status .s-add { color: var(--green); }
.entry-status .s-del { color: var(--red); }
.entry-status .s-mod { color: var(--amber); }
.entry-status .s-unt { color: var(--blue); }

.viewer-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.4rem 0 0.6rem;
  color: var(--bone-faint);
  font-size: 11px;
  flex-wrap: wrap;
}
.viewer-head .viewer-path { color: var(--bone); font-size: 12px; }
.code-view {
  margin: 0;
  background: var(--ink-1);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.8rem 1rem;
  overflow: auto;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  tab-size: 4;
}
.code-view.is-wrap { white-space: pre-wrap; word-break: break-word; }

.diff-view .d-add { color: var(--green); }
.diff-view .d-del { color: var(--red); }
.diff-view .d-hunk { color: var(--blue); }
.diff-view .d-meta { color: var(--bone-faint); }
.diff-line { display: block; }

.load-more-row { padding: 0.8rem 0; }

/* ---------- Dialogs ---------- */

.dialog {
  background: var(--ink-1);
  color: var(--bone);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0;
  width: min(440px, 92vw);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(5, 4, 3, 0.7); }
.dialog-form { padding: 1.4rem 1.5rem 1.2rem; display: grid; gap: 0.8rem; }
.dialog-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.3rem;
  letter-spacing: 0.06em;
}
.dialog-sub { margin: -0.4rem 0 0; color: var(--bone-dim); font-size: 12px; }
.dialog-section { display: grid; gap: 0.8rem; }
.dialog-divider { height: 1px; background: var(--line); margin: 0.4rem 0; }
.field { display: grid; gap: 5px; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--bone-faint); }
.field input {
  font: 13px/1.4 var(--font-mono);
  letter-spacing: normal;
  text-transform: none;
  color: var(--bone);
  background: var(--ink-0);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0.55rem 0.7rem;
}
.field input:focus { outline: none; border-color: var(--amber); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 0.4rem; }

/* ---------- Narrow screens ---------- */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .rail { border-right: none; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .session-head { flex-wrap: wrap; }
  .gauge-block { width: 120px; }
}
