:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --line: #d7ded8;
  --text: #18211b;
  --muted: #607066;
  --green: #14784f;
  --green-soft: #dff2e8;
  --blue: #1f5f99;
  --amber: #a76316;
  --red: #b52c2c;
  --shadow: 0 10px 24px rgba(25, 38, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 46px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

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

.button-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.primary {
  background: var(--green);
  color: #fff;
}

.secondary {
  background: #edf1ee;
  color: var(--text);
  border: 1px solid var(--line);
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  font-size: 26px;
  line-height: 1;
  font-weight: 800;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.status-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
  font-size: 14px;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(330px, 1.05fr) minmax(360px, 1.15fr);
  gap: 14px;
  padding: 14px;
}

section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

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

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.party-panel {
  grid-row: span 2;
}

.active-party {
  min-height: 104px;
  border: 2px solid var(--green);
  border-radius: 8px;
  padding: 14px;
  background: var(--green-soft);
  margin-bottom: 14px;
}

.active-party strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.15;
}

.active-party small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 700;
}

.operator-field {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.operator-field input {
  width: 100%;
  height: 42px;
  margin-top: 5px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}

.party-list {
  display: grid;
  gap: 10px;
}

.party-card {
  width: 100%;
  text-align: left;
  display: block;
  min-height: 82px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px;
}

.party-card.active {
  border-color: var(--green);
  background: #edf8f2;
}

.party-card b {
  display: block;
  font-size: 17px;
  line-height: 1.2;
  margin-bottom: 6px;
}

.party-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.weight-panel {
  text-align: center;
}

.weight-display {
  height: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 78px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.weight-unit {
  color: var(--muted);
  font-weight: 800;
  margin-top: -6px;
}

.gate-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0;
}

.gate {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f4f6f4;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.gate.ok {
  background: var(--green-soft);
  border-color: var(--green);
  color: var(--green);
}

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

.alert {
  min-height: 42px;
  margin-top: 14px;
  padding: 11px 12px;
  border-radius: 8px;
  background: #eef2f5;
  color: var(--blue);
  font-weight: 700;
}

.alert.error {
  background: #f8e7e7;
  color: var(--red);
}

.alert.good {
  background: var(--green-soft);
  color: var(--green);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  color: var(--green);
}

.switch input {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #101710;
  border-radius: 8px;
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.roi-box {
  position: absolute;
  left: 20%;
  top: 34%;
  width: 60%;
  height: 28%;
  border: 3px solid #35d17f;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.22);
}

#ocrCanvas {
  width: 100%;
  height: 92px;
  display: block;
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.camera-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 10px;
  align-items: end;
}

.camera-controls label {
  text-align: left;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.camera-controls input {
  width: 100%;
  height: 46px;
  margin-top: 5px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 24px;
  font-weight: 800;
}

.quick-test {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.calibration {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.calibration-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

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

.slider-grid label {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.slider-grid input {
  width: 100%;
  accent-color: var(--green);
}

.ocr-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dashboard-panel,
.loss-panel,
.recent-panel {
  min-height: 260px;
}

.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.loss-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.totals div {
  min-height: 72px;
  border-radius: 8px;
  background: #f4f7f4;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.loss-grid div {
  min-height: 72px;
  border-radius: 8px;
  background: #f8faf8;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.totals span {
  font-size: 28px;
  font-weight: 900;
}

.loss-grid span {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.totals small {
  color: var(--muted);
  font-weight: 800;
}

.loss-grid small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

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

.cycle-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.cycle-control span,
.cycle-control b {
  display: block;
}

.cycle-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}

.cycle-control b {
  font-size: 15px;
  line-height: 1.25;
  word-break: break-word;
}

.cycle-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.cycle-actions button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
}

.process-recent {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.cycle-list,
.passport-cycles {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.process-row {
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.process-row b,
.process-row span {
  display: block;
}

.process-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.process-weight {
  color: var(--blue);
  font-size: 18px;
  font-weight: 900;
  white-space: nowrap;
}

.cycle-row {
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

.cycle-row.open {
  border-color: var(--green);
  background: var(--green-soft);
}

.cycle-row.closed_warning {
  border-color: var(--amber);
  background: #fff8ef;
}

.cycle-row b,
.cycle-row span {
  display: block;
}

.cycle-row b {
  font-size: 13px;
  line-height: 1.25;
  word-break: break-word;
}

.cycle-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.cycle-metrics {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 3px 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cycle-metrics span {
  color: var(--text);
  white-space: nowrap;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 6px;
  text-align: left;
}

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

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

.recent-item {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.recent-item.needs-reprint {
  border-color: var(--amber);
  background: #fff8ef;
}

.recent-item b {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.recent-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.recent-weight {
  font-size: 18px;
  font-weight: 900;
  color: var(--green);
  white-space: nowrap;
}

.recent-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.recent-actions button,
.recent-actions a {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.mini-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f5f7f4;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.mini-tag.warn {
  border-color: var(--amber);
  background: #fff0dc;
  color: var(--amber);
}

.link-pill {
  color: var(--text);
  text-decoration: none;
}

.passport-layout {
  display: grid;
  gap: 14px;
  padding: 14px;
  max-width: 1180px;
  margin: 0 auto;
}

.markers-layout {
  display: grid;
  gap: 14px;
  padding: 14px;
  max-width: 1280px;
  margin: 0 auto;
}

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

.marker-totals div {
  min-height: 86px;
  border-radius: 8px;
  background: #f4f7f4;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.marker-totals span {
  font-size: 32px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.marker-totals small {
  color: var(--muted);
  font-weight: 800;
  margin-top: 7px;
}

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

.camera-card {
  min-height: 132px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.camera-card-head b,
.camera-card-head span {
  display: block;
}

.camera-card-head b {
  font-size: 16px;
  line-height: 1.2;
}

.camera-card-head span {
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  text-align: right;
}

.camera-card p {
  margin: 10px 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 700;
}

.camera-card-metrics {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.camera-card-metrics span {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 0 8px;
  background: #f4f7f4;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.marker-filter-head {
  align-items: flex-start;
}

.marker-filters {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(150px, 0.8fr) minmax(190px, 1.1fr);
  gap: 8px;
  min-width: min(100%, 560px);
}

.marker-filters select,
.marker-filters input {
  height: 40px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

.marker-list {
  display: grid;
  gap: 10px;
}

.marker-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.marker-row.legacy_no_marker {
  border-color: var(--amber);
  background: #fff8ef;
}

.marker-row.linked_video {
  border-color: var(--green, #1c9c4f);
  background: #f1fbf4;
}

.marker-row.partial_video {
  border-color: var(--amber);
  background: #fffbef;
}

.marker-video-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.marker-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.marker-main b,
.marker-main span {
  display: block;
}

.marker-main b {
  font-size: 17px;
  line-height: 1.25;
}

.marker-main span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  word-break: break-word;
}

.marker-main strong {
  color: var(--green);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.marker-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.marker-meta span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.marker-window {
  min-height: 36px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.marker-window > span:first-child {
  margin-right: auto;
  color: var(--blue);
  font-size: 13px;
  font-weight: 900;
}

.passport-hero {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.passport-hero h1 {
  margin-top: 8px;
  font-size: 34px;
  line-height: 1.1;
}

.passport-id {
  margin-top: 10px;
  color: var(--muted);
  font-weight: 800;
}

.passport-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.metric {
  min-height: 96px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.metric span {
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.metric small {
  color: var(--muted);
  font-weight: 800;
  margin-top: 7px;
}

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

.detail {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.detail span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 5px;
}

.detail b {
  display: block;
  font-size: 16px;
  line-height: 1.25;
}

.passport-packages {
  display: grid;
  gap: 8px;
}

.package-row {
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.package-row.focused {
  border-color: var(--green);
  background: var(--green-soft);
}

.package-row b,
.package-row span {
  display: block;
}

.package-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.package-row strong {
  font-size: 22px;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

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

  .party-panel {
    grid-row: auto;
  }

  .topbar {
    height: auto;
    min-height: 72px;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    flex-direction: column;
  }

  .passport-grid,
  .details-grid,
  .marker-totals,
  .loss-grid,
  .process-actions {
    grid-template-columns: 1fr;
  }

  .camera-grid,
  .marker-filters,
  .marker-meta {
    grid-template-columns: 1fr;
  }

  .cycle-control,
  .cycle-row,
  .marker-main {
    grid-template-columns: 1fr;
  }

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

  .cycle-actions button {
    flex: 1 1 130px;
  }

  .cycle-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    text-align: left;
  }

  .marker-window {
    justify-content: stretch;
  }

  .marker-window > span:first-child {
    width: 100%;
  }

  .passport-hero h1 {
    font-size: 28px;
  }
}
