:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --surface-strong: #ecfdf5;
  --text: #14211f;
  --muted: #64716d;
  --line: #dde5e0;
  --primary: #0f766e;
  --primary-dark: #0a5f59;
  --primary-soft: #ccfbf1;
  --accent: #f59e0b;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 18px 40px rgba(20, 33, 31, 0.14);
  --radius: 8px;
  --bottom-bar-height: 92px;
  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;
  color: var(--text);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

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

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  padding: 18px 14px calc(var(--bottom-bar-height) + env(safe-area-inset-bottom) + 22px);
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px 14px;
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(100%, 430px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.login-brand h1,
.app-header h1,
.section-title h2,
.modal h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-brand h1 {
  font-size: 1.55rem;
  line-height: 1.1;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--primary);
  font-size: 1.5rem;
  font-weight: 900;
}

.login-message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 800;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.app-header h1 {
  font-size: 1.45rem;
  line-height: 1.12;
}

.header-actions {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.user-email {
  max-width: 148px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-pill {
  max-width: 128px;
  padding: 7px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
}

.status-ok {
  color: #065f46;
  background: #d1fae5;
}

.status-warning {
  color: #854d0e;
  background: #fef3c7;
}

.cart-button {
  position: relative;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.24);
}

.cart-icon {
  font-size: 1.15rem;
  font-weight: 900;
}

.cart-count {
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  padding: 0 6px;
  border: 2px solid var(--bg);
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
}

.logout-button,
.small-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--primary-dark);
  background: var(--surface);
  font-weight: 900;
}

.main-content {
  display: grid;
  gap: 12px;
}

.mode-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  font-weight: 900;
}

.mode-button.active {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.mode-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 900;
}

.feedback-banner {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.feedback-banner p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.feedback-icon {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 1.1rem;
  font-weight: 900;
}

.feedback-banner.success {
  border-color: #86efac;
  background: #f0fdf4;
}

.feedback-banner.success .feedback-icon {
  color: #ffffff;
  background: var(--success);
  animation: pop 440ms ease both;
}

.feedback-banner.warning {
  border-color: #fde68a;
  background: #fffbeb;
}

.feedback-banner.warning .feedback-icon {
  color: #854d0e;
  background: #fef3c7;
}

.feedback-banner.danger {
  border-color: #fecaca;
  background: #fef2f2;
}

.feedback-banner.danger .feedback-icon {
  color: #ffffff;
  background: var(--danger);
}

.list-panel,
.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

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

.section-title,
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.scanned-list,
.cart-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 18px 12px;
  border: 1px dashed #b7c8c3;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

.scanned-item,
.cart-item {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.scanned-item.entrada {
  border-left: 5px solid var(--success);
}

.scanned-item.saida,
.scanned-item.finalizado {
  border-left: 5px solid var(--primary);
}

.scanned-item.duplicado,
.scanned-item.nao_encontrado {
  border-left: 5px solid var(--accent);
}

.item-photo {
  width: 68px;
  height: 68px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--surface-soft);
}

.photo-fallback {
  display: grid;
  place-items: center;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-weight: 900;
}

.item-body {
  min-width: 0;
}

.item-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.item-line strong,
.item-body strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-line span,
.barcode-small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.item-body p {
  margin: 4px 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.item-meta span {
  max-width: 100%;
  overflow: hidden;
  padding: 5px 7px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.75rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  min-height: var(--bottom-bar-height);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(15, 118, 110, 0.16);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: blur(14px);
}

.primary-action,
.secondary-action {
  min-height: 56px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 900;
}

.primary-action {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.28);
}

.secondary-action {
  min-width: 100px;
  padding: 0 14px;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  align-items: end;
  padding: 12px;
  background: rgba(5, 12, 11, 0.52);
}

.modal {
  width: min(100%, 620px);
  max-height: min(90vh, 780px);
  margin: 0 auto;
  overflow: auto;
  padding: 14px;
  box-shadow: var(--shadow);
}

.scanner-modal {
  background: #071412;
}

.scanner-modal .modal-header h2,
.scanner-modal .eyebrow {
  color: #ffffff;
}

.compact-modal {
  max-height: none;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  font-size: 1.2rem;
  font-weight: 900;
}

.reader,
.camera-placeholder {
  min-height: 50vh;
  overflow: hidden;
  border: 1px dashed #2dd4bf;
  border-radius: var(--radius);
  background: #0b1715;
}

.reader {
  display: none;
}

.reader.active {
  display: block;
}

.reader video {
  min-height: 50vh;
  object-fit: cover;
}

.camera-placeholder {
  display: grid;
  position: relative;
  place-items: center;
  color: #d9f8ef;
}

.scan-frame {
  position: absolute;
  width: min(72vw, 340px);
  aspect-ratio: 1.55;
  border: 3px solid rgba(45, 212, 191, 0.95);
  border-radius: var(--radius);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.36);
}

.code-summary {
  display: grid;
  gap: 4px;
  margin: 12px 0;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.code-summary span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.code-summary strong {
  overflow-wrap: anywhere;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.form-stack label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 800;
}

.form-stack input,
.form-stack textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 12px;
  color: var(--text);
  background: #ffffff;
}

.form-action {
  width: 100%;
  margin-top: 2px;
}

.photo-preview {
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.photo-preview img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
}

.cart-item {
  grid-template-columns: 62px 1fr 42px;
}

.cart-item .item-photo {
  width: 62px;
  height: 62px;
}

.remove-cart-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  color: var(--danger);
  background: #fee2e2;
  font-weight: 900;
}

.checkout-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 14px;
  bottom: calc(var(--bottom-bar-height) + 16px + env(safe-area-inset-bottom));
  left: 14px;
  z-index: 60;
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #ffffff;
  background: #111827;
  box-shadow: var(--shadow);
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

@keyframes pop {
  0% {
    transform: scale(0.68);
  }
  70% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

@media (min-width: 720px) {
  .app-shell {
    max-width: 760px;
    margin: 0 auto;
    padding-top: 28px;
  }

  .app-header h1 {
    font-size: 1.8rem;
  }

  .reader,
  .reader video,
  .camera-placeholder {
    min-height: 460px;
  }

  .bottom-bar {
    right: 50%;
    left: 50%;
    width: min(760px, 100%);
    transform: translateX(-50%);
    border-right: 1px solid rgba(15, 118, 110, 0.16);
    border-left: 1px solid rgba(15, 118, 110, 0.16);
  }
}
