:root {
  --bg: #f6f3ee; --card: #fff; --ink: #1f2a2e; --muted: #6b7478; --line: #e4ded5;
  --accent: #b3261e; --accent-ink: #fff; --green: #2e7d4f; --blue: #2b5c8a; --gold: #c58b00;
  --radius: 12px;
}
[hidden] { display: none !important; } /* que no lo anule un display: flex (filtros de Actividades) */
@media (prefers-color-scheme: dark) {
  :root { --bg: #171b1d; --card: #22282b; --ink: #ecebe7; --muted: #9aa3a7; --line: #343c40;
          --accent: #e05a4f; --green: #5cbf86; --blue: #7fb0dd; --gold: #e2b23c; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: .3rem 0; }
h2 a { color: inherit; }
h3 { margin: 0 0 .6rem; font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .7rem 1rem;
       background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--accent); font-size: 1.1rem; }
.top nav { display: flex; gap: .3rem; flex: 1; }
.top nav a { padding: .35rem .7rem; border-radius: 999px; color: var(--ink); }
.top nav a.on { background: var(--accent); color: var(--accent-ink); }
.me { color: var(--muted); font-size: .9rem; margin-left: auto; white-space: nowrap; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

.flash { background: #fff4d6; color: #5a4300; padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }
.hint { background: var(--card); border-left: 4px solid var(--gold); padding: .5rem .8rem; border-radius: 6px; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.narrow { max-width: 380px; margin: 3rem auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.act { display: flex; flex-direction: column; margin: 0; scroll-margin-top: 80px; }
.act .desc { color: var(--muted); font-size: .92rem; margin: .4rem 0; flex: 1; }
.act-top { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .3rem; }
.act-bottom { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.facts { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .95rem; }
.tag { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.tag.cold { color: var(--blue); }
.tag.out { color: var(--muted); }
.tag.warn { color: var(--gold); }
.who-list { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }

.btn { display: inline-block; font: inherit; padding: .45rem .9rem; border-radius: 999px; border: 1px solid var(--line);
       background: var(--card); color: var(--ink); cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.joined { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--accent); }

.votes { display: flex; gap: .3rem; }
.vote { font-size: 1.15rem; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: .2rem .55rem;
        cursor: pointer; color: var(--ink); filter: grayscale(.6); opacity: .8; }
.vote .t { font-size: .9rem; }
.vote .n { font-size: .8rem; color: var(--muted); }
.vote.on { filter: none; opacity: 1; border-color: var(--gold); background: color-mix(in srgb, var(--gold) 18%, var(--card)); }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; font: inherit; padding: .3rem .75rem; border-radius: 999px;
        border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
.chip input { display: none; }
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }
.chip.big { font-size: 1.1rem; padding: .6rem 1.1rem; }
.who section { margin-bottom: 1.2rem; }
.famrow { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: .7rem; }
.famrow > b { min-width: 120px; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
select, input, textarea { font: inherit; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px;
                          background: var(--card); color: var(--ink); }
select { appearance: none; -webkit-appearance: none; padding-right: 2.1rem; cursor: pointer;
         background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a9397' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right .75rem center; }
.form label { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .7rem; font-size: .9rem; color: var(--muted); flex: 1; }
.form label input, .form label select, .form label textarea { color: var(--ink); }
.row { display: flex; gap: .8rem; flex-wrap: wrap; align-items: end; }
label.check { flex-direction: row !important; align-items: center; gap: .4rem; color: var(--ink) !important; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: .4rem .8rem; margin: 0 0 .8rem; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
.grid > *, .cols > *, .days > * { min-width: 0; }
.pre { white-space: pre-wrap; }
ul.plain { list-style: none; padding: 0; margin: .6rem 0 0; }
ul.plain li { padding: .15rem 0; }

.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; scroll-margin-top: 80px; }
.day.empty { opacity: .7; }
.day h3 { font-size: .95rem; border-bottom: 1px solid var(--line); padding-bottom: .4rem; }
.event { display: flex; gap: .7rem; padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.event:last-child { border-bottom: 0; }
.event .time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3.2rem; color: var(--accent); }
.dates summary { cursor: pointer; color: var(--muted); }
.dates form { margin-top: .5rem; }

table { width: 100%; border-collapse: collapse; margin: .4rem 0 .8rem; }
td { padding: .3rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

@media (max-width: 600px) {
  main { padding: .8rem; }
  .top { gap: .5rem; position: static; } /* en el móvil la cabecera no se queda fija */
  .top nav { order: 3; width: 100%; }
  .grid, .cols, .days { grid-template-columns: 1fr; }
  dl { grid-template-columns: 1fr; gap: .1rem; }
  dd { margin-bottom: .5rem; }
  .famrow > b { min-width: 0; width: 100%; }
  input, select, textarea { font-size: 16px; } /* evita el zoom automático en iOS */
}
.day.empty { padding: .5rem .8rem; }
.day.empty h3 { display: inline; border: 0; padding: 0; }
.day.empty p { display: inline; margin-left: .4rem; font-size: .85rem; }

.warn-text { color: var(--gold); }
.savebar { position: sticky; bottom: 0; padding: .7rem 0; background: var(--bg); }
.totals td { white-space: nowrap; }
@media (max-width: 600px) {
  .totals { font-size: .85rem; }
  .totals td { padding: .3rem .2rem; }
}
.prices { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 .8rem; }
@media (max-width: 600px) {
  .prices { grid-template-columns: 1fr 1fr; }
  .top nav { gap: .1rem; }
  .top nav a { padding: .35rem .55rem; font-size: .92rem; }
}
.prices label { justify-content: space-between; }
.voters { columns: 2; }
.totals td:first-child { white-space: normal; }
@media (max-width: 600px) {
  .totals { font-size: .8rem; }
  .totals td { padding: .3rem .15rem; }
}
.scroll-x { overflow-x: auto; }
.chip .price { opacity: .75; font-size: .8rem; }

details.menu { position: relative; }
details.menu > summary { list-style: none; user-select: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-items { position: absolute; right: 0; bottom: calc(100% + .3rem); z-index: 10; min-width: 13rem;
              background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
              box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: .3rem; display: flex; flex-direction: column; }
.menu-items button, .menu-items a { font: inherit; text-align: left; background: none; border: 0; color: var(--ink);
              padding: .55rem .7rem; border-radius: 8px; cursor: pointer; }
.menu-items button:hover, .menu-items a:hover { background: var(--bg); text-decoration: none; }
.menu-items .danger { color: var(--accent); }
.menu-items a { color: var(--muted); font-size: .9rem; border-top: 1px solid var(--line); border-radius: 0; margin-top: .2rem; }

/* Matriz quién va a qué */
.matrix { border-collapse: separate; border-spacing: 0; width: auto; font-size: .85rem; }
.matrix th, .matrix td { border-bottom: 1px solid var(--line); padding: .3rem .25rem; }
.matrix .act-col { position: sticky; left: 0; z-index: 2; background: var(--card); text-align: left;
                   min-width: 9.5rem; max-width: 12rem; white-space: normal; }
.matrix .fam-row th { font-size: .72rem; font-weight: 600; color: var(--muted); text-align: left;
                      border-bottom: 0; white-space: normal; line-height: 1.15; vertical-align: bottom; }
.matrix th.rot { height: 82px; vertical-align: bottom; padding: 0; white-space: nowrap; border-bottom: 1px solid var(--line); }
.matrix th.rot > div { width: 2.2rem; transform: translate(.9rem, -.4rem) rotate(-45deg); transform-origin: bottom left; }
.matrix th.rot span { font-weight: 500; }
.matrix .fam-1 { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.matrix .fam-start { border-left: 2px solid var(--line); }
.matrix td.cell { width: 2.2rem; min-width: 2.2rem; text-align: center; font-variant-numeric: tabular-nums; }
.matrix td.cell.on { background: color-mix(in srgb, var(--green) 22%, var(--card)); color: var(--ink); font-weight: 600; }
.matrix tbody tr:hover td { filter: brightness(.97); }
.matrix tfoot td { border-top: 2px solid var(--line); }
@media (max-width: 600px) { .matrix .act-col { min-width: 8rem; max-width: 9rem; } }
.menu-items .sep { border-top: 1px solid var(--line); border-radius: 0; margin-top: .2rem; }
.matrix tr.empty .act-col a, .matrix tr.empty .act-col small { color: var(--muted); }
.matrix tr.empty td { opacity: .75; }

/* Cosas a probar */
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progress span { display: block; height: 100%; background: var(--green); }
.foods { list-style: none; padding: 0; margin: 0 0 1rem; background: var(--card); border: 1px solid var(--line);
         border-radius: var(--radius); }
.foods li { display: flex; align-items: center; gap: .5rem; padding: .2rem .6rem .2rem .9rem; border-bottom: 1px solid var(--line); scroll-margin-top: 80px; }
@media (max-width: 600px) { .act, .day, .foods li { scroll-margin-top: .5rem; } } /* sin cabecera fija */
.foods li:last-child { border-bottom: 0; }
.food-check { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 0 .6rem; }
.food-check label { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; cursor: pointer; flex: 1; min-width: 12rem; }
.food-check input[type=checkbox] { width: 1.4rem; height: 1.4rem; accent-color: var(--green); flex-shrink: 0; }
.foods li.done .food-name { text-decoration: line-through; color: var(--muted); }
.food-check .tried { font-size: .8rem; margin-left: 2.1rem; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1rem; cursor: pointer; padding: .5rem; border-radius: 8px; }
.icon-btn:hover { color: var(--accent); background: var(--bg); }
/* En el móvil las 7 pestañas no caben en una fila: van en dos, todas a la vista */
@media (max-width: 600px) {
  .top nav { flex: 1 0 100%; min-width: 0; flex-wrap: wrap; justify-content: center; gap: .25rem .2rem; }
  .top nav a { padding: .3rem .6rem; font-size: .9rem; white-space: nowrap; }
}
.clash { color: var(--accent); font-size: .85rem; margin-top: .2rem; }
.free-list { font-size: .82rem; color: var(--green); margin-top: .5rem; padding-top: .4rem; border-top: 1px dashed var(--line); }
[data-live].updating { opacity: .6; transition: opacity .15s; }
.big-btn { display: block; text-align: center; font-size: 1.3rem; font-weight: 600; padding: 1rem; margin: .5rem 0 1rem; }
.sections { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.sections .card { margin: 0; display: flex; flex-direction: column; gap: .2rem; color: var(--ink); text-decoration: none; }
.sections .card small { line-height: 1.3; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpis .card, .cols .card { margin: 0; }
.cols { margin-bottom: 1rem; }
.kpi { display: flex; flex-direction: column; gap: .15rem; }
.kpi b { font-size: 2rem; font-variant-numeric: tabular-nums; }
.kpi-num { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.kpi { --act: #2a78d6; --log: #eb6834; --lunch: #c79a1e; --free: #1baf7a; }
@media (prefers-color-scheme: dark) { .kpi { --act: #3987e5; --log: #d95926; --lunch: #d1a62a; --free: #199e70; } }
.split-bar { display: flex; gap: 2px; height: 14px; margin: .5rem 0 .4rem; }
.split-bar .seg { border-radius: 2px; min-width: 4px; }
.split-bar .seg:first-child { border-radius: 4px 2px 2px 4px; }
.split-bar .seg:last-child { border-radius: 2px 4px 4px 2px; }
.seg.act, .dot.act { background: var(--act); }
.seg.log, .dot.log { background: var(--log); }
.seg.lunch, .dot.lunch { background: var(--lunch); }
.seg.free, .dot.free { background: var(--free); }
ul.cat-bars { margin: .5rem 0 0; display: grid; grid-template-columns: auto 1fr auto; gap: .25rem .5rem; align-items: center; font-size: .9rem; }
ul.cat-bars li { display: contents; }
.cat-bars i { display: block; height: 10px; border-radius: 0 3px 3px 0; background: var(--act); min-width: 4px; }
.cat-bars b { font-size: .9rem; text-align: right; font-variant-numeric: tabular-nums; }
ul.split-legend { margin: 0 0 .3rem; }
ul.split-legend li { display: flex; align-items: baseline; gap: .4rem; padding: .1rem 0; }
.split-legend li b { font-size: 1rem; margin-left: auto; }
.split-legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; align-self: center; }
.fam-costs { width: 100%; border-collapse: collapse; }
.fam-costs td { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.fam-costs tr.mine td { font-weight: 600; color: var(--accent); }
