/* ==========================================================================
   AGROPET — tema visual (claro/escuro) sobre Bootstrap 5
   ========================================================================== */

:root {
  --ap-verde: #16794a;
  --ap-verde-claro: #1fa564;
  --ap-terra: #c9741c;
  --ap-sidebar: #0f2a1f;
  --ap-sidebar-ativo: #16794a;
  --ap-surface: #ffffff;
  --ap-bg: #f2f5f3;
  --ap-borda: rgba(15, 42, 31, .1);
  --ap-texto-suave: #667a70;
  --ap-sombra: 0 1px 2px rgba(15, 42, 31, .06), 0 8px 24px rgba(15, 42, 31, .06);
  --ap-radius: 14px;
}

[data-bs-theme="dark"] {
  --ap-sidebar: #0b1712;
  --ap-surface: #14201b;
  --ap-bg: #0d1613;
  --ap-borda: rgba(255, 255, 255, .08);
  --ap-texto-suave: #9bb0a6;
  --ap-sombra: 0 8px 24px rgba(0, 0, 0, .35);
}

body {
  background: var(--ap-bg);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light dark;
}

/* --- Estrutura ----------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--ap-sidebar);
  color: #d8e6de;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: transform .25s ease;
  z-index: 1045;
}

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.brand {
  display: flex; align-items: center; gap: .65rem;
  padding: 1.15rem 1.25rem; font-size: 1.15rem; letter-spacing: .5px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--ap-verde-claro), var(--ap-verde));
  color: #fff; flex: 0 0 34px;
}
.brand-text { color: #fff; font-weight: 300; }
.brand-text strong { font-weight: 700; }

/* --- Menu lateral por categorias ----------------------------------------- */
.brand { justify-content: space-between; }
.brand-link { display: flex; align-items: center; gap: .65rem; text-decoration: none; min-width: 0; }
.sidebar-toggle {
  background: transparent; border: 0; color: #7d968b; width: 28px; height: 28px;
  border-radius: 8px; display: inline-grid; place-items: center; flex: 0 0 28px;
  transition: background .18s ease, color .18s ease;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }

.sidebar-busca { position: relative; padding: .75rem .75rem .25rem; }
.sidebar-busca i {
  position: absolute; left: 1.4rem; top: 50%; transform: translateY(-30%);
  color: #7d968b; font-size: .8rem; pointer-events: none;
}
.sidebar-busca .form-control {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  color: #eaf3ee; padding-left: 2rem; border-radius: 10px;
}
.sidebar-busca .form-control::placeholder { color: #7d968b; }
.sidebar-busca .form-control:focus {
  background: rgba(255,255,255,.1); color: #fff; border-color: var(--ap-verde-claro); box-shadow: none;
}

.app-nav { padding: .5rem .6rem 1rem; overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; }
.app-nav::-webkit-scrollbar { width: 6px; }
.app-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 6px; }

.nav-secao-titulo {
  display: flex; align-items: center; gap: .5rem; padding: .55rem .8rem .3rem;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: #6f8a7e; font-weight: 700;
}
.nav-favoritos { border-bottom: 1px solid rgba(255,255,255,.07); margin-bottom: .35rem; padding-bottom: .35rem; }

.nav-item-link, .nav-grupo-botao {
  position: relative; width: 100%; text-align: left; background: transparent; border: 0;
  color: #b9cdc3; border-radius: 10px; padding: .58rem .75rem;
  display: flex; align-items: center; gap: .7rem; font-size: .92rem; text-decoration: none;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-item-link:hover, .nav-grupo-botao:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item-link.active, .nav-grupo-botao.active { color: #fff; }
.nav-item-link.active { background: var(--ap-sidebar-ativo); box-shadow: 0 6px 16px rgba(22,121,74,.35); }
.nav-grupo.aberto > .nav-grupo-botao { background: rgba(255,255,255,.06); color: #fff; }
.nav-texto { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-seta { font-size: .7rem; color: #7d968b; transition: transform .22s ease; flex: 0 0 auto; }
.nav-grupo.aberto .nav-seta { transform: rotate(180deg); }

.nav-submenu {
  max-height: 0; overflow: hidden; opacity: .4;
  transition: max-height .28s ease, opacity .2s ease;
  margin-left: 1.35rem; border-left: 1px solid rgba(255,255,255,.09);
}
.nav-grupo.aberto > .nav-submenu { max-height: 1400px; opacity: 1; }

.nav-sub-link {
  position: relative; display: flex; align-items: center; gap: .5rem;
  padding: .42rem .7rem; margin: 1px 0 1px .5rem; border-radius: 8px;
  color: #9fb7ab; font-size: .855rem; text-decoration: none;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.nav-sub-link:hover { background: rgba(255,255,255,.07); color: #fff; transform: translateX(2px); }
.nav-sub-link.active { background: var(--ap-sidebar-ativo); color: #fff; font-weight: 600; }
.nav-sub-link.desabilitado { color: #62786e; cursor: not-allowed; }
.nav-sub-titulo {
  display: block; padding: .6rem .7rem .25rem 1.2rem;
  font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: #6f8a7e; font-weight: 700;
}
.nav-badge {
  font-size: .6rem; padding: .12rem .38rem; border-radius: 20px;
  background: rgba(255,255,255,.09); color: #8fa89c; text-transform: uppercase; letter-spacing: .04em;
}
.nav-badge.destaque { background: var(--ap-terra); color: #fff; }

.nav-fav {
  opacity: 0; background: transparent; border: 0; color: #7d968b; font-size: .72rem;
  padding: 0 .15rem; transition: opacity .15s ease, color .15s ease; flex: 0 0 auto;
}
.nav-item-link:hover .nav-fav, .nav-sub-link:hover .nav-fav, .nav-fav.marcado { opacity: 1; }
.nav-fav.marcado { color: #f2b544; }
.nav-fav:hover { color: #ffd36b; }

.nav-vazio { color: #7d968b; font-size: .82rem; padding: 1rem .8rem; margin: 0; }

/* Modo recolhido (desktop) */
@media (min-width: 992px) {
  .app-shell.menu-recolhido .app-sidebar { width: 74px; flex: 0 0 74px; }
  .app-shell.menu-recolhido .brand-text,
  .app-shell.menu-recolhido .sidebar-busca,
  .app-shell.menu-recolhido .sidebar-footer,
  .app-shell.menu-recolhido .nav-secao-titulo,
  .app-shell.menu-recolhido .nav-texto,
  .app-shell.menu-recolhido .nav-seta,
  .app-shell.menu-recolhido .nav-badge,
  .app-shell.menu-recolhido .nav-fav { display: none; }
  .app-shell.menu-recolhido .brand { justify-content: center; padding: 1.15rem .5rem; }
  .app-shell.menu-recolhido .nav-submenu { display: none; }
  .app-shell.menu-recolhido .nav-item-link,
  .app-shell.menu-recolhido .nav-grupo-botao { justify-content: center; padding: .6rem 0; }
  .app-shell.menu-recolhido .sidebar-toggle i { transform: rotate(180deg); }
}

.sidebar-footer { padding: .8rem 1.25rem; font-size: .75rem; color: #7d968b; border-top: 1px solid rgba(255,255,255,.07); }

/* --- Topbar -------------------------------------------------------------- */
.app-topbar {
  position: sticky; top: 0; z-index: 1030;
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1.25rem;
  background: var(--ap-surface);
  border-bottom: 1px solid var(--ap-borda);
}
.topbar-title { font-size: 1.05rem; font-weight: 600; margin: 0; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: .35rem; flex: 0 0 auto; }
.btn-ghost { border: 1px solid var(--ap-borda); background: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(22,121,74,.1); color: inherit; }

.app-content { padding: 1.25rem; animation: apFade .25s ease; }
@keyframes apFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --- Cartões ------------------------------------------------------------- */
.card {
  border: 1px solid var(--ap-borda);
  border-radius: var(--ap-radius);
  box-shadow: var(--ap-sombra);
  background: var(--ap-surface);
}
.card-header { background: transparent; border-bottom: 1px solid var(--ap-borda); font-weight: 600; }

.kpi { display: flex; align-items: center; gap: .9rem; }
.kpi-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.1rem; color: #fff; flex: 0 0 46px;
  background: linear-gradient(135deg, var(--ap-verde-claro), var(--ap-verde));
}
.kpi-icon.laranja { background: linear-gradient(135deg, #f0a04b, var(--ap-terra)); }
.kpi-icon.azul    { background: linear-gradient(135deg, #4f9dde, #1c5f97); }
.kpi-icon.vermelho{ background: linear-gradient(135deg, #e77b7b, #b3312f); }
.kpi-valor { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: .78rem; color: var(--ap-texto-suave); text-transform: uppercase; letter-spacing: .4px; }

.table > :not(caption) > * > * { padding: .6rem .7rem; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--ap-texto-suave); }

.btn-primary { background: var(--ap-verde); border-color: var(--ap-verde); }
.btn-primary:hover, .btn-primary:focus { background: #12613b; border-color: #12613b; }
.btn-outline-primary { color: var(--ap-verde); border-color: var(--ap-verde); }
.btn-outline-primary:hover { background: var(--ap-verde); border-color: var(--ap-verde); }
a { color: var(--ap-verde); }

.form-control:focus, .form-select:focus {
  border-color: var(--ap-verde-claro);
  box-shadow: 0 0 0 .2rem rgba(31,165,100,.18);
}

/* --- PDV ----------------------------------------------------------------- */
.pdv-grid { display: grid; grid-template-columns: 1fr 380px; gap: 1rem; align-items: start; }
.pdv-total { font-size: 2.4rem; font-weight: 800; line-height: 1; color: var(--ap-verde); }
.pdv-itens { max-height: 46vh; overflow-y: auto; }
.pdv-sugestoes { max-height: 260px; overflow-y: auto; }
.pdv-sugestoes .list-group-item { cursor: pointer; }
.pdv-sugestoes .list-group-item.ativo { background: rgba(31,165,100,.14); }

/* --- Login --------------------------------------------------------------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 15% 10%, #1fa56422, transparent),
              radial-gradient(900px 500px at 90% 90%, #c9741c1f, transparent),
              var(--ap-bg);
}
.login-card { width: 100%; max-width: 400px; }

/* --- Cupom térmico ------------------------------------------------------- */
.cupom { width: 80mm; margin: 0 auto; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
.cupom hr { border-top: 1px dashed #000; }
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}

/* --- Responsivo ---------------------------------------------------------- */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1040; }
.sidebar-backdrop.ativo { display: block; }

@media (max-width: 1200px) { .pdv-grid { grid-template-columns: 1fr; } }

@media (max-width: 991.98px) {
  .app-sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); }
  .app-sidebar.aberta { transform: none; }
  .app-content { padding: 1rem .85rem; }
}

/* ==========================================================================
   Central de Aparência — preferências aplicadas globalmente
   As variáveis (--ap-primaria, --ap-radius, --ap-fonte, --ap-escala...) são
   injetadas no <html> pelo layout a partir de Aparencia::cssInline().
   ========================================================================== */

html { font-size: calc(16px * var(--ap-escala, 1)); }
body { font-family: var(--ap-fonte, "Segoe UI", system-ui, sans-serif); }

/* Densidade das tabelas */
[data-ap-densidade="compacta"] .table > :not(caption) > * > * { padding: .28rem .5rem; }
[data-ap-densidade="confortavel"] .table > :not(caption) > * > * { padding: .5rem .75rem; }
[data-ap-densidade="espacada"] .table > :not(caption) > * > * { padding: .85rem 1rem; }

/* Estilo das linhas */
[data-ap-zebra="1"] .table tbody tr:nth-child(odd) { background: rgba(125, 125, 125, .05); }
[data-ap-bordas="1"] .table th,
[data-ap-bordas="1"] .table td { border: 1px solid var(--ap-borda); }
[data-ap-hover="1"] .table tbody tr:hover { background: var(--ap-primaria-soft, rgba(22, 163, 74, .1)); }

/* Animações */
[data-ap-animacao="0"] *,
[data-ap-animacao="0"] *::before,
[data-ap-animacao="0"] *::after {
  transition: none !important;
  animation: none !important;
}

/* Menu sem ícones */
[data-ap-menu-icones="0"] .app-sidebar .nav-link > i { display: none; }
