:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --surface-3: #fbfcfd;
  --text: #17202a;
  --muted: #667282;
  --border: #d8dee7;
  --accent: #0c7b65;
  --accent-strong: #075c4c;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(22, 31, 44, 0.08);
  --focus: 0 0 0 3px rgba(12, 123, 101, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

h1,
h2,
p {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
}

.app-header,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 17px;
}

.button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

.button.primary {
  background: var(--accent);
  color: white;
}

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

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

.button.secondary:hover,
.icon-button:hover {
  border-color: #b9c4d1;
  background: #f8fafc;
}

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

.button.compact {
  min-height: 32px;
  padding: 0 10px;
}

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

.button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.list-item:focus-visible,
.capture-target:focus-visible,
.mini-capture:focus-visible {
  outline: 0;
  box-shadow: var(--focus);
}

.icon-button {
  width: 34px;
  height: 34px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

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

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

.list {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: calc(100vh - 290px);
  overflow: auto;
}

.list-item {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: stretch;
}

.list-row.selected .list-item {
  border-color: var(--accent);
  background: #eef8f5;
}

.list-item:hover {
  border-color: var(--accent);
}

.list-item span {
  overflow: hidden;
  font-weight: 750;
  text-overflow: ellipsis;
}

.danger-icon {
  align-self: stretch;
  height: auto;
  border-color: #f1b6b0;
  background: #fff5f5;
  color: var(--danger);
  font-weight: 800;
}

small,
.status,
.pill,
.empty-state,
.review-empty {
  color: var(--muted);
}

.pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
}

.review-empty,
.empty-state {
  padding: 18px;
}

.review-empty {
  display: grid;
  gap: 6px;
}

.extraction-note {
  padding: 10px 12px;
  border: 1px solid #f4c27b;
  border-radius: 7px;
  background: #fff7ed;
  color: #7c3f05;
  font-size: 13px;
  font-weight: 700;
}

.review-form {
  display: grid;
  grid-template-columns: minmax(320px, 58%) minmax(300px, 1fr);
  gap: 16px;
  padding: 14px;
  align-items: start;
}

.document-frame {
  height: clamp(520px, calc(100vh - 250px), 860px);
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
}

.document-frame img,
.document-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: contain;
}

form,
.store-form,
.dialog-form {
  display: grid;
  gap: 12px;
}

.store-form {
  align-content: start;
}

.form-section {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-3);
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 10px;
  background: white;
  color: var(--text);
}

input:hover,
textarea:hover {
  border-color: #b9c4d1;
}

textarea {
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.agreements-panel {
  grid-column: 1 / -1;
}

.search {
  max-width: 260px;
}

.agreements-table {
  overflow: auto;
  max-height: 42vh;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td small {
  display: block;
  margin-top: 3px;
}

.store-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.2fr;
  gap: 10px;
  position: sticky;
  bottom: 0;
  padding-top: 4px;
  background: var(--surface);
}

dialog {
  width: min(720px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(23, 32, 42, 0.34);
}

.dialog-form {
  padding-bottom: 14px;
}

.dialog-form > label,
.dialog-form > .form-row,
.dialog-actions {
  margin: 0 14px;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.scanner-page {
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(246, 247, 249, 0.96)),
    radial-gradient(circle at top left, rgba(12, 123, 101, 0.16), transparent 32%);
}

.scanner-shell {
  width: min(720px, calc(100vw - 36px));
  max-width: 720px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.upload-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.capture-target {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 170px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.capture-target small {
  color: var(--muted);
}

.capture-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 30px;
  line-height: 1;
}

#documentInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

#adminDocumentInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.inline-capture {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-3);
}

.mini-capture {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: start;
  min-height: 74px;
  padding: 0 16px;
  border: 1px dashed var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.mini-capture span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 22px;
  line-height: 1;
  grid-row: span 2;
}

.mini-capture small {
  margin-top: -18px;
}

.preview {
  display: grid;
  place-items: center;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.preview img {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
}

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

@media (max-width: 1180px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .list {
    max-height: none;
  }

  .review-form {
    grid-template-columns: minmax(300px, 54%) minmax(280px, 1fr);
  }
}

@media (max-width: 900px) {
  .review-form {
    grid-template-columns: 1fr;
  }

  .document-frame {
    height: 460px;
  }
}

@media (max-width: 640px) {
  .app-header,
  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-grid {
    padding: 10px;
    gap: 10px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }

  .panel-header {
    gap: 8px;
  }

  .document-frame {
    height: 380px;
  }

  .store-actions,
  .dialog-actions {
    grid-template-columns: 1fr;
    display: grid;
  }

  .agreements-table {
    max-height: none;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }

  td {
    display: grid;
    grid-template-columns: 94px 1fr;
    gap: 10px;
    padding: 5px 0;
    border: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  td:last-child {
    display: block;
    padding-top: 10px;
  }
}
