:root {
  --gold: #c9a24b;
  --dark: #2b2b2b;
  --olive: #7a8471;
  --brick: #a0522d;
  --bg: #f7f5f0;
  --card: #ffffff;
  --border: #e5e0d5;
  --text: #2b2b2b;
  --muted: #8a8578;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: var(--dark);
  color: #fff;
}
.topnav .brand { font-weight: 600; letter-spacing: 0.3px; }
.navlinks a {
  color: #e5e0d5;
  text-decoration: none;
  margin-left: 22px;
  font-size: 14px;
}
.navlinks a:hover { color: var(--gold); }
.navlinks a.logout { color: #c98a4b; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px; }

.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px 0; color: var(--dark); }

.mes-selector select { padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); margin-left: 6px; background: #fff; }
.btn-pdf { background: var(--dark); color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 6px; font-size: 13px; white-space: nowrap; }
.btn-pdf:hover { opacity: 0.85; }

/* Tablas responsivas: en pantallas angostas, cada fila se convierte en una
   tarjeta apilada (etiqueta: valor) en vez de columnas apretadas.
   No aplica a .historico, que necesita su propio scroll horizontal. */
@media (max-width: 700px) {
  .table:not(.historico) thead { display: none; }
  .table:not(.historico) tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 6px 10px;
    background: #fff;
  }
  .table:not(.historico) tr.cat-header { background: #f0ead9; }
  .table:not(.historico) td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid #f0ead9;
    text-align: right;
  }
  .table:not(.historico) td:last-child { border-bottom: none; }
  .table:not(.historico) td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--muted);
    text-align: left;
    flex-shrink: 0;
  }
  .table:not(.historico) td:not([data-label]),
  .table:not(.historico) td[data-label=""] {
    justify-content: flex-start;
  }
  .table:not(.historico) input[type="text"],
  .table:not(.historico) input[type="number"],
  .table:not(.historico) select {
    text-align: right;
    max-width: 62%;
  }
  .table:not(.historico) .row-actions { justify-content: flex-end; gap: 8px; }
  .kpi-row, .quincenas-row { flex-direction: column; }
  .grid-2 { grid-template-columns: 1fr; }
}

.kpi-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.kpi { flex: 1 1 220px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 20px 22px; position: relative; overflow: hidden; transition: transform 0.15s ease; }
.kpi-icon { font-size: 26px; margin-bottom: 6px; line-height: 1; }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -0.5px; }
.kpi-value.positive { color: #3f7a52; }
.kpi-value.negative { color: var(--brick); }
.kpi-edit { display: flex; gap: 6px; margin-top: 10px; }
.kpi-edit input { flex: 1; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); }
.kpi-edit button, .inline-form button, button { background: var(--gold); border: none; color: #fff; padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.kpi-edit button:hover, button:hover { opacity: 0.88; }

.kpi-ingreso-card { background: linear-gradient(160deg, #fbf7ec 0%, var(--card) 65%); border-color: #e8dcb8; }
.kpi-gastos-card { background: linear-gradient(160deg, #fbf0ea 0%, var(--card) 65%); border-color: #edd6c8; }
.kpi-balance-card {
  border-width: 2px;
  background: linear-gradient(160deg, #eef6ef 0%, var(--card) 65%);
  border-color: #bfe0c6;
}
.kpi-balance-card.kpi-card-negative { background: linear-gradient(160deg, #fbeceb 0%, var(--card) 65%); border-color: #eabdb6; }
.kpi-balance-card .kpi-value { font-size: 34px; }
.kpi-mensaje { margin-top: 8px; font-size: 13px; font-weight: 600; color: #3f7a52; }
.kpi-balance-card.kpi-card-negative .kpi-mensaje { color: var(--brick); }

.kpi-progress { margin-top: 12px; height: 8px; border-radius: 5px; background: #ece5d5; overflow: hidden; }
.kpi-progress-bar { height: 100%; border-radius: 5px; background: linear-gradient(90deg, #c9a24b, #a0522d); transition: width 0.3s ease; }
.kpi-progress-bar.kpi-progress-over { background: linear-gradient(90deg, #a0522d, #7a2f1f); }
.kpi-pendiente { font-size: 11px; color: var(--brick); margin-top: 6px; font-weight: 600; }
.kpi-pendiente.kpi-pendiente-ok { color: #3f7a52; }
.kpi-por-vencer { font-size: 11px; color: var(--muted); margin-top: 4px; }

.quincenas-row { display: flex; gap: 16px; flex-wrap: wrap; }
.quincena-box { flex: 1 1 260px; background: #faf8f2; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.quincena-titulo { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--dark); margin-bottom: 8px; }
.quincena-linea { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; font-size: 13px; }
.quincena-linea.muted span { color: var(--muted); }
.quincena-pendiente { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; color: var(--brick); }
.quincena-pendiente strong { font-size: 15px; }
.prox-badge { background: #f0ead9; color: var(--dark); font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 12px; white-space: nowrap; }

.moneda-toggle { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.moneda-toggle label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.link-editar { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--olive); text-decoration: none; cursor: pointer; }
.link-editar:hover { text-decoration: underline; }
#panel-editar-ingreso { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.kpi-edit-usd { margin-top: 8px; }
.usd-fila { margin-bottom: 8px; }
.usd-fila label { display: flex; justify-content: space-between; align-items: center; }
.usd-fila input { width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); margin-top: 3px; }
.btn-trm { background: none; border: 1px solid var(--olive); color: var(--olive); font-size: 10px; padding: 2px 8px; border-radius: 10px; cursor: pointer; }
.btn-trm:hover { background: var(--olive); color: #fff; }
.usd-resultado { font-weight: 700; font-size: 15px; color: var(--dark); margin: 6px 0 4px; }

.grid-2 { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; margin-bottom: 18px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; margin-bottom: 18px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--border); color: var(--muted); font-size: 12px; text-transform: uppercase; }
.table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .center { text-align: center; }
.table tfoot td { border-top: 2px solid var(--dark); border-bottom: none; }
.table.editable input, .table.editable select { width: 100%; padding: 5px 6px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; }
.table.editable td { padding: 5px 8px; }
tr.inactivo { opacity: 0.45; }
tr.cat-header td { background: #f0ead9; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--dark); padding-top: 10px; padding-bottom: 6px; }
.table.historico { font-size: 12px; white-space: nowrap; }
.table.historico th, .table.historico td { padding: 5px 8px; }

.toggle-nota { cursor: pointer; text-align: center; color: var(--muted); user-select: none; }
.toggle-icon { font-size: 11px; display: inline-block; width: 14px; }
.nota-badge { margin-left: 6px; font-size: 12px; cursor: help; }
tr.fila-detalle td { border-top: none; padding-top: 0; padding-bottom: 12px; background: #faf8f2; }
.detalle-box { background: #faf8f2; border: 1px dashed var(--border); border-radius: 8px; padding: 12px 14px; }
.detalle-box textarea { width: 100%; margin-top: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 13px; resize: vertical; }
.nota-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.nota-confirmacion, .nombre-confirmacion { font-size: 12px; color: #3f7a52; font-weight: 600; opacity: 0; transition: opacity 0.2s ease; }
.nota-confirmacion.visible, .nombre-confirmacion.visible { opacity: 1; }
.detalle-separador { border-top: 1px solid var(--border); margin: 14px 0 10px; }
.detalle-acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-secundario { background: #e5e0d2; color: var(--dark); border: none; padding: 7px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-secundario:hover { opacity: 0.85; }
.btn-peligro { background: #b0453a; color: #fff; border: none; padding: 7px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-peligro:hover { opacity: 0.88; }
.row-form { display: contents; }
.row-actions { display: flex; gap: 4px; }
.row-actions button.danger { background: #b0453a; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }

.login-box { max-width: 360px; margin: 80px auto; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 32px; text-align: center; }
.login-box h1 { font-size: 20px; }
.login-box form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; text-align: left; }
.login-box input { padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; }
.login-box label { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.alert.error { background: #fbe2df; color: #a0392c; padding: 8px 12px; border-radius: 6px; font-size: 13px; }
