:root {
  --ink: #0f1720;
  --muted: #5a6a78;
  --soft: #8a9aab;
  --line: #d7e0e8;
  --line-strong: #c2ced9;
  --surface: #ffffff;
  --surface-2: #f4f7fa;
  --bg: #e8eef4;
  --accent: #0d6e6e;
  --accent-hover: #0a5858;
  --accent-soft: #e6f3f3;
  --ok: #1a7f5a;
  --ok-bg: #e8f6ef;
  --warn: #9a6b16;
  --warn-bg: #f8efd9;
  --danger: #b42318;
  --shadow: 0 1px 0 rgba(15, 23, 32, 0.04), 0 12px 32px rgba(15, 23, 32, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --display: "Space Grotesk", "IBM Plex Sans", sans-serif;
  --sidebar: 300px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% 0%, #d4e8e6 0%, transparent 55%),
    radial-gradient(700px 380px at 100% 0%, #d9e3f0 0%, transparent 50%),
    linear-gradient(165deg, #eef3f7 0%, #e4ebea 48%, #e8eef4 100%);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

/* —— Sidebar —— */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.15rem 1rem 1rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.15rem 0.25rem 0.85rem;
  border-bottom: 1px solid var(--line);
}
.brand h1 {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.03em;
}
.brand p { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.82rem; }
.mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  flex-shrink: 0;
  background:
    linear-gradient(145deg, #149090 0%, #0b5555 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.28);
  position: relative;
}
.mark::after {
  content: "";
  position: absolute;
  inset: 11px 9px 11px 9px;
  border: 2px solid rgba(255,255,255,0.9);
  border-radius: 99px;
  border-left-color: transparent;
  transform: rotate(-40deg);
}

.side-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem;
  box-shadow: var(--shadow);
}
.side-block.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-block h2 {
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  letter-spacing: -0.01em;
}
.side-note {
  margin: 0;
  padding: 0 0.35rem;
  color: var(--soft);
  font-size: 0.78rem;
  line-height: 1.35;
}

.pair-box {
  margin-top: 0.85rem;
  padding: 0.85rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid #b7d9d9;
  text-align: center;
}
.pair-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.pair-box strong {
  display: block;
  font-family: var(--display);
  font-size: 1.85rem;
  letter-spacing: 0.22em;
  margin: 0.35rem 0 0.45rem;
  color: var(--accent);
}
.pair-box .hint { margin: 0 0 0.65rem; }
code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.78rem;
  word-break: break-all;
}

/* —— Main —— */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1.15rem 1.35rem 1.5rem;
  gap: 0.85rem;
}
.main-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.main-head h2 {
  font-family: var(--display);
  font-size: clamp(1.35rem, 2.2vw, 1.7rem);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.03em;
}
.lead { color: var(--muted); margin: 0.25rem 0 0; font-size: 0.92rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 0.55rem;
}
.stat {
  min-width: 100px;
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.stat b {
  display: block;
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.stat span { color: var(--muted); font-size: 0.78rem; }

/* —— Tabs —— */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
.tab {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 0.9rem;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); background: rgba(15, 23, 32, 0.04); }
.tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 23, 32, 0.08);
}

.tab-panels { flex: 1; min-height: 0; }
.tab-panel { display: none; gap: 0.85rem; }
.tab-panel.active { display: grid; }

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
}
.block h3 {
  font-family: var(--display);
  font-size: 0.98rem;
  font-weight: 600;
  margin: 0 0 0.65rem;
  letter-spacing: -0.01em;
}
.block h3 + .hint,
.block .hint { margin-top: -0.35rem; margin-bottom: 0.75rem; }
.block-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.block-head h3 { margin-bottom: 0.2rem; }
.block-head .hint { margin: 0; }
.block-head.flat {
  margin: 0 0 0.35rem;
  padding: 0 0.15rem;
  align-items: center;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }
.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
}
.form-inline label { margin: 0; flex: 1; min-width: 160px; }
.form-inline label.grow { flex: 1 1 220px; min-width: 180px; }
.shot-panel .block-head { margin-bottom: 0.85rem; }
.shot-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}
.status-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.status-pill.on { background: var(--ok-bg); color: var(--ok); }
.status-pill.off { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.interval-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.55rem 0.2rem 0.65rem;
}
.interval-chip input {
  width: 52px;
  padding: 0.2rem 0.25rem;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}
.shot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 0;
  margin-bottom: 0.65rem;
}
.shot-chips:empty { display: none; }
.shot-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.35rem 0.28rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid #9ecfcf;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}
.shot-chip button {
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font-size: 0.85rem;
  line-height: 1;
  border: 0;
}
.shot-chip button:hover { background: rgba(13, 110, 110, 0.12); }
.shot-picker {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
  margin-bottom: 1rem;
}
.shot-picker-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.shot-picker-bar input[type="search"] {
  flex: 1 1 160px;
  min-width: 140px;
  margin: 0;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  font: inherit;
}
.shot-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.shot-app-list {
  display: grid;
  gap: 0;
  max-height: 220px;
  overflow: auto;
}
.shot-app {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.65rem;
  align-items: start;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: #fff;
}
.shot-app:last-child { border-bottom: 0; }
.shot-app:hover { background: var(--surface-2); }
.shot-app:has(input:checked) { background: var(--accent-soft); }
.shot-app input {
  margin-top: 0.2rem;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.shot-app .label { font-weight: 600; font-size: 0.9rem; color: var(--ink); display: block; }
.shot-app .pkg { font-size: 0.74rem; color: var(--muted); word-break: break-all; }
.shot-app.hidden-by-filter { display: none; }
.shot-gallery-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-bottom: 0.55rem;
}
.shot-gallery-head h3 { margin: 0; flex: 1 1 auto; }
.shot-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.55rem;
}
.shot-empty {
  grid-column: 1 / -1;
  padding: 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
}
.shot-thumb {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #111;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.shot-thumb:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.shot-thumb img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  display: block;
  background: #1a232c;
}
.shot-thumb span {
  display: block;
  padding: 0.4rem 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: #fff;
  border-top: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

label {
  display: grid;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
}
input[type="text"],
input[type="time"],
input[type="number"] {
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: #fff;
  width: 100%;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 110, 110, 0.15);
}

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 9px;
  padding: 0.62rem 0.9rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
button.ghost:hover:not(:disabled) { background: var(--surface-2); }
button.compact { padding: 0.42rem 0.7rem; font-size: 0.84rem; }

.hint { color: var(--muted); font-size: 0.84rem; }
.status-line {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
  min-height: 1.2em;
}
.hidden { display: none !important; }

/* —— Devices —— */
.device-list {
  display: grid;
  gap: 0.45rem;
  overflow: auto;
  flex: 1;
}
.device-list.empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0.35rem 0;
}
.device-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: stretch;
}
.device {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.55rem;
  padding: 0.7rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  font-weight: 500;
  width: 100%;
}
.device:hover { border-color: var(--line-strong); background: #fff; }
.device.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(13, 110, 110, 0.2);
}
.device .name { font-weight: 600; font-size: 0.92rem; }
.device .meta { color: var(--muted); font-size: 0.78rem; grid-column: 1 / -1; }
.device-del {
  align-self: center;
  color: var(--danger) !important;
  border-color: #e8c5c1 !important;
  min-width: 44px;
}
.device-del:hover:not(:disabled) {
  background: #fdf2f0 !important;
}
.pill {
  align-self: start;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.pill.on { background: var(--ok-bg); color: var(--ok); }
.pill.off { background: var(--warn-bg); color: var(--warn); }

/* —— Lists —— */
.usage-list,
.scroll-list,
.rules-list,
.alert-list {
  display: grid;
  gap: 0.4rem;
}
.scroll-list {
  max-height: 280px;
  overflow: auto;
  padding-right: 0.15rem;
}
.scroll-list.tall { max-height: 360px; }

.usage-item,
.alert-item,
.rule-item {
  display: flex;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.88rem;
}
.usage-bar {
  height: 5px;
  border-radius: 99px;
  background: #dde6ee;
  margin-top: 0.35rem;
  overflow: hidden;
}
.usage-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #0d6e6e, #1a9a8f);
}
.location-box {
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--surface-2);
}
.location-map {
  height: 220px;
  width: 100%;
  background: #dce4ec;
}
.location-map.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}
.location-meta {
  padding: 0.65rem 0.8rem;
  font-size: 0.88rem;
  border-top: 1px solid var(--line);
}
.location-meta a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.location-meta a:hover { text-decoration: underline; }
.location-meta .coords {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.84rem;
}
.leaflet-container { font: inherit; }

.media-frame {
  border-radius: var(--radius-sm);
  background:
    linear-gradient(135deg, #1a232c 0%, #0f1419 100%);
  border: 1px solid #2a3540;
  overflow: auto;
  display: grid;
  place-items: center;
  min-height: 240px;
  max-height: min(85vh, 1200px);
}
.media-frame img {
  width: 100%;
  height: auto;
  max-height: min(85vh, 1200px);
  object-fit: contain;
  object-position: center;
  display: block;
}
.live-frame { position: relative; }
.live-badge {
  position: absolute;
  top: 0.65rem;
  left: 0.65rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(15, 23, 32, 0.72);
  color: #fff;
  letter-spacing: 0.02em;
}
.live-badge.on { background: rgba(26, 127, 90, 0.9); }
.screen-controls { flex-wrap: wrap; }
.video-progress {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 0.88rem;
}
.video-progress.hidden { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 12, 16, 0.88);
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 1rem 1rem 0.75rem;
  gap: 0.75rem;
}
.lightbox.hidden { display: none; }
.lb-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.lb-nav {
  position: absolute;
  top: 40%;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1.8rem;
  cursor: pointer;
}
.lb-prev { left: 0.75rem; }
.lb-next { right: 0.75rem; }
.lb-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  gap: 0.55rem;
}
.lb-stage img {
  max-width: min(96vw, 1100px);
  max-height: calc(100vh - 180px);
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  background: #111;
}
.lb-meta {
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
}
.lb-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.lb-actions .ghost,
.lb-actions a {
  background: rgba(255,255,255,0.1) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,0.2) !important;
  text-decoration: none;
}
.lb-film {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0.35rem 0.25rem 0.75rem;
  scrollbar-width: thin;
}
.lb-film button {
  flex: 0 0 auto;
  width: 88px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #111;
  cursor: pointer;
}
.lb-film button.active { border-color: #5ecfcf; }
.lb-film img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}

audio {
  width: 100%;
  margin: 0.35rem 0 0.65rem;
  height: 36px;
}

.rule-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: end;
  margin-bottom: 0.65rem;
}
.rule-form label { margin: 0; }

.foot {
  margin-top: auto;
  padding-top: 0.35rem;
  color: var(--soft);
  font-size: 0.8rem;
  text-align: center;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 32, 0.55);
  backdrop-filter: blur(6px);
}
.auth-gate.hidden { display: none; }
.auth-card {
  width: min(420px, 92vw);
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.75rem;
}
.auth-card h1 {
  font-family: var(--display);
  margin: 0;
  font-size: 1.4rem;
}
.schema-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.65rem;
}
.schema-node {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.9rem;
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}
.schema-node.root {
  grid-column: 1 / -1;
  background: var(--accent-soft);
  border-color: #b7d9d9;
}
.schema-node strong { font-size: 0.92rem; }
.schema-node span {
  font-family: var(--display);
  font-weight: 700;
  color: var(--accent);
}
.schema-ext { margin-top: 1rem; }
.schema-ext h4 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.schema-ext-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ext-pill {
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: #eef3f7;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
}
.docs-list { display: grid; gap: 0.45rem; }
.doc-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.doc-actions { display: flex; gap: 0.45rem; align-items: center; flex-shrink: 0; }
.doc-badge {
  font-size: 0.72rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: #eef3f7;
  color: var(--muted);
}
.doc-badge.on { background: var(--ok-bg); color: var(--ok); }
#docsFilter {
  min-width: 180px;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.folder-tree {
  max-height: min(70vh, 720px);
  overflow: auto;
  padding: 0.35rem 0.25rem 0.75rem;
  font-size: 0.9rem;
}
.folder-tree ul {
  list-style: none;
  margin: 0;
  padding: 0 0 0 1.05rem;
  border-left: 1px solid var(--line);
}
.folder-tree > ul.tree-root {
  padding-left: 0;
  border-left: 0;
}
.tree-node { margin: 0.1rem 0; }
.tree-node details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.22rem 0.35rem;
  border-radius: 6px;
}
.tree-node details > summary::-webkit-details-marker { display: none; }
.tree-node details > summary:hover { background: var(--accent-soft); }
.tree-leaf {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0.35rem;
  border-radius: 6px;
}
.tree-leaf:hover { background: var(--surface-2); }
.tree-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}
.tree-ico {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  flex-shrink: 0;
}
.tree-ico.dir {
  background: var(--accent);
  opacity: 0.85;
}
.tree-ico.file {
  background: var(--line-strong);
  border-radius: 1px;
}
.tree-more {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.2rem 0.35rem;
  font-style: italic;
}
.tree-leaf { cursor: pointer; }
.tree-open {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.75rem;
  cursor: pointer;
  margin-left: 0.35rem;
}

.file-browser {
  margin-top: 0.75rem;
  max-height: min(55vh, 560px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.file-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  width: 100%;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
}
.file-row:hover { background: var(--accent-soft); }
.file-row .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .meta { color: var(--muted); font-size: 0.78rem; }

.key-log {
  max-height: min(65vh, 680px);
  overflow: auto;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
}
.key-chunk {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.key-chunk .head {
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.key-chunk .when { color: var(--soft); font-size: 0.75rem; font-weight: 400; margin-left: 0.4rem; }
.key-chunk pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
}

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .stats { width: 100%; }
  .main { padding: 1rem; }
  .doc-row { flex-direction: column; align-items: flex-start; }
}
