/* Reset y base */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #0d0d0d;
  color: #e0e0e0;
}
a { color: #6a9fb5; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 260px;
  background: #1a1a1a;
  padding: 20px 0;
  border-right: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}
.sidebar-header h2 {
  color: #fff;
  text-align: center;
  margin-bottom: 30px;
}
.sidebar nav ul {
  list-style: none;
  padding: 0 20px;
  flex: 1;
}
.sidebar nav ul li {
  margin: 8px 0;
}
.sidebar nav ul li a {
  color: #b0b0b0;
  display: block;
  padding: 10px 15px;
  border-radius: 8px;
  transition: background 0.2s;
}
.sidebar nav ul li a:hover,
.sidebar nav ul li a.active {
  background: #2a2a2a;
  color: #fff;
}
.sidebar-user {
  padding: 15px 20px;
  border-top: 1px solid #2a2a2a;
  color: #888;
  font-size: 0.9em;
  text-align: center;
}
.main-content {
  flex: 1;
  padding: 30px 40px;
  background: #121212;
}

/* Autenticación */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 80vh;
}
.auth-box {
  background: #1e1e1e;
  padding: 40px;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.auth-box h1 { margin-bottom: 20px; text-align: center; }
.auth-box label {
  display: block;
  margin: 15px 0 5px;
}
.auth-box input {
  width: 100%;
  padding: 10px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #0d0d0d;
  color: #e0e0e0;
}
.auth-box .btn-primary {
  width: 100%;
  margin-top: 20px;
}
.error {
  color: #ff6b6b;
  margin-bottom: 15px;
}

/* Botones */
.btn-primary, .btn-secondary {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}
.btn-primary {
  background: #3b82f6;
  color: #fff;
}
.btn-primary:hover { background: #2563eb; }
.btn-secondary {
  background: #2a2a2a;
  color: #e0e0e0;
}
.btn-secondary:hover { background: #3a3a3a; }

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}
.toolbar h1 { font-size: 1.8rem; }
.toolbar div { display: flex; gap: 10px; }

/* Modales */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.modal.visible { display: flex; }
.modal-content {
  background: #1e1e1e;
  padding: 30px;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content .close {
  position: absolute;
  top: 10px; right: 20px;
  font-size: 28px;
  cursor: pointer;
  color: #aaa;
}
.modal-content .close:hover { color: #fff; }
.modal-content h2 { margin-bottom: 20px; }
.modal-content label {
  display: block;
  margin: 10px 0 5px;
}
.modal-content input, .modal-content select {
  width: 100%;
  padding: 8px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #0d0d0d;
  color: #e0e0e0;
}
.modal-content .btn-primary { margin-top: 15px; }

/* Cuotas dentro del modal de dividir */
.cuota-input {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}
.cuota-input input { flex: 1; }
.btn-remove-cuota {
  background: #ff6b6b;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  color: #fff;
  cursor: pointer;
  font-weight: bold;
}
#btn-agregar-cuota { margin: 10px 0; }

/* Menú contextual (tres puntos) */
.menu-contextual {
  position: fixed;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 5px 0;
  z-index: 2000;
  min-width: 160px;
}
.menu-contextual.hidden { display: none; }
.menu-contextual ul {
  list-style: none;
}
.menu-contextual ul li {
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.menu-contextual ul li:hover {
  background: #2a2a2a;
}

/* Listado de gastos */
.gasto-item {
  background: #1a1a1a;
  border-radius: 8px;
  margin-bottom: 15px;
  overflow: hidden;
}
.gasto-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.gasto-header:hover { background: #222; }
.gasto-info { display: flex; gap: 15px; align-items: center; flex-wrap: wrap; }
.gasto-info .tipo { color: #6a9fb5; font-size: 0.9em; }
.gasto-info .fecha { color: #888; font-size: 0.9em; }
.gasto-valor {
  display: flex;
  align-items: center;
  gap: 15px;
  font-weight: 600;
}
.menu-tres-puntos {
  cursor: pointer;
  font-size: 1.5em;
  line-height: 1;
  padding: 0 5px;
  user-select: none;
}

/* Cuotas dentro de un gasto */
.cuotas-container {
  background: #111;
  padding: 10px 20px 15px 40px;
  border-top: 1px solid #2a2a2a;
}
.cuota-item {
  display: flex;
  gap: 15px;
  align-items: center;
  padding: 4px 0;
}
.cuota-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.cuota-item .fecha-pago {
  color: #888;
  font-size: 0.85em;
  margin-left: auto;
}
.empty {
  color: #888;
  text-align: center;
  padding: 40px 0;
}

/* Detalle */
.detalle-container {
  max-width: 700px;
  margin: 0 auto;
}
.btn-back {
  display: inline-block;
  margin-bottom: 20px;
  color: #6a9fb5;
}
.detalle-container ul {
  list-style: none;
  padding: 0;
}
.detalle-container ul li {
  background: #1a1a1a;
  padding: 8px 15px;
  margin: 5px 0;
  border-radius: 6px;
}
/* Botones de cuentas */
.cuentas-container {
  margin-bottom: 25px;
}
.cuentas-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cuenta-btn {
  padding: 8px 18px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 20px;
  color: #b0b0b0;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9em;
}
.cuenta-btn:hover {
  background: #2a2a2a;
  border-color: #555;
}
.cuenta-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

/* Checkbox de gasto */
.gasto-info input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  margin-right: 10px;
}

/* Fecha de pago editable en cuotas */
.fecha-pago-input {
  background: #0d0d0d;
  border: 1px solid #333;
  border-radius: 4px;
  color: #e0e0e0;
  padding: 2px 6px;
  font-size: 0.85em;
  width: 130px;
  cursor: pointer;
}
.fecha-pago-input:focus {
  border-color: #3b82f6;
  outline: none;
}

/* Sección archivados */
.archivados-section {
  margin-top: 40px;
  border-top: 1px solid #2a2a2a;
  padding-top: 15px;
}
.archivados-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background: #1a1a1a;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.archivados-toggle:hover {
  background: #222;
}
.archivados-toggle .arrow {
  transition: transform 0.3s;
}
.archivados-toggle.open .arrow {
  transform: rotate(90deg);
}
.archivados-content {
  margin-top: 10px;
}
.archivados-content .gasto-item {
  opacity: 0.7;
  background: #111;
}