:root {
  --bg: #F5F6EC;
  --bg-card: #FFFFFF;
  --pine: #23321E;
  --pine-soft: #34462B;
  --gold: #C8963A;
  --gold-soft: #E9C983;
  --green: #4C6B3F;
  --brown: #8B5E34;
  --ink: #23321E;
  --ink-muted: #6B7263;
  --line: #E3E1D2;
  --danger: #A6432E;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35,50,30,0.06), 0 4px 14px rgba(35,50,30,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Work Sans', -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.mono { font-family: 'JetBrains Mono', monospace; font-weight: 600; }

a { color: inherit; text-decoration: none; }

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  background: var(--pine);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: 'Zilla Slab', serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
}
.brand-logo {
  height: 36px;
  width: 36px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.brand-text em { font-style: normal; color: var(--gold-soft); }

.topnav { display: flex; gap: 1.5rem; flex: 1; margin-left: 2rem; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}
.user-name {
  color: var(--gold-soft);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.user-link {
  color: rgba(255,255,255,0.7);
  font-size: 0.82rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.user-link:hover { color: #fff; }
@media (max-width: 900px) {
  .user-name { display: none; }
  .topnav { gap: 1rem; margin-left: 1rem; }
}
.topnav a {
  color: rgba(255,255,255,0.72);
  font-weight: 500;
  font-size: 0.94rem;
  padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
}
.topnav a.active, .topnav a:hover { color: #fff; border-bottom-color: var(--gold); }

@media (max-width: 720px) {
  .topnav { display: none; }
}

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  display: none;
}
@media (max-width: 720px) {
  .bottomnav {
    display: flex;
    position: sticky;
    bottom: 0;
    background: var(--pine);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 20;
  }
  .bottomnav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.55rem 0 0.7rem;
    color: rgba(255,255,255,0.6);
    font-size: 0.72rem;
  }
  .bottomnav a .icon { font-size: 1.15rem; }
  .bottomnav a.active { color: var(--gold-soft); }
}

/* ---------- Content ---------- */
.content {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 2.5rem;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-family: 'Zilla Slab', serif;
  font-size: 1.7rem;
  margin: 0;
  color: var(--pine);
}
.page-header .subtitle {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--pine);
  color: #fff;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--pine-soft); }
.btn.btn-gold { background: var(--gold); color: var(--pine); }
.btn.btn-gold:hover { background: #d9ab54; }
.btn.btn-ghost { background: transparent; color: var(--pine); border: 1px solid var(--line); }
.btn.btn-danger { background: transparent; color: var(--danger); padding: 0.3rem 0.6rem; font-weight: 500; }
.btn.btn-danger:hover { background: #f7e9e5; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.stat-card .label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  font-weight: 600;
}
.stat-card .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.65rem;
  font-weight: 600;
  margin-top: 0.3rem;
  color: var(--pine);
}
.stat-card.accent-gold .value { color: var(--brown); }
.stat-card.accent-green .value { color: var(--green); }
.stat-card .sub { font-size: 0.78rem; color: var(--ink-muted); margin-top: 0.15rem; }

/* ---------- Silo gauge (signature element) ---------- */
.silo {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.3rem 1.4rem;
  margin-bottom: 1.75rem;
}
.silo-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.8rem;
}
.silo-head h2 {
  font-family: 'Zilla Slab', serif;
  font-size: 1.05rem;
  margin: 0;
  color: var(--pine);
}
.silo-head .silo-balance {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--green);
}
.silo-bar {
  height: 26px;
  border-radius: 6px;
  background: repeating-linear-gradient(135deg, #EFECDA, #EFECDA 8px, #E8E4CE 8px, #E8E4CE 16px);
  overflow: hidden;
  display: flex;
  position: relative;
  border: 1px solid var(--line);
}
.silo-bar .fill-vendido {
  background: var(--gold);
  height: 100%;
}
.silo-legend {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.7rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
}
.silo-legend span { display: flex; align-items: center; gap: 0.4rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.produzido { background: #EFECDA; border: 1px solid #D8D3B8; }
.dot.vendido { background: var(--gold); }

/* ---------- Chart ---------- */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.3rem 1.4rem;
  margin-bottom: 1.75rem;
}
.chart-card h2 {
  font-family: 'Zilla Slab', serif;
  font-size: 1.05rem;
  margin: 0 0 1rem;
  color: var(--pine);
}

/* ---------- Tables ---------- */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; min-width: 560px; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #FAFAF3;
}
tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFAF3; }
td.num, th.num { text-align: right; font-family: 'JetBrains Mono', monospace; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Filters ---------- */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  align-items: flex-end;
}
.filter-bar .field { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-bar label { font-size: 0.75rem; color: var(--ink-muted); font-weight: 600; }
.filter-bar input {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: inherit;
}

/* ---------- Forms ---------- */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  max-width: 520px;
}
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--pine);
  margin-bottom: 0.35rem;
}
.form-group input, .form-group textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.92rem;
}
.form-group input:focus, .form-group textarea:focus {
  outline: 2px solid var(--gold-soft);
  outline-offset: 1px;
  border-color: var(--gold);
}
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

/* ---------- Flash ---------- */
.flash-stack { margin-bottom: 1.25rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
}
.flash-success { background: #EAF1E4; color: var(--green); border: 1px solid #CFE0C3; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.section-title {
  font-family: 'Zilla Slab', serif;
  font-size: 1.05rem;
  color: var(--pine);
  margin: 0 0 0.8rem;
}

.header-actions { display: flex; gap: 0.6rem; align-items: center; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
.btn-icon { padding: 0.4rem 0.6rem; }

/* ---------- Admin / usuarios ---------- */
.tag-voce { color: var(--ink-muted); font-size: 0.78rem; font-weight: 400; }
.select-permissao {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-family: inherit;
  font-size: 0.85rem;
  background: #fff;
}
.status-badge {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
}
.status-on { background: #EAF1E4; color: var(--green); }
.status-off { background: #F7E9E5; color: var(--danger); }
.acoes-usuario, .acoes-venda { display: flex; gap: 0.5rem; align-items: center; }

/* ---------- Auth pages (login / troca de senha) ---------- */
.auth-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pine);
  background-image: radial-gradient(circle at 20% 20%, rgba(200,150,58,0.12), transparent 45%),
                     radial-gradient(circle at 80% 80%, rgba(76,107,63,0.25), transparent 50%);
  font-family: 'Work Sans', sans-serif;
  padding: 1rem;
}
.auth-wrap { width: 100%; max-width: 380px; }
.auth-card {
  background: #fff;
  border-radius: 14px;
  padding: 2.2rem 2rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
}
.auth-logo {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 16px;
  margin-bottom: 0.9rem;
}
.auth-card h1 {
  font-family: 'Zilla Slab', serif;
  color: var(--pine);
  margin: 0;
  font-size: 1.5rem;
}
.auth-subtitle { color: var(--ink-muted); font-size: 0.85rem; margin: 0.2rem 0 0.3rem; }
.auth-slogan { color: var(--gold); font-size: 0.78rem; font-style: italic; margin: 0 0 1.4rem; }
.auth-card form { text-align: left; }
.auth-btn { width: 100%; justify-content: center; margin-top: 0.3rem; }
.flash-danger { background: #F7E9E5; color: var(--danger); border: 1px solid #E4C3BA; }

/* ---------- Print header (relatorios gerais) ---------- */
.print-header { display: none; }
@media print {
  .no-print, .topbar, .bottomnav { display: none !important; }
  body { background: #fff; }
  .content { max-width: 100%; padding: 0; margin: 0; }
  .print-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding-bottom: 1rem;
    margin-bottom: 1.2rem;
    border-bottom: 2px solid var(--pine);
  }
  .print-header img { height: 56px; width: 56px; object-fit: cover; border-radius: 10px; }
  .print-header-title { font-family: 'Zilla Slab', serif; font-size: 1.3rem; color: var(--pine); }
  .print-header-sub { font-size: 0.78rem; color: var(--ink-muted); }
  .stat-card, .table-card, .silo, .chart-card { box-shadow: none; border: 1px solid #ccc; }
}

/* ---------- Recibo individual ---------- */
.recibo-body {
  margin: 0;
  background: #EFEDE0;
  font-family: 'Work Sans', sans-serif;
  min-height: 100vh;
}
.recibo-toolbar {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.2rem 1.5rem 0;
  display: flex;
  justify-content: space-between;
}
.recibo-page {
  max-width: 640px;
  margin: 1rem auto 3rem;
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 2rem 2.2rem;
}
.recibo-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.2rem;
  border-bottom: 2px solid var(--pine);
  margin-bottom: 1.4rem;
}
.recibo-logo { width: 60px; height: 60px; object-fit: cover; border-radius: 12px; }
.recibo-titulo { font-family: 'Zilla Slab', serif; font-size: 1.25rem; color: var(--pine); }
.recibo-codigo { color: var(--ink-muted); font-size: 0.85rem; }
.recibo-corpo { display: flex; flex-direction: column; gap: 0.9rem; }
.recibo-linha { display: flex; flex-direction: column; gap: 0.15rem; }
.recibo-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-muted); font-weight: 600; }
.recibo-valor { font-size: 1rem; color: var(--ink); }
.recibo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.recibo-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--pine);
  border-top: 1px dashed var(--line);
  padding-top: 1rem;
  margin-top: 0.4rem;
}
.recibo-assinaturas {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 3rem;
}
.assinatura-linha { border-top: 1px solid var(--ink); margin-bottom: 0.4rem; }
.assinatura-label { text-align: center; font-size: 0.82rem; color: var(--ink-muted); }
.recibo-rodape { text-align: center; font-size: 0.72rem; color: var(--ink-muted); margin-top: 2rem; }
@media print {
  .recibo-body { background: #fff; }
  .recibo-page { box-shadow: none; margin: 0; max-width: 100%; }
}

/* ---------- Telas pequenas de celular (largura reduzida) ---------- */
@media (max-width: 480px) {
  .content { padding: 1.1rem 1rem 5.5rem; }
  .page-header h1 { font-size: 1.4rem; }
  .stat-card .value { font-size: 1.35rem; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.7rem; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .field { width: 100%; }
  .filter-bar input { width: 100%; }
  .form-card { padding: 1.2rem; max-width: 100%; }
  .form-row { flex-direction: column; gap: 0; }
  .recibo-grid { grid-template-columns: 1fr; }
  .recibo-assinaturas { grid-template-columns: 1fr; gap: 2.5rem; }
  .recibo-page { padding: 1.4rem 1.2rem; margin: 0.5rem auto 2rem; }
  .auth-card { padding: 1.8rem 1.4rem; }
  .silo-legend { flex-direction: column; gap: 0.4rem; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; justify-content: center; }
}

/* bottomnav ja empurra conteudo pra cima; garante espaco no fim da pagina */
@media (max-width: 720px) {
  .content { padding-bottom: 5rem; }
}
