/* ===================================================================
   GRODZISKO ENGINE — investigative console (dark "intelligence" theme)
   =================================================================== */

:root {
  --bg:        #0b0e14;
  --bg-2:      #11151f;
  --bg-3:      #161c28;
  --bg-card:   #131925;
  --panel:     #0e131c;
  --line:      #232b3a;
  --line-2:    #2e3850;
  --text:      #d4dbe8;
  --text-dim:  #8893a6;
  --text-mute: #5a6477;
  --cyan:      #35e0d0;
  --cyan-dim:  #1d8f86;
  --amber:     #f5b545;
  --amber-dim: #9a7128;
  --green:     #4fd17a;
  --red:       #ff5d6c;
  --red-dim:   #7a2730;
  --grey-badge:#46506280;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --shadow: 0 6px 24px rgba(0,0,0,.45);
  --rail-w: 320px;
  --detail-w: 384px;
  --top-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
kbd {
  font-family: var(--mono);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  font-size: 10px;
  color: var(--text-dim);
}

/* ---------------- TOP BAR ---------------- */
.topbar {
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: linear-gradient(180deg, #0d121b 0%, #0a0d14 100%);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-glyph {
  color: var(--cyan);
  font-size: 20px;
  text-shadow: 0 0 12px rgba(53,224,208,.6);
}
.brand-text h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #eaf0fa;
}
.brand-sub {
  display: block;
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: .04em;
  margin-top: 1px;
}

.aoi-block {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.aoi-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--cyan);
  letter-spacing: .14em;
  margin-right: 2px;
}
.aoi-field { display: flex; align-items: center; gap: 3px; }
.aoi-field > span {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-mute);
}
.aoi-field input {
  width: 74px;
  padding: 5px 6px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
}
.aoi-field input:focus {
  outline: none;
  border-color: var(--cyan-dim);
  box-shadow: 0 0 0 2px rgba(53,224,208,.15);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.runs-select { display: flex; align-items: center; gap: 6px; }
.runs-select > span, .mini-select > span {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: .08em;
}
.runs-select select, .mini-select select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 11px;
  max-width: 180px;
}
select:focus { outline: none; border-color: var(--cyan-dim); }

/* ---------------- Language toggle ---------------- */
.lang-switch {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-2);
}
.lang-btn {
  background: transparent;
  border: none;
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  padding: 6px 10px;
  transition: background .12s, color .12s;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--line-2); }
.lang-btn:hover { color: var(--text); background: var(--bg-3); }
.lang-btn.active {
  background: #0d2220;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(53,224,208,.4);
}
.lang-btn:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--cyan-dim); }

/* ---------------- Buttons ---------------- */
.btn {
  border: 1px solid var(--line-2);
  background: var(--bg-3);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--bg-2); border-color: var(--line-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-primary {
  background: linear-gradient(180deg, #1cc6b7, #15a99c);
  color: #03110f;
  border-color: #2ee6d4;
  letter-spacing: .1em;
  box-shadow: 0 0 16px rgba(53,224,208,.25);
}
.btn-primary:hover { background: linear-gradient(180deg, #2ee6d4, #1cc6b7); }
.btn-confirm { background: #14361f; border-color: var(--green); color: #b6f3c9; }
.btn-confirm:hover { background: #1a4a2a; }
.btn-reject  { background: #3a161c; border-color: var(--red); color: #ffc4ca; }
.btn-reject:hover { background: #4d1c24; }
.btn-field   { background: #3a2f14; border-color: var(--amber); color: #f7dca0; }
.btn-field:hover { background: #4d3e1a; }

/* ---------------- Status pill ---------------- */
.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 20px;
  border: 1px solid var(--line-2);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .06em;
  background: var(--bg-2);
  min-width: 92px;
  justify-content: center;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-mute);
  flex: none;
}
.status-idle   .status-dot { background: var(--text-mute); }
.status-idle   .status-text { color: var(--text-dim); }
.status-running { border-color: var(--amber-dim); }
.status-running .status-dot {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  animation: pulse 1s infinite;
}
.status-running .status-text { color: var(--amber); }
.status-done   { border-color: var(--cyan-dim); }
.status-done   .status-dot { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.status-done   .status-text { color: var(--cyan); }
.status-error  { border-color: var(--red-dim); }
.status-error  .status-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.status-error  .status-text { color: var(--red); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------------- LAYOUT GRID ---------------- */
.layout {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr var(--detail-w);
  height: calc(100vh - var(--top-h));
}

/* ---------------- LEFT RAIL ---------------- */
.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-head { padding: 12px 12px 8px; border-bottom: 1px solid var(--line); }
.rail-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 8px;
}
.count-badge {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
  color: var(--cyan);
}
.rail-controls {
  display: flex; align-items: center; gap: 14px; margin-top: 9px;
}
.mini-select { display: flex; align-items: center; gap: 5px; }
.mini-toggle {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-dim); cursor: pointer;
}
.mini-toggle input { accent-color: var(--cyan); }

.queue {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  outline: none;
}
.rail-foot {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  color: var(--text-mute);
  text-align: center;
}

/* candidate card */
.cand {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 9px;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.cand:hover { border-color: var(--line-2); background: var(--bg-3); }
.cand.selected {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 16px rgba(53,224,208,.18);
}
.cand-thumb {
  width: 64px; height: 64px;
  border-radius: 5px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--line);
}
.cand-thumb.broken {
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: var(--text-mute); text-align: center;
}
.cand-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cand-top { display: flex; align-items: center; gap: 6px; }
.cand-rank { font-family: var(--mono); font-size: 10px; color: var(--text-mute); }
.cand-id { font-family: var(--mono); font-size: 11px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand-badges { margin-left: auto; display: flex; gap: 4px; }
.confbar {
  height: 6px; border-radius: 3px;
  background: var(--bg);
  overflow: hidden; position: relative;
  border: 1px solid var(--line);
}
.confbar > i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--cyan-dim), var(--cyan));
}
.cand-meta {
  display: flex; gap: 10px;
  font-family: var(--mono); font-size: 10px; color: var(--text-dim);
}
.cand-meta b { color: var(--text); font-weight: 600; }

/* badges */
.badge {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .06em;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.badge-new  { background: #14361f; color: var(--green); border: 1px solid var(--green); }
.badge-known{ background: var(--grey-badge); color: var(--text-dim); border: 1px solid var(--line-2); }
.badge-warn { background: #3a161c; color: var(--red); border: 1px solid var(--red); }

/* ---------------- CENTER MAP ---------------- */
.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #05070b; }

.map-overlay-controls {
  position: absolute; top: 10px; left: 10px; z-index: 5;
  display: flex; gap: 8px; align-items: center;
}
.map-btn {
  background: rgba(14,19,28,.9);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  backdrop-filter: blur(4px);
}
.map-btn:hover { border-color: var(--cyan-dim); }
.map-toggle {
  display: flex; align-items: center; gap: 6px;
  background: rgba(14,19,28,.9);
  border: 1px solid var(--line-2);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px; color: var(--text-dim);
  backdrop-filter: blur(4px);
}
.map-toggle input { accent-color: var(--cyan); }

/* basemap segmented control: Dark | Satellite | Orthophoto */
.basemap-switch {
  display: flex; align-items: stretch;
  background: rgba(14,19,28,.9);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  overflow: hidden;
  backdrop-filter: blur(4px);
}
.base-btn {
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line-2);
  color: var(--text-dim);
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
}
.base-btn:first-child { border-left: 0; }
.base-btn:hover { color: var(--text); }
.base-btn.active { background: var(--cyan); color: #07131a; font-weight: 600; }

.draw-hint {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 6;
  background: rgba(11,14,20,.95);
  border: 1px solid var(--cyan-dim);
  color: var(--cyan);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 11px;
  box-shadow: var(--shadow);
}

/* maplibre control restyle */
.maplibregl-ctrl-group {
  background: var(--bg-2) !important;
  border: 1px solid var(--line) !important;
}
.maplibregl-ctrl-group button { background: var(--bg-2) !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(.85); }
.maplibregl-ctrl-attrib { background: rgba(11,14,20,.7) !important; }
.maplibregl-ctrl-attrib a { color: var(--text-mute) !important; }

/* ---------------- RIGHT DETAIL ---------------- */
.detail {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}
.detail-empty, .queue .empty-state {
  padding: 40px 22px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state { color: var(--text-dim); }
.empty-glyph { font-size: 34px; color: var(--line-2); margin-bottom: 10px; }
.detail-empty p, .empty-state p { margin: 4px 0; }
.muted { color: var(--text-mute); font-size: 11px; }

.detail-body { padding: 14px; }

.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.detail-id { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.cid { font-family: var(--mono); font-size: 14px; color: #eaf0fa; font-weight: 600; }
.detail-score { text-align: right; }
.score-num { font-family: var(--mono); font-size: 22px; font-weight: 600; color: var(--cyan); display: block; line-height: 1; }
.score-lbl { font-size: 9px; color: var(--text-mute); letter-spacing: .1em; text-transform: uppercase; }

/* viz swiper */
.viz { margin-top: 14px; }
.viz-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.viz-tab {
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text-dim);
  border-radius: 5px;
}
.viz-tab:hover { border-color: var(--line-2); color: var(--text); }
.viz-tab.active { border-color: var(--cyan); color: var(--cyan); background: #0d2220; }
.viz-stage { display: flex; align-items: center; gap: 6px; }
.viz-nav {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--text-dim);
  font-size: 16px; line-height: 1;
}
.viz-nav:hover { color: var(--cyan); border-color: var(--cyan-dim); }
.viz-img-frame {
  flex: 1 1 auto;
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #05070b
    repeating-linear-gradient(45deg, transparent 0 7px, rgba(255,255,255,.015) 7px 14px);
  display: flex; align-items: center; justify-content: center;
}
#viz-img { width: 100%; height: 100%; object-fit: contain; display: block; image-rendering: auto; }
.viz-loading, .viz-missing {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5,7,11,.7);
}
.viz-missing { color: var(--text-mute); font-family: var(--mono); font-size: 11px; background: rgba(5,7,11,.5); }
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--line-2);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.viz-caption { margin-top: 8px; }
.viz-layer-name { font-family: var(--mono); font-size: 12px; color: var(--cyan); font-weight: 600; display: block; }
.viz-layer-desc { font-size: 11px; color: var(--text-dim); }

/* panels */
.panel { margin-top: 16px; }
.panel-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--text-dim);
  margin: 0 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 8px;
}
.panel-sub { font-size: 9px; color: var(--text-mute); letter-spacing: .04em; }

/* morphometrics table */
.morpho { width: 100%; border-collapse: collapse; }
.morpho td { padding: 4px 4px; border-bottom: 1px solid var(--bg-3); vertical-align: middle; }
.morpho .m-key { color: var(--text-dim); font-size: 11px; }
.morpho .m-val { font-family: var(--mono); font-size: 11px; color: var(--text); text-align: right; white-space: nowrap; }
.morpho .m-chip { width: 1%; }
.chip {
  display: inline-block;
  width: 9px; height: 9px; border-radius: 50%;
  vertical-align: middle;
}
.chip-green { background: var(--green); box-shadow: 0 0 6px rgba(79,209,122,.5); }
.chip-amber { background: var(--amber); box-shadow: 0 0 6px rgba(245,181,69,.5); }
.chip-red   { background: var(--red);   box-shadow: 0 0 6px rgba(255,93,108,.5); }
.chip-none  { background: var(--line-2); }

/* xref */
.xref { display: flex; flex-direction: column; gap: 8px; }
.xref-row { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.xref-row .k { color: var(--text-mute); font-family: var(--mono); font-size: 10px; min-width: 96px; }
.xref-row .v { color: var(--text); }
.xref-mask {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px;
}
.mask-tag {
  font-family: var(--mono); font-size: 9px;
  padding: 1px 6px; border-radius: 4px;
  background: #3a161c; color: var(--red); border: 1px solid var(--red-dim);
}

/* triage */
.triage-btns { display: flex; gap: 6px; }
.triage-btns .btn { flex: 1; }
.verdict-state {
  margin-top: 8px;
  font-family: var(--mono); font-size: 11px;
  min-height: 14px;
}
.verdict-confirm { color: var(--green); }
.verdict-reject  { color: var(--red); }
.verdict-needs-field { color: var(--amber); }
.triage-note {
  width: 100%;
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  color: var(--text);
  padding: 7px;
  font-size: 11px;
  resize: vertical;
}
.triage-note:focus { outline: none; border-color: var(--cyan-dim); }

/* honesty banner */
.honesty {
  margin-top: 16px;
  padding: 10px 12px;
  background: #1c1408;
  border: 1px solid var(--amber-dim);
  border-left: 3px solid var(--amber);
  border-radius: 6px;
  font-size: 10.5px;
  line-height: 1.5;
  color: #e7cf9f;
}
.honesty strong { color: var(--amber); }

/* ---------------- toasts ---------------- */
.toast-host {
  position: fixed; bottom: 16px; right: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 360px;
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--cyan);
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--text);
  animation: toast-in .2s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.warn  { border-left-color: var(--amber); }
.toast.ok    { border-left-color: var(--green); }
.toast-title { font-weight: 600; display: block; margin-bottom: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3c4763; }

/* responsive: collapse rails on narrow viewports */
@media (max-width: 1180px) {
  :root { --rail-w: 270px; --detail-w: 330px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .rail { max-height: 220px; }
  .detail { max-height: 50vh; }
  .aoi-block { display: none; }
}
