/* CustomizedStacks v2 — information-dense dark theme.
   Same palette as v1 so admin.html continues to work; layouts rebuilt. */

:root {
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1b2030;
  --panel-3: #232a3e;
  --border: #2a3142;
  --border-hi: #3a4258;
  --text: #f5f7fa;
  --muted: #8b93a7;
  --muted-2: #6b7288;
  --accent: #5eead4;
  --accent-hi: #4dd9c2;
  --warn: #fbbf24;
  --danger: #ff6b6b;
  --nav-h: 56px;
  --tray-w: 320px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
input, button, textarea, select { font-family: inherit; }

/* ---------- Top nav ---------- */
header.nav {
  position: sticky; top: 0; z-index: 100; height: var(--nav-h);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: rgba(11,13,18,0.95); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
header.nav .brand { font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  white-space: nowrap; margin-right: 4px; }
header.nav .brand a { color: var(--text); }
header.nav .brand .tag { color: var(--accent); font-weight: 500; margin-left: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; opacity: .8; }
header.nav .tabs { display: flex; gap: 4px; }
header.nav .tabs a {
  padding: 6px 12px; border-radius: 6px; font-size: 13px;
  color: var(--muted); border: 1px solid transparent;
}
header.nav .tabs a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
header.nav .tabs a.active { background: var(--panel-2); color: var(--text);
  border-color: var(--border); font-weight: 500; }
header.nav .search-wrap { flex: 1; max-width: 520px; position: relative; }
header.nav input.search {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px 8px 34px; font-size: 13px;
}
header.nav input.search:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
header.nav .search-wrap::before {
  content: "\1f50d"; position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); font-size: 12px; opacity: .5;
}
header.nav .stack-tray-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
header.nav .stack-tray-btn:hover { border-color: var(--border-hi); }
header.nav .stack-tray-btn .n {
  background: var(--accent); color: #0b0d12; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; font-size: 11px; min-width: 18px;
  text-align: center; display: inline-block;
}
header.nav .stack-tray-btn.empty .n { background: var(--border); color: var(--muted); }

/* ---------- Browse (three-pane) ---------- */
.browse {
  display: grid; grid-template-columns: 220px 1fr;
  min-height: calc(100vh - var(--nav-h));
}
.filters {
  border-right: 1px solid var(--border); padding: 16px 12px;
  overflow-y: auto; max-height: calc(100vh - var(--nav-h));
  position: sticky; top: var(--nav-h);
}
.filters .group { margin-bottom: 18px; }
.filters h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.filters .chip {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 9px; border-radius: 5px; font-size: 13px; cursor: pointer;
  margin-bottom: 2px; border: 1px solid transparent; user-select: none;
}
.filters .chip:hover { background: var(--panel); }
.filters .chip.on { background: var(--panel-2); border-color: var(--border-hi); }
.filters .chip .sw { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 8px; }
.filters .chip .lbl { flex: 1; margin: 0 8px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.filters .chip .cnt { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.filters .reset {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 5px; padding: 5px 10px; font-size: 12px; cursor: pointer;
  width: 100%; margin-top: 4px;
}
.filters .reset:hover { color: var(--text); border-color: var(--border-hi); }

.results { padding: 18px 20px 40px; overflow: auto; }
.results-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
}
.results-head .count { color: var(--muted); font-size: 13px; }
.results-head .count strong { color: var(--text); }
.results-head .sort {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 5px 10px; font-size: 12px;
}
.results-head .active-filters {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  color: var(--muted); font-size: 12px;
}
.results-head .active-filters .pill {
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 3px 8px 3px 10px; border-radius: 999px; color: var(--text);
  display: inline-flex; align-items: center; gap: 6px;
}
.results-head .active-filters .pill button {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  padding: 0 2px; font-size: 14px; line-height: 1;
}
.results-head .active-filters .pill button:hover { color: var(--danger); }

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
  position: relative; transition: border-color .1s, transform .1s;
  min-height: 140px;
}
.card:hover { border-color: var(--border-hi); }
.card.in-stack { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card .ctop { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card .name { font-size: 14px; font-weight: 600; line-height: 1.3; flex: 1;
  min-width: 0; word-break: break-word; }
.card .name a { color: var(--text); }
.card .branded { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .cat-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px;
  margin-top: 5px; }
.card .field {
  font-size: 12px; line-height: 1.4; color: #c5cdd9;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .field.dose { color: var(--muted); font-variant-numeric: tabular-nums; }
.card .stack-hint { color: var(--accent); font-size: 11px; font-weight: 500; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .actions {
  display: flex; gap: 6px; margin-top: auto; padding-top: 8px;
  border-top: 1px solid var(--border);
}
.card .actions button {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 5px; font-size: 11px; cursor: pointer;
  flex: 1; transition: all .1s;
}
.card .actions button:hover { color: var(--text); border-color: var(--border-hi); }
.card .actions button.primary { color: var(--accent); border-color: var(--accent); font-weight: 500; }
.card .actions button.primary:hover { background: var(--accent); color: #0b0d12; }
.card .actions button.in { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 500; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px;
  grid-column: 1/-1; font-size: 14px; }
.loading { text-align: center; color: var(--muted); padding: 30px; font-size: 13px;
  grid-column: 1/-1; }
.sentinel { height: 20px; grid-column: 1/-1; }

/* ---------- Stack tray (right slide-in) ---------- */
.tray {
  position: fixed; top: 0; right: calc(-1 * var(--tray-w) - 20px);
  width: var(--tray-w); max-width: 92vw; height: 100vh;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0,0,0,0.4);
  transition: right .22s ease; z-index: 250; display: flex; flex-direction: column;
}
.tray.open { right: 0; }
.tray .th {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.tray .th h3 { margin: 0; font-size: 14px; }
.tray .th .close { background: transparent; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; line-height: 1; }
.tray .th .close:hover { color: var(--text); }
.tray .items { flex: 1; overflow-y: auto; padding: 8px; }
.tray .item {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 6px; background: var(--panel-2);
  display: flex; align-items: flex-start; gap: 8px;
}
.tray .item .body { flex: 1; min-width: 0; }
.tray .item .n { font-size: 13px; font-weight: 500; }
.tray .item .n a { color: var(--text); }
.tray .item .c { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tray .item .x {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 4px;
}
.tray .item .x:hover { color: var(--danger); }
.tray .empty-tray { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.tray .foot {
  padding: 12px 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.tray .btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.tray .btn:hover { background: var(--panel-3); }
.tray .btn.primary { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 600; }
.tray .btn.primary:hover { background: var(--accent-hi); }
.tray .btn.danger { color: var(--danger); border-color: transparent; }
.tray .btn.danger:hover { background: rgba(255,107,107,0.1); }

.tray-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 240;
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
.tray-overlay.on { opacity: 1; pointer-events: auto; }

/* ---------- Molecule page ---------- */
.mol-page { max-width: 880px; margin: 0 auto; padding: 24px 20px 60px; }
.crumb { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent); }
.mol-head { display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.mol-head h1 { margin: 0; font-size: 28px; line-height: 1.15; }
.mol-head .branded { color: var(--muted); font-style: italic; font-size: 14px; margin-top: 4px; }
.mol-head .cat-pill { font-size: 11px; padding: 4px 10px; border-radius: 999px;
  font-weight: 600; color: #0b0d12; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.mol-actions { display: flex; gap: 8px; margin: 14px 0 22px; flex-wrap: wrap; }
.mol-actions .btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.mol-actions .btn:hover { border-color: var(--border-hi); }
.mol-actions .btn.primary { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 600; }
.mol-actions .btn.primary:hover { background: var(--accent-hi); }
.mol-actions .btn.in { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 600; }

.sec { margin-top: 22px; }
.sec h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 8px; border-bottom: 1px solid var(--border);
  padding-bottom: 5px; font-weight: 600; }
.sec .body { font-size: 15px; line-height: 1.6; color: #d8dde7; }
.sec ul { margin: 6px 0; padding-left: 20px; line-height: 1.7; color: #d8dde7; }
.sec .outcome { color: var(--accent); font-style: italic; margin-top: 8px; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; margin-top: 10px;
}
.panel textarea {
  width: 100%; min-height: 130px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px;
  font-size: 14px; line-height: 1.5; resize: vertical;
}
.panel textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.save-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.btn.primary { background: var(--accent); color: #0b0d12; border: 1px solid var(--accent); font-weight: 600; padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.btn.primary:hover { background: var(--accent-hi); }
.saved { color: var(--accent); font-size: 12px; opacity: 0; transition: opacity .2s; }
.saved.show { opacity: 1; }

/* Dose table */
table.dose { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 14px; }
table.dose th, table.dose td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
table.dose th { color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; font-weight: 600; background: var(--panel-2); }
table.dose td input { width: 100%; background: transparent; color: var(--text);
  border: none; font-size: 14px; }
table.dose td input:focus { outline: 1px solid var(--accent); border-radius: 3px; }
table.dose td.num { width: 140px; }
table.dose td.del { width: 40px; text-align: center; }
table.dose td.del button { background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px; }
table.dose td.del button:hover { color: var(--danger); }
table.dose tfoot td { font-weight: 700; background: var(--panel-2); }
.total-val { color: var(--accent); font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.5; }

/* ---------- Mindmap (redesigned) ---------- */
#map-wrap { position: absolute; inset: var(--nav-h) 0 0 0; overflow: hidden;
  display: grid; grid-template-columns: 260px 1fr; }
#map-side {
  border-right: 1px solid var(--border); padding: 16px 14px; overflow-y: auto;
  background: var(--panel);
}
#map-side h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 10px; }
#map-side .info { color: var(--muted); font-size: 12px; line-height: 1.5; margin-bottom: 14px; }
#map-side .row { display: flex; align-items: center; gap: 8px; padding: 5px 8px;
  border-radius: 5px; cursor: pointer; font-size: 13px; }
#map-side .row:hover { background: var(--panel-2); }
#map-side .row.on { background: var(--panel-2); }
#map-side .row .sw { width: 10px; height: 10px; border-radius: 3px; }
#map-side .row .lab { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#map-side .row .cnt { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#map-side .mode-toggle {
  display: flex; gap: 4px; background: var(--panel-2); padding: 4px;
  border-radius: 6px; margin-bottom: 14px;
}
#map-side .mode-toggle button {
  flex: 1; background: transparent; color: var(--muted); border: none;
  padding: 5px 8px; font-size: 12px; border-radius: 4px; cursor: pointer;
}
#map-side .mode-toggle button.on { background: var(--accent); color: #0b0d12; font-weight: 600; }
#graph { position: relative; }
#graph svg { width: 100%; height: 100%; display: block; }
.node circle { cursor: pointer; }
.node text {
  fill: #fff; font-size: 11px; font-weight: 500;
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
  pointer-events: all; cursor: pointer; user-select: none;
}
.node.root text, .node.category text { font-size: 13px; font-weight: 700; }
.link { stroke: #38415a; stroke-opacity: .45; fill: none; }

#tip {
  position: fixed; pointer-events: none; opacity: 0; z-index: 200;
  background: rgba(20,24,33,.97); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; max-width: 320px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); transition: opacity .1s;
}
#tip h4 { margin: 0 0 4px; font-size: 15px; }
#tip .br { color: var(--muted); font-size: 11px; font-style: italic; margin-bottom: 4px; }
#tip .ds { font-size: 12px; color: #c5cdd9; margin-bottom: 4px; }
#tip .sl { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; margin-top: 6px; }
#tip .pill { display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }

/* ---------- Stack page ---------- */
.stack-page { max-width: 960px; margin: 0 auto; padding: 24px 20px 60px; }
.stack-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  align-items: flex-start; margin-bottom: 6px; }
.stack-head h1 { margin: 0; font-size: 26px; }
.stack-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack-summary { display: flex; gap: 20px; flex-wrap: wrap; margin: 14px 0 24px;
  color: var(--muted); font-size: 13px; }
.stack-summary strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Responsive ---------- */
@media (max-width: 800px) {
  .browse { grid-template-columns: 1fr; }
  .filters { position: relative; top: 0; max-height: none;
    border-right: none; border-bottom: 1px solid var(--border); }
  #map-wrap { grid-template-columns: 1fr; }
  #map-side { display: none; }
  header.nav input.search { font-size: 14px; }
  header.nav .tabs a { padding: 6px 10px; }
}

footer.site { text-align: center; color: var(--muted); font-size: 12px;
  padding: 24px 20px; border-top: 1px solid var(--border); margin-top: 40px; }
