:root {
  --page: #eceff4; --surface: #fff; --ink: #0d1626; --ink-2: #2a3446; --muted: #576072; --line: #e1e5ec; --soft: #f4f6f9;
  --navy: #13213b; --gold: #f4c24f; --ok: #13655b; --okbg: #ddf2ee; --warn: #7d5908; --warnbg: #fcefcf; --bad: #a12a2a; --badbg: #fbe3e3;
  --font: "Inter", system-ui, sans-serif; --display: "Inter Tight", "Inter", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14.5px/1.45 var(--font); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .grow { flex: 1; }

.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-size: 19px; color: #344360; }
.logo b { color: var(--ink); }
.badge { padding: 3px 10px; border-radius: 999px; background: var(--navy); color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.who { margin-left: auto; color: var(--muted); font-size: 13px; }

.wrap { max-width: 1180px; margin: 22px auto; padding: 0 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.login { max-width: 420px; margin: 60px auto; padding: 28px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-family: var(--display); font-size: 26px; letter-spacing: -.02em; }
.login p { margin: 0; }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy); outline-offset: -1px; }
label.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.chk input { width: auto; }
.err { margin: 0; color: var(--bad); font-weight: 600; min-height: 1.2em; }

.btn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 16px; border: 1px solid var(--navy); border-radius: 9px; background: var(--navy); color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.15); }
.btn--ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { background: var(--soft); filter: none; }
.btn--danger { background: #fff; color: var(--bad); border-color: #efc4c4; }
.btn:disabled { opacity: .5; cursor: wait; }
.file { cursor: pointer; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab { height: 38px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.tab.is-on { background: var(--navy); color: #fff; }
.bar { display: flex; gap: 10px; margin-bottom: 12px; }
.bar input { flex: 1; }

.list { width: 100%; border-collapse: collapse; }
.list th, .list td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--soft); vertical-align: middle; }
.list th { background: var(--soft); font-size: 12px; color: var(--muted); font-weight: 600; }
.list tr[data-id] { cursor: pointer; }
.list tr[data-id]:hover td { background: #fafbfd; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill--jugado { background: var(--okbg); color: var(--ok); }
.pill--proximo { background: var(--navy); color: #fff; }
.pill--borrador { background: var(--soft); color: var(--muted); }

.dlg { width: min(1000px, calc(100% - 24px)); max-height: calc(100% - 32px); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 30px 80px -20px rgba(8, 14, 28, .6); }
.dlg--sm { width: min(560px, calc(100% - 24px)); }
.dlg::backdrop { background: rgba(10, 16, 30, .5); }
.dlg__in { display: grid; gap: 16px; padding: 20px 22px; }
.dlg__head { display: flex; align-items: center; justify-content: space-between; }
.dlg__head h2 { margin: 0; font-family: var(--display); font-size: 22px; letter-spacing: -.02em; }
.x { width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--soft); font-size: 22px; cursor: pointer; }
.dlg__foot { display: flex; gap: 10px; align-items: center; position: sticky; bottom: 0; background: #fff; padding-top: 10px; border-top: 1px solid var(--line); }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.span2 { grid-column: span 2; }
.dlg--sm .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.up-only .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.res { display: grid; gap: 10px; }
.res__head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.res__head h3 { margin: 0; font-size: 16px; }
.res__tools { display: flex; gap: 8px; flex-wrap: wrap; }
code { background: var(--soft); padding: 1px 6px; border-radius: 5px; }
.tablewrap { max-height: 380px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.rtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.rtable th { position: sticky; top: 0; background: var(--soft); text-align: left; padding: 7px 8px; font-size: 12px; color: var(--muted); z-index: 1; }
.rtable td { padding: 3px 4px; border-top: 1px solid var(--soft); }
.rtable input { padding: 6px 7px; border-color: transparent; background: transparent; }
.rtable input:hover { border-color: var(--line); }
.rtable .c-pos { width: 70px; } .rtable .c-cc { width: 140px; } .rtable .c-pts { width: 90px; } .rtable .c-who { width: 190px; } .rtable .c-x { width: 36px; }
.who-tag { display: inline-block; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.who-ok { background: var(--okbg); color: var(--ok); }
.who-new { background: var(--warnbg); color: var(--warn); }
.who-anon { background: var(--soft); color: var(--muted); }
.who-amb { background: var(--badbg); color: var(--bad); }
.rx { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; }

.check { display: grid; gap: 6px; }
.check p { margin: 0; padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
.check .ok { background: var(--okbg); color: var(--ok); }
.check .warn { background: var(--warnbg); color: var(--warn); }
.check .bad { background: var(--badbg); color: var(--bad); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 10px 18px; border-radius: 10px; background: var(--navy); color: #fff; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
.toast.on { opacity: 1; }

@media (max-width: 760px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .list .hide-m { display: none; }
  .top { padding: 12px 14px; }
}

.c-date { white-space: nowrap; color: var(--muted); font-size: 13px; }
.m-meta { display: none; }
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px 10px; }
  .who { display: none; }
  #logout { margin-left: auto; height: 34px; padding: 0 12px; }
  .wrap { margin: 14px auto; padding: 0 12px; }
  .bar { flex-direction: column; }
  .bar .btn { justify-content: center; }
  .list th { display: none; }
  .list tr[data-id] { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name st" "date st"; gap: 2px 10px; padding: 12px 14px; border-bottom: 1px solid var(--soft); }
  .list tr[data-id] td { padding: 0; border: 0; }
  .list .c-name { grid-area: name; }
  .list .c-date { grid-area: date; font-size: 12.5px; }
  .list .c-st { grid-area: st; align-self: center; }
  .m-meta { display: block; margin-top: 2px; font-size: 12.5px; color: var(--muted); font-weight: 400; }
}
@media (max-width: 760px) {
  .top { flex-wrap: nowrap; }
  .logo { font-size: 16px; gap: 7px; min-width: 0; }
  .logo span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .badge { font-size: 10.5px; padding: 2px 7px; }
}

.m-only { display: none; }
@media (min-width: 761px) { .list .m-meta { display: none; } }
@media (max-width: 760px) {
  .list .hide-m { display: none; }
  .list tr.logrow { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 12px 14px; border-bottom: 1px solid var(--soft); }
  .list tr.logrow td { padding: 0; border: 0; }
  .list .logrow .c-date { order: 2; }
  .m-only { display: table-cell; }
  .list .c-st.m-only { font-size: 22px; color: var(--muted); }
  .m-mail { word-break: break-all; font-size: 12px; }
}

/* ---------- Editor: scroll interno, pie fijo, movil ---------- */
.dlg { overflow: hidden; display: none; }
.dlg[open] { display: flex; }
.dlg__in { width: 100%; max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; padding-bottom: 0; }
.dlg__in:focus { outline: none; }
.dlg__foot { margin: 0 -22px; padding: 12px 22px; z-index: 3; box-shadow: 0 -8px 16px -12px rgba(13,22,38,.25); }
input[type="date"] { -webkit-appearance: none; appearance: none; min-width: 0; min-height: 40px; text-align: left; }
.grid > * { min-width: 0; }

@media (max-width: 760px) {
  .dlg { width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
  .dlg__in { padding: 16px 14px 0; gap: 14px; max-height: calc(100dvh - 16px); }
  .dlg__foot { margin: 0 -14px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .dlg__foot .btn { flex: 1; justify-content: center; }
  .dlg__foot .grow { display: none; }
  .dlg__foot { flex-wrap: nowrap; gap: 8px; }
  #ed-delete { flex: 0 0 auto; padding: 0 12px; }
  .dlg__head h2 { font-size: 20px; }
  .grid, .dlg--sm .grid, .up-only .grid { grid-template-columns: 1fr; gap: 10px; }
  .span2 { grid-column: auto; }
  .res__tools { display: grid; grid-template-columns: 1fr 1fr; }
  .res__tools .btn { justify-content: center; }
  .res__head .small code { word-break: break-word; }

  /* resultados como tarjetas */
  .tablewrap { max-height: none; overflow: visible; border: 0; }
  .rtable, .rtable tbody { display: block; }
  .rtable tr:first-child { display: none; }
  .rtable tr[data-i] { display: grid; grid-template-columns: 64px 1fr 36px; grid-template-areas: "pos name x" "mail mail mail" "cc pts pts" "who who who"; gap: 6px 8px; padding: 10px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
  .rtable td { padding: 0; border: 0; }
  .rtable td input { border-color: var(--line); background: #fff; }
  .rtable .r-pos { grid-area: pos; } .rtable .r-name { grid-area: name; } .rtable .r-mail { grid-area: mail; }
  .rtable .r-cc { grid-area: cc; } .rtable .r-pts { grid-area: pts; } .rtable .r-who { grid-area: who; } .rtable .r-x { grid-area: x; align-self: center; }
  .rtable td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
  .rtable .r-pos::before, .rtable .r-name::before { content: attr(data-l); }
  .who-tag { max-width: 100%; }
}

.addp { flex: 1 1 320px; }
.addp input { height: 38px; border-color: var(--navy); background: #fff; }
.addp input::placeholder { color: var(--ink-2); }
@media (max-width: 760px) { .addp { grid-column: 1 / -1; } }

.rtable select { width: 100%; text-overflow: ellipsis; padding: 6px 4px; border-color: transparent; background: transparent; }
.rtable select:hover { border-color: var(--line); }
@media (max-width: 760px) { .rtable td select { border-color: var(--line); background: #fff; } }

.rtable tr.is-dup td { background: var(--badbg); }
.rtable tr.is-dup td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
@media (max-width: 760px) { .rtable tr.is-dup { border-color: var(--bad); background: var(--badbg); } .rtable tr.is-dup td { background: none; box-shadow: none; } }
