:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #f0f4ef;
  --ink: #1d2521;
  --muted: #68746d;
  --line: #dce3dd;
  --line-strong: #c4cec6;
  --brand: #0f766e;
  --brand-strong: #0b5d56;
  --accent: #a16207;
  --danger: #b42318;
  --success: #15803d;
  --shadow: 0 18px 50px rgba(29, 37, 33, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), transparent 280px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--brand-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3.4vw, 4.1rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.topbar-actions,
.batch-actions,
.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button,
.segmented button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  white-space: nowrap;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease;
}

.button:hover,
.segmented button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: var(--brand);
  color: white;
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.2);
}

.button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.button.dark {
  background: var(--ink);
  color: white;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.dropzone {
  min-height: 170px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.dropzone strong,
.dropzone span {
  display: block;
  text-align: center;
}

.dropzone strong {
  color: var(--ink);
  font-size: 1.08rem;
  margin-bottom: 4px;
}

.dropzone.is-dragover {
  border-color: var(--brand);
  background: rgba(15, 118, 110, 0.08);
  transform: scale(1.005);
}

.ocr-status {
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 12px 14px;
  font-weight: 850;
}

.workspace {
  display: grid;
  gap: 16px;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 8px 24px rgba(29, 37, 33, 0.04);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 1.9rem;
  line-height: 1;
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) repeat(3, minmax(160px, 0.7fr)) auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-field,
.select-field {
  display: grid;
  gap: 6px;
}

.search-field label,
.select-field label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

input[type="search"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 12px;
}

input[type="search"]:focus,
select:focus,
button:focus-visible,
.button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.toggle {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-strong);
  font-weight: 800;
  white-space: nowrap;
}

.toggle input,
.read-check {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.action-row {
  justify-content: space-between;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  background: var(--surface);
}

.segmented button {
  min-height: 36px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.is-active {
  background: var(--ink);
  color: white;
}

.results-panel {
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1540px;
  border-collapse: collapse;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3ee;
  color: #39443e;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

tbody tr:hover {
  background: rgba(15, 118, 110, 0.05);
}

.job-code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-weight: 900;
}

.muted {
  color: var(--muted);
}

.reason-cell {
  max-width: 360px;
  line-height: 1.42;
}

.solution-cell {
  max-width: 340px;
  line-height: 1.42;
}

.editable-text {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 9px 10px;
  line-height: 1.42;
}

.editable-text:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  border-color: var(--brand);
}

.editable-text.is-dirty {
  border-color: #93c5fd;
  box-shadow: inset 3px 0 0 #2563eb;
}

.copy-text {
  max-width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  line-height: 1.42;
  white-space: normal;
}

.copy-text:hover {
  color: var(--brand-strong);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.copy-mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-weight: 900;
}

.strong-copy {
  display: block;
}

.subtle-copy {
  color: var(--muted);
}

.copy-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.2;
  background: #edf1ed;
}

.copy-pill.type {
  color: var(--accent);
  background: #fff6db;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.2;
}

.pill.open {
  color: var(--danger);
  background: #fff0ed;
}

.pill.closed {
  color: var(--success);
  background: #edf8f0;
}

.pill.type {
  color: var(--accent);
  background: #fff6db;
}

.status-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 118px;
}

.status-select {
  min-height: 32px;
  width: auto;
  border-radius: 999px;
  padding: 0 30px 0 10px;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: lowercase;
}

.status-select.open {
  border-color: #ffd2ca;
  background: #fff0ed;
  color: var(--danger);
}

.status-select.closed {
  border-color: #ccebd3;
  background: #edf8f0;
  color: var(--success);
}

.status-dirty-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
  opacity: 0;
}

.status-dirty-dot.is-visible {
  opacity: 1;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  padding: 12px;
}

.error-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  display: grid;
  gap: 12px;
  background: var(--surface);
}

.error-card.is-read {
  background: #f7fbf8;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  display: grid;
  gap: 5px;
}

.card-title strong,
.card-job {
  font-size: 1.15rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.card-section {
  display: grid;
  gap: 4px;
}

.card-section span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.card-section p {
  margin: 0;
  line-height: 1.45;
}

.card-section .copy-text {
  display: block;
}

.card-section .editable-text {
  min-height: 92px;
}

.empty-results {
  min-height: 280px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  padding: 24px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 16px);
  max-width: min(520px, calc(100% - 32px));
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--ink);
  color: white;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: 0 12px 30px rgba(29, 37, 33, 0.24);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.is-hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .topbar {
    display: grid;
  }

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

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

  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100% - 22px, 1480px);
    padding-top: 18px;
  }

  h1 {
    font-size: 2.2rem;
  }

  .topbar-actions,
  .batch-actions,
  .action-row,
  .segmented {
    width: 100%;
  }

  .button,
  .topbar-actions label,
  .batch-actions button,
  .segmented button {
    flex: 1 1 auto;
  }

  .summary-grid,
  .controls,
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }

  .metric strong {
    margin-top: 0;
    font-size: 1.55rem;
  }
}
