:root {
  --primary: #5b3df0;
  --primary-dark: #4527d1;
  --primary-light: #8a6ef8;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --bg: #f4f5fa;
  --card-bg: #ffffff;
  --text: #1e1b2e;
  --text-muted: #7c7a8c;
  --border: #ececf3;
  --overlay-backdrop: rgba(20, 12, 50, 0.45);
  --radius: 16px;
  --shadow: 0 4px 16px rgba(30, 20, 70, 0.08);
}

html.dark {
  --primary: #7c5cf5;
  --primary-dark: #5b3df0;
  --primary-light: #9c85f8;
  --danger: #f87171;
  --danger-light: rgba(248, 113, 113, 0.16);
  --success: #4ade80;
  --success-light: rgba(74, 222, 128, 0.16);
  --bg: #121018;
  --card-bg: #1e1b2b;
  --text: #f1eefc;
  --text-muted: #9b96b3;
  --border: #322d47;
  --overlay-backdrop: rgba(0, 0, 0, 0.6);
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html {
  color-scheme: light;
}

html.dark {
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 90px;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 20px 16px 24px;
  border-radius: 0 0 24px 24px;
  box-shadow: var(--shadow);
}

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

.topbar-row h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.topbar-row h1 span {
  font-weight: 300;
  opacity: 0.85;
}

.btn-tema {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.total-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}

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

.total-value {
  font-size: 26px;
  font-weight: 700;
}

.search-row input {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  outline: none;
}

/* ---------- Lista de clientes ---------- */
.lista-clientes {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

.loading, .vazio {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 0;
  font-size: 14px;
}

.cliente-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.cliente-card:active {
  transform: scale(0.98);
}

.cliente-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary-light);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.cliente-info {
  flex: 1;
  min-width: 0;
}

.cliente-nome {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cliente-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.cliente-saldo {
  font-weight: 700;
  font-size: 15px;
  text-align: right;
  white-space: nowrap;
}

.saldo-devendo { color: var(--danger); }
.saldo-quitado { color: var(--success); }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(91, 61, 240, 0.45);
  cursor: pointer;
  z-index: 30;
}

/* ---------- Painel de detalhes ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 40;
  overflow-y: auto;
}

.painel {
  max-width: 560px;
  margin: 0 auto;
  padding-bottom: 100px;
}

.painel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 18px 14px;
  border-radius: 0 0 20px 20px;
}

.btn-voltar, .btn-excluir-cliente {
  background: rgba(255, 255, 255, 0.16);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.painel-titulo {
  flex: 1;
  min-width: 0;
}

.painel-titulo h2 {
  margin: 0;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.painel-sub {
  font-size: 12px;
  opacity: 0.85;
}

.saldo-box {
  margin: 18px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.saldo-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.saldo-valor {
  font-size: 32px;
  font-weight: 800;
}

.acoes-row {
  display: flex;
  gap: 12px;
  padding: 0 16px;
  margin-bottom: 20px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.acao-divida {
  flex: 1;
  background: var(--danger-light);
  color: var(--danger);
}

.acao-pagamento {
  flex: 1;
  background: var(--success-light);
  color: var(--success);
}

.historico-titulo {
  padding: 0 16px;
  margin: 10px 0;
  font-size: 15px;
  color: var(--text-muted);
}

.historico-lista {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.historico-item {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.historico-icone {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.historico-icone.divida { background: var(--danger-light); color: var(--danger); }
.historico-icone.pagamento { background: var(--success-light); color: var(--success); }

.historico-info {
  flex: 1;
  min-width: 0;
}

.historico-desc {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.historico-data {
  font-size: 11px;
  color: var(--text-muted);
}

.historico-valor {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.historico-valor.divida { color: var(--danger); }
.historico-valor.pagamento { color: var(--success); }

.btn-remover-item {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

/* ---------- Modais ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-backdrop);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--card-bg);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom, 0px));
  animation: subir 0.2s ease;
}

@keyframes subir {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

.modal label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0 6px;
}

.modal input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 15px;
  outline: none;
  background: var(--bg);
}

.modal input:focus {
  border-color: var(--primary);
}

.modal-botoes {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.btn-primario {
  flex: 1;
  background: var(--primary);
  color: #fff;
}

.btn-secundario {
  flex: 1;
  background: var(--border);
  color: var(--text);
}

/* ---------- Toast moderno ---------- */
.toast-container {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(92%, 380px);
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #211c38;
  color: #fff;
  border-radius: 14px;
  padding: 13px 14px 15px;
  box-shadow: 0 10px 30px rgba(20, 12, 50, 0.35);
  overflow: hidden;
  animation: toast-entra 0.25s cubic-bezier(.34,1.56,.64,1);
}

.toast-item.saindo {
  animation: toast-sai 0.2s ease forwards;
}

@keyframes toast-entra {
  from { transform: translateY(-16px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes toast-sai {
  from { transform: translateY(0) scale(1); opacity: 1; }
  to { transform: translateY(-10px) scale(0.97); opacity: 0; }
}

.toast-icone {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}

.toast-texto {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.35;
}

.toast-progresso {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.5);
  animation: toast-progresso linear forwards;
}

@keyframes toast-progresso {
  from { width: 100%; }
  to { width: 0%; }
}

.toast-item.sucesso { background: linear-gradient(135deg, #1b8a4a, #16a34a); }
.toast-item.sucesso .toast-icone { background: rgba(255, 255, 255, 0.22); color: #fff; }

.toast-item.erro { background: linear-gradient(135deg, #dc2626, #ef4444); }
.toast-item.erro .toast-icone { background: rgba(255, 255, 255, 0.22); color: #fff; }

.toast-item.info { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.toast-item.info .toast-icone { background: rgba(255, 255, 255, 0.22); color: #fff; }

/* ---------- Comprovante de pagamento ---------- */
.modal-comprovante {
  text-align: center;
}

.comprovante-check {
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--success-light);
  color: var(--success);
  font-size: 28px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: check-pop 0.3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes check-pop {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-comprovante h3 {
  text-align: center;
}

.comprovante-resumo {
  background: var(--bg);
  border-radius: 12px;
  padding: 4px 14px;
  margin-top: 6px;
}

.comprovante-linha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  gap: 10px;
}

.comprovante-linha:last-child { border-bottom: none; }

.comprovante-linha span { color: var(--text-muted); }
.comprovante-linha strong {
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Confirmação de ação ---------- */
.modal-confirmacao {
  text-align: center;
}

.confirm-icone {
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--danger-light);
  color: var(--danger);
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: check-pop 0.3s cubic-bezier(.34,1.56,.64,1);
}

.confirm-icone.info {
  background: rgba(91, 61, 240, 0.14);
  color: var(--primary);
}

.modal-confirmacao h3 {
  text-align: center;
  margin-bottom: 6px;
}

.confirm-mensagem {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}

.btn-perigo {
  flex: 1;
  background: var(--danger);
  color: #fff;
}

.btn-whatsapp {
  flex: 1.3;
  background: #25d366;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 20px; }
}
