:root {
  --navy: #1a2332;
  --cyan: #0ba2c3;
  --cyan-dark: #0a8aa6;
  --contra: #d06a6f;
  --abst: #97a2ad;
  --bg: #f5f7fa;
  --line: #e1e6eb;
  --mut: #6b7280;
  --white: #ffffff;
  --warn: #b58a2e;
  --sidebar-w: 240px;
  --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--navy);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.4;
  height: 100dvh;
  overflow: hidden;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

/* ---------- Boot ---------- */
.boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--mut);
}

.mark {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  background: var(--navy);
  color: var(--white);
  font-weight: 800;
  font-size: 16px;
}

/* ---------- Layout principal: sidebar + contenido ---------- */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
}

.sidebar {
  background: var(--navy);
  color: var(--white);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 10px;
}
.sidebar-brand h1 { margin: 0; font-size: 0.95rem; font-weight: 700; line-height: 1.1; }
.sidebar-brand p { margin: 2px 0 0; font-size: 0.7rem; color: rgba(255,255,255,0.55); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 7px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: var(--white); }
.nav-item.active { background: rgba(11,162,195,0.25); color: var(--white); font-weight: 600; }

.sidebar-status {
  margin-top: auto;
  padding: 10px 8px 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.72rem;
  color: rgba(255,255,255,0.55);
}
.sidebar-status .pill { background: rgba(255,255,255,0.12); color: var(--white); margin-bottom: 6px; }

.content {
  overflow-y: auto;
  padding: 18px 22px;
}

/* ---------- Pills / estado ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  padding: 4px 9px;
  background: #eef1f5;
  color: var(--navy);
  font-size: 0.74rem;
  font-weight: 600;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mut);
}
.dot.open { background: var(--cyan); animation: pulse 1.4s ease-in-out infinite; }
.dot.closed { background: var(--warn); }
.dot.results { background: var(--cyan-dark); }
.dot.finalizado { background: var(--cyan-dark); }

/* ---------- Cards ---------- */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}
.grid .full { grid-column: 1 / -1; }

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.section-head h2 { margin: 0; font-size: 0.95rem; font-weight: 700; }

.eyebrow {
  color: var(--mut);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 3px;
}

.question-title {
  font-size: 1rem;
  line-height: 1.3;
  margin: 3px 0 0;
  font-weight: 600;
}

/* ---------- Progreso de votaciones ---------- */
.progress { display: flex; gap: 4px; }
.segment {
  width: 26px;
  height: 5px;
  border-radius: 999px;
  background: var(--line);
}
.segment.done { background: var(--cyan); }
.segment.current { background: var(--navy); }

/* ---------- Timer ---------- */
.timer { margin-top: 10px; }
.timer-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
}
.timer-value {
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.bar {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}
.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--cyan);
  transition: width 0.4s linear, background 0.2s ease;
}
.bar-fill.urgent { background: var(--contra); }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  padding: 9px;
  text-align: center;
}
.stat-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--mut);
  font-size: 0.68rem;
  font-weight: 600;
}
.swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}
.stat strong {
  display: block;
  margin-top: 5px;
  font-size: 1.35rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}
.stat small {
  display: block;
  margin-top: 2px;
  color: var(--mut);
  font-size: 0.68rem;
}

.participation {
  margin-top: 7px;
  text-align: center;
  color: var(--mut);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Acciones ---------- */
.actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  margin-top: 10px;
}
.actions .wide { grid-column: 1 / -1; }

.btn {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 36px;
  padding: 0 11px;
  background: var(--white);
  color: var(--navy);
  font-weight: 600;
  font-size: 0.82rem;
}
.btn.primary { background: var(--cyan); border-color: var(--cyan); color: var(--white); }
.btn.dark { background: var(--navy); border-color: var(--navy); color: var(--white); }
.btn.danger { border-color: rgba(208, 106, 111, 0.4); color: var(--contra); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { background: #f1f3f5; border-color: var(--line); color: #aeb5bd; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card { width: min(340px, 100%); }

.form { display: grid; gap: 10px; }
.field { display: grid; gap: 4px; }
.field label { color: var(--mut); font-size: 0.76rem; font-weight: 600; }
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  color: var(--navy);
  padding: 9px 11px;
  outline: none;
}
.field textarea { min-height: 64px; resize: vertical; }
.field input:focus, .field textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(11, 162, 195, 0.12);
}

/* ---------- Config ---------- */
.config-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 0.7fr;
  gap: 7px;
}
.question-editor { display: grid; gap: 7px; margin-top: 8px; }
.question-row {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  background: #fbfcfd;
}
.question-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.inline-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }

/* ---------- Mensajes ---------- */
.msg {
  margin-top: 9px;
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 0.78rem;
  font-weight: 600;
}
.msg.error { background: rgba(208, 106, 111, 0.1); color: #9a3f44; }
.msg.ok { background: rgba(11, 162, 195, 0.1); color: var(--cyan-dark); }

.empty {
  border: 1px dashed var(--line);
  border-radius: 7px;
  padding: 12px;
  color: var(--mut);
  background: #fbfcfd;
  font-size: 0.8rem;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--cyan);
  animation: spin 1s linear infinite;
  margin: 10px auto 5px;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.6; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Censo ---------- */
.census-summary {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.census-table-wrap {
  max-height: calc(100dvh - 280px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
table td { padding: 6px 9px; border-bottom: 1px solid #f0f3f6; }
table th {
  font-weight: 600;
  text-align: left;
  padding: 7px 9px;
  color: var(--mut);
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    align-items: center;
    padding: 8px 12px;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sidebar-brand { padding: 0 8px 0 0; border: none; border-right: 1px solid rgba(255,255,255,0.1); margin: 0 6px 0 0; }
  .sidebar-brand p { display: none; }
  .nav-item { white-space: nowrap; }
  .sidebar-status { margin: 0; padding: 0; border: none; }
  .grid { grid-template-columns: 1fr; }
  .content { padding: 12px; }
}
