/* ── reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #222;
  background: #fafafa;
  display: flex;
  flex-direction: column;
}

/* ── toolbar ──────────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  z-index: 10;
}
.app-title { font-weight: 700; font-size: 16px; margin-right: 8px; }
.back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 6px;
  background: #f0f0f0;
  color: #444;
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
  transition: background 0.15s;
  flex-shrink: 0;
}
.back-btn:hover { background: #ddd; }
#toolbar label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #555; }
#toolbar select {
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  max-width: 280px;
}
.stats { font-size: 12px; color: #888; margin-left: auto; }

/* ── main split ───────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── document pane ────────────────────────────────────────────────── */
#doc-pane {
  flex: 3;
  min-width: 200px;
  overflow-y: auto;
  padding: 0;
  background: #fff;
}
#doc-scroll {
  position: relative;
  min-height: 100%;
}
#doc-lines { padding: 8px 0; }

.doc-line {
  display: flex;
  padding: 0 12px 0 0;
  line-height: 1.6;
  font-family: "Menlo", "Consolas", "Courier New", monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  transition: background 0.15s;
}
.doc-line:hover { background: rgba(0,0,0,0.018); }
.line-no {
  min-width: 42px;
  text-align: right;
  padding-right: 14px;
  color: #bbb;
  user-select: none;
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1.6;
}
.line-text { flex: 1; }

/* ── range brackets gutter ────────────────────────────────────────── */
#range-brackets {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;           /* width set dynamically by JS */
  height: 100%;
  pointer-events: none; /* let clicks pass through the container */
  z-index: 2;
}
.range-bar {
  position: absolute;
  width: 6px;
  border-radius: 4px;
  cursor: pointer;
  pointer-events: auto; /* but bars themselves are clickable */
  opacity: 0.55;
  transition: opacity 0.15s, width 0.12s, filter 0.15s;
}
.range-bar:hover {
  opacity: 0.85;
  width: 9px;
  filter: brightness(1.1);
}
.range-bar.active {
  opacity: 1;
  width: 9px;
}

/* tooltip on hover */
.range-bar::after {
  content: attr(data-title);
  position: absolute;
  left: calc(100% + 6px);
  top: 0;
  background: #333;
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
}
.range-bar:hover::after { opacity: 1; }

/* highlighted lines */
.doc-line.hl {
  background: rgba(255, 213, 50, 0.18);
}
.doc-line.hl-anchor {
  background: rgba(255, 190, 30, 0.32);
}

/* ── gutter (drag handle) ─────────────────────────────────────────── */
#gutter {
  width: 5px;
  cursor: col-resize;
  background: #e8e8e8;
  flex-shrink: 0;
  transition: background 0.15s;
}
#gutter:hover, #gutter.dragging { background: #bbb; }

/* ── policy pane ──────────────────────────────────────────────────── */
#policy-pane {
  flex: 2;
  min-width: 200px;
  overflow-y: auto;
  background: #fafafa;
  padding: 8px 12px;
}

/* ── metadata panel ──────────────────────────────────────────────── */
#metadata-panel {
  border: 1px solid #d4dae2;
  border-radius: 6px;
  background: #f4f7fa;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 12.5px;
  line-height: 1.5;
}
.meta-heading {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7a8d;
  margin-bottom: 6px;
}
.meta-row {
  display: flex;
  gap: 8px;
  margin-bottom: 3px;
}
.meta-label {
  font-weight: 600;
  color: #556;
  min-width: 72px;
  flex-shrink: 0;
}
.meta-value {
  color: #333;
}
.meta-tag {
  display: inline-block;
  background: #e0eaff;
  color: #2a4a8a;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}
.meta-affil {
  color: #777;
  font-size: 12px;
}

/* policy card */
.policy-card {
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-bottom: 6px;
  background: #fff;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.policy-card:hover { border-color: #bbb; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.policy-card.selected {
  border-color: #f5c542;
  box-shadow: 0 0 0 2px rgba(245,197,66,0.25);
}

.policy-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.policy-header .idx {
  color: #aaa;
  font-size: 11px;
  min-width: 22px;
  text-align: right;
  flex-shrink: 0;
}
.policy-header .icon { flex-shrink: 0; }
.policy-header .title {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.policy-header .line-hint {
  font-size: 11px;
  color: #999;
  flex-shrink: 0;
}

/* expanded detail */
.policy-detail {
  display: none;
  padding: 4px 12px 10px 44px;
  font-size: 12.5px;
  line-height: 1.55;
  border-top: 1px solid #f0f0f0;
}
.policy-card.selected .policy-detail { display: block; }
.policy-detail .field { margin-bottom: 3px; }
.policy-detail .field-label { font-weight: 600; color: #555; }
.policy-detail .excerpt {
  margin-top: 6px;
  padding: 6px 10px;
  background: #f7f7f7;
  border-radius: 4px;
  font-size: 12px;
  color: #555;
  max-height: 120px;
  overflow-y: auto;
}

/* area badge */
.area-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

/* ── line-range links ─────────────────────────────────────────────── */
.line-link {
  color: #4363d8;
  text-decoration: none;
  border-bottom: 1px dashed #4363d888;
  cursor: pointer;
  font-size: 12px;
}
.line-link:hover {
  color: #1a3ab5;
  border-bottom-style: solid;
}

/* ── loading state ────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: #999;
  font-size: 13px;
}
