/* ============================================================
   RESET & VARIÁVEIS
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #f48fb1;
  --primary-dark: #e91e8c;
  --primary-light: #fce4ec;
  --accent: #ce93d8;
  --success: #66bb6a;
  --warning: #ffa726;
  --danger: #ef5350;
  --bg: #fdf6f9;
  --surface: #ffffff;
  --text: #333333;
  --text-light: #888888;
  --border: #f0d6e4;
  --shadow: 0 2px 12px rgba(244,143,177,0.15);
  --radius: 14px;
  --radius-sm: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;

  /* Safe areas para notch e barra de navegação */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);

  /* Largura máxima do layout no desktop */
  --max-width: 480px;
}

/* ============================================================
   BASE
   ============================================================ */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  height: 100%;
  background: #f0e0ea; /* fundo externo visível no desktop */
  font-family: var(--font);
  color: var(--text);
  font-size: 16px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* ============================================================
   WRAPPER — centraliza o app no desktop como "celular"
   ============================================================ */
#app-wrapper {
  position: relative;
  width: 100%;
  max-width: var(--max-width);
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
}

/* ============================================================
   SCREENS
   ============================================================ */
.screen {
  display: none;
  flex-direction: column;
  position: absolute;
  inset: 0;
  background: var(--bg);
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary);
  color: white;
  padding-top:    max(14px, calc(14px + var(--safe-top)));
  padding-bottom: 14px;
  padding-left:   max(16px, calc(16px + var(--safe-left)));
  padding-right:  max(16px, calc(16px + var(--safe-right)));
  min-height: 60px;
  box-shadow: 0 2px 8px rgba(244,143,177,0.35);
  flex-shrink: 0;
  gap: 8px;
}

.app-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header h2 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-back {
  background: rgba(255,255,255,0.25);
  border: none;
  color: white;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  min-width: 76px;
  transition: background 0.15s;
}

.btn-back:hover  { background: rgba(255,255,255,0.35); }
.btn-back:active { background: rgba(255,255,255,0.45); }

.btn-icon {
  background: rgba(255,255,255,0.25);
  border: none;
  color: white;
  font-size: 1.25rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.btn-icon:hover  { background: rgba(255,255,255,0.35); }
.btn-icon:active { background: rgba(255,255,255,0.45); }

/* ============================================================
   RESUMO DIÁRIO
   ============================================================ */
.daily-summary {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.daily-summary::-webkit-scrollbar { display: none; }

.summary-card {
  flex: 1;
  min-width: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 9px 5px;
  gap: 4px;
}

.summary-card.highlight-pending {
  background: #fff8e1;
  border: 1.5px solid #ffe082;
}

.summary-label {
  font-size: 0.58rem;
  color: var(--text-light);
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  line-height: 1.3;
}

.summary-value {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--primary-dark);
  text-align: center;
  word-break: break-all;
}

.summary-value.green  { color: var(--success); }
.summary-value.orange { color: var(--warning); }
.summary-value.red    { color: var(--danger);  }

/* ============================================================
   BUSCA
   ============================================================ */
.search-bar {
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-bar input {
  width: 100%;
  padding: 11px 16px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

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

/* ============================================================
   LISTA GENÉRICA (scrollável)
   ============================================================ */
.list-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  /* Espaço generoso no final para não cobrir com FAB + safe area */
  padding: 12px 14px calc(90px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) transparent;
}

.list-container::-webkit-scrollbar       { width: 4px; }
.list-container::-webkit-scrollbar-track { background: transparent; }
.list-container::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}

/* ============================================================
   ESTADO VAZIO
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-light);
}

.empty-state .empty-icon {
  font-size: 3.2rem;
  display: block;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 0.92rem;
  line-height: 1.7;
}

/* ============================================================
   CARD DE CLIENTE
   ============================================================ */
.client-card {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 13px 12px;
  box-shadow: var(--shadow);
  border: 1.5px solid transparent;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  gap: 8px;
}

.client-card:hover {
  box-shadow: 0 4px 18px rgba(244,143,177,0.25);
  border-color: var(--primary-light);
}

/* Área clicável principal */
.client-card-main {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 10px;
  cursor: pointer;
  min-width: 0;
}

.client-card-main:active { opacity: 0.72; }

.client-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
  user-select: none;
}

.client-info {
  flex: 1;
  min-width: 0;
}

.client-name {
  font-size: 0.97rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-meta {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 2px;
}

.client-badges {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-shrink: 0;
}

.badge {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 12px;
  white-space: nowrap;
}

.badge-pending { background: #fff3e0; color: var(--warning); }
.badge-paid    { background: #e8f5e9; color: var(--success); }

.client-arrow {
  font-size: 1.1rem;
  color: var(--text-light);
}

/* Botão excluir cliente */
.btn-delete-client {
  background: #fce4ec;
  border: none;
  color: var(--danger);
  font-size: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.btn-delete-client:hover  { background: #ffcdd2; }
.btn-delete-client:active { transform: scale(0.9); }

/* ============================================================
   CARD DE PRODUTO
   ============================================================ */
.product-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 14px;
  box-shadow: var(--shadow);
  gap: 12px;
  transition: box-shadow 0.15s;
}

.product-card:hover {
  box-shadow: 0 4px 18px rgba(244,143,177,0.25);
}

.product-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.product-info { flex: 1; min-width: 0; }

.product-name {
  font-size: 0.97rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-price {
  font-size: 0.83rem;
  color: var(--primary-dark);
  font-weight: 600;
  margin-top: 2px;
}

.btn-delete {
  background: #fce4ec;
  border: none;
  color: var(--danger);
  font-size: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.btn-delete:hover  { background: #ffcdd2; }
.btn-delete:active { transform: scale(0.9); }

/* ============================================================
   ITEM DE PRODUTO NO PEDIDO
   ============================================================ */
.order-item {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 12px;
  box-shadow: var(--shadow);
  gap: 10px;
  transition: background 0.25s, box-shadow 0.15s;
}

.order-item:hover {
  box-shadow: 0 4px 18px rgba(244,143,177,0.22);
}

.order-item-info { flex: 1; min-width: 0; }

.order-item-name {
  font-size: 0.93rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-item-price {
  font-size: 0.77rem;
  color: var(--text-light);
  margin-top: 2px;
}

.order-item-subtotal {
  font-size: 0.83rem;
  color: var(--primary-dark);
  font-weight: 700;
  text-align: right;
  min-width: 56px;
  flex-shrink: 0;
}

/* Controles de quantidade */
.qty-controls {
  display: flex;
  align-items: center;
  background: var(--primary-light);
  border-radius: 24px;
  overflow: hidden;
  flex-shrink: 0;
}

.btn-qty {
  background: transparent;
  border: none;
  color: var(--primary-dark);
  font-size: 1.25rem;
  font-weight: 700;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}

.btn-qty:hover  { background: rgba(244,143,177,0.25); }
.btn-qty:active { background: var(--primary); color: white; }

.qty-value {
  min-width: 28px;
  text-align: center;
  font-size: 0.97rem;
  font-weight: 700;
  color: var(--text);
  user-select: none;
}

/* ============================================================
   RODAPÉ DO PEDIDO
   ============================================================ */
.order-footer {
  background: var(--surface);
  border-top: 1.5px solid var(--border);
  padding-top: 13px;
  padding-bottom: max(13px, calc(13px + var(--safe-bottom)));
  padding-left:  14px;
  padding-right: 14px;
  flex-shrink: 0;
  box-shadow: 0 -4px 16px rgba(244,143,177,0.12);
}

.order-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.97rem;
  font-weight: 600;
}

.order-total-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary-dark);
}

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

.btn-save {
  flex: 1;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  font-size: 0.93rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-save:hover  { background: #f06292; }
.btn-save:active { background: var(--primary-dark); transform: scale(0.98); }

.btn-paid {
  flex: 1;
  background: var(--success);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  font-size: 0.93rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-paid:hover  { background: #57a05a; }
.btn-paid:active { background: #43a047; transform: scale(0.98); }

/* ============================================================
   FAB — Floating Action Button
   ============================================================ */
.fab {
  position: absolute; /* relativo ao #app-wrapper, não à janela */
  bottom: max(20px, calc(20px + var(--safe-bottom)));
  right: 16px;
  background: var(--primary-dark);
  color: white;
  border: none;
  border-radius: 28px;
  padding: 15px 22px;
  font-size: 0.97rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(233,30,140,0.35);
  z-index: 100;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  white-space: nowrap;
}

.fab:hover {
  background: #c2185b;
  box-shadow: 0 6px 20px rgba(233,30,140,0.42);
}

.fab:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(233,30,140,0.3);
}

/* ============================================================
   HISTÓRICO
   ============================================================ */
.history-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--border);
  transition: box-shadow 0.15s;
}

.history-card:hover       { box-shadow: 0 4px 18px rgba(244,143,177,0.22); }
.history-card.paid        { border-left-color: var(--success); }
.history-card.pending     { border-left-color: var(--warning); }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.history-date {
  font-size: 0.76rem;
  color: var(--text-light);
}

.history-status {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.history-status.paid    { background: #e8f5e9; color: var(--success); }
.history-status.pending { background: #fff3e0; color: var(--warning); }

.history-items {
  font-size: 0.83rem;
  color: var(--text-light);
  margin-bottom: 8px;
  line-height: 1.55;
}

.history-total {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--primary-dark);
}

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

.btn-small {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-small.success { background: #e8f5e9; color: var(--success); }
.btn-small.danger  { background: #fce4ec; color: var(--danger);  }

.btn-small:hover  { opacity: 0.82; }
.btn-small:active { transform: scale(0.96); }

/* ============================================================
   MODAL — bottom sheet
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.48);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 999;
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding-top: 24px;
  padding-left:  20px;
  padding-right: 20px;
  padding-bottom: max(28px, calc(20px + var(--safe-bottom)));
  width: 100%;
  max-width: var(--max-width);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-box h3 {
  font-size: 1.08rem;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--primary-dark);
}

.modal-box input,
.modal-box select {
  width: 100%;
  padding: 13px 15px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

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

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

.btn-cancel {
  flex: 1;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-light);
  transition: background 0.15s;
}

.btn-cancel:hover { background: #fafafa; }

.btn-confirm {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary-dark);
  color: white;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-confirm:hover  { background: #c2185b; }
.btn-confirm:active { transform: scale(0.97); }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: max(90px, calc(82px + var(--safe-bottom)));
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 11px 22px;
  border-radius: 24px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  max-width: min(88vw, 400px);
  text-align: center;
  white-space: normal;
  word-break: break-word;
  pointer-events: none;
}

.toast.hidden  { display: none; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger);  }
.toast.info    { background: var(--primary-dark); }

/* ============================================================
   DESKTOP — tela larga (> 520px)
   ============================================================ */
@media (min-width: 520px) {
  body {
    align-items: center; /* centraliza verticalmente no desktop */
  }

  #app-wrapper {
    height: 100dvh;
    height: 100vh;
    max-height: 860px;     /* limita a altura como um celular */
    border-radius: 24px;
    overflow: hidden;
    margin: auto;
  }

  /* No desktop o FAB fica fixo dentro do wrapper */
  .fab {
    bottom: 20px;
    right: 16px;
  }

  /* Toast centralizado no wrapper */
  .toast {
    bottom: 96px;
  }

  /* Modal limitado à largura do app */
  .modal-box {
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: 28px;
  }

  /* Hover nos cards só no desktop */
  .client-card:hover {
    transform: translateY(-1px);
  }

  .product-card:hover {
    transform: translateY(-1px);
  }
}

/* ============================================================
   MOBILE PEQUENO (< 360px) — ex: iPhone SE
   ============================================================ */
@media (max-width: 359px) {
  .app-header h1 { font-size: 1rem; }
  .app-header h2 { font-size: 0.9rem; }

  .btn-back {
    font-size: 0.78rem;
    padding: 7px 9px;
    min-width: 60px;
  }

  .summary-value  { font-size: 0.78rem; }
  .summary-label  { font-size: 0.54rem; }
  .summary-card   { min-width: 60px; padding: 8px 3px; }

  .btn-qty        { width: 34px; height: 34px; font-size: 1.1rem; }
  .qty-value      { min-width: 24px; font-size: 0.9rem; }

  .btn-save,
  .btn-paid       { font-size: 0.82rem; padding: 12px 6px; }

  .order-total-value { font-size: 1.15rem; }

  .fab { padding: 13px 18px; font-size: 0.88rem; }
}

/* ============================================================
   LANDSCAPE MOBILE — orientação horizontal
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  .app-header {
    padding-top: 8px;
    padding-bottom: 8px;
    min-height: 48px;
  }

  .daily-summary { padding: 6px 10px; }
  .summary-card  { padding: 6px 4px; }

  .list-container {
    padding-bottom: calc(70px + var(--safe-bottom));
  }

  .order-footer {
    padding-top: 8px;
    padding-bottom: max(8px, calc(8px + var(--safe-bottom)));
  }

  .fab {
    bottom: max(10px, calc(10px + var(--safe-bottom)));
    padding: 11px 18px;
    font-size: 0.88rem;
  }
}

/* ============================================================
   BOTÃO WHATSAPP
   ============================================================ */
.btn-whatsapp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 13px 10px;
  background: #25D366;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
}

.btn-whatsapp:hover  { background: #1ebe5d; }
.btn-whatsapp:active { background: #17a34a; transform: scale(0.98); }
.btn-whatsapp svg    { flex-shrink: 0; }

/* ============================================================
   BANNER INSTALAÇÃO iOS
   ============================================================ */
.ios-banner {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1a2e;
  color: white;
  padding: 12px 16px;
  padding-bottom: max(12px, calc(12px + var(--safe-bottom)));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.82rem;
  line-height: 1.5;
  z-index: 500;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
}

.ios-banner.hidden { display: none; }

.ios-banner span { flex: 1; }

.ios-banner button {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 1rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ios-banner button:active { background: rgba(255,255,255,0.3); }