:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1c1b18;
  --muted: #6b675e;
  --border: #e2dfd6;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d6efec;
  --danger: #b42318;
  --ok-bg: #dcfce7;
  --ok-ink: #166534;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1e1d1a;
    --surface-2: #2a2925;
    --text: #f1efe9;
    --muted: #a39f95;
    --border: #36342f;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --accent-soft: #123b37;
        --danger: #f97066;
    --ok-bg: #14361f;
    --ok-ink: #86efac;
    --warn-bg: #3a2a0c;
    --warn-ink: #fcd34d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code { font-size: .85em; background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: .55rem 1rem; }
button:disabled { cursor: not-allowed; opacity: .4; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.danger { background: transparent; color: var(--danger); border-color: currentColor; }
button.link { background: none; border: none; color: var(--muted); padding: .3rem .4rem; text-decoration: underline; text-underline-offset: 3px; }
button.small { padding: .35rem .75rem; font-size: .9rem; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; width: 100%;
}
label { display: grid; gap: .3rem; font-weight: 500; font-size: .92rem; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; }
.row.end { justify-content: flex-end; }
.row > label { flex: 1 1 160px; }

main { max-width: 1180px; margin: 0 auto; padding: 0 16px 64px; }

/* --- Barra superior --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem max(16px, calc((100vw - 1180px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-size: .95rem; }
.brand-logo { width: 28px; height: 28px; border-radius: 22%; flex: none; display: block; }
.brand-logo.big { width: 72px; height: 72px; justify-self: center; box-shadow: var(--shadow); }
.tabs { display: flex; gap: .25rem; background: var(--surface-2); padding: .25rem; border-radius: 12px; }
.tabs button { background: none; padding: .4rem .9rem; color: var(--muted); font-weight: 500; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.me { margin-left: auto; display: flex; align-items: center; gap: .4rem; font-size: .9rem; }
.me-name { color: var(--muted); }

/* --- Entrada --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 0; }
.login-card {
  width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 2rem; display: grid; gap: 1rem; box-shadow: var(--shadow);
}
.roster-title { font-weight: 500; font-size: .92rem; margin: 0 0 .5rem; }
.roster { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.roster button {
  padding: .85rem .6rem; border: 1.5px solid var(--border); border-radius: 12px; background: var(--surface);
  color: var(--text); font-weight: 600; font-size: 1rem; overflow-wrap: anywhere;
}
.roster button:hover { border-color: var(--accent); background: var(--accent-soft); }
.roster button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.roster button:disabled { opacity: .6; }
.roster-empty { grid-column: 1 / -1; text-align: center; margin: .5rem 0; }

/* --- Votar --- */
.view { padding-top: 1.2rem; }
.budget {
  position: sticky; top: calc(var(--topbar-h, 58px) + 8px); z-index: 5;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem 1rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.budget-text { font-weight: 600; }
.budget-text small { display: block; font-weight: 400; color: var(--muted); }
.budget-dots { display: flex; gap: 5px; flex-wrap: wrap; }
.budget-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); transition: background .2s; }
.budget-dots i.spent { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--border); }
.budget-cta { margin-left: auto; }
.closed-banner { background: var(--warn-bg); color: var(--warn-ink); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 500; }

.toolbar { display: flex; gap: .6rem; margin-bottom: .7rem; }
.toolbar .search { flex: 1; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .3rem .75rem; border-radius: 999px; font-size: .85rem; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .9rem; }
.card {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 1rem; display: flex; flex-direction: column; gap: .5rem; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.card.voted { border-color: var(--accent); }
.card-meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.module {
  font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px;
  background: hsl(var(--h) 70% 92%); color: hsl(var(--h) 60% 28%);
}
@media (prefers-color-scheme: dark) {
  .module { background: hsl(var(--h) 35% 22%); color: hsl(var(--h) 80% 80%); }
}
.badge { font-size: .75rem; color: var(--muted); }
.code { font: 600 .72rem/1 ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); letter-spacing: .02em; }
.facts { display: flex; flex-wrap: wrap; gap: .3rem; }
.fact { font-size: .72rem; padding: .1rem .45rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.fact.ai { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.card h3 { font-size: 1.02rem; margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card p.open { -webkit-line-clamp: unset; }
.card .more { align-self: flex-start; padding: 0; font-size: .82rem; }
.card-foot { margin-top: auto; padding-top: .4rem; display: flex; align-items: center; justify-content: space-between; }
.pips { display: flex; gap: 4px; }
.pips i { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--border); }
.pips i.on { background: var(--accent); box-shadow: none; }
.stepper { display: flex; align-items: center; gap: .4rem; }
.stepper button { width: 38px; height: 38px; padding: 0; font-size: 1.2rem; line-height: 1; background: var(--surface-2); color: var(--text); }
.stepper button.plus { background: var(--accent); color: var(--accent-ink); }
.stepper output { min-width: 1.5ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 2rem; }

/* --- Resultados --- */
.locked { text-align: center; max-width: 420px; margin: 3rem auto; display: grid; gap: .5rem; justify-items: center; }
.locked-icon { font-size: 2.2rem; }
.results-head { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.seg { display: inline-flex; background: var(--surface-2); padding: .25rem; border-radius: 12px; gap: .2rem; margin-bottom: .6rem; }
.seg button { background: none; padding: .35rem .8rem; font-size: .9rem; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tag-help { font-size: .85rem; margin: 0 0 1rem; }
.tag { font-size: .72rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; white-space: nowrap; }
.tag.muy-votado { background: var(--ok-bg); color: var(--ok-ink); }
.tag.dividido { background: var(--warn-bg); color: var(--warn-ink); }

.ranking { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.rank-row {
  display: grid; grid-template-columns: 2.2rem 1fr; gap: .2rem .8rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .75rem 1rem;
}
.rank-n { grid-row: span 2; font-size: 1.3rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.rank-row:nth-child(-n+3) .rank-n { color: var(--accent); }
.rank-title { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; font-weight: 600; }
.rank-bar { display: flex; align-items: center; gap: .7rem; }
.bar { flex: 1; height: 14px; border-radius: 7px; background: var(--surface-2); display: flex; overflow: hidden; }
.bar span { background: var(--accent); border-radius: 7px; transition: width .4s ease; }
.rank-nums { font-size: .82rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-nums b { color: var(--text); font-size: .95rem; }

/* --- Admin --- */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; display: grid; gap: .8rem; align-content: start; }
.panel.wide { grid-column: 1 / -1; }
.switch { display: flex; align-items: center; gap: .5rem; }
.switch input { width: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .4rem .3rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }
td.done { color: var(--accent); font-weight: 600; }
td.act { text-align: right; width: 1%; white-space: nowrap; }
td.act button { padding: .25rem .6rem; font-size: .82rem; }
.team-add { display: grid; gap: .5rem; }
.admin-features { display: grid; gap: .5rem; }
.af-row { display: grid; grid-template-columns: 2fr 1fr auto; gap: .5rem; align-items: start; padding: .6rem; border: 1px solid var(--border); border-radius: 10px; }
.af-row.is-hidden { opacity: .55; }
.af-row textarea { grid-column: 1 / 3; }
.af-actions { display: flex; gap: .3rem; flex-direction: column; }
.af-actions button { padding: .35rem .6rem; font-size: .85rem; }

/* --- Diálogo y toast --- */
dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(480px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
.dialog-form { padding: 1.4rem; display: grid; gap: .9rem; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  .topbar { gap: .5rem; }
  .brand > span:last-child { display: none; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; }
  .budget-cta { margin-left: 0; width: 100%; }
  .toolbar { flex-direction: column; }
  .admin-grid { grid-template-columns: 1fr; }
  .af-row { grid-template-columns: 1fr; }
  .af-row textarea { grid-column: auto; }
  .af-actions { flex-direction: row; }
  .login-card { padding: 1.4rem; }
}
