:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --line: #d8dee8;
  --text: #18202a;
  --muted: #657286;
  --accent: #176f78;
  --accent-2: #315f9d;
  --warn: #9a5b16;
  --danger: #b13b3b;
  --ok: #24734d;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
select,
input,
textarea {
  font: inherit;
}

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

button {
  cursor: pointer;
  min-height: 34px;
  padding: 7px 12px;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.secondary {
  background: var(--surface-2);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

select,
input {
  min-height: 34px;
  padding: 6px 9px;
}

.annotator-identity {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}

textarea {
  min-height: 82px;
  padding: 9px;
  resize: vertical;
}

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

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.page-tabs {
  display: inline-flex;
  gap: 6px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  height: calc(100vh - 56px);
  min-height: 0;
  overflow: hidden;
}

.analytics-workspace {
  height: calc(100vh - 56px);
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fbfcfd;
}

.metric strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.filters {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.status-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.status-tabs button {
  padding-inline: 6px;
  background: var(--surface);
}

.status-tabs button.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.list {
  overflow: auto;
  min-height: 0;
}

.item-row {
  width: 100%;
  min-height: 88px;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  text-align: left;
}

.item-row:hover,
.item-row.active {
  background: #edf6f7;
}

.item-head,
.item-meta,
.chip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.item-head {
  justify-content: space-between;
}

.item-id {
  font-weight: 700;
}

.item-title,
.item-meta {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  max-width: 100%;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
}

.chip.ok {
  background: #e5f4ec;
  color: var(--ok);
}

.chip.warn {
  background: #fff0d9;
  color: var(--warn);
}

.chip.danger {
  background: #fae7e7;
  color: var(--danger);
}

.content {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 16px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 50vh;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.detail {
  display: grid;
  gap: 14px;
  max-width: 1480px;
  margin: 0 auto;
}

.analytics-page {
  max-width: 1440px;
}

.analytics-content {
  padding: 18px;
}

.analytics-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.section-header h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.section-body {
  padding: 14px;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.datum {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.datum span {
  color: var(--muted);
  font-size: 12px;
}

.datum strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}

.rationale-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
  color: #2d3746;
}

.code-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.code-pane {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.code-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.code-pane-header h3 {
  margin: 0;
  font-size: 13px;
}

.code-window {
  margin: 0;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: #e8eef5;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.code-line {
  display: grid;
  grid-template-columns: var(--line-number-width, 5ch) max-content;
  min-width: max-content;
}

.code-line:first-child {
  padding-top: 10px;
}

.code-line:last-child {
  padding-bottom: 10px;
}

.code-line:hover {
  background: rgba(255, 255, 255, 0.045);
}

.line-number {
  position: sticky;
  left: 0;
  z-index: 1;
  padding: 0 10px 0 8px;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  background: #101820;
  color: #7f8b99;
  text-align: right;
  user-select: none;
}

.line-code {
  display: block;
  padding: 0 14px 0 10px;
  white-space: pre;
}

.tok-keyword {
  color: #7dd3fc;
  font-weight: 700;
}

.tok-string {
  color: #bef264;
}

.tok-number {
  color: #fda4af;
}

.tok-comment {
  color: #91a4b7;
  font-style: italic;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.field.full {
  grid-column: 1 / -1;
}

.field.disagreement-field {
  padding: 8px;
  border: 1px solid #e6a23c;
  border-radius: 8px;
  background: #fff7e8;
}

.field.disagreement-field label {
  color: var(--warn);
  font-weight: 700;
}

.field.disagreement-field select,
.field.disagreement-field textarea,
.field.disagreement-field .checkbox-control {
  border-color: #d99025;
}

.field label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  max-width: 100%;
  font-size: 12px;
  color: var(--muted);
}

.field-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  outline: none;
}

.field-help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.field-tooltip {
  position: absolute;
  z-index: 30;
  top: calc(100% + 7px);
  left: 50%;
  width: min(320px, calc(100vw - 32px));
  max-height: 260px;
  overflow: auto;
  transform: translateX(-50%);
  visibility: hidden;
  opacity: 0;
  padding: 10px 12px;
  border: 1px solid #ced7e0;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(18, 35, 54, 0.16);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  transition: opacity 120ms ease, visibility 120ms ease;
}

.field-tooltip ul {
  display: grid;
  gap: 4px;
  margin: 7px 0 0;
  padding-left: 16px;
}

.field-tooltip strong {
  font-weight: 700;
}

.tooltip-note {
  display: block;
  color: var(--text);
  font-weight: 600;
}

.field-help:hover .field-tooltip,
.field-help:focus .field-tooltip,
.field-help:focus-within .field-tooltip {
  visibility: visible;
  opacity: 1;
}

.field:nth-child(3n + 1) .field-tooltip {
  left: 0;
  transform: none;
}

.field:nth-child(3n) .field-tooltip {
  right: 0;
  left: auto;
  transform: none;
}

.field.full .field-tooltip {
  right: auto;
  left: 0;
  transform: none;
}

.checkbox-field {
  align-content: end;
}

.checkbox-control {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.checkbox-control label {
  color: var(--text);
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.message {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
}

.message.error {
  color: var(--danger);
}

.message.ok {
  color: var(--ok);
}

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

.table-scroll {
  overflow: auto;
}

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

.data-table th,
.data-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.data-table tbody tr:hover {
  background: #f7fafc;
}

.comparison th,
.comparison td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.comparison th {
  color: var(--muted);
  font-weight: 600;
}

.comparison tr.diff td {
  background: #fff8eb;
}

.comparison .final-label {
  background: #eef8f2;
  color: var(--ok);
  font-weight: 700;
}

.export-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.export-links a {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-heading h1 {
  margin: 0;
  font-size: 22px;
}

.login-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

#loginForm {
  display: grid;
  gap: 10px;
}

#loginForm button {
  margin-top: 6px;
}

.manager-panel {
  display: grid;
  gap: 12px;
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 26px;
}

.merge-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 1060px) {
  .topbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .analytics-workspace {
    height: auto;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .list {
    max-height: 340px;
  }

  body {
    overflow: auto;
  }

  .content {
    height: auto;
  }

  .metadata-grid,
  .form-grid,
  .metric-grid,
  .merge-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .filter-row,
  .metadata-grid,
  .form-grid,
  .code-grid,
  .metric-grid,
  .merge-summary {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 10px;
  }
}
