@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --green: #2E4632;
  --green-light: #3F6C4C;
  --green-hover: #345a3f;
  --cream: #F2ECDE;
  --card: rgba(255,255,255,0.6);
  --line: #d8cdae;
  --line-light: #e5dcc2;
  --red: #a8402f;
  --ink: #2A2416;
  --muted: #5c5335;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: var(--cream);
  color: var(--ink);
}
h1, h2, h3, .font-display { font-family: 'Fraunces', serif; }
.hidden { display: none !important; }
.print-only { display: none; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
}
.login-card {
  background: var(--cream);
  padding: 2.5rem 2rem;
  border-radius: 14px;
  width: 320px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.login-card p { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}
.login-card button {
  width: 100%;
  padding: 0.7rem;
  background: var(--green-light);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { background: var(--green-hover); }
.error-text { color: var(--red); font-size: 0.85rem; min-height: 1.2em; margin-top: 0.5rem; }

/* ---------- App shell ---------- */
.app-header { background: var(--green); color: var(--cream); }
.header-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-icon { font-size: 1.4rem; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 6px; background: white; }
.brand h1 { font-size: 1.3rem; margin: 0; }
.link-btn {
  background: none; border: none; color: var(--cream); opacity: 0.75;
  cursor: pointer; font-size: 0.85rem; text-decoration: underline;
}
.link-btn:hover { opacity: 1; }

.tabs {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem 0;
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
}
.tab-btn {
  background: none; border: none; color: rgba(242,236,222,0.7);
  padding: 0.6rem 1rem; border-radius: 8px 8px 0 0; cursor: pointer;
  font-family: 'Inter', sans-serif; font-size: 0.9rem; white-space: nowrap;
}
.tab-btn.active { background: var(--cream); color: var(--green); font-weight: 600; }

.content { max-width: 1000px; margin: 0 auto; padding: 1.5rem; }
.view { display: none; }
.view.active { display: block; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
.card p.hint { font-size: 0.85rem; color: var(--muted); margin: -0.4rem 0 0.75rem; }

.field-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.field-row input, .field-row select, .field-row textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.75rem;
  font-size: 0.9rem; background: white; font-family: inherit;
}
.field-row input[type=text], .field-row input[type=number], .field-row input:not([type]) { flex: 1; min-width: 140px; }

.btn {
  background: var(--green-light); color: white; border: none; border-radius: 8px;
  padding: 0.55rem 1rem; cursor: pointer; font-size: 0.9rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn:hover { background: var(--green-hover); }
.btn.secondary { background: transparent; color: var(--green-light); border: 1px solid var(--green-light); }
.btn.danger-link { background: none; border: none; color: var(--red); opacity: 0.6; cursor: pointer; padding: 0.2rem; }
.btn.danger-link:hover { opacity: 1; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); color: var(--muted); font-weight: 500; }
tbody td { padding: 0.5rem 0.9rem; border-bottom: 1px solid var(--line-light); }
tbody tr:last-child td { border-bottom: none; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }

.empty-state {
  border: 1px dashed #c9bd97; border-radius: 12px; padding: 3rem 1.5rem;
  text-align: center; color: var(--muted); font-size: 0.9rem;
}

/* ---------- Mensalidades matrix ---------- */
.matrix-wrap { overflow-x: auto; }
.matrix th, .matrix td { text-align: center; white-space: nowrap; }
.matrix td:first-child, .matrix th:first-child { text-align: left; position: sticky; left: 0; background: var(--cream); }
.stamp {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--green-light);
  color: var(--green-light); transform: rotate(-8deg); line-height: 1;
}
.stamp .val { font-size: 9px; margin-top: 2px; }
.x-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; background: rgba(168,64,47,0.1); color: var(--red);
  font-weight: bold;
}
.count-badge { font-size: 10px; opacity: 0.5; margin-top: 2px; }

/* ---------- Reports ---------- */
.report-summary { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat-box { flex: 1; min-width: 140px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.stat-box .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-box .value { font-family: 'Fraunces', serif; font-size: 1.5rem; margin-top: 0.2rem; }
.stat-box.receita .value { color: var(--green-light); }
.stat-box.despesa .value { color: var(--red); }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.ok { background: rgba(63,108,76,0.15); color: var(--green-light); }
.badge.pending { background: rgba(168,64,47,0.12); color: var(--red); }

/* ---------- Recibos / configurações / livro caixa ---------- */
.receipt-form > input[type="text"] { min-width: 220px; }
.form-message { min-height: 1.2em; margin: 0.7rem 0 0; font-size: 0.85rem; }
.form-message.success { color: var(--green-light); font-weight: 600; }
.actions-cell { display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.money { font-weight: 600; white-space: nowrap; }
.settings-card { max-width: 760px; }
.settings-card > label, .settings-card .field-row > label {
  display: flex; flex: 1; flex-direction: column; gap: 0.3rem;
  color: var(--muted); font-size: 0.8rem; margin-bottom: 0.85rem;
}
.settings-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 0.6rem 0.75rem; background: white; font: inherit; color: var(--ink);
}
.document-heading { margin-bottom: 1rem; display: flex; align-items: center; gap: 1rem; }
.document-heading h2 { margin: 0 0 0.25rem; }
.document-heading p { margin: 0; color: var(--muted); }
.document-logo { width: 76px; height: 76px; object-fit: contain; flex: 0 0 auto; }
.logo-setting { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line-light); }
.logo-preview { width: 112px; height: 112px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px; background: white; overflow: hidden; flex: 0 0 auto; }
.logo-preview.empty { color: var(--muted); font-size: 0.75rem; border-style: dashed; }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.file-label { display: flex; flex-direction: column; gap: 0.35rem; color: var(--muted); font-size: 0.8rem; }
.file-label input { max-width: 100%; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000; padding: 1rem;
  display: flex; align-items: center; justify-content: center;
  background: rgba(25, 31, 25, 0.66);
}
.modal-card {
  width: min(620px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--cream); border-radius: 14px; padding: 1.25rem;
  box-shadow: 0 18px 55px rgba(0,0,0,0.35);
}
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 1px solid var(--line); padding-bottom: 0.85rem; }
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-header p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.8rem; }
.modal-close { border: 0; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
.attachment-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0 0.5rem; }
.attachment-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 0; border-bottom: 1px solid var(--line-light); }
.attachment-item > div { flex: 1; min-width: 0; }
.attachment-item a { color: var(--green-light); font-weight: 600; overflow-wrap: anywhere; }
.attachment-item small { display: block; color: var(--muted); margin-top: 0.2rem; }
.attachment-icon { font-size: 1.35rem; }
.attachment-empty, .attachment-loading { padding: 1.5rem; text-align: center; color: var(--muted); }
.cashbook .income { color: var(--green-light); white-space: nowrap; }
.cashbook .expense { color: var(--red); white-space: nowrap; }
.signature-row { display: flex; gap: 5rem; justify-content: center; margin: 5rem 0 2rem; }
.signature-row > div { min-width: 240px; border-top: 1px solid var(--ink); text-align: center; padding-top: 0.4rem; }
.signature-row small { display: block; color: var(--muted); margin-top: 0.2rem; }

@media print {
  .app-header, .btn, .field-row, #view-relatorios .no-print { display: none !important; }
  body { background: white; }
  .content { max-width: none; padding: 0; }
  .table-wrap, .card, .stat-box { background: white; }
  .print-only { display: inline; }
}

@media (max-width: 640px) {
  .header-inner, .tabs, .content { padding-left: 1rem; padding-right: 1rem; }
  .signature-row { gap: 3rem; flex-direction: column; align-items: center; }
  .logo-setting { align-items: flex-start; }
}
