/* ==========================================================================
   Calculadora de Bipagem — estilos mobile-first
   ========================================================================== */

:root {
  --color-bg: #f2f4f7;
  --color-surface: #ffffff;
  --color-text: #1a1d29;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-success: #16a34a;
  --color-success-bg: #ecfdf3;
  --color-danger: #dc2626;
  --color-danger-dark: #b91c1c;
  --color-warning: #d97706;
  --color-border: #e5e7eb;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, 0.18);
  --tap-target: 52px;
}

* {
  box-sizing: border-box;
}

/* elementos com display definido pelo autor precisam de override explicito
   para o atributo [hidden], pois CSS de autor tem prioridade sobre o UA */
.scanner-overlay[hidden],
.confirm-overlay[hidden],
.items-list[hidden],
.manual-entry[hidden],
.camera-error[hidden] {
  display: none;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button {
  font-family: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- layout raiz ---------- */

.app {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */

.header {
  text-align: center;
  margin-bottom: 18px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.header-logo {
  display: block;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  object-fit: cover;
  box-shadow: var(--shadow-sm);
}

.header-text {
  text-align: left;
}

.header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---------- abas ---------- */

.tabs {
  display: flex;
  gap: 6px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 8px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
}

.tab-btn.is-active {
  background: var(--color-primary);
  color: #fff;
}

/* ---------- resumo ---------- */

.summary {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.summary-label {
  color: var(--color-text-muted);
}

.summary-value {
  font-weight: 700;
  font-size: 1.05rem;
}

.total-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  border-radius: var(--radius-md);
  padding: 18px 12px;
  color: #fff;
}

.total-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.85;
  margin-bottom: 4px;
}

.total-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  word-break: break-word;
}

/* ---------- botoes base ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  min-height: var(--tap-target);
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-scan {
  width: 100%;
  font-size: 1.1rem;
  margin-bottom: 24px;
}

.btn-icon {
  font-size: 1.3rem;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: #f9fafb;
}

.btn-danger {
  background: #fff;
  color: var(--color-danger);
  border: 1px solid #fecaca;
}

.btn-danger:hover {
  background: #fef2f2;
}

/* ---------- lista de itens ---------- */

.items-section {
  margin-bottom: 8px;
}

.items-title {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  text-transform: uppercase;
  margin: 0 0 10px 4px;
}

.items-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 4px 10px;
}

.items-title-row .items-title {
  margin: 0;
}

.label-total-count {
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.label-total-count strong {
  color: var(--color-text);
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--color-border);
}

.empty-state p {
  margin: 4px 0;
  font-size: 0.95rem;
}

.items-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 14px 14px;
  box-shadow: var(--shadow-sm);
  animation: item-in 0.18s ease;
}

@keyframes item-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.item-index {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-text-muted);
}

.item-code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.item-value {
  font-size: 1.05rem;
  font-weight: 700;
}

.item-delete {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  background: #fef2f2;
  color: var(--color-danger);
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.item-delete:hover {
  background: #fee2e2;
}

/* ---------- acoes finais ---------- */

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- overlay do scanner (fullscreen mobile) ---------- */

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.scanner-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  padding-top: calc(14px + env(safe-area-inset-top));
}

.btn-icon-only {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  color: var(--color-text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon-only:hover {
  background: #e5e7eb;
}

.scanner-header-title {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.scanner-header-spacer {
  width: 44px;
}

.scanner-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 16px 16px 0;
  gap: 14px;
  min-height: 0;
}

/* ---------- palco de captura: camera ou entrada manual ---------- */

.scan-stage {
  position: relative;
  flex: 1;
  min-height: 260px;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.camera-view,
.manual-entry {
  position: absolute;
  inset: 0;
}

.camera-view {
  background: #0b0c10;
}

.camera-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-status-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(15, 18, 30, 0.6);
  color: #fff;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  z-index: 3;
}

.camera-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-success);
  flex-shrink: 0;
}

.camera-status-badge.paused .camera-status-dot {
  background: var(--color-warning);
}

.camera-status-badge.error .camera-status-dot {
  background: var(--color-danger);
}

.viewfinder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.viewfinder-box {
  width: 80%;
  max-width: 340px;
  aspect-ratio: 16 / 9;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  transition: opacity 0.15s ease;
}

.scan-stage.is-paused .viewfinder-box {
  opacity: 0.35;
}

.viewfinder-hint {
  margin-top: 14px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  background: rgba(0, 0, 0, 0.35);
  padding: 6px 14px;
  border-radius: 20px;
  text-align: center;
}

.camera-error {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 28px;
  text-align: center;
  background: #12141c;
  color: #fff;
}

.camera-error p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ---------- modo manual (fallback) ---------- */

.manual-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
}

.manual-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-muted);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.manual-status .status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-primary);
  flex-shrink: 0;
}

.scanner-input {
  width: 100%;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.08em;
  padding: 16px 12px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.scanner-input:focus {
  border-color: var(--color-primary);
}

.link-btn {
  border: none;
  background: none;
  color: var(--color-primary);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}

.link-btn:hover {
  text-decoration: underline;
}

/* ---------- feedback (sobreposto ao palco de captura) ---------- */

.feedback {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  text-align: center;
  background: var(--color-success-bg);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-md);
  animation: feedback-in 0.15s ease;
}

.feedback.is-error {
  background: #fef2f2;
  border-color: #fecaca;
}

@keyframes feedback-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.feedback-icon {
  font-size: 1.6rem;
  color: var(--color-success);
  margin-bottom: 2px;
}

.feedback.is-error .feedback-icon {
  color: var(--color-danger);
}

.feedback-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.feedback-code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.feedback-value {
  font-size: 1.3rem;
  font-weight: 800;
  margin-top: 2px;
}

.scanner-summary {
  width: 100%;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--color-border);
  padding-top: 16px;
  margin-top: auto;
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

.scanner-summary strong {
  color: var(--color-text);
  font-size: 1rem;
}

.scanner-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
}

.btn-pause {
  flex: 1;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-finish {
  flex: 2;
  background: var(--color-primary);
  color: #fff;
}

.btn-finish:hover {
  background: var(--color-primary-dark);
}

/* ---------- confirmacao ---------- */

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 30, 0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.confirm-box {
  width: 100%;
  max-width: 340px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.confirm-box p {
  margin: 0 0 18px;
  font-size: 1rem;
  font-weight: 600;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-actions .btn {
  flex: 1;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1a1d29;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  max-width: 90vw;
  text-align: center;
}

/* ---------- telas maiores ---------- */

@media (min-width: 480px) {
  .actions {
    flex-direction: row;
  }

  .actions .btn {
    flex: 1;
  }
}

@media (min-width: 600px) {
  body {
    padding: 24px 0;
  }

  .app {
    padding-bottom: 40px;
  }

  .scanner-overlay {
    align-items: center;
    justify-content: center;
    padding: 24px;
  }

  .scanner-panel {
    height: min(760px, 92vh);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
  }
}

/* ---------- aba de etiquetas ---------- */

.label-form-section {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.label-value-field,
.label-qty-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label-value-field label,
.label-qty-field label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text-muted);
}

.label-qty-field input {
  width: 100%;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 14px 12px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.label-qty-field input:focus {
  border-color: var(--color-primary);
}

.currency-input-wrap {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: var(--color-bg);
  overflow: hidden;
}

.currency-input-wrap:focus-within {
  border-color: var(--color-primary);
}

.currency-prefix {
  display: flex;
  align-items: center;
  padding: 0 4px 0 14px;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-text-muted);
}

.currency-input-wrap input {
  flex: 1;
  min-width: 0;
  width: 100%;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 14px 14px 14px 4px;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.currency-input-wrap input:focus {
  outline: none;
}

/* itens da fila de etiquetas reaproveitam os estilos de .item-card */

.label-qty-badge {
  font-weight: 700;
  color: var(--color-text-muted);
}

/* ---------- folha de impressao (fora da tela normal) ---------- */

.print-sheet {
  display: none;
}

@media print {
  body {
    background: #fff;
  }

  body * {
    visibility: hidden;
  }

  .print-sheet,
  .print-sheet * {
    visibility: visible;
  }

  .print-sheet {
    display: grid;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    grid-template-columns: repeat(8, 1fr);
    gap: 1.2mm;
  }
}

@page {
  size: A4;
  margin: 8mm;
}

.print-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 12mm;
  padding: 0.3mm;
  border: 1px dashed #999;
  break-inside: avoid;
  page-break-inside: avoid;
  overflow: hidden;
}

.print-label .print-label-value {
  font-weight: 700;
  font-size: 5.5pt;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.2;
  margin-bottom: 0.3mm;
}

.print-label svg {
  width: 92%;
  height: auto;
  max-height: 6.5mm;
}
