:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #edf7f4;
  --text: #14201f;
  --muted: #60706d;
  --line: #d8e3df;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 12px 28px rgba(22, 32, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

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

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 248, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand div {
  display: grid;
  min-width: 0;
}

.brand strong {
  font-size: 1rem;
}

.brand span,
.metric small,
label span,
.item-main span,
.item-meta small,
.detail-item small {
  color: var(--muted);
  font-size: 0.78rem;
}

.icon-button {
  display: grid;
  width: 42px;
  min-width: 42px;
  padding: 0;
  place-items: center;
}

main {
  display: grid;
  gap: 14px;
  padding: 14px 12px 24px;
}

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

.metric {
  display: grid;
  min-height: 68px;
  align-content: center;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric span {
  overflow-wrap: anywhere;
  font-size: 1.16rem;
  font-weight: 800;
}

.metric-state span {
  color: var(--accent);
}

.metric-state.offline span {
  color: var(--danger);
}

.panel,
.filters,
.tab-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel.hidden,
.hidden {
  display: none;
}

body.auth-locked .status-strip,
body.auth-locked .active-panel,
body.auth-locked .filters,
body.auth-locked .tabs,
body.auth-locked .tab-panel {
  display: none;
}

.panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.panel-heading,
.list-header,
.retry-row,
.qr-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1,
h2 {
  margin: 0;
  font-size: 1.04rem;
  line-height: 1.2;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill.ok {
  background: #dff7ec;
  color: #067647;
}

.empty-state {
  display: grid;
  min-height: 72px;
  align-content: center;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

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

.detail-item {
  display: grid;
  min-width: 0;
  gap: 3px;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
}

.detail-item strong {
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

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

.retry-row {
  min-height: 34px;
  color: var(--muted);
  font-size: 0.86rem;
}

.text-button {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--accent-2);
  font-weight: 700;
}

.filters {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
  padding: 12px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

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

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  align-self: end;
  min-height: 42px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tab {
  background: #e9eef0;
  font-weight: 800;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.tab-panel {
  overflow: hidden;
}

.list-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.list-header span {
  color: var(--muted);
  font-weight: 800;
}

.list {
  display: grid;
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  min-height: 70px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  text-align: left;
}

.list-item:last-child {
  border-bottom: 0;
}

.list-item.selected {
  background: #e6f8f3;
}

.item-main {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.item-main strong,
.item-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  display: grid;
  justify-items: end;
  align-content: center;
  gap: 4px;
  min-width: 72px;
}

.item-meta span {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.qr-panel video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  object-fit: cover;
}

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

.result-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.result-line.ok {
  color: #067647;
}

.result-line.bad {
  color: var(--danger);
}

.toast {
  position: fixed;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 50;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: #172120;
  color: #fff;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 560px) {
  main {
    padding-inline: 10px;
  }

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

  .filters,
  .active-order-grid {
    grid-template-columns: 1fr;
  }

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

  .list-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .item-meta {
    grid-template-columns: auto 1fr;
    justify-items: start;
  }
}
