/* Estilos compartidos por index.html y candidatos.html. */

/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #edece8;
  --border:    #dcdbd5;
  --border-strong: #c2c1b9;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #76756f;
  --accent:      #2a78d6;
  --accent-ink:  #1c5cab;
  --good:        #1baf7a;
  --good-ink:    #0f6f4d;
  --warn-bg:     #fdf4e0;
  --warn-border: #eda100;
  --warn-ink:    #7a5300;
  --danger:      #e34948;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #131312;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --border:    #343432;
    --border-strong: #4a4a47;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #949389;
    --accent:      #3987e5;
    --accent-ink:  #86b6ef;
    --good:        #199e70;
    --good-ink:    #5fd0a6;
    --warn-bg:     #3a2f14;
    --warn-border: #c98500;
    --warn-ink:    #eda100;
    --danger:      #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #131312;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --border:    #343432;
  --border-strong: #4a4a47;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #949389;
  --accent:      #3987e5;
  --accent-ink:  #86b6ef;
  --good:        #199e70;
  --good-ink:    #5fd0a6;
  --warn-bg:     #3a2f14;
  --warn-border: #c98500;
  --warn-ink:    #eda100;
  --danger:      #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 16px 72px; }

h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent-ink); }

/* --------------------------------------------------------------- header */
.top {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px;
}
.top .sub { color: var(--text-secondary); font-size: .9rem; margin-top: 4px; max-width: 62ch; }
/* Qué elección está cargada: el h1 nombra la herramienta, esto el dato */
.eleccion-actual { font-size: 1rem; font-weight: 600; color: var(--accent-ink); margin-top: 2px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }

.nav { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.nav a {
  padding: 8px 14px; font-size: .875rem; font-weight: 550;
  color: var(--text-secondary); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.nav a:hover { color: var(--text-primary); }
.nav a[aria-current="page"] { color: var(--text-primary); border-bottom-color: var(--accent); }
/* Qué se carga en cada página, para que la diferencia se entienda sin entrar */
.nav a .desc { font-weight: 400; font-size: .78rem; color: var(--text-muted); }
.nav a[aria-current="page"] .desc { color: var(--text-secondary); }
.nav a .desc::before { content: "· "; }
@media (max-width: 560px) { .nav a .desc { display: none; } }

/* -------------------------------------------------------------- controles */
button, .btn {
  font: inherit; font-size: .875rem; font-weight: 550;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
button:hover { background: var(--surface-2); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
button.ghost:hover { background: var(--surface-2); color: var(--text-primary); }
button.danger { color: var(--danger); }
button.tiny { padding: 3px 8px; font-size: .78rem; }

input[type="text"], input[type="number"], select, textarea {
  font: inherit; font-size: .875rem;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 9px;
  width: 100%;
}
textarea { line-height: 1.55; resize: vertical; }
input[type="number"] { font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ------------------------------------------------------------- contenedores */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 20px;
}
.card > header { display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.card > header .hint { color: var(--text-muted); font-size: .82rem; }
.paso { font-family: var(--mono); font-size: .75rem; font-weight: 650; color: var(--accent-ink); letter-spacing: .06em; text-transform: uppercase; }

.config { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.field label { display: block; font-size: .78rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.field .note { font-size: .72rem; color: var(--text-muted); margin-top: 4px; }

/* ----------------------------------------------------------- stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat .k { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.stat .v { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .d { font-size: .78rem; color: var(--text-secondary); }

/* ---------------------------------------------------------- lista (ficha) */
.listas { display: flex; flex-direction: column; gap: 10px; }
.lista { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1); overflow: hidden; }
.lista.electa { border-color: var(--border-strong); }
.lista-head {
  display: grid;
  grid-template-columns: 6px 44px minmax(0,1fr) 132px 82px 96px;
  align-items: center; gap: 12px;
  padding: 10px 12px 10px 0;
}
.lista-color { align-self: stretch; margin: -10px 0; min-height: 46px; }
.lista-num { font-family: var(--mono); font-size: 1rem; font-weight: 650; text-align: center; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.lista-nombre { min-width: 0; }
.lista-nombre .p { font-weight: 600; overflow-wrap: anywhere; }
.lista-nombre .s { font-size: .78rem; color: var(--text-muted); }
.lista-votos { display: flex; align-items: center; gap: 6px; }
.lista-pct { font-size: .82rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; text-align: right; }
.lista-bancas { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.bancas-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 26px; padding: 0 8px;
  border-radius: 7px; font-weight: 650; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-secondary);
}
.bancas-badge.win { background: var(--accent); border-color: var(--accent); color: #fff; }
.lista-body { border-top: 1px solid var(--border); padding: 14px; background: var(--surface-0); }
.cand-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }

/* ---------------------------------------------------------- seat ribbon */
.ribbon { display: flex; width: 100%; height: 46px; gap: 2px; margin: 4px 0 12px; }
.ribbon-seg { min-width: 2px; border-radius: 3px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.ribbon-seg span { font-size: .76rem; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.45); white-space: nowrap; padding: 0 4px; }
.seats-grid { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 14px; }
.seat-dot { width: 17px; height: 17px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface-1); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .8rem; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .chip { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* --------------------------------------------------------------- tablas */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 650; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tr.total td { font-weight: 650; border-top: 2px solid var(--border-strong); }
td .chip, th .chip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: baseline; }
td.nombre { white-space: normal; min-width: 180px; }
tr.electo td { background: color-mix(in srgb, var(--good) 13%, transparent); }
tr.electo td.nombre { font-weight: 600; }

.qtable td { font-variant-numeric: tabular-nums; }
.qtable td.hit { background: color-mix(in srgb, var(--accent) 16%, transparent); font-weight: 650; }
.qtable td.hit .r { font-size: .7rem; color: var(--text-secondary); margin-left: 5px; }
.qtable th.div { color: var(--text-secondary); }

/* ----------------------------------------------------------------- misc */
.callout {
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  border-radius: 10px; padding: 12px 14px; font-size: .85rem;
  color: var(--warn-ink); margin-bottom: 20px;
}
.empty { color: var(--text-muted); font-size: .88rem; padding: 10px 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grow { flex: 1 1 auto; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 24px; height: 24px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { border-color: var(--text-primary); }
.tag-electo { font-size: .7rem; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; color: var(--good-ink); }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-1); color: var(--text-primary);
  padding: 0; width: min(620px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg-body { padding: 18px; }
dialog .dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-0); }

.footer { color: var(--text-muted); font-size: .8rem; margin-top: 28px; line-height: 1.6; }

@media (max-width: 720px) {
  .lista-head {
    grid-template-columns: 6px 38px 1fr;
    grid-template-areas: "c n p" ". v v" ". b b";
    row-gap: 8px; padding-right: 12px;
  }
  .lista-color { grid-area: c; } .lista-num { grid-area: n; } .lista-nombre { grid-area: p; }
  .lista-votos { grid-area: v; } .lista-bancas { grid-area: b; justify-content: flex-start; }
  .lista-pct { display: none; }
}
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
}
