:root {
  --bg: #ffffff;
  --surface: #f5f5f3;
  --text: #1f1f1d;
  --text-2: #5f5e5a;
  --muted: #8a8983;
  --line: rgba(0, 0, 0, 0.09);
  --line-2: rgba(0, 0, 0, 0.16);
  --accent: #0f6e56;
  --accent-soft: #e1f5ee;
  --warn: #854f0b;
  --notif: #a8923f; /* notifications: muted yellow */
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1b;
    --surface: #262625;
    --text: #ecebe6;
    --text-2: #b4b2a9;
    --muted: #888780;
    --line: rgba(255, 255, 255, 0.09);
    --line-2: rgba(255, 255, 255, 0.18);
    --accent: #5dcaa5;
    --accent-soft: rgba(93, 202, 165, 0.14);
    --warn: #fac775;
    --notif: #b9a865;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
.pagina { max-width: 1040px; margin: 0 auto; padding: 28px 24px 48px; }
@media (max-width: 600px) { .pagina { padding: 16px; } }
h1 { font-size: 19px; font-weight: 600; margin: 0; }
h2 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.muted { color: var(--muted); font-size: 13px; }
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.marca { display: flex; align-items: center; gap: 10px; }

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
input[type=date], .ms-buscar {
  height: 34px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 0 10px;
  background: var(--bg);
  font-size: 14px;
}

/* filters */
.filtros { display: grid; gap: 12px; }
.fila { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.fila.dos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 600px) { .fila.dos { grid-template-columns: 1fr; } }
.fechas { display: flex; align-items: center; gap: 8px; }

.seg { display: inline-flex; flex-wrap: wrap; background: var(--surface); border-radius: var(--radius); padding: 3px; gap: 2px; }
.seg button { padding: 5px 12px; border-radius: 6px; font-size: 13px; color: var(--text-2); }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 0 0 1px var(--line-2); }

.switch-lbl { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.sw { width: 32px; height: 18px; border-radius: 9px; background: var(--line-2); padding: 0; position: relative; }
.sw span { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .15s; }
.sw[aria-checked=true] { background: var(--accent); }
.sw[aria-checked=true] span { left: 16px; }

/* multi-select */
.ms { position: relative; }
.ms-caja {
  min-height: 34px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 3px 28px 3px 6px;
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  cursor: pointer; position: relative;
}
.ms-caja::after { content: "▾"; position: absolute; right: 10px; top: 6px; color: var(--muted); font-size: 12px; }
.ms-ph { color: var(--muted); font-size: 14px; padding-left: 4px; }
.tag { font-size: 12px; background: var(--accent-soft); color: var(--accent); border-radius: 5px; padding: 1px 2px 1px 8px; display: inline-flex; align-items: center; }
.tag button { padding: 0 6px; font-size: 13px; color: inherit; }
.ms-panel {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}
.ms-buscar { width: 100%; }
.ms-lista { max-height: 260px; overflow-y: auto; margin-top: 6px; }
.ms-op { display: flex; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.ms-op:hover { background: var(--surface); }
.ms-pie { display: flex; justify-content: space-between; margin-top: 6px; }
.ms-pie button { font-size: 13px; color: var(--accent); padding: 4px 6px; }

/* totals */
.estado { min-height: 20px; margin: 18px 0 4px; font-size: 13px; color: var(--muted); }
.metricas { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 760px) { .metricas { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.metrica p { margin: 0; }
.m-tit { font-size: 13px; color: var(--text-2); }
.m-val { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.m-notif { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 2px; font-size: 13px; color: var(--notif); font-variant-numeric: tabular-nums; }
.m-notif > div { display: flex; flex-direction: column; white-space: nowrap; }
.m-sub { font-size: 11px; opacity: .8; }
.pie-metricas { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0 20px; flex-wrap: wrap; }
.acciones { display: flex; gap: 4px; }
.link { font-size: 13px; color: var(--accent); padding: 4px 8px; border-radius: 6px; }
.link:hover { background: var(--accent-soft); }

/* tables */
.scroll { overflow-x: auto; }
.t { width: 100%; border-collapse: collapse; font-size: 13px; }
.t th, .t td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t th { font-weight: 500; color: var(--muted); text-align: left; font-size: 12px; white-space: nowrap; }
.t th[data-col] { cursor: pointer; user-select: none; }
.t th[data-col]:hover, .t th.ordenada { color: var(--text); }
.flecha { font-size: 10px; margin-left: 4px; }
.t .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t tbody tr:last-child td { border-bottom: 0; }
.sub { font-size: 12px; color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.vacio { color: var(--muted); text-align: center; padding: 24px; }

.cp { cursor: copy; border-radius: 4px; padding: 0 2px; }
.cp:hover { background: var(--accent-soft); }

.aviso { font-size: 12px; color: var(--notif); margin: 2px 0 0; }

/* notifications in the table: a second, smaller row under each row's totals */
.t .sub-enc th { color: var(--notif); font-size: 11px; padding-top: 0; }
.t .sub-enc th[data-col]:hover, .t .sub-enc th.ordenada { color: var(--warn); }
/* with notifications: equal-width sub-columns (a C2C group is twice an externas column),
   everything right-aligned, and a thin line where each group starts */
.t.con-notif { table-layout: fixed; }
.t.con-notif #thClave { width: 22%; }
.t.con-notif thead tr:first-child th:not(#thClave) { border-bottom: 0; white-space: normal; vertical-align: bottom; }
.t.con-notif .g { border-left: 1px solid var(--line); padding-left: 12px; }
.t tr.fila-d td:not([rowspan]) { border-bottom: 0; padding-bottom: 0; }
/* C2C groups: centered, with a short rule under the merged total over its two parts */
.t.con-notif th[colspan="2"], .t.con-notif .c2c { text-align: center; }
.t tr.fila-d td[colspan="2"] {
  text-align: center;
  padding-bottom: 3px;
  background: linear-gradient(var(--line-2), var(--line-2)) no-repeat center bottom / 70% 1px;
}
.t tr.fila-n td { padding-top: 1px; }
.t td.n { color: var(--notif); font-size: 12px; }
.t tbody tr.fila-d:nth-last-child(2) td[rowspan] { border-bottom: 0; }

/* login */
.login { max-width: 300px; margin: 18vh auto 0; padding: 0 24px; display: grid; gap: 20px; justify-items: center; }
.login form { display: grid; gap: 10px; width: 100%; }
.login input {
  height: 38px; border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 0 12px; background: var(--bg); font-size: 15px;
}
.login button[type=submit] {
  height: 38px; border-radius: var(--radius); background: var(--accent); color: #fff; font-weight: 600;
}
@media (prefers-color-scheme: dark) { .login button[type=submit] { color: #04342c; } }
.login .muted { text-align: center; }
.error { color: #c0392b; font-size: 13px; margin: 0; text-align: center; }
.salir { font-size: 13px; color: var(--muted); text-decoration: none; margin-left: 14px; }
.salir:hover { color: var(--text); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  font-size: 13px; padding: 7px 14px; border-radius: var(--radius);
  opacity: 0; transition: opacity .15s; pointer-events: none;
}
#toast.on { opacity: 1; }
