:root {
  --sidebar-width: 240px;
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --bg: #f1f5f9;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: #334155;
  --sidebar-active: #1a56db;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', sans-serif; background: var(--bg); }

/* LOGIN */
.login-wrap {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #1a56db 100%);
}
.login-card {
  background: white; border-radius: 16px;
  padding: 2.5rem; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 2rem; color: var(--primary); }
.login-logo i { font-size: 3rem; display: block; margin-bottom: 0.5rem; }
.login-logo h4 { margin: 0; color: #1e293b; }

/* LAYOUT */
#sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-width); height: 100vh;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  z-index: 1000; transition: transform 0.3s;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 1.5rem 1.25rem; font-size: 1.1rem;
  font-weight: 700; color: white;
  border-bottom: 1px solid #334155;
  display: flex; align-items: center; gap: 0.75rem;
}
.sidebar-brand i { font-size: 1.4rem; color: #60a5fa; }
.sidebar-nav { list-style: none; padding: 1rem 0; margin: 0; flex: 1; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 1.25rem; color: var(--sidebar-text);
  text-decoration: none; transition: all 0.2s; font-size: 0.9rem;
}
.sidebar-nav li a:hover { background: var(--sidebar-hover); color: white; }
.sidebar-nav li a.active { background: var(--sidebar-active); color: white; border-radius: 0; }
.sidebar-nav li a i { font-size: 1.1rem; width: 20px; }
.sidebar-footer {
  padding: 1rem 1.25rem; border-top: 1px solid #334155;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.8rem; color: var(--sidebar-text);
}
.sidebar-footer a { color: #94a3b8; }
.sidebar-footer a:hover { color: white; }

#sidebarToggle {
  display: none; position: fixed; top: 1rem; left: 1rem;
  z-index: 1100; background: var(--sidebar-bg); color: white;
  border: none; border-radius: 8px; width: 40px; height: 40px;
  font-size: 1.2rem;
}

#mainContent {
  margin-left: var(--sidebar-width);
  min-height: 100vh; padding: 2rem;
}

/* PAGE HEADER */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem;
}
.page-header h2 { margin: 0; font-size: 1.5rem; font-weight: 700; color: #1e293b; }

/* CARDS */
.stat-card {
  background: white; border-radius: 12px;
  padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-left: 4px solid transparent;
}
.stat-card.income  { border-left-color: #10b981; }
.stat-card.expense { border-left-color: #ef4444; }
.stat-card.result  { border-left-color: #3b82f6; }
.stat-card.pending { border-left-color: #f59e0b; }
.stat-card .stat-label { font-size: 0.8rem; color: #64748b; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: #1e293b; margin: 0.25rem 0; }
.stat-card .stat-icon { font-size: 2rem; opacity: 0.15; float: right; margin-top: -2.5rem; }

/* TABLE */
.table-card { background: white; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); overflow: hidden; }
.table-card .table { margin: 0; }
.table-card .table th { background: #f8fafc; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; border-bottom: 1px solid #e2e8f0; font-weight: 600; }
.table-card .table td { vertical-align: middle; font-size: 0.9rem; }
.table-card .table-title { padding: 1rem 1.25rem; font-weight: 700; font-size: 1rem; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: space-between; }

/* BADGES */
.badge-empresa  { background: #dbeafe; color: #1d4ed8; }
.badge-personal { background: #dcfce7; color: #166534; }
.badge-habitaciones  { background: #fef3c7; color: #92400e; }
.badge-tradicional   { background: #ede9fe; color: #5b21b6; }
.badge-estudios      { background: #e0f2fe; color: #0369a1; }
.badge-apartamentos  { background: #fce7f3; color: #9d174d; }

.badge-paid    { background: #dcfce7; color: #166534; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-partial { background: #fed7aa; color: #9a3412; }
.table-partial > td { background-color: #fff7ed !important; }
/* Gastos provisionales (suministros estimados del año anterior) */
.exp-prov-input  { background: #fffbeb !important; border-color: #f59e0b !important; color: #92400e !important; }
.exp-prov-cell   { background: #fffdf7; }
.exp-prov-label  { font-size: .58rem; color: #d97706; text-align: center; line-height: 1; margin-top: 2px; }
.exp-prov-star   { font-size: .65rem; color: #d97706; margin-left: 2px; vertical-align: super; }
.exp-prov-total  { color: #d97706 !important; }

.badge-transfer { background: #dbeafe; color: #1d4ed8; }
.badge-cash   { background: #f0fdf4; color: #166534; }

.badge { font-weight: 500; padding: 0.3em 0.65em; border-radius: 6px; font-size: 0.78rem; }

/* MONTH SELECTOR */
.month-nav { display: flex; align-items: center; gap: 0.5rem; }
.month-nav select { border-radius: 8px; border: 1px solid #e2e8f0; padding: 0.4rem 0.75rem; font-size: 0.9rem; background: white; }

/* PAYMENT GRID */
.payment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.payment-item {
  background: white; border-radius: 10px; padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-left: 4px solid #e2e8f0;
  cursor: pointer; transition: all 0.2s;
}
.payment-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.payment-item.paid    { border-left-color: #10b981; }
.payment-item.pending { border-left-color: #f59e0b; }
.payment-item.partial { border-left-color: #d97706; background: #fffbeb; }
.payment-item .pi-property { font-size: 0.75rem; color: #64748b; }
.payment-item .pi-unit     { font-weight: 700; font-size: 0.95rem; color: #1e293b; }
.payment-item .pi-tenant   { font-size: 0.82rem; color: #475569; }
.payment-item .pi-amount   { font-size: 1.1rem; font-weight: 700; color: #1e293b; margin-top: 0.5rem; }
.payment-item .pi-method   { font-size: 0.75rem; }

/* FORM */
.form-label { font-size: 0.85rem; font-weight: 600; color: #374151; }

/* ALERTS */
.alert-pending { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 10px; padding: 1rem; }

/* PROPERTY CARDS */
.prop-card {
  background: white; border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden; transition: transform 0.2s;
}
.prop-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.prop-card-header { padding: 1rem; border-bottom: 1px solid #f1f5f9; }
.prop-card-body   { padding: 1rem; }
.prop-card-footer { padding: 0.75rem 1rem; background: #f8fafc; display: flex; gap: 0.5rem; border-top: 1px solid #f1f5f9; }

/* ── MOBILE (≤768px — iPhone, Android) ──────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar */
  #sidebarToggle { display: flex; align-items: center; justify-content: center; }
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }

  /* Layout */
  #mainContent { margin-left: 0; padding: 0.75rem; padding-top: 4rem; }

  /* Page header: título arriba, controles abajo */
  .page-header {
    flex-direction: column; align-items: flex-start; gap: 0.6rem;
    margin-bottom: 1rem;
  }
  .page-header h2 { font-size: 1.2rem; }
  .page-header .d-flex { flex-wrap: wrap; gap: 0.4rem; width: 100%; }
  .page-header .btn { font-size: 0.78rem; padding: 0.3rem 0.6rem; }

  /* Selector de mes más compacto */
  .month-nav select { font-size: 0.8rem; padding: 0.3rem 0.5rem; }

  /* Stat cards */
  .stat-card { padding: 1rem; }
  .stat-card .stat-value { font-size: 1.3rem; }
  .stat-card .stat-label { font-size: 0.72rem; }

  /* Tablas: scroll horizontal, celdas más compactas */
  .table-card { border-radius: 8px; }
  .table-card .table td,
  .table-card .table th { font-size: 0.78rem; padding: 0.4rem 0.5rem; }
  .table-responsive { -webkit-overflow-scrolling: touch; }

  /* Modales: pantalla completa en móvil */
  .modal-dialog { margin: 0.5rem; max-width: calc(100vw - 1rem); }
  .modal-dialog-scrollable .modal-content { max-height: calc(100vh - 1rem); }

  /* Ocultar columnas secundarias en tablas de ingresos */
  .inc-col-method { display: none; }

  /* Botones de acción en tablas: solo icono */
  .btn-sm .btn-label { display: none; }

  /* Timeline en historial: altura mínima */
  .timeline-bar { height: 18px !important; }

  /* Cards de inmuebles: ocupan todo el ancho */
  .prop-card { margin-bottom: 0.75rem; }

  /* Payment grid: 1 columna en móvil */
  .payment-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .payment-item { padding: 0.75rem; }
  .payment-item .pi-amount { font-size: 0.95rem; }

  /* Bottom navigation bar para acceso rápido */
  #mobileNav {
    display: flex !important;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--sidebar-bg); z-index: 1050;
    border-top: 1px solid #334155;
  }
  /* Ajuste para que el contenido no quede bajo el nav */
  #mainContent { padding-bottom: 5rem; }
}

/* ── TABLET (768–992px) ──────────────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 992px) {
  :root { --sidebar-width: 200px; }
  #mainContent { padding: 1.25rem; }
  .stat-card .stat-value { font-size: 1.5rem; }
}

/* Ocultar bottom nav en desktop */
#mobileNav { display: none; }

/* OVERLAY */
#sidebarOverlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 999;
}
#sidebarOverlay.show { display: block; }

/* REPORT */
.report-text { font-family: 'Courier New', monospace; font-size: 0.85rem; background: #1e293b; color: #e2e8f0; padding: 1.5rem; border-radius: 10px; white-space: pre-wrap; line-height: 1.6; }

/* RENTABILITY */
.rent-good   { color: #10b981; font-weight: 700; }
.rent-mid    { color: #f59e0b; font-weight: 700; }
.rent-bad    { color: #ef4444; font-weight: 700; }

.progress-sm { height: 6px; border-radius: 3px; }

/* ── VISTA INVERSIÓN / KPI CARDS ─────────────────────────────────────────── */
.ov-card {
  background: white; border-radius: 14px;
  padding: 1.25rem; height: 100%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: box-shadow 0.2s;
}
.ov-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.ov-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; margin-bottom: 0.75rem;
}
.ov-num {
  font-size: 2rem; font-weight: 800;
  color: #1e293b; line-height: 1.1; margin-bottom: 0.2rem;
}
.ov-denom { font-size: 1rem; font-weight: 500; color: #94a3b8; }
.ov-label {
  font-size: 0.72rem; font-weight: 600; color: #64748b;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.ov-sub { font-size: 0.75rem; color: #94a3b8; margin-top: 0.2rem; }

/* Celdas de resumen financiero */
.ov-fin-cell {
  padding: 0.5rem 0.3rem;
}
.ov-fin-label {
  font-size: 0.65rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  margin-bottom: 0.3rem;
}
.ov-fin-label i { margin-right: 3px; }
.ov-fin-value {
  font-size: 1.15rem; font-weight: 700;
  line-height: 1.2;
}

@media (max-width: 768px) {
  .ov-card { padding: 0.9rem; }
  .ov-num { font-size: 1.55rem; }
  .ov-icon { width: 36px; height: 36px; font-size: 1rem; margin-bottom: 0.5rem; }
  .ov-label { font-size: 0.65rem; }
  .ov-fin-value { font-size: 0.95rem; }
  .ov-fin-label { font-size: 0.58rem; }
  .ov-fin-label i { display: none; }
}

@media (max-width: 380px) {
  .ov-num { font-size: 1.35rem; }
  .ov-denom { font-size: 0.85rem; }
  .ov-fin-value { font-size: 0.85rem; }
}

/* PRINT / PDF ─────────────────────────────────────────────────────────────── */
@media print {
  #sidebar, #sidebarToggle, #mobileNav, #sidebarOverlay,
  .no-print, .nav-tabs, .page-header .d-flex { display: none !important; }
  #appPage { display: block !important; }
  #mainContent { margin-left: 0 !important; padding: 0 !important; }
  #pageContent { padding: 0 !important; }
  .table-card { box-shadow: none !important; border: 1px solid #dee2e6; break-inside: avoid; }
  .stat-card   { box-shadow: none !important; border: 1px solid #dee2e6; }
  body { background: white !important; }
  .page-header h2 { font-size: 1.1rem; margin-bottom: .5rem; }
  @page { margin: 1.5cm; }
}
