:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1c2129;
  --text-muted: #667085;
  --accent: #2f5ce0;
  --accent-soft: #eaefff;
  --danger-bg: #fdecec;
  --danger-text: #9a1c1c;
  --radius: 14px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0.5px;
}

.brand h1 { font-size: 18px; margin: 0; }
.brand p { font-size: 12.5px; color: var(--text-muted); margin: 2px 0 0; }

main.vista {
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px;
}

.lead { color: var(--text-muted); font-size: 14px; margin: 0 0 20px; }
.muted { color: var(--text-muted); font-size: 13.5px; }

.grid-grupos, .grid-reportes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
  text-align: left;
}

.card:hover {
  box-shadow: 0 6px 18px rgba(20, 25, 40, 0.08);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.card .icono { font-size: 28px; margin-bottom: 10px; display: block; }
.card h3 { margin: 0 0 6px; font-size: 15.5px; }
.card p { margin: 0; font-size: 13px; color: var(--text-muted); line-height: 1.45; }
.card .cuenta { font-size: 12px; color: var(--accent); margin-top: 10px; font-weight: 600; }

.btn-ghost {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  padding: 6px 0;
  font-weight: 600;
}
.btn-ghost:hover { text-decoration: underline; }

.form-parametros {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-end;
  margin-top: 6px;
}

.campo { display: flex; flex-direction: column; gap: 6px; min-width: 170px; }
.campo label { font-size: 13px; font-weight: 600; color: var(--text); }
.campo input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
}
.campo input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.btn-primario {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primario:hover { filter: brightness(1.08); }
.btn-primario:disabled { opacity: .55; cursor: default; }

.btn-secundario {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secundario:hover { filter: brightness(0.97); }

.error-msg {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}

#panel-ejecucion, #panel-resultado { margin-top: 24px; }

.log {
  background: #10131a;
  color: #d7ffe0;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  padding: 16px;
  border-radius: 10px;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.resultado-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.resultado-botones { display: flex; gap: 10px; }

.tabla-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 12px;
}

table#tabla-resultado {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  background: var(--surface);
}

table#tabla-resultado th {
  background: #1f3864;
  color: white;
  text-align: left;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  white-space: nowrap;
}

table#tabla-resultado td {
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  white-space: nowrap;
}

table#tabla-resultado tr:nth-child(even) td { background: #fdf5f5; }

::selection { background: #cfe0ff; }

/* ── Multiempresa ─────────────────────────────────────────────────────────── */
.topbar-der { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.selector-empresa { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.selector-empresa select, .campo select {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 14px; font-family: inherit; background: var(--surface); max-width: 340px;
}

.card-off { cursor: default; opacity: .6; background: #f2f3f5; }
.card-off:hover { box-shadow: none; transform: none; border-color: var(--border); }
.card .motivo { font-size: 12px; color: var(--text-muted); margin-top: 10px; font-weight: 600; }

.lista-empresas { display: flex; flex-direction: column; gap: 14px; margin: 18px 0; }
.empresa-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 22px;
}
.empresa-cab { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.empresa-cab h3 { margin: 0 0 4px; font-size: 15.5px; }
.empresa-botones { display: flex; gap: 8px; align-items: flex-start; }
.btn-peligro { color: var(--danger-text); }
.tag {
  font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: 2px 8px; vertical-align: middle;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px; }
.chip { font-size: 12px; border-radius: 999px; padding: 3px 10px; font-weight: 600; }
.chip-ok { background: #e7f6ec; color: #1d6b38; }
.chip-no { background: var(--danger-bg); color: var(--danger-text); }
.validacion { font-size: 13px; }
.val-lista { margin: 6px 0 0; padding-left: 18px; }
.val-ok { color: #1d6b38; }
.val-no { color: var(--danger-text); word-break: break-word; }

.form-empresa {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px;
}
.form-empresa h3 { margin-top: 0; }
.form-empresa fieldset {
  border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px 18px;
  margin: 0 0 16px; display: flex; flex-wrap: wrap; gap: 16px;
}
.form-empresa legend { font-size: 13px; font-weight: 700; padding: 0 6px; }
.campo-ancho { flex: 1 1 320px; }
.ayuda { flex-basis: 100%; margin: 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }
.form-botones { display: flex; gap: 14px; align-items: center; }
#empresa-msg { margin-top: 12px; }

/* ── Buzón SUNAT ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 4px;
  border-radius: 999px; background: #d92d20; color: #fff; font-size: 11.5px; font-weight: 700;
}
.tabs { display: flex; gap: 6px; margin: 14px 0 10px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; cursor: pointer; font-weight: 600; color: var(--text-muted);
}
.tab.activa { background: var(--accent); color: #fff; border-color: var(--accent); }
table.tabla-buzon { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--surface); }
table.tabla-buzon th { background: #1f3864; color: #fff; text-align: left; padding: 9px 12px; position: sticky; top: 0; }
table.tabla-buzon td { padding: 8px 12px; border-top: 1px solid var(--border); vertical-align: top; }
table.tabla-buzon td.asunto { white-space: normal; min-width: 320px; }
table.tabla-buzon td.acciones { white-space: nowrap; }
table.tabla-buzon tr.sin-revisar td { background: #fff8e1; }
.urgente { color: #d92d20; }
#buzon-log { margin: 10px 0; max-height: 160px; }

/* ── Multiusuario ─────────────────────────────────────────────────────────── */
.usuario-info { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.usuario-info #usuario-nombre { font-weight: 600; color: var(--text); }
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-caja {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: min(420px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 16px;
}
.login-caja .btn-primario { width: 100%; }
.lista-check { display: flex; flex-direction: column; gap: 6px; }
.check { font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
dialog#dlg-clave { border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
dialog#dlg-clave::backdrop { background: rgba(20, 25, 40, .35); }
.form-clave { display: flex; flex-direction: column; gap: 14px; min-width: 300px; }
.form-clave h3 { margin: 0; }

/* ── Casilla SUNAFIL en el Buzón ──────────────────────────────────────────── */
.sunafil-caja { margin: 16px 0 6px; }
.sunafil-caja table { margin-top: 10px; }
.sunafil-caja h3 .badge { vertical-align: middle; }
.subtitulo-buzon { margin: 22px 0 0; font-size: 16px; }

/* ── "Guardar en" ─────────────────────────────────────────────────────────── */
.guardar-en {
  flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  font-size: 13px; padding-top: 12px; border-top: 1px solid var(--border);
}
.guardar-en code { background: var(--accent-soft); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.guardar-botones { display: flex; gap: 8px; }
.ge-nota { flex-basis: 100%; font-size: 12px; }
a.btn-secundario { text-decoration: none; display: inline-flex; align-items: center; }

/* ── Celular (gerente desde el teléfono, 11-oct-2026) ─────────────────────── */
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; padding: 14px 16px; }
  .topbar-der { gap: 8px; }
  .selector-empresa { flex-basis: 100%; }
  .selector-empresa select { width: 100%; max-width: none; }
  .usuario-info { flex-basis: 100%; flex-wrap: wrap; }
  main.vista { padding: 16px; }
  .resultado-header { flex-direction: column; align-items: stretch; }
  .resultado-botones, .empresa-botones, .form-botones { flex-wrap: wrap; }
  .grid-grupos, .grid-reportes { grid-template-columns: 1fr; }
  table.tabla-buzon td.asunto { min-width: 220px; }
  .form-parametros { padding: 16px; }
  .campo { min-width: 0; flex: 1 1 100%; }
  dialog#dlg-telegram, dialog#dlg-clave { width: calc(100vw - 32px); }
  .form-clave { min-width: 0; }
}

/* Detalle de requerimientos SUNAFIL (plegable, con scroll horizontal en celular) */
.sf-detalle { margin: 10px 0; }
.sf-detalle summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.sf-detalle .tabla-scroll { overflow-x: auto; }
.sf-resumen { margin: 10px 0 12px; padding: 10px 14px; border-radius: 8px; background: #eef4ff; line-height: 1.5; }
.sf-resumen.alerta { background: #fff4e5; border-left: 4px solid #d9480f; }
.btn-mini { padding: 3px 10px; font-size: 12px; margin-top: 4px; }
.sf-informativa summary { font-weight: 500; color: #555; }

/* Permisos por usuario (10-oct-2026) */
.permisos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 20px; }
.perm-grupo h4 { margin: 4px 0 6px; font-size: 13px; color: #1f3864; }
.perm-grupo .check { margin: 3px 0; }
.perm-reportes { grid-column: 1 / -1; }
.perm-reportes-lista { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 2px 20px; margin-top: 6px; }
.perm-subgrupo { grid-column: 1 / -1; font-size: 12px; margin-top: 6px; text-transform: uppercase; letter-spacing: .04em; }
.no-otorgable { opacity: .45; }
.delicado { color: #d9480f; }
.badge[hidden] { display: none !important; }
#tabla-usuarios td.acciones { white-space: nowrap; }
.tabla-wrap { overflow-x: auto; }
[hidden] { display: none !important; }
#tabla-usuarios td.asunto { min-width: 160px; }
#tabla-usuarios td.acciones button { display: block; width: 100%; margin: 2px 0; }
.tabla-scroll { overflow-x: auto; }
@media (max-width: 600px) {
  .col-tipo { display: none; }
  .sunafil-caja table.tabla-buzon th, .sunafil-caja table.tabla-buzon td { padding: 7px 8px; }
}
/* Acceso a SUNAT rechazado / sin conexión (10-oct-2026) */
.franja-acceso { margin: 10px 0; padding: 12px 14px; border-radius: 8px; background: #fde9e9; border-left: 5px solid #c92a2a; line-height: 1.5; color: #5c1414; }
.franja-acceso.leve { background: #fff4e5; border-left-color: #d9480f; color: #5c2b0a; }

/* Origen de empresas y filtro por cliente (11-oct-2026) */
.origen-empresa { margin: 4px 0 8px; font-size: 13px; }
.filtro-cliente { display: inline-flex; gap: 8px; align-items: center; margin: 6px 0 12px; font-size: 14px; }
.filtro-cliente select { padding: 6px 10px; }

/* Emisión de comprobantes (oct-2026) */
.em-tipos { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.em-items input { width: 100%; box-sizing: border-box; padding: 6px 8px; }
.em-items td { vertical-align: middle; }
.em-items td:nth-child(2), .em-items td:nth-child(3) { width: 110px; }
.em-items td:nth-child(4) { width: 110px; text-align: right; font-weight: 600; }
.em-totales { margin: 8px 0 4px auto; max-width: 360px; font-size: 14px; }
.em-totales div { display: flex; justify-content: space-between; padding: 3px 0; }
.em-totales .em-total { font-size: 17px; font-weight: 700; border-top: 2px solid var(--border); padding-top: 6px; }
.em-totales .em-det { font-size: 12.5px; color: #8a4b00; }
.tag.beta { background: #fff4e5; color: #8a4b00; }
.tag.prod { background: #e8f5e9; color: #1b5e20; }
.estado-ok { color: #1b5e20; font-weight: 600; }
.estado-no { color: #c92a2a; font-weight: 600; }
dialog.em-dlg { max-width: 520px; }
#em-emitidos td:nth-child(2) { white-space: nowrap; }
#em-emitidos td.acciones { white-space: normal; min-width: 150px; }
#em-emitidos td.acciones button { padding: 3px 8px; font-size: 12px; margin: 1px 0; }

/* Guía de remisión */
.em-sub { display: contents; }
.em-sub[hidden] { display: none !important; }
#gr-mod { margin: 0 0 .4rem; }
#gr-items select { width: 100%; }
#gr-items .gr-desc { width: 100%; min-width: 260px; }
#gr-items td:first-child { width: 60%; }

/* Reporte de emitidos */
.em-reporte { margin: 1.2rem 0 .4rem; }
.em-reporte-fila { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.em-reporte-fila label { display: flex; gap: .3rem; align-items: center; font-size: .9rem; }

/* Asistente de configuración de emisión */
.wz { display: flex; flex-direction: column; gap: .5rem; margin: .6rem 0; }
.wz-paso { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .8rem; background: var(--surface); }
.wz-paso > summary { cursor: pointer; font-weight: 600; padding: .2rem 0; }
.wz-paso[open] > summary { margin-bottom: .4rem; }
.wz-check { list-style: none; padding: 0; margin: .3rem 0 .6rem; }
.wz-check li { margin: .2rem 0; }
