:root {
  --gold: #b8933f;
  --gold-dark: #8f6f2e;
  --radius: 10px;
}

[data-theme="light"] {
  --bg: #f7f5f0;
  --bg-card: #ffffff;
  --bg-elevated: #fbfaf7;
  --text: #262320;
  --text-muted: #6f6a63;
  --border: #e4e0d6;
  --success: #2f7d4f;
  --danger: #b3402f;
  --input-bg: #ffffff;
}

[data-theme="dark"] {
  --bg: #17161a;
  --bg-card: #201f24;
  --bg-elevated: #26252b;
  --text: #f1efe9;
  --text-muted: #a6a29a;
  --border: #34323a;
  --success: #4caf7d;
  --danger: #e0685a;
  --input-bg: #26252b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s ease, color .2s ease;
}

a { color: var(--gold-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  flex-shrink: 0;
}

.sidebar .brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gold-dark);
  margin-bottom: 24px;
  padding: 0 8px;
  line-height: 1.3;
}

.sidebar nav a {
  display: block;
  padding: 10px 10px;
  border-radius: var(--radius);
  color: var(--text);
  margin-bottom: 2px;
  font-size: .93rem;
}
.sidebar nav a:hover { background: var(--bg-elevated); text-decoration: none; }
.sidebar nav a.active { background: var(--gold); color: #fff; }

.main { flex: 1; padding: 24px 32px; max-width: 1100px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: .85rem;
}

h1, h2, h3 { font-weight: 650; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    padding: 12px 10px;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .sidebar .brand { margin-bottom: 10px; padding: 0 4px; }
  .sidebar nav {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a {
    white-space: nowrap;
    flex-shrink: 0;
    margin-bottom: 0;
    font-size: .85rem;
    padding: 8px 12px;
  }
  .main { padding: 16px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  /* inputs em 16px evitam o zoom automático do Safari/iOS ao focar */
  input, select, textarea { font-size: 16px; }
  table { font-size: .82rem; }
  th, td { padding: 8px 6px; }
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.foto-mini {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}

.stat { }
.stat .label { color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.5rem; font-weight: 700; margin-top: 4px; }
.stat .value.gold { color: var(--gold-dark); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: var(--bg-elevated); }

tr.total-row td {
  background: var(--bg-elevated);
  border-top: 2px solid var(--gold);
  font-size: 1rem;
  padding-top: 12px;
  padding-bottom: 12px;
}

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--gold);
  background: var(--gold);
  color: #fff;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
}
.btn:hover { background: var(--gold-dark); text-decoration: none; }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg-elevated); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: .8rem; }

form .field { margin-bottom: 14px; }
label { display: block; font-size: .82rem; margin-bottom: 5px; color: var(--text-muted); }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: .92rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge.green { background: rgba(47,125,79,.15); color: var(--success); }
.badge.red { background: rgba(179,64,47,.15); color: var(--danger); }
.badge.gold { background: rgba(184,147,63,.18); color: var(--gold-dark); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .9rem; }
.flash.sucesso { background: rgba(47,125,79,.15); color: var(--success); }
.flash.erro { background: rgba(179,64,47,.15); color: var(--danger); }

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.actions { display: flex; gap: 8px; }
.progress {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 20px;
  overflow: hidden;
  margin-top: 8px;
}
.progress > div { height: 100%; background: var(--gold); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card { width: 320px; }

/* ---- Modal de cobrança via WhatsApp ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.aberto { display: flex; }
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 24px;
  border: 1px solid var(--border);
}
.modal-box h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.modal-subtitle { color: var(--text-muted); font-size: .88rem; margin: 0 0 16px; }
.tipo-cobranca-opcao {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: .92rem;
}
.tipo-cobranca-opcao.selecionada { border-color: var(--gold); background: rgba(184,147,63,.08); }
.tipo-cobranca-opcao.desabilitada { opacity: .45; cursor: not-allowed; }
.tipo-cobranca-opcao input { width: auto; margin: 0; }
