@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

:root {
  --azul: #0066dd;
  --azul-h: #0050bb;
  --verde: #28a745;
  --verde-h: #1e7e34;
  --gris-bg: #f5f5f5;
  --card: #ffffff;
  --texto: #1c2533;
  --muted: #6b7280;
  --border: #e3e8ef;
  --error: #c0392b;
  --ok: #1e8449;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Roboto', -apple-system, Segoe UI, sans-serif;
  background-color: var(--gris-bg);
  color: var(--texto);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
}
a { color: var(--azul); text-decoration: none; }

/* --- Logo --- */
.logo-img { max-width: 300px; width: 100%; height: auto; margin: 0 auto 20px; display: block; }

/* --- Botones de menú --- */
.menu-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 8px; }
.menu-button {
  background-color: var(--azul); color: #fff; border: none; padding: 10px 18px;
  border-radius: 6px; font-size: 16px; font-weight: 700; cursor: pointer; transition: background-color .3s;
}
.menu-button:hover { background-color: var(--azul-h); text-decoration: none; color: #fff; }
.menu-button.on { background-color: var(--azul-h); }

.cliente-nombre { text-align: center; font-weight: 700; margin: 14px 0 6px; font-size: 1.1rem; }

.volver { display: inline-block; background: #9aa0a6; color: #fff; border: none; border-radius: 8px;
  padding: 10px 18px; font-weight: 700; margin: 6px auto 4px; }
.volver:hover { background: #808589; color: #fff; text-decoration: none; }
.centro { text-align: center; }

/* --- Contenedor y tarjetas --- */
.contenido { width: 100%; max-width: 960px; margin: 0 auto; }
.resumen-container { display: flex; flex-direction: column; align-items: center; gap: 20px; margin-top: 16px; width: 100%; }
.resumen-card, .card {
  background: var(--card); width: 100%; max-width: 760px; padding: 20px; border-radius: 12px;
  box-shadow: 0 3px 12px rgba(0,0,0,.08); margin: 0 auto;
}
.resumen-title { font-weight: 700; font-size: 18px; margin-bottom: 10px; }
.resumen-detalle { margin-left: 8px; margin-bottom: 12px; color: #444; }
.resumen-detalle .linea { margin: 6px 0; }
.boton-cupon { background-color: var(--azul); color: #fff; font-weight: 700; border: none; border-radius: 6px; padding: 10px 20px; cursor: pointer; margin-top: 12px; display: inline-block; }
.boton-cupon:hover { background-color: var(--azul-h); color: #fff; text-decoration: none; }
.boton-expensas { background-color: var(--verde); color: #fff; font-weight: 700; border: none; border-radius: 6px; padding: 10px 20px; cursor: pointer; margin-top: 12px; display: inline-block; }
.boton-expensas:hover { background-color: var(--verde-h); color: #fff; text-decoration: none; }
.boton-vencido { background-color: #9aa0a6; cursor: default; }
.boton-vencido:hover { background-color: #9aa0a6; }
.muted { color: var(--muted); }
.vacio { color: var(--muted); text-align: center; }

/* --- Sección estándar (título centrado con línea) --- */
.seccion { max-width: 760px; margin: 16px auto; background: var(--card); padding: 1rem 1.2rem; border-radius: 12px; box-shadow: 0 3px 12px rgba(0,0,0,.06); }
.seccion-titulo { font-weight: 700; font-size: 1.2rem; margin-bottom: 1rem; border-bottom: 1px solid #ccc; padding-bottom: .5rem; text-align: center; }

/* --- Combos de filtro --- */
.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: center; margin-bottom: 12px; }
.filtros label { font-weight: 600; font-size: .9rem; display: flex; gap: 6px; align-items: center; }
.filtros select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; background: #fff; }

/* --- Tablas --- */
.tabla { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabla th, .tabla td { padding: 9px 8px; border-top: 1px solid #e5e7eb; text-align: left; }
.tabla thead th { background: #f0f0f0; border-top: none; font-weight: 700; }
.tabla td.num, .tabla th.num { text-align: right; white-space: nowrap; }
.tabla td.centro, .tabla th.centro { text-align: center; }
.icono { width: 26px; height: 26px; vertical-align: middle; }
.aviso-rojo { color: var(--error); font-weight: 700; margin: 6px 0 12px; }

/* --- Subida de archivos (impuestos) --- */
.subir-label { display: inline-block; width: 28px; height: 28px; position: relative; cursor: pointer; }
.subir-label input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.estado { font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.estado-INI { background: #fff4e0; color: #b8770a; }
.estado-APR { background: #e8f6ee; color: var(--ok); }
.estado-REC { background: #fdecea; color: var(--error); }

/* Botón "Informar Pago" y tacho en la grilla de impuestos */
.btn-informar { background: var(--primario, #0066dd); color: #fff; border: none; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 700; font-size: .82rem; }
.btn-tacho { border: none; background: none; cursor: pointer; margin-left: 6px; padding: 2px; vertical-align: middle; }
.btn-tacho img { width: 20px; height: 20px; vertical-align: middle; }

/* Modal "Informar Pago de Impuestos/Servicios" (adaptable a móvil) */
.dlg-imp { border: none; border-radius: 12px; padding: 20px; width: min(440px, 94vw); max-width: 94vw; box-sizing: border-box; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dlg-imp::backdrop { background: rgba(0,0,0,.5); }
.dlg-imp h3 { margin: 0 0 14px; color: #0a3d62; font-size: 1.05rem; }
.dlg-imp label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-weight: 600; font-size: .9rem; color: #374151; }
.dlg-imp input[type=file] { font-size: .9rem; }
.leyenda-roja { color: #b91c1c; font-size: .82rem; margin: 6px 0 14px; line-height: 1.35; }
.dlg-acciones { display: flex; gap: 8px; justify-content: flex-end; }
.dlg-acciones button { padding: 9px 16px; border: none; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: .9rem; }
.dlg-acciones button[type=submit] { background: var(--primario, #0066dd); color: #fff; }
.dlg-acciones button[type=submit]:disabled { background: #9aa0a6; cursor: not-allowed; }
.dlg-acciones button[type=button] { background: #e5e7eb; color: #374151; }

/* --- Login --- */
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: #fff; border-radius: 12px; box-shadow: 0 5px 20px rgba(0,0,0,.1); padding: 30px; max-width: 400px; width: 100%; text-align: center; }
.login-logo { max-height: 90px; margin-bottom: 16px; }
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 22px; color: #111; line-height: 1.4; }
.form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.form input, .form select { padding: 11px 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; }
.btn-primario { background-color: #1d4ed8; color: #fff; border: none; width: 100%; padding: 12px; font-weight: 700; border-radius: 6px; cursor: pointer; }
.btn-primario:hover { background-color: #1538b2; }
.opcion { flex-direction: row; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.opcion input { width: auto; }
.links { margin-top: 16px; font-size: .9rem; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ayuda { font-size: .9rem; color: var(--muted); margin-bottom: 14px; }
.msg-error { background: #fdecea; color: var(--error); padding: 10px; border-radius: 10px; font-size: .9rem; }
.msg-ok { background: #e8f6ee; color: var(--ok); padding: 10px; border-radius: 10px; font-size: .9rem; }
.pie { text-align: center; padding: 14px; color: var(--muted); font-size: .8rem; }

/* --- Splash --- */
#splash-screen { position: fixed; inset: 0; background: #fff; display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 99999; }
#splash-screen img { width: 140px; animation: fadeInScale 1.2s ease-in-out; }
.splash-spinner { margin-top: 20px; width: 40px; height: 40px; border: 4px solid #ccc; border-top-color: var(--azul); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes fadeInScale { 0% { opacity: 0; transform: scale(.8);} 100% { opacity: 1; transform: scale(1);} }
@keyframes spin { to { transform: rotate(360deg);} }

/* --- Banner de instalación PWA --- */
.install-banner { display: none; position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background-color: var(--azul); color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); z-index: 9999; max-width: 90%; text-align: center; }
.install-banner button { margin-left: 12px; padding: 6px 14px; border: none; border-radius: 6px; background: #fff; color: var(--azul); font-weight: 700; cursor: pointer; }
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 20px);} to { opacity: 1; transform: translate(-50%, 0);} }
@keyframes desaparecer { from { opacity: 1;} to { opacity: 0;} }

/* --- Datos importantes (tarjeta) --- */
.datos-imp { margin: 10px 0; background: #f0f6ff; border: 1px solid #d6e4ff; border-radius: 10px; padding: 10px 12px; }
.datos-imp-tit { font-weight: 700; font-size: .82rem; color: #0a3d62; margin-bottom: 4px; }
.datos-imp-txt { font-size: .9rem; white-space: pre-line; }

@media (max-width: 768px) {
  body { padding: 12px; }
  .menu-buttons { flex-direction: column; gap: 10px; }
  .menu-button, .boton-cupon, .boton-expensas { width: 100%; }
  .tabla { font-size: .88rem; }
  .filtros { flex-direction: column; align-items: stretch; }
  .filtros label { flex-direction: column; align-items: stretch; }
}

/* ===========================================================================
   PANEL ADMIN — sidebar izquierdo + navbar flotante + tema naranja (look viejo)
   =========================================================================== */
:root { --naranja: #f97316; --naranja-h: #ea580c; --peach: #fdf1ea; }
body:has(.admin-sidebar) { display: block; align-items: initial; padding: 0; background: #f3f4f6; font-family: 'Roboto', sans-serif; }

/* Sidebar */
.admin-sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 240px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.06); overflow-y: auto; z-index: 40; }
.admin-sidebar .marca { display: flex; flex-direction: column; align-items: center; padding: 24px 12px 8px; }
.admin-sidebar .marca img { width: 150px; height: auto; }
.admin-sidebar .marca .menu-txt { font-weight: 600; margin: 8px 0 4px; }
.admin-nav-list { list-style: none; padding: 8px 0; margin: 0; }
.admin-nav-list a { display: flex; align-items: center; gap: 12px; padding: 11px 18px; color: #0a3d62; font-size: .95rem; }
.admin-nav-list a:hover { background: #f3f4f6; text-decoration: none; }
.admin-nav-list a.on { background: var(--peach); color: var(--naranja-h); font-weight: 600; }
.admin-nav-list a svg { width: 20px; height: 20px; flex-shrink: 0; fill: currentColor; }
.admin-sidebar .hamburguesa { background: none; border: 0; color: #0a3d62; cursor: pointer; padding: 6px; margin-top: 4px; border-radius: 8px; line-height: 0; }
.admin-sidebar .hamburguesa:hover { background: #f3f4f6; }

/* Estado colapsado (persistido en localStorage, toggle con la hamburguesa) */
body.sidebar-colapsada .admin-sidebar { width: 64px; }
body.sidebar-colapsada .admin-sidebar .marca img { width: 40px; }
body.sidebar-colapsada .admin-sidebar .marca .menu-txt,
body.sidebar-colapsada .admin-nav-list a span { display: none; }
body.sidebar-colapsada .admin-nav-list a { justify-content: center; padding: 12px 0; }
body.sidebar-colapsada .admin-navbar { left: 88px; }
body.sidebar-colapsada .admin-main { margin-left: 88px; }

/* Herramientas: botón destructivo + caja de resultado */
.btn-peligro { background: #dc2626 !important; }
.btn-peligro:hover { background: #b91c1c !important; }
.result-box { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: #f3f4f6;
  border: 1px solid #e5e7eb; font-size: .9rem; color: #374151; }
.result-box.done { background: #ecfdf5; border-color: #a7f3d0; }

/* Slots de logos en el form de empresa */
/* Formularios largos en columnas: entra todo sin scrollear. */
.modal-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 0 28px; }
.modal-cols > * { min-width: 0; }
.modal-cols > div > h4:first-child { margin-top: 0; }

.logos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.logos-grid > * { min-width: 0; }
.logo-slot { border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.logo-slot .logo-tit { font-weight: 600; font-size: .85rem; color: #0a3d62; }
.logo-slot .logo-pv { max-width: 100%; max-height: 64px; object-fit: contain; align-self: flex-start; background: #f9fafb; border-radius: 6px; }
.logo-slot small { color: #6b7280; font-size: .75rem; }
.logo-slot input[type=file] { font-size: .8rem; }
@media (max-width: 700px) { .logos-grid { grid-template-columns: 1fr; } }

/* Celda de impuestos (ojo + radios A/R) */
.imp-cell { display: inline-flex; align-items: center; gap: 10px; }
.imp-cell .ojo { color: #0a3d62; line-height: 0; }
.imp-cell .ojo:hover { color: var(--naranja-h); }
.imp-radios { display: inline-flex; gap: 8px; margin: 0; }
.imp-radios .rlbl { font-size: .85rem; color: #374151; display: inline-flex; align-items: center; gap: 3px; cursor: pointer; }

/* Navbar flotante */
.admin-navbar { position: fixed; top: 20px; right: 24px; left: 264px; z-index: 30; background: rgba(255,255,255,.97); border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.admin-navbar .inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; }
.admin-navbar .titulo { font-weight: 600; }

/* Main */
.admin-main { margin-left: 264px; padding: 100px 28px 40px; }
.admin-main h1 { font-size: 1.6rem; margin: 0 0 16px; color: #0a3d62; }

/* Botones naranja */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 8px; background: var(--naranja); color: #fff; border: none; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--naranja-h); color: #fff; text-decoration: none; }

/* Toolbar de filtros */
.adm-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.adm-toolbar input, .adm-toolbar select { padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: .95rem; background: #fff; }
.adm-toolbar input:focus, .adm-toolbar select:focus { outline: none; border-color: var(--naranja); box-shadow: 0 0 0 3px #fbe3d4; }
.adm-toolbar .crece { flex: 1; min-width: 200px; }

/* Tabla admin */
.adm-table { width: 100%; border-collapse: collapse; background: #fff; }
.adm-table thead th { background: var(--peach); padding: 12px 10px; text-align: left; font-weight: 600; color: #374151; border-bottom: 1px solid #eee; }
.adm-table tbody td { padding: 12px 10px; border-bottom: 1px solid #eef0f2; }
.adm-table tbody tr:hover { background: #fafafa; }
.adm-table .acc { display: flex; gap: 12px; align-items: center; }
.adm-table .acc img { width: 22px; height: 22px; cursor: pointer; }
/* Botón-ícono de acción (mismo look que las imágenes de Personas) */
.icono-btn { border: none; background: none; cursor: pointer; padding: 0; display: inline-flex; }
.acc .icono-btn img, .acc img.icono-accion { width: 22px; height: 22px; cursor: pointer; }

/* Tabla con scroll interno y encabezado fijo (sticky). El alto se limita para
   que SIEMPRE quede visible la barra de paginación debajo. */
.tabla-scroll { max-height: calc(100vh - 300px); min-height: 200px; overflow: auto; }
.tabla-scroll .adm-table thead th { position: sticky; top: 0; z-index: 3; }
/* Encabezados ordenables */
.adm-table thead th a.th-sort { color: inherit; text-decoration: none; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.adm-table thead th a.th-sort:hover { text-decoration: underline; }
.adm-table thead th a.th-sort .arr { font-size: .7em; opacity: .8; }

/* Paginación */
.paginacion { display: flex; gap: 6px; align-items: center; justify-content: center; margin: 14px 0; flex-wrap: wrap; }
.paginacion a, .paginacion span { padding: 6px 10px; border-radius: 8px; border: 1px solid #d1d5db; color: #374151; text-decoration: none; font-size: .85rem; }
.paginacion a:hover { background: #f3f4f6; }
.paginacion .on { background: var(--naranja); color: #fff; border-color: var(--naranja); }
.paginacion .disabled { opacity: .45; pointer-events: none; }
.paginacion .info { border: none; color: #6b7280; }

/* Autocompletar (sugerencias de persona en alta de usuario) */
.sug-box { border: 1px solid #d1d5db; border-radius: 8px; margin-top: 3px; max-height: 220px; overflow: auto; background: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.sug-box .it { padding: 8px 10px; cursor: pointer; font-size: .88rem; border-bottom: 1px solid #f0f0f0; }
.sug-box .it:last-child { border-bottom: none; }
.sug-box .it:hover { background: #f3f4f6; }
.sug-box .it small { color: #6b7280; }
.adm-chip { padding: 6px 12px; border-radius: 20px; border: 1px solid #d1d5db; background: #fff; font-weight: 600; font-size: .85rem; color: var(--muted); }
.adm-chip.on { background: var(--naranja); color: #fff; border-color: var(--naranja); }
.adm-card { background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.06); padding: 16px 18px; margin-bottom: 16px; }
.adm-tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.adm-tarjeta { background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.06); padding: 22px; font-weight: 600; color: #0a3d62; text-align: center; }

/* utilidades reusadas por partial-imp-cell */
.btn-mini { display: inline-block; background: var(--naranja); color: #fff; border: none; border-radius: 8px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; }
.btn-ok { background: var(--ok); } .btn-no { background: var(--error); }
.inline-form { display: inline; }
.acciones { display: flex; gap: 6px; white-space: nowrap; }

/* Modales admin */
dialog { border: none; border-radius: 12px; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
  width: min(560px, 94vw); max-width: 94vw; max-height: 92vh; box-sizing: border-box;
  overflow-x: hidden; overflow-y: auto; }
/* Variante ancha para formularios largos (empresa, perfil). */
dialog.ancho { width: min(1020px, 95vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 14px; color: #0a3d62; }
dialog h4 { margin: 16px 0 8px; color: #0a3d62; font-size: .95rem;
  border-bottom: 1px solid #e5e7eb; padding-bottom: 5px; }
.modal-form { min-width: 0; }
.modal-form label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: .88rem; color: #374151; min-width: 0; }
.modal-form input, .modal-form select { padding: 9px 10px; border: 1px solid #d1d5db; border-radius: 8px;
  font-size: .95rem; width: 100%; box-sizing: border-box; min-width: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px;
  position: sticky; bottom: -22px; background: #fff; padding: 12px 0 0; border-top: 1px solid #e5e7eb; }
.btn-cancel { background: #e5e7eb; color: #374151; border: none; border-radius: 8px; padding: 10px 16px; font-weight: 600; cursor: pointer; }
/* Se adapta al ancho disponible: sin barras horizontales. */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 14px; }
.form-grid > * { min-width: 0; }
.form-grid .full { grid-column: 1 / -1; }
/* Checkbox y texto en la MISMA linea (hay que resetear el column que hereda
   de .modal-form label, que tiene la misma especificidad). */
.flags { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 8px 0; }
.flags label { display: flex; flex-direction: row; align-items: center; gap: 6px;
  font-size: .9rem; margin-bottom: 0; white-space: nowrap; }
.flags label input[type=checkbox] { width: auto; margin: 0; }

@media (max-width: 900px) {
  .admin-sidebar { width: 64px; }
  .admin-sidebar .marca img { width: 40px; } .admin-sidebar .marca .menu-txt { display: none; }
  .admin-nav-list a span { display: none; }
  .admin-navbar { left: 88px; } .admin-main { margin-left: 88px; }
}
