:root {
  --bg: #f7f8f4;
  --surface: #ffffff;
  --surface-2: #edf2ec;
  --text: #18221f;
  --muted: #65716c;
  --primary: #24463f;
  --primary-strong: #17302b;
  --accent: #d9a441;
  --line: #dce3dd;
  --danger: #b43232;
  --success: #287a4d;
  --shadow: 0 10px 30px rgba(24, 34, 31, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(36, 70, 63, 0.08), transparent 210px),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(82px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 68px;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
}

.status-line {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

main {
  min-height: calc(100vh - 170px);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

h1 {
  margin: 0 0 18px;
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 1.2;
}

.login-panel,
.scan-form,
.last-scan,
.settings-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.login-panel {
  margin-top: 34px;
}

.login-status {
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

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

input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--text);
  outline: none;
  padding: 0 13px;
  font-size: 17px;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 70, 63, 0.14);
}

.code-field input {
  min-height: 62px;
  font-size: 24px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.scanner-fallback {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 15px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:active {
  background: var(--primary-strong);
}

.secondary-button {
  background: var(--surface-2);
  color: var(--primary);
  border: 1px solid var(--line);
}

.secondary-button:active {
  background: #dfe8df;
}

.small {
  min-height: 40px;
  padding: 0 12px;
}

.icon-button {
  width: 46px;
  min-width: 46px;
  padding: 0;
  color: var(--primary);
  background: var(--surface);
  border: 1px solid var(--line);
}

svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  flex: 0 0 auto;
}

.scan-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.scan-head h1,
.section-head h1 {
  margin: 0;
}

.pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.action-grid,
.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.message {
  min-height: 42px;
  margin: 12px 0;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
}

.message:empty {
  visibility: hidden;
}

.message.ok {
  color: var(--success);
  border-color: rgba(40, 122, 77, 0.25);
  background: rgba(40, 122, 77, 0.08);
}

.message.error {
  color: var(--danger);
  border-color: rgba(180, 50, 50, 0.25);
  background: rgba(180, 50, 50, 0.08);
}

.camera-panel {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  max-height: 64vh;
  background:
    linear-gradient(145deg, rgba(36, 70, 63, 0.92), rgba(24, 34, 31, 0.96)),
    #111;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

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

.scan-frame {
  position: absolute;
  inset: 26% 11%;
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.camera-hint {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--primary);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.hidden {
  display: none;
}

.last-scan {
  margin-top: 14px;
}

.empty-state {
  color: var(--muted);
  min-height: 40px;
  display: flex;
  align-items: center;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--muted);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.history-item.ok {
  border-left-color: var(--success);
}

.history-item.failed {
  border-left-color: var(--danger);
}

.history-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.history-code {
  font-size: 18px;
  font-weight: 860;
  word-break: break-word;
}

.history-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.history-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(720px, 100%);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(247, 248, 244, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.tab {
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 800;
}

.tab svg {
  width: 21px;
  height: 21px;
}

.tab.active {
  color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow);
}

@media (max-width: 420px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  h1 {
    font-size: 26px;
  }

  .action-grid,
  .settings-actions {
    grid-template-columns: 1fr;
  }

  .code-field input {
    font-size: 21px;
  }
}
