:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --border: #e3e3e8;
  --text: #1d1d22;
  --muted: #6b6b76;
  --accent: #6a3df0;
  --accent-soft: #efe9ff;
  --danger: #c4314b;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.topbar-actions { display: flex; gap: 8px; }

.layout { flex: 1; display: flex; min-height: 0; }
.nav {
  width: 280px; flex-shrink: 0; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--border); padding: 8px 0;
}
.main { flex: 1; overflow-y: auto; padding: 24px 32px 64px; }

.btn {
  display: inline-block; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: var(--text); font: inherit; font-size: 14px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #c8c8d0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.add { margin-top: 8px; }

.muted { color: var(--muted); }
.pad { padding: 8px 16px; }
.error { color: var(--danger); }

/* Nav */
.family { border-bottom: 1px solid var(--border); }
.family summary {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; cursor: pointer;
  font-weight: 600; list-style: none;
}
.family summary::-webkit-details-marker { display: none; }
.family summary::before { content: "▸"; color: var(--muted); font-size: 12px; transition: transform .15s; }
.family[open] summary::before { transform: rotate(90deg); }
.family-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 0 8px; }
.family ul { list-style: none; margin: 0; padding: 0 0 6px; }
.family li a {
  display: grid; grid-template-columns: auto 1fr; column-gap: 8px;
  padding: 5px 16px 5px 34px; color: var(--text); text-decoration: none; font-size: 14px;
}
.family li a:hover { background: var(--bg); }
.family li a.active { background: var(--accent-soft); }
.ver { font-weight: 600; color: var(--accent); }
.vname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vdate { grid-column: 2; font-size: 12px; color: var(--muted); }

/* Main views */
.empty { max-width: 560px; margin: 60px auto; text-align: center; }
.view-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.view-head h1 { margin: 0 0 4px; font-size: 24px; }
.view-head p { margin: 0; }
.description { margin: 4px 0 8px !important; max-width: 70ch; white-space: pre-wrap; color: var(--text); }
.notice {
  display: inline-block; margin: 0 0 8px !important; padding: 4px 10px; border-radius: 6px;
  background: #fff6e0; color: #7a5600; font-size: 13px;
}
.badge {
  font-size: 13px; vertical-align: middle; background: var(--accent-soft); color: var(--accent);
  padding: 2px 8px; border-radius: 10px;
}
.meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.share {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.share-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); margin-right: 2px;
}
.btn.small { padding: 3px 8px; font-size: 12px; }

.section-title {
  display: flex; align-items: center; gap: 8px; margin: 8px 0 12px;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}

.block {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px 20px; margin-bottom: 16px;
}
.block-label { margin: 0 0 8px; font-size: 16px; color: var(--accent); }
.block.editing { padding: 12px; }
.block-toolbar { display: flex; gap: 6px; margin-bottom: 8px; }
.label-input, .field input, .field textarea {
  flex: 1; padding: 8px 10px; font: inherit; border: 1px solid var(--border); border-radius: 6px;
}
.label-input { font-weight: 600; }
.icon {
  width: 34px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel);
  cursor: pointer; color: var(--muted);
}
.icon:hover { color: var(--text); }
.icon.danger:hover { color: var(--danger); border-color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; font-weight: 600; }
.field input { font-size: 17px; }
.field textarea { font-weight: normal; resize: vertical; }

.build {
  position: fixed; right: 10px; bottom: 8px; z-index: 10; pointer-events: none;
  font-size: 11px; color: var(--muted); background: var(--bg);
  padding: 2px 6px; border-radius: 4px; opacity: 0.8;
}

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .nav { width: auto; max-height: 35vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .main { padding: 16px; }
  .view-actions, .share { align-items: flex-start; justify-content: flex-start; }
}
