:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-soft: #f0f3ef;
  --ink: #202428;
  --muted: #626d75;
  --line: #d9ded7;
  --accent: #2f6f5e;
  --accent-strong: #245647;
  --warning: #9f6428;
  --danger: #a33a32;
  --code: #1f2522;
  --shadow: 0 12px 32px rgba(26, 34, 30, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "IBM Plex Sans", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

button:hover {
  background: var(--accent-strong);
  color: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(47, 111, 94, 0.24);
  outline-offset: 2px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

input[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(120deg, rgba(47, 111, 94, 0.12), transparent 42%),
    var(--bg);
}

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

.auth-brand {
  padding-bottom: 4px;
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.auth-message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(170px, auto) minmax(0, 1fr) minmax(220px, 320px);
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.brand {
  display: grid;
  gap: 4px;
}

.brand strong {
  font-size: 1rem;
}

.brand span,
.eyebrow,
.panel-head p,
.list-item p,
.history-head p,
.field-pill small,
.selected-field p,
.message {
  color: var(--muted);
}

.nav {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.nav-item {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px 10px;
  text-align: center;
  background: transparent;
  color: var(--ink);
  border-color: transparent;
}

.nav-item:hover {
  background: var(--surface-soft);
  color: var(--ink);
  border-color: var(--line);
}

.nav-item.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.message {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px 10px;
  font-size: 0.92rem;
}

.message.error {
  color: var(--danger);
  border-color: rgba(163, 58, 50, 0.28);
  background: #fff7f5;
}

.main {
  min-width: 0;
  padding: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.6rem;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

h3 {
  margin-bottom: 4px;
  font-size: 0.96rem;
}

p {
  margin-bottom: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 104px);
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

.view {
  display: block;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
}

.work-grid.two {
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.stack {
  display: grid;
  gap: 10px;
}

.dual {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.secondary {
  background: #eef1ed;
  color: var(--ink);
  border-color: var(--line);
}

.secondary:hover,
.ghost:hover {
  background: #e4ebe5;
  color: var(--ink);
  border-color: #c6d0c7;
}

.ghost {
  background: transparent;
  color: var(--accent-strong);
  border-color: #bdd0c8;
}

.danger {
  background: #fff1ef;
  color: var(--danger);
  border-color: rgba(163, 58, 50, 0.22);
}

.danger:hover {
  background: #f8ded9;
  color: var(--danger);
  border-color: rgba(163, 58, 50, 0.34);
}

.list {
  display: grid;
  gap: 8px;
}

.list-item,
.history-item,
.selected-field {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.actions {
  display: flex;
  align-items: start;
  gap: 8px;
  flex-shrink: 0;
}

.item-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge,
.chips span,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge {
  color: var(--accent-strong);
  background: #e7f0eb;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chips span {
  color: var(--warning);
  background: #f7eee4;
}

.options-editor {
  display: grid;
  gap: 6px;
}

.file-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.file-field span {
  color: var(--ink);
  font-weight: 600;
}

.file-field small {
  min-height: 18px;
}

.template-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(240px, 0.8fr) minmax(320px, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.selected-fields-panel,
.preview-panel {
  min-height: 260px;
}

.field-library {
  display: grid;
  gap: 8px;
}

.field-pill {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.field-pill:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.field-pill small {
  font-family: "IBM Plex Mono", monospace;
}

.selected-fields {
  display: grid;
  gap: 8px;
}

.selected-field {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.selected-field.is-dragging {
  opacity: 0.6;
}

.drag-handle {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  cursor: grab;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  white-space: nowrap;
}

.check-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.code-block {
  min-height: 220px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  border-radius: 8px;
  background: var(--code);
  color: #dce7df;
  padding: 14px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.86rem;
}

.code-block.small {
  min-height: 120px;
  margin-top: 10px;
}

.result-panel.full {
  grid-column: 1 / -1;
}

.history-item {
  display: grid;
  gap: 10px;
}

.history-item summary {
  cursor: pointer;
  list-style: none;
}

.history-item summary::-webkit-details-marker {
  display: none;
}

.history-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.image-list {
  display: grid;
  gap: 8px;
}

.image-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfcfa;
}

.image-preview {
  width: 76px;
  height: 56px;
  padding: 0;
  overflow: hidden;
  background: var(--surface-soft);
  border-color: var(--line);
}

.image-preview img,
.detail-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.image-rows {
  grid-column: 1 / -1;
}

.compact-table {
  min-width: 760px;
}

.error-text {
  color: var(--danger);
  font-size: 0.86rem;
}

.data-layout {
  display: grid;
  gap: 16px;
}

.rate-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.rate-field,
.filters-grid label,
.modal-grid label,
.summary-year {
  display: grid;
  gap: 6px;
}

.rate-field span,
.filters-grid label span,
.modal-grid label span,
.detail-grid dt,
.summary-year span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.filter-actions {
  display: flex;
  align-items: end;
}

.table-meta {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.86rem;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 1260px;
  border-collapse: collapse;
}

.summary-table {
  min-width: 1360px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.data-table td {
  white-space: nowrap;
}

.data-table td:nth-child(7) {
  min-width: 140px;
}

.data-table td strong,
.data-table td small {
  display: block;
}

.data-table td small,
.muted-value {
  color: var(--muted);
}

.data-table button,
.actions.compact button {
  white-space: nowrap;
}

.actions.compact {
  align-items: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 40px;
  margin-top: 10px;
}

.pagination span {
  color: var(--muted);
  font-size: 0.9rem;
}

.status.success {
  color: var(--accent-strong);
  background: #e7f0eb;
}

.status.warning {
  color: var(--warning);
  background: #f7eee4;
}

.status.failed {
  color: var(--danger);
  background: #fff1ef;
}

.modal {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(22, 29, 25, 0.42);
}

.modal-card {
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-grid,
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-grid {
  margin: 0;
}

.detail-grid div {
  min-width: 0;
}

.detail-grid dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.detail-image {
  height: min(360px, 52vh);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 8px;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
}

.summary-company {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.summary-company:first-child {
  margin-top: 0;
}

.summary-total td {
  background: var(--surface-soft);
  font-weight: 700;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--muted);
  padding: 14px;
}

@media (max-width: 1180px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .template-grid,
  .work-grid,
  .topbar {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .rate-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .nav {
    overflow-x: auto;
  }

  .main {
    padding: 16px;
  }

  .dual,
  .modal-grid,
  .detail-grid,
  .image-item,
  .selected-field,
  .list-item,
  .history-head {
    grid-template-columns: 1fr;
  }

  .list-item,
  .history-head {
    flex-direction: column;
  }

  .history-actions {
    width: 100%;
    justify-content: space-between;
  }

  .actions {
    width: 100%;
  }

  .actions button {
    flex: 1;
  }

  .actions.compact button {
    flex: 0 0 38px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rate-grid {
    grid-template-columns: 1fr;
  }

  .filters-grid {
    grid-template-columns: 1fr;
  }

  .filter-actions,
  .filter-actions button {
    width: 100%;
  }

  .pagination {
    justify-content: stretch;
  }

  .pagination button {
    flex: 1;
  }
}
