/* ── Annotation tool styles ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f5f5f5;
  color: #222;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

#app {
  display: flex; flex-direction: column; flex: 1;
  overflow: hidden; height: 100vh;
}

/* ── login overlay ────────────────────────────────────────────────── */
#login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: #f5f5f5;
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 36px 40px;
  width: 440px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}
.login-box h2 { text-align: center; font-size: 22px; }
.login-box p { text-align: center; color: #777; font-size: 13px; }
.login-box input[type="text"],
.login-box select {
  width: 100%; padding: 8px 10px; font-size: 14px;
  border: 1px solid #ccc; border-radius: 6px;
}
.login-box label { font-size: 12px; color: #666; display: flex; flex-direction: column; gap: 4px; }
.login-box button {
  padding: 10px; font-size: 14px; font-weight: 700;
  background: #2563eb; color: #fff; border: none; border-radius: 6px;
  cursor: pointer;
}
.login-box button:hover { background: #1d4ed8; }
.login-msg { font-size: 12px; color: #888; text-align: center; min-height: 1.4em; }

/* ── existing annotations list ────────────────────────────────────── */
#existing-annos { border-top: 1px solid #e8e8e8; padding-top: 12px; }
#existing-annos h3 { font-size: 13px; color: #555; margin-bottom: 8px; }
.anno-loading { font-size: 12px; color: #999; }
#anno-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.anno-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 6px;
  cursor: pointer; font-size: 13px; background: #fafafa;
  transition: background 0.15s;
}
.anno-row:hover { background: #eef2ff; border-color: #93a8f0; }
.anno-row .anno-doc { font-weight: 600; flex-shrink: 0; }
.anno-row .anno-who { color: #555; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.anno-row .anno-seed {
  flex: 1; min-width: 0; color: #2e8a3a; font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.anno-row .anno-prog { flex-shrink: 0; }
.anno-row .anno-del {
  flex-shrink: 0; padding: 2px 6px; font-size: 12px; line-height: 1;
  border: 1px solid transparent; border-radius: 4px; background: transparent;
  cursor: pointer; color: #aaa;
}
.anno-row .anno-del:hover { background: #e6194b15; color: #c4163f; border-color: #e6194b55; }
.anno-prog-bar {
  display: inline-block; width: 60px; height: 8px; background: #e0e0e0;
  border-radius: 4px; vertical-align: middle; margin-right: 4px; overflow: hidden;
}
.anno-prog-fill {
  height: 100%; background: #22c55e; border-radius: 4px;
}
.anno-empty { font-size: 12px; color: #999; font-style: italic; }

/* ── toolbar ──────────────────────────────────────────────────────── */
#toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: #fff; border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.back-btn {
  text-decoration: none; font-size: 20px; color: #555;
  padding: 2px 8px; border-radius: 4px;
}
.back-btn:hover { background: #eee; }
.app-title { font-weight: 700; font-size: 15px; }
.toolbar-info { font-size: 12px; color: #666; flex: 1; }
.toolbar-progress { font-size: 12px; font-weight: 600; color: #2563eb; }
.btn-mode {
  padding: 4px 10px; font-size: 12px; border: 1px solid #ccc;
  border-radius: 4px; background: #fff; cursor: pointer;
}
.btn-mode.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-sm {
  padding: 4px 10px; font-size: 11px; border: 1px solid #ccc;
  border-radius: 4px; background: #fff; cursor: pointer; color: #666;
}

/* ── progress bar ─────────────────────────────────────────────────── */
#progress-bar {
  height: 3px; background: #eee; flex-shrink: 0;
}
#progress-fill {
  height: 100%; background: #2563eb; width: 0%;
  transition: width 0.3s;
}

/* ── global notes ─────────────────────────────────────────────────── */
#global-notes-bar {
  padding: 8px 16px; background: #fafafa; border-bottom: 1px solid #eee;
  flex-shrink: 0;
}
#global-notes-bar label { font-size: 11px; color: #888; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
#global-notes {
  width: 100%; margin-top: 4px; padding: 6px 10px; font-size: 13px;
  border: 1px solid #ddd; border-radius: 4px; resize: vertical;
  font-family: inherit;
}

/* ── policy list ──────────────────────────────────────────────────── */
#policy-list { padding: 8px 12px; }

/* ── main split pane ──────────────────────────────────────────────── */
#main {
  flex: 1; display: flex; overflow: hidden;
}
#doc-pane {
  flex: 3; min-width: 200px; overflow-y: auto; 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; }
.doc-line.hl { background: rgba(255, 213, 50, 0.18); }
.doc-line.hl-anchor { background: rgba(255, 190, 30, 0.32); }

/* range brackets */
#range-brackets {
  position: absolute; top: 0; left: 0; width: 0; height: 100%;
  pointer-events: none; z-index: 2;
}
.range-bar {
  position: absolute; width: 6px; border-radius: 4px;
  cursor: pointer; pointer-events: auto;
  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; }
.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; }

/* gutter */
#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: 0;
}
.policy-card.selected { border-color: #4363d8; box-shadow: 0 0 0 2px #4363d833; }

/* line links */
.line-link { color: #4363d8; text-decoration: none; cursor: pointer; }
.line-link:hover { text-decoration: underline; }

/* ── policy card ──────────────────────────────────────────────────── */
.policy-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 8px;
  transition: border-color 0.15s, opacity 0.2s;
}
.policy-card.status-approved { border-left: 4px solid #3cb44b; }
.policy-card.status-deleted  { border-left: 4px solid #e6194b; opacity: 0.55; }
.policy-card.status-split    { border-left: 4px solid #f58231; }
.policy-card.status-merged   { border-left: 4px solid #4363d8; }

/* merged group visual */
.merge-group {
  border: 2px solid #4363d888;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 8px;
  background: #4363d808;
}
.merge-group .merge-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; font-size: 11px; color: #4363d8; font-weight: 600;
}
.merge-group .merge-group-header .merge-undo {
  font-size: 11px; color: #999; cursor: pointer; margin-left: auto;
}
.merge-group .merge-group-header .merge-undo:hover { color: #e6194b; }
.merge-group .policy-card { margin-bottom: 4px; }
.merge-group .policy-card:last-child { margin-bottom: 0; }

.pc-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer; user-select: none;
}
.pc-header .pc-idx {
  flex-shrink: 0; font-size: 11px; color: #aaa; font-weight: 600; width: 24px;
}
.pc-header .pc-flag { flex-shrink: 0; font-size: 16px; line-height: 1; }
.pc-header .pc-icon { flex-shrink: 0; font-size: 16px; }
.pc-header .pc-title { flex: 1; font-size: 13px; font-weight: 600; }
.pc-header .pc-status-badge {
  flex-shrink: 0; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; padding: 2px 6px; border-radius: 3px;
}
.pc-status-badge.badge-pending   { background: #f5f5f5; color: #999; }
.pc-status-badge.badge-approved  { background: #3cb44b22; color: #2e8a3a; }
.pc-status-badge.badge-deleted   { background: #e6194b22; color: #c4163f; }
.pc-status-badge.badge-split     { background: #f5823122; color: #c46a28; }
.pc-status-badge.badge-merged    { background: #4363d822; color: #3352b0; }

/* merge-mode checkbox */
.pc-header .pc-merge-cb {
  flex-shrink: 0; width: 18px; height: 18px; cursor: pointer;
  accent-color: #4363d8;
}

.pc-body {
  padding: 0 14px 10px 14px;
  border-top: 1px solid #f0f0f0;
}
.policy-card.collapsed .pc-body { display: none; }

.pc-fields { font-size: 12.5px; line-height: 1.6; margin-bottom: 10px; }
.pc-fields .field { margin-bottom: 2px; }
.pc-fields .field-label { color: #888; font-weight: 600; }
.area-badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 11px; font-weight: 600;
}
.country-badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 11px; font-weight: 600;
  background: #4363d818; color: #3352b0;
}

/* action buttons */
.pc-actions {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding-top: 8px; border-top: 1px solid #f0f0f0;
}
.pc-actions button {
  padding: 4px 10px; font-size: 11px; border-radius: 4px;
  border: 1px solid #ccc; background: #fff; cursor: pointer;
  font-weight: 600;
}
.pc-actions button:hover { background: #f5f5f5; }
.pc-actions button.act-approve { color: #2e8a3a; border-color: #3cb44b55; }
.pc-actions button.act-approve:hover { background: #3cb44b15; }
.pc-actions button.act-delete  { color: #c4163f; border-color: #e6194b55; }
.pc-actions button.act-delete:hover  { background: #e6194b15; }
.pc-actions button.act-split   { color: #c46a28; border-color: #f5823155; }
.pc-actions button.act-split:hover   { background: #f5823115; }
.pc-actions button.act-undo    { color: #666; }

.pc-actions .note-input {
  flex: 1; min-width: 160px; padding: 4px 8px; font-size: 11px;
  border: 1px solid #ddd; border-radius: 4px; font-family: inherit;
}

.pc-note {
  margin-top: 6px; font-size: 11px; color: #888; font-style: italic;
}

/* ── merge footer ─────────────────────────────────────────────────── */
#merge-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: #fff; border-top: 2px solid #4363d8;
  flex-shrink: 0;
}
#merge-footer span { font-size: 13px; font-weight: 600; color: #4363d8; }
#merge-footer input {
  flex: 1; padding: 6px 10px; font-size: 13px;
  border: 1px solid #ddd; border-radius: 4px;
}
#merge-footer button {
  padding: 6px 14px; font-size: 13px; font-weight: 600;
  border: none; border-radius: 4px; cursor: pointer;
}
#btn-merge-confirm { background: #4363d8; color: #fff; }
#btn-merge-confirm:disabled { opacity: 0.4; cursor: default; }
#btn-merge-cancel { background: #eee; color: #555; }

/* ── excerpt highlighting (exact-substring marks) ─────────────────── */
.excerpt-mark {
  background: rgba(234, 179, 8, 0.32);
  border-bottom: 1.5px solid #eab308;
  border-radius: 2px;
  color: inherit;
  cursor: pointer;
  padding: 0;
}
.excerpt-mark:hover { background: rgba(234, 179, 8, 0.5); }
.excerpt-mark.flash { animation: exc-flash 1.2s ease-out; }
@keyframes exc-flash {
  0%, 40% { background: rgba(234, 179, 8, 0.85); }
  100% { background: rgba(234, 179, 8, 0.32); }
}
.range-bar.range-bar-excerpt { opacity: 0.7; }

/* ── excerpt list (right pane) ────────────────────────────────────── */
#excerpt-section {
  border-bottom: 1px solid #eee; background: #fffdf5;
  padding: 8px 12px;
}
#excerpt-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px; color: #a16207; margin-bottom: 6px;
}
.excerpt-item {
  background: #fff; border: 1px solid #f0e6c0; border-left: 4px solid #eab308;
  border-radius: 6px; padding: 6px 10px; margin-bottom: 6px; cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.excerpt-item:hover { border-color: #eab308; }
.excerpt-item.flash { box-shadow: 0 0 0 2px #eab30899; }
.excerpt-item .exc-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 3px;
}
.exc-lines { font-size: 11px; font-weight: 600; color: #a16207; }
.exc-poltag {
  font-size: 10px; font-weight: 700; color: #2e8a3a;
  background: #3cb44b22; padding: 1px 6px; border-radius: 3px;
}
.exc-actions { margin-left: auto; display: flex; gap: 4px; }
.exc-actions button {
  padding: 2px 7px; font-size: 10px; font-weight: 600;
  border: 1px solid #e0d9b8; border-radius: 4px; background: #fff;
  cursor: pointer; color: #777;
}
.exc-addpol:hover { background: #3cb44b15; color: #2e8a3a; border-color: #3cb44b55; }
.exc-del:hover { background: #e6194b15; color: #c4163f; border-color: #e6194b55; }
.exc-text {
  font-size: 12px; color: #444; line-height: 1.5;
  font-family: "Menlo", "Consolas", "Courier New", monospace;
}

/* ── floating selection toolbar ───────────────────────────────────── */
#sel-toolbar {
  position: fixed; z-index: 200; display: flex; gap: 4px;
  background: #222; padding: 4px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
#sel-toolbar button {
  padding: 5px 10px; font-size: 12px; font-weight: 600;
  border: none; border-radius: 5px; cursor: pointer;
  background: #fff; color: #222;
}
#sel-toolbar button:hover { background: #eab308; color: #222; }

/* ── manual policy form modal ─────────────────────────────────────── */
#exc-form-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
}
.exc-form-box {
  background: #fff; border-radius: 12px; padding: 24px 28px; width: 480px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.exc-form-box h3 { font-size: 16px; }
.exc-form-excerpt {
  font-size: 12px; color: #555; background: #fffdf5;
  border: 1px solid #f0e6c0; border-left: 4px solid #eab308;
  border-radius: 6px; padding: 8px 10px; max-height: 120px; overflow-y: auto;
  font-family: "Menlo", "Consolas", "Courier New", monospace; line-height: 1.5;
}
.exc-form-box label {
  font-size: 12px; color: #666; font-weight: 600;
  display: flex; flex-direction: column; gap: 4px;
}
.exc-form-box input[type="text"],
.exc-form-box textarea {
  width: 100%; padding: 8px 10px; font-size: 13px; font-family: inherit;
  border: 1px solid #ccc; border-radius: 6px; resize: vertical;
}
.exc-form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.exc-form-actions button {
  padding: 8px 16px; font-size: 13px; font-weight: 600;
  border: none; border-radius: 6px; cursor: pointer;
}
#exc-form-cancel { background: #eee; color: #555; }
#exc-form-save { background: #eab308; color: #fff; }
#exc-form-save:hover { background: #ca9a04; }

/* ── manual policy card decorations ───────────────────────────────── */
.policy-card.status-added { border-left: 4px solid #eab308; }
.pc-status-badge.badge-added { background: #eab30822; color: #a16207; }
.pc-manual-tag {
  flex-shrink: 0; font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: #a16207; background: #eab30822;
  padding: 1px 5px; border-radius: 3px;
}
.pc-actions button.act-remove { color: #c4163f; border-color: #e6194b55; }
.pc-actions button.act-remove:hover { background: #e6194b15; }
