/* ==========================================================================
   Cashflow App — estilos generales (mobile-first)
   ========================================================================== */

:root {
  --azul: #1F4E78;
  --azul-claro: #DDEBF7;
  --gris-borde: #d9d9d9;
  --gris-fondo: #f5f6f8;
  --verde: #C6EFCE;
  --verde-texto: #006100;
  --rojo: #FFC7CE;
  --rojo-texto: #9C0006;
  --texto: #2c2c2c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--gris-fondo);
  color: var(--texto);
  font-size: 15px;
}

a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* --- Barra superior / navegación --- */
header.topbar {
  background: var(--azul);
  color: white;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
header.topbar .brand {
  font-weight: bold;
  font-size: 1.1em;
  color: white;
}
header.topbar .user-info {
  font-size: 0.85em;
  color: #dbe8f5;
}

nav.mainnav {
  background: #163a5c;
}
nav.mainnav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
}
nav.mainnav a {
  display: block;
  padding: 10px 14px;
  color: #eaf2fa;
  font-size: 0.92em;
  white-space: nowrap;
}
nav.mainnav a:hover, nav.mainnav a.active {
  background: var(--azul);
  text-decoration: none;
}

/* --- Tarjetas / bloques --- */
.card {
  background: white;
  border: 1px solid var(--gris-borde);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

h1 { font-size: 1.4em; margin: 0 0 4px; color: var(--azul); }
h2 { font-size: 1.15em; color: var(--azul); margin-top: 0; }
.subtitle { color: #666; font-size: 0.9em; margin-bottom: 16px; }

/* --- Formularios --- */
label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: 0.9em; }
input[type=text], input[type=date], input[type=number], input[type=password],
input[type=search], select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--gris-borde);
  border-radius: 6px;
  font-size: 1em;
  background: white;
}
input[type=checkbox] { width: 20px; height: 20px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  min-width: 150px;
  border-radius: 6px;
  border: none;
  background: var(--azul);
  color: white;
  font-size: 0.95em;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}
.btn:hover { background: #163a5c; color: white; text-decoration: none; }
.btn.secundario { background: #6c757d; }
.btn.peligro { background: #b02a37; }
.btn.pequeno { padding: 6px 10px; font-size: 0.85em; min-width: 0; white-space: normal; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > div { flex: 1 1 200px; }

.alert {
  padding: 12px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.92em;
}
.alert.ok { background: var(--verde); color: var(--verde-texto); }
.alert.error { background: var(--rojo); color: var(--rojo-texto); }
.alert.info { background: var(--azul-claro); color: var(--azul); }

/* --- Badges de Tipo / Estado --- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 0.8em;
  font-weight: 600;
  white-space: nowrap;
}

/* --- Filtros --- */
.filtros {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: flex-end;
}
.filtros > div { flex: 1 1 150px; }
.filtros label { margin-top: 0; }

/* --- Tablas responsive tipo "tarjeta" en móvil --- */
table.datos {
  width: 100%;
  border-collapse: collapse;
  background: white;
}
table.datos th {
  background: #eef3f8;
  text-align: left;
  padding: 10px;
  font-size: 0.85em;
  color: var(--azul);
  border-bottom: 2px solid var(--gris-borde);
}
table.datos td {
  padding: 10px;
  border-bottom: 1px solid var(--gris-borde);
  vertical-align: middle;
  font-size: 0.92em;
}
table.datos tr:hover td { background: #fafcff; }

.check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  margin: 0;
}
.marcado-por {
  display: block;
  font-size: 0.75em;
  color: #777;
  margin-top: 2px;
}

.resumen-final {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 16px 0;
}
.resumen-final .bloque {
  flex: 1 1 200px;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.resumen-final .bloque .label { font-size: 0.85em; font-weight: 600; }
.resumen-final .bloque .valor { font-size: 1.5em; font-weight: bold; margin-top: 6px; }

.tabla-scroll { overflow-x: auto; }

footer.pie {
  text-align: center;
  color: #888;
  font-size: 0.8em;
  padding: 20px;
}

/* ---------- MÓVIL ---------- */
@media (max-width: 760px) {
  nav.mainnav ul { flex-direction: column; }
  nav.mainnav a { padding: 12px 14px; border-bottom: 1px solid #23507a; }

  table.datos, table.datos thead, table.datos tbody, table.datos th, table.datos td, table.datos tr {
    display: block;
  }
  table.datos thead { display: none; }
  table.datos tr {
    margin-bottom: 12px;
    border: 1px solid var(--gris-borde);
    border-radius: 8px;
    overflow: hidden;
  }
  table.datos td {
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    text-align: right;
  }
  table.datos td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--azul);
    text-align: left;
    font-size: 0.85em;
  }
  .form-row { flex-direction: column; }
  .resumen-final .bloque { flex: 1 1 100%; }
}

/* --- Portal: estructura con barra lateral --- */
.app-shell {
  display: flex;
  align-items: flex-start;
}
.sidebar-toggle {
  display: inline-block;
  background: none;
  border: none;
  color: white;
  font-size: 1.4em;
  cursor: pointer;
  margin-right: 12px;
  padding: 0 4px;
}
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: #f5f7fa;
  border-right: 1px solid var(--gris-borde);
  min-height: calc(100vh - 52px);
  transition: width 0.15s, margin 0.15s;
  overflow: hidden;
}
/* Escritorio: al esconderla, se reduce a 0 y el contenido ocupa todo el ancho, en vez del
   cajón deslizante que se usa en móvil. Se recuerda la preferencia entre páginas. */
@media (min-width: 901px) {
  .app-shell.sidebar-oculta-escritorio .sidebar {
    width: 0;
    min-width: 0;
    border-right: none;
  }
}
.sidebar-inner { padding: 10px 0 30px; }
.sidebar-link, .sidebar-section a {
  display: block;
  padding: 9px 18px;
  color: var(--texto);
  font-size: 0.92em;
  border-right: 3px solid transparent;
}
.sidebar-link { font-weight: 600; }
.sidebar-link:hover, .sidebar-section a:hover { background: #eaf0f7; text-decoration: none; }
.sidebar-link.active, .sidebar-section a.active {
  background: var(--azul-claro);
  color: var(--azul);
  font-weight: 700;
  border-right: 3px solid var(--azul);
}
.sidebar-section-title {
  padding: 16px 18px 4px;
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8a93a3;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.sidebar-section-title .chevron { font-size: 11px; opacity: 0.7; }
.sidebar-section-links { display: none; flex-direction: column; }
.sidebar-section-links.abierto { display: flex; }
.sidebar-subtitulo { font-size: 0.72em; text-transform: uppercase; letter-spacing: .04em; color: #9aa4b2; padding: 10px 0 2px 4px; font-weight: 600; }
.sidebar-backdrop { display: none; }
.main-content { flex: 1 1 auto; min-width: 0; }

.cf-dropzone {
  border: 2px dashed #7ba7d4;
  border-radius: 8px;
  padding: 18px;
  text-align: center;
  color: #1F4E78;
  cursor: pointer;
  font-size: 0.9em;
  margin-bottom: 8px;
  transition: background 0.15s;
}
.cf-dropzone:hover { background: #f3f8fd; }
.cf-dropzone-sobre { background: #eaf3fc; border-color: #1F4E78; }
.cf-dropzone-nombre { font-weight: bold; color: #006100; }

/* ---------- MÓVIL: barra lateral en cajón (off-canvas) ---------- */
@media (max-width: 900px) {
  .sidebar-toggle { display: inline-block; }
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    width: 250px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.22s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.18);
    overflow-y: auto;
  }
  .sidebar.abierto { left: 0; }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
  }
  .sidebar-backdrop.abierto { display: block; }
  .main-content { width: 100%; }
}

/* --- Portal: pantalla de inicio con módulos --- */
.modulos-inicio {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.modulo-card {
  flex: 1 1 220px;
  background: white;
  border: 1px solid var(--gris-borde);
  border-radius: 10px;
  padding: 28px 20px;
  text-align: center;
  color: var(--texto);
  transition: box-shadow 0.15s, transform 0.15s;
}
.modulo-card:hover {
  box-shadow: 0 6px 18px rgba(31,78,120,0.15);
  transform: translateY(-2px);
  text-decoration: none;
}
.modulo-card .icono { font-size: 2.6em; margin-bottom: 10px; }
.modulo-card h2 { margin: 0 0 6px; color: var(--azul); font-size: 1.15em; }
.modulo-card p { margin: 0; color: #666; font-size: 0.88em; }

.tabs-modulo {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--gris-borde);
  margin-bottom: 18px;
}
.tabs-modulo a {
  padding: 10px 16px;
  color: #666;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  font-size: 0.92em;
}
.tabs-modulo a.active {
  color: var(--azul);
  font-weight: 700;
  border-bottom-color: var(--azul);
}

.print-only { display: none; }

.cf-enviando { opacity: 0.55; cursor: not-allowed; }

/* --- "Papel" de informe: aspecto de documento profesional --- */
.hoja-informe {
  background: #fff;
  max-width: 980px;
  margin: 0 auto 24px;
  padding: 34px 42px 20px;
  border: 1px solid #e0e2e6;
  border-radius: 6px;
  box-shadow: 0 4px 18px rgba(20, 40, 70, 0.07);
}
.informe-letterhead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.informe-empresa {
  display: flex;
  align-items: center;
  gap: 14px;
}
.informe-logo {
  max-height: 60px;
  max-width: 150px;
  object-fit: contain;
}
.informe-empresa-datos {
  font-size: 0.82em;
  line-height: 1.55;
  color: #555;
}
.informe-titulo-bloque {
  text-align: right;
  flex: 1 1 260px;
}
.informe-ref {
  font-size: 0.72em;
  letter-spacing: 0.08em;
  color: #9aa5b1;
  font-weight: 700;
  text-transform: uppercase;
}
.informe-titulo-bloque h1 {
  margin: 2px 0 2px;
  font-size: 1.5em;
  color: #16324f;
}
.informe-titulo-bloque .subtitle {
  margin-bottom: 2px;
  color: #64748b;
}
.informe-fecha {
  font-size: 0.76em;
  color: #a3aab3;
  margin: 0;
}
.informe-separador {
  border: none;
  border-top: 3px solid var(--azul);
  margin: 14px 0 22px;
}
.informe-pie {
  margin-top: 26px;
  padding-top: 12px;
  border-top: 1px solid #eceef1;
  font-size: 0.72em;
  color: #b0b6bd;
  text-align: center;
}

/* Tablas dentro de un informe: estilo "documento de gestión" */
.hoja-informe table.datos {
  border: 1px solid #dde2e8;
  border-radius: 4px;
  overflow: hidden;
}
.hoja-informe table.datos thead th {
  background: #16324f;
  color: #fff;
  font-size: 0.74em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 11px 13px;
  border-bottom: none;
}
.hoja-informe table.datos tbody td {
  padding: 9px 13px;
  border-bottom: 1px solid #edf0f3;
  font-size: 0.92em;
}
.hoja-informe table.datos tbody tr:nth-child(even) td { background: #f7f9fb; }
.hoja-informe table.datos tbody tr:hover td { background: #eef4fa; }
.hoja-informe table.datos tfoot td,
.hoja-informe table.datos tr.fila-total td {
  font-weight: 700;
  background: #eaf1f8 !important;
  border-top: 2px solid #16324f;
  color: #16324f;
}
.hoja-informe .resumen-final { margin: 18px 0 24px; }
.hoja-informe .resumen-final .bloque { border-radius: 5px; }
.hoja-informe h2 {
  font-size: 1.05em;
  color: #16324f;
  border-left: 4px solid var(--azul);
  padding-left: 10px;
  margin: 28px 0 12px;
}
.hoja-informe h2:first-of-type { margin-top: 6px; }

@media (max-width: 700px) {
  .informe-titulo-bloque { text-align: left; }
  .hoja-informe { padding: 20px; }
}
@media print {
  @page { margin: 14mm; }
  .hoja-informe {
    box-shadow: none;
    border: none;
    padding: 0;
    max-width: 100%;
    margin: 0;
  }
  .hoja-informe table.datos thead { display: table-header-group; }
  .hoja-informe table.datos tr { page-break-inside: avoid; }
  .informe-letterhead { margin-top: 0; }
}

/* --- Galería de avatares estándar --- */
.galeria-avatares {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}
.avatar-preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 84px;
  padding: 8px 4px;
  background: #f8f9fb;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.7em;
  color: #555;
  text-align: center;
}
.avatar-preset-btn:hover { background: #eef3f8; }
.avatar-preset-btn.seleccionado {
  border-color: var(--azul);
  background: var(--azul-claro);
  color: var(--azul);
  font-weight: 600;
}
.avatar-preset-btn img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

/* --- Accesibilidad: tamaño de letra --- */
body.fuente-grande { font-size: 18px; }
body.fuente-muy-grande { font-size: 21px; }

/* ---------- IMPRESIÓN ---------- */
.print-solo-texto { display: none; }
@media print {
  header.topbar, .sidebar, .sidebar-backdrop, .sidebar-toggle, .no-print, footer.pie { display: none !important; }
  .print-solo-texto { display: inline !important; }
  .print-only { display: inline; }
  body { background: white; font-size: 12px; }
  .card { border: none; padding: 0; }
  table.datos, table.datos thead, table.datos tbody, table.datos th, table.datos td, table.datos tr {
    display: revert;
  }
  table.datos td::before { content: none; }
  table.datos td { text-align: left; }
  a { color: black; text-decoration: none; }
}
