/* HiperRoll — CSS único, responsivo, mobile-first.
   Mesma folha para celular e desktop — sem duplicar manutenção. */

:root {
  --color-bg: #f7f7f8;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-muted: #6b7280;
  --color-primary: #0f766e;   /* placeholder — trocar pela cor da marca HiperRoll */
  --color-primary-dark: #0b5c56;
  --color-border: #e5e7eb;
  --color-danger: #b91c1c;
  --radius: 12px;
  --tap-min: 44px; /* alvo de toque mínimo recomendado */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(64px + var(--safe-bottom)); /* espaço pra nav inferior no mobile */
}

a { color: inherit; }

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

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
}

.table-selector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--color-muted);
  cursor: pointer;
  min-height: 32px;
}

.table-selector strong {
  color: var(--color-primary);
}

/* ---------- Conteúdo ---------- */
main {
  padding: 12px 16px 24px;
  max-width: 1100px;
  margin: 0 auto;
}

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-bar input, .search-bar select {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  min-height: var(--tap-min);
}

/* ---------- Grade de produtos: 1-2 colunas no celular, 4-5 no desktop ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 640px) {
  .product-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .product-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1200px) {
  .product-grid { grid-template-columns: repeat(5, 1fr); }
}

.product-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.product-card:active { transform: scale(0.98); }

.product-card .photo {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-card .photo-edit-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.product-card .photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  loading: lazy;
}

.product-card .info {
  padding: 8px 10px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.product-card .code { font-size: 11px; color: var(--color-muted); }
.product-card .name { font-size: 14px; font-weight: 600; line-height: 1.25; }
.product-card .price { font-size: 15px; color: var(--color-primary); font-weight: 700; margin-top: 4px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap-min);
  padding: 10px 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.btn:active { background: var(--color-primary-dark); }
.btn.secondary { background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); }
.btn.danger { background: var(--color-danger); }
.btn.block { width: 100%; }

/* ---------- Nav inferior (mobile-first, também funciona no desktop) ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: var(--safe-bottom);
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  font-size: 12px;
  text-decoration: none;
  color: var(--color-muted);
  min-height: var(--tap-min);
}
.bottom-nav a.active { color: var(--color-primary); font-weight: 700; }
.bottom-nav .icon { display: flex; justify-content: center; margin-bottom: 2px; }
.bottom-nav .icon svg { width: 20px; height: 20px; }

/* ---------- Ícones inline (SVG outline, sem emojis) ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  color: var(--color-text);
  padding: 0;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.danger { color: var(--color-danger); border-color: var(--color-danger); }

/* ---------- Modal de fotos do produto ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}
.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-box { border-radius: var(--radius); }
}
.modal-box h2 { font-size: 16px; margin: 0 0 4px; }
.modal-box .modal-sub { font-size: 13px; color: var(--color-muted); margin: 0 0 16px; }
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}
.photo-thumb-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.photo-thumb-grid .thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-bg);
}
.photo-thumb-grid .thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb-grid .thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  padding: 0;
}
.photo-thumb-grid .thumb-remove svg { width: 13px; height: 13px; }
.photo-thumb-grid .thumb-remove:active { background: var(--color-danger); }

/* ---------- Orçamento: linhas de item ---------- */
.quote-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
}
.quote-item .thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-bg);
  flex-shrink: 0;
}
.quote-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.quote-item .details { flex: 1; min-width: 0; }
.quote-item .details .name { font-size: 14px; font-weight: 600; }
.quote-item .details .sub { font-size: 12px; color: var(--color-muted); }
.quote-item .qty-input {
  width: 56px;
  padding: 6px;
  text-align: center;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  min-height: var(--tap-min);
}
.quote-item .table-pill {
  display: flex;
  gap: 4px;
}
.quote-item .table-pill button {
  min-width: 30px;
  min-height: 30px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  font-size: 12px;
  cursor: pointer;
}
.quote-item .table-pill button.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.quote-total {
  position: sticky;
  bottom: calc(64px + var(--safe-bottom));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 700;
  margin-top: 12px;
}

/* ---------- Histórico ---------- */
.history-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.history-item .client { font-weight: 600; }
.history-item .date { font-size: 12px; color: var(--color-muted); }
.history-item .total { font-weight: 700; color: var(--color-primary); }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--color-border);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--color-muted); font-size: 13px; margin-top: 0; margin-bottom: 20px; }
.login-card input {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  margin-bottom: 12px;
  min-height: var(--tap-min);
}
.login-error { color: var(--color-danger); font-size: 13px; margin-bottom: 12px; min-height: 1em; }

/* ---------- Transições suaves entre telas (evita "flash" branco) ---------- */
body { animation: fade-in .15s ease-in; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Versão do sistema ---------- */
.version-tag {
  position: fixed;
  right: 8px;
  bottom: calc(68px + var(--safe-bottom));
  font-size: 10px;
  color: #9ca3af;
  z-index: 5;
  pointer-events: none;
}

.empty-state {
  text-align: center;
  color: var(--color-muted);
  padding: 48px 16px;
  font-size: 14px;
}
