:root {
  --bg: #f2f0eb;
  --surface: #ffffff;
  --text: #23262b;
  --muted: #686f78;
  --border: #d9d5cb;
  --accent: #3c4a5c;
  --accent-hover: #2c3846;
  --error: #8a3324;
  --error-bg: #f6e9e6;
  --ok-bg: #e9efe6;
  --ok: #3c5c3c;
  --aviso-bg: #f6efe0;
  --aviso: #8a6416;
}

* { box-sizing: border-box; }

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

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

/* ---------- Login ---------- */

.pantalla-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tarjeta-login {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2.5rem 2.5rem 2rem;
  width: 340px;
  border-radius: 4px;
}

.tarjeta-login h1 {
  font-size: 1.4rem;
  text-align: center;
  margin-bottom: 0.25rem;
}

.tarjeta-login .subtitulo {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1.75rem;
}

/* ---------- Layout general ---------- */

.encabezado {
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
}

.encabezado .marca {
  font-family: Georgia, serif;
  font-size: 1.15rem;
}

.encabezado nav {
  display: flex;
  gap: 1.25rem;
}

.encabezado nav button {
  background: none;
  border: none;
  color: #dfe3e8;
  font-size: 0.9rem;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.encabezado nav button.activo {
  color: #fff;
  border-bottom-color: #fff;
}

.encabezado .usuario-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
  color: #dfe3e8;
}

.encabezado .usuario-info button {
  background: none;
  border: 1px solid #6a7889;
  color: #fff;
  padding: 0.3rem 0.7rem;
  border-radius: 3px;
}

.usuario-menu {
  position: relative;
}

.usuario-menu > button {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.usuario-menu-lista {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  min-width: 190px;
  overflow: hidden;
  z-index: 20;
}

.encabezado .usuario-info .usuario-menu-lista button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0;
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  color: var(--text);
}

.encabezado .usuario-info .usuario-menu-lista button:hover {
  background: #f2f4f7;
}

.usuario-menu-lista button + button {
  border-top: 1px solid var(--border);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ---------- Formularios genéricos ---------- */

.campo {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
}

.campo label {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.campo input[type="text"],
.campo input[type="email"],
.campo input[type="password"],
.campo textarea,
.campo select {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.55rem 0.65rem;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

.campo textarea { resize: vertical; min-height: 4.5rem; }

.campo-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.campo-checkbox label { margin-bottom: 0; font-size: 0.9rem; color: var(--text); }

.boton-principal {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.65rem 1.4rem;
  border-radius: 3px;
  font-size: 0.95rem;
}

.boton-principal:hover { background: var(--accent-hover); }
.boton-principal:disabled { opacity: 0.6; cursor: default; }

.boton-secundario {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 3px;
  font-size: 0.9rem;
}

.mensaje-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid #dcb8ae;
  padding: 0.6rem 0.85rem;
  border-radius: 3px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.mensaje-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid #b9ceb0;
  padding: 0.6rem 0.85rem;
  border-radius: 3px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.mensaje-aviso {
  background: var(--aviso-bg);
  color: var(--aviso);
  border: 1px solid #d9c48f;
  padding: 0.6rem 1.5rem;
  font-size: 0.85rem;
  text-align: center;
}

/* ---------- Plantillas ---------- */

.lista-plantillas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.tarjeta-plantilla {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem;
  text-align: left;
}

.tarjeta-plantilla h3 { font-size: 1.05rem; }
.tarjeta-plantilla p { color: var(--muted); font-size: 0.85rem; margin: 0 0 1rem; }

/* ---------- Formulario dinámico ---------- */

.seccion-formulario {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.seccion-formulario h3 {
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.6rem;
  margin-bottom: 1.1rem;
}

.grilla-campos {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0 1.25rem;
}

.ancho-completo { grid-column: 1 / -1; }
.ancho-mitad { grid-column: span 6; }
.ancho-tercio { grid-column: span 4; }
.ancho-cuarto { grid-column: span 3; }

@media (max-width: 640px) {
  .ancho-mitad, .ancho-tercio, .ancho-cuarto { grid-column: 1 / -1; }
}

.grupo-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  margin-bottom: 0.4rem;
}

.grupo-radios .opcion-radio {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
}

.titular-bloque {
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 1rem 1.1rem 0.3rem;
  margin-bottom: 1rem;
}

.titular-bloque h4 {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
  font-family: inherit;
}

.buscador-persona {
  position: relative;
  margin-bottom: 0.9rem;
}

.resultados-persona {
  position: absolute;
  z-index: 5;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  max-height: 180px;
  overflow-y: auto;
}

.resultados-persona div {
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.resultados-persona div:hover { background: var(--bg); }
.resultados-persona div:last-child { border-bottom: none; }

.acciones-formulario {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* ---------- Historial ---------- */

table.tabla-historial {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
}

table.tabla-historial th,
table.tabla-historial td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

table.tabla-historial th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.tabla-historial a { color: var(--accent); }

/* Evita que una tabla ancha (ej. la de Usuarios, con selects y botones en
   la última columna) empuje toda la página a hacer scroll horizontal. */
.tabla-scroll {
  overflow-x: auto;
}

/* ---------- Presupuestos ---------- */

table.tabla-desglose {
  width: 100%;
  max-width: 480px;
  border-collapse: collapse;
}

table.tabla-desglose td {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

table.tabla-desglose td.monto {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.tabla-desglose tr.fila-total td {
  font-weight: 700;
  border-bottom: none;
  border-top: 2px solid var(--text);
  padding-top: 0.7rem;
  font-size: 1.05rem;
}

table.tabla-desglose tr.fila-detalle-gasto td {
  padding: 0.3rem 0 0.3rem 1.25rem;
  border-bottom: none;
  font-size: 0.82rem;
  color: var(--muted);
}

.nota-etiqueta {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 400;
}

table.tabla-historial select {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.3rem 0.4rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

table.tabla-historial select:disabled {
  background: var(--bg);
  color: var(--muted);
}

.vacio {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1rem 0;
}
