/*
 * Portal de clientes Nattia — hoja de estilos.
 * Sigue docs/especificacion-interfaz-portal-nattia.md (v1.1) con el verde de la
 * intranet (decisión del 2026-10-02, static/css/design-tokens.css de la intranet):
 *   --accent #29ac82  primario de la intranet: marca, pestañas, detalles y fondos suaves
 *   --brand  #1d7a5c  «enlace» de la intranet: botones y texto en verde (contraste 5,3:1;
 *                     #29ac82 sobre blanco da 2,9:1, insuficiente para texto, §11)
 * Fondos claros, bordes suaves, radios moderados, sin sombras decorativas,
 * transiciones breves y respeto a «reducir movimiento».
 */

:root {
    /* Paleta (§3, ajustada a la intranet) */
    --accent: #29ac82;         /* verde de la intranet */
    --brand: #1d7a5c;          /* verde de la intranet para botones y enlaces */
    --brand-hover: #17654c;
    --text: #18302D;           /* verde carbón */
    --heading: #173C35;        /* verde oscuro */
    --text-2: #60716C;         /* gris verdoso */
    --text-3: #73867F;         /* gris medio (auxiliar) */
    --bg: #F6F8F7;             /* blanco verdoso */
    --surface: #FFFFFF;
    --border: #DDE8E3;         /* gris verdoso claro */
    --border-hover: #B5DCCB;
    --soft: #E5F5EF;           /* tinte suave de #29ac82 */
    --soft-border: #C3E6D8;
    --soft-2: #EDF2F8;         /* azul grisáceo claro */

    /* Estados (fondos suaves, texto oscuro; §3 y §8) */
    --ok-bg: #E5F5EF;   --ok-text: #17654c;
    --warn-bg: #FBF1E1; --warn-text: #6B4A12;
    --info-bg: #EDF2F8; --info-text: #2B4466;
    --error-bg: #FBEAE7; --error-text: #8A2A1E; --error-border: #E8B9B1;
    --neutral-bg: #EEF1EF; --neutral-text: #3F4F4B;

    --focus: #1d7a5c;
    --radius-l: 14px;   /* contenedores (§6: 12–16) */
    --radius-m: 12px;   /* filas de información (§6: 12–14) */
    --radius-s: 9px;    /* campos y botones (§6: ~9) */
    --fast: 150ms;      /* §9: 120–180 ms */

    /* Escala de espaciado (múltiplos de 4/8) */
    --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
}

a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-hover); }

/* Foco visible y consistente en todo lo interactivo (§8, §11) */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}

h1, h2, h3 { color: var(--heading); font-weight: 600; margin: 0; }
h1 { font-size: 30px; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: 19px; line-height: 1.3; }
h3 { font-size: 16px; }

.muted { color: var(--text-2); }
.aux { color: var(--text-3); font-size: 13px; }
.num, .tabular { font-variant-numeric: tabular-nums; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute; left: var(--s4); top: -48px; z-index: 10;
    background: var(--brand); color: #fff; padding: var(--s2) var(--s3); border-radius: var(--radius-s);
}
.skip-link:focus { top: var(--s2); color: #fff; }

/* ---------------------------------------------------------------------------
 * Cabecera (§7 Marca y cabecera)
 * ------------------------------------------------------------------------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__inner {
    max-width: 1160px; margin: 0 auto; padding: var(--s3) var(--s5);
    display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
    min-height: 64px;
}
.brand { display: flex; align-items: center; gap: var(--s3); color: var(--heading); text-decoration: none; }
.brand:hover { color: var(--heading); }
.brand__logo { display: block; flex: none; height: 56px; width: auto; }

.session { display: flex; align-items: center; gap: var(--s4); min-width: 0; }
.session__who { text-align: right; min-width: 0; line-height: 1.3; }
.session__name { display: block; font-weight: 600; color: var(--heading); font-size: 14px;
                 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.session__role { display: block; color: var(--text-3); font-size: 12px; }
.session form { margin: 0; }

/* ---------------------------------------------------------------------------
 * Retícula (§5)
 * ------------------------------------------------------------------------- */
.container { width: 100%; max-width: 1160px; margin: 0 auto; padding: var(--s6) var(--s5) var(--s7); flex: 1; }
.container--narrow { max-width: 480px; padding-top: var(--s7); }
.container--reading { max-width: 800px; padding-top: var(--s6); }

.page-head { margin-bottom: var(--s5); }
.page-head p { margin: var(--s2) 0 0; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-l);
    padding: var(--s5);
}
.panel + .panel { margin-top: var(--s5); }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3);
               margin-bottom: var(--s4); flex-wrap: wrap; }

/* ---------------------------------------------------------------------------
 * Botones (§7 Acciones; §8 Estados)
 * ------------------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
    min-height: 44px; padding: 0 var(--s4);
    border-radius: var(--radius-s); border: 1px solid transparent;
    font: inherit; font-weight: 600; font-size: 15px; line-height: 1;
    text-decoration: none; cursor: pointer; white-space: nowrap;
    transition: background-color var(--fast) ease, border-color var(--fast) ease, color var(--fast) ease;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-hover); color: #fff; }
.btn--secondary { background: var(--surface); color: var(--brand); border-color: var(--border); }
.btn--secondary:hover { background: var(--soft); color: var(--brand-hover); border-color: var(--border-hover); }
.btn--ghost { background: transparent; color: var(--brand); }
.btn--ghost:hover { background: var(--soft); }
.btn--small { min-height: 38px; padding: 0 var(--s3); font-size: 14px; }
.btn--block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

/* ---------------------------------------------------------------------------
 * Formularios (§7 Campos de entrada)
 * ------------------------------------------------------------------------- */
.field { margin-top: var(--s4); }
.field label { display: block; font-weight: 600; font-size: 14px; color: var(--heading); margin-bottom: var(--s2); }
.field input {
    width: 100%; min-height: 46px; padding: 0 var(--s3);
    font: inherit; font-size: 16px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-s);
    transition: border-color var(--fast) ease, box-shadow var(--fast) ease;
}
.field textarea {
    width: 100%; min-height: 84px; padding: var(--s3); font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); resize: vertical;
}
.field textarea:hover { border-color: var(--border-hover); }
.field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(41, 172, 130, 0.28); }
.field__hint { margin-top: var(--s2); }
.notice-form .field, .notice-form fieldset, .notice-form .btn, .notice-form .contact-choice--main { margin-top: var(--s4); }
.notice-form fieldset { margin-bottom: 0; padding: var(--s3) var(--s4); border: 1px solid var(--border); border-radius: var(--radius-s); }
.notice-form legend { padding: 0 var(--s2); font-weight: 600; font-size: 14px; color: var(--heading); }
.contact-choice { display: flex; align-items: center; gap: var(--s3); min-height: 40px; cursor: pointer; font-size: 15px; overflow-wrap: anywhere; }
.contact-choice input { width: 18px; height: 18px; flex: none; accent-color: var(--brand); }
.contact-choice--main { font-weight: 600; color: var(--heading); }
.contact-choice input:disabled + span { color: var(--text-3); }
.notice-list__count { margin: var(--s2) 0 0; }
.field input::placeholder { color: var(--text-3); }
.field input:hover { border-color: var(--border-hover); }
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(41, 172, 130, 0.28); }
.field input[aria-invalid="true"] { border-color: var(--error-text); }
.field__hint { margin: var(--s2) 0 0; font-size: 13px; color: var(--text-2); }
.field__error { margin: var(--s2) 0 0; font-size: 13px; color: var(--error-text); font-weight: 500; }
.input--code { letter-spacing: 0.45em; font-size: 22px !important; text-align: center; font-variant-numeric: tabular-nums; }
.form-actions { margin-top: var(--s5); }

/* ---------------------------------------------------------------------------
 * Mensajes de estado (§8). Siempre con icono y texto, nunca solo color.
 * ------------------------------------------------------------------------- */
.message {
    display: flex; gap: var(--s3); align-items: flex-start;
    padding: var(--s3) var(--s4); border-radius: var(--radius-s); border: 1px solid transparent;
    font-size: 14px; margin: var(--s4) 0 0;
}
.message svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.message p { margin: 0; }
.message--ok { background: var(--ok-bg); color: var(--ok-text); border-color: var(--soft-border); }
.message--error { background: var(--error-bg); color: var(--error-text); border-color: var(--error-border); }
.message--info { background: var(--info-bg); color: var(--info-text); border-color: #D5E0EE; }

/* ---------------------------------------------------------------------------
 * Pestañas (§7 Pestañas y selección)
 * ------------------------------------------------------------------------- */
/* La línea base es una sombra interior: el subrayado de la pestaña activa la
   tapa sin márgenes negativos (que provocaban barra de desplazamiento). */
.tabs {
    display: flex; gap: var(--s5); margin-bottom: var(--s5);
    box-shadow: inset 0 -1px 0 var(--border);
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.zip-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3);
    margin: 0 0 var(--s4); padding: var(--s3) var(--s4);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-s);
}
.zip-bar__label { font-weight: 600; font-size: 14px; color: var(--heading); }
.period-filters {
    display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0 0 var(--s4);
}
.period-filters__link {
    display: inline-flex; align-items: center; min-height: 38px; padding: 0 var(--s3);
    border: 1px solid var(--border); border-radius: var(--radius-s);
    color: var(--text-2); text-decoration: none; font-size: 14px; font-weight: 500;
    background: var(--surface);
}
.period-filters__link:hover { border-color: var(--border-hover); color: var(--brand); }
.period-filters__link[aria-current="true"] {
    background: var(--soft); border-color: var(--soft-border); color: var(--brand); font-weight: 600;
}
.incident-groups { display: grid; gap: var(--s5); }
.month-divider {
    display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3);
    margin: 0 0 var(--s3); padding-bottom: var(--s2);
    border-bottom: 1px solid var(--border);
    font-size: 15px; font-weight: 600; color: var(--heading);
}
.month-divider__count {
    font-size: 13px; font-weight: 500; color: var(--text-3);
}
.tab {
    display: inline-flex; align-items: center; gap: var(--s2);
    padding: var(--s3) 0;
    color: var(--text-2); text-decoration: none; font-weight: 500;
    border-bottom: 3px solid transparent;   /* reserva el espacio: no cambia la geometría */
    transition: color var(--fast) ease, border-color var(--fast) ease;
    white-space: nowrap;
}
.tab:hover { color: var(--heading); border-bottom-color: var(--border); }
.tab--aside { margin-left: auto; color: var(--brand); }
.tab--aside:hover { color: var(--brand-hover); }
.tab[aria-current="page"] { color: var(--heading); font-weight: 700; border-bottom-color: var(--accent); }
.tab__count {
    font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
    background: var(--neutral-bg); color: var(--neutral-text);
    border-radius: 999px; padding: 1px 8px;
}
.tab[aria-current="page"] .tab__count { background: var(--soft); color: var(--brand); }

/* ---------------------------------------------------------------------------
 * Etiquetas de estado (§7): píldoras con el mismo color para el mismo significado
 * ------------------------------------------------------------------------- */
.pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 13px; font-weight: 600; line-height: 1.4; white-space: nowrap;
    background: var(--neutral-bg); color: var(--neutral-text);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.pill--ok { background: var(--ok-bg); color: var(--ok-text); }
.pill--warn { background: var(--warn-bg); color: var(--warn-text); }
.pill--info { background: var(--info-bg); color: var(--info-text); }
.pill--neutral { background: var(--neutral-bg); color: var(--neutral-text); }

/* ---------------------------------------------------------------------------
 * Filas de información (§6): facturas, incidencias, empresas
 * ------------------------------------------------------------------------- */
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    padding: var(--s4) var(--s5);
    transition: border-color var(--fast) ease;
}
.row:hover { border-color: var(--border-hover); }

/* Factura: número/fecha · estado · importe · acción, en una sola fila en escritorio */
.invoice {
    display: grid;
    grid-template-columns: minmax(160px, 1.4fr) minmax(110px, 0.8fr) minmax(110px, 0.8fr) 172px;
    align-items: center; gap: var(--s4);
}
.invoice__id { font-weight: 600; color: var(--heading); font-variant-numeric: tabular-nums; }
.invoice__date { display: block; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.invoice__total { text-align: right; font-weight: 600; font-size: 16px; color: var(--heading); font-variant-numeric: tabular-nums; }
.invoice__action { justify-self: end; min-width: 172px; text-align: right; }
.label-sm { display: block; font-size: 12px; color: var(--text-3); font-weight: 500; }

/* Incidencia: cabecera con estado, fechas y acción; debajo los textos */
.incident__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); }
.incident__title { font-weight: 600; color: var(--heading); }
.incident__dates { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.incident__action { margin-left: auto; }
.incident__body {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3) var(--s5);
    margin: var(--s4) 0 0; padding-top: var(--s4); border-top: 1px solid var(--border);
}
.incident__body div { min-width: 0; }
.incident__body dt { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.incident__body dd { margin: var(--s1) 0 0; white-space: pre-line; overflow-wrap: anywhere; }

/* Empresa (administración) */
.company { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--s4); }
.company__name { font-weight: 600; color: var(--heading); overflow-wrap: anywhere; }
.company__cif { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.empty {
    border: 1px dashed var(--border); border-radius: var(--radius-m);
    padding: var(--s6) var(--s5); text-align: center; color: var(--text-2); background: var(--surface);
}
.empty p { margin: 0; }

/* Aviso de vista de administración: acento secundario suave (§3) */
.admin-banner {
    display: flex; gap: var(--s3); align-items: flex-start;
    background: var(--soft-2); color: var(--info-text);
    border: 1px solid #D5E0EE; border-radius: var(--radius-m);
    padding: var(--s4) var(--s5); margin-bottom: var(--s5); font-size: 14px;
}
.admin-banner svg { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.admin-banner p { margin: 0; }
.admin-banner p + p { margin-top: var(--s1); }
.admin-banner a { color: inherit; font-weight: 600; }
.emails { overflow-wrap: anywhere; }

/* Tarjeta de acceso */
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); padding: var(--s6); }
.auth-card h1 { font-size: 26px; }
.auth-card .lead { margin: var(--s2) 0 0; color: var(--text-2); }
.auth-card__foot { margin: var(--s5) 0 0; padding-top: var(--s4); border-top: 1px solid var(--border); font-size: 14px; }

/* Pie */
.footer { border-top: 1px solid var(--border); background: var(--surface); }
.legal h2 { font-size: 19px; margin: var(--s6) 0 var(--s2); padding-top: var(--s4); border-top: 1px solid var(--border); }
.legal h3 { font-size: 15px; margin: var(--s4) 0 var(--s1); color: var(--heading); }
.legal p, .legal li { line-height: 1.65; max-width: 68ch; }
.legal ul { padding-left: 1.2em; }
.legal__toc { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); margin: var(--s4) 0 0; }
.legal__data { margin: var(--s3) 0; padding: var(--s3) var(--s4); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.legal__data.facts { max-width: none; }
.legal code { font-size: 13px; }
.footer__inner { max-width: 1160px; margin: 0 auto; padding: var(--s4) var(--s5); color: var(--text-3); font-size: 13px; }

/* ---------------------------------------------------------------------------
 * Tableta (§10)
 * ------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------
 * Componentes añadidos: resumen, fichas, tablas, filtros, administración
 * ------------------------------------------------------------------------- */
.section-gap { margin-top: var(--s6); }
.nowrap { white-space: nowrap; }
.block { display: block; }

/* Enlace principal de una fila: abre la ficha */
.row-link { color: var(--heading); text-decoration: none; font-weight: 600; }
.row-link:hover { color: var(--brand); text-decoration: underline; }

.invoice__action, .incident__action { display: flex; gap: var(--s2); justify-content: flex-end; flex-wrap: wrap; align-items: center; }
/* Ocupa el hueco del botón PDF para que «Ver» quede alineado en todas las filas */
.pdf-missing { display: inline-flex; align-items: center; justify-content: center; min-width: 64px; min-height: 38px; }
.incident__summary {
    margin: var(--s3) 0 0; color: var(--text-2); font-size: 14px;
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* Cifras de resumen */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s3); margin-bottom: var(--s5); }
.stat {
    display: flex; flex-direction: column; gap: 2px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
    padding: var(--s4) var(--s5);
}
.stat__label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.stat__value { font-size: 26px; font-weight: 600; color: var(--heading); line-height: 1.2; }
.stat__hint { font-size: 12px; color: var(--text-3); }
.stat--warn { border-color: #EBD3A6; background: var(--warn-bg); }
.stat--alert { border-color: var(--error-border); background: var(--error-bg); }
.stat--alert .stat__value { color: var(--error-text); }

/* Fichas */
.back-link {
    display: inline-flex; align-items: center; gap: var(--s2); margin-bottom: var(--s4);
    min-height: 40px; padding: 0 var(--s1);
    color: var(--brand); text-decoration: none;
    font-size: 15px; font-weight: 600;
}
.back-link svg { width: 20px; height: 20px; stroke-width: 2.2; }
.back-link:hover { color: var(--brand-hover); }
.detail-head {
    display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s4); flex-wrap: wrap;
    margin-bottom: var(--s5);
}
.detail-head h1 { margin-top: 2px; }
.detail-head p { margin: var(--s2) 0 0; }
.detail-head__side { display: flex; flex-direction: column; align-items: flex-end; gap: var(--s3); }
.detail-total { font-size: 28px; font-weight: 600; color: var(--heading); }
.detail-asset {
    margin-top: var(--s3);
    font-size: 18px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--heading);
}

/* Tablas (conceptos, actividad) */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: var(--s3) var(--s2); border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines { table-layout: fixed; }
.lines th, .lines td { padding: var(--s4) var(--s3); }
.lines th:first-child, .lines td:first-child { padding-left: 0; }
.lines th:last-child, .lines td:last-child { padding-right: 0; width: 7.5rem; }
.lines th:nth-child(2), .lines td:nth-child(2) { width: 5.5rem; }
.lines th:nth-child(3), .lines td:nth-child(3) { width: 7rem; }
.lines th:nth-child(4), .lines td:nth-child(4) { width: 4.5rem; }
.lines thead th { border-bottom-color: var(--border-hover); }
.lines__concept { overflow-wrap: anywhere; color: var(--heading); font-weight: 500; }
.lines__amount { font-weight: 600; color: var(--heading); }
.events__detail { overflow-wrap: anywhere; max-width: 360px; }
.events__detail .aux { margin-right: 6px; }

/* Totales y listas de datos */
.totals {
    margin: var(--s5) 0 0 auto; max-width: 280px; width: 100%;
    display: grid; gap: var(--s3);
    padding: var(--s4);
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-s);
}
.totals div { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s4); }
.totals dt { color: var(--text-2); font-size: 14px; }
.totals dd { margin: 0; font-variant-numeric: tabular-nums; }
.totals__grand {
    border-top: 1px solid var(--border); padding-top: var(--s3);
    font-weight: 700; color: var(--heading); font-size: 18px;
}
.totals__grand dt { color: var(--heading); font-size: inherit; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s3) var(--s5); margin: 0; }
.facts dt { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.facts dd { margin: var(--s1) 0 0; overflow-wrap: anywhere; }
.report { display: grid; gap: var(--s4); margin: 0; }
.report dt { font-weight: 600; color: var(--heading); }
.report dd { margin: var(--s1) 0 0; white-space: pre-line; overflow-wrap: anywhere; }

/* Datos de pago */
.iban {
    display: flex; flex-direction: column; gap: 2px; margin: var(--s4) 0;
    padding: var(--s3) var(--s4); background: var(--soft); border: 1px solid var(--soft-border);
    border-radius: var(--radius-s);
}
.iban__value {
    font-family: "IBM Plex Mono", Consolas, "Courier New", monospace; font-size: 19px; font-weight: 600;
    color: var(--heading); letter-spacing: 0.02em; overflow-wrap: anywhere; user-select: all;
}
.payment .facts + .iban { margin-top: var(--s4); }
.payment p { margin: var(--s3) 0 0; }
.issuer { border-top: 1px solid var(--border); padding-top: var(--s3); }

/* Encuesta */
.survey { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); flex-wrap: wrap;
          background: var(--soft); border-color: var(--soft-border); }
.survey p { margin: var(--s1) 0 0; }
.survey__admin {
    display: flex; flex-direction: column; align-items: flex-end; gap: var(--s2);
    min-width: 0; max-width: min(100%, 420px);
}
.survey__admin .btn[aria-disabled="true"] {
    pointer-events: none; opacity: 0.7; cursor: default;
}
.survey__admin .aux { margin: 0; text-align: right; }

/* Administración */
.tabs--admin { margin-bottom: var(--s5); }
.company { grid-template-columns: minmax(0, 1.6fr) minmax(130px, 0.8fr) minmax(110px, 0.6fr) auto; }
.company__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.company__activity { display: flex; flex-direction: column; font-size: 14px; }
.company__actions { display: flex; gap: var(--s2); justify-content: flex-end; flex-wrap: wrap; }
.search { display: flex; gap: var(--s2); align-items: center; }
.search input, .filters input, .filters select {
    min-height: 40px; padding: 0 var(--s3); font: inherit; font-size: 15px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-s);
}
.search input { width: 260px; max-width: 100%; }
/* Filtros del listado (texto + periodo, comunes a facturas e incidencias): un solo bloque. */
.filters-panel {
    display: grid; gap: var(--s3); margin: 0 0 var(--s4); padding: var(--s4);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.search--list { width: 100%; gap: var(--s3); }
.search--list input { flex: 1; width: auto; min-width: 0; }
.search--list .btn { flex: none; }
.filters-panel__row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.filters-panel__label { font-size: 13px; font-weight: 600; color: var(--text-3); }
.filters-panel .period-filters { margin: 0; }
.filters-panel__summary { margin: 0; padding-top: var(--s3); border-top: 1px solid var(--border); font-size: 14px; color: var(--text-2); }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: var(--s3) var(--s3); align-items: end; }
.filters .field { margin-top: 0; }
.filters input, .filters select { width: 100%; }
.filters__actions { display: flex; gap: var(--s2); flex-wrap: wrap; grid-column: 1 / -1; }
.pager { display: flex; justify-content: center; align-items: center; gap: var(--s4); margin-top: var(--s5); }
.admin-banner__body { min-width: 0; }
.admin-banner__activity { margin-top: var(--s2); }
.admin-banner__activity summary { cursor: pointer; font-weight: 600; }
.admin-banner__activity ul { margin: var(--s2) 0 0; padding-left: var(--s5); }
.pill--error { background: var(--error-bg); color: var(--error-text); }

/* Elegir empresa */
.choices { list-style: none; margin: var(--s5) 0 0; padding: 0; display: grid; gap: var(--s3); }
.choices form { margin: 0; }
.choice {
    width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name icon" "meta icon";
    align-items: center; gap: 2px var(--s3); text-align: left; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
    padding: var(--s4); font: inherit; color: var(--text);
    transition: border-color var(--fast) ease, background-color var(--fast) ease;
}
.choice:hover { border-color: var(--accent); background: var(--soft); }
.choice svg { grid-area: icon; width: 20px; height: 20px; color: var(--brand); }
.choice__name { grid-area: name; font-weight: 600; color: var(--heading); overflow-wrap: anywhere; }
.choice__meta { grid-area: meta; font-size: 13px; color: var(--text-2); }
.choice__current { font-size: 12px; font-weight: 600; color: var(--brand); }
.choice--current { border-color: var(--accent); }

.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.check { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--radius-s); border: 1px solid; }
.check svg { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.check p { margin: var(--s1) 0 0; font-size: 14px; overflow-wrap: anywhere; }
.check__state { margin-left: var(--s2); font-size: 13px; font-weight: 600; }
.check--ok { background: var(--ok-bg); border-color: var(--soft-border); color: var(--ok-text); }
.check--error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }
.button-row { display: flex; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s4); }
.button-row form { margin: 0; }

@media (max-width: 900px) {
    .company { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .company__main, .company__actions { grid-column: 1 / -1; }
    .company__actions { justify-content: flex-start; }
    .incident__body { grid-template-columns: minmax(0, 1fr); }
    .session__name { max-width: 200px; }
    /* Tableta vertical: la factura sigue en una fila, con columnas más justas */
    .invoice { grid-template-columns: minmax(130px, 1.3fr) minmax(90px, 0.7fr) minmax(100px, 0.8fr) 150px; gap: var(--s3); }
    .invoice__action { min-width: 0; }
}

@media (max-width: 760px) {
    .invoice { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "id total" "status action"; row-gap: var(--s3); }
    .invoice__main { grid-area: id; }
    .invoice__status { grid-area: status; }
    .invoice__total { grid-area: total; }
    .invoice__action { grid-area: action; min-width: 0; }
}

/* ---------------------------------------------------------------------------
 * Móvil (§10): bloques verticales, acciones a todo el ancho, sin scroll horizontal
 * ------------------------------------------------------------------------- */
@media (max-width: 600px) {
    body { font-size: 15px; }
    h1 { font-size: 24px; }
    .topbar__inner { padding: var(--s3) var(--s4); }
    .brand__logo { height: 46px; }
    .session__who { display: none; }
    .container { padding: var(--s5) var(--s4) var(--s6); }
    .container--narrow, .container--reading { padding-top: var(--s5); }
    .panel, .auth-card { padding: var(--s4); }
    .row { padding: var(--s4); }
    .invoice { grid-template-columns: minmax(0, 1fr); grid-template-areas: "id" "status" "total" "action"; }
    .invoice__total { text-align: left; }
    .invoice__action, .incident__action { justify-self: stretch; margin-left: 0; width: 100%; }
    .invoice__action .btn, .incident__action .btn, .form-actions .btn { width: 100%; }
    .company { grid-template-columns: minmax(0, 1fr); }
    .company__actions { flex-direction: column; }
    .company .btn { width: 100%; }
    .footer__inner { padding: var(--s4); }
    .invoice__action, .incident__action { flex-direction: column; }
    .detail-head__side { align-items: stretch; width: 100%; }
    .detail-head__side .btn, .survey .btn, .button-row .btn, .button-row form { width: 100%; }
    .survey__admin { align-items: stretch; max-width: none; width: 100%; }
    .survey__admin .aux { text-align: left; }
    .search { width: 100%; }
    .search input { width: auto; flex: 1; min-width: 0; }
    /* Tablas como tarjetas: cada celda con su etiqueta */
    table.lines thead, table.events thead { display: none; }
    table.lines, table.events { table-layout: auto; }
    table.lines tr, table.events tr { display: block; padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
    table.lines td, table.events td { display: flex; justify-content: space-between; gap: var(--s3);
                                      border: 0; padding: 2px 0; text-align: right; width: auto !important; }
    table.lines td::before, table.events td::before { content: attr(data-label); color: var(--text-3);
                                                      font-size: 12px; font-weight: 600; text-align: left; }
    table.lines td.lines__concept { display: block; text-align: left; font-weight: 600; padding-bottom: var(--s2); }
    table.lines td.lines__concept::before { content: none; }
    .totals { max-width: none; margin-left: 0; }
    .events__detail { max-width: none; }
}

/* ---------------------------------------------------------------------------
 * Pantallas táctiles (móvil y tableta): zonas de pulsación de al menos 44 px
 * ------------------------------------------------------------------------- */
@media (pointer: coarse) {
    .btn--small { min-height: 44px; padding: 0 var(--s4); }
    .tab { min-height: 44px; }
    .back-link { min-height: 44px; }
    .link-button, .stat__hint, .admin-banner a { padding-block: 6px; display: inline-block; }
    .search input, .filters input, .filters select { min-height: 44px; }
}

/* Márgenes seguros del iPhone (muesca, barra inferior) */
@supports (padding: max(0px)) {
    .topbar__inner, .container, .footer__inner {
        padding-left: max(var(--s4), env(safe-area-inset-left));
        padding-right: max(var(--s4), env(safe-area-inset-right));
    }
    .footer__inner { padding-bottom: max(var(--s4), env(safe-area-inset-bottom)); }
}
@media (min-width: 601px) {
    @supports (padding: max(0px)) {
        .topbar__inner, .container, .footer__inner {
            padding-left: max(var(--s5), env(safe-area-inset-left));
            padding-right: max(var(--s5), env(safe-area-inset-right));
        }
    }
}

/* Móvil: el resumen en dos columnas y campos a 16 px (iOS no amplía al escribir) */
@media (max-width: 600px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
    .stat { padding: var(--s3) var(--s4); }
    .stat__value { font-size: 22px; }
    .search input, .filters input, .filters select { font-size: 16px; }
    .panel__head { flex-direction: column; align-items: flex-start; }
    .panel__head .search { align-self: stretch; }
    .detail-total { font-size: 24px; }
    .detail-head__side .pill { align-self: flex-start; }
    .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
    .iban__value { font-size: 17px; }
    .tabs { gap: var(--s4); }
}

.error-ref { margin: var(--s4) 0 0; font-size: 13px; color: var(--text-2); }

/* Impresión: solo el contenido (útil para la ficha de factura) */
@media print {
    .topbar, .footer, .tabs, .back-link, .btn, .admin-banner, .skip-link, .button-row, .filters, .pager { display: none !important; }
    body { background: #fff; }
    .container { padding: 0; max-width: none; }
    .panel, .row, .stat { border-color: #ccc; break-inside: avoid; }
}

/* Movimiento reducido (§9, §11) */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
