/* Layout: app de panel con barra lateral fija en escritorio y pestañas arriba en móvil; cada vista es una columna de 72rem */
/* Marca kobi.es: azul marino #1E3A5F + cian #00B4D8 sobre gris muy claro; Plus Jakarta Sans + Inter. Barra lateral marina, contenido claro. */
:root {
  --bg: #F8FAFC; --surface: #ffffff; --surface-2: #F1F5F9; --ink: #1E2A38; --muted: #4A5568; --faint: #94A3B8; --line: #E2E8F0;
  --navy: #1E3A5F; --navy-2: #24466F; --on-navy: #ffffff; --on-navy-muted: rgba(255,255,255,.68);
  --cyan: #00B4D8; --accent: #007C99; --accent-ink: #ffffff; --accent-soft: #E6F7FB;
  --ok: #15803D; --ok-soft: #E8F6EE; --warn: #A16207; --warn-soft: #FDF4DC; --bad: #C2413A; --bad-soft: #FDECEA; --info: #1E5FA8; --info-soft: #E8F0FB;
  --series-1: #0096B8; --series-2: #D97300;
  --shadow-sm: 0 1px 3px rgba(30,58,95,.07), 0 1px 2px rgba(30,58,95,.05);
  --shadow: 0 4px 16px rgba(30,58,95,.09), 0 1px 4px rgba(30,58,95,.06);
  --radius: 14px;
  --font-display: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1826; --surface: #16263D; --surface-2: #1D3150; --ink: #E7EDF5; --muted: #A3B1C4; --faint: #6E809A; --line: #263C5C;
    --navy: #0A1422; --navy-2: #132238; --on-navy: #ffffff; --on-navy-muted: rgba(255,255,255,.62);
    --cyan: #22C3E6; --accent: #3CC8E8; --accent-ink: #0A1422; --accent-soft: #123A4E;
    --ok: #5FCB8A; --ok-soft: #14352A; --warn: #E8B45A; --warn-soft: #3A2E14; --bad: #F28B82; --bad-soft: #43201F; --info: #8DB8F0; --info-soft: #1B2D4A;
    --series-1: #1BA3C4; --series-2: #C27A12;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.35); --shadow: 0 4px 16px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1826; --surface: #16263D; --surface-2: #1D3150; --ink: #E7EDF5; --muted: #A3B1C4; --faint: #6E809A; --line: #263C5C;
  --navy: #0A1422; --navy-2: #132238; --on-navy: #ffffff; --on-navy-muted: rgba(255,255,255,.62);
  --cyan: #22C3E6; --accent: #3CC8E8; --accent-ink: #0A1422; --accent-soft: #123A4E;
  --ok: #5FCB8A; --ok-soft: #14352A; --warn: #E8B45A; --warn-soft: #3A2E14; --bad: #F28B82; --bad-soft: #43201F; --info: #8DB8F0; --info-soft: #1B2D4A;
  --series-1: #1BA3C4; --series-2: #C27A12;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.35); --shadow: 0 4px 16px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* `hidden` oculta siempre, aunque la clase del elemento fije un display (p. ej. .check es inline-flex). */
[hidden] { display: none !important; }
html, body { min-height: 100%; }
/* Sin el margen de 8 px del navegador, que dejaba un borde blanco alrededor de la barra lateral. */
body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 0.98rem; }
p { margin: 0; }
.num, td.n, .tab { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 0.82em; }
.muted { color: var(--muted); }

/* Estructura */
.app { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: env(safe-area-inset-top, 0px); align-self: start; height: 100vh; border-right: 1px solid var(--line); background: var(--surface); padding: 20px 14px calc(20px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; }
.brand strong { font-family: var(--font-display); font-size: 1.15rem; display: block; line-height: 1.1; }
.brand span { font-size: 0.75rem; color: var(--muted); }
/* El menú se desplaza solo; el pie (sincronización con Holded, cuenta) queda siempre a la vista. */
.nav { display: grid; gap: 2px; align-content: start; flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; }
.nav a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--ink); font-weight: 600; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav .badge { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.nav .badge.alert { background: var(--bad-soft); color: var(--bad); }
.nav-sec { display: grid; gap: 2px; }
.nav-sec .nav-items { display: none; gap: 2px; }
.nav-sec.open .nav-items { display: grid; }
.nav .nav-group { display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 8px; padding: 7px 10px; border: 0; border-radius: 8px; background: none; font: inherit; font-size: 0.7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); cursor: pointer; text-align: left; }
.nav .nav-group:hover:not(:disabled) { background: var(--surface-2); }
.nav .nav-group:disabled { cursor: default; }
.nav .nav-group > span:first-child { flex: 1; }
.nav .nav-group .badge { text-transform: none; letter-spacing: 0; }
.nav .nav-group .chev { flex: none; width: 8px; height: 8px; margin-right: 3px; border-right: 2px solid var(--on-navy, currentColor); border-bottom: 2px solid var(--on-navy, currentColor); transform: rotate(-45deg); transition: transform .15s ease; }
.nav-sec.open .nav-group .chev { transform: rotate(45deg); }
.nav .nav-group:disabled .chev { opacity: .45; }
@media (prefers-reduced-motion: reduce) { .nav .nav-group .chev { transition: none; } }
.nav a.mobile-only { display: none; }
.menu-btn { display: none; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; background: transparent; color: var(--on-navy, #fff); font: inherit; font-weight: 600; cursor: pointer; max-width: 60vw; }

.menu-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.menu-btn .burger { flex: none; width: 16px; height: 2px; background: currentColor; box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor; }
.side.menu-open .menu-btn .burger { height: 0; box-shadow: none; position: relative; }
.side.menu-open .menu-btn .burger::before, .side.menu-open .menu-btn .burger::after { content: ""; position: absolute; left: 0; top: -1px; width: 16px; height: 2px; background: currentColor; transform: rotate(45deg); }
.side.menu-open .menu-btn .burger::after { transform: rotate(-45deg); }
.menu-btn .badge { font-family: var(--font-mono); font-size: 0.72rem; padding: 1px 7px; border-radius: 99px; background: #F87171; color: #fff; }
.side .foot { flex: none; margin-top: auto; font-size: 0.78rem; color: var(--muted); padding: 0 8px; display: grid; gap: 4px; }
main { min-width: 0; padding-block: 28px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.view { max-width: 110rem; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.view-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; }
.view-head .sub { color: var(--muted); margin-top: 4px; }
.view-head .title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.help-btn { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: 700 0.85rem/1 var(--font-head, inherit); cursor: pointer; display: inline-grid; place-items: center; }
.help-btn:hover, .help-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.help-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.view-head .help-text { max-width: 65ch; }
.hero .help-btn { background: transparent; color: rgba(255,255,255,.85); border-color: rgba(255,255,255,.4); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.crumb { font-size: 0.85rem; }

/* Bloques */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; align-content: start; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.panel-head a { font-size: 0.88rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; }
.kpi .label { font-size: 0.82rem; color: var(--muted); }
.kpi .value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .note { font-size: 0.8rem; color: var(--muted); }
.kpi.bad .value { color: var(--bad); }
.alert-bar { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--bad); background: var(--bad-soft); border-radius: 12px; padding: 12px 16px; }
.alert-bar .icon { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--bad); color: var(--surface); display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; }
.alert-bar strong { display: block; }

/* Tablas */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.n, th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--surface-2); }
tr.sub-row td:first-child { padding-left: 26px; }
.date { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Estados */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 0.76rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.pending { background: var(--warn-soft); color: var(--warn); }
.pill.notified { background: var(--info-soft); color: var(--info); }
.pill.invoiced { background: var(--accent-soft); color: var(--accent); }
.pill.paid, .pill.active, .pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.overdue, .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.cancelled, .pill.ended, .pill.archived { background: var(--surface-2); color: var(--muted); }
.tag { font-family: var(--font-mono); font-size: 0.72rem; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.days { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.days.bad { color: var(--bad); font-weight: 600; }
.days.soon { color: var(--warn); font-weight: 600; }

/* Controles */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ovh-filters { margin-bottom: 12px; }
.ovh-filters select.input { width: auto; }
.ovh-filters input[type=search] { flex: 1 1 16rem; max-width: 24rem; }
details.panel > summary { cursor: pointer; }
details.panel[open] > summary { margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: none; background: none; padding: 6px 12px; cursor: pointer; font-size: 0.88rem; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.search { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 6px 12px; min-width: 0; width: 16rem; max-width: 100%; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: 0.84rem; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.84rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; vertical-align: 3px; width: 16px; }
.legend i.dash { height: 0; border-top: 2px dashed var(--muted); background: none; width: 16px; vertical-align: 3px; }

/* Listas */
.rows { display: grid; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; }
.row:last-child { border-bottom: none; }
.row .t { font-weight: 600; min-width: 0; }
.row .s { font-size: 0.84rem; color: var(--muted); grid-column: 1; }
.row .r { text-align: right; grid-row: 1 / span 2; grid-column: 2; display: grid; gap: 2px; justify-items: end; }
/* «Por facturar» de la ficha: casilla para elegir lo que va en el borrador. */
.row.row-sel { grid-template-columns: auto minmax(0, 1fr) auto; }
.row.row-sel .row-check { grid-column: 1; grid-row: 1 / span 2; margin: 0; }
.row.row-sel .t, .row.row-sel .s { grid-column: 2; }
.row.row-sel .r { grid-column: 3; }
.empty { color: var(--muted); padding: 10px 0; }
details.rev { border-top: 1px solid var(--line); }
details.rev:first-of-type { border-top: none; }
details.rev summary { cursor: pointer; padding: 10px 0; display: flex; justify-content: space-between; gap: 10px; font-weight: 600; list-style: none; }
details.rev summary::-webkit-details-marker { display: none; }
details.rev summary::before { content: "▸"; color: var(--muted); margin-right: 8px; transition: transform .15s; display: inline-block; }
details.rev[open] summary::before { transform: rotate(90deg); }
details.rev summary .left { display: flex; flex: 1; min-width: 0; }
details.rev ul { margin: 0 0 12px; padding-left: 22px; display: grid; gap: 5px; color: var(--muted); font-size: 0.9rem; }
.kv { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 6px 12px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Gráficos */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-family: var(--font-body); font-size: 11px; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--ink); stroke-width: 1; opacity: .6; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 0.82rem; box-shadow: 0 4px 14px rgb(0 0 0 / .12); min-width: 11rem; z-index: 5; }
.tip strong { display: block; margin-bottom: 4px; }
.tip .l { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tip .l i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 0.9rem; z-index: 20; max-width: min(36rem, calc(100vw - 32px)); display: flex; align-items: flex-start; gap: 10px; line-height: 1.45; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.toast[hidden] { display: none; }
.toast.error { background: #B42318; color: #fff; }
.toast-text { flex: 1; min-width: 0; }
.toast-close { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 0 2px; opacity: .8; line-height: 1.45; }
.toast-close:hover, .toast-close:focus-visible { opacity: 1; }
.proto { font-size: 0.78rem; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; padding: 6px 10px; }

@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  /* Barra arriba y el contenido debajo: sin filas fijas, la rejilla repartía la altura sobrante
     entre las dos y una página corta salía con un hueco grande bajo la barra. */
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .side { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; height: auto; flex-direction: column; gap: 10px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); border-right: none; border-bottom: 1px solid var(--line); }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 11; background: var(--surface); }
  /* Menú plegado tras el botón «Menú»; abierto, los mismos grupos que en escritorio. */
  .side { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px 12px; }
  .menu-btn { display: inline-flex; }
  .side .brand { min-width: 0; }
  .side .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nav, .side .foot { display: none; grid-column: 1 / -1; }
  .side.menu-open .nav { display: grid; max-height: calc(100dvh - 170px); overflow-y: auto; overscroll-behavior: contain; }
  .side.menu-open .foot { display: grid; margin-top: 0; }
  main { padding-block: 18px 56px; }
  /* Filas con botones de texto (Conectores → Apps…): los botones bajan debajo del texto; al lado
     dejaban el texto en una columna de una palabra. Las filas solo con iconos siguen igual. */
  .row:has(.r .actions > .btn:not(.icon)) { grid-template-columns: minmax(0, 1fr); }
  .row:has(.r .actions > .btn:not(.icon)) .r { grid-row: auto; grid-column: 1; justify-items: start; text-align: left; }
  .row:has(.r .actions > .btn:not(.icon)) .r .actions { justify-content: flex-start; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0 0; }
  .kv dt { margin-top: 8px; }
  .search { width: 100%; }
  /* Que nada sea más ancho que la pantalla: filas de botones que bajan de línea, buscadores a todo
     el ancho y campos de las tarjetas que encogen. */
  .seg { display: flex; flex-wrap: wrap; max-width: 100%; }
  .seg button { flex: 1 1 auto; }
  .seg button + button { border-left: none; }
  .seg button { border-right: 1px solid var(--line); }
  .toolbar > * { max-width: 100%; }
  .toolbar input[type=search], .ovh-filters input[type=search] { flex: 1 1 100%; max-width: none; }
  .toolbar select.input { max-width: 100%; }
  .match-cell select, .match-cell input { min-width: 0; width: 100%; }
  /* En las tarjetas, una celda con un campo lleva la etiqueta encima y el campo debajo, a todo el
     ancho (a su lado no cabe y se salía de la tarjeta). */
  .table-wrap td:has(> .match-cell)::before { float: none; display: block; max-width: none; margin: 0 0 4px; }
  .table-wrap td:has(> .match-cell) { text-align: left; }
  .table-wrap td .input, .table-wrap td select, .table-wrap td input { max-width: 100%; }
  .table-wrap td:empty { display: none; }
  .chart { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Marca kobi.es ---------- */
body { font-size: 14.5px; letter-spacing: -0.003em; }
h1, h2, h3 { letter-spacing: -0.015em; font-weight: 700; }
h1 { font-size: 1.7rem; font-weight: 800; }
.side { background: var(--navy); border-right: none; color: var(--on-navy); }
.brand .mark { background: none; width: 34px; height: 34px; }
.brand .mark svg { width: 34px; height: 34px; display: block; }
.brand strong { color: var(--on-navy); font-weight: 800; letter-spacing: -0.02em; }
.brand span { color: var(--on-navy-muted); }
.nav a { color: var(--on-navy-muted); font-weight: 600; border-radius: 10px; }
.nav a:hover { background: rgba(255,255,255,.07); color: var(--on-navy); }
.nav a[aria-current="page"] { background: rgba(0,180,216,.18); color: var(--on-navy); box-shadow: inset 3px 0 0 var(--cyan); }
.nav .badge { background: rgba(255,255,255,.12); color: var(--on-navy); }
.nav .badge.alert { background: #F87171; color: #fff; }
.nav .nav-group { color: var(--on-navy-muted); }
.nav .nav-group:hover:not(:disabled) { background: rgba(255,255,255,.07); color: var(--on-navy); }
/* La barra del menú, discreta sobre el marino: invisible hasta pasar por encima o moverse con el teclado. */
.nav { scrollbar-width: thin; scrollbar-color: transparent transparent; transition: scrollbar-color .2s; }
.nav:hover, .nav:focus-within { scrollbar-color: rgba(255,255,255,.28) transparent; }
.side .foot { color: var(--on-navy-muted); border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; gap: 8px; }
.side .foot .btn { background: transparent; color: var(--on-navy); border-color: rgba(255,255,255,.25); }
.side .foot .btn:hover { border-color: var(--cyan); color: var(--cyan); }
.panel, .kpi { border-radius: var(--radius); box-shadow: var(--shadow-sm); border-color: var(--line); }
.kpi { gap: 6px; padding: 16px 18px; }
.kpi .label { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
.kpi .value { font-weight: 800; font-size: 1.7rem; letter-spacing: -0.02em; }
.btn { border-radius: 10px; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.seg { border-radius: 10px; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.search { border-radius: 10px; }
th { color: var(--faint); font-size: 0.72rem; }
.alert-bar { border-radius: var(--radius); }

/* Cabecera de Inicio: el único degradado de la marca */
.hero { background: linear-gradient(135deg, #1E3A5F 0%, #0F6E8C 55%, #00B4D8 100%); color: #fff; border-radius: 18px; padding: 24px 26px; display: grid; gap: 16px; box-shadow: var(--shadow); }
.daily { position: relative; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.daily img { display: block; width: 100%; height: 100%; min-height: 160px; max-height: 240px; object-fit: cover; }
.daily-text { padding: 20px 52px 20px 24px; display: grid; gap: 6px; min-width: 0; }
.daily blockquote { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; line-height: 1.35; text-wrap: balance; }
.daily-orig { margin: 0; font-size: .85rem; font-style: italic; }
.daily-author { margin: 0; font-weight: 600; color: var(--accent); }
.daily-credit { margin: 4px 0 0; font-size: .78rem; }
.daily-close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 1.2rem; line-height: 1; cursor: pointer; }
.daily-close:hover, .daily-close:focus-visible { border-color: var(--accent); }
@media (max-width: 760px) { .daily { grid-template-columns: 1fr; } .daily img { max-height: 200px; } .daily-text { padding: 16px 48px 18px 16px; } }
.hero h1 { color: #fff; font-size: 1.9rem; }
.hero .sub { color: rgba(255,255,255,.82); }
.hero .kpis { gap: 10px; }
.hero .kpi { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); box-shadow: none; backdrop-filter: blur(2px); }
.hero .kpi .label { color: rgba(255,255,255,.72); }
.hero .kpi .value { color: #fff; }
.hero .kpi .note { color: rgba(255,255,255,.72); }
.hero .kpi.bad .value { color: #FFC9C4; }
/* Cajas de Inicio que llevan a donde se resuelve lo que cuentan. */
a.kpi { color: inherit; text-decoration: none; transition: background-color .15s, border-color .15s, transform .15s; }
a.kpi:hover { border-color: var(--accent); transform: translateY(-1px); }
a.kpi:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hero a.kpi:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.45); }
.hero a.kpi:focus-visible { outline-color: #fff; }
.hero .alert-bar { background: rgba(0,0,0,.18); border-color: rgba(255,201,196,.55); color: #fff; }
.hero .alert-bar .muted { color: rgba(255,255,255,.8); }
.hero .alert-bar a { color: #9BE7F7; font-weight: 600; }
.hero .alert-bar .icon { background: #F87171; color: #fff; }

@media (max-width: 760px) {
  .side { border-bottom: none; }
  body::before { background: var(--navy); }
  .hero { padding: 18px; border-radius: 14px; }
}

.tag.sepa { background: var(--info-soft); color: var(--info); font-weight: 600; }
.tag.modulards { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag.modulards.bad { background: var(--bad-soft); color: var(--bad); }
button.tag.sepa, button.tag.modulards { border: none; cursor: pointer; font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600; line-height: inherit; }
button.tag.sepa:hover, button.tag.modulards:hover { filter: brightness(0.95); }
.sub-h { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }

/* Formularios */
.form { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.field { display: grid; gap: 5px; align-content: start; font-weight: 600; font-size: 0.88rem; min-width: 0; }
.field small { font-weight: 400; }
.input { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 11px; width: 100%; min-width: 0; font-weight: 400; }
.editor .input[readonly] { background: var(--surface-2); color: var(--muted); }
.input:disabled { background: var(--surface-2); color: var(--muted); }
.check { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.check-help { display: block; margin: -4px 0 4px 26px; }
.form-error { color: var(--bad); background: var(--bad-soft); border-radius: 10px; padding: 8px 12px; }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 18rem); gap: 6px 24px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: none; }
.setting-label { font-weight: 600; }
.setting .muted { font-size: 0.85rem; margin-top: 2px; }
.int-status { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-top: 6px; }
.int-status .muted { margin: 0; }
.int-form { display: grid; gap: 8px; }
.int-form .actions, .int-save { justify-content: flex-end; }
.int-save { padding-top: 12px; border-top: 1px solid var(--line); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
tr.muted-row td { opacity: .6; }

/* Tarifas en bloque: hoja editable. En el móvil no se convierte en tarjetas: se desplaza de lado. */
.sheet-wrap { overflow-x: auto; overscroll-behavior-x: contain; margin: 0 -4px; }
table.sheet { min-width: 860px; }
table.sheet th { letter-spacing: 0.02em; }
table.sheet th, table.sheet td { padding-inline: 5px; vertical-align: middle; }
table.sheet td { font-size: 0.92rem; }
table.sheet td.edit { padding: 4px 5px; background: var(--surface-2); }
table.sheet input.cell { width: 5rem; padding: 5px 7px; border-radius: 6px; font-variant-numeric: tabular-nums; }
table.sheet input.cell[data-col="from"] { width: 6.6rem; }
table.sheet select.cell { width: auto; padding: 5px 8px; border-radius: 6px; }
table.sheet input.cell:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
table.sheet td.chg { width: 7rem; min-width: 6rem; white-space: nowrap; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
table.sheet td.chg .sheet-err { display: block; white-space: normal; line-height: 1.3; }
tr.row-bad td { background: var(--bad-soft); }
tr.row-bad input.cell { border-color: var(--bad); }
.sheet-err { color: var(--bad); font-size: 0.85rem; }
.sheet-tools { flex-wrap: wrap; gap: 12px 24px; align-items: end; }
.sheet-tools .actions { justify-content: flex-start; flex-wrap: wrap; }
@media (max-width: 760px) {
  .form-grid, .setting { grid-template-columns: minmax(0, 1fr); }
}

/* Tablas ordenables */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--ink); }
th.sortable::after { content: "↕"; margin-left: 5px; opacity: .35; font-size: .9em; }
th.sortable[aria-sort="ascending"]::after { content: "↑"; opacity: 1; color: var(--accent); }
th.sortable[aria-sort="descending"]::after { content: "↓"; opacity: 1; color: var(--accent); }
th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Ventas */
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: start; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; min-width: 0; }
.col-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; padding: 2px 4px 4px; }
.col-head h3 { font-size: .9rem; }
.opp { display: grid; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; color: var(--ink); box-shadow: var(--shadow-sm); }
.opp:hover { border-color: var(--accent); text-decoration: none; }
.opp .muted, .opp-next { font-size: .82rem; }
.opp .tag { justify-self: start; }
.stages { display: flex; flex-wrap: wrap; gap: 6px; }
.stage { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.stage.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stage:disabled { cursor: default; opacity: .6; }
.btn.primary.armed { background: var(--ok); border-color: var(--ok); }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { border-left: 2px solid var(--line); padding-left: 12px; display: grid; gap: 2px; }
textarea.input { resize: vertical; font: inherit; }
/* Un desplegable dentro de una lista (Inicio → «Última pasada automática»): una sola columna, no la rejilla de .row. */
details.row { display: block; }
details.row summary { cursor: pointer; }
details.row ul { margin: 6px 0 0; padding-left: 1.2em; }
a.row { color: inherit; } a.row:hover { text-decoration: none; background: var(--surface-2); }
@media (max-width: 980px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .board { grid-template-columns: minmax(0, 1fr); } }
.opp[draggable="true"] { cursor: grab; }
.opp.dragging { opacity: .45; }
.col.drop { outline: 2px dashed var(--accent); outline-offset: -4px; background: var(--accent-soft); }

/* Revisión A/B/C */
.rev-items { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.rev-items li { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; }
.rev-items li.decided { background: var(--surface-2); }
.rev-items li p { color: var(--ink); font-size: .92rem; }
.rev-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.choice { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: .84rem; color: var(--muted); }
.choice b { color: var(--accent); }
.choice.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.choice.on b { color: var(--accent-ink); }
.choice:disabled { cursor: default; }
.rev-note { flex: 1 1 14rem; padding: 5px 10px; font-size: .86rem; }

/* Catálogo editable */
tr.edit-row td { background: var(--surface-2); padding: 16px; }
.editor { display: grid; gap: 14px; }
.editor h3 { margin-bottom: 8px; }
table.mini { font-size: .86rem; }
table.mini th { font-size: .7rem; }

/* Botones de icono */
.btn.icon { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: 10px; color: var(--muted); }
.btn.icon:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.btn.icon:disabled { opacity: .5; cursor: progress; }
.btn.icon svg { display: block; }
.tag.opened { font-family: var(--font-body); cursor: help; }
.tag.opened.yes { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.inv-mails { list-style: none; margin: 4px 0 0; padding: 0; font-size: 0.82rem; display: grid; gap: 2px; }
.inv-mails li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tag.notice { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.tag.ok { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
/* Remesas generadas: una línea por factura, con «Marcar como devuelta». */
.rem-inv { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.rem-detail summary { cursor: pointer; color: var(--accent); width: fit-content; }
.rem-detail[open] summary { margin-bottom: 2px; }
.tag.kobi { font-family: var(--font-body); background: var(--info-soft); color: var(--info); font-weight: 600; }
/* Contratos de la ficha: sin desplazamiento lateral. Un buzón o un dominio largo (en letra fija, sin espacios) y las etiquetas se parten en vez de ensanchar la tabla. */
table.subs td { overflow-wrap: anywhere; }
table.subs td .tag { white-space: normal; }
.tag.internal { font-family: var(--font-body); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Ventana de correo */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgb(14 24 38 / .45); display: grid; place-items: start center; overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.modal { width: 100%; max-width: 44rem; box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
.modal textarea { font: inherit; line-height: 1.5; }
.chips .tag { cursor: pointer; border: none; }
.chips .tag:hover { background: var(--accent-soft); color: var(--accent); }

/* Descuentos */
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; padding: 12px 0; border-top: 1px solid var(--line); margin-top: 8px; }
.inline-form .field { flex: 1 1 14rem; }
fieldset.checks { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
fieldset.checks legend { font-size: .85rem; color: var(--muted); padding: 0 4px; }

/* Enlace a Holded junto al número de factura */
a.ext { text-decoration: none; font-size: .85em; color: var(--muted); }
a.ext:hover { color: var(--accent); }

/* Historial del cliente */
.hist { display: grid; gap: 0; margin-top: 12px; }
.hist-entry { display: grid; gap: 6px; padding: 12px 0; border-top: 1px solid var(--line); }
.hist-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: .85rem; }
.hist-remind { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .88rem; }

/* Prueba de correo: resultado correcto */
.alert-bar.ok-bar { border-color: var(--ok); background: var(--ok-soft); }
.alert-bar.ok-bar .icon { background: var(--ok); }
.alert-bar.info-bar { border-color: var(--info); background: var(--info-soft); }
.alert-bar.info-bar .icon { background: var(--info); }
.match-bar { align-items: center; flex-wrap: wrap; }
.match-bar > div:nth-child(2) { flex: 1 1 16rem; }

/* Mi cuenta */
.sig-preview { width: 100%; min-height: 140px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
/* Editor de correos con formato (richEditor en panel.js). */
.rte { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-width: 0; font-weight: 400; }
.rte:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.rte-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px; border-bottom: 1px solid var(--line); border-radius: 10px 10px 0 0; }
.rte-btn { font: inherit; font-size: .82rem; font-weight: 600; line-height: 1; padding: 7px 10px; border: 0; border-radius: 8px; background: none; color: var(--ink); cursor: pointer; }
.rte-btn.rte-icon { padding: 6px; display: inline-grid; place-items: center; }
.rte-btn:hover:not(:disabled) { background: var(--surface-2); }
.rte-btn:disabled { opacity: .45; cursor: default; }
.rte-html { margin-left: auto; }
.rte-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.rte-area { padding: 10px 12px; outline: none; overflow-wrap: anywhere; max-height: 55vh; overflow: auto; line-height: 1.5; }
.rte-area p { margin: 0 0 .8em; }
.rte-area p:last-child { margin-bottom: 0; }
.rte-area ul, .rte-area ol { margin: 0 0 .8em; padding-left: 1.4em; }
.rte-area a { color: var(--accent); text-decoration: underline; }
.rte-area:empty::before { content: attr(data-placeholder); color: var(--muted); }
/* Se ve como el correo (Arial 14 px) y las tablas de una firma, sin el estilo de las tablas del panel
   (relleno, líneas, mayúsculas). Se anulan una a una: «all: revert» quitaría también width, height y cellpadding. */
.rte-area { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #1E2A38; }
.rte-area :is(h1, h2, h3, h4) { font-family: inherit; letter-spacing: normal; }
.rte-area table { border-collapse: separate; font-size: inherit; }
.rte-area table:not([width]) { width: max-content; }
.rte-area :is(th, td) { overflow-wrap: normal; padding: 0; border: 0; vertical-align: inherit; text-align: inherit; text-transform: none; letter-spacing: normal; font-weight: inherit; font-size: inherit; color: inherit; white-space: normal; }
.rte textarea { border: 0; border-radius: 0 0 10px 10px; width: 100%; }
.mail-preview { width: 100%; height: 22rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; resize: vertical; }
.side .foot a.me-link { color: inherit; text-decoration: none; }
.side .foot a.me-link:hover { text-decoration: underline; }

/* Responsive: pantallas grandes aprovechan el ancho; en el móvil las tablas pasan a tarjetas. */
@media (min-width: 1200px) { main { padding-left: 32px; padding-right: 32px; } }
.chips .tag, .kv dd .tag { white-space: normal; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .table-wrap { overflow: visible; margin: 0; }
  .table-wrap table { min-width: 0 !important; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table-wrap tbody tr:last-child { border-bottom: none; }
  .table-wrap td { display: block; padding: 3px 0; border: none; text-align: right; overflow-wrap: anywhere; }
  .table-wrap td::after { content: ""; display: block; clear: both; }
  .table-wrap td::before { content: attr(data-label); float: left; max-width: 45%; margin-right: 12px; color: var(--muted); font-size: 0.8rem; line-height: 1.6; text-align: left; }
  .table-wrap td:not([data-label])::before, .table-wrap td[data-label=""]::before { content: none; }
  .table-wrap td:first-child { display: block; text-align: left; font-size: 1rem; }
  .table-wrap td:first-child::before { content: none; }
  .table-wrap td:not([data-label]) { text-align: left; }
  .table-wrap td .actions { justify-content: flex-start; flex-wrap: wrap; }
  .table-wrap tr.sub-row { padding-left: 14px; border-left: 3px solid var(--line); }
}

/* Gráficos: el texto del SVG escala con el ancho. En grande se limita; en el móvil se desplazan de lado. */
.chart.hbar { max-width: 900px; }
.chart.hbar.compact { max-width: 560px; }
.chart svg { max-height: 340px; }
@media (max-width: 760px) {
  .chart:not(.hbar) { overflow-x: auto; overscroll-behavior-x: contain; }
  .chart:not(.hbar) svg { min-width: 640px; }
  .chart.hbar svg { min-width: 0; }
}
details.rev ul.rev-items { padding-left: 0; color: inherit; font-size: inherit; }

/* Prueba de correo: avisos de configuración */
.alert-bar.warn-bar { border-color: var(--warn); background: var(--warn-soft); }
.alert-bar.warn-bar .icon { background: var(--warn); }
.warn-list { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 4px; }

/* Etiquetas de clientes */
.tag.label { font-family: var(--font-body); font-size: 0.75rem; background: var(--accent-soft); color: var(--accent); }
button.tag.label { border: none; cursor: pointer; }
button.tag.label:hover { filter: brightness(0.95); }
.tag-row { margin-top: 4px; }
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; background: var(--surface); }
.tag-editor .input { border: none; flex: 1 1 12rem; min-width: 8rem; padding: 4px; background: transparent; }
.tag-editor .input:focus { outline: none; }
.tag-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-x { border: none; background: none; color: inherit; cursor: pointer; padding: 0 0 0 4px; font-size: 0.9rem; line-height: 1; }

/* Iconos de acción de las tablas en una sola línea (en el móvil, las tarjetas ya los reparten) */
@media (min-width: 761px) { .table-wrap td .actions { flex-wrap: nowrap; } }

/* Respuesta de los botones: al pasar el ratón cambian de color y al pulsar se hunden un poco. */
.btn, .choice, .seg button, button.tag.label, .tag-x, th.sortable, .nav a {
  transition: background-color .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease, transform .08s ease, filter .12s ease;
}
.btn:not(:disabled):hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); box-shadow: 0 1px 3px rgb(0 0 0 / .08); }
.btn.primary:not(:disabled):hover { background: var(--accent); color: var(--accent-ink); filter: brightness(.9); box-shadow: 0 2px 8px rgb(0 124 153 / .3); }
.btn.danger:not(:disabled):hover { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn.danger.armed:not(:disabled):hover { background: var(--bad); color: #fff; filter: brightness(.92); }
.side .foot .btn:not(:disabled):hover { background: rgba(255,255,255,.08); }
.btn:not(:disabled):active, .choice:not(:disabled):active, .seg button:not(:disabled):active, button.tag.label:active { transform: translateY(1px) scale(.97); box-shadow: none; }
.btn.primary:not(:disabled):active { filter: brightness(.8); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.choice:not(:disabled):not(.on):hover { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.choice.on:not(:disabled):hover { filter: brightness(.92); }
.seg button:not([aria-pressed="true"]):not(:disabled):hover { background: var(--surface-2); color: var(--ink); }
.seg button:disabled { opacity: .5; cursor: not-allowed; }
.tag-x:hover { color: var(--bad); }
@media (prefers-reduced-motion: reduce) {
  .btn:active, .choice:active, .seg button:active, button.tag.label:active { transform: none; }
}

/* Selección y acciones en bloque */
th.sel, td.sel { width: 36px; padding-right: 0; }
td.sel input, th.sel input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.bulk-bar { position: sticky; top: 8px; z-index: 6; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  background: var(--navy, #1E3A5F); color: #fff; border-radius: 12px; padding: 10px 14px; box-shadow: 0 6px 18px rgb(0 0 0 / .18); }
.bulk-bar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.bulk-bar .btn:not(:disabled):hover { background: rgba(255,255,255,.12); color: #fff; border-color: #fff; }
.bulk-bar select.input { width: auto; color: #1E2A38; background-color: #fff; }
.bulk-bar input.input { color: #1E2A38; background-color: #fff; }
@media (min-width: 761px) { .bulk-bar input.input { width: 20rem; } }
.bulk-bar .muted { color: rgba(255,255,255,.8); }
/* Remesa SEPA: «Cobro el [fecha]» dentro de la barra. */
.bulk-bar .inline-field { display: inline-flex; align-items: center; gap: 6px; }
.bulk-bar .inline-field input.input { width: auto; }
@media (max-width: 760px) {
  .table-wrap td.sel { position: absolute; right: 0; top: 10px; width: auto; }
  .table-wrap tbody tr { position: relative; }
  .bulk-bar { top: 108px; }
  /* La casilla va arriba a la derecha: que no tape el valor de la primera celda. */
  .table-wrap td.sel + td { padding-right: 36px; }
}

/* Editor de contrato encima de la tabla */
.sub-editor { border: 1px solid var(--accent); border-radius: 12px; padding: 14px 16px; margin: 4px 0 14px; background: var(--surface); }

/* Horas de Toggl */
.match-cell { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.match-cell select, .match-cell input { min-width: 12rem; flex: 1; }
.rate-view { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }
.rate-edit { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.rate-edit .input { width: 7rem; }

/* Adjuntos de los correos */
.att-actions { justify-content: flex-start; }
.att-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.att-list[hidden] { display: none; }
.att-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: .88rem; }
.att-list .att-name { overflow-wrap: anywhere; font-weight: 600; }
.att-list .btn { padding: 2px 10px; font-size: .8rem; margin-left: auto; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; text-align: left; overflow-wrap: anywhere; }

/* CC y CCO: pasar una dirección de «Para» a CC o CCO */
.move-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.move-row[hidden] { display: none; }
.move-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: .82rem; max-width: 100%; }
.btn.mini { padding: 1px 8px; font-size: .75rem; border-radius: 999px; }
.tag.match-chip { font-family: var(--font-body); white-space: normal; display: inline-block; }

/* Horas: selector de mes y estado de cada registro */
.month-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.month-nav .month-title { margin: 0 4px; min-width: 11rem; text-align: center; font-size: 1.15rem; }
.month-nav > .btn:first-child, .month-nav > .month-title + .btn { min-width: 2.4rem; font-size: 1.1rem; }
tr.selected td { background: var(--accent-soft); }

/* Filtro con muchas opciones (estado de las renovaciones): en el móvil, rejilla de 3 columnas en vez de salirse de la pantalla. */
@media (max-width: 760px) {
  .seg.seg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); width: 100%; }
  .seg.seg-grid button { background: var(--surface); border-left: none; }
  .seg.seg-grid button[aria-pressed="true"] { background: var(--accent-soft); }
}

/* Revisión: enlaces para arreglarlo en la ficha y qué hace cada opción */
.rev-links { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .86rem; }
.rev-links a { color: var(--accent); font-weight: 600; }
.rev-help { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: .8rem; color: var(--muted); }
.rev-help b { color: var(--ink); font-weight: 600; }
tr.focus td { background: var(--accent-soft); }

/* Cajas plegables de Cashflow */
details.fold > summary.fold-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; cursor: pointer; list-style: none; }
details.fold > summary.fold-head::-webkit-details-marker { display: none; }
details.fold > summary.fold-head::before { content: "▸"; color: var(--muted); transition: transform .15s; display: inline-block; }
details.fold[open] > summary.fold-head::before { transform: rotate(90deg); }
details.fold > summary.fold-head h2 { margin: 0; }
details.fold[open] > summary.fold-head { margin-bottom: 12px; }
.fold-actions { display: flex; justify-content: flex-end; margin-bottom: 8px; }
@media (prefers-reduced-motion: reduce) { details.fold > summary.fold-head::before { transition: none; } }
button.link { background: none; border: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
button.link:hover { text-decoration: underline; }

/* Acciones de cada contrato en la ficha: en dos filas de iconos para que no se salgan de la tarjeta. */
@media (min-width: 761px) { .table-wrap td .actions.sub-actions { flex-wrap: wrap; justify-content: flex-end; width: 4.9rem; margin-left: auto; } }
@media (min-width: 761px) { .table-wrap td .actions.sub-actions:has(.btn:not(.icon)) { width: auto; } }

.sub-actions > * { flex: none; }
a.tag-link { text-decoration: none; color: var(--accent, #007C99); }
a.tag-link:hover { text-decoration: underline; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.join-hint { font-size: .82rem; margin-top: 2px; }
.btn.icon.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---------- Menú: el logo lleva a Inicio y los grupos destacan sobre sus secciones ---------- */
a.brand { color: inherit; text-decoration: none; border-radius: 10px; padding: 4px 8px; margin: -4px 0; }
a.brand:hover { text-decoration: none; background: rgba(255,255,255,.07); }
a.brand[aria-current="page"] strong { color: #fff; }
.nav .nav-group { font-family: var(--font-display); font-size: 0.98rem; font-weight: 800; letter-spacing: -0.01em; text-transform: none; color: var(--on-navy); margin-top: 12px; }
.nav .nav-group:disabled { color: var(--on-navy); }
.nav-sec .nav-items a { padding-left: 22px; font-size: 0.93rem; }

/* ---------- Inicio: cajas que se ordenan entre columnas ---------- */
.home-col { display: grid; gap: 16px; align-content: start; min-height: 120px; border-radius: 14px; }
.home-col.drop { outline: 2px dashed var(--line); outline-offset: 6px; }
.home-box.dragging { opacity: .45; }
.home-box .panel-head h2 { margin-right: auto; }
.grip { flex: none; align-self: center; width: 22px; height: 22px; margin: -2px 0 -2px -6px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: grab; display: grid; place-items: center; opacity: .55; }
.grip span { width: 8px; height: 12px; background: radial-gradient(circle, currentColor 1.2px, transparent 1.6px) 0 0 / 4px 4px; }
.home-box:hover .grip, .grip:focus-visible { opacity: 1; }
.grip:hover { background: var(--surface-2); }
.grip:active { cursor: grabbing; }
.home-reset { justify-self: end; font-size: 0.82rem; }
@media (max-width: 980px) { .grip, .home-reset { display: none; } .home-col { min-height: 0; } .home-col.drop { outline: none; } }
@media (max-width: 760px) { a.brand { margin: 0; } }
.nav > a { font-family: var(--font-display); font-size: 0.98rem; font-weight: 800; letter-spacing: -0.01em; color: var(--on-navy); margin-top: 4px; }
@media (max-width: 760px) { .nav > a { font-family: inherit; font-size: inherit; font-weight: 600; margin-top: 0; color: var(--on-navy-muted); } .nav-sec .nav-items a { padding-left: 10px; font-size: inherit; } }

/* ---------- Conectores: un botón grande por servicio ---------- */
.connector { align-content: start; align-self: start; }
.connector .kv { grid-template-columns: minmax(0, 12rem) minmax(0, 1fr); }
.btn.btn-big { justify-self: stretch; justify-content: center; padding: 14px 18px; font-size: 1.05rem; font-weight: 700; border-radius: 12px; }
.muted.small { font-size: 0.85rem; margin: -4px 0 0; }
.ok-msg { color: var(--ok, #15803D); background: var(--ok-soft, #E7F6EC); border-radius: 10px; padding: 8px 12px; margin: 0; }
.meter { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 6px; overflow: hidden; max-width: 16rem; }
.meter span { display: block; height: 100%; background: var(--cyan, #00B4D8); border-radius: inherit; }
.meter span.high { background: var(--bad); }
@media (max-width: 760px) { .connector .kv { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Integraciones: línea del cron para copiar ---------- */
.cron-line { display: flex; align-items: center; gap: 10px; margin: 6px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.cron-line code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 0.86rem; }

/* ---------- Conectores: registro de las tareas programadas ---------- */
.task-log { margin: 0; max-height: 28rem; overflow: auto; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-family: var(--font-mono); font-size: 0.8rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Hoja del cashflow (como el Excel): se desplaza de lado y la primera columna se queda fija.
   No usa .table-wrap, para que en el móvil no se convierta en tarjetas. */
.cf-sheet { overflow-x: auto; margin-top: 8px; width: 0; min-width: 100%; } /* no ensancha la página: se desplaza dentro */
table.cf-grid { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: .85rem; }
table.cf-grid th, table.cf-grid td { padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.cf-grid thead th { font-size: .75rem; }
table.cf-grid tbody th { text-align: left; font-weight: 400; max-width: 16rem; overflow: hidden; text-overflow: ellipsis;
  text-transform: none; letter-spacing: normal; font-size: inherit; color: var(--ink); }
table.cf-grid tr.grp .link { font-size: inherit; }
table.cf-grid th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
table.cf-grid .fc { background: var(--accent-soft); }
table.cf-grid .tot { font-weight: 700; border-left: 1px solid var(--line); }
table.cf-grid tr.grp th, table.cf-grid tr.grp td { background: var(--surface-2); font-weight: 700; }
table.cf-grid tr.grp .link { font-weight: 700; color: var(--ink); }
table.cf-grid tr.grand th, table.cf-grid tr.grand td { font-weight: 700; border-top: 2px solid var(--line); }
@media (max-width: 760px) { table.cf-grid tbody th { max-width: 9rem; } }
/* Hoja: previsión pulsable, lo real debajo y validar meses. */
table.cf-grid .cf-fc { all: unset; display: inline-block; min-width: 2.2rem; min-height: 1.1em; text-align: right; cursor: pointer; padding: 0 2px; border-radius: 4px; font-variant-numeric: tabular-nums; }
table.cf-grid .cf-fc:hover, table.cf-grid .cf-fc:focus-visible { background: var(--surface-2); outline: 1px solid var(--accent); }
table.cf-grid .cf-fc.manual { color: var(--accent); font-weight: 700; text-decoration: underline dotted; }
table.cf-grid .real-under { font-size: .72rem; color: var(--muted); line-height: 1.1; }
table.cf-grid td.real { color: var(--ink); }
table.cf-grid .cf-edit { width: 5.5rem; padding: 2px 6px; text-align: right; font-size: .85rem; }
table.cf-grid .cf-val { display: block; margin: 3px 0 0 auto; padding: 1px 6px; font-size: .68rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--accent); cursor: pointer; text-transform: none; }
table.cf-grid .cf-val.on { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.cf-warn { margin: 6px 0; padding: 6px 10px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: .85rem; }
table.cf-grid td.cf-chk { cursor: help; font-weight: 700; }
table.cf-grid td.cf-chk.warn { background: var(--warn-soft); color: var(--warn); }
table.cf-grid td.cf-chk.bad { background: var(--bad-soft); color: var(--bad); }

/* Conectores: una pestaña por servicio (#conectores/<servicio>), solo con el nombre; el estado va dentro. */
/* Como pestañas de carpeta: borde arriba y a los lados; la activa tapa la línea de abajo con el fondo de la página.
   Sin desplazamiento: si no caben, bajan de línea (con overflow salía una barra de scroll por el píxel de solape). */
.con-tabs { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 4px; padding: 0 2px; border-bottom: 1px solid var(--line); }
.con-tab { flex: none; padding: 9px 16px; margin-bottom: -1px; border: 1px solid var(--line); border-radius: 9px 9px 0 0; background: var(--surface-2);
  color: var(--muted); font-weight: 600; text-decoration: none; white-space: nowrap; }
.con-tab:hover { color: var(--ink); background: var(--surface); }
.con-tab[aria-current="page"] { color: var(--accent); background: var(--bg); border-bottom-color: var(--bg); }
/* Texto seguido (no flex): en el móvil se parte por palabras, no deja el «·» al principio de otra línea. */
.con-status { margin: 0; color: var(--muted); }
.con-status .dot { display: inline-block; margin-right: 6px; vertical-align: 0.05em; }
.con-status strong { color: var(--ink); }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
@media (max-width: 760px) {
  .con-tabs { row-gap: 0; }
  .con-tab { padding: 8px 11px; }
}
/* En una columna de .grid-2 no caben etiqueta y campo lado a lado: uno encima de otro. */
.grid-2 .setting { grid-template-columns: minmax(0, 1fr); }

/* Ficha → Datos → «Enlazar con Holded» */
.billing-link { margin-top: 12px; display: grid; gap: 8px; min-width: 0; }
.billing-link > .btn { justify-self: start; }
.billing-link h3 { margin: 8px 0 0; font-size: 0.95rem; }
.blink-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.blink-list li { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.blink-list li .muted { font-size: 0.85rem; overflow-wrap: anywhere; }
/* Correo enviado abierto desde el registro de Conectores → Correo. */
.email-view { display: grid; gap: 10px; }
.email-view .kv { grid-template-columns: minmax(0, 7rem) minmax(0, 1fr); }
.email-view dd { overflow-wrap: anywhere; }
.email-body { white-space: pre-line; overflow-wrap: anywhere; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); max-height: 60vh; overflow-y: auto; }

/* Desplegables: el mismo aspecto que los campos de texto, con flecha propia (sin la del sistema) */
select, select.input {
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--line); border-radius: 10px; background-color: var(--surface); color: var(--ink);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
  padding: 8px 32px 8px 11px; font-weight: 400; line-height: 1.3; cursor: pointer; max-width: 100%;
}
select:hover:not(:disabled) { border-color: var(--faint); }
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
select:disabled { background-color: var(--surface-2); color: var(--muted); cursor: not-allowed; }
select option { color: var(--ink); background-color: var(--surface); }
/* Un desplegable a todo el ancho de una página grande: Chrome dibuja su lista más estrecha y corta el principio de cada opción (Proponer contratos → Cliente, 05/11/2026). */
.form .field > select { max-width: min(100%, 40rem); }
/* En las barras de filtros, a la altura de los botones y del buscador */
.toolbar select, .ovh-filters select { width: auto; padding-top: 6px; padding-bottom: 6px; font-size: 0.88rem; }
table.sheet select.cell { padding: 5px 26px 5px 8px; background-position: calc(100% - 13px) 52%, calc(100% - 8px) 52%; }
/* Ficha del cliente: las mismas pestañas que Conectores, con un recuento pequeño (lo pendiente de facturar, los presupuestos sin respuesta…). */
.tab-count { display: inline-block; min-width: 1.4em; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: .75rem; line-height: 1.4; text-align: center; }
.con-tab[aria-current="page"] .tab-count { color: var(--accent); border-color: currentColor; }

/* Cobros: las dadas por perdidas, al final, plegadas y discretas. */
.lost-box { margin-top: 4px; font-size: .9rem; }
.lost-box summary { cursor: pointer; width: fit-content; padding: 4px 0; }
.lost-box[open] { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
/* Hoja: el nombre de una línea abre su ventana (renombrar, categoría, archivar). */
table.cf-grid .cf-line { color: var(--ink); text-decoration: none; text-align: left; }
table.cf-grid .cf-line:hover, table.cf-grid .cf-line:focus-visible { text-decoration: underline; }
/* Presupuestos: proyecto, «En curso» y «Terminado» bajan de línea en vez de salirse de la tabla. */
@media (min-width: 761px) { .table-wrap td .actions.est-actions { flex-wrap: wrap; min-width: 10rem; } }

/* Proponer contratos: la tabla de líneas necesita más ancho que una ventana normal. */
.modal.pp-modal { max-width: 78rem; }
.pp-table td { vertical-align: top; }
.pp-table select, .pp-table input { min-width: 0; }
.pp-why { display: block; }
.pp-table td:nth-child(2) select { min-width: 7.5rem; }
.pp-table td:nth-child(3) select { min-width: 12rem; }
.pp-table td:nth-child(4) select { min-width: 5rem; }

/* Filtros en desplegable con su nombre encima (Por facturar). */
.filter { display: flex; flex-direction: column; gap: 3px; }
.filter > span { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.toolbar.filters { align-items: flex-end; gap: 10px 12px; }
.toolbar.filters select { max-width: 22rem; }
@media (max-width: 760px) {
  .toolbar.filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .toolbar.filters select { width: 100%; }
}
/* Historial de facturas de un contrato (ficha → icono de la lista con reloj). */
.modal.hist-modal { max-width: 60rem; }
.hist-ok { color: var(--ok); font-weight: 600; }
tr.hist-missing td { background: var(--bad-soft); }

/* ---------- Campana de avisos (04/11/2026): arriba a la derecha; en el móvil, en la barra junto al menú. */
main > .topbar { display: flex; justify-content: flex-end; margin: -14px 0 6px; }
.bell-wrap { position: relative; }
.bell-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); cursor: pointer; }
.bell-btn:hover { border-color: var(--accent); color: var(--accent); }
.bell-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.bell-count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: #DC2626; color: #fff; font: 600 0.7rem/18px var(--font-mono, monospace); text-align: center; }
.bell-count[hidden], .bell-panel[hidden] { display: none; }
.bell-panel { position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: min(380px, calc(100vw - 32px)); max-height: min(70vh, 520px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(15, 30, 50, .18); padding: 12px; display: grid; gap: 8px; text-align: left; }
.bell-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 4px; }
.bell-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.bell-list a { display: grid; gap: 2px; padding: 8px 10px; border-radius: 8px; color: inherit; text-decoration: none; border-left: 3px solid transparent; }
.bell-list a:hover, .bell-list a:focus-visible { background: var(--surface-2); }
.bell-list li.unread a { background: var(--accent-soft); border-left-color: var(--accent); }
.bell-list li:not(.unread) strong { font-weight: 500; }
.bell-list span { color: var(--muted); font-size: 0.86rem; }
.bell-list small { font-size: 0.75rem; }
.side .bell-btn { background: transparent; color: var(--on-navy, #fff); border-color: rgba(255,255,255,.25); }
@media (max-width: 760px) {
  .side { grid-template-columns: minmax(0, 1fr) auto auto; }
  .bell-panel { position: fixed; top: calc(64px + env(safe-area-inset-top, 0px)); right: 16px; left: 16px; width: auto; }
}
