:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #15803d;
  --border: #e5e7eb;
  --warning: #f59e0b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; }

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 0 6px;
}

.brand {
  font-weight: 700;
  font-size: 1.2rem;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 14px;
}

.nav-link {
  text-decoration: none;
  padding: 10px 14px;
  background: #e5e7eb;
  border-radius: 12px;
  white-space: nowrap;
}

.nav-link.active {
  background: var(--primary);
  color: white;
}

.page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.04);
}

.compact-card { padding: 14px 16px; }
.grow { min-width: 0; }

.auth-wrap {
  min-height: 85vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: 100%;
  max-width: 430px;
}

h1, h2 { margin: 0 0 12px; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label { display: flex; flex-direction: column; gap: 6px; }
input, select, textarea, button {
  font: inherit;
}

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e5e7eb; color: var(--text); }

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 600;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }

.stats-grid,
.responsive-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.stat-card {
  grid-column: span 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-card strong { font-size: 1.8rem; }

.responsive-grid > .card:first-child { grid-column: span 4; }
.responsive-grid > .card:last-child { grid-column: span 8; }

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

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

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

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge-warning { background: #fef3c7; color: #92400e; }

.scan-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.detail-grid > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.helper-box {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 14px;
}

.scanner-box {
  width: 100%;
  max-width: 560px;
  background: #111827;
  color: white;
  border-radius: 18px;
  padding: 14px;
}

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

video {
  width: 100%;
  border-radius: 14px;
  background: black;
}

@media (max-width: 900px) {
  .stat-card { grid-column: span 6; }
  .responsive-grid > .card:first-child,
  .responsive-grid > .card:last-child,
  .detail-grid > div {
    grid-column: span 12;
  }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .app-shell { padding: 10px; }
  .topbar { align-items: flex-start; }
  .stat-card { grid-column: span 12; }
  .section-head { flex-direction: column; align-items: stretch; }
  th, td { padding: 10px 8px; font-size: 0.92rem; }
}
