:root {
  color-scheme: light;
  --bg: #eef5f4;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-2: #18a999;
  --danger: #b91c1c;
  --line: #d7e2e0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.shell {
  min-height: 100svh;
  padding: 24px;
}

.center {
  display: grid;
  place-items: center;
}

.app {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 4px 18px;
}

.topbar span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.card, .scanner-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.card {
  width: min(430px, 100%);
  padding: 24px;
}

.compact {
  width: 100%;
  margin-top: 14px;
}

.form-card label {
  display: block;
  color: var(--muted);
  margin-top: 14px;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font: inherit;
  margin-top: 6px;
}

h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }

.logo {
  width: 88px;
  height: 88px;
  object-fit: contain;
  border-radius: 18px;
  background: var(--brand-2);
  margin-bottom: 18px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 0 18px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.secondary {
  background: #e2f3f0;
  color: var(--brand);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--brand);
  font: inherit;
  cursor: pointer;
}

.scanner-card {
  padding: 12px;
}

.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 12px;
  background: #0b1220;
}

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

.scan-frame {
  position: absolute;
  inset: 18%;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.24);
}

.controls, .inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.inline-form input {
  flex: 1 1 230px;
  margin-top: 0;
}

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

select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font: inherit;
}

.list-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.message, .hint {
  min-height: 22px;
  color: var(--muted);
  margin: 12px 0 0;
}

.message.error {
  color: var(--danger);
}

.result {
  white-space: pre-line;
  font-size: 22px;
  font-weight: 800;
  color: var(--brand);
  margin: 14px 0 0;
}

@media (max-width: 640px) {
  .app { padding: 12px; }
  .video-wrap { aspect-ratio: 3 / 4; }
  .button { width: 100%; }
  .controls .button { flex: 1 1 100%; }
}

.admin-layout {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.admin-shell {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 14px;
  margin: 0;
}

.admin-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  background: #fff;
  color: var(--brand);
  font-weight: 700;
  text-decoration: none;
}

.admin-nav a:hover {
  background: #e2f3f0;
}

.admin-content {
  min-width: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  align-items: start;
}

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

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 6px;
}

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

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 700;
}

.table-scroll {
  width: 100%;
  overflow: auto;
}

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

@media (max-width: 860px) {
  .admin-shell {
    display: block;
  }

  .admin-nav {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    margin-bottom: 14px;
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 12px 0 16px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: #f8fbfb;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  line-height: 1.2;
  color: var(--ink);
}

.driver-app {
  width: min(1180px, 100%);
}

.driver-wide-card {
  padding: 22px;
}

.driver-stats {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.driver-stats .stat-card {
  min-height: 92px;
}

.driver-table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.driver-delivery-table,
.driver-detail-table {
  min-width: 1060px;
  font-size: 15px;
}

.driver-delivery-table th,
.driver-delivery-table td,
.driver-detail-table th,
.driver-detail-table td {
  padding: 14px 12px;
  line-height: 1.45;
}

.driver-delivery-table th,
.driver-detail-table th {
  position: sticky;
  top: 0;
  background: #f8fbfb;
  color: #334155;
  z-index: 1;
}

.driver-product-table {
  min-width: 620px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.check-row input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.form-subtitle {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbfb;
  padding: 12px 14px;
}

.form-subtitle strong {
  display: block;
  margin-bottom: 4px;
}

.form-subtitle span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.modal-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.38);
}

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

.modal-card {
  width: min(680px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.22);
}

.modal-card.large {
  width: min(980px, 100%);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.detail-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fbfb;
}

@media (max-width: 640px) {
  .driver-wide-card {
    padding: 16px;
  }

  .driver-delivery-table,
  .driver-detail-table {
    min-width: 980px;
    font-size: 14px;
  }

  .stat-card strong {
    font-size: 22px;
  }

  .modal-panel {
    align-items: flex-end;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .modal-card {
    max-height: 86vh;
  }
}
