:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11,11,11,0.10);
  --border-strong: rgba(11,11,11,0.22);

  --tag-hk: #2a78d6;
  --tag-hk-bg: #eaf2fc;
  --tag-rwr: #eb6834;
  --tag-rwr-bg: #fdece4;
  --tag-lux: #4a3aa7;
  --tag-lux-bg: #eeecfa;

  --status-good: #0ca30c;
  --status-good-bg: #e7f7e7;
  --status-critical: #d03b3b;
  --status-critical-bg: #fbeaea;
  --status-muted-bg: #f0efec;

  --box-gray: #f3f2ef;
  --box-gray-border: #b9b7ae;
  --box-orange-border: #eb6834;
  --box-lp-bg: #eaf2fc;
  --box-lp-border: #2a78d6;
  --box-outline-border: #c3c2b7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-1);
  border-bottom: 1px solid var(--gridline);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--gridline);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.tab-btn:hover { border-color: var(--border-strong); color: var(--text-primary); }
.tab-btn.active {
  background: var(--text-primary);
  color: #fff;
  border-color: var(--text-primary);
}

.main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; }

.struct-header { margin-bottom: 6px; }
.struct-header h1 { font-size: 16px; margin: 0 0 2px; }
.struct-header p { font-size: 13px; color: var(--text-secondary); margin: 0; max-width: 900px; }

.legend { display: flex; gap: 16px; margin: 14px 0; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-secondary); }
.legend-chip {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 6px; border-radius: 4px; color: #fff;
}

.canvas-wrap {
  border: 1px solid var(--gridline);
  border-radius: 12px;
  background: var(--surface-1);
  overflow: auto;
  box-shadow: 0 1px 2px rgba(11,11,11,0.04);
}
.canvas { position: relative; width: 100%; min-width: 1000px; }
.edges { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.edges path { fill: none; stroke: #b9b7ae; stroke-width: 1.5; }
.edges polygon { fill: #b9b7ae; }

.node {
  position: absolute;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.node:hover { box-shadow: 0 4px 14px rgba(11,11,11,0.12); transform: translateY(-1px); z-index: 5; }

.node.gray { background: var(--box-gray); border: 1px solid var(--box-gray-border); }
.node.gray-key { background: var(--box-gray); border: 2px solid var(--text-primary); }
.node.outline { background: var(--surface-1); border: 1px solid var(--box-outline-border); }
.node.orange { background: var(--surface-1); border: 1.5px solid var(--box-orange-border); }
.node.orange-key { background: #fff9f6; border: 2.5px solid var(--box-orange-border); }
.node.lp { background: var(--box-lp-bg); border: 1px solid var(--box-lp-border); }

.node-label { font-size: 12.5px; font-weight: 700; line-height: 1.25; color: var(--text-primary); }
.node-sublabel { font-size: 10.5px; color: var(--text-secondary); line-height: 1.25; margin-top: 3px; }

.node-tags { position: absolute; top: -8px; right: 8px; display: flex; gap: 4px; }
.node-tag {
  font-size: 9px; font-weight: 800; letter-spacing: 0.03em;
  padding: 2px 6px; border-radius: 4px; color: #fff;
  box-shadow: 0 1px 2px rgba(11,11,11,0.15);
}
.node-tag.HK { background: var(--tag-hk); }
.node-tag.RWR { background: var(--tag-rwr); }
.node-tag.LUX { background: var(--tag-lux); }

.doc-icon {
  position: absolute;
  bottom: -9px;
  right: -9px;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  border: 1.5px solid var(--surface-1);
  box-shadow: 0 1px 3px rgba(11,11,11,0.2);
}
.doc-icon.real { background: var(--status-good); color: #fff; }
.doc-icon.placeholder { background: var(--text-muted); color: #fff; }
.doc-icon.flagged { background: var(--status-critical); color: #fff; }

.scrim {
  position: fixed; inset: 0; background: rgba(11,11,11,0.35);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 30;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: min(560px, 92vw);
  background: var(--surface-1);
  box-shadow: -8px 0 28px rgba(11,11,11,0.18);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 31;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-close {
  position: sticky; top: 12px; float: right; margin-right: 14px;
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--gridline);
  background: var(--surface-1); font-size: 18px; cursor: pointer; color: var(--text-secondary);
  z-index: 2;
}
.drawer-content { padding: 20px 26px 60px; clear: both; }

.doc-status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
  margin-bottom: 12px;
}
.doc-status-badge.real { background: var(--status-good-bg); color: #0a7a0a; }
.doc-status-badge.placeholder { background: var(--status-muted-bg); color: var(--text-secondary); }

.drawer-title { font-size: 17px; font-weight: 700; line-height: 1.3; margin: 4px 0 4px; }
.drawer-type { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 2px; }
.drawer-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }

.drawer-section-title {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin: 20px 0 8px;
}
.drawer-summary { font-size: 13.5px; line-height: 1.55; color: var(--text-primary); }

.term-row { padding: 10px 0; border-top: 1px solid var(--gridline); }
.term-row:first-child { border-top: none; }
.term-label { font-size: 11.5px; font-weight: 700; color: var(--text-secondary); margin-bottom: 3px; }
.term-value { font-size: 13px; line-height: 1.5; color: var(--text-primary); }

.flag-box {
  background: var(--status-critical-bg);
  border: 1px solid rgba(208,59,59,0.25);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #7a2323;
  margin-bottom: 8px;
}

.file-links { display: flex; flex-direction: column; gap: 8px; }
.file-link {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  text-decoration: none; padding: 10px 12px;
  border: 1px solid var(--gridline); border-radius: 8px;
  background: var(--surface-1);
}
.file-link:hover { border-color: var(--border-strong); background: var(--status-muted-bg); }

.placeholder-note {
  font-size: 13px; color: var(--text-secondary); line-height: 1.55;
  background: var(--status-muted-bg); border-radius: 8px; padding: 12px 14px;
}

.doc-divider { height: 1px; background: var(--gridline); margin: 26px 0; }

.footer {
  text-align: center; font-size: 11.5px; color: var(--text-muted);
  padding: 20px 24px 40px;
}

@media (max-width: 720px) {
  .brand-sub { display: none; }
}

/* Password gate */
html.locked .topbar,
html.locked .main,
html.locked .footer {
  display: none;
}
.gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  background: var(--page);
}
html.locked .gate {
  display: flex;
}
.gate-box {
  width: min(360px, 88vw);
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(11,11,11,0.10);
  padding: 28px 26px 24px;
  text-align: center;
}
.gate-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.gate-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; }
.gate-input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  margin-bottom: 12px;
  background: var(--surface-1);
  color: var(--text-primary);
}
.gate-input:focus { outline: 2px solid var(--tag-hk); outline-offset: 1px; }
.gate-submit {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--text-primary);
  color: #fff;
  cursor: pointer;
}
.gate-submit:hover { opacity: 0.9; }
.gate-error {
  display: none;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--status-critical);
}
