:root {
  --azul: #2952e3;
  --azul-oscuro: #1c3aa8;
  --gris: #f4f5f7;
  --gris-borde: #dde1e8;
  --texto: #1f2430;
  --verde: #1a8f5e;
  --rojo: #c0392b;
  --naranja: #b8720b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  color: var(--texto);
  background: var(--gris);
}
a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #14162b;
  color: #fff;
  padding: 20px 0;
  flex-shrink: 0;
}
.sidebar .logo { font-weight: 700; font-size: 1.2rem; padding: 0 20px 20px; }
.sidebar a {
  display: block;
  color: #cfd3e6;
  padding: 10px 20px;
}
.sidebar a:hover, .sidebar a.activo { background: #23264a; color: #fff; text-decoration: none; }
.sidebar .separador { border-top: 1px solid #2a2d54; margin: 12px 0; }
.sidebar .empresa-actual { padding: 0 20px 16px; font-size: .85rem; color: #9aa1c9; }

.contenido { flex: 1; padding: 28px 36px; max-width: 1100px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.topbar h1 { margin: 0; font-size: 1.5rem; }

.card {
  background: #fff;
  border: 1px solid var(--gris-borde);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: #fff; border: 1px solid var(--gris-borde); border-radius: 10px; padding: 18px; }
.stat .valor { font-size: 1.6rem; font-weight: 700; }
.stat .etiqueta { color: #666; font-size: .85rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--gris-borde); font-size: .92rem; }
th { color: #666; font-weight: 600; font-size: .8rem; text-transform: uppercase; }
tr:hover td { background: #fafbff; }

.btn {
  display: inline-block;
  background: var(--azul);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9rem;
}
.btn:hover { background: var(--azul-oscuro); text-decoration: none; color: #fff; }
.btn.secundario { background: #fff; color: var(--texto); border: 1px solid var(--gris-borde); }
.btn.peligro { background: var(--rojo); }
.btn.pequeno { padding: 5px 10px; font-size: .8rem; }

form .campo { margin-bottom: 14px; }
label { display: block; margin-bottom: 5px; font-size: .88rem; font-weight: 600; }
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--gris-borde);
  border-radius: 6px;
  font-size: .92rem;
  font-family: inherit;
}
.fila { display: flex; gap: 14px; }
.fila .campo { flex: 1; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge.borrador { background: #eee; color: #555; }
.badge.enviada { background: #fff3cd; color: var(--naranja); }
.badge.pagada { background: #d7f5e5; color: var(--verde); }
.badge.cliente { background: #e3ecff; color: var(--azul); }
.badge.proveedor { background: #fde3e3; color: var(--rojo); }
.badge.conciliado { background: #d7f5e5; color: var(--verde); }
.badge.pendiente { background: #fde3e3; color: var(--rojo); }

.alerta { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: .9rem; }
.alerta.success { background: #d7f5e5; color: var(--verde); }
.alerta.error { background: #fde3e3; color: var(--rojo); }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--gris); }
.login-box { background: #fff; padding: 36px; border-radius: 12px; width: 340px; border: 1px solid var(--gris-borde); }
.login-box h1 { font-size: 1.3rem; margin-top: 0; }

.vacio { color: #888; padding: 30px 0; text-align: center; }
.ayuda { color: #777; font-size: .82rem; margin-top: 4px; }

@media print {
  .sidebar, .topbar .acciones, .no-imprimir { display: none !important; }
  .layout { display: block; }
  .contenido { padding: 0; max-width: none; }
}

/* Biblioteca y buzón */
.badge-buzon {
  background: #e53935; color: #fff; border-radius: 10px;
  padding: 1px 8px; font-size: 12px; margin-left: 6px;
}
.notificacion {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.notificacion.sin-leer { border-left: 4px solid #e53935; }
.badge {
  background: #e53935; color: #fff; border-radius: 4px;
  padding: 1px 6px; font-size: 11px; margin-right: 6px;
}
.fecha-notif { color: #888; font-size: 12px; margin-top: 4px; }

/* Ficha de acceso */
.ficha-acceso { max-width: 600px; }
.tabla-ficha th { text-align: left; padding: 8px 16px 8px 0; white-space: nowrap; }
.tabla-ficha td { padding: 8px 0; }
.password-grande { font-size: 20px; font-family: monospace; letter-spacing: 1px; }
.nota-ficha { color: #666; font-size: 13px; margin-top: 16px; }
@media print {
  .no-imprimir, .sidebar { display: none !important; }
  .contenido { margin: 0 !important; }
}

/* Pantallas pequeñas (móvil) */
/* ---------- Botón de menú (solo móvil) ---------- */
.menu-movil {
  display: none;
  position: sticky; top: 0; z-index: 900;
  width: 100%; border: none; cursor: pointer;
  background: #23264a; color: #fff;
  /* Deja hueco arriba para la barra de estado del iPhone (notch/isla) */
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 16px;
  font-size: 17px; font-weight: 600; min-height: 56px;
  text-align: left; align-items: center; gap: 10px;
  box-sizing: border-box;
}
.menu-movil.modo-cliente { background: #14532d; }

/* ---------- Pantallas de móvil (vertical) ---------- */
@media (max-width: 768px) {
  .menu-movil { display: flex; }

  .layout { flex-direction: column; }

  /* Menú lateral: oculto por defecto, se abre con el botón */
  .sidebar {
    width: 100%; min-height: auto; padding: 8px 0 14px;
    display: none; box-sizing: border-box;
  }
  /* Menú abierto: panel corto y con scroll propio, para poder tocar las opciones */
  .sidebar.abierta {
    display: block;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    border-bottom: 3px solid rgba(255,255,255,.15);
  }
  /* En móvil los grupos empiezan cerrados: el menú cabe en pantalla */
  .sidebar details.grupo:not([open]) > *:not(summary) { display: none; }
  .sidebar .logo { padding: 10px 18px; font-size: 1.05rem; }
  .sidebar .empresa-actual { padding: 0 18px 12px; }
  .sidebar a, .sidebar details.grupo summary {
    padding: 13px 18px; font-size: 1rem;      /* dedos, no ratón */
  }
  .sidebar details.grupo a { padding-left: 34px; }

  .contenido { padding: 14px 12px 80px; max-width: 100%; }

  /* Cabeceras: título arriba, botones debajo */
  .topbar, .cabecera-pagina {
    flex-direction: column; align-items: stretch; gap: 10px;
  }
  .topbar h1, .cabecera-pagina h1 { font-size: 1.4rem; margin: 0; }
  .acciones { display: flex; flex-wrap: wrap; gap: 8px; }

  /* Formularios: cada campo en su línea */
  .fila { flex-direction: column; gap: 0; }
  .fila .campo { width: 100%; }
  .campo { margin-bottom: 14px; }

  /* Evita que el iPhone haga zoom al tocar un campo (necesita 16px) */
  input, select, textarea { font-size: 16px !important; width: 100%; box-sizing: border-box; }

  /* Botones cómodos de pulsar */
  .btn, .boton, button[type="submit"] {
    min-height: 46px; display: inline-flex; align-items: center; justify-content: center;
  }
  .btn.pequeno, .boton.pequeno { min-height: 38px; }

  /* Tablas anchas: se deslizan en horizontal sin romper la página */
  table {
    display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
    white-space: nowrap; width: 100%;
  }
  th, td { padding: 10px 10px; }
  .tabla-ficha, .tabla-borrador { white-space: normal; }

  /* Tarjetas y paneles a una columna */
  .card, .tarjeta { padding: 14px; margin-bottom: 14px; }
  .fila-paneles { flex-direction: column; }
  .fila-paneles .card { flex: 1 1 auto; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px; }
  .stat .valor { font-size: 1.2rem; }
  .stat .etiqueta { font-size: .75rem; }
  .resumen-impuestos { flex-direction: column; }
  .rejilla-importes { grid-template-columns: repeat(2, 1fr); }

  /* Banda de "estás viendo la empresa" */
  .banda-cliente { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* Gráfica del panel */
  .grafica-barras { height: 150px; gap: 8px; }
  .barra { width: 12px; }
  .mes-etiqueta { font-size: .7rem; }

  /* El botón flotante de instalar no tapa el contenido */
  #btn-instalar { bottom: 12px; right: 12px; padding: 10px 16px; font-size: 14px; }
}

/* Móviles estrechos */
@media (max-width: 400px) {
  .grid-stats { grid-template-columns: 1fr; }
  .rejilla-importes { grid-template-columns: 1fr; }
  .contenido { padding: 12px 10px 80px; }
}

/* Etiqueta de categoría en la biblioteca */
.etiqueta-cat {
  background: #eef3f8; color: #345; border: 1px solid #cdd9e5;
  border-radius: 4px; padding: 1px 8px; font-size: 12px; white-space: nowrap;
}

/* Grupos desplegables del menú */
.sidebar details.grupo { margin: 2px 0; }
.sidebar details.grupo summary {
  cursor: pointer; list-style: none; padding: 10px 20px;
  color: #cfd3f1; font-weight: 600; font-size: .95rem; user-select: none;
}
.sidebar details.grupo summary::before { content: "▸ "; font-size: .8em; }
.sidebar details.grupo[open] summary::before { content: "▾ "; }
.sidebar details.grupo summary:hover { background: #23264a; }
.sidebar details.grupo a { padding-left: 38px; font-size: .92rem; }

/* Modo cliente: cuando el admin está dentro de una empresa */
.sidebar.modo-cliente { background: #14532d; }
.sidebar.modo-cliente a:hover, .sidebar.modo-cliente a.activo,
.sidebar.modo-cliente details.grupo summary:hover { background: #1c6b3c; }
.sidebar.modo-cliente .separador { border-top-color: #1c6b3c; }
.sidebar.modo-cliente .empresa-actual { color: #b7e4c7; }
.banda-cliente {
  background: #d1fae5; border: 1px solid #6ee7b7; color: #065f46;
  padding: 10px 16px; border-radius: 6px; margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.banda-cliente a { color: #065f46; font-weight: 600; }

/* Panel de impuestos y gráfica del dashboard */
.fila-paneles { display: flex; gap: 16px; flex-wrap: wrap; align-items: stretch; }
.fila-paneles .card { flex: 1 1 380px; margin-bottom: 16px; }

.proximo-plazo { border: 1px solid #e3e7ef; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.plazo-titulo { font-size: 1.02rem; }
.plazo-fecha { color: #52514e; font-size: .9rem; margin: 2px 0 8px; }
.tabla-borrador { width: 100%; margin-bottom: 10px; }
.tabla-borrador td { padding: 3px 0; }
.tabla-borrador .importe { text-align: right; font-weight: 600; }

.resumen-impuestos { display: flex; gap: 12px; margin-bottom: 12px; }
.mini-stat { flex: 1; background: #f6f8fb; border-radius: 8px; padding: 10px 12px; text-align: center; }
.mini-stat .valor { font-size: 1.35rem; font-weight: 700; }
.mini-stat .etiqueta { font-size: .8rem; color: #52514e; }

.chips-trimestres { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid #cdd9e5; border-radius: 999px; padding: 4px 12px;
  font-size: .85rem; color: #52514e; text-decoration: none; background: #fff;
}
.chip.con-docs { border-color: #2a78d6; color: #0b0b0b; }
.chip:hover { background: #eef3f8; text-decoration: none; }

.leyenda { font-size: .85rem; color: #52514e; margin-bottom: 10px; }
.leyenda .muestra {
  display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  vertical-align: -1px; margin: 0 4px 0 10px;
}
.leyenda .muestra:first-child { margin-left: 0; }
.muestra.ingresos, .barra.ingresos { background: #2a78d6; }
.muestra.gastos, .barra.gastos { background: #1baf7a; }

.grafica-barras {
  display: flex; align-items: flex-end; gap: 14px;
  height: 180px; padding: 8px 4px 0;
  border-bottom: 1px solid #e3e7ef;
}
.grupo-mes { flex: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; }
.grupo-mes .barras {
  flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px;
}
.barra {
  width: 18px; min-height: 2px;
  border-radius: 4px 4px 0 0;
  transition: opacity .15s;
}
.barra:hover { opacity: .75; }
.mes-etiqueta { text-align: center; font-size: .78rem; color: #52514e; padding-top: 6px; }

.tabla-datos-grafica { margin-top: 12px; font-size: .85rem; }
.tabla-datos-grafica th, .tabla-datos-grafica td { padding: 3px 10px 3px 0; text-align: right; }
.tabla-datos-grafica th:first-child, .tabla-datos-grafica td:first-child { text-align: left; }

/* Estados de pago de los impresos */
.estado-pago {
  border-radius: 4px; padding: 2px 8px; font-size: .8rem; white-space: nowrap;
  background: #eef1f5; color: #444;
}
.estado-pago.ingresado { background: #d9ecdb; color: #1d5a24; }
.estado-pago.domiciliado { background: #dbe7f6; color: #1c4c86; }
.estado-pago.negativa { background: #eef1f5; color: #555; }
.estado-pago.devolver { background: #fdf3d7; color: #7a5a00; }
.estado-pago.desconocido { background: #f8dede; color: #8a2323; }
.total-trimestre { float: right; font-size: .95rem; color: #345; }

/* Subida y revisión de facturas contables */
.tipo-selector { display: flex; flex-direction: column; gap: 8px; }
.tipo-opcion {
  border: 1px solid #cdd9e5; border-radius: 8px; padding: 12px 14px;
  cursor: pointer; font-size: 1rem;
}
.tipo-opcion:hover { background: #eef3f8; }
.rejilla-importes {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; margin-bottom: 8px;
}
.grupo-avanzado { margin-top: 14px; border-top: 1px solid #e3e7ef; padding-top: 10px; }
.grupo-avanzado summary { cursor: pointer; font-weight: 600; color: #345; }

/* Lista de alertas de inteligencia de datos */
.lista-alertas { list-style: none; padding: 0; margin: 0 0 12px; }
.lista-alertas li { padding: 6px 0; border-bottom: 1px solid #eef1f5; font-size: .92rem; }
.lista-alertas li:last-child { border-bottom: none; }

/* Pasos de la ficha de acceso imprimible */
.pasos-acceso { margin: 6px 0 14px; padding-left: 22px; line-height: 1.6; }
.pasos-acceso li { margin-bottom: 5px; }
.ficha-acceso h2 { border-bottom: 1px solid #ddd; padding-bottom: 4px; }
.ficha-acceso h3 { margin-top: 16px; font-size: 1rem; }

/* Avisos del vigilante de facturas */
.avisos-vigilante { list-style: none; padding: 0; margin: 6px 0 0; font-size: .8rem; }
.avisos-vigilante li { padding: 2px 0; white-space: normal; }
.aviso-alto { color: #a11; font-weight: 600; }
.aviso-medio { color: #8a5a00; }
.aviso-bajo { color: #666; }

/* Interruptor tipo "switch" (avisos push) */
.interruptor-fila {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 0; flex-wrap: wrap;
}
.interruptor-texto { flex: 1; min-width: 200px; }
.interruptor-estado { font-weight: 600; font-size: .9rem; }
.interruptor-estado.on { color: #1a8f5e; }
.interruptor-estado.off { color: #888; }

.interruptor { position: relative; display: inline-block; width: 62px; height: 34px; flex-shrink: 0; }
.interruptor input { opacity: 0; width: 0; height: 0; }
.interruptor .palanca {
  position: absolute; cursor: pointer; inset: 0;
  background-color: #c8ccd4; transition: background-color .25s; border-radius: 34px;
}
.interruptor .palanca:before {
  position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px;
  background-color: #fff; transition: transform .25s; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.interruptor input:checked + .palanca { background-color: #1a8f5e; }
.interruptor input:checked + .palanca:before { transform: translateX(28px); }
.interruptor input:disabled + .palanca { opacity: .55; cursor: wait; }

/* Visor de facturas */
.visor-documento { text-align: center; }
.imagen-factura {
  max-width: 100%; height: auto; border: 1px solid var(--gris-borde);
  border-radius: 6px; background: #fff;
}
