:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #eef1ed;
  --line: #cfd6d1;
  --text: #18201c;
  --muted: #66716b;
  --accent: #146c5c;
  --accent-strong: #0a4c42;
  --ok: #16834f;
  --ng: #b42318;
  --warn: #9a6700;
  --shadow: 0 18px 50px rgba(24, 32, 28, 0.08);
}

* {
  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;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
}

.app-header h1,
.app-header p {
  margin: 0;
}

.app-header h1 {
  font-size: 21px;
  line-height: 1.2;
}

.app-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.header-statuses {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.weather-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-right: 10px;
  min-width: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.weather-status img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex: 0 0 auto;
}

.weather-status--loading {
  color: var(--warn);
}

.weather-status--ready {
  color: var(--ok);
}

.weather-status--error {
  color: var(--ng);
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  min-height: calc(100vh - 78px);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: #fbfcfa;
  overflow: auto;
}

.upload-zone,
.tool-panel,
.result-banner,
.details-grid,
.result-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.upload-zone {
  position: relative;
  padding: 22px;
  text-align: center;
  outline: none;
}

.upload-zone:focus,
.upload-zone.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 108, 92, 0.16);
}

.upload-zone input {
  display: none;
}

.upload-zone__icon {
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 30px;
  line-height: 1;
  font-weight: 500;
}

.upload-zone h2,
.tool-panel h2 {
  margin: 0;
  font-size: 16px;
}

.upload-zone p {
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.primary-button,
.secondary-button,
.upload-zone button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button,
.upload-zone button {
  color: #fff;
  background: var(--accent);
}

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

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

.secondary-button:hover {
  border-color: var(--accent);
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.tool-panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.control-row,
.toggle-row,
.number-row {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

.control-row span,
.number-row span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

.control-row strong {
  color: var(--text);
}

.toggle-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf7;
}

.toggle-row strong,
.toggle-row small {
  display: block;
}

.toggle-row strong {
  color: var(--text);
  font-size: 14px;
}

.toggle-row small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.toggle-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.advanced-controls {
  opacity: 0.45;
  pointer-events: none;
}

.advanced-controls.is-manual {
  opacity: 1;
  pointer-events: auto;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="number"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

.image-list {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.image-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  text-align: left;
}

.image-item.is-active {
  border-color: var(--accent);
  background: #eef8f5;
}

.image-item__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 13px;
}

.image-item__result {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
}

.result-ok {
  color: var(--ok);
  background: #e6f5ee;
}

.result-ng {
  color: var(--ng);
  background: #feeceb;
}

.result-failed {
  color: var(--warn);
  background: #fff4ce;
}

.workspace {
  min-width: 0;
  padding: 18px;
  display: grid;
  grid-template-rows: auto minmax(180px, 32vh) minmax(0, 1fr);
  gap: 16px;
}

.result-banner,
.batch-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

.batch-toolbar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.batch-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.report-info-status {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.report-info-status.is-saved {
  color: var(--ok);
}

.canvas-wrap {
  position: relative;
  justify-self: start;
  width: 100%;
  max-width: none;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202823;
  min-height: 180px;
  max-height: 320px;
  display: grid;
  place-items: center;
}

#imageCanvas {
  display: block;
  max-width: 100%;
  max-height: 300px;
  width: auto;
  height: auto;
  cursor: crosshair;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  color: #dfe7e1;
  text-align: center;
  padding: 24px;
}

.empty-state strong {
  font-size: 18px;
}

.empty-state span {
  color: #aeb9b2;
  font-size: 13px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  overflow: hidden;
}

.details-grid div {
  padding: 14px;
  border-right: 1px solid var(--line);
}

.details-grid div:last-child {
  border-right: 0;
}

.details-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.details-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 15px;
  word-break: break-word;
}

.result-table-wrap {
  overflow: auto;
}

.result-card-panel {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.result-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  max-height: calc(100vh - 430px);
  min-height: 160px;
  overflow: auto;
}

.result-card {
  display: grid;
  grid-template-rows: 140px auto;
  gap: 8px;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  text-align: left;
}

.result-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 108, 92, 0.12);
}

.result-card__thumb {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 6px;
  background: #202823;
  color: #dfe7e1;
  font-size: 12px;
  font-weight: 700;
}

.result-card__thumb canvas {
  display: block;
  max-width: 100%;
  max-height: 140px;
}

.result-card__meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 8px;
  align-items: center;
}

.result-card__name {
  grid-column: 1 / -1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.result-card__meta strong {
  font-size: 22px;
  line-height: 1;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 22, 18, 0.42);
}

.modal__panel {
  position: relative;
  width: min(680px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(16, 22, 18, 0.24);
  padding: 20px;
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal__header h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.report-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

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

.report-form input,
.report-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  resize: vertical;
}

.report-form input:focus,
.report-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 108, 92, 0.14);
}

.report-form__wide,
.modal__actions {
  grid-column: 1 / -1;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

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

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

th {
  color: var(--muted);
  background: #f8faf7;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 1400px) {
  .app-shell {
    grid-template-columns: 300px minmax(0, 1fr);
  }
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  
  .side-panel {
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    grid-template-rows: auto minmax(160px, 260px) minmax(0, 1fr);
  }

  .canvas-wrap {
    width: 100%;
    max-width: none;
  }

  .result-cards {
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

@media (max-width: 620px) {
  .app-header,
  .result-banner,
  .batch-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .batch-actions {
    justify-content: stretch;
  }

  .batch-actions button {
    flex: 1;
  }

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

  .modal__actions {
    flex-direction: column-reverse;
  }

  .workspace,
  .side-panel {
    padding: 12px;
  }

  .result-cards {
    grid-template-columns: 1fr;
  }
}
