:root {
  --bg: #ece8dd;
  --surface: #f8f6f0;
  --surface-2: #f0ede4;
  --ink: #23251f;
  --muted: #707468;
  --line: rgba(56, 66, 44, 0.14);
  --olive-900: #314527;
  --olive-800: #415733;
  --olive-700: #65814c;
  --olive-500: #95ad74;
  --amber-600: #d08a3f;
  --amber-500: #e1a25b;
  --red-600: #b95746;
  --green-600: #4b8a53;
  --slate-500: #7c847b;
  --shadow: 0 24px 60px rgba(48, 54, 42, 0.16);
  --shadow-soft: 0 14px 30px rgba(48, 54, 42, 0.1);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(149, 173, 116, 0.22), transparent 24%),
    linear-gradient(180deg, #f4f0e7, #e5ded1 46%, #d8d0c0 100%);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  touch-action: pan-y;
}

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

button {
  border: 0;
  cursor: pointer;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  padding: 14px 15px;
}

textarea {
  resize: vertical;
}

.hidden {
  display: none !important;
}

.helper-text {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.mill-shell,
.auth-shell,
.app-shell {
  min-height: 100vh;
}

.auth-shell,
.app-shell {
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.auth-card,
.device,
.panel,
.hero-card,
.metric-card,
.action-card,
.list-card,
.progress-card,
.map-card,
.notice-card {
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.auth-card,
.panel,
.metric-card,
.action-card,
.list-card,
.progress-card,
.map-card,
.notice-card {
  background: rgba(248, 246, 240, 0.95);
}

.auth-card {
  width: min(760px, 100%);
  padding: 28px;
  border-radius: 32px;
}

.brand-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.brand-mark {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--olive-700), var(--olive-900));
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--olive-700);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.lede,
.panel p,
.metric-card small,
.list-card small {
  color: var(--muted);
  line-height: 1.5;
}

.status-strip,
.global-strip,
.button-row,
.footer-actions,
.hero-line,
.hero-meta,
.panel-head,
.device-header,
.bottom-nav,
.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-badge {
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.neutral { background: rgba(112, 116, 104, 0.12); color: var(--muted); }
.status-badge.success { background: rgba(75, 138, 83, 0.14); color: var(--green-600); }
.status-badge.warn { background: rgba(208, 138, 63, 0.14); color: var(--amber-600); }
.status-badge.danger { background: rgba(185, 87, 70, 0.14); color: var(--red-600); }

.notice-card {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: 18px;
}

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

#appNoticeCard[data-tone="danger"] {
  border-color: rgba(185, 87, 70, 0.34);
  background: rgba(185, 87, 70, 0.08);
}

#appNoticeCard[data-tone="warn"] {
  border-color: rgba(208, 138, 63, 0.34);
  background: rgba(208, 138, 63, 0.08);
}

#appNoticeCard[data-tone="success"] {
  border-color: rgba(75, 138, 83, 0.34);
  background: rgba(75, 138, 83, 0.08);
}

.form-grid,
.stat-grid,
.review-list,
.status-list,
.list-stack {
  display: grid;
  gap: 14px;
}

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

.field span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  background: rgba(255, 255, 255, 0.84);
}

.camera-stage {
  height: clamp(220px, 34vh, 300px);
  border-radius: 22px;
  border: 1px dashed rgba(59, 84, 43, 0.28);
  display: grid;
  place-items: center;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  background:
    radial-gradient(circle at center, rgba(135, 165, 102, 0.14), transparent 34%),
    rgba(235, 239, 228, 0.9);
  overflow: hidden;
}

.camera-feed {
  width: 100%;
  height: clamp(220px, 34vh, 300px);
  border-radius: 22px;
  object-fit: cover;
  background: #24301d;
  border: 1px solid rgba(59, 84, 43, 0.18);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.scan-session-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-soft);
}

.scan-session-card p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
}

.checkbox-field span {
  margin: 0;
}

.btn {
  min-height: 48px;
  padding: 13px 16px;
  border-radius: 16px;
  font-weight: 700;
  transition: transform 140ms ease, filter 140ms ease;
}

.btn:hover,
.action-card:hover,
.nav-item:hover,
.list-card:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.btn.primary { background: linear-gradient(180deg, var(--olive-700), var(--olive-900)); color: #fff; }
.btn.secondary { background: linear-gradient(180deg, #efe1c6, #dcc38f); color: #4a3918; }
.btn.ghost { background: rgba(112, 116, 104, 0.1); color: var(--ink); }
.btn.danger { background: linear-gradient(180deg, #d87b5b, #b94f3b); color: #fff; }
.btn.compact { min-height: 42px; padding: 10px 14px; }

.terminal-log {
  margin: 0;
  padding: 16px;
  min-height: 120px;
  border-radius: 18px;
  background: #273124;
  color: #dae4d2;
  white-space: pre-wrap;
  overflow: auto;
}

.device {
  width: min(480px, 100%);
  max-width: 100%;
  min-height: min(950px, 94vh);
  max-height: 94vh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 16px;
  border-radius: 36px;
  background:
    linear-gradient(180deg, rgba(251, 249, 244, 0.98), rgba(239, 235, 226, 0.96)),
    radial-gradient(circle at top, rgba(149, 173, 116, 0.14), transparent 38%);
  box-shadow: var(--shadow);
}

.panel-head,
.device-header {
  align-items: flex-start;
  justify-content: space-between;
}

.hero-card {
  border-radius: 24px;
  padding: 18px;
  background:
    radial-gradient(circle at top right, rgba(225, 162, 91, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(62, 83, 46, 0.98), rgba(49, 69, 39, 0.98));
  color: #fff;
}

.hero-card p,
.hero-card .eyebrow {
  color: rgba(255, 255, 255, 0.82);
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #8ed078;
  box-shadow: 0 0 0 6px rgba(142, 208, 120, 0.16);
}

.hero-line { align-items: center; }

.screen-stack {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.screen {
  display: none;
}

.screen.active {
  display: grid;
  gap: 14px;
}

.panel,
.metric-card,
.action-card,
.list-card,
.progress-card,
.map-card {
  border-radius: 22px;
  padding: 16px;
}

.metric-card strong,
.review-row strong,
.status-row strong,
.list-card strong,
.progress-card strong {
  display: block;
  font-size: 20px;
  margin: 6px 0;
}

.metric-card span,
.review-row span,
.status-row span,
.list-card span,
.progress-card span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.action-card,
.list-card {
  text-align: left;
  background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(240,237,228,0.92));
}

.action-card strong,
.list-card strong {
  font-size: 16px;
}

.scan-card {
  overflow: hidden;
  min-width: 0;
}

.scan-summary-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.76);
  padding: 12px 14px;
}

.scan-summary-card small {
  display: block;
  margin-top: 4px;
}

.scan-card-topline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.scan-code {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  font-size: 15px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.scan-card-details {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  min-width: 0;
}

.scan-detail-row {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.scan-detail-row span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scan-detail-row strong {
  display: block;
  max-width: 100%;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.scan-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.review-row,
.status-row {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,0.82);
  padding: 14px;
}

.empty-state strong {
  font-size: 16px;
}

.empty-state small {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}

.history-card.selected,
.list-card.selected {
  border-color: rgba(101, 129, 76, 0.46);
  box-shadow: inset 0 0 0 1px rgba(101, 129, 76, 0.36);
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.mini-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(149, 173, 116, 0.14);
  color: var(--olive-900);
  font-size: 12px;
  font-weight: 700;
}

.detail-section {
  display: grid;
  gap: 10px;
}

.detail-section h4 {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--olive-900);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.progress-bar {
  margin-top: 10px;
  height: 12px;
  border-radius: 999px;
  background: rgba(112, 116, 104, 0.14);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--olive-700), var(--amber-600));
  transition: width 200ms ease;
}

.map-card {
  min-height: 220px;
  overflow: hidden;
}

.map-placeholder {
  height: 220px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  text-align: center;
  padding: 18px;
}

.map-canvas,
.leaflet-container {
  width: 100%;
  height: 220px;
}

.leaflet-container {
  background: #d8d0c0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.leaflet-control-attribution {
  background: rgba(248, 246, 240, 0.9);
}

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

.nav-item {
  min-height: 44px;
  border-radius: 16px;
  background: rgba(112, 116, 104, 0.1);
  font-weight: 700;
}

.nav-item.active {
  background: rgba(149, 173, 116, 0.34);
}

@media (max-width: 640px) {
  .auth-card {
    padding: 22px;
  }

  .brand-row,
  .form-grid,
  .stat-grid,
  .action-grid {
    grid-template-columns: 1fr;
  }

  .device {
    width: 100%;
    min-height: 100vh;
    max-height: none;
    border-radius: 0;
    padding: 14px;
  }

  .app-shell {
    padding: 0;
  }

  .panel-head,
  .device-header {
    flex-direction: column;
  }

  .scan-card-meta {
    justify-content: stretch;
  }
}
