/* ==========================================================================
   TSH knowledge base - dark "tech" theme, mirrors the Kivy app proportions:
   compact header, two column body (inner layer list 40% / content 60%),
   monospace content panel, cyan accents on a dark blue background.
   ========================================================================== */
:root {
  --bg: #0d1520;
  --bg-2: #131f2e;
  --bg-3: #1a2838;
  --panel: #101b28;
  --border: #24384d;
  --text: #dbe7f3;
  --text-dim: #8ba3b8;
  --accent: #35d0e0;
  --accent-dim: #1d7f8c;
  --warn: #e0b13a;
  --danger: #e0555f;
  --ok: #45c98a;
  --radius: 6px;
  --mono: "PT Mono", "JetBrains Mono", "DejaVu Sans Mono", Consolas, monospace;
  --sans: "PT Sans", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body, #root {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}

.fatal, .boot {
  padding: 24px;
  font: 16px var(--mono);
  color: var(--accent);
}

.muted { color: var(--text-dim); }
.spacer { flex: 1 1 auto; }
.hint { color: var(--text-dim); font-size: 12px; line-height: 1.5; }
code {
  font-family: var(--mono);
  background: var(--bg-3);
  padding: 1px 4px;
  border-radius: 3px;
}

/* ------------------------------------------------------------------ forms */
input, textarea, select, button { font-family: inherit; font-size: 14px; }

input[type="text"], input:not([type]), input[type="password"], textarea {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}

input:focus, textarea:focus { outline: 1px solid var(--accent-dim); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { color: var(--text-dim); font-size: 12px; }
.field.grow { flex: 1 1 auto; min-height: 0; }
.field.grow textarea { flex: 1 1 auto; min-height: 240px; resize: vertical; width: 100%; }

.btn {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover:not(:disabled) { background: #21364b; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.is-active { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent-dim); border-color: var(--accent); color: #06131a; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.warn { border-color: var(--warn); color: var(--warn); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }

.switch { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 12px; }
.switch input { accent-color: var(--accent); }

/* ------------------------------------------------------------------ login */
.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 20% -10%, #14324a 0%, transparent 60%),
    radial-gradient(700px 400px at 100% 100%, #17293b 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-error { color: var(--danger); margin: 10px 0 0; }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent) 0%, #1c6f9c 100%);
  color: #05131a;
  font: 700 15px/1 var(--mono);
  letter-spacing: 0.5px;
}
.brand-title { font-weight: 600; }
.brand-sub { color: var(--text-dim); font-size: 12px; }

/* ------------------------------------------------------------------ shell */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.app.is-moving .left { box-shadow: inset 0 0 0 2px var(--warn); }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
  padding: 2px 4px;
}
.brand .brand-mark { width: 30px; height: 30px; font-size: 12px; }
.brand-title { font-weight: 600; letter-spacing: 0.2px; }
.topbar-center { display: flex; align-items: center; gap: 12px; margin-left: 8px; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.status-chip {
  font-size: 12px;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  background: var(--panel);
}

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  padding: 6px;
}
.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.dropdown-item:hover:not(.disabled) { background: var(--bg-3); }
.dropdown-item.disabled { color: #55697c; cursor: default; }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 4px; }
.dropdown-note { color: var(--text-dim); font-size: 11px; padding: 4px 10px 8px; }

.searchbar, .addbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.search-input, .add-input { flex: 1 1 auto; }
.scope-group { display: flex; gap: 4px; }

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
}
.directory-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 45%;
}
.dir-sep { color: var(--border); margin: 0 4px; }
.dir-current { color: var(--accent); }

.body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  padding: 2px 10px 6px 1px;
}
.left {
  flex: 0 0 38%;
  min-width: 240px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 4px 6px 4px 4px;
}
.right {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  padding-left: 10px;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------ left column */
.article-list { display: flex; flex-direction: column; gap: 3px; }
.list-empty { padding: 14px 8px; font-size: 13px; }
.list-separator {
  margin: 10px 0 4px;
  padding: 4px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  background: var(--bg-3);
  border-radius: 4px;
}
.article-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  text-align: left;
  background: var(--panel);
  border: 1px solid transparent;
  border-left: 3px solid var(--accent-dim);
  border-radius: 4px;
  color: var(--text);
  padding: 7px 9px;
  cursor: pointer;
}
.article-row:hover { background: var(--bg-3); }
.article-row.is-selected { border-color: var(--accent); }
.article-row-name { font-size: 14px; }
.article-row-badge {
  align-self: flex-start;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  padding: 0 6px;
}
.article-row-path { font-size: 11px; color: var(--text-dim); }
.article-row-snippet {
  font-family: var(--mono);
  font-size: 12px;
  color: #b9cddd;
  white-space: pre-wrap;
  word-break: break-word;
}
.article-row-terms { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.term { font-size: 10px; color: var(--warn); border: 1px solid #6b5420; border-radius: 3px; padding: 0 4px; }
mark { background: #2c6d78; color: #eafcff; border-radius: 2px; padding: 0 1px; }

/* --------------------------------------------------------- content column */
.content {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding-right: 4px;
}
.content-empty { padding: 20px 8px; }
.content-toolbar { display: flex; align-items: center; gap: 10px; }
.content-actions { margin-left: auto; display: flex; gap: 6px; }
.lang-selectors { display: flex; gap: 4px; }
.lang-chip {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
}
.lang-chip.is-active { border-color: var(--accent); color: var(--accent); }
.lang-chip.is-missing { color: var(--danger); border-color: #6d2f34; }
.lang-chip.is-missing.is-active { color: #ffd9dc; }

.links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
  align-items: center;
  padding: 2px 0;
  border-bottom: 1px dashed var(--border);
}
.link-chip {
  background: #232b52;
  border: 1px solid #4b5aa8;
  color: #cfd8ff;
  border-radius: 14px;
  padding: 3px 12px;
  cursor: pointer;
}
.link-chip:hover:not(:disabled) { background: #2d3670; }
.link-chip.is-unresolved { color: var(--text-dim); border-color: var(--border); background: var(--panel); cursor: not-allowed; }

.meta-line {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: pre-wrap;
}
.content-body {
  margin: 0;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.content-body { flex: 1 1 auto; min-height: 160px; }

/* ---------------------------------------------------------------- editor */
.editor { display: flex; flex-direction: column; }
.editor-head { display: flex; align-items: baseline; gap: 10px; }
.editor-title { font-weight: 600; color: var(--accent); }
.editor-foot { display: flex; align-items: center; gap: 8px; padding-top: 4px; }

/* -------------------------------------------------------------- overlays */
.tree-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 14, 0.6);
  display: flex;
  z-index: 50;
}
.tree-panel {
  width: min(420px, 92vw);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.tree-panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.tree-body { overflow-y: auto; padding: 8px 6px 16px; }
.tree-row { display: flex; align-items: center; gap: 2px; }
.tree-toggle {
  width: 20px;
  background: none;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
}
.tree-toggle:disabled { color: #3d5266; cursor: default; }
.tree-label {
  flex: 1 1 auto;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.tree-label:hover { background: var(--bg-3); }
.tree-count { color: var(--accent); font-size: 11px; margin-left: 6px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 14, 0.6);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 20px;
}
.modal {
  width: min(560px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-title { font-weight: 600; color: var(--accent); margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.report-area {
  width: 100%;
  min-height: 200px;
  font-family: var(--mono);
  font-size: 12px;
  margin-top: 8px;
}

.updates-list { display: flex; flex-direction: column; gap: 4px; max-height: 48vh; overflow-y: auto; }
.updates-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.updates-action { font-size: 11px; color: var(--warn); text-transform: uppercase; }
.updates-name { background: none; border: 0; color: var(--text); text-align: left; cursor: pointer; padding: 0; }
.updates-name:hover { color: var(--accent); text-decoration: underline; }

/* --------------------------------------------------------------- banners */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
}
.banner-error { background: #3a1a1e; color: #ffced3; border-bottom: 1px solid #6d2f34; }
.banner-close {
  background: none;
  border: 0;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  margin-left: auto;
}
.toast {
  position: fixed;
  bottom: 42px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--accent-dim);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 20px;
  z-index: 70;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .body { flex-direction: column; }
  .left { flex: 0 0 40%; border-right: 0; border-bottom: 1px solid var(--border); }
  .right { padding-left: 0; }
  .directory-label { max-width: 100%; }
  .brand-title { display: none; }
  .topbar-center { display: none; }
  .statusbar { display: none; }
}
@media (max-width: 560px) {
  .scope-group, .searchbar .btn { font-size: 12px; }
  .searchbar { flex-wrap: wrap; }
}
