/* =====================================================
   STYLES.CSS — Finanzas Personales
   Primero el diseño de computadora, al final los
   ajustes para celular (@media).
   ===================================================== */


/* ===============================
   COLORES Y MEDIDAS
   =============================== */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --border: #e5e7eb;
  --text: #222222;
  --text-muted: #6b7280;

  --header-bg: #1f2933;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;

  --green: #2ecc71;
  --green-hover: #27ae60;
  --red: #e74c3c;
  --red-hover: #c0392b;
  --yellow: #f1c40f;
  --yellow-hover: #d4ac0d;
  --gray: #6b7280;
  --gray-hover: #4b5563;

  --radius: 8px;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}


/* ===============================
   GENERAL
   =============================== */
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
}

.hidden {
  display: none !important;
}


/* ===============================
   HEADER
   =============================== */
.app-header {
  background: var(--header-bg);
  color: #fff;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
}

.logout-btn {
  background: var(--red);
  color: #fff;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

.logout-btn:hover {
  background: var(--red-hover);
}

.month-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.month-selector .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.month-selector label {
  font-size: 0.85rem;
  color: #d1d5db;
}

.month-selector input {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-size: 1rem;
}

.month-selector button {
  padding: 9px 16px;
  border-radius: 6px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.month-selector button:hover {
  background: var(--primary-hover);
}


/* ===============================
   CONTENIDO
   =============================== */
.app-main {
  padding: 16px 24px;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}


/* ===============================
   TARJETAS DEL RESUMEN GENERAL
   =============================== */
.summary-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  padding: 12px 0;
  border-bottom: 2px solid var(--border);
}

.summary-header h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 4px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.card p {
  margin: 0;
  font-weight: 700;
  font-size: 1.3rem;
}

.card-balance {
  border-left: 4px solid var(--primary);
}

.card-savings {
  border-left: 4px solid var(--green);
}

/* Mini tarjetas Total / Pagado / Pendiente */
.subcards {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.subcard strong {
  font-weight: 600;
  color: var(--text);
}


/* ===============================
   TABS
   =============================== */
.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}

.tab-btn {
  padding: 10px 18px;
  border: none;
  background: #dddddd;
  cursor: pointer;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
}

.tab-btn:hover {
  background: #cfcfcf;
}

.tab-btn.active {
  background: #4a90e2;
  color: #fff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}


/* ===============================
   GRÁFICOS (pestaña Dashboard)
   =============================== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.chart-box {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.chart-head h3 {
  margin: 0;
  font-size: 1rem;
}

.chart-sub {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Botones Barras / Dona / Línea ... */
.chart-switch {
  display: inline-flex;
  flex-shrink: 0;
  background: #f3f4f6;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.chart-switch button {
  border: none;
  background: transparent;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.chart-switch button:hover {
  color: var(--text);
}

.chart-switch button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.chart-canvas {
  position: relative;
  height: 280px;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
}

.chart-note {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.chart-note strong {
  color: var(--text);
}

.note-bad,
.chart-note strong.note-bad {
  color: #c0392b;
  font-weight: 600;
}

/* Saldo / ahorro negativo en las tarjetas */
.card p.negative {
  color: #c0392b;
}


/* ===============================
   ENCABEZADO DE CADA TABLA + BOTONES
   =============================== */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.table-header h3 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
  border: none;
  color: #fff;
}

.action-edit {
  background: var(--green);
}

.action-edit:hover {
  background: var(--green-hover);
}

.action-delete {
  background: var(--red);
}

.action-delete:hover {
  background: var(--red-hover);
}

.btn-cancel {
  background: var(--gray);
}

.btn-cancel:hover {
  background: var(--gray-hover);
}


/* ===============================
   TABLAS
   =============================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;                 /* en celular la tabla se desliza de lado */
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead {
  background: #f3f4f6;
}

th,
td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

tbody tr:nth-child(even) {
  background: var(--surface-soft);
}

tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.06);
  cursor: pointer;
}

/* Campos editables dentro de las tablas */
td input[type="text"],
td input[type="number"],
td input[type="date"] {
  width: 100%;
  border: none;
  background: transparent;
  padding: 4px;
  font-size: inherit;
  font-family: inherit;
}

td input:focus {
  outline: 2px solid #93c5fd;
  border-radius: 4px;
  background: #fff;
}

/* Ordenar columnas */
th[data-column] {
  cursor: pointer;
  user-select: none;
}

th .sort-arrow {
  margin-left: 4px;
  opacity: 0.5;
}

th.sorted-asc .sort-arrow::after {
  content: "↑";
}

th.sorted-desc .sort-arrow::after {
  content: "↓";
}

/* Selección de filas */
.selected-row {
  background-color: #dbeafe !important;
}

.clicked-cell {
  background-color: #0adb26 !important;
}

/* Tabla de resumen centrada */
#summaryTable th,
#summaryTable td {
  text-align: center;
}


/* ===============================
   PESTAÑA FIJOS
   =============================== */
.help-text {
  margin: -4px 0 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.fixed-block {
  margin-top: 22px;
}

.fixed-block .table-header {
  margin-bottom: 8px;
}

.fixed-block h4 {
  margin: 0;
  font-size: 1.1rem;
}

td select {
  width: 100%;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
}

td select:focus {
  outline: 2px solid #93c5fd;
  background: #fff;
}


/* ===============================
   BOTÓN CATEGORÍAS + BARRA DE FILTRO
   =============================== */
.action-category {
  background: #4a5568;
}

.action-category:hover {
  background: #2d3748;
}

.btn-light {
  background: #eef0f3;
  color: var(--text);
}

.btn-light:hover {
  background: #e2e5ea;
}

.filter-bar {
  margin-bottom: 12px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.status-switch button {
  font-size: 0.85rem;
  padding: 6px 12px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e40af;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip span {
  font-size: 0.75rem;
  opacity: 0.7;
}

.filter-chip:hover {
  background: #dbeafe;
}

.filter-clear {
  border: none;
  background: none;
  color: #c0392b;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px;
}

.filter-summary {
  margin: 8px 0 0;
  padding: 8px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.filter-summary strong {
  color: var(--text);
}


/* ===============================
   VENTANA DE CATEGORÍAS
   =============================== */
.modal-content.categories-content {
  width: 760px;
  max-width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.categories-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.categories-header h3 {
  margin: 0;
}

.categories-subtitle {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.categories-close {
  border: none;
  background: #f3f4f6;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.categories-close:hover {
  background: #e5e7eb;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  overflow-y: auto;
  align-items: start;
}

.categories-empty {
  color: var(--text-muted);
  grid-column: 1 / -1;
  text-align: center;
}

.categories-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
}

.categories-footer-left {
  display: flex;
  gap: 8px;
}

/* Tarjeta de categoría */
.category-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.category-card:hover {
  border-color: #93c5fd;
}

.category-card:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.category-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: #f8fbff;
}

.category-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-check {
  width: 20px;
  height: 20px;
  border: 2px solid #cbd5e1;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.category-card.selected .category-check {
  background: var(--primary);
  border-color: var(--primary);
}

.category-name {
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-total {
  font-weight: 700;
}

.category-meta {
  margin: 2px 0 10px 28px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.category-progress {
  height: 8px;
  background: #fde68a;
  border-radius: 999px;
  overflow: hidden;
}

.category-progress span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 999px;
}

.category-count {
  margin-top: 6px;
  font-size: 0.85rem;
}

.category-card.complete .category-count {
  color: #166534;
}

.category-money {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.category-money strong {
  color: var(--text);
}

.category-money .money-pending {
  color: #b45309;
}

.category-details-btn {
  margin-top: 10px;
  border: none;
  background: none;
  padding: 2px 0;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.category-details {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  cursor: default;
}

.category-details ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-details li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid #f3f4f6;
}

.category-details li:last-child {
  border-bottom: none;
}

.detail-date {
  color: var(--text-muted);
  text-transform: capitalize;
  white-space: nowrap;
  font-size: 0.8rem;
}

.detail-value {
  font-weight: 600;
}

.category-details .status-pill {
  padding: 3px 8px;
  font-size: 0.75rem;
  cursor: default;
}

.mark-all-btn {
  width: 100%;
  margin-top: 10px;
  font-size: 0.85rem;
}


/* ===============================
   ESTADO (Pagado / Pendiente)
   =============================== */
.status-pill {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease;
  white-space: nowrap;
}

.status-paid {
  background: var(--green);
  color: #fff;
}

.status-paid:hover {
  background: var(--green-hover);
}

.status-pending {
  background: var(--yellow);
  color: #000;
}

.status-pending:hover {
  background: var(--yellow-hover);
}


/* ===============================
   POPUPS (nuevo gasto / ingreso)
   =============================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9999;
}

.modal-content {
  background: var(--surface);
  border-radius: 10px;
  padding: 18px 20px;
  width: 360px;
  max-width: 100%;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.modal-content h3 {
  margin-top: 0;
}

.modal-content label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 8px;
}

.modal-content input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  margin: 4px 0 6px;
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}


/* ===============================
   LOGIN
   =============================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgb(250, 249, 249);
  z-index: 10000;
}

.login-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  padding: 30px;
  border-radius: 12px;
  z-index: 10001;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.35);
  border: 2px solid #333;
  width: 350px;
  max-width: 90%;
  text-align: center;
}

.login-popup h2 {
  margin: 0 0 15px;
  font-size: 22px;
}

.login-popup input {
  width: 100%;
  padding: 12px;
  margin: 10px 0;
  font-size: 16px;
  border: 1px solid #aaa;
  border-radius: 6px;
}

.login-popup button {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  font-size: 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.login-message {
  margin: 6px 0 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.9rem;
}

#loginBtn {
  background: #007bff;
  color: #fff;
}

#loginBtn:hover {
  background: #0069d9;
}


/* ===============================
   PROCESANDO...
   =============================== */
#loadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
}


/* ===============================
   FOOTER
   =============================== */
.app-footer {
  margin-top: 24px;
  padding: 12px 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}


/* =====================================================
   📱 CELULAR Y TABLETA (pantallas de 768px o menos)
   ===================================================== */
@media (max-width: 768px) {

  .app-header {
    padding: 12px 16px;
  }

  .app-header h1 {
    font-size: 1.25rem;
  }

  .month-selector .field {
    flex: 1 1 140px;
  }

  .month-selector input {
    width: 100%;
    font-size: 16px; /* 16px evita que el iPhone haga zoom */
  }

  .month-selector button {
    flex: 1 1 100%;
  }

  .app-main {
    padding: 12px;
  }

  /* Las tarjetas ya no se quedan fijas arriba (ocuparían toda la pantalla) */
  .summary-header {
    position: static;
    border-bottom: none;
    padding: 4px 0;
  }

  .dashboard-cards {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .card p {
    font-size: 1.1rem;
  }

  .card-balance,
  .card-savings,
  .dashboard-cards .card:nth-child(4) {
    grid-column: 1 / -1; /* saldo, ingresos y ahorro a lo ancho */
  }

  /* Tabs que se deslizan de lado */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    margin: 12px 0;
  }

  .tab-btn {
    padding: 9px 14px;
    font-size: 0.9rem;
  }

  .panel {
    padding: 12px;
  }

  .table-header h3 {
    font-size: 1.2rem;
  }

  .table-actions {
    width: 100%;
  }

  .table-actions .action-btn {
    flex: 1 1 auto;
  }

  /* La tabla tiene un ancho mínimo y se desliza de lado */
  table {
    min-width: 560px;
  }

  td input[type="text"],
  td input[type="number"],
  td input[type="date"],
  td select,
  .modal-content input {
    font-size: 16px; /* evita zoom automático en iPhone */
  }

  .charts-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .chart-box {
    padding: 12px;
  }

  .chart-head {
    flex-direction: column;
  }

  .chart-canvas {
    height: 240px;
  }

  #loadingOverlay {
    font-size: 22px;
  }

  .app-footer {
    text-align: center;
  }

  /* Categorías: la ventana sale desde abajo, a pantalla completa */
  .categories-modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-content.categories-content {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .categories-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .categories-footer {
    padding: 10px 12px;
  }

  .categories-footer .action-btn {
    flex: 1 1 auto;
  }

  .categories-footer-left {
    flex: 1 1 100%;
  }

  .categories-footer-left .action-btn {
    flex: 1;
  }

  #categoriesApply {
    flex: 1 1 100%;
    padding: 12px;
  }

  .status-switch {
    width: 100%;
  }

  .status-switch button {
    flex: 1;
  }
}
