:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #657084;
  --line: #dfe5ef;
  --accent: #156f7a;
  --accent-2: #234b8a;
  --ok: #16734b;
  --fail: #a13c32;
  --warn: #9a6a18;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

.login-body {
  display: block;
  background: #edf2f7;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(23, 32, 51, 0.12);
}

.login-card label {
  display: grid;
  gap: 6px;
}

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

.login-error {
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--fail);
  background: #faecea;
  font-weight: 700;
}

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #172033;
  color: white;
}

.brand {
  font-size: 22px;
  font-weight: 700;
  margin: 6px 8px 14px;
}

.user-panel {
  display: grid;
  gap: 3px;
  margin: 0 0 20px;
  padding: 11px 12px;
  border: 1px solid rgba(215, 222, 235, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.user-panel strong {
  overflow-wrap: anywhere;
}

.user-panel span {
  color: #b8c3d6;
  font-size: 12px;
  font-weight: 600;
}

nav {
  display: grid;
  gap: 6px;
}

nav a {
  color: #d7deeb;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 7px;
  font-weight: 600;
}

nav a:hover,
nav a.active {
  background: #243249;
  color: #ffffff;
}

main {
  padding: 28px;
  max-width: 1480px;
  width: 100%;
}

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

h1 {
  margin: 0 0 6px;
  font-size: 30px;
}

h2 {
  margin: 28px 0 12px;
  font-size: 20px;
}

.subheading {
  margin: 18px 0 8px;
  color: #39465b;
  font-size: 16px;
}

p {
  margin: 0;
  color: var(--muted);
}

.search {
  display: flex;
  gap: 8px;
  min-width: 320px;
}

input,
button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
}

input {
  min-width: 0;
  flex: 1;
  padding: 0 12px;
  background: white;
}

select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: white;
  color: var(--ink);
  font: inherit;
}

button {
  padding: 0 14px;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 700;
}

.secondary-button {
  background: white;
  color: var(--accent-2);
  border-color: var(--line);
}

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

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi,
.split article,
.table-wrap,
.detail-grid,
.empty,
.error {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi {
  padding: 17px;
}

.kpi span,
.detail-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

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

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

.split article {
  padding: 0;
}

.filter-panel {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-panel {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-panel.narrow {
  max-width: 560px;
}

.stack-form {
  display: grid;
  gap: 14px;
}

.stack-form label {
  display: grid;
  gap: 6px;
}

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

.stack-form button {
  justify-self: start;
}

.notice {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 7px;
  font-weight: 700;
}

.notice.success {
  color: var(--ok);
  background: #e8f5ee;
}

.notice.error {
  color: var(--fail);
  background: #faecea;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.filter-grid label {
  display: grid;
  gap: 6px;
}

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

.search-with-scan {
  grid-column: span 2;
}

.search-input-row {
  display: flex;
  gap: 8px;
}

.search-input-row input {
  width: 100%;
}

.scanner-modal[hidden] {
  display: none;
}

.scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.62);
}

.scanner-panel {
  width: min(560px, 100%);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 70px rgba(23, 32, 51, 0.28);
}

.scanner-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.scanner-head h2 {
  margin: 0 0 4px;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
  background: white;
  color: var(--ink);
  border-color: var(--line);
}

.scanner-video-wrap {
  position: relative;
  background: #101827;
}

.scanner-video-wrap video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

#scanner-reader {
  width: 100%;
}

#scanner-reader video {
  width: 100% !important;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

#scanner-reader__dashboard_section,
#scanner-reader__scan_region {
  background: #101827;
}

#scanner-reader__dashboard_section {
  padding: 10px !important;
}

#scanner-reader__dashboard_section button {
  min-height: 36px;
}

.scanner-frame {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 36%;
  height: 28%;
  border: 3px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(16, 24, 39, 0.28);
}

.scanner-status {
  padding: 14px 18px 0;
  color: var(--ink);
  font-weight: 700;
}

.scanner-actions {
  padding: 14px 18px 18px;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.filter-actions a {
  color: var(--accent-2);
  font-weight: 700;
  text-decoration: none;
}

.filter-actions span {
  margin-left: auto;
  color: var(--muted);
  font-weight: 700;
}

.dashboard-chart {
  padding: 18px;
}

.detail-section,
.status-panel {
  margin-bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-section {
  overflow: hidden;
}

.detail-section > .section-heading {
  margin: 0;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.detail-section > .table-wrap,
.detail-section > .detail-grid,
.detail-section > .empty,
.detail-section > .image-grid {
  border: 0;
  border-radius: 0;
  margin-bottom: 0;
}

.detail-section > .subheading {
  margin: 16px 18px 8px;
}

.status-panel {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
  border-left: 5px solid var(--accent);
}

.status-kicker {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.status-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.status-facts div {
  min-width: 130px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
}

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

.status-facts strong {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 0 0 4px;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(120px, 170px) minmax(180px, 1fr) minmax(170px, auto);
  gap: 14px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.chart-label strong {
  display: block;
}

.chart-label span,
.chart-values {
  color: var(--muted);
  font-size: 13px;
}

.stacked-bar {
  display: flex;
  width: 100%;
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f7;
}

.stacked-bar span {
  display: block;
  min-width: 0;
}

.bar-ok {
  background: var(--ok);
}

.bar-fail {
  background: var(--fail);
}

.chart-values {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
}

.ok-dot {
  background: var(--ok);
}

.fail-dot {
  background: var(--fail);
}

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

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

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

th {
  color: #39465b;
  font-size: 13px;
  background: #f8fafc;
}

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

.row-link {
  color: var(--accent-2);
  font-weight: 700;
  text-decoration: none;
}

.row-link:hover {
  text-decoration: underline;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: -4px 0 18px;
}

.primary-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  text-decoration: none;
}

.primary-link:hover {
  background: #105d66;
}

.button-icon {
  display: inline-grid;
  min-width: 34px;
  height: 24px;
  place-items: center;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 11px;
  letter-spacing: 0;
}

.button-link {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #435069;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  background: #e8f5ee;
}

.badge.fail {
  color: var(--fail);
  background: #faecea;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 18px;
}

.detail-grid div {
  padding: 14px;
  background: white;
}

.detail-grid strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

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

.image-card {
  margin: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #eef2f7;
}

.image-card figcaption {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
}

.image-card figcaption span {
  color: var(--muted);
  font-size: 13px;
}

.empty,
.error {
  padding: 18px;
}

.empty {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafc;
}

.error {
  color: var(--fail);
  white-space: pre-wrap;
}

@media (max-width: 820px) {
  body {
    grid-template-columns: 1fr;
  }

  aside {
    position: static;
    height: auto;
  }

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

  main {
    padding: 18px;
  }

  .topbar,
  .split {
    grid-template-columns: 1fr;
    display: grid;
  }

  .chart-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .status-panel,
  .status-facts {
    align-items: stretch;
    flex-direction: column;
  }

  .status-facts {
    justify-content: flex-start;
  }

  .chart-values {
    justify-content: flex-start;
  }

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

  .search-with-scan {
    grid-column: auto;
  }

  .search-input-row {
    flex-direction: column;
  }

  .filter-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-actions span {
    margin-left: 0;
  }

  .search {
    min-width: 0;
    width: 100%;
  }
}
