/* Contabilidad de Matriz · base
   La familia de MailDraft en la dirección «Mesa»: el papel frío y los radios de MailDraft,
   botón principal y foco en tinta, y el color solo donde significa algo
   (verde, lo que entra; ámbar, lo que pide una decisión; rojo, solo error).
   Todo color, fuente y radio sale de un token de aquí. Escala de espacio de 4 px. */

:root {
  color-scheme: light;
  --f-ui: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --f-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --f-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;

  --bg: #f5f6f8;          /* el papel */
  --surface: #ffffff;     /* la ficha */
  --soft: #f2f3f5;        /* ficha dentro de ficha */
  --row-hover: #e7e9ed;
  --line: #e6e8ec;
  --line-btn: #d9dce2;
  --ink: #12161f;
  --ink2: #2b313c;
  --ink3: #4a5160;
  --muted: #5b6270;       /* texto secundario: 5,7:1 sobre el papel */
  --primary: #12161f;
  --on-primary: #ffffff;
  --ok: #0f7a55;
  --ok-soft: #e6f5ef;
  --warn: #8a4700;
  --warn-soft: #fdf3e3;
  --error: #b3261e;
  --error-soft: #fbeaea;
  --backdrop: rgba(18, 22, 31, .32);
  --ve-at: #12161f; --ve-de: #9aa1ad; --ve-luz: #ffffff;
  --an-a: #9aa1ad; --an-b: #12161f; --an-mix: multiply;
  --pop: 0 1px 2px rgba(18, 22, 31, .06), 0 14px 32px rgba(18, 22, 31, .12);

  --r-card: 22px; --r-block: 18px; --r-field: 14px; --r-pill: 999px;
  --t-title: 17px; --t-body: 13.4px; --t-ui: 12.7px; --t-meta: 12.4px; --t-min: 11.8px;
  --top-h: 56px; --tira-w: 76px; --chat-w: 400px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121316; --surface: #1b1c20; --soft: #24262b; --row-hover: #2a2c32;
  --line: rgba(255, 255, 255, .09); --line-btn: rgba(255, 255, 255, .16);
  --ink: #ececef; --ink2: #d0d1d6; --ink3: #a9abb3; --muted: #9a9ca6;
  --primary: #ececef; --on-primary: #121316;
  --ok: #3fcf98; --ok-soft: rgba(63, 207, 152, .14);
  --warn: #f0a44a; --warn-soft: rgba(240, 164, 74, .14);
  --error: #ff8a80; --error-soft: rgba(255, 138, 128, .14);
  --backdrop: rgba(0, 0, 0, .55);
  --ve-at: #ececef; --ve-de: #686a73; --ve-luz: #ffffff;
  --an-a: #a9abb3; --an-b: #ececef; --an-mix: screen;
  --pop: 0 1px 2px rgba(0, 0, 0, .35), 0 14px 32px rgba(0, 0, 0, .5);
}

*, *::before, *::after { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: var(--line-btn) transparent; }
html, body { margin: 0; height: 100%; overflow-x: clip; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--f-ui); font-size: var(--t-body); line-height: 1.5;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: left; }
button:disabled { cursor: not-allowed; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--ink); text-underline-offset: 3px; }
a:hover { color: var(--ink3); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 9px; }
::selection { background: var(--row-hover); }
[hidden] { display: none !important; }
strong { font-weight: 600; }
table { border-collapse: collapse; }
summary { list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.salto { position: absolute; left: 16px; top: -48px; z-index: 50; padding: 8px 16px; border-radius: var(--r-pill); background: var(--primary); color: var(--on-primary); }
.salto:focus { top: 8px; color: var(--on-primary); }
.tenue { color: var(--muted); }
.mono { font-family: var(--f-mono); font-size: var(--t-meta); }

/* —— Iconos ———————————————————————————————————————————— */
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ic-s { width: 15px; height: 15px; }
.v-at { fill: var(--ve-at); } .v-de { fill: var(--ve-de); } .v-luz { fill: var(--ve-luz); }
.anillo { width: 46px; height: 46px; }
.hilo { fill: none; stroke-width: 22; mix-blend-mode: var(--an-mix); }
.hilo-a { stroke: var(--an-a); } .hilo-b { stroke: var(--an-b); }

/* —— Botones: uno principal por pantalla ———————————————————————— */
.btn { height: 40px; padding: 0 18px; border-radius: var(--r-pill); font-size: var(--t-ui); font-weight: 600; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; text-decoration: none; }
.btn-1 { background: var(--primary); color: var(--on-primary); }
.btn-1:hover { opacity: .88; color: var(--on-primary); }
.btn-2 { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-btn); }
.btn-2:hover { background: var(--soft); color: var(--ink); }
.btn-3 { color: var(--ink3); padding: 0 12px; }
.btn-3:hover { color: var(--ink); background: var(--soft); }
.btn-s { height: 36px; padding: 0 14px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; }
.btn-1:disabled:hover { opacity: .5; }
kbd { font-family: var(--f-ui); font-size: var(--t-min); font-weight: 500; padding: 1px 6px; border-radius: 6px; background: var(--row-hover); color: var(--ink2); white-space: nowrap; }
.btn-1 kbd { background: color-mix(in srgb, var(--on-primary) 18%, transparent); color: var(--on-primary); }
.t-btn { width: 36px; height: 36px; flex: none; border-radius: var(--r-pill); display: inline-flex; align-items: center; justify-content: center; color: var(--ink3); }
.t-btn:hover { background: var(--row-hover); color: var(--ink); }
.acc { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* —— Etiquetas de estado: el texto dice el estado, el color acompaña ——————————— */
.tag { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: var(--r-pill); font-size: var(--t-min); font-weight: 500; white-space: nowrap; background: var(--soft); color: var(--ink2); }
.tag-lista { background: var(--row-hover); color: var(--ink); }
.tag-decision { background: var(--warn-soft); color: var(--warn); }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-sola, .tag-neutra { background: var(--soft); color: var(--ink3); }
.tag-error { background: var(--error-soft); color: var(--error); }
.num { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 7px; border-radius: var(--r-pill); font-size: var(--t-min); font-weight: 600; background: var(--row-hover); color: var(--ink2); }
.num.dec { background: var(--warn-soft); color: var(--warn); }

/* —— Pestañas y conmutador —————————————————————————————————— */
.tabs { display: flex; gap: 24px; flex-wrap: wrap; box-shadow: inset 0 -1px 0 var(--line); }
.tab { height: 44px; display: inline-flex; align-items: center; gap: 8px; color: var(--ink3); text-decoration: none; }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--ink); }
.conm { display: inline-flex; padding: 3px; border-radius: var(--r-pill); background: var(--row-hover); }
.conm-i { height: 30px; padding: 0 12px; border-radius: var(--r-pill); display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-ui); font-weight: 500; color: var(--ink3); text-decoration: none; }
.conm-i:hover { color: var(--ink); }
.conm-i.on { background: var(--surface); color: var(--ink); font-weight: 600; }

/* —— Importes, cuentas y piezas de contabilidad —————————————————————— */
.imp { font-weight: 600; white-space: nowrap; }
.imp.entra { color: var(--ok); }
.cta { font-family: var(--f-mono); font-size: var(--t-meta); color: var(--ink3); margin-right: 10px; }
.rot { margin: 0 0 6px; font-size: var(--t-meta); color: var(--muted); }
.banco { font-family: var(--f-mono); font-size: var(--t-meta); background: var(--soft); border-radius: var(--r-field); padding: 10px 14px; color: var(--ink2); overflow-wrap: anywhere; }
.motivos { display: flex; flex-direction: column; gap: 6px; color: var(--ink2); }
.motivos li { display: flex; align-items: center; gap: 10px; }
.motivos .ic { color: var(--ok); }
.datos { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 16px; }
.datos.dos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.datos dt { font-size: var(--t-min); color: var(--muted); }
.datos dd { font-weight: 500; }
.asiento { width: 100%; }
.asiento th { font-weight: 400; font-size: var(--t-min); color: var(--muted); text-align: left; padding: 0 0 6px; }
.asiento td { padding: 8px 0; border-top: 1px solid var(--line); }
.asiento .n { text-align: right; white-space: nowrap; }

/* —— Progreso medido ——————————————————————————————————————— */
.medida-caja { display: flex; flex-direction: column; gap: 8px; }
.medida-txt { font-size: var(--t-ui); color: var(--ink2); }
.medida { height: 6px; border-radius: var(--r-pill); background: var(--row-hover); overflow: hidden; }
.medida span { display: block; height: 100%; border-radius: var(--r-pill); background: var(--ink); transform-origin: left center; transition: transform .35s ease-out; }

/* —— Avisos en línea, vacíos y campos ——————————————————————————— */
.aviso { display: flex; align-items: flex-start; gap: 10px; font-size: var(--t-ui); color: var(--ink2); }
.aviso .ic { margin-top: 2px; color: var(--muted); }
.aviso.atento .ic { color: var(--warn); }
.vacio { padding: 48px 24px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.vacio-t { font-family: var(--f-serif); font-size: 22px; line-height: 1.4; }
.vacio-x { color: var(--muted); max-width: 52ch; }
.vacio .acc { margin-top: 8px; }
.campo { display: flex; flex-direction: column; gap: 6px; }
.campo > span, .campo > label { font-size: var(--t-meta); color: var(--muted); }
.campo input, .campo select, .campo textarea { height: 40px; padding: 0 12px; border-radius: var(--r-field); border: 0; background: var(--soft); box-shadow: inset 0 0 0 1px transparent; }
.campo textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
.campo input:hover, .campo select:hover, .campo textarea:hover { box-shadow: inset 0 0 0 1px var(--line-btn); }
.campo input::placeholder, .campo textarea::placeholder { color: var(--muted); }
.campo .n { text-align: right; }

/* —— Hoja: el contenedor de una vista con una sola columna ————————————————— */
.hoja { flex: 1; min-width: 0; overflow-y: auto; padding: 16px 32px 96px 16px; }
.hoja-col { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.hoja-estrecha { max-width: 860px; }
.cab { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; }
.cab h1 { font-size: var(--t-title); font-weight: 700; letter-spacing: -.01em; }
.cab-fin { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ficha { background: var(--surface); border-radius: var(--r-card); padding: 20px 24px; }
.ficha h2 { font-size: var(--t-body); font-weight: 600; }
.bloque { background: var(--soft); border-radius: var(--r-block); padding: 16px 20px; }
.serif { font-family: var(--f-serif); font-size: 22px; line-height: 1.45; font-weight: 400; text-wrap: pretty; max-width: 760px; }

/* —— Tabla de datos ——————————————————————————————————————— */
.tabla-caja { background: var(--surface); border-radius: var(--r-card); overflow: auto; }
.tabla { width: 100%; min-width: 640px; }
.tabla th { position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 400; font-size: var(--t-min); color: var(--muted); padding: 12px 12px 8px; white-space: nowrap; }
.tabla td { padding: 0 12px; height: 44px; border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
.tabla .n { text-align: right; }
.tabla td.n { font-family: var(--f-mono); font-size: var(--t-meta); font-weight: 500; }
.tabla td.n.entra { color: var(--ok); }
.tabla tbody tr:hover td { background: var(--soft); }
.tabla tr.on td { background: var(--row-hover); }
.tabla th:first-child, .tabla td:first-child { padding-left: 20px; }
.tabla th:last-child, .tabla td:last-child { padding-right: 20px; }
.tabla .grupo th { position: static; padding: 14px 20px 6px; font-size: var(--t-meta); color: var(--ink3); font-weight: 500; }

/* —— Diálogo y avisos flotantes: lo único que lleva sombra —————————————————— */
dialog { border: 0; padding: 0; background: transparent; color: inherit; max-width: calc(100vw - 32px); width: var(--ancho, 520px); }
dialog::backdrop { background: var(--backdrop); }
.dlg { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--pop); display: flex; flex-direction: column; max-height: calc(100dvh - 48px); }
.dlg-cab { display: flex; align-items: center; gap: 12px; padding: 16px 16px 8px 24px; }
.dlg-cab h2 { font-size: var(--t-title); font-weight: 700; flex: 1; }
.dlg-cuerpo { padding: 8px 24px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.dlg-pie { padding: 12px 24px 20px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.atajos { width: 100%; }
.atajos td { padding: 8px 0; border-top: 1px solid var(--line); }
.atajos td:first-child { width: 140px; }
.avisos-caja { position: fixed; left: calc(var(--tira-w) + 16px); bottom: 24px; z-index: 40; }
.sin-marco .avisos-caja { left: 50%; bottom: auto; top: 64px; transform: translateX(-50%); }
.toast { display: flex; align-items: center; gap: 12px; padding: 10px 8px 10px 18px; border-radius: var(--r-pill); background: var(--primary); color: var(--on-primary); box-shadow: var(--pop); font-size: var(--t-ui); animation: sube .2s ease-out; }
.toast-btn { height: 30px; padding: 0 12px; border-radius: var(--r-pill); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.toast-x { width: 30px; height: 30px; border-radius: var(--r-pill); display: inline-flex; align-items: center; justify-content: center; }
.toast :focus-visible { outline-color: var(--on-primary); }
@keyframes sube { from { opacity: .7; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* —— Menús desplegables —————————————————————————————————————— */
.menu { position: relative; }
.menu-caja { position: absolute; z-index: 30; top: calc(100% + 8px); left: 0; min-width: 280px; padding: 8px; border-radius: var(--r-block); background: var(--surface); box-shadow: var(--pop); display: flex; flex-direction: column; gap: 2px; }
.menu-der { left: auto; right: 0; }
.menu-t { padding: 8px 12px; font-size: var(--t-meta); color: var(--muted); }
.menu-i { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-radius: var(--r-field); width: 100%; text-decoration: none; }
.menu-i:hover { background: var(--soft); }
.menu-i.on { background: var(--row-hover); font-weight: 600; }
.menu-s { font-size: var(--t-min); color: var(--muted); font-weight: 400; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 900px) {
  .hoja { padding: 8px 16px 96px; overflow: visible; }
  .datos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .avisos-caja, .sin-marco .avisos-caja { left: 16px; right: 88px; top: auto; bottom: 16px; transform: none; }
  .serif { font-size: 19px; }
  .tabs { flex-wrap: nowrap; gap: 20px; overflow-x: auto; scrollbar-width: none; }
  .tab { flex: none; }
}
