.keeper-page {
  --fig: #8ca632;
  --fig-deep: #526b1e;
  --fig-soft: rgba(140, 166, 50, 0.13);
  --chartreuse: #65507e;
  --chartreuse-soft: rgba(101, 80, 126, 0.16);
  --bluegray: #52645f;
}

.keeper-page.dark-mode {
  --fig: #c7dd66;
  --fig-deep: #e0ef98;
  --fig-soft: rgba(199, 221, 102, 0.16);
  --chartreuse: #b7a0dc;
  --chartreuse-soft: rgba(183, 160, 220, 0.16);
  --bluegray: #b8c7bf;
}

.keeper-page .brand-mark {
  border-color: rgba(101, 80, 126, 0.42);
  background: linear-gradient(145deg, var(--fig), var(--fig-deep));
}

.keeper-shell {
  width: min(1500px, calc(100vw - 80px));
}

.keeper-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.keeper-help {
  position: relative;
}

.hint-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--fig-soft);
  color: var(--fig-deep);
  font-size: 16px;
  font-weight: 850;
}

.hint-button:hover,
.hint-button:focus-visible {
  background: var(--chartreuse-soft);
}

.hint-popover {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  z-index: 500;
  width: min(300px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--paper-strong);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.keeper-help:hover .hint-popover,
.keeper-help:focus-within .hint-popover {
  opacity: 1;
  transform: translateY(0);
}

.keeper-actions .quiet-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px 0 8px;
  border-radius: var(--radius-pill);
  color: var(--chartreuse);
  text-decoration: none;
  font-size: 13px;
  font-weight: 820;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.keeper-actions .quiet-button:hover {
  background: var(--chartreuse-soft);
  color: var(--chartreuse);
  transform: translateY(-1px);
}

.keeper-actions .quiet-button::before {
  content: "S";
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(184, 205, 88, 0.55);
  border-radius: 8px;
  background: linear-gradient(145deg, #65507e, #48325f);
  color: #fffbea;
  font-size: 13px;
  font-weight: 850;
}

.keeper-controls {
  position: relative;
  z-index: 260;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 64px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 1px 0 rgba(38, 31, 45, 0.04), 0 10px 24px rgba(38, 31, 45, 0.045);
  backdrop-filter: blur(18px);
}

.keeper-controls:has(.paste-drawer:not([hidden])) {
  align-items: flex-start;
  border-radius: var(--radius);
}

.level-field,
.source-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.level-field > span,
.source-actions > span {
  color: var(--bluegray);
  max-width: 74px;
  padding-left: 5px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.08;
  white-space: normal;
}

.source-action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: rgba(140, 166, 50, 0.075);
}

.source-action-buttons .quiet-button {
  width: 78px;
  min-width: 78px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.primary-button {
  flex: 0 0 128px;
  margin-left: auto;
  width: 128px;
  min-width: 104px;
  height: 36px;
  border: 0;
  background: linear-gradient(145deg, var(--fig), var(--fig-deep));
  color: #fffef4;
  font-weight: 830;
}

.dark-mode .primary-button {
  background: linear-gradient(145deg, rgba(139, 158, 68, 0.72), rgba(76, 96, 34, 0.78));
  color: rgba(255, 254, 244, 0.9);
}

.keeper-controls .quiet-button {
  height: 34px;
  border: 0;
  background: var(--fig-soft);
  color: var(--fig-deep);
  box-shadow: none;
  font-size: 14px;
  font-weight: 800;
}

.keeper-controls .quiet-button:hover {
  border-color: transparent;
  background: var(--chartreuse-soft);
}

.level-button {
  width: 184px;
  height: 36px;
  min-width: 0;
  padding: 0 34px 0 14px;
  text-align: left;
  border-color: rgba(140, 166, 50, 0.22);
  border-radius: var(--radius-pill);
  background-color: var(--paper-strong);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--fig) 50%),
    linear-gradient(135deg, var(--fig) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 15px,
    calc(100% - 12px) 15px;
  background-repeat: no-repeat;
  background-size: 6px 6px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
  color: var(--ink);
  font-size: 14px;
  font-weight: 760;
}

.level-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 400;
  display: grid;
  width: min(380px, 84vw);
  max-height: 300px;
  overflow: auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--paper-strong);
  box-shadow: var(--shadow);
}

.level-menu[hidden] {
  display: none;
}

.level-option {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  height: 30px;
  min-width: 0;
  padding: 0 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
  text-align: left;
}

.level-book-group {
  display: grid;
  gap: 6px;
}

.level-book-heading {
  color: var(--bluegray);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

.level-radio {
  display: grid;
  place-items: center;
  width: 12px;
  height: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.level-option.is-selected .level-radio::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fig-deep);
}

.level-option:hover,
.level-option.is-selected {
  background: var(--fig-soft);
  color: var(--fig-deep);
}

.paste-drawer {
  display: grid;
  flex: 0 0 100%;
  gap: 8px;
  padding-top: 4px;
}

.paste-drawer[hidden] {
  display: none;
}

.paste-drawer-heading {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.paste-drawer-heading span {
  color: var(--bluegray);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.text-button {
  width: auto;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fig-deep);
  font-size: 12px;
  font-weight: 820;
}

.text-button:hover {
  text-decoration: underline;
}

.paste-drawer textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  outline: none;
  background: var(--paper-strong);
  color: var(--ink);
  font: 16px/1.65 "New York", ui-serif, Georgia, "Times New Roman", serif;
}

.dark-mode .paste-drawer textarea {
  background: rgba(39, 34, 47, 0.92);
}

.loaded-file {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1 1 130px;
  min-width: 90px;
  max-width: none;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.loaded-file[hidden] {
  display: none;
}

.loaded-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-file-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 0;
  border-radius: 50%;
  background: var(--paper-strong);
  color: var(--fig-deep);
  font-size: 15px;
  font-weight: 850;
  line-height: 1;
  padding: 0 0 1px;
}

.remove-file-button:hover {
  background: var(--chartreuse-soft);
}

.keeper-workspace {
  display: grid;
  grid-template-columns: minmax(420px, var(--review-fr, 1.34fr)) 6px minmax(320px, var(--detail-fr, 0.66fr));
  gap: 4px;
  min-height: 0;
}

.review-panel {
  display: grid;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 1px 0 rgba(38, 31, 45, 0.04), 0 10px 24px rgba(38, 31, 45, 0.045);
  backdrop-filter: blur(18px);
}

.review-panel {
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.workspace-resizer {
  position: relative;
  align-self: stretch;
  border-radius: var(--radius-pill);
  outline: none;
  cursor: col-resize;
  touch-action: none;
}

.workspace-resizer::before {
  content: "";
  position: absolute;
  inset: 28px 1px;
  border-radius: var(--radius-pill);
  background: rgba(101, 80, 126, 0.14);
  transition: background 0.16s ease;
}

.workspace-resizer:hover::before,
.workspace-resizer:focus-visible::before,
.keeper-workspace.is-resizing .workspace-resizer::before {
  background: var(--chartreuse);
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  gap: 10px;
  min-height: 82px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(30px) saturate(1.2);
}

.dark-mode .stats-strip {
  background: rgba(255, 255, 255, 0.075);
  backdrop-filter: blur(32px) saturate(1.18);
}

.stat-card {
  display: grid;
  align-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 50px;
  padding: 8px 12px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--fig), var(--fig-deep));
  box-shadow: none;
}

.dark-mode .stat-card {
  background: linear-gradient(145deg, rgba(199, 221, 102, 0.38), rgba(82, 107, 30, 0.52));
}

.stat-card strong {
  color: #fffef4;
  font-size: 20px;
  line-height: 1;
}

.stat-card span {
  overflow: hidden;
  color: rgba(255, 254, 244, 0.76);
  font-size: 11px;
  font-weight: 780;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.highlighted-text {
  min-height: 0;
  overflow: auto;
  padding: 20px;
  border-top: 1px solid var(--line);
  background: transparent;
  font: 17px/1.75 "New York", ui-serif, Georgia, "Times New Roman", serif;
  white-space: pre-wrap;
  tab-size: 2;
}

.dark-mode .highlighted-text {
  background: rgba(18, 16, 22, 0.26);
}

.highlighted-text.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: inherit;
  font-size: 15px;
  text-align: center;
}

.hit {
  border-radius: 5px;
  padding: 1px 3px;
  cursor: pointer;
}

.hit.is-selected {
  outline: 2px solid rgba(199, 221, 102, 0.78);
  outline-offset: 1px;
}

.hit-outside {
  background: rgba(205, 95, 70, 0.24);
  box-shadow: inset 0 -2px 0 rgba(171, 54, 38, 0.55);
}

.hit-ambiguous {
  background: rgba(101, 80, 126, 0.18);
  box-shadow: inset 0 -2px 0 rgba(101, 80, 126, 0.45);
}

.hit-unknown {
  background: rgba(83, 104, 121, 0.14);
  box-shadow: inset 0 -2px 0 rgba(83, 104, 121, 0.28);
}

.ignored-span {
  border-radius: 5px;
  color: var(--subtle);
  background: rgba(138, 135, 146, 0.11);
  font-style: italic;
}

.keeper-detail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.compact-heading {
  padding-bottom: 12px;
}

.findings-list {
  min-height: 0;
  overflow: auto;
  padding: 0 0 14px;
}

.finding-group {
  margin-top: 14px;
}

.finding-group:first-child {
  margin-top: 0;
}

.finding-group h3 {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0 0 10px;
  padding: 9px 30px 7px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-strong);
  box-shadow: 0 5px 12px rgba(38, 31, 45, 0.045);
  color: var(--bluegray);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.finding-row {
  display: grid;
  gap: 5px;
  width: calc(100% - 60px);
  height: auto;
  min-height: 0;
  margin: 0 30px;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 8px;
  color: inherit;
  font: inherit;
  line-height: normal;
  text-align: left;
  white-space: normal;
}

.finding-row:first-of-type {
  border-top: 0;
}

.finding-row + .finding-row {
  margin-top: 4px;
}

.finding-row.is-selected,
.finding-row:hover {
  background: var(--fig-soft);
}

.finding-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: start;
  gap: 10px;
}

.finding-main strong {
  min-width: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.22;
  overflow-wrap: anywhere;
}

.finding-main span,
.finding-row p {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.finding-row p {
  margin: 0;
}

.summary-link {
  width: auto;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fig-deep);
  font: inherit;
  font-weight: 780;
  text-align: left;
}

.summary-link:hover {
  color: var(--chartreuse);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.summary-dot {
  padding: 0 5px;
  color: var(--muted);
}

.panel-clear-button {
  width: auto;
  min-width: 72px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--fig-soft);
  color: var(--fig-deep);
  font-size: 13px;
  font-weight: 820;
}

.panel-clear-button:hover {
  background: var(--chartreuse-soft);
}

.finding-row.is-selected strong,
.finding-row:hover strong {
  color: var(--fig-deep);
}

.detail-card {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: rgba(255, 255, 255, 0.42);
}

.selected-detail {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.28));
}

.selected-detail:empty {
  display: none;
}

.dark-mode .detail-card {
  background: rgba(255, 255, 255, 0.04);
}

.detail-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
}

.detail-card dl {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px 10px;
  margin: 0;
  font-size: 13px;
}

.detail-card dt {
  color: var(--bluegray);
  font-weight: 800;
}

.detail-card dd {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1120px) {
  .keeper-shell {
    width: min(100vw - 28px, 900px);
    overflow: auto;
  }

  .keeper-page {
    overflow: auto;
  }

  .keeper-controls,
  .keeper-workspace {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .workspace-resizer {
    display: none;
  }

  .highlighted-text {
    min-height: 320px;
  }
}

@media (max-width: 720px) {
  .keeper-shell {
    width: min(100vw - 20px, 560px);
    padding-top: 18px;
  }

  .keeper-controls {
    grid-template-columns: 1fr 1fr;
  }

  .level-field,
  .source-actions {
    grid-column: 1 / -1;
  }

  .stats-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
