/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f172a;
  --surface:    #1e293b;
  --surface2:   #263145;
  --border:     #334155;
  --text:       #f1f5f9;
  --muted:      #94a3b8;
  --green:      #22c55e;
  --green-dim:  #166534;
  --red:        #ef4444;
  --red-dim:    #7f1d1d;
  --blue:       #3b82f6;
  --blue-dim:   #1e3a5f;
  --orange:     #f97316;
  --orange-dim: #7c2d12;
  --radius:     8px;
  --shadow:     0 4px 24px rgba(0,0,0,.4);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ── Auth pages ───────────────────────────────────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  text-align: center;
}

.auth-logo h1 { font-size: 1.3rem; font-weight: 700; }
.auth-subtitle { color: var(--muted); font-size: 0.85rem; }

/* ── Navbar ───────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.875rem;
  transition: background .15s, color .15s;
}
.nav-link:hover, .nav-link.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}
.nav-link-danger:hover { background: var(--red-dim); color: var(--red); }

/* Hamburger button — hidden on desktop */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background .15s;
}
.nav-toggle:hover { background: var(--surface2); }
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .25s, opacity .25s;
}

/* Animated → X when open */
.nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Mobile navbar ────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .navbar {
    flex-wrap: wrap;
    height: auto;
    padding: 0 16px;
  }

  .nav-brand {
    height: 56px;
    flex: 1;
  }

  .nav-toggle {
    display: flex;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    padding: 8px 0 12px;
    border-top: 1px solid var(--border);
    gap: 2px;
  }

  .nav-links.open {
    display: flex;
  }

  .nav-link {
    padding: 10px 12px;
    font-size: 0.9rem;
    border-radius: 6px;
  }
}

/* ── Container ────────────────────────────────────────────────────────────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

@media (max-width: 640px) {
  .container { padding: 16px; }
}

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.period-label {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--muted);
}

/* ── Summary cards ────────────────────────────────────────────────────────── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 640px) {
  .summary-cards {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-left: 4px solid transparent;
}

.card-green  { border-left-color: var(--green);  }
.card-red    { border-left-color: var(--red);    }
.card-blue   { border-left-color: var(--blue);   }
.card-orange { border-left-color: var(--orange); }
.card-neutral{ border-left-color: var(--muted);  }

.card-icon {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1;
  min-width: 32px;
  text-align: center;
}

.card-green  .card-icon { color: var(--green);  }
.card-red    .card-icon { color: var(--red);    }
.card-blue   .card-icon { color: var(--blue);   }
.card-orange .card-icon { color: var(--orange); }

.card-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.card-value { font-size: 1.25rem; font-weight: 700; }

/* ── Table section ────────────────────────────────────────────────────────── */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.section-header h2 { font-size: 1rem; font-weight: 600; }

.table-wrapper { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(51,65,85,.5);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--surface2); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tfoot td {
  padding: 10px 14px;
  border-top: 2px solid var(--border);
  background: var(--surface2);
}

.totals-row { font-size: 0.875rem; }

/* ── Type badges ──────────────────────────────────────────────────────────── */
.badge-tipo {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-creditar { background: var(--green-dim); color: var(--green); }
.badge-debitar  { background: var(--red-dim);   color: var(--red); }

.tag {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Action buttons ───────────────────────────────────────────────────────── */
.actions-cell { white-space: nowrap; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background .15s;
  text-decoration: none;
}
.btn-edit   { background: var(--blue-dim); color: var(--blue); }
.btn-delete { background: var(--red-dim);  color: var(--red); }
.btn-edit:hover   { background: var(--blue);  color: #fff; }
.btn-delete:hover { background: var(--red);   color: #fff; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 48px 24px;
  color: var(--muted);
}

/* ── Groups summary ───────────────────────────────────────────────────────── */
.grupos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1px;
  background: var(--border);
}

.grupo-card {
  background: var(--surface);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.grupo-nome { font-weight: 600; margin-bottom: 4px; }

.grupo-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.grupo-bar-row > span:first-child { width: 52px; flex-shrink: 0; }

.bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .4s ease;
}
.bar-green { background: var(--green); }
.bar-red   { background: var(--red); }
.bar-val   { min-width: 80px; text-align: right; font-size: 0.78rem; }

/* ── Form page ────────────────────────────────────────────────────────────── */
.form-page {
  max-width: 700px;
  margin: 0 auto;
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow);
}

.form-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.form-card-header h2 { font-size: 1.1rem; }

.section-title {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 0;
}

@media (max-width: 520px) { .form-row { grid-template-columns: 1fr; } }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.input-row { display: flex; gap: 8px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ── Inputs ───────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="email"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

input::placeholder, textarea::placeholder { color: var(--muted); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

textarea { resize: vertical; min-height: 60px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--blue);     color: #fff; }
.btn-primary:hover { background: #2563eb; }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-full { width: 100%; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: 11px 14px;
  border-radius: 6px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.alert-error   { background: var(--red-dim);   border-color: var(--red);   color: #fca5a5; }
.alert-success { background: var(--green-dim); border-color: var(--green); color: #86efac; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--muted); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.font-bold   { font-weight: 700; }
.required    { color: var(--red); }
.obs-cell    { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Installment progress ─────────────────────────────────────────────────── */
.parcela-cell { white-space: nowrap; }
.parcela-prog {
  display: inline-block;
  font-weight: 600;
  font-size: 0.85rem;
}
.parcela-rest {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.72rem;
  color: var(--muted);
}
.tag-ultima {
  display: inline-block;
  margin-left: 6px;
  background: var(--green-dim);
  color: var(--green);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 600;
}

/* ── Scrollbar (Webkit) ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
