:root {
  color-scheme: dark;
  --bg: #14160f;
  --bg-2: #1e2318;
  --bg-3: #0c0e09;
  --line: #353b2c;
  --text: #ebe6d4;
  --muted: #a4a58f;
  --brass: #e2c56e;
  --brass-ink: #241c08;
  --ok: #9dcf73;
  --bad: #e07a62;
  --warn: #e0b15a;
  --sans: "Segoe UI", "Liberation Sans", "Nimbus Sans", sans-serif;
  --serif: "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "Cascadia Mono", "DejaVu Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-columns: 11.5rem 1fr;
  grid-template-rows: auto 1fr 12.5rem;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h1 { font-size: 1.45rem; letter-spacing: 0.01em; }
h2 { font-size: 1.15rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button, input, select, textarea { background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px; }
button { padding: 0.4rem 0.75rem; cursor: pointer; }
button.primary { background: var(--brass); color: var(--brass-ink); border-color: transparent; font-weight: 650; }
button.ghost { background: transparent; }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.danger:disabled { opacity: 0.45; cursor: default; }
.storage-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.storage-list .path { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 1px;
}
input, select { padding: 0.35rem 0.5rem; width: 100%; }
label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.82rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 0.45rem; }
label.check input { width: auto; }
.hint, .lead { color: var(--muted); margin: 0 0 0.8rem; }
.lead { max-width: 70rem; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.68rem; color: var(--brass); }
code { font-family: var(--mono); font-size: 0.86em; }
.error { color: var(--bad); }

header {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.8rem 1.25rem;
  padding: 0.85rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #23281b, var(--bg));
}
.case-pick { min-width: 14rem; }
.status { margin: 0 0 0.2rem auto; color: var(--muted); font-size: 0.82rem; text-align: right; }
.status .ok { color: var(--ok); }
.status .bad { color: var(--bad); }

nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.8rem;
  border-right: 1px solid var(--line);
  background: var(--bg-3);
}
nav button { text-align: left; background: transparent; border-color: transparent; }
nav button.active { background: var(--bg-2); border-color: var(--line); box-shadow: inset 3px 0 var(--brass); }

main { overflow: auto; padding: 1rem 1.15rem 1.2rem; }
.view { max-width: 78rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 0.9rem; }
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: 0.5rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; }
.row > label { flex: 1 1 10rem; }
.file-list, .job-table { list-style: none; margin: 0; padding: 0; }
.file-list li.with-side { display: flex; gap: 0.35rem; align-items: stretch; }
.file-list li.with-side > button:first-child { flex: 1; width: auto; }
.file-list li.with-side > button.danger { width: auto; flex: 0 0 auto; }
details.channel-past { margin-top: 0.7rem; border-top: 1px solid var(--line); padding-top: 0.45rem; }
details.channel-past summary { cursor: pointer; font-weight: 650; }
details.channel-past .storage-list { margin-top: 0.4rem; }
.file-list button, .job-table button {
  width: 100%;
  text-align: left;
  background: transparent;
  border-color: transparent;
  border-radius: 4px;
}
.file-list button.on, .job-table button.on { background: #2a311f; }
.file-list .meta, .job-table .meta { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; }
.editor, .snippet, #log-body {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.editor { width: 100%; min-height: 28rem; padding: 0.8rem; resize: vertical; }
.snippet { padding: 0.7rem; white-space: pre-wrap; margin: 0; }
.preview img, .viewer img { max-width: 100%; height: auto; border-radius: 8px; background: #000; }
.heat-preview { margin: 0.7rem 0 0; }
.heat-mini { height: 14rem; }
.places-map { height: 20rem; margin-top: 0.6rem; }
.places-list { max-height: 16rem; overflow: auto; margin-top: 0.6rem; }
.places-list li { padding: 0.12rem 0; }
.leaflet-tooltip.place-tip {
  background: #241c08;
  color: #e2c56e;
  border: 1px solid #e2c56e;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: none;
}
.leaflet-tooltip.place-tip::before { border-top-color: #e2c56e; }
.heat-preview img {
  display: block;
  width: 100%;
  max-height: 9rem;
  object-fit: contain;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.heat-links { display: flex; flex-wrap: wrap; gap: 0.8rem; margin: 0.35rem 0 0; }
button.textlink {
  width: auto;
  padding: 0;
  background: none;
  border: 0;
  color: var(--brass);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.split { display: grid; grid-template-columns: minmax(16rem, 22rem) 1fr; gap: 1rem; min-height: 24rem; }
.viewer { overflow: auto; }
.viewer table, .viewer .md table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
.viewer th, .viewer td { border-bottom: 1px solid var(--line); padding: 0.28rem 0.4rem; text-align: left; vertical-align: top; }
.viewer h2, .viewer h3 { margin: 0.8rem 0 0.3rem; }
.map { height: 26rem; border-radius: 8px; border: 1px solid var(--line); }
.job-table li { border-bottom: 1px solid var(--line); }
.badge { font-family: var(--mono); font-size: 0.75rem; }
.badge.run { color: var(--brass); }
.badge.done { color: var(--ok); }
.badge.bad { color: var(--bad); }

#log-dock {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: 1px solid var(--line);
  background: var(--bg-3);
}
#log-dock.shut { grid-template-rows: auto; }
body.shut { grid-template-rows: auto 1fr 2.4rem; }
.log-bar { display: flex; align-items: center; gap: 0.7rem; padding: 0.25rem 0.7rem; }
.log-links { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0 0.7rem; }
.log-links button { font-family: var(--mono); font-size: 0.75rem; }
#log-body { flex: 1; margin: 0 0.7rem 0.5rem; overflow: auto; padding: 0.55rem 0.7rem; white-space: pre-wrap; }
body.shut #log-body, body.shut .log-links { display: none; }
.toast {
  position: fixed;
  right: 1rem;
  bottom: 13.5rem;
  max-width: 28rem;
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: #3a241e;
  color: #ffd7cc;
  border: 1px solid var(--bad);
  border-radius: 8px;
}
body.shut .toast { bottom: 3.2rem; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(8, 9, 6, 0.92);
}
.gate-card {
  width: min(26rem, calc(100% - 2rem));
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1.3rem 1.3rem 1.4rem;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr 12.5rem; }
  nav { flex-direction: row; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  header { flex-wrap: wrap; }
  .status { margin-left: 0; text-align: left; }
  .split { grid-template-columns: 1fr; }
}
