:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-subtle: #f0f3f5;
  --surface-strong: #e6ebee;
  --text: #182026;
  --muted: #66737d;
  --border: #d8e0e5;
  --border-strong: #b7c4cc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d9f0ed;
  --warning: #945d10;
  --warning-soft: #fff0d3;
  --danger: #b42318;
  --danger-soft: #fce3df;
  --shadow: 0 18px 45px rgba(28, 39, 48, 0.12);
  --radius: 8px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family:
    Inter,
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.annotation-item:focus-within {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.app-header {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-logo {
  flex: 0 0 auto;
  width: 72px;
  height: 56px;
  object-fit: contain;
}

.brand-text {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.1rem;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p,
dl {
  margin: 0;
}

h1 {
  font-size: 1.15rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  font-size: 0.92rem;
  line-height: 1.2;
}

.header-actions,
.input-row,
.section-heading,
.section-heading.with-actions,
.tool-actions {
  display: flex;
  align-items: center;
}

.header-actions {
  justify-content: flex-end;
  gap: var(--space-3);
  min-width: 0;
}

.local-state {
  min-width: 11rem;
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-subtle);
  font-size: 0.82rem;
  text-align: center;
  white-space: nowrap;
}

.local-state.is-dirty {
  border-color: #efbf67;
  color: var(--warning);
  background: var(--warning-soft);
}

.workspace {
  height: calc(100vh - 84px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(420px, 1fr) minmax(320px, 390px);
  gap: var(--space-3);
  padding: var(--space-3);
  overflow: hidden;
}

.source-panel,
.review-panel,
.viewer-shell {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.source-panel,
.review-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-section {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: 0;
}

.source-panel .catalog-section,
.review-panel .list-section {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
}

.section-heading {
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.field-label {
  display: block;
  margin: 0 0 0.28rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.source-group {
  margin-top: var(--space-3);
}

.input-row {
  gap: var(--space-2);
}

.text-input,
.text-area {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  color: var(--text);
  background: #fff;
}

.text-input {
  height: 2.35rem;
}

.text-area {
  min-height: 5.2rem;
  resize: vertical;
  line-height: 1.35;
}

.text-input::placeholder {
  color: #98a4ad;
}

.button,
.text-button {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.button {
  min-height: 2.35rem;
  padding: 0.45rem 0.72rem;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent-strong);
  font-weight: 650;
}

.button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button.secondary {
  color: var(--text);
  background: var(--surface-subtle);
  border-color: var(--border-strong);
}

.button.secondary:hover:not(:disabled),
.button.secondary[aria-pressed="true"] {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.button.danger {
  color: var(--danger);
  background: #fff;
  border-color: #efb5ad;
}

.button.danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.text-button {
  padding: 0.15rem 0.25rem;
  color: var(--accent-strong);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
}

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

.mini-actions {
  display: flex;
  gap: var(--space-2);
}

.status {
  margin-top: var(--space-4);
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-subtle);
  font-size: 0.86rem;
  line-height: 1.35;
}

.status.error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #f2b8b1;
}

.summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem var(--space-3);
  margin-top: var(--space-3);
  color: var(--muted);
  font-size: 0.8rem;
}

.summary dt {
  font-weight: 700;
}

.summary dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.category-option {
  display: grid;
  grid-template-columns: 1rem 1fr auto;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: 0.42rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 0.83rem;
}

.category-option input {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

.category-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  height: 1.4rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-subtle);
  font-size: 0.74rem;
  font-weight: 700;
}

.viewer-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 58px;
  padding: 0.72rem var(--space-4);
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.viewer-toolbar p {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.tool-actions {
  justify-content: flex-end;
  gap: var(--space-2);
}

.osd {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: #15191d;
}

.region-tooltip {
  position: fixed;
  z-index: 50;
  max-width: min(320px, calc(100vw - 2rem));
  padding: 0.65rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  color: #f8fafb;
  background: rgba(17, 24, 30, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  line-height: 1.35;
  pointer-events: none;
}

.region-tooltip dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.22rem 0.6rem;
}

.region-tooltip dt {
  color: #b9c3ca;
  font-weight: 700;
}

.region-tooltip dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.editor-section {
  flex: 0 0 auto;
}

.annotation-form {
  display: block;
}

.empty-state {
  padding: var(--space-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-subtle);
  font-size: 0.86rem;
  line-height: 1.35;
}

.editor-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.selected-id {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.selected-id code {
  min-width: 0;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  color: var(--text);
  background: var(--surface-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.32rem var(--space-3);
  margin: var(--space-1) 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.selected-details dt {
  font-weight: 700;
}

.selected-details dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.form-error {
  min-height: 1rem;
  color: var(--danger);
  font-size: 0.78rem;
}

.annotation-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.annotation-item {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  align-items: center;
  padding: 0.62rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: #fff;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

.annotation-item:hover,
.annotation-item.is-hovered {
  border-color: var(--accent);
  background: #f9fdfc;
}

.annotation-item.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.annotation-main {
  min-width: 0;
}

.annotation-select {
  min-width: 0;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.annotation-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 750;
}

.annotation-title span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.annotation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.55rem;
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.annotation-meta span {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.local-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0.08rem 0.34rem;
  color: var(--warning);
  background: var(--warning-soft);
  font-size: 0.68rem;
  font-weight: 800;
}

.crop-link {
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 700;
  text-decoration: none;
}

.crop-link:hover {
  text-decoration: underline;
}

.file-input {
  width: 100%;
  min-width: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.compact-file {
  align-self: center;
}

.single-source {
  margin-top: var(--space-4);
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
}

.single-source summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 800;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.checkbox-label input {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

.checkbox-label.compact {
  white-space: nowrap;
}

.catalog-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.catalog-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow: auto;
}

.catalog-item {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.catalog-item:hover,
.catalog-item.is-active {
  border-color: var(--accent);
  background: #f9fdfc;
}

.catalog-item.is-active {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.catalog-item-main {
  min-width: 0;
}

.catalog-item-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: 0.84rem;
  font-weight: 760;
}

.catalog-item-title span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalog-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.55rem;
  margin-top: 0.26rem;
  color: var(--muted);
  font-size: 0.73rem;
}

.catalog-item-meta span {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.dirty-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px var(--warning-soft);
}

.failed-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.item-heading {
  min-width: 0;
}

.item-heading h2,
.item-heading p {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warning-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 0.8rem;
}

.warning-item {
  padding: 0.48rem 0.55rem;
  border: 1px solid #efbf67;
  border-radius: 6px;
  color: var(--warning);
  background: var(--warning-soft);
  line-height: 1.35;
}

.a9s-annotationlayer {
  --a9s-handle-fill: #ffffff;
}

@media (max-width: 1180px) {
  html,
  body {
    overflow: auto;
  }

  .app-header {
    height: auto;
    min-height: 68px;
    align-items: flex-start;
    flex-direction: column;
    padding: var(--space-3) var(--space-4);
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 96px);
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .source-panel,
  .review-panel {
    overflow: visible;
  }

  .viewer-shell {
    min-height: 62vh;
  }

  .source-panel .panel-section:last-child,
  .review-panel .list-section {
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: var(--space-2);
    gap: var(--space-2);
  }

  .brand-logo {
    width: 58px;
    height: 46px;
  }

  .viewer-toolbar,
  .header-actions,
  .tool-actions,
  .input-row {
    align-items: stretch;
    flex-direction: column;
  }

  .local-state,
  .button {
    width: 100%;
  }

  .summary,
  .selected-details,
  .region-tooltip dl {
    grid-template-columns: 1fr;
  }

  .annotation-item {
    grid-template-columns: 1fr;
  }
}
