/* Layout: barra superior con pestañas + área de trabajo de una columna; el resumen de cuenta se ve como una hoja de papel */
:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #e9efec;
  --fg: #16231e;
  --muted: #5b6b64;
  --line: #d5dfda;
  --accent: #14735a;
  --accent-fg: #ffffff;
  --accent-soft: #dcefe7;
  --ok: #1f7a4d;   --ok-soft: #dff3e8;
  --warn: #9a6200; --warn-soft: #fbefd6;
  --bad: #b3342b;  --bad-soft: #fbe2df;
  --info: #2c5d9e; --info-soft: #e1ebf8;
  --paper: #ffffff; --ink: #1b1f1d; --ink-muted: #5f6763; --paper-line: #d9dedb; --paper-band: #eef3f0;
  --shadow: 0 1px 2px rgba(20,40,32,.06), 0 4px 14px rgba(20,40,32,.06);
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Public Sans", "Segoe UI", system-ui, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1614; --surface: #17211e; --surface-2: #1f2b27; --fg: #e3ebe7; --muted: #93a39c; --line: #2c3a35;
    --accent: #4cc39a; --accent-fg: #06231a; --accent-soft: #1b3b31;
    --ok: #5fd39a; --ok-soft: #173a2a; --warn: #f0b54f; --warn-soft: #3a2c12; --bad: #f08076; --bad-soft: #43201d; --info: #86b3ee; --info-soft: #1b2c44;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--f-body); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; text-wrap: balance; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.label { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.cap { text-transform: capitalize; }

/* Barra superior */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; min-width: 0; text-decoration: none; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-size: .95rem; overflow: hidden; flex: none; font-family: var(--f-display); font-weight: 700; }
.logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.logo.grande { width: 64px; height: 64px; font-size: 1.4rem; }
/* Logotipo cargado: se muestra apaisado, sin caja (en modo oscuro va sobre una placa blanca para que se lea) */
.logo.marca { display: block; width: auto; height: 40px; background: transparent; border-radius: 0; overflow: visible; }
.logo.marca img { display: block; width: auto; height: 100%; max-width: none; background: transparent; }
.logo.grande.marca { height: 72px; }
.logo.login-logo.marca { height: 110px; }
@media (prefers-color-scheme: dark) {
  .logo.marca { background: #fff; padding: 4px 8px; border-radius: 8px; }
}
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; max-width: 100%; align-items: center; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; text-decoration: none; }
.tab:hover { background: var(--surface-2); color: var(--fg); }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.salir { margin: 0 0 0 8px; }

main { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 20px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head > div { min-width: 0; }

/* Controles */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.fin { justify-content: flex-end; }
input[type=text], input[type=number], input[type=date], input[type=month], input[type=email], input[type=tel], input[type=search], input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
}
textarea { resize: vertical; min-height: 70px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 12px; }
.full { grid-column: 1 / -1; }
form { margin: 0; }

/* Bloques */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 14px; min-width: 0; }
.panel.sub { background: var(--surface-2); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; }
.tile .v { font-family: var(--f-num); font-size: clamp(1rem, 1.6vw + .4rem, 1.35rem); font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile { min-width: 0; }
.tile.bad .v { color: var(--bad); }
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--warn-soft); color: var(--fg); border: 1px solid var(--warn); border-radius: 12px; padding: 12px 16px; }
.banner b { color: var(--warn); }

.tablewrap { overflow-x: auto; margin: 0 -2px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.click a { text-decoration: none; }
tr.prev td { color: var(--muted); font-style: italic; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.off { background: var(--surface-2); color: var(--muted); }
.neg { color: var(--ok); }
.rojo { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.iconbtn { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.iconbtn:hover { background: var(--bad-soft); color: var(--bad); }

/* Ventanas (dialog) */
dialog { border: 0; border-radius: 14px; width: calc(100% - 32px); max-width: 520px; padding: 20px; background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
dialog.wide { max-width: 860px; }
dialog::backdrop { background: rgba(8,16,13,.5); }
dialog > form, dialog > .cuerpo { display: grid; gap: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hint { background: var(--surface-2); border-radius: 9px; padding: 10px 12px; font-size: .88rem; }
.note { background: var(--info-soft); color: var(--info); border-radius: 9px; padding: 10px 12px; font-size: .85rem; }
.error { background: var(--bad-soft); color: var(--bad); border-radius: 9px; padding: 10px 12px; font-size: .9rem; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); animation: toast 4s forwards; }
.toast.error { background: var(--bad); color: #fff; }
@keyframes toast { 0%, 85% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

/* Login */
.login { max-width: 400px; margin: 8vh auto 0; width: 100%; }
.login .brand { justify-content: center; font-size: 1.2rem; }

/* Hoja del resumen de cuenta (siempre papel claro) */
.paper { background: var(--paper); color: var(--ink); border-radius: 6px; padding: 28px; box-shadow: var(--shadow); border: 1px solid var(--paper-line); display: grid; gap: 18px; font-size: 13.5px; min-width: 0; }
.paper .ph { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid var(--ink); padding-bottom: 14px; }
.paper .pl { display: flex; gap: 12px; align-items: center; min-width: 0; }
.paper .logo { width: 56px; height: 56px; background: #14735a; color: #fff; font-size: 1.3rem; }
.paper .logo.marca { width: auto; height: 60px; background: transparent; padding: 0; border-radius: 0; }
.paper h3 { font-size: 1.15rem; color: var(--ink); }
.paper .pm { color: var(--ink-muted); font-size: 12px; }
.paper .ptitle { text-align: right; }
.paper .ptitle b { font-family: var(--f-display); font-size: 1.1rem; letter-spacing: .04em; display: block; }
.paper .box { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); border: 1px solid var(--paper-line); border-radius: 6px; overflow: hidden; }
.paper .box > div { padding: 10px 12px; border-right: 1px solid var(--paper-line); display: grid; gap: 2px; }
.paper .box > div:last-child { border-right: 0; background: #14735a; color: #fff; }
.paper .box .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); font-weight: 600; }
.paper .box > div:last-child .k { color: #d7efe5; }
.paper .box .v { font-family: var(--f-num); font-weight: 600; font-size: 14.5px; }
.paper table th { color: var(--ink-muted); border-color: var(--paper-line); background: var(--paper-band); }
.paper table td { border-color: var(--paper-line); color: var(--ink); }
.paper .pf { border-top: 1px solid var(--paper-line); padding-top: 12px; color: var(--ink-muted); font-size: 12px; display: grid; gap: 4px; white-space: pre-line; }

/* Gráficos del panel (paleta validada para daltonismo en claro y oscuro) */
:root { --serie-1: #2a78d6; --serie-2: #eb6834; }
@media (prefers-color-scheme: dark) { :root { --serie-1: #3987e5; --serie-2: #d95926; } }
.dash2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 20px; align-items: start; }
.grafico-wrap { overflow-x: auto; }
.grafico { display: block; width: 100%; min-width: 560px; height: auto; }
.grafico .grilla { stroke: var(--line); stroke-width: 1; }
.grafico .base { stroke: var(--muted); stroke-width: 1; }
.grafico .eje { fill: var(--muted); font-size: 11px; font-family: var(--f-body); }
.grafico .fondo { fill: transparent; }
.grafico .banda:hover .fondo, .grafico .banda:focus .fondo { fill: var(--surface-2); }
.grafico .banda:focus { outline: none; }
.grafico .s1 { fill: var(--serie-1); }
.grafico .s2 { fill: var(--serie-2); }
.leyenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; margin-right: 6px; vertical-align: -1px; }
.leyenda .sw { margin-right: 0; }
.sw.s1, .relleno.s1 { background: var(--serie-1); }
.sw.s2 { background: var(--serie-2); }
.barras { display: grid; gap: 10px; }
.barra { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 10px; align-items: center; border-radius: 6px; padding: 2px 4px; }
.barra:hover, .barra:focus { background: var(--surface-2); outline: none; }
.barra .et { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra .pista { height: 16px; display: block; }
.barra .relleno { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.barra .val { font-size: .85rem; color: var(--fg); min-width: 72px; text-align: right; }
.hero { font-family: var(--f-body); font-size: 3rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.meter { height: 8px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
details.datos summary { cursor: pointer; font-size: .85rem; color: var(--muted); font-weight: 600; }
details.datos[open] summary { margin-bottom: 8px; }
.tip { position: fixed; z-index: 70; pointer-events: none; background: var(--fg); color: var(--bg); padding: 8px 10px; border-radius: 8px; font-size: .82rem; line-height: 1.5; box-shadow: var(--shadow); max-width: 260px; }
.tip i { font-style: normal; }

@media (max-width: 640px) {
  .hero { font-size: 2.3rem; }
  .tabs { margin-left: 0; width: 100%; }
  .paper { padding: 16px; }
  .paper .ptitle { text-align: left; }
  h1 { font-size: 1.35rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.acciones-dia { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.acciones-dia .field { min-width: 240px; }
