/* === Shared styles for annotation platform === */

:root {
  --color-person: #AEC6CF;
  --color-org: #77DD77;
  --color-gpe: #FFD700;
  --color-norp: #DDA0DD;
  --color-bg: #f8f9fa;
  --color-border: #dee2e6;
  --color-primary: #4a90d9;
  --color-danger: #dc3545;
  --color-success: #28a745;
  --color-warning: #ffc107;
  --color-text: #212529;
  --color-muted: #6c757d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}

/* === Layout === */

.container { max-width: 1400px; margin: 0 auto; padding: 0 20px; }

.toolbar {
  position: sticky; top: 0; z-index: 100;
  background: #fff; border-bottom: 1px solid var(--color-border);
  padding: 10px 20px;
  display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap;
}

.toolbar h1 { font-size: 16px; font-weight: 600; margin-right: auto; }

.toolbar .stage-nav {
  display: flex; gap: 4px;
}

.toolbar .stage-nav a {
  padding: 4px 12px; border-radius: 4px;
  text-decoration: none; color: var(--color-muted);
  font-size: 13px; border: 1px solid var(--color-border);
}

.toolbar .stage-nav a.active {
  background: var(--color-primary); color: #fff; border-color: var(--color-primary);
}

.toolbar .stage-nav a.completed {
  background: var(--color-success); color: #fff; border-color: var(--color-success);
}

.split-layout {
  display: flex; gap: 16px; padding: 16px 0;
  min-height: calc(100vh - 60px);
}

.split-layout .main-panel { flex: 7; min-width: 0; }
.split-layout .side-panel {
  flex: 3; min-width: 280px; max-width: 400px;
  max-height: calc(100vh - 80px); overflow-y: auto;
  position: sticky; top: 60px;
}

/* === Cards === */

.card {
  background: #fff; border: 1px solid var(--color-border);
  border-radius: 8px; padding: 16px; margin-bottom: 12px;
}

.card h3 { font-size: 14px; margin-bottom: 8px; }

/* === Buttons === */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 4px; border: 1px solid var(--color-border);
  background: #fff; color: var(--color-text);
  cursor: pointer; font-size: 13px; font-family: inherit;
  transition: background 0.15s;
}

.btn:hover { background: #f0f0f0; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: #3a7bc8; }
.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: #c82333; }
.btn-success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-sm { padding: 3px 8px; font-size: 12px; }

/* === Entity type colors === */

.ent-PERSON { background: var(--color-person); }
.ent-ORG { background: var(--color-org); }
.ent-GPE { background: var(--color-gpe); }
.ent-NORP { background: var(--color-norp); }
.ent-COREF { background: #B0BEC5; }

/* === Article text with entity spans === */

.article-text {
  background: #fff; padding: 20px; border-radius: 8px;
  border: 1px solid var(--color-border);
  font-size: 15px; line-height: 1.8;
  white-space: pre-wrap; word-wrap: break-word;
  cursor: text;
  user-select: text;
}

.article-text .entity-span {
  padding: 1px 3px; border-radius: 3px;
  cursor: pointer; position: relative;
  border: 2px solid transparent;
}

.article-text .entity-span:hover {
  outline: 2px solid var(--color-primary);
}

.article-text .entity-span.pipeline-pred {
  border-style: dashed;
  opacity: 0.7;
}

.article-text .entity-span.coref-only {
  opacity: 0.65;
  cursor: default;
  border-style: dotted;
  border-color: #90A4AE;
}

.article-text .entity-span.ungrouped {
  border: 2px dashed var(--color-danger);
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 3px,
    rgba(220, 53, 69, 0.08) 3px,
    rgba(220, 53, 69, 0.08) 6px
  );
}

.article-text .entity-span .ent-label {
  font-size: 9px; font-weight: 700;
  vertical-align: super; margin-left: 2px;
  opacity: 0.7;
}

/* === Toggle switch === */

.toggle-wrapper {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
}

.toggle-switch {
  position: relative; width: 40px; height: 22px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-switch .slider {
  position: absolute; inset: 0;
  background: #ccc; border-radius: 22px; cursor: pointer;
  transition: background 0.2s;
}

.toggle-switch .slider::before {
  content: ""; position: absolute;
  width: 16px; height: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .slider { background: var(--color-primary); }
.toggle-switch input:checked + .slider::before { transform: translateX(18px); }

/* === Save indicator === */

.save-indicator {
  font-size: 12px; color: var(--color-muted);
  transition: color 0.2s;
}

.save-indicator.saving { color: var(--color-warning); }
.save-indicator.saved { color: var(--color-success); }
.save-indicator.error { color: var(--color-danger); }

/* === Mention list (side panel) === */

.mention-list { list-style: none; }

.mention-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 4px;
  margin-bottom: 4px; font-size: 13px;
  cursor: pointer;
}

.mention-item:hover { background: #f0f0f0; }

.mention-item .ent-badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 700;
}

.mention-item .mention-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === Popup (for NER type selection) === */

.entity-popup {
  position: fixed; z-index: 200;
  background: #fff; border: 1px solid var(--color-border);
  border-radius: 8px; padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex; gap: 4px;
}

.entity-popup .btn { min-width: 60px; justify-content: center; }

/* === Sentence list (bias stage) === */

.sentence-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--color-border);
  background: #fff;
}

.sentence-row:hover { background: #f8f9fa; }

.sentence-row.low-confidence { border-left: 3px solid var(--color-warning); }
.sentence-row.focused { background: #e8f0fe; }

.sentence-row .sent-index {
  color: var(--color-muted); font-size: 12px;
  min-width: 30px; text-align: right; padding-top: 2px;
}

.sentence-row .sent-text { flex: 1; font-size: 14px; }

.sentence-row .pred-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  white-space: nowrap;
}

.sentence-row .pred-badge.gold { background: #fff3cd; color: #856404; }
.sentence-row .pred-badge.predicted { background: #d1ecf1; color: #0c5460; }

.sentence-row .label-btns { display: flex; gap: 4px; flex-shrink: 0; }

.sentence-row .label-btns .btn.selected-biased {
  background: var(--color-danger); color: #fff; border-color: var(--color-danger);
}

.sentence-row .label-btns .btn.selected-nonbiased {
  background: var(--color-success); color: #fff; border-color: var(--color-success);
}

.sentence-row .label-btns .btn.selected-uncertain {
  background: var(--color-warning); color: #000; border-color: var(--color-warning);
}

/* === Cluster cards (coref stage) === */

.cluster-panel {
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 16px 0;
}

.cluster-card {
  background: #fff; border: 2px solid var(--color-border);
  border-radius: 8px; padding: 10px; width: 240px;
  flex-shrink: 0; overflow: hidden;
}

.cluster-card.active { border-color: var(--color-primary); }

.cluster-card .cluster-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}

.cluster-card .cluster-header input {
  min-width: 0; width: 0; flex: 1;
  border: 1px solid var(--color-border); border-radius: 4px;
  padding: 4px 6px; font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis;
}

.cluster-card .cluster-header .ent-badge { flex-shrink: 0; font-size: 9px; padding: 1px 4px; }
.cluster-card .cluster-header .btn { flex-shrink: 0; padding: 2px 6px; font-size: 11px; }

.cluster-card .mention-pills {
  display: flex; flex-wrap: wrap; gap: 4px;
}

.cluster-card .mention-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px;
  font-size: 12px; cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}

.cluster-card .mention-pill .remove-pill {
  cursor: pointer; font-size: 10px; opacity: 0.6;
}

.cluster-card .mention-pill .remove-pill:hover { opacity: 1; }

/* === Entity bias targeting (legacy card style) === */

.entity-card {
  background: #fff; border: 1px solid var(--color-border);
  border-radius: 8px; padding: 14px; margin-bottom: 10px;
}

.entity-card:hover { border-color: var(--color-primary); }

.entity-card .entity-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}

.entity-card .wiki-info {
  font-size: 12px; color: var(--color-muted); margin-bottom: 8px;
}

.entity-card .bias-options {
  display: flex; flex-direction: column; gap: 6px;
}

.entity-card .bias-options label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; cursor: pointer;
}

.entity-card textarea {
  width: 100%; margin-top: 6px; padding: 6px 8px;
  border: 1px solid var(--color-border); border-radius: 4px;
  font-size: 13px; font-family: inherit; resize: vertical;
}

/* === Entity bias targeting (sentence-centric view) === */

.eb-section {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.eb-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #f8f9fa;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.eb-name { font-size: 15px; }

.eb-stats {
  font-size: 12px;
  color: var(--color-muted);
}

.eb-biased-count { color: var(--color-danger); font-weight: 600; }

.eb-wiki {
  font-size: 11px;
  background: #e9ecef;
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--color-muted);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eb-empty {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--color-muted);
  font-style: italic;
}

/* Paragraph groups */

.eb-para {
  border-bottom: 1px solid var(--color-border);
}

.eb-para:last-child { border-bottom: none; }

.eb-para-has-biased {
  background: #fffcfc;
}

.eb-para-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f0f4f8;
  border-bottom: 1px solid #e4e8ec;
  flex-wrap: wrap;
}

.eb-para-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-primary);
  min-width: 90px;
}

/* Sentence rows */

.eb-sent {
  padding: 10px 16px;
  border-bottom: 1px solid #f0f0f0;
}

.eb-sent:last-child { border-bottom: none; }

.eb-sent-biased {
  border-left: 3px solid var(--color-danger);
  background: #fff8f8;
}

.eb-sent-context {
  opacity: 0.55;
}

.eb-sent-manual-biased {
  border-left: 3px solid var(--color-warning);
  background: #fffdf5;
}

.eb-bias-tag-manual {
  background: var(--color-warning);
  color: #000;
}

.eb-manual-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--color-muted);
  cursor: pointer;
  white-space: nowrap;
  margin-right: 4px;
}

.eb-sent-controls-collapsed {
  padding-left: 36px;
  padding-bottom: 2px;
}

/* Entity cards below sentences (new sentence-first layout) */

.eb-entity-cards {
  margin: 6px 0 4px 36px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.eb-entity-card {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 6px 10px;
  background: #fafbfc;
}

.eb-entity-card-active {
  background: #f4f8ff;
  border-color: #b8d4f0;
}

.eb-entity-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.eb-entity-card-name {
  font-size: 13px;
  font-weight: 600;
}

.eb-entity-card-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid #e8ecf0;
}

.eb-inline-direction,
.eb-inline-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  flex-wrap: wrap;
}

.eb-biased-words-input {
  font-size: 12px;
  padding: 3px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  min-width: 140px;
  max-width: 250px;
}

.eb-entity-card-manual {
  border-style: dashed;
  border-color: #a0c4e8;
  background: #f0f6ff;
}

.eb-remove-link {
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  color: var(--color-muted);
  border: none;
  background: none;
  cursor: pointer;
}
.eb-remove-link:hover { color: #c33; }

.eb-add-entity {
  margin-top: 4px;
}

.eb-add-entity-btn {
  font-size: 12px;
  color: var(--color-muted);
  border: 1px dashed var(--color-border);
  background: transparent;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
}
.eb-add-entity-btn:hover {
  color: #333;
  border-color: #999;
}

.eb-add-entity-select {
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

.eb-create-entity-form {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.eb-create-entity-form input[type="text"] {
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  width: 140px;
}
.eb-create-entity-form select {
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}
.eb-create-entity-confirm {
  font-size: 12px;
  background: #4CAF50;
  color: white;
  border: none;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.eb-create-entity-cancel {
  font-size: 12px;
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}

/* Entity summaries section at bottom */

.eb-summaries-header {
  font-size: 16px;
  margin: 24px 0 12px;
  padding-top: 16px;
  border-top: 2px solid var(--color-border);
}

.eb-summary-section {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}

.eb-sent-text {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.eb-sent-idx {
  color: var(--color-muted);
  font-size: 12px;
  min-width: 24px;
  text-align: right;
  padding-top: 2px;
  flex-shrink: 0;
}

.eb-bias-tag {
  font-size: 10px;
  font-weight: 600;
  background: #ffe0e0;
  color: #b33;
  padding: 1px 6px;
  border-radius: 3px;
  flex-shrink: 0;
  line-height: 1.8;
}

.eb-sent-body {
  font-size: 14px;
  line-height: 1.6;
}

.eb-mention {
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
}

/* Annotation controls (shared for sentence & paragraph rows) */

.eb-sent-controls,
.eb-para-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.eb-sent-controls {
  padding-left: 36px;
}

.eb-ctrl-label {
  font-size: 12px;
  color: var(--color-muted);
  white-space: nowrap;
}

.eb-btn-group {
  display: flex;
  gap: 3px;
}

.eb-dir-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eb-ctrl-sep {
  width: 1px;
  height: 16px;
  background: var(--color-border);
}

/* Citation controls */

.eb-citation-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eb-citation-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--color-muted);
  cursor: pointer;
  white-space: nowrap;
}

.eb-citation-select {
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  max-width: 180px;
}

/* Selected button states */

.btn.eb-sel-yes {
  background: var(--color-danger); color: #fff; border-color: var(--color-danger);
}

.btn.eb-sel-no {
  background: var(--color-success); color: #fff; border-color: var(--color-success);
}

.btn.eb-sel-unclear {
  background: var(--color-warning); color: #000; border-color: var(--color-warning);
}

.btn.eb-sel-neg {
  background: #b83232; color: #fff; border-color: #b83232;
}

.btn.eb-sel-pos {
  background: #1d8348; color: #fff; border-color: #1d8348;
}

.btn.eb-sel-mix {
  background: #7d6608; color: #fff; border-color: #7d6608;
}

/* Entity-level summary */

.eb-summary {
  padding: 12px 16px;
  background: #f8f9fa;
  border-top: 1px solid var(--color-border);
}

.eb-summary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  flex-wrap: wrap;
}

.eb-summary-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.eb-summary textarea {
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

/* === Comparison === */

.tabs {
  display: flex; gap: 0; border-bottom: 2px solid var(--color-border);
  margin-bottom: 16px;
}

.tabs .tab {
  padding: 8px 16px; cursor: pointer; font-size: 13px;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  color: var(--color-muted);
}

.tabs .tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.metric-card {
  display: inline-flex; flex-direction: column; align-items: center;
  padding: 12px 20px; background: #fff; border: 1px solid var(--color-border);
  border-radius: 8px; margin: 4px;
}

.metric-card .metric-value { font-size: 24px; font-weight: 700; }
.metric-card .metric-label { font-size: 11px; color: var(--color-muted); }

.diff-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}

.diff-table th, .diff-table td {
  padding: 6px 10px; border: 1px solid var(--color-border); text-align: left;
}

.diff-table th { background: #f8f9fa; font-weight: 600; }
.diff-table .agree { background: #d4edda; }
.diff-table .disagree { background: #f8d7da; }

/* === Index page === */

.login-box {
  max-width: 400px; margin: 80px auto; text-align: center;
}

.login-box input {
  width: 100%; padding: 10px 14px; font-size: 16px;
  border: 2px solid var(--color-border); border-radius: 8px;
  margin-bottom: 12px;
}

.article-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px; padding: 20px 0;
}

.article-card {
  background: #fff; border: 1px solid var(--color-border);
  border-radius: 8px; padding: 16px; cursor: pointer;
  transition: border-color 0.15s;
}

.article-card:hover { border-color: var(--color-primary); }
.article-card.poc-selected { border-color: var(--color-warning); border-width: 2px; }
.article-card.median-range { border-color: #4dabf7; border-width: 2px; }

.article-card h3 { font-size: 15px; margin-bottom: 6px; }
.article-card .poc-star { color: var(--color-warning); margin-right: 4px; }
.article-card .meta { font-size: 12px; color: var(--color-muted); margin-bottom: 10px; }
.article-card .median-badge {
  display: inline-block; background: #4dabf7; color: #fff;
  font-size: 10px; padding: 1px 6px; border-radius: 3px; margin-left: 4px;
  vertical-align: middle;
}

.article-card .progress-bar {
  display: flex; gap: 4px;
}

.article-card .progress-bar .step {
  flex: 1; height: 4px; background: #e9ecef; border-radius: 2px;
}

.article-card .progress-bar .step.done { background: var(--color-success); }
.article-card .progress-bar .step.current { background: var(--color-primary); }

/* === Biased sentence highlight (entity bias stage) === */

.article-text .sentence-biased { border-left: 3px solid var(--color-danger); padding-left: 4px; }

.article-text .entity-pulse {
  animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { outline: 2px solid transparent; }
  to { outline: 2px solid var(--color-primary); }
}
