:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1a1d23;
  --muted: #5c6570;
  --line: #e2e6eb;
  --accent: #1f6f5b;
  --accent-soft: #e6f3ef;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --danger: #9b2c2c;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.app-header h1 {
  margin: 0 0 .25rem;
  font-size: 1.25rem;
  font-weight: 700;
}
.app-header p {
  margin: 0;
  color: var(--muted);
  font-size: .9rem;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .85rem;
  align-items: center;
}
.toolbar input[type="search"],
.toolbar select {
  font: inherit;
  padding: .45rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-width: 10rem;
}
.toolbar input[type="search"] { flex: 1; min-width: 12rem; max-width: 28rem; }
.stats-pill {
  font-size: .8rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .3rem .7rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 0;
  min-height: calc(100vh - 120px);
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); max-height: 40vh; }
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: .75rem;
}
.nav-section { margin-bottom: .75rem; }
.nav-section h2 {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: .5rem .4rem .35rem;
}
.nav-std {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: .45rem;
  overflow: hidden;
  background: #fff;
}
.nav-std > button {
  width: 100%;
  text-align: left;
  border: 0;
  background: #fafbfc;
  padding: .55rem .65rem;
  font: inherit;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  align-items: flex-start;
}
.nav-std > button:hover { background: var(--accent-soft); }
.nav-std.active > button { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-std .std-id { font-family: var(--mono); font-size: .8rem; }
.nav-std .std-meta { font-size: .72rem; color: var(--muted); font-weight: 400; }
.badge {
  display: inline-block;
  font-size: .65rem;
  padding: .1rem .35rem;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  text-transform: uppercase;
}
.badge.ext { background: var(--accent-soft); color: var(--accent); border-color: #b7d9ce; }
.badge.int { background: #eef0f3; }

.topic-list { list-style: none; margin: 0; padding: 0 .25rem .4rem; display: none; }
.nav-std.open .topic-list { display: block; }
.topic-list li button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: .4rem .55rem;
  font: inherit;
  font-size: .88rem;
  cursor: pointer;
  border-radius: 6px;
  color: var(--ink);
}
.topic-list li button:hover { background: var(--bg); }
.topic-list li button.selected { background: var(--accent); color: #fff; }
.topic-list .sub { display: block; font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.topic-list li button.selected .sub { color: rgba(255,255,255,.85); }
.qcount {
  float: right;
  font-size: .72rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: .05rem .4rem;
}
.topic-list li button.selected .qcount { background: rgba(255,255,255,.2); color: #fff; }

.main {
  padding: 1rem 1.25rem 2rem;
  overflow: auto;
}
.breadcrumb {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: .75rem;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}
.panel h2 { margin: 0 0 .25rem; font-size: 1.15rem; }
.panel .notes { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }

.empty {
  color: var(--muted);
  padding: 2rem 1rem;
  text-align: center;
}
.empty.internal {
  background: var(--warn-soft);
  border-radius: var(--radius);
  color: var(--warn);
}

.q-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.q-table th, .q-table td {
  text-align: left;
  padding: .55rem .45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.q-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.q-table tr { cursor: pointer; }
.q-table tr:hover td { background: var(--accent-soft); }
.q-table .year { font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.q-table .qlabel { font-family: var(--mono); white-space: nowrap; }
.legacy { font-size: .75rem; color: var(--muted); }
.conf {
  font-size: .7rem;
  text-transform: uppercase;
  padding: .1rem .35rem;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.conf.high { background: #e7f6ec; color: #1b6b3a; }
.conf.medium { background: var(--warn-soft); color: var(--warn); }
.conf.low { background: #fde8e8; color: var(--danger); }

/* Modal viewer */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,24,30,.55);
  z-index: 50;
  display: none;
  align-items: stretch;
  justify-content: center;
  padding: .75rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 12px;
  width: min(1100px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal-header {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  padding: .65rem .85rem;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.modal-header h3 {
  margin: 0;
  font-size: 1rem;
  flex: 1;
  min-width: 12rem;
}
.modal-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.btn {
  font: inherit;
  font-size: .85rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: .35rem .65rem;
  cursor: pointer;
  color: var(--ink);
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.linkish { text-decoration: none; display: inline-flex; align-items: center; }
.modal-body { flex: 1; min-height: 0; background: #525659; }
.modal-body iframe {
  width: 100%;
  height: 100%;
  min-height: 70vh;
  border: 0;
  background: #525659;
}
.snip-note {
  font-size: .75rem;
  color: var(--muted);
  padding: .35rem .85rem;
  border-top: 1px solid var(--line);
  background: #fff;
}

.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: .75rem;
  margin-top: .75rem;
}
.home-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .85rem;
  background: #fff;
  cursor: pointer;
}
.home-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.home-card h3 { margin: 0 0 .35rem; font-size: 1rem; }
.home-card p { margin: 0; font-size: .85rem; color: var(--muted); }

.footer-note {
  margin-top: 1.5rem;
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
}
