:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --grid: #ebeae6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #767570;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  /* Etapas: gris neutro -> azul -> verde (con etiqueta y leyenda siempre) */
  --stage-todo: #9a9891;
  --stage-doing: #2a78d6;
  --stage-done: #0ca30c;
  --series: #2a78d6;
  --sev-alta: #d03b3b;
  --sev-media: #ec835a;
  --sev-baja: #8f8d86;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  /* Resultado de un issue en su sprint */
  --out-carried: #eb6834;
  --out-cancel: #d6d4ce;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --grid: #2a2a28;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --stage-todo: #77766f;
    --stage-doing: #3987e5;
    --stage-done: #0ca30c;
    --series: #3987e5;
    --sev-baja: #9a998f;
    --shadow: none;
    --out-carried: #d95926;
    --out-cancel: #45443f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #2f2f2c; --grid: #2a2a28;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #9a998f; --accent: #3987e5; --accent-ink: #86b6ef;
  --stage-todo: #77766f; --stage-doing: #3987e5; --stage-done: #0ca30c; --series: #3987e5;
  --sev-baja: #9a998f; --shadow: none; --out-carried: #d95926; --out-cancel: #45443f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-3); }
h1 { font-size: 18px; margin: 0; font-weight: 650; }
h2 { font-size: 14px; margin: 0 0 12px; font-weight: 600; }

/* ---------- Barra superior y pestañas ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.subtitle { color: var(--text-3); font-size: 12px; }
.sync { display: flex; gap: 12px; align-items: center; font-size: 12px; }
.btn {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: default; }

.tabs {
  display: flex; gap: 4px; padding: 0 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tab {
  font: inherit; background: none; border: 0; padding: 12px 14px; cursor: pointer; color: var(--text-2);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px; border-radius: 9px;
  background: var(--sev-alta); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

main { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }

/* ---------- Tarjetas y rejilla ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card-note { color: var(--text-3); font-size: 12px; margin: -6px 0 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  box-shadow: var(--shadow);
}
.tile .label { color: var(--text-2); font-size: 12px; }
.tile .value { font-size: 28px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .value.hero { font-size: 34px; }
.tile .detail { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.tile.link { cursor: pointer; }
.tile.link:hover { border-color: var(--accent); }

/* ---------- Barras horizontales ---------- */
.bars { display: grid; grid-template-columns: minmax(90px, 32%) 1fr; gap: 6px 10px; align-items: center; }
.bar-label { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* El padding derecho reserva el espacio del número: el ancho % de la barra se mide sin él. */
.bar-track { display: flex; align-items: center; min-width: 0; padding-right: 56px; }
.bar {
  height: 14px; border-radius: 0 4px 4px 0; background: var(--series); min-width: 2px; flex: none;
}
.bar.other { background: var(--stage-todo); }
.bar-value {
  font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap;
  margin-left: 6px; margin-right: -56px;
}

/* Barra apilada: 2px de superficie entre segmentos, extremos redondeados */
.stack { display: flex; gap: 2px; height: 14px; flex: none; min-width: 2px; }
.stage-split .stack { width: 100%; }
.stack.big { height: 22px; }
.seg { height: 100%; min-width: 2px; }
.seg:first-child { border-radius: 0; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.stage-todo { background: var(--stage-todo); }
.stage-doing { background: var(--stage-doing); }
.stage-done { background: var(--stage-done); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); margin: 0 0 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.stage-summary { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.stage-summary b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Filtros ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters input, .filters select {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.filters input[type="search"] { min-width: 260px; flex: 1; max-width: 380px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button {
  font: inherit; font-size: 13px; padding: 6px 12px; border: 0; background: var(--surface);
  color: var(--text-2); cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ---------- Tablas ---------- */
.table-wrap {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
  position: sticky; top: 0;
}
.table td { padding: 8px 12px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .title { max-width: 380px; }
.table .title > span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.table .sub { color: var(--text-3); font-size: 12px; }
.table .empty { text-align: center; color: var(--text-3); padding: 32px; }
.nowrap { white-space: nowrap; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; color: var(--text);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.sev { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sev::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.sev-alta { color: var(--sev-alta); }
.sev-media { color: var(--sev-media); }
.sev-baja { color: var(--sev-baja); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; font-size: 12px; color: var(--text-2); }

/* ---------- Reglas de desalineación ---------- */
.rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-bottom: 14px; }
.rule {
  text-align: left; font: inherit; color: inherit; cursor: pointer; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow);
}
.rule[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.rule .count { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.rule .name { font-weight: 600; margin: 2px 0 4px; }
.rule .hint { color: var(--text-3); font-size: 12px; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 280px;
  background: var(--text); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 6px;
}
[data-tip] { cursor: default; }

.error { color: var(--sev-alta); padding: 12px; }

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar, .tabs { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .filters input[type="search"] { min-width: 0; max-width: none; width: 100%; }
}

/* ================= Explorador de sprints ================= */
.out-completado { background: var(--stage-done); }
.out-en_curso { background: var(--stage-doing); }
.out-por_hacer { background: var(--stage-todo); }
.out-arrastrado { background: var(--out-carried); }
.out-cancelado { background: var(--out-cancel); }

.explorer-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 15px; }
.crumbs a { cursor: pointer; }
.crumbs .sep { color: var(--text-3); }
.crumbs .here { font-weight: 650; }
.ex-filter { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.ex-filter select {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .label { color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .value.hero { font-size: 32px; }
.kpi .detail { color: var(--text-3); font-size: 12px; }
.sprint-meta { color: var(--text-2); font-size: 13px; margin: -4px 0 14px; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.state-chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.state-chip.active { background: var(--accent); color: #fff; }

/* Filas clicables (zoom) */
.zoom-rows { display: grid; grid-template-columns: minmax(110px, 26%) 1fr auto; gap: 4px 12px; align-items: center; }
.zoom-row { display: contents; cursor: pointer; }
.zoom-row > * { padding: 5px 0; }
.zoom-row:hover > * { background: var(--surface-2); }
.zoom-row:focus-visible > * { outline: 2px solid var(--accent); outline-offset: -2px; }
.zoom-row .zr-label { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 6px; border-radius: 6px 0 0 6px; }
.zoom-row .zr-label .sub { display: block; font-size: 11px; color: var(--text-3); }
.zoom-row .zr-bar { min-width: 0; }
.zoom-row .zr-stat { font-size: 12px; color: var(--text-2); text-align: right; white-space: nowrap; padding-right: 8px; border-radius: 0 6px 6px 0; font-variant-numeric: tabular-nums; }
.zoom-row .zr-stat b { color: var(--text); font-size: 13px; }
.zoom-row.future .zr-label { color: var(--text-3); }
.zoom-hint { color: var(--text-3); font-size: 12px; margin: -6px 0 10px; }

/* Matriz sprint x tipo */
.matrix-wrap { overflow-x: auto; }
.matrix { border-collapse: separate; border-spacing: 2px; font-size: 12px; width: 100%; }
.matrix th { font-weight: 600; color: var(--text-2); padding: 4px 6px; text-align: center; white-space: nowrap; }
.matrix th.row { text-align: left; }
.matrix td.cell {
  text-align: center; padding: 6px 4px; border-radius: 4px; cursor: pointer; min-width: 58px;
  font-variant-numeric: tabular-nums; line-height: 1.2;
}
.matrix td.cell:hover { outline: 2px solid var(--text); outline-offset: -2px; }
.matrix td.cell .c-main { font-weight: 650; }
.matrix td.cell .c-sub { font-size: 10px; opacity: .85; }
.matrix td.empty { color: var(--text-3); text-align: center; }
.heat-0 { background: #cde2fb; color: #0b0b0b; }
.heat-1 { background: #9ec5f4; color: #0b0b0b; }
.heat-2 { background: #6da7ec; color: #0b0b0b; }
.heat-3 { background: #3987e5; color: #fff; }
.heat-4 { background: #256abf; color: #fff; }
.heat-5 { background: #184f95; color: #fff; }
.heat-na { background: var(--surface-2); color: var(--text-2); }
.heat-legend { display: flex; align-items: center; gap: 2px; font-size: 11px; color: var(--text-3); margin-top: 8px; }
.heat-legend i { width: 22px; height: 10px; display: inline-block; }
.heat-legend span { margin: 0 6px; }

.outcome { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; }
.outcome .dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.carry-flag { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }

/* Panel lateral del issue */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 20;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -8px 0 24px rgba(0, 0, 0, .12);
  display: flex; flex-direction: column;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
#ex-drawer-body { padding: 16px 18px; overflow-y: auto; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; margin: 12px 0 18px; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; }
.timeline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 18px; }
.timeline .chip { font-size: 12px; padding: 3px 9px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.timeline .chip.active { border-color: var(--accent); }
.timeline .arrow { color: var(--text-3); }
.drawer h3 { font-size: 13px; margin: 16px 0 8px; }
.mini-list { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.mini-list li { padding: 6px 0; border-bottom: 1px solid var(--grid); display: flex; gap: 8px; align-items: baseline; }
.mini-list li:last-child { border-bottom: 0; }

/* Velocidad por equipo */
.vel-grid { overflow-x: auto; }
.vel-row {
  display: grid; grid-template-columns: minmax(110px, 14%) minmax(240px, 1fr) repeat(5, 84px);
  gap: 10px; align-items: end; padding: 6px 6px; border-radius: 6px; min-width: 780px;
}
.vel-row[data-team] { cursor: pointer; }
.vel-row[data-team]:hover { background: var(--surface-2); }
.vel-row[data-team]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.vel-head { align-items: center; font-size: 11px; color: var(--text-3); font-weight: 600; border-bottom: 1px solid var(--grid); border-radius: 0; }
.vel-team { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: center; }
.vel-bars { display: grid; gap: 2px; height: 36px; align-items: end; }
.vel-head .vel-bars { height: auto; }
.vel-slot { height: 100%; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--grid); }
.vel-bar { width: 100%; max-width: 24px; background: var(--series); border-radius: 4px 4px 0 0; }
.vel-bar.current { opacity: .45; }
.vel-slot-label { text-align: center; font-size: 10px; }
.vel-num { text-align: right; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; align-self: center; white-space: nowrap; }
.vel-num b { color: var(--text); }
.vel-warn { color: var(--sev-media); }
.cyc-bar { background: var(--accent-ink); }
.card-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-start; justify-content: space-between; }
.card-head h2 { margin-bottom: 8px; }

/* Matriz tipo x sprint a todo el ancho */
.matrix-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.matrix th.row { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 120px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.matrix td.cell { min-width: 64px; padding: 8px 4px; }
.matrix td.cell .c-main { font-size: 13px; }
.matrix.dense td.cell { min-width: 44px; padding: 6px 2px; }
.matrix.dense td.cell .c-main { font-size: 12px; }
.matrix.dense th { padding: 4px 2px; font-size: 11px; }

/* Filtro raíz: tablero de Jira */
.board-filter { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); margin-left: auto; margin-right: 16px; }
.board-filter select {
  font: inherit; font-size: 14px; font-weight: 600; padding: 7px 12px; border-radius: 8px; min-width: 240px; max-width: 360px;
  border: 1px solid var(--accent); background: var(--surface); color: var(--text);
}
.board-banner {
  padding: 8px 24px; font-size: 12px; color: var(--text-2); background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.link-btn { font: inherit; border: 0; background: none; color: var(--accent-ink); cursor: pointer; padding: 0 0 0 8px; text-decoration: underline; }
@media (max-width: 640px) {
  .board-filter { margin: 0; width: 100%; }
  .board-filter select { flex: 1; min-width: 0; }
  .board-banner { padding: 8px 16px; }
}

/* ================= Inicio de sesión ================= */
.login-page { min-height: 100vh; display: flex; }
.login-wrap { margin: auto; width: 100%; max-width: 400px; padding: 24px 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 26px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .06); display: flex; flex-direction: column; gap: 14px;
}
.login-brand { text-align: center; margin-bottom: 6px; }
.login-brand h1 { font-size: 20px; margin-top: 12px; }
.login-brand p { margin: 4px 0 0; font-size: 13px; }
.login-mark { display: inline-flex; gap: 3px; height: 26px; align-items: flex-end; }
.login-mark span { width: 8px; border-radius: 3px 3px 0 0; }
.login-mark span:nth-child(1) { height: 12px; }
.login-mark span:nth-child(2) { height: 19px; }
.login-mark span:nth-child(3) { height: 26px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.field input {
  font: inherit; font-size: 15px; padding: 10px 12px; border-radius: 8px; width: 100%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.password-row { position: relative; display: flex; align-items: center; }
.password-row input { padding-right: 76px; }
.password-row .link-btn { position: absolute; right: 10px; font-size: 12px; padding: 0; }
.login-error {
  margin: 0; font-size: 13px; color: var(--sev-alta); background: color-mix(in srgb, var(--sev-alta) 10%, transparent);
  border-radius: 8px; padding: 8px 10px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 10px 12px; font-size: 14px; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }
.login-foot { margin: 0; font-size: 12px; text-align: center; }

/* Usuario en la barra superior */
.user-box { display: inline-flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-2); }
.user-box b { color: var(--text); font-weight: 600; }
