:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #171d23;
  --panel-soft: #1e252c;
  --line: #303a43;
  --text: #f2f6f8;
  --muted: #9eabb5;
  --accent: #2fd17c;
  --accent-dark: #0f7e4b;
  --danger: #ff6b6b;
  --warning: #f3c969;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: radial-gradient(circle at top left, rgba(47, 209, 124, 0.08), transparent 34rem), var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

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

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1014;
  color: var(--text);
  padding: 0 0.85rem;
}

input:focus,
button:focus-visible {
  outline: 3px solid rgba(47, 209, 124, 0.35);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) max(0.9rem, env(safe-area-inset-right)) max(1.4rem, env(safe-area-inset-bottom)) max(0.9rem, env(safe-area-inset-left));
}

.topbar,
.scanner-header,
.records-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 0.85rem;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  text-decoration: none;
}

.topbar {
  margin-bottom: 1rem;
}

.eyebrow,
.muted,
label span,
.summary-grid span,
.latest-scan span {
  color: var(--muted);
  font-size: 0.84rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.55rem, 1.2rem + 1vw, 2.2rem);
  line-height: 1.1;
}

h2 {
  font-size: 1rem;
}

.panel,
.scanner-panel,
.records-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 29, 35, 0.92);
  box-shadow: var(--shadow);
}

.setup-panel,
.records-panel {
  padding: 1rem;
}

.field-grid {
  display: grid;
  gap: 0.85rem;
  margin-top: 0.9rem;
}

label {
  display: grid;
  gap: 0.35rem;
}

.scanner-panel {
  margin-top: 1rem;
  overflow: hidden;
}

.scanner-header {
  padding: 1rem;
}

.scanner-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.camera-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 260px;
  max-height: 65vh;
  background: #050708;
  overflow: hidden;
}

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

.scan-guide {
  position: absolute;
  inset: 28% 8%;
  border: 2px solid rgba(47, 209, 124, 0.9);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
}

.latest-scan {
  display: grid;
  gap: 0.25rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--line);
}

.latest-scan strong {
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 1rem 0;
}

.summary-grid div {
  display: grid;
  gap: 0.25rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.summary-grid strong {
  font-size: 1.5rem;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.sync-panel {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11171c;
}

.sync-panel span {
  color: var(--muted);
  font-size: 0.84rem;
}

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

.secondary-button {
  background: #28313a;
}

.danger-button {
  background: #61272b;
}

.icon-button {
  width: 44px;
  flex: 0 0 44px;
  background: var(--panel-soft);
  font-size: 1.4rem;
}

.records-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.record-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11171c;
}

.record-main {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.barcode {
  font-size: 1rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.record-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.qty-row {
  display: grid;
  grid-template-columns: 44px minmax(4.5rem, 1fr) 44px 44px;
  gap: 0.45rem;
  align-items: center;
}

.qty-row input {
  min-height: 44px;
  text-align: center;
}

.qty-button {
  background: #26323b;
}

.delete-button {
  background: #54252a;
  color: #ffd8d8;
}

.admin-load-button {
  align-self: end;
}

.admin-record-card {
  grid-template-columns: minmax(0, 1fr) auto;
}

.admin-qty {
  min-width: 3rem;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  background: #26323b;
  text-align: center;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  left: 1rem;
  z-index: 20;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1014;
  color: var(--text);
  box-shadow: var(--shadow);
}

@media (min-width: 520px) {
  .field-grid,
  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-card {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 0.65fr);
    align-items: center;
  }
}

@media (min-width: 720px) {
  .toolbar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
