:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --ink: #17211b;
  --muted: #607064;
  --panel: #ffffff;
  --line: #dfe5dc;
  --field: #f8faf6;
  --shadow: 0 18px 55px rgba(32, 48, 35, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.72), rgba(246,247,242,0.95)),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1680px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 4.4rem);
  line-height: 0.95;
  font-weight: 780;
  letter-spacing: 0;
}

.lede {
  margin: 12px 0 0;
  max-width: 780px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,0.78);
  color: #465348;
  white-space: nowrap;
}

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

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: #26342a;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.nav-link:hover {
  border-color: #9db79b;
  background: #f4f8f1;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(560px, 700px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(211, 221, 207, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.controls,
.inspector {
  padding: 18px;
}

.section-title {
  margin: 0 0 10px;
  color: #26342a;
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

label.field span {
  display: block;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
}

.controls > .field {
  display: block;
  margin-bottom: 20px;
}

input[type="date"],
input[type="search"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: #6f9e72;
  box-shadow: 0 0 0 3px rgba(111, 158, 114, 0.18);
}

.quick,
.selector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.month-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 20px;
}

.quick button,
.selector-grid button,
.stage-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #2f3d33;
  cursor: pointer;
  transition: transform 120ms ease, border 120ms ease, background 120ms ease;
}

.quick button:hover,
.selector-grid button:hover,
.stage-actions button:hover {
  transform: translateY(-1px);
  border-color: #9db79b;
  background: #f4f8f1;
}

.quick button.active,
.selector-grid button.active {
  border-color: #6f9e72;
  background: #eaf4e8;
  color: #1f512b;
  font-weight: 750;
}

.selector-grid button:disabled {
  cursor: not-allowed;
  color: #a5aea8;
  background: #f3f5f2;
  transform: none;
}

.stage-list {
  display: grid;
  gap: 9px;
  margin-bottom: 12px;
}

.stage-toggle {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
  cursor: pointer;
  user-select: none;
}

.stage-toggle input {
  inline-size: 16px;
  block-size: 16px;
  accent-color: var(--stage-color);
}

.stage-name {
  min-width: 0;
  color: #26342a;
  font-size: 0.91rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.swatch {
  width: 30px;
  height: 10px;
  border-radius: 999px;
  background: var(--stage-color);
}

.stage-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.main {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.92);
}

.stat .label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat .value {
  margin-top: 8px;
  font-size: clamp(1.25rem, 2.4vw, 2rem);
  font-weight: 780;
  line-height: 1.05;
}

.chart-panel {
  position: relative;
  padding: 16px 16px 12px;
}

.chart-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 8px;
}

.chart-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 780;
}

.chart-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.mode {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f8f4;
}

.mode button {
  min-height: 32px;
  min-width: 78px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.mode button.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(32,48,35,0.1);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: clamp(370px, 58vh, 660px);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 7px;
}

.tooltip {
  position: absolute;
  z-index: 3;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 50px));
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
  border: 1px solid rgba(40, 55, 45, 0.14);
  border-radius: 8px;
  background: rgba(255,255,255,0.96);
  box-shadow: 0 18px 40px rgba(32,48,35,0.16);
  padding: 10px;
  opacity: 0;
  transition: opacity 100ms ease;
}

.tooltip.visible {
  opacity: 1;
}

.tooltip strong {
  display: block;
  margin-bottom: 6px;
}

.image-preview {
  display: grid;
  grid-template-rows: auto 220px;
  gap: 10px;
  min-width: 0;
}

.image-preview-head {
  min-width: 0;
}

.image-preview .section-title {
  margin-bottom: 4px;
}

.image-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
  min-height: calc(1.35em * 2);
  overflow-wrap: anywhere;
}

.image-frame {
  position: relative;
  display: grid;
  place-items: center;
  height: 220px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111712;
  overflow: hidden;
}

.image-frame img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-preview.has-image .image-frame img {
  display: block;
}

.image-preview.has-image .image-empty {
  display: none;
}

.image-frame.loading::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border: 3px solid rgba(255,255,255,0.34);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.image-empty {
  padding: 18px;
  color: #cbd5cb;
  font-size: 0.9rem;
  text-align: center;
}

.stage-title {
  margin-top: 18px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.tip-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 7px;
  align-items: center;
  color: #3a483d;
  font-size: 0.86rem;
  padding: 2px 0;
}

.tip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--stage-color);
}

.records {
  padding: 14px;
  overflow: hidden;
}

.records-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.table-wrap {
  max-height: 330px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
  background: #fff;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #eef2ec;
  text-align: right;
  font-size: 0.88rem;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7faf5;
  color: #516050;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

tr:hover td {
  background: #fbfdf9;
}

.review-shell {
  width: min(1740px, calc(100vw - 40px));
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.device-panel,
.image-review-panel {
  padding: 16px;
}

.device-panel {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.review-panel-head {
  margin-bottom: 10px;
}

.device-list {
  display: grid;
  gap: 8px;
}

.device-list button {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
  color: #26342a;
  text-align: left;
  cursor: pointer;
}

.device-list button.active {
  border-color: #6f9e72;
  background: #eaf4e8;
}

.device-list span {
  min-width: 0;
  font-weight: 780;
  overflow-wrap: anywhere;
}

.device-list small {
  color: var(--muted);
  font-size: 0.78rem;
}

.image-review-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 520px);
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
}

.review-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.review-tools {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  gap: 10px;
  align-items: center;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: #334139;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.check-field input {
  inline-size: 16px;
  block-size: 16px;
  accent-color: #6f9e72;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.image-card {
  display: grid;
  grid-template-rows: 180px auto auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.image-card.disabled {
  background: #f4f5f2;
}

.review-image-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  background: #111712;
}

.review-image-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.review-image-frame.unavailable::after {
  content: "Image unavailable";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #111712;
  color: #cbd5cb;
  text-align: center;
}

.image-card.disabled .review-image-frame img {
  filter: grayscale(1);
  opacity: 0.48;
}

.status-pill {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.9);
  color: #26342a;
  font-size: 0.72rem;
  font-weight: 780;
}

.image-card-body {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
}

.image-card-body strong,
.image-card-body span,
.image-card-body small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.image-card-body span,
.image-card-body small {
  color: var(--muted);
  font-size: 0.82rem;
}

.image-card button {
  min-height: 38px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fbfcfa;
  color: #26342a;
  cursor: pointer;
  font-weight: 780;
}

.image-card button.danger {
  color: #9f2733;
}

.image-card button.restore {
  color: #1f6f36;
}

.image-card button:hover {
  background: #f4f8f1;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1050px) {
  header,
  .dashboard,
  .review-layout,
  .image-review-head {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .device-panel {
    position: static;
    max-height: none;
  }

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

@media (max-width: 650px) {
  .shell {
    width: min(100vw - 24px, 1440px);
    padding-top: 18px;
  }

  .date-grid,
  .quick,
  .selector-grid,
  .sidebar,
  .stage-actions,
  .chart-head,
  .records-head,
  .review-tools {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    padding: 12px;
  }

  .canvas-wrap {
    height: 390px;
  }

  .image-frame {
    height: 260px;
  }

  .image-preview {
    grid-template-rows: auto 260px;
  }

  .source-chip,
  .header-actions {
    width: fit-content;
    justify-content: flex-start;
  }
}
