:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --ink: #16202a;
  --muted: #637083;
  --line: #d8e0e7;
  --brand: #174c5c;
  --brand-dark: #0e3340;
  --accent: #23745f;
  --warn: #a76712;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(22, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, "Noto Sans TC", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--brand-dark);
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #8fd0bd 50%, #e8b34c 100%);
  position: relative;
  flex: 0 0 auto;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: var(--brand-dark);
}

.brand-mark::before {
  width: 22px;
  height: 8px;
  left: 11px;
  top: 12px;
}

.brand-mark::after {
  width: 8px;
  height: 18px;
  left: 18px;
  top: 20px;
}

.brand h1,
.login-panel h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: #c8d9e2;
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #f8fafc;
  text-align: left;
  padding: 0 14px;
}

.nav-tab.active {
  background: #fff;
  color: var(--brand-dark);
  border-color: #fff;
  font-weight: 700;
}

.login-panel {
  margin-top: auto;
  display: grid;
  gap: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 14px;
}

.login-panel form,
.session-box {
  display: grid;
  gap: 12px;
}

.session-box span {
  color: #c8d9e2;
  font-size: 13px;
}

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

.login-panel label {
  color: #d8e7f2;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
}

.main {
  min-width: 0;
  padding: 28px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 28px;
  line-height: 1.2;
}

h3 {
  font-size: 17px;
}

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

.metric-card,
.table-panel,
.form-panel,
.form-grid,
.notice,
.device-card,
.empty-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 104px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric-card span,
.device-card dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 30px;
  line-height: 1;
}

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

.device-card {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.card-top p {
  margin: 5px 0 0;
  color: var(--muted);
}

dl {
  margin: 0;
  display: grid;
  gap: 10px;
}

dl div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
}

.form-panel,
.form-grid {
  padding: 16px;
}

.form-panel {
  display: grid;
  gap: 13px;
  align-content: start;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.compact-form {
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto auto;
}

.two-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.wide-field {
  min-width: 220px;
}

.primary-button,
.text-button,
.ghost-button,
.danger-icon {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

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

.scan-button {
  width: fit-content;
}

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

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

.text-button {
  background: #fff;
  color: var(--brand);
  border-color: var(--line);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
}

.text-button.danger,
.danger-icon {
  color: var(--danger);
}

.danger-icon {
  width: 38px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
}

.table-panel {
  overflow: hidden;
}

.panel-heading {
  min-height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

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

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

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

td:nth-child(5),
td:last-child {
  white-space: normal;
  min-width: 220px;
}

th {
  background: #e7eff2;
  color: #213547;
  font-size: 13px;
}

tbody tr:hover {
  background: #f8fbfd;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-good {
  background: #e5f7ee;
  color: #176548;
}

.status-warn {
  background: #fff3d8;
  color: #8a5a00;
}

.status-danger {
  background: #ffe8e5;
  color: #9f1d15;
}

.notice,
.empty-card,
.empty-row {
  color: var(--muted);
}

.notice {
  padding: 14px 16px;
  line-height: 1.6;
}

.empty-card {
  padding: 24px;
  text-align: center;
}

.empty-row {
  text-align: center;
}

.admin-table {
  min-width: 620px;
}

.label-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  padding: 16px;
}

.qr-label {
  min-height: 154px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.qr-label img {
  width: 112px;
  height: 112px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

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

.qr-label strong,
.qr-label span,
.qr-label small {
  overflow-wrap: anywhere;
}

.qr-label span {
  font-size: 20px;
  font-weight: 800;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(14, 51, 64, 0.72);
  display: grid;
  place-items: center;
  padding: 18px;
}

.scanner-modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.modal-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.scanner-frame {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #0e3340;
  aspect-ratio: 1 / 1;
}

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

.scan-guide {
  position: absolute;
  inset: 18%;
  border: 3px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
}

.scanner-status {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.manual-scan-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 14px;
  }

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

  .nav-tab {
    text-align: center;
    padding: 0 8px;
  }

  .login-panel {
    margin-top: 0;
  }

  .main {
    padding: 18px;
  }

  .metrics-grid,
  .device-grid,
  .split-layout {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid,
  .compact-form {
    grid-template-columns: 1fr 1fr;
  }

  .wide-field {
    grid-column: 1 / -1;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .page-header,
  .metrics-grid,
  .form-grid,
  .form-panel,
  .notice,
  .table-panel:not(:has(.label-grid)) {
    display: none !important;
  }

  .app-shell,
  .main,
  .view.active {
    display: block;
    padding: 0;
  }

  .view {
    display: none !important;
  }

  #adminView {
    display: block !important;
  }

  .label-grid {
    grid-template-columns: repeat(2, 1fr);
    padding: 0;
    gap: 10mm;
  }

  .qr-label {
    box-shadow: none;
    break-inside: avoid;
  }
}

@media (max-width: 720px) {
  .brand {
    align-items: flex-start;
  }

  .nav-tabs,
  .metrics-grid,
  .device-grid,
  .split-layout,
  .form-grid,
  .compact-form,
  .two-fields,
  .manual-scan-form {
    grid-template-columns: 1fr;
  }

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

  h2 {
    font-size: 24px;
  }

  .metric-card strong {
    font-size: 24px;
  }
}
