/* ── Variáveis ─────────────────────────────────────────── */
:root {
  --verde:      #1a7a3e;
  --verde-claro:#2ecc71;
  --verde-bg:   #e8f5ee;
  --laranja:    #e67e22;
  --laranja-bg: #fef4e8;
  --azul:       #2980b9;
  --azul-bg:    #eaf3fb;
  --cinza:      #7f8c8d;
  --cinza-bg:   #f0f0f0;
  --vermelho:   #e74c3c;
  --bg:         #f4f6f8;
  --card:       #ffffff;
  --txt:        #2c3e50;
  --txt-light:  #7f8c8d;
  --radius:     14px;
  --shadow:     0 2px 12px rgba(0,0,0,.10);
  --tab-h:      64px;
}

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--txt);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── Loading ───────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--verde);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; color: #fff;
}
#loading-overlay .spin {
  width: 44px; height: 44px;
  border: 4px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-overlay p { font-size: 1rem; opacity: .8; }
#loading-overlay.hidden { display: none; }

/* ── Login ─────────────────────────────────────────────── */
#tela-login {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 24px;
  background: linear-gradient(160deg, var(--verde) 0%, #0f4d26 100%);
}
#tela-login.hidden { display: none; }

.login-logo { font-size: 72px; margin-bottom: 12px; }
.login-titulo { color: #fff; font-size: 1.6rem; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: rgba(255,255,255,.7); font-size: .95rem; margin-bottom: 40px; }

.login-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%; max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-card label { display: block; font-size: .85rem; font-weight: 600; color: var(--txt-light); margin-bottom: 8px; }
.login-card select {
  width: 100%; padding: 14px 16px;
  border: 2px solid #e0e0e0; border-radius: 10px;
  font-size: 1rem; color: var(--txt);
  appearance: none; background: #fafafa;
  transition: border-color .2s;
}
.login-card select:focus { outline: none; border-color: var(--verde); }
.login-card select option[value=""] { color: var(--txt-light); }

.btn-entrar {
  margin-top: 20px; width: 100%;
  padding: 16px; border: none; border-radius: 10px;
  background: var(--verde); color: #fff;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
  transition: background .2s, transform .1s;
}
.btn-entrar:active { transform: scale(.98); background: #145f30; }

/* ── App Principal ─────────────────────────────────────── */
#app {
  display: flex; flex-direction: column;
  height: 100vh; max-width: 520px; margin: 0 auto;
}
#app.hidden { display: none; }

/* Header */
.app-header {
  background: var(--verde);
  color: #fff; padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header-info h1 { font-size: 1rem; font-weight: 700; }
.header-info span { font-size: .8rem; opacity: .75; }
.header-actions { display: flex; gap: 10px; align-items: center; }

.btn-icon-header {
  background: rgba(255,255,255,.15); border: none;
  border-radius: 50%; width: 38px; height: 38px;
  color: #fff; font-size: 1.1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.btn-icon-header:active { background: rgba(255,255,255,.3); }

/* Tab Content */
.tab-content {
  flex: 1; overflow-y: auto;
  padding: 16px 14px calc(var(--tab-h) + 16px);
}

/* Bottom Tab Bar */
.tab-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px;
  height: var(--tab-h);
  background: #fff;
  display: flex; align-items: center;
  border-top: 1px solid #e8e8e8;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  z-index: 100;
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  border: none; background: none; cursor: pointer;
  padding: 8px 4px; color: var(--cinza);
  transition: color .2s;
  position: relative;
}
.tab-btn.active { color: var(--verde); }
.tab-btn .tab-icon { font-size: 1.4rem; line-height: 1; }
.tab-btn .tab-label { font-size: .68rem; font-weight: 600; letter-spacing: .02em; }

.badge {
  position: absolute; top: 6px; right: 50%; margin-right: -18px;
  background: var(--vermelho); color: #fff;
  border-radius: 10px; min-width: 18px; height: 18px;
  font-size: .68rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px; border: 2px solid #fff;
}
.badge.hidden { display: none; }

/* ── Status chips ──────────────────────────────────────── */
.status-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: .75rem; font-weight: 700; letter-spacing: .03em;
}
.status-confirmado  { background: var(--azul-bg);    color: var(--azul); }
.status-em_preparo  { background: var(--laranja-bg);  color: var(--laranja); }
.status-saiu_entrega{ background: var(--verde-bg);    color: var(--verde); }
.status-entregue    { background: var(--cinza-bg);    color: var(--cinza); }

/* ── Cards de entrega ──────────────────────────────────── */
.entrega-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
  transition: transform .15s;
}
.entrega-card.em-rota {
  border-left: 4px solid var(--verde-claro);
}
.entrega-card.entregue-hoje {
  opacity: .65;
}

.card-top {
  padding: 14px 16px 10px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.card-num { font-size: .8rem; color: var(--txt-light); font-weight: 600; }
.card-cliente { font-size: 1rem; font-weight: 700; margin-top: 2px; }

.card-body { padding: 0 16px 12px; }

.card-endereco {
  display: flex; align-items: flex-start; gap: 6px;
  font-size: .88rem; color: var(--txt); line-height: 1.4;
  margin-bottom: 8px;
}
.card-endereco-icon { font-size: 1rem; margin-top: 1px; flex-shrink: 0; }

.card-meta {
  display: flex; gap: 14px; font-size: .82rem;
  color: var(--txt-light); margin-bottom: 4px; flex-wrap: wrap;
}
.card-meta span { display: flex; align-items: center; gap: 4px; }

.card-itens-resumo {
  font-size: .8rem; color: var(--txt-light);
  background: var(--bg); border-radius: 8px;
  padding: 8px 10px; margin-top: 8px;
}
.card-itens-resumo .item-linha {
  display: flex; justify-content: space-between;
  padding: 2px 0; border-bottom: 1px solid #ebebeb;
}
.card-itens-resumo .item-linha:last-child { border-bottom: none; }
.card-itens-resumo .item-obs {
  font-size: .75rem; color: var(--cinza); padding: 2px 0 4px 8px;
}
.card-itens-resumo .item-nome { font-weight: 500; }
.card-itens-resumo .item-obs-pizza {
  font-size: .75rem; color: var(--verde); font-style: italic;
  padding: 0 0 4px 8px;
}

.card-actions {
  display: flex; gap: 8px; padding: 10px 16px 14px;
  border-top: 1px solid #f0f0f0;
}

.btn-mapa {
  flex: 0 0 auto; padding: 10px 14px;
  border: 2px solid var(--azul); border-radius: 10px;
  background: #fff; color: var(--azul);
  font-size: .85rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  text-decoration: none;
  transition: background .2s;
}
.btn-mapa:active { background: var(--azul-bg); }

.btn-acao {
  flex: 1; padding: 12px 8px;
  border: none; border-radius: 10px;
  font-size: .9rem; font-weight: 700; cursor: pointer;
  transition: opacity .2s, transform .1s;
}
.btn-acao:active { opacity: .85; transform: scale(.98); }
.btn-iniciar  { background: var(--laranja); color: #fff; }
.btn-confirmar{ background: var(--verde);   color: #fff; }
.btn-entregue { background: var(--cinza-bg); color: var(--cinza); cursor: default; }

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 24px;
}
.empty-icon { font-size: 56px; display: block; margin-bottom: 14px; }
.empty-state h3 { font-size: 1.1rem; color: var(--txt); margin-bottom: 6px; }
.empty-state p { font-size: .88rem; color: var(--txt-light); }

/* ── Stats (perfil) ────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 16px; text-align: center;
}
.stat-num { font-size: 2rem; font-weight: 800; color: var(--verde); }
.stat-label { font-size: .78rem; color: var(--txt-light); margin-top: 4px; }

.perfil-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 20px;
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 20px;
}
.perfil-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--verde-bg); color: var(--verde);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; flex-shrink: 0;
}
.perfil-nome { font-size: 1.1rem; font-weight: 700; }
.perfil-sub { font-size: .82rem; color: var(--txt-light); margin-top: 2px; }

.btn-sair {
  width: 100%; padding: 15px;
  border: 2px solid var(--vermelho); border-radius: 10px;
  background: #fff; color: var(--vermelho);
  font-size: .95rem; font-weight: 700; cursor: pointer;
  transition: background .2s;
}
.btn-sair:active { background: #fdecea; }

/* ── Mensagens ─────────────────────────────────────────── */
.msg-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
  margin-bottom: 12px; cursor: pointer;
  transition: opacity .2s;
  border-left: 4px solid transparent;
}
.msg-card.nao-lida { border-left-color: var(--verde); }
.msg-card.lida { opacity: .65; }

.msg-topo {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.msg-de { font-size: .78rem; font-weight: 700; color: var(--verde); }
.msg-hora { font-size: .75rem; color: var(--txt-light); }
.msg-texto { font-size: .9rem; line-height: 1.5; }
.msg-pedido {
  margin-top: 6px; font-size: .78rem; color: var(--azul);
  background: var(--azul-bg); display: inline-flex;
  align-items: center; gap: 4px; padding: 3px 8px; border-radius: 6px;
}
.msg-geral-tag {
  font-size: .75rem; color: var(--cinza); background: var(--cinza-bg);
  padding: 2px 8px; border-radius: 6px; margin-top: 6px; display: inline-block;
}

/* ── Seção header ──────────────────────────────────────── */
.secao-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.secao-titulo {
  font-size: .82rem; font-weight: 700;
  color: var(--txt-light); text-transform: uppercase; letter-spacing: .06em;
}


/* ── Toast ─────────────────────────────────────────────── */
#toast {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff;
  padding: 10px 20px; border-radius: 24px;
  font-size: .88rem; z-index: 9999;
  opacity: 0; transition: opacity .3s;
  pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ── Pull-to-refresh ───────────────────────────────────── */
.ptr-indicator {
  text-align: center; padding: 10px;
  font-size: .85rem; color: var(--txt-light);
  display: none;
}
.ptr-indicator.visible { display: block; }

/* ── Utilitários ───────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Botão instalar PWA (no header) ───────────────────── */
#btn-instalar {
  background: rgba(255,255,255,.2);
  color: #fff; border: 1px solid rgba(255,255,255,.4);
  border-radius: 20px; padding: 6px 14px;
  font-size: .78rem; font-weight: 700; cursor: pointer;
  white-space: nowrap;
}
#btn-instalar.hidden { display: none !important; }

/* ── Aba: itens na seção header ────────────────────────── */
#aba-entregas.hidden,
#aba-mensagens.hidden,
#aba-perfil.hidden { display: none !important; }

/* ── Responsivo extra ──────────────────────────────────── */
@media (min-width: 520px) {
  .tab-bar { border-radius: 0; }
  .app-header { border-radius: 0; }
}
