:root {
  --verde: #33422a;
  --verde-escuro: #232f1c;
  --laranja: #d9662e;
  --bg: #f2f1ec;
  --card: #ffffff;
  --texto: #24261f;
  --borda: #ddd8cb;
  --muted: #74786c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--texto);
}

/* ---------- Tela de login (nuvem) ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--verde-escuro);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 30px 26px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 12px 44px rgba(0,0,0,0.35);
}

.login-logo { height: 56px; margin-bottom: 14px; }
.login-card h2 { margin: 0 0 4px; color: var(--verde-escuro); font-size: 21px; }
.login-sub { font-size: 13px; color: var(--muted); margin: 0 0 20px; }

.login-card input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px 13px;
  font-size: 16px;
  border: 1px solid var(--borda);
  border-radius: 8px;
}
.login-card input:focus { outline: none; border-color: var(--laranja); }

.login-erro { color: #b23b2e; font-size: 13px; margin-top: 10px; min-height: 18px; }

.sync-status {
  position: absolute;
  top: 12px;
  left: 14px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  z-index: 5;
  color: #fff;
  background: rgba(255,255,255,0.14);
}
.sync-status.ok { background: rgba(61,122,58,0.9); }
.sync-status.saving { background: rgba(217,102,46,0.9); }
.sync-status.erro { background: rgba(178,59,46,0.95); }
.sync-status.offline { background: rgba(120,120,120,0.85); }

.logout-wrap {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--borda);
  display: flex;
  justify-content: center;
}
.btn-logout-full {
  background: var(--verde-escuro);
  color: #fff;
  min-width: 220px;
  max-width: 100%;
  padding: 13px 22px;
  font-size: 15px;
}

/* ---------- Barra superior ---------- */
.topbar {
  background: var(--verde-escuro);
  padding: 10px 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-logo {
  height: 54px;
}

.tabs {
  display: flex;
  gap: 4px;
  width: 100%;
  max-width: 860px;
}

.tab {
  flex: 1;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #c7cabf;
  font-size: 15px;
  font-weight: 600;
  padding: 11px 8px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
}

.tab.active {
  background: var(--bg);
  color: var(--verde-escuro);
}

/* ---------- Painéis ---------- */
.main {
  display: flex;
  justify-content: center;
  padding: 20px 16px 40px;
}

.tab-panel { display: none; width: 100%; max-width: 860px; }
.tab-panel.active { display: block; }

.panel {
  background: var(--card);
  border: 1px solid var(--borda);
  border-radius: 12px;
  padding: 26px 28px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.panel h1 {
  margin: 0;
  font-size: 21px;
  color: var(--verde-escuro);
}

.panel h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--laranja);
  border-bottom: 2px solid var(--borda);
  padding-bottom: 6px;
  margin: 26px 0 14px 0;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  cursor: pointer;
}

.check-field input[type="checkbox"] {
  width: 19px;
  height: 19px;
  accent-color: var(--laranja);
  flex-shrink: 0;
}

.check-field input[type="checkbox"]:disabled + * ,
.check-field:has(input:disabled) {
  color: var(--muted);
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--texto);
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--borda);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--texto);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--laranja);
}

textarea { resize: vertical; }

/* ---------- Listas de salvos ---------- */
.saved-box {
  border: 1px solid var(--borda);
  border-radius: 8px;
  margin-bottom: 18px;
  background: #faf9f5;
}

.saved-box summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  color: var(--verde);
}

.saved-list {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  background: #fff;
  border: 1px solid var(--borda);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}

.history-item:hover { border-color: var(--laranja); }

.history-item .h-num {
  font-weight: 700;
  color: var(--laranja);
  font-size: 13px;
}

.history-item .h-vinculo {
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
}

.history-item .h-cliente { font-size: 13px; margin-top: 2px; }

.history-item .h-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
}

.history-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 2px;
}

/* ---------- Cards de clientes ---------- */
.cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.cliente-card {
  border: 1px solid var(--borda);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: #faf9f5;
}

.cliente-card .c-nome { font-weight: 700; font-size: 14px; }
.cliente-card .c-info { font-size: 12px; color: var(--muted); margin-top: 2px; }

.cliente-card .c-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-mini {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-mini.editar { background: var(--verde); color: #fff; }
.btn-mini.excluir { background: #b23b2e; color: #fff; }

/* ---------- Financeiro ---------- */
.subnav {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--borda);
  flex-wrap: wrap;
}

.subtab {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.subtab.active {
  color: var(--laranja);
  border-bottom-color: var(--laranja);
}

/* sub-abas internas (Receitas / Despesas) */
.subnav-inner { margin-bottom: 12px; }
.subtab-lanc {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.subtab-lanc.active { color: var(--verde-escuro); border-bottom-color: var(--verde-escuro); }

/* Gráfico de barras por mês */
.chart-wrap {
  width: 100%;
  overflow: hidden;
  margin-bottom: 6px;
}

.chart-wrap svg { width: 100%; height: auto; display: block; }

.chart-bar-receita { fill: #3d7a3a; }
.chart-bar-despesa { fill: #b23b2e; }
.chart-axis { stroke: var(--borda); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 9px; }
.chart-val { fill: var(--texto); font-size: 8px; font-weight: 600; }

.chart-legend {
  display: flex;
  gap: 18px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 3px;
}

.dot-verde { background: #3d7a3a; }
.dot-vermelho { background: #b23b2e; }

/* Barras horizontais por categoria */
.cat-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.cat-row .cat-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 3px;
}

.cat-row .cat-top .cat-val { font-weight: 700; color: var(--verde-escuro); }

.cat-track {
  background: #ece9df;
  border-radius: 6px;
  height: 12px;
  overflow: hidden;
}

.cat-fill {
  background: var(--laranja);
  height: 100%;
  border-radius: 6px;
}

/* Alertas do painel */
.fin-alertas { margin-bottom: 6px; display: flex; flex-direction: column; gap: 8px; }

.fin-alerta {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  border-left: 5px solid;
}

.fin-alerta.aviso { background: #fbe4c9; border-left-color: var(--laranja); color: #7a3f10; }
.fin-alerta.ok { background: #d9efd7; border-left-color: #3d7a3a; color: #2c5a2a; }

.fin-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.fin-card {
  border-radius: 10px;
  padding: 12px 14px;
  color: #fff;
}

.fin-verde { background: #3d7a3a; }
.fin-laranja { background: var(--laranja); }
.fin-vermelho { background: #b23b2e; }
.fin-escuro { background: var(--verde-escuro); }

.fin-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.fin-valor {
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
}

.fin-item {
  border: 1px solid var(--borda);
  border-left: 5px solid var(--muted);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: #faf9f5;
}

.fin-item.receita { border-left-color: #3d7a3a; }
.fin-item.despesa { border-left-color: #b23b2e; }

.fin-item .f-desc { font-weight: 600; font-size: 14px; }
.fin-item .f-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.fin-item .f-valor {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.fin-item.receita .f-valor { color: #3d7a3a; }
.fin-item.despesa .f-valor { color: #b23b2e; }

.fin-item .f-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.fin-item .f-actions { display: flex; gap: 6px; }

.chip-status {
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.chip-status.pago { background: #d9efd7; color: #2c5a2a; }
.chip-status.pendente { background: #fbe4c9; color: #8a4a12; }

/* ---------- Tabelas de itens ---------- */
.itens-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

.itens-table th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 2px solid var(--borda);
}

.itens-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--borda);
  vertical-align: middle;
}

.itens-table .col-num { text-align: right; width: 120px; }
.itens-table .col-actions { width: 36px; text-align: center; }

.itens-table input {
  padding: 6px 8px;
  font-size: 13px;
}
.itens-table td.col-num input { text-align: right; }

.total-label {
  text-align: right;
  font-weight: 700;
  padding: 10px 8px;
}

.total-value {
  font-weight: 700;
  color: var(--verde-escuro);
  font-size: 15px;
}

.remove-item {
  background: none;
  border: none;
  color: #b23b2e;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

/* ---------- Botões ---------- */
.btn {
  border: none;
  border-radius: 7px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }

.btn-primary { background: var(--laranja); color: #fff; }
.btn-secondary { background: var(--verde); color: #fff; }
.btn-share { background: var(--verde-escuro); color: #fff; }
.btn-whatsapp { background: #25d366; color: #fff; }
.btn-email { background: #3b6ea5; color: #fff; }

.actions {
  margin-top: 22px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  border-top: 1px solid var(--borda);
  padding-top: 18px;
}

.actions-share {
  border-top: none;
  padding-top: 0;
  margin-top: 12px;
}

/* ---------- Celular ---------- */
@media (max-width: 800px) {
  .topbar-logo { height: 44px; }
  .grid2 { grid-template-columns: 1fr; }
  .main { padding: 12px 10px 30px; }
  .panel { padding: 16px 14px; }

  .itens-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .itens-table input { min-width: 110px; }
  .itens-table .col-num input { min-width: 80px; }

  input[type="text"],
  input[type="tel"],
  input[type="email"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px;
    padding: 11px 12px;
  }

  .btn { padding: 13px 18px; font-size: 15px; }

  .actions .btn,
  .actions-share .btn { flex: 1 1 100%; }

  .cliente-card { flex-direction: column; align-items: stretch; }
  .cliente-card .c-actions { justify-content: flex-end; }

  .fin-cards { grid-template-columns: repeat(2, 1fr); }
  .fin-item { flex-direction: column; align-items: stretch; }
  .fin-item .f-right { flex-direction: row; justify-content: space-between; align-items: center; }

  .tab { font-size: 13px; padding: 10px 4px; }
}
