/* ============================================================
   PDV Sistema - CSS Mobile-first
   Compatível com Safari iOS e Chrome
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #4f46e5;
  --primary-d: #3730a3;
  --success:   #16a34a;
  --danger:    #dc2626;
  --warning:   #d97706;
  --bg:        #0f0f1a;
  --bg2:       #1a1a2e;
  --bg3:       #252540;
  --card:      #1e1e35;
  --border:    #2d2d50;
  --text:      #e2e2f0;
  --text-muted:#9090b0;
  --radius:    12px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
  --nav-h:     60px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- NAVBAR ---------- */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg2);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.navbar::-webkit-scrollbar { display: none; }

.nav-brand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  padding-right: 8px;
}

.nav-menu {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
}
.nav-btn.active, .nav-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* ---------- PAGES ---------- */
.page { display: none; padding-top: calc(var(--nav-h) + 12px); padding-bottom: 24px; min-height: 100vh; }
.page.active { display: block; }

.container { max-width: 600px; margin: 0 auto; padding: 0 12px; }

/* ---------- CARD ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

/* ---------- DASHBOARD CARDS ---------- */
.dash-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.dash-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
}
.dash-card .dc-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 4px; }
.dash-card .dc-value { font-size: 1.25rem; font-weight: 700; }
.dash-card.verde .dc-value  { color: #4ade80; }
.dash-card.azul .dc-value   { color: #60a5fa; }
.dash-card.laranja .dc-value{ color: #fb923c; }
.dash-card.roxo .dc-value   { color: #a78bfa; }

/* ---------- FORMS ---------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.form-group label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="tel"],
input[type="date"],
select,
textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1rem;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
  transition: border .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}
select option { background: var(--bg3); }
textarea { resize: vertical; }

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.input-row > .form-group { margin-bottom: 0; }
.flex1 { flex: 1; }

.search-input {
  width: 100%;
  margin-bottom: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
}

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); opacity: .85; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 8px 14px; font-size: 0.82rem; }
.w100 { width: 100%; }

/* Produto inativo */
.list-item.inativo { opacity: 0.5; }
.badge-inativo { display: inline-block; font-size: 0.7rem; background: #6b7280; color: #fff; border-radius: 4px; padding: 1px 6px; vertical-align: middle; margin-left: 6px; }

.btn-finalizar { padding: 18px; font-size: 1.1rem; margin-top: 8px; }

/* ---------- TIPO PAGAMENTO ---------- */
.tipo-pagamento {
  display: flex;
  gap: 10px;
  margin: 12px 0;
}
.btn-tipo {
  flex: 1;
  padding: 12px;
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all .15s;
}
.btn-tipo.active {
  border-color: var(--primary);
  background: rgba(79,70,229,.15);
  color: var(--text);
}

/* ---------- CLIENTE BADGE ---------- */
.cliente-badge {
  background: rgba(79,70,229,.15);
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.92rem;
}
.cliente-badge .remove-btn {
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  background: none;
  border: none;
  padding: 4px 8px;
}

/* ---------- DROPDOWN ---------- */
.lista-dropdown {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 4px;
  z-index: 50;
}
.lista-dropdown .dropdown-item {
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  -webkit-tap-highlight-color: transparent;
}
.lista-dropdown .dropdown-item:last-child { border-bottom: none; }
.lista-dropdown .dropdown-item:hover { background: var(--bg2); }
.lista-dropdown .dropdown-item .item-sub { font-size: 0.75rem; color: var(--text-muted); }

/* ---------- CARRINHO ---------- */
.item-carrinho {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.item-carrinho:last-child { border-bottom: none; }
.item-carrinho .item-info { flex: 1; }
.item-carrinho .item-nome { font-weight: 600; }
.item-carrinho .item-detalhe { font-size: 0.78rem; color: var(--text-muted); }
.item-carrinho .item-preco { font-weight: 700; color: #60a5fa; white-space: nowrap; padding-left: 8px; }
.item-carrinho .rm-item { color: var(--danger); background: none; border: none; cursor: pointer; padding: 4px 8px; font-size: 1rem; }

.preview-valor {
  background: rgba(22,163,74,.12);
  border: 1px solid var(--success);
  border-radius: 8px;
  padding: 10px 14px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #4ade80;
  margin-bottom: 10px;
}

.total-venda {
  text-align: right;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 12px 0 4px;
  color: #4ade80;
}

.obs-input {
  margin-bottom: 8px;
}

/* ---------- LISTAS ---------- */
.list-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.list-item-info { flex: 1; }
.list-item-nome { font-size: 1rem; font-weight: 600; margin-bottom: 3px; }
.list-item-sub  { font-size: 0.8rem; color: var(--text-muted); }
.list-item-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  margin-left: 8px;
}
.badge-danger  { background: rgba(220,38,38,.2); color: #f87171; }
.badge-success { background: rgba(22,163,74,.2); color: #4ade80; }
.badge-info    { background: rgba(96,165,250,.2); color: #60a5fa; }

.list-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; margin-left: 8px; }

/* ---------- PAGE HEADER ---------- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.page-header h2 { font-size: 1.2rem; }

/* ---------- MODAIS ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: flex-end;
  z-index: 200;
  padding: 0;
}
.modal-box {
  background: var(--bg2);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px 32px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .2s ease;
}
.modal-large { max-height: 85vh; }

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  font-size: 1.05rem;
  font-weight: 700;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* ---------- RELATÓRIOS ---------- */
.rel-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: 14px;
  padding-bottom: 2px;
}
.rel-tabs::-webkit-scrollbar { display: none; }

.rel-tab {
  flex-shrink: 0;
  padding: 9px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.rel-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filtro-periodo { }

.rel-resumo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.rel-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
}
.rel-card .rc-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 4px; }
.rel-card .rc-value { font-size: 1.15rem; font-weight: 700; }

.tabela { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.tabela th, .tabela td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.tabela th { color: var(--text-muted); font-weight: 600; }
.tabela-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--card); }

/* ---------- INFO DEVEDOR ---------- */
.info-devedor {
  background: rgba(220,38,38,.1);
  border: 1px solid rgba(220,38,38,.3);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  z-index: 999;
  white-space: nowrap;
  box-shadow: var(--shadow);
  animation: fadeInOut 2.5s forwards;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateX(-50%) translateY(10px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- HISTORICO ---------- */
.hist-section { margin-bottom: 20px; }
.hist-section h4 { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.hist-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.hist-item:last-child { border-bottom: none; }
.hist-item .hi-date { font-size: 0.75rem; color: var(--text-muted); }

/* ---------- LOGIN ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #0f0f1a 0%, #1a1a35 50%, #0f0f1a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px 16px;
  /* evita zoom no iOS ao focar input */
  touch-action: manipulation;
}
.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 28px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
  /* sobe o box quando o teclado virtual abre no iOS */
  position: relative;
  transform: translateY(0);
}
.login-icon {
  font-size: 3.6rem;
  margin-bottom: 12px;
  display: block;
  line-height: 1;
  /* animação suave de entrada */
  animation: loginPop .4s ease;
}
@keyframes loginPop {
  from { transform: scale(.7); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}
.login-titulo {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -.5px;
}
.login-sub {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 28px;
  line-height: 1.4;
}
/* input de senha maior para dedos */
.login-box .form-group input {
  font-size: 1.1rem;
  padding: 16px 18px;
  border-radius: 14px;
  text-align: center;
  letter-spacing: 4px;
}
.login-box .form-group input::placeholder {
  letter-spacing: normal;
  font-size: 0.95rem;
  color: var(--text-muted);
}
/* botão maior no mobile */
.login-box .btn-finalizar {
  padding: 16px;
  font-size: 1.05rem;
  border-radius: 14px;
  margin-top: 4px;
}
.login-erro {
  background: rgba(220,38,38,.15);
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: #f87171;
  padding: 12px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}
.nav-btn-sair { color: #f87171 !important; margin-left: 4px; }

/* ---------- UTILITIES ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); font-size: 0.85rem; }
.mt8  { margin-top: 8px; }
.mb0  { margin-bottom: 0; }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .es-icon { font-size: 2.5rem; margin-bottom: 8px; }

/* ---------- MEDIA ---------- */
@media (min-width: 600px) {
  .modal { align-items: center; padding: 20px; }
  .modal-box { border-radius: var(--radius); max-height: 80vh; }
  .dash-cards { grid-template-columns: repeat(4, 1fr); }
}
