:root {
  --bl-red: #a12b1f;
  --bl-red-dark: #7c2016;
  --bl-black: #1a1a1a;
  --bl-gold: #c99a2e;
  --bl-gold-light: #e7c04d;
  --bl-bg: #f2e8d0;
  --bl-card: #ffffff;
  --bl-text: #23262b;
  --bl-muted: #6c7280;
  --bl-border: #e3e5e9;
  --bl-green: #1e8449;
  --bl-red-soft: #c0392b;
}

* { box-sizing: border-box; }

body {
  background: var(--bl-bg);
  color: var(--bl-text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, var(--bl-red) 0%, var(--bl-black) 65%);
  padding: 1rem;
}

.login-card {
  background: var(--bl-card);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  text-align: center;
}

.login-card img { width: 76px; height: 76px; margin-bottom: .75rem; }

.login-card h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--bl-red-dark);
  margin-bottom: .1rem;
}

.login-card p.subtitle {
  color: var(--bl-muted);
  font-size: .85rem;
  margin-bottom: 1.5rem;
}

.demo-creds {
  font-size: .75rem;
  color: var(--bl-muted);
  background: #f8f4e9;
  border: 1px dashed var(--bl-gold);
  border-radius: 8px;
  padding: .6rem .75rem;
  margin-top: 1rem;
  text-align: left;
}

/* ---------- App shell ---------- */
.app-header {
  background: linear-gradient(120deg, var(--bl-red) 0%, var(--bl-red-dark) 100%);
  color: #fff;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 2px 10px rgba(0,0,0,.2);
}

.app-header img.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  padding: 3px;
}

.app-header .brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.1;
}

.app-header .brand-sub {
  font-size: .7rem;
  opacity: .85;
  letter-spacing: .03em;
}

.app-header .header-actions { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

.badge-role {
  background: var(--bl-gold);
  color: #2a1d00;
  font-weight: 600;
}

.app-body { display: flex; min-height: calc(100vh - 62px); }

.sidebar {
  width: 230px;
  background: var(--bl-black);
  color: #eee;
  flex-shrink: 0;
  padding-top: .75rem;
  transition: transform .2s ease;
}

.sidebar .nav-link {
  color: #cfd2d8;
  padding: .65rem 1.1rem;
  border-left: 3px solid transparent;
  font-size: .92rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
}

.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }

.sidebar .nav-link.active {
  background: rgba(161,43,31,.25);
  border-left-color: var(--bl-gold);
  color: #fff;
  font-weight: 600;
}

.sidebar .nav-divider {
  border-top: 1px solid rgba(255,255,255,.1);
  margin: .5rem 1rem;
}

.main-content { flex: 1; padding: 1.25rem 1.5rem 3rem; max-width: 100%; overflow-x: hidden; }

.view-section { display: none; }
.view-section.active { display: block; }

.page-title {
  font-weight: 700;
  color: var(--bl-red-dark);
  margin-bottom: .1rem;
}

.page-subtitle { color: var(--bl-muted); font-size: .88rem; margin-bottom: 1.25rem; }

/* ---------- KPI cards ---------- */
.kpi-card {
  background: var(--bl-card);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--bl-border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  height: 100%;
}

.kpi-card .kpi-label { font-size: .78rem; color: var(--bl-muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi-card .kpi-value { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; }
.kpi-card .kpi-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #fff; margin-bottom: .5rem;
}
.kpi-icon.ingresos { background: var(--bl-green); }
.kpi-icon.egresos { background: var(--bl-red-soft); }
.kpi-icon.donaciones { background: var(--bl-gold); color: #2a1d00; }
.kpi-icon.saldo { background: var(--bl-black); }
.kpi-icon.movs { background: #34495e; }

.chart-card {
  background: var(--bl-card);
  border-radius: 12px;
  border: 1px solid var(--bl-border);
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.chart-card h6 { font-weight: 700; color: var(--bl-red-dark); margin-bottom: .75rem; }
.chart-wrap { position: relative; height: 260px; }

/* ---------- Cards / tables ---------- */
.section-card {
  background: var(--bl-card);
  border-radius: 12px;
  border: 1px solid var(--bl-border);
  padding: 1.1rem 1.2rem 1.4rem;
  margin-bottom: 1.25rem;
}

.table-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .85rem; }
.table-toolbar .form-control, .table-toolbar .form-select { max-width: 210px; }

table.bl-table thead th {
  background: #faf7f0;
  color: var(--bl-red-dark);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .02em;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid var(--bl-gold);
}

table.bl-table thead th .sort-arrow { font-size: .7rem; opacity: .5; margin-left: 3px; }
table.bl-table tbody td { vertical-align: middle; font-size: .88rem; }
table.bl-table tbody tr:hover { background: #fbf6ea; }

.amount-pos { color: var(--bl-green); font-weight: 600; }
.amount-neg { color: var(--bl-red-soft); font-weight: 600; }

.type-badge { font-size: .72rem; padding: .3em .6em; border-radius: 20px; font-weight: 600; }
.type-badge.ingreso { background: #d9f2e3; color: var(--bl-green); }
.type-badge.egreso { background: #fbe1de; color: var(--bl-red-soft); }
.type-badge.donacion { background: #fbecc4; color: #8a6a05; }

.btn-brand {
  background: var(--bl-red);
  border-color: var(--bl-red);
  color: #fff;
}
.btn-brand:hover { background: var(--bl-red-dark); border-color: var(--bl-red-dark); color: #fff; }

.btn-gold {
  background: var(--bl-gold);
  border-color: var(--bl-gold);
  color: #2a1d00;
  font-weight: 600;
}
.btn-gold:hover { background: var(--bl-gold-light); border-color: var(--bl-gold-light); color: #2a1d00; }

.form-required::after { content: " *"; color: var(--bl-red-soft); }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--bl-muted); }
.empty-state i { font-size: 2.2rem; color: var(--bl-border); display: block; margin-bottom: .5rem; }

.audit-item { border-left: 3px solid var(--bl-gold); padding: .4rem .8rem; margin-bottom: .5rem; font-size: .84rem; background: #fafafa; border-radius: 0 6px 6px 0; }
.audit-item .audit-meta { color: var(--bl-muted); font-size: .74rem; }

.toast-container { z-index: 2000; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1025;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0; top: 62px; bottom: 0;
    transform: translateX(-100%);
    z-index: 1029;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .main-content { padding: 1rem .85rem 3rem; }
}

.report-total-row td { font-weight: 700; background: #faf7f0; }

.backup-banner {
  background: #fff8e1;
  border: 1px solid var(--bl-gold);
  border-radius: 10px;
  padding: .6rem 1rem;
  font-size: .82rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  color: #6b5300;
}

@media print {
  .app-header, .sidebar, .table-toolbar, .no-print { display: none !important; }
  .main-content { padding: 0; }
}
