:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --brand: #1f4e79; --brand-2: #2f6ea8; --ok: #1e7b45; --ok-bg: #e5f4ea;
  --warn: #9a5b00; --warn-bg: #fdf1dc; --off: #8a1c1c; --off-bg: #fbe5e5;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 20px; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--brand); color: #fff; flex-wrap: wrap; }
.top .brand { font-weight: 700; font-size: 17px; }
.top nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.top nav a { color: #dbe7f3; padding: 6px 12px; border-radius: 6px; }
.top nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.top nav a.on { background: rgba(255,255,255,.2); color: #fff; }
/* Menú agrupado (desplegable) */
.menu-grupo { position: relative; }
.menu-titulo { background: transparent; border: 0; color: #dbe7f3; font: inherit; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.menu-titulo:hover { background: rgba(255,255,255,.12); }
.menu-grupo.on > .menu-titulo { background: rgba(255,255,255,.2); color: #fff; }
.menu-titulo .flecha { font-size: 11px; opacity: .8; }
.menu-items { display: none; position: absolute; top: 100%; left: 0; z-index: 20; min-width: 240px; padding: 6px; margin-top: 2px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.menu-grupo:hover > .menu-items, .menu-grupo.desplegado > .menu-items, .menu-grupo:focus-within > .menu-items { display: block; }
.top nav .menu-items a { display: block; color: var(--text); padding: 8px 10px; border-radius: 6px; }
.top nav .menu-items a:hover { background: #eef1f5; text-decoration: none; }
.top nav .menu-items a.on { background: #e8f0f8; color: var(--brand); font-weight: 600; }
.top .user { font-size: 14px; display: flex; align-items: center; gap: 10px; }
.top .user .muted { color: #b9cde0; }

h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.stat .value.neg { color: var(--off); }

dl.datos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.datos dt { color: var(--muted); }
dl.datos dd { margin: 0; }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #eef1f5; font-weight: 600; font-size: 13px; color: #374151; position: sticky; top: 0; }
tr:hover td { background: #fafbfc; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: #f3f5f8; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap table { border: 0; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.off { background: var(--off-bg); color: var(--off); }
.badge.neutral { background: #eceff3; color: #4b5563; }

form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input[type=text], input[type=number], input[type=password], select {
  padding: 8px 10px; border: 1px solid #cfd5dd; border-radius: 6px; font: inherit; background: #fff; min-width: 220px;
}
input:focus, select:focus { outline: 2px solid #9cc3e6; border-color: var(--brand-2); }
.btn { display: inline-block; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--brand); background: var(--brand); color: #fff; font: inherit; cursor: pointer; }
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.5); }
.btn.light { background: #fff; color: var(--brand); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.tabs { display: flex; gap: 6px; margin: 8px 0 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); }
.tabs a.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.alert { padding: 12px 14px; border-radius: 8px; background: var(--off-bg); color: var(--off); margin-bottom: 14px; }
.info { padding: 12px 14px; border-radius: 8px; background: #e8f0f8; color: #1f4e79; margin-bottom: 14px; }

details > summary { cursor: pointer; color: var(--brand-2); }
.sub { margin: 8px 0 4px; font-size: 13px; }
/* Detalle de aplicaciones dentro de una celda: se desplaza dentro de su columna sin estirar la tabla */
@media (min-width: 701px) {
  table.tarjetas td.t-pie { max-width: 0; width: 45%; }
  table.tarjetas td.t-pie .sub-wrap { overflow-x: auto; }
  table.tarjetas td.t-pie .sub th, table.tarjetas td.t-pie .sub td { padding: 5px 6px; }
  table.tarjetas td.t-pie .sub td.saldo { white-space: normal; min-width: 7.5em; }
}
.sub th { position: static; }

.login-box { max-width: 360px; margin: 10vh auto; }
.login-box h1 { text-align: center; }
.login-box label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 14px; }
.login-box input { width: 100%; }
.login-box .btn { width: 100%; margin-top: 18px; padding: 10px; }

@media print {
  .top, form.inline, .tabs, .noprint { display: none !important; }
  body { background: #fff; }
  .card, .table-wrap { border: 0; }
}
.nowrap { white-space: nowrap; }

.form-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.form-row label { color: var(--muted); font-size: 14px; }
.recibo { max-width: 800px; margin: 0 auto; padding: 24px; }
.rec-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; border-bottom: 2px solid #333; padding-bottom: 12px; font-size: 13px; }
.rec-emisor { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.rec-letra { font-size: 36px; font-weight: 700; border: 2px solid #333; width: 70px; text-align: center; line-height: 1.1; padding: 6px 0; height: fit-content; }
.rec-letra small { display: block; font-size: 8px; font-weight: 400; padding: 0 2px; }
.rec-num { text-align: right; }
.rec-tit { font-size: 20px; font-weight: 700; }
.rec-cli { padding: 12px 0; border-bottom: 1px solid #999; font-size: 14px; }
.rec-body { padding: 12px 0; min-height: 140px; }
.rec-foot { display: flex; justify-content: space-between; align-items: end; border-top: 2px solid #333; padding-top: 12px; }
.rec-total { font-size: 20px; font-weight: 700; }
.rec-firma { border-top: 1px solid #333; padding-top: 4px; width: 220px; text-align: center; font-size: 12px; margin-top: 40px; }
@media print { .recibo { border: 0; max-width: none; } }
/* Servicios del contrato: cantidad editable y botón quitar */
.cant-form { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; margin: 0; }
.cant-form input[type=number] { min-width: 0; width: 5.5em; padding: 4px 6px; text-align: right; }
.c-lbl-cel { display: none; }
input.corto { min-width: 0; width: 6em; }
.motivo-row[hidden] { display: none; }
a.neg, .neg { color: var(--off); }
select.corto2 { min-width: 0; width: 7em; }
table.tarifa input { min-width: 0; padding: 5px 8px; }
table.tarifa input.desc { width: 100%; min-width: 180px; }
table.tarifa input.kw { width: 6em; text-align: right; }
table.tarifa input.precio { width: 9em; text-align: right; }
table.tarifa td { vertical-align: middle; }
.simular { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.lista-simple { margin: 8px 0 0; padding-left: 18px; }
.lista-simple li { margin-bottom: 4px; }
.aumento { margin-top: 12px; }
.datos-comp { display: contents; }
.datos-comp[hidden] { display: none; }
input.corto2b { min-width: 0; width: 9em; }
.gasto-form select { min-width: 220px; }
.chequeos { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 8px; }
.permisos { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.permiso-sector { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.usuario-form h3 { font-size: 15px; margin: 18px 0 8px; }
.barra { display: block; height: 10px; border-radius: 5px; width: var(--ing); min-width: 2px; background: #c9dcef;
  background-image: linear-gradient(var(--brand), var(--brand)); background-repeat: no-repeat; background-size: var(--r) 100%; }
td.barra-col { width: 22%; vertical-align: middle; }
table.resultados tr.sel td { background: #f3f7fb; }
input.imp { min-width: 0; width: 9em; text-align: right; padding: 4px 6px; }
@media (min-width: 701px) { table.concilia tr.en-saldo > td:first-child { box-shadow: inset 3px 0 0 var(--brand-2); } }
.saldo-luz .btn { margin-top: 8px; }
.base-real { padding: 12px 14px; border-radius: 8px; background: var(--off); color: #fff; font-weight: 600; margin-bottom: 14px; }
.deshacer { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
textarea.pegar { width: 100%; min-height: 220px; font: 13px/1.4 ui-monospace, Consolas, monospace; padding: 8px 10px; border: 1px solid #cfd5dd; border-radius: 6px; }
ol.pasos { margin: 0 0 8px; padding-left: 20px; }
ol.pasos li { margin-bottom: 4px; }
label.tilde { display: inline-flex; align-items: center; gap: 6px; }
label.tilde input { width: 20px; height: 20px; }
.motivo-row label { flex: 1 1 360px; }
.motivo-row input { width: 100%; }
.cant-form button[hidden] { display: none; }
.btn.quitar { background: #fff; color: var(--off); border-color: #e7b9b9; }
.btn.quitar:hover { background: var(--off-bg); }
table.servicios-ct td { vertical-align: middle; }
.agregar-serv h2 { margin-top: 0; }
.agregar-serv select { min-width: 0; max-width: 100%; }

/* Estado de cuenta: servicios de cada período, debajo de su fila */
tr.con-serv td { border-bottom: 0; }
tr.det-serv > td { padding: 0 10px 10px 28px; }
tr.det-serv:hover td { background: transparent; }
table.servicios { width: auto; min-width: 60%; background: transparent; font-size: 13px; }
table.servicios th { position: static; background: transparent; color: var(--muted); font-weight: 400; font-style: italic; padding: 2px 10px; border-bottom: 1px solid var(--line); }
table.servicios td { padding: 2px 10px; border-bottom: 0; }
table.servicios tr:hover td { background: transparent; }
.mail-body { white-space: pre-wrap; overflow-wrap: anywhere; background: #f7f8fa; border: 1px solid var(--line); border-radius: 6px; padding: 10px; font: 14px/1.4 inherit; margin: 8px 0; }

/* ---- Celular ---- */
.menu-btn { display: none; }
input.ancho { min-width: 360px; }
@media (max-width: 700px) {
  .wrap { padding: 14px; }
  h1 { font-size: 19px; }
  h1 .muted { display: block; font-size: 15px; font-weight: 500; margin-top: 2px; }

  .top { gap: 0; padding: 10px 14px; justify-content: space-between; }
  .menu-btn { display: block; background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff; font-size: 20px; line-height: 1; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
  .top nav, .top .user { display: none; flex-basis: 100%; }
  .top.abierto nav { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
  .top.abierto nav a { padding: 10px 12px; }
  /* En el celular los grupos se muestran abiertos, uno debajo del otro */
  .menu-grupo { position: static; }
  .menu-titulo { display: block; width: 100%; text-align: left; padding: 12px 12px 4px; color: #b9cde0; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; cursor: default; }
  .menu-titulo:hover, .menu-grupo.on > .menu-titulo { background: transparent; color: #b9cde0; }
  .menu-titulo .flecha { display: none; }
  .menu-items, .menu-grupo:hover > .menu-items { display: block; position: static; min-width: 0; padding: 0; margin: 0; background: transparent; border: 0; box-shadow: none; }
  .top nav .menu-items a { color: #dbe7f3; padding: 10px 12px 10px 20px; }
  .top nav .menu-items a:hover { background: rgba(255,255,255,.12); }
  .top nav .menu-items a.on { background: rgba(255,255,255,.2); color: #fff; }
  .top.abierto .user { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.2); }

  input[type=text], input[type=number], input[type=password], select, input.ancho { min-width: 0; width: 100%; font-size: 16px; }
  form.inline > .btn, form.inline > button { flex: 1 1 auto; }
  .form-row { flex-direction: column; gap: 10px; }
  .form-row label { width: 100%; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .card { padding: 12px; overflow-wrap: anywhere; }
  .stat .value { font-size: 20px; }

  th, td { padding: 7px 8px; white-space: nowrap; }
  td details { white-space: normal; }
  dl.datos { grid-template-columns: 1fr; gap: 0; }
  dl.datos dd { margin-bottom: 8px; }

  .recibo { padding: 14px; }
  .rec-head { grid-template-columns: 1fr auto; }
  .rec-head > div:first-child { grid-column: 1 / -1; }
  .rec-num { text-align: left; }
  .rec-foot { flex-direction: column; align-items: stretch; gap: 10px; }
  .rec-firma { width: auto; margin-top: 30px; }

  /* Listados como tarjetas (class="tarjetas"): sin deslizar de costado */
  .table-wrap:has(> table.tarjetas) { border: 0; overflow: visible; }
  table.tarjetas, table.tarjetas > tbody, table.tarjetas > tfoot { display: block; width: 100%; background: transparent; }
  table.tarjetas > thead { display: none; }
  table.tarjetas > tbody > tr:not(.vacio):not(.det-serv), table.tarjetas > tfoot > tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px;
  }
  table.tarjetas > tbody > tr:not(.det-serv)::before, table.tarjetas > tbody > tr:not(.det-serv)::after { content: ""; flex-basis: 100%; height: 0; }
  table.tarjetas > tbody > tr::after { order: 3; }
  table.tarjetas > tbody > tr::before { order: 6; }
  table.tarjetas > tbody > tr.vacio > td { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
  table.tarjetas > * > tr:hover > td, table.tarjetas > tfoot > tr > td { background: transparent; }
  table.tarjetas > * > tr > td { padding: 0; border: 0; white-space: normal; text-align: left; overflow-wrap: anywhere; }
  table.tarjetas > * > tr > td:empty { display: none; }
  table.tarjetas > * > tr > td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-weight: 400; font-size: 14px; }
  table.tarjetas > * > tr > .t-tit { order: 1; flex: 1 1 0; min-width: 60%; font-weight: 600; font-size: 16px; }
  table.tarjetas > * > tr > .t-tit .muted { font-weight: 400; font-size: 14px; }
  table.tarjetas > * > tr > .t-badge { order: 2; margin-left: auto; align-self: flex-start; }
  table.tarjetas > * > tr > .t-meta { order: 4; color: var(--muted); font-size: 14px; }
  table.tarjetas > * > tr > .t-sub { order: 5; flex-basis: 100%; font-size: 14px; }
  table.tarjetas > * > tr > .t-monto, table.tarjetas > * > tr > .t-monto2 { order: 7; font-size: 16px; font-weight: 600; margin-top: 8px; }
  table.tarjetas > * > tr > .t-accion { order: 8; margin-left: auto; margin-top: 8px; }
  table.tarjetas > * > tr > .t-accion a { display: inline-block; padding: 10px 16px; border-radius: 6px; background: var(--brand); border: 1px solid var(--brand); color: #fff; font-size: 15px; text-decoration: none; }
  table.servicios-ct .cant-form input[type=number] { width: 5em; font-size: 16px; }
  table.servicios-ct .c-lbl-cel { display: inline; color: var(--muted); font-size: 14px; }
  table.servicios-ct > tbody > tr > .t-sub { flex-basis: auto; order: 7; margin-top: 8px; }
  .agregar-serv select { width: 100%; }
  table.tarifa input.desc { min-width: 140px; }
  table.resultados td.barra-col { width: auto; }
  table.resultados > tbody > tr > .barra-col { order: 8; flex-basis: 100%; margin-top: 6px; }
  table.concilia > tbody > tr > .t-sub { flex-basis: auto; order: 7; margin-top: 8px; }
  table.concilia input.imp { width: 8em; font-size: 16px; }
  table.concilia .c-lbl-cel { display: inline; color: var(--muted); font-size: 14px; }
  table.concilia > tbody > tr.en-saldo:not(.vacio):not(.det-serv) { border-left: 3px solid var(--brand-2); }
  table.tarjetas > * > tr > .t-pie { order: 9; flex-basis: 100%; min-width: 0; margin-top: 6px; }
  table.tarjetas .sin-det { display: none; }
  table.tarjetas > tfoot > tr { background: #f3f5f8; font-weight: 700; }
  .sub-wrap { overflow-x: auto; max-width: 100%; }
  .sub-wrap td, .sub-wrap th { white-space: nowrap; }

  /* Estado de cuenta: los servicios quedan pegados abajo de la tarjeta de su período */
  table.tarjetas > tbody > tr.con-serv:not(.vacio):not(.det-serv) { margin-bottom: 0; border-bottom: 0; border-radius: 10px 10px 0 0; }
  table.tarjetas > tbody > tr.det-serv { display: block; }
  table.tarjetas > tbody > tr.det-serv > td { display: block; background: var(--card); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 10px 10px; padding: 0 12px 12px; margin-bottom: 10px; }
  table.servicios { width: 100%; min-width: 0; border-top: 1px dashed var(--line); padding-top: 6px; }
  table.servicios thead { display: none; }
  table.servicios tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; padding: 6px 0 0; }
  table.servicios td { padding: 0; white-space: normal; }
  table.servicios .s-desc { flex-basis: 100%; font-size: 14px; }
  table.servicios .s-cant, table.servicios .s-pu { color: var(--muted); font-size: 13px; }
  table.servicios .s-cant::after { content: " ×"; }
  table.servicios .s-imp { margin-left: auto; font-weight: 600; }
}

/* Formularios chicos con un campo por renglón (Mi caja) */
form.apilado label { display: block; margin-bottom: 10px; }
form.apilado input[type=text], form.apilado select { max-width: 100%; }

/* Plan de cuentas */
.plan-arbol details > summary { cursor: pointer; padding: 6px 4px; }
.plan-rubro { border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: 10px; padding: 4px 12px; }
.plan-sub { margin: 4px 0 4px 12px; border-left: 3px solid var(--line); padding-left: 10px; }
.plan-col { margin: 8px 0 14px 12px; }
.plan-col-tit { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.plan-acciones { display: flex; gap: 10px; flex-wrap: wrap; font-size: 13px; margin: 2px 0 6px; }
.plan-acciones details > summary { color: var(--brand-2); padding: 0; }
.plan-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.plan-tabla td, .plan-tabla th { padding: 5px 8px; font-size: 14px; vertical-align: top; }
/* Mismos anchos en todas las tablas del plan, para que las columnas queden alineadas entre colectivas */
.plan-tabla { table-layout: fixed; width: 100%; min-width: 780px; }
.plan-tabla .c-cod { width: 110px; } .plan-tabla .c-tipo { width: 100px; } .plan-tabla .c-mov { width: 110px; }
.plan-tabla .c-saldo { width: 150px; } .plan-tabla .c-acc { width: 220px; }
.plan-tabla td { overflow-wrap: anywhere; }
.plan-tabla td .plan-acciones { margin: 0; }
.plan-tabla td .plan-acciones details[open] { flex-basis: 100%; }
.plan-tabla .plan-form input, .plan-tabla .plan-form select { width: 100%; min-width: 0 !important; box-sizing: border-box; }
@media (max-width: 820px) {   /* en el celular cada tabla se acomoda sola (como antes) */
  .plan-tabla { table-layout: auto; min-width: 0; }
  .plan-tabla col { width: auto !important; }
  .plan-tabla td { overflow-wrap: normal; }
  .plan-tabla td .plan-acciones:not(:has(details[open])) { flex-wrap: nowrap; white-space: nowrap; }
  .plan-tabla .plan-form input, .plan-tabla .plan-form select { min-width: 200px !important; }
}
.plan-revision { border-color: #e9c46a; background: #fffbea; }
.plan-problema { padding: 8px 0; border-bottom: 1px solid #f1e2b0; }
.plan-problema:last-child { border-bottom: 0; }
.neg { color: var(--off); }
