/* ===== KNGT panel: colores de la plataforma (marfil, rojo, dorado) con modo oscuro ===== */
:root {
  color-scheme: light;
  --rojo: #8B0000; --rojo-osc: #5A0A0A; --dorado: #C7A44D; --pergamino: #DCCFA6; --bronce: #8C6239;
  --bg: #F3F1E6; --surf: #ffffff; --surf2: #faf8f0; --surf3: #f0eee5; --line: #e2ddcc; --line2: #f0ede1;
  --text: #0D0D0D; --soft: #5A5F66; --muted: #7E7E7E;
  --side-bg: #1b1410; --side-tx: #efe6d2; --side-soft: #b9ae95; --side-hover: #2c2219; --side-act: #8B0000;
  --ok-bg: #e6efe0; --ok-tx: #2f5426; --ok-bd: #9db88d;
  --bad-bg: #f3dcdc; --bad-tx: #5A0A0A; --bad-bd: #d4a3a3;
  --focus: #C7A44D;
  --radius: 12px; --shadow: 0 1px 3px rgba(13,13,13,.07), 0 4px 14px rgba(13,13,13,.04);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --rojo: #e2564c; --rojo-osc: #ef9186; --dorado: #d9b45c; --pergamino: #3c3220; --bronce: #d9a768;
  --bg: #15120d; --surf: #221d15; --surf2: #2b2419; --surf3: #332b1d; --line: #4a4030; --line2: #3a3124;
  --text: #efe9db; --soft: #c9bfa8; --muted: #9c927c;
  --side-bg: #0f0c08; --side-tx: #efe6d2; --side-soft: #9c927c; --side-hover: #221b13; --side-act: #a32a22;
  --ok-bg: #1c2b16; --ok-tx: #8fd67a; --ok-bd: #4a6b3a;
  --bad-bg: #3a1b18; --bad-tx: #f0948a; --bad-bd: #7a4038;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--rojo); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h2 { font-size: 1.15rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- estructura ---------- */
.app { display: flex; min-height: 100vh; }
.side { width: 248px; flex: 0 0 248px; background: var(--side-bg); color: var(--side-tx); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 800; letter-spacing: .3px; border-bottom: 1px solid rgba(255,255,255,.07); }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--rojo-osc), #8B0000); color: #F3F1E6; font-size: 18px; }
nav { padding: 8px; flex: 1; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .8px; color: var(--side-soft); padding: 14px 10px 6px; font-weight: 700; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--side-tx); text-decoration: none; font-weight: 600; font-size: .93rem; }
.nav-item:hover { background: var(--side-hover); }
.nav-item.active { background: var(--side-act); color: #fff; }
.nav-item .ic { width: 20px; text-align: center; opacity: .9; }
.pill { margin-left: auto; background: var(--dorado); color: #1b1410; border-radius: 20px; font-size: .72rem; font-weight: 800; padding: 1px 8px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px; border-top: 1px solid rgba(255,255,255,.07); }
.side-user .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.side-user .who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user small { color: var(--side-soft); }
.side-user .icon-btn { color: var(--side-tx); border-color: rgba(255,255,255,.15); }
.av { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: 0 0 36px; background: var(--surf3); }
.av-txt { display: inline-grid; place-items: center; font-weight: 800; color: var(--text); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--surf); position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 1.2rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-tools { display: flex; align-items: center; gap: 8px; }
.content { padding: 22px; max-width: 1200px; width: 100%; }
.scrim { display: none; }
.only-mobile { display: none !important; }

/* ---------- componentes ---------- */
.card { background: var(--surf); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.narrow-wide { max-width: 720px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.big-ic { font-size: 42px; margin-bottom: 6px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; font-weight: 500; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surf2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; min-height: 40px; width: 100%; }
input[type="checkbox"] { width: auto; min-height: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--dorado); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--dorado) 25%, transparent); }
input[readonly] { color: var(--soft); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; font-size: .9rem; padding: 9px 14px; min-height: 40px; border-radius: 9px; border: 1px solid var(--line); background: var(--surf); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--dorado); }
.btn-primary { background: var(--rojo); border-color: var(--rojo-osc); color: #fff; }
html[data-theme="dark"] .btn-primary { color: #1b1410; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--bad-tx); border-color: var(--bad-bd); background: var(--bad-bg); }
.btn-discord { background: #5865F2; border-color: #4752c4; color: #fff; }
.btn-discord:hover { filter: brightness(1.08); border-color: #4752c4; }
.btn-block { width: 100%; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; font-size: 17px; }
.alert { border-radius: 9px; padding: 10px 14px; margin-bottom: 14px; font-size: .92rem; border: 1px solid; }
.alert-ok { background: var(--ok-bg); color: var(--ok-tx); border-color: var(--ok-bd); }
.alert-err { background: var(--bad-bg); color: var(--bad-tx); border-color: var(--bad-bd); }
.tag { display: inline-block; font-size: .72rem; font-weight: 800; border-radius: 20px; padding: 2px 9px; background: var(--surf3); color: var(--soft); vertical-align: middle; }
.tag-admin { background: var(--rojo); color: #fff; }
.tag-leader { background: var(--dorado); color: #1b1410; }
.tag-collab { background: #dbe7f5; color: #23476e; }
html[data-theme="dark"] .tag-collab { background: #16283b; color: #7ec2f5; }
.tag-member { background: var(--surf3); color: var(--soft); }
.tag-ok { background: var(--ok-bg); color: var(--ok-tx); } .tag-bad { background: var(--bad-bg); color: var(--bad-tx); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0 0 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.secret { display: inline-block; padding: 6px 10px; background: var(--surf3); border-radius: 8px; letter-spacing: 1px; word-break: break-all; }
.qr { width: 200px; height: 200px; margin: 6px auto 10px; background: #fff; border-radius: 10px; padding: 6px; }
.qr svg { width: 100%; height: 100%; display: block; }
.copy-row { display: flex; gap: 8px; }

/* ---------- usuarios ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--surf); border: 1px solid var(--line); border-radius: 10px; padding: 3px; padding: 3px; flex-wrap: wrap; }
.seg a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--soft); font-weight: 700; font-size: .9rem; }
.seg a.on { background: var(--rojo); color: #fff; }
html[data-theme="dark"] .seg a.on { color: #1b1410; }
.seg .cnt { font-size: .75rem; opacity: .85; margin-left: 3px; }
.search input { width: 240px; }
.user-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.user-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; background: var(--surf); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.u-main { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 280px; }
.u-main > div { min-width: 0; }
.u-actions { display: flex; flex-wrap: wrap; gap: 8px; }
form.inline { display: inline-flex; gap: 6px; align-items: center; }
form.inline select { width: auto; }
.roles-help ul { margin: 10px 0 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.roles-help summary { cursor: pointer; font-weight: 700; }

/* ---------- tabla ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); border-bottom: 2px solid var(--dorado); padding: 8px; white-space: nowrap; }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.tbl td.wrap { white-space: normal; max-width: 360px; word-break: break-word; }
.tbl tr.warn td { background: var(--bad-bg); }

/* ---------- pantallas sin menu (login) ---------- */
body.bare { min-height: 100vh; background: radial-gradient(circle at 30% 0%, color-mix(in srgb, var(--rojo) 18%, var(--bg)), var(--bg) 60%); }
.bare-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 14px; }
.bare-card { width: 100%; max-width: 420px; background: var(--surf); border: 1px solid var(--line); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
.bare-brand { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; margin-bottom: 18px; }
.bare-title { font-size: 1.3rem; }
.bare-foot { display: flex; gap: 8px; align-items: center; }
.bare-foot select { width: auto; }

/* ---------- movil ---------- */
@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s ease; z-index: 30; box-shadow: 4px 0 20px rgba(0,0,0,.3); }
  body.side-open .side { transform: none; }
  body.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
  .only-mobile { display: inline-grid !important; }
  .top { padding: 10px 16px; }
  .content { padding: 16px; }
  .lang-form select { width: auto; max-width: 110px; }
  .search, .search input { width: 100%; }
  .user-row { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ===== Fase 2: datos del clan ===== */
.m0 { margin: 0; } .mt { margin-top: 16px; } h3 { font-size: 1rem; margin: 8px 0; }
.grow { flex: 1; min-width: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.grid-6 { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: .8rem; }
.week-sel select { width: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surf); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi small { color: var(--muted); font-size: .78rem; font-weight: 600; }
.kpi b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.av.sm { width: 28px; height: 28px; flex-basis: 28px; font-size: .8rem; }
.av.lg { width: 72px; height: 72px; flex-basis: 72px; border-radius: 14px; font-size: 1.6rem; }
.rk { display: inline-block; font-size: .7rem; font-weight: 800; border-radius: 6px; padding: 1px 6px; background: var(--surf3); color: var(--soft); vertical-align: middle; }
.rk-R5 { background: var(--rojo); color: #fff; } .rk-R4 { background: var(--dorado); color: #1b1410; }
.rk-R3 { background: #dbe7f5; color: #23476e; } html[data-theme="dark"] .rk-R3 { background: #16283b; color: #7ec2f5; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.low, .daygrid .low { background: var(--bad-bg); color: var(--bad-tx); }
.low-tx { color: var(--bad-tx); } .ok-tx { color: var(--ok-tx); }
tr.dim td { opacity: .55; }
.tbl tfoot td { border-top: 2px solid var(--dorado); background: var(--surf2); }
.rank-tbl td:nth-child(2) { white-space: nowrap; }
.toplist { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.toplist li { display: flex; align-items: center; gap: 8px; }
.toplist .pos { width: 22px; text-align: center; font-weight: 800; color: var(--muted); }
.toplist .num { margin-left: auto; }
.duel-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.duel-head > div { display: flex; flex-direction: column; }
.duel-head .right { text-align: right; }
.duel-score { flex-direction: row !important; gap: 8px; align-items: baseline; font-size: 1.8rem; font-weight: 800; }
.bar { width: 100%; height: 10px; border-radius: 6px; margin: 12px 0 4px; display: block; overflow: hidden; }
.bar .b-us { fill: var(--rojo); } .bar .b-them { fill: var(--surf3); }
.duel-tot { display: flex; justify-content: space-between; font-weight: 700; font-variant-numeric: tabular-nums; }
.duel-days { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 12px; }
.dd { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border-radius: 8px; background: var(--surf2); font-size: .8rem; font-variant-numeric: tabular-nums; }
.dd.win { background: var(--ok-bg); } .dd.loss { background: var(--bad-bg); }
.profile { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.profile .kpi { min-width: 130px; }
.daygrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.daygrid > div { background: var(--surf2); border-radius: 8px; padding: 6px; text-align: center; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.daygrid small { color: var(--muted); }
.spark { width: 100%; height: 70px; display: block; }
.spark polyline { fill: none; stroke: var(--rojo); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chip { display: inline-block; background: var(--surf3); border-radius: 6px; padding: 2px 7px; margin: 0 4px 4px 0; }
.pre { white-space: pre-wrap; }
.inline-lbl { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-weight: 500; }
.inline-lbl select { width: auto; max-width: 260px; }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
summary { cursor: pointer; }
@media (max-width: 860px) { .duel-days, .daygrid { grid-template-columns: repeat(3, 1fr); } }
