:root {
  --blue: #025f7f;
  --blue-dark: #014a63;
  --blue-water: #186d8a;
  --blue-soft: #e6f0f3;
  --bg: #f4f7f8;
  --card: #ffffff;
  --text: #1f2b33;
  --muted: #55656f;
  --border: #dce5e9;
  --field-border: #8193a0;
  --ok: #2e7d5b;
  --ok-soft: #e5f3ec;
  --warn: #9a6412;
  --warn-soft: #fbf1df;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --radius: 10px;
  --serif: Perpetua, 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
}
[hidden] { display: none !important; }
a { color: var(--blue); }
h1, h2, h3 { font-family: var(--serif); font-weight: normal; color: var(--blue); line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.pad { padding: 2rem 0; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem max(16px, env(safe-area-inset-right)) .6rem max(16px, env(safe-area-inset-left));
  background: var(--blue); color: #fff;
}
.brand { display: flex; line-height: 0; }
.brand img { width: 84px; height: auto; }
.brand-sub { font-family: var(--serif); font-size: 1.15rem; letter-spacing: .04em; opacity: .9; border-left: 1px solid rgba(255,255,255,.35); padding-left: .75rem; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.who { opacity: .9; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { background: none; border: 1px solid rgba(255,255,255,.5); color: #fff; border-radius: 6px; padding: .3rem .8rem; min-height: 44px; font: inherit; cursor: pointer; }
.link-btn:hover { background: rgba(255,255,255,.12); }

.container { width: 100%; max-width: 880px; margin: 0 auto; padding: 1.25rem 16px 2.5rem; flex: 1; }
.footer { text-align: center; padding: 1rem 16px 1.5rem; font-size: .85rem; color: var(--muted); }
.footer a { color: var(--muted); display: inline-flex; align-items: center; min-height: 44px; }
.dot { margin: 0 .4rem; }

/* Ingreso */
.login {
  position: relative; overflow: hidden;
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--blue); padding: 24px 16px;
}
.login::before {
  content: ''; position: absolute; inset: auto -12% -6% auto; width: 115%; aspect-ratio: 555 / 245;
  background: url('/brand/isotipo.svg') no-repeat center / contain; opacity: .09; pointer-events: none;
}
.login-card { position: relative; width: 100%; max-width: 400px; text-align: center; color: #fff; }
.login-card img.logo { width: 200px; max-width: 70%; height: auto; margin-bottom: 1.25rem; }
.login-card h1 { color: #fff; font-size: 1.6rem; margin-bottom: .35rem; }
.login-card p { color: rgba(255,255,255,.85); }
.login-buttons { display: grid; gap: .75rem; margin: 1.75rem 0 1rem; }
.sso {
  display: flex; align-items: center; justify-content: center; gap: .7rem;
  background: #fff; color: #1f2b33; text-decoration: none; font-weight: 600;
  border-radius: 8px; padding: .85rem 1rem; min-height: 48px;
}
.sso:hover { background: #eef5f7; }
.sso svg { width: 20px; height: 20px; flex: none; }
.login-note { font-size: .85rem; color: rgba(255,255,255,.75); }
.alert { border-radius: 8px; padding: .75rem 1rem; margin: 0 0 1rem; text-align: left; font-size: .95rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--blue-soft); color: var(--blue-dark); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* Tarjetas y listas */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.15rem; margin-bottom: 1rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .75rem 1rem; margin: 1.5rem 0 .6rem; }
.section-head h2 { margin: 0; }
.list { display: grid; gap: .65rem; }
.qitem { display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.qitem:hover { border-color: var(--blue-water); }
.qitem-title { font-weight: 600; color: var(--text); margin-bottom: .3rem; overflow-wrap: anywhere; }
.qitem-meta { display: flex; flex-wrap: wrap; gap: .35rem .8rem; align-items: center; font-size: .85rem; color: var(--muted); }
.empty { color: var(--muted); font-size: .95rem; padding: .25rem 0 .5rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; border-radius: 999px; padding: .12rem .6rem; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.b-open { background: var(--blue-soft); color: var(--blue-dark); }
.b-pending { background: var(--warn-soft); color: #7a4d0b; }
.b-done { background: var(--ok-soft); color: #1f5e44; }
.b-muted { background: #eceff1; color: #46545c; }
.b-draft { background: #f1ecf7; color: #5b3c88; }
.b-alert { background: var(--danger); color: #fff; }

.progress { height: 6px; border-radius: 3px; background: var(--blue-soft); overflow: hidden; min-width: 70px; flex: 1; max-width: 140px; }
.progress > span { display: block; height: 100%; background: var(--blue); }

/* Detalle */
.back { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: .4rem; font-size: .95rem; text-decoration: none; }
.qhead h1 { overflow-wrap: anywhere; }
.qhead .meta { color: var(--muted); font-size: .9rem; margin-bottom: 1rem; }
.attachments { display: grid; gap: .4rem; margin: .5rem 0 0; padding: 0; list-style: none; }
.attachments a { display: flex; gap: .5rem; align-items: center; text-decoration: none; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 8px; overflow-wrap: anywhere; }
.attachments a:hover { border-color: var(--blue-water); }
.att-size { margin-left: auto; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; margin: .5rem 0 0; padding: 0; list-style: none; }
.person { display: flex; align-items: center; gap: .5rem; padding: .5rem .65rem; border-radius: 8px; border: 1px solid var(--border); font-size: .92rem; }
.person .mark { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; flex: none; }
.person.voted .mark { background: var(--ok); color: #fff; }
.person.pending .mark { background: #fff; border: 2px solid var(--border); }
.person.voted { background: var(--ok-soft); border-color: transparent; }

/* Votar */
.choices { display: grid; gap: .55rem; margin: .5rem 0 1rem; }
.choice { display: flex; align-items: center; gap: .75rem; padding: .8rem .9rem; border: 1.5px solid var(--field-border); border-radius: 9px; cursor: pointer; min-height: 50px; background: #fff; }
.choice:hover { border-color: var(--blue-water); }
.choice input { width: 20px; height: 20px; accent-color: var(--blue); flex: none; margin: 0; }
.choice:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); }
.choice span { overflow-wrap: anywhere; }
.choice.abstain { border-style: dashed; }
.scale { display: grid; grid-template-columns: repeat(auto-fit, minmax(52px, 1fr)); gap: .5rem; margin: .5rem 0 .3rem; }
.scale .choice { justify-content: center; padding: .7rem .4rem; flex-direction: column; gap: .3rem; }
fieldset.choices, fieldset.scale, fieldset.plain { border: 0; padding: 0; min-width: 0; }
fieldset.plain { margin: 0; }
fieldset.plain > legend { padding: 0; }
.scale-labels { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-bottom: 1rem; gap: 1rem; }
.rank { list-style: none; padding: 0; margin: .5rem 0 1rem; display: grid; gap: .5rem; }
.rank li { display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem .55rem .8rem; border: 1.5px solid var(--border); border-radius: 9px; background: #fff; }
.rank .pos { font-weight: 700; color: var(--blue); width: 1.6rem; flex: none; }
.rank .label { flex: 1; overflow-wrap: anywhere; }
.rank .moves { display: flex; gap: .35rem; flex: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 1.05rem; color: var(--blue); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:not(:disabled):hover { background: var(--blue-soft); }

label.field { display: block; font-weight: 600; margin: 1rem 0 .35rem; }
.hint { font-weight: normal; color: var(--muted); font-size: .85rem; }
input[type=text], input[type=number], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: #fff;
  border: 1.5px solid var(--field-border); border-radius: 8px; padding: .65rem .75rem; min-height: 46px;
}
input:focus, textarea:focus, select:focus, .choice:focus-within, button:focus-visible, a:focus-visible { outline: 3px solid rgba(2,95,127,.3); outline-offset: 1px; border-color: var(--blue); }
textarea { min-height: 110px; resize: vertical; }
.counter { text-align: right; font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.check { display: flex; align-items: center; gap: .6rem; margin: 1rem 0 .25rem; cursor: pointer; min-height: 44px; }
input[type=file] { min-height: 44px; padding: .5rem 0; font: inherit; max-width: 100%; }
.check input { width: 20px; height: 20px; accent-color: var(--blue); }
.opt-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.opt-row input { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; border-radius: 8px; padding: .7rem 1.2rem; min-height: 46px; cursor: pointer; border: 1.5px solid var(--blue); background: var(--blue); color: #fff; text-decoration: none; }
.btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: #fff; color: var(--blue); }
.btn-ghost:hover { background: var(--blue-soft); }
.btn-danger { background: #fff; color: var(--danger); border-color: #e7b8b3; }
.btn-danger:hover { background: var(--danger-soft); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.voted-box { display: flex; gap: .8rem; align-items: flex-start; background: var(--ok-soft); color: #1d5a40; border-radius: var(--radius); padding: 1rem 1.1rem; }
.voted-box .big { font-size: 1.4rem; line-height: 1; }

/* Resultados */
.bars { display: grid; gap: .75rem; margin: .5rem 0 1rem; }
.bar-label { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .15rem 1rem; font-size: .95rem; margin-bottom: .25rem; }
.bar-label span:first-child { overflow-wrap: anywhere; }
.bar-label b { overflow-wrap: anywhere; }
.bar { height: 12px; border-radius: 6px; background: var(--blue-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--blue); border-radius: 6px; }
.stat { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin: .25rem 0 1rem; color: var(--muted); font-size: .92rem; }
.stat b { color: var(--text); }
.comments { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .6rem; }
.comments li { background: var(--bg); border-left: 3px solid var(--blue-water); border-radius: 0 8px 8px 0; padding: .7rem .9rem; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Modal y aviso */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(1,30,41,.55); display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.modal { background: #fff; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; border-radius: 14px 14px 0 0; padding: 1.3rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom)); }
.modal-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: flex-end; margin-top: 1.2rem; }
.summary { background: var(--blue-soft); border-radius: 8px; padding: .8rem .9rem; margin: .5rem 0; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: #13303b; color: #fff; padding: .7rem 1.1rem; border-radius: 8px; font-size: .95rem; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); }

.prose h2 { margin-top: 1.4rem; }
.prose li { margin-bottom: .45rem; }
.versions { list-style: none; padding: 0; display: grid; gap: .5rem; }
.versions li { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; background: #fff; }

@media (min-width: 640px) {
  h1 { font-size: 2.2rem; }
  .container { padding-top: 1.75rem; }
  .card { padding: 1.4rem 1.5rem; }
  .modal-backdrop { align-items: center; padding: 16px; }
  .modal { border-radius: 14px; padding: 1.5rem; }
  .brand img { width: 96px; }
}

@media (max-width: 480px) {
  /* Ranking: el texto usa todo el ancho y las flechas pasan abajo a la derecha. */
  .rank li { flex-wrap: wrap; row-gap: .35rem; }
  .rank .label { flex: 1 1 calc(100% - 2.4rem); }
  .rank .moves { margin-left: auto; }
}

@media (max-width: 420px) {
  .brand-sub { display: none; }
  .row { grid-template-columns: 1fr; }
  .actions .btn { flex: 1 1 100%; }
}
