:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #18202f;
  --muted: #637083;
  --line: #dce3ee;
  --primary: #1e66f5;
  --primary-dark: #174fc0;
  --success: #108a4a;
  --success-bg: #e8f8ef;
  --warning: #a86500;
  --warning-bg: #fff4d8;
  --danger: #b42318;
  --danger-bg: #ffe7e4;
  --radius: 8px;
  --shadow: 0 14px 40px rgba(20, 35, 65, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 14px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  color: var(--ink);
  background: #e8edf5;
}

button.secondary:hover {
  background: #dce5f1;
}

button.danger {
  background: var(--danger);
}

button.warning {
  background: #b7791f;
}

button.success {
  background: var(--success);
}

button.ghost {
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--line);
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  color: var(--ink);
  background: #ffffff;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, #eaf1ff 0%, #f7fafc 54%, #f5f7fb 100%);
}

.login-panel {
  width: min(470px, 100%);
  padding: 20px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-panel p {
  margin: 0 0 16px;
  color: var(--muted);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand-title {
  font-size: 17px;
  line-height: 1.2;
  font-weight: 800;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.user-strip,
.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.user-strip {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: calc(100vh - 66px);
}

.side-nav {
  padding: 14px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.side-nav button {
  width: 100%;
  margin-bottom: 8px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  text-align: left;
}

.side-nav button.active {
  color: var(--primary);
  background: #eef4ff;
  border-color: #cfe0ff;
}

.content {
  padding: 18px;
  min-width: 0;
}

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

.page-title h1,
.page-title h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.panel {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(20, 35, 65, 0.04);
}

.grid {
  display: grid;
  gap: 12px;
}

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

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

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

.metric {
  padding: 13px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric strong {
  display: block;
  font-size: 25px;
  line-height: 1.1;
}

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

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.tabs button {
  min-width: max-content;
  color: var(--ink);
  background: #e8edf5;
}

.tabs button.active {
  color: #ffffff;
  background: var(--primary);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

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

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

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

td .actions button {
  min-height: 34px;
  padding: 0 10px;
}

.notice {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #f8fafc;
}

.notice.success {
  color: #075d31;
  background: var(--success-bg);
  border-color: #99dfb9;
}

.notice.warning {
  color: #774600;
  background: var(--warning-bg);
  border-color: #f2cc76;
}

.notice.danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #ffb4ad;
}

.scanner-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
  gap: 14px;
}

#qr-reader {
  width: 100%;
  min-height: 310px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0f172a;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: none;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #ffffff;
  background: #111827;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

.result-panel,
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.62);
}

.result-panel.show,
.modal.show {
  display: flex;
}

.result-card,
.modal-content {
  width: min(640px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: var(--radius);
  padding: 18px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.result-card.success {
  color: #ffffff;
  background: #0f8f4f;
}

.result-card.warning {
  color: #593600;
  background: #fff3cd;
}

.result-card.danger {
  color: #ffffff;
  background: #b42318;
}

.result-card h2 {
  margin: 0 0 10px;
  font-size: 31px;
  line-height: 1.05;
}

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

.qr-card {
  break-inside: avoid;
  padding: 10px;
  text-align: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.qr-card img {
  width: 150px;
  height: 150px;
  object-fit: contain;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .topbar,
  .layout,
  .grid.two,
  .grid.three,
  .grid.four,
  .scanner-grid {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: sticky;
    top: 83px;
    z-index: 9;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav button {
    width: auto;
    min-width: max-content;
    margin: 0;
  }

  .content {
    padding: 12px;
  }

  .page-title {
    align-items: stretch;
    flex-direction: column;
  }
}

@media print {
  .topbar,
  .side-nav,
  .tabs,
  button,
  form,
  .no-print {
    display: none !important;
  }

  body {
    background: #ffffff;
  }

  .layout {
    display: block;
  }

  .content,
  .panel {
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .qr-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
