:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #1c2233;
  --muted: #6b7489;
  --accent: #5b5bd6;
  --accent-soft: #ecebfd;
  --pos: #15803d;
  --neg: #c2410c;
  --danger: #dc2626;
  --maybe: #b45309;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 4px 16px rgba(20, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #20242f;
    --border: #2b303d;
    --text: #e7e9f0;
    --muted: #8e97ab;
    --accent: #8b8cf4;
    --accent-soft: #25264a;
    --pos: #4ade80;
    --neg: #fb923c;
    --danger: #f87171;
    --maybe: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[x-cloak] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 26px; font-weight: 650; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 14px; }
h3 { font-size: 14px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 24px; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
code { font: 13px ui-monospace, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* Navegación */
.nav {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; margin-right: 20px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 26px; height: 26px; border-radius: 7px; }
.nav a.link { padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.nav a.link:hover { background: var(--surface-2); color: var(--text); }
.nav a.link.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }
main.narrow { max-width: 720px; }

/* Tarjetas y rejillas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 800px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.empty { text-align: center; padding: 40px 24px; }
.empty .big { font-size: 40px; }

/* Controles */
button, .btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 10px; transition: background .12s, border-color .12s, transform .06s;
}
button:hover { background: var(--surface-2); }
button:active { transform: scale(.98); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.icon { padding: 5px 9px; }
button.danger:hover { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid input, .form-grid select { color: var(--text); }
.form-grid.narrow { max-width: 480px; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); cursor: pointer; }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Tablas */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.right { text-align: right; }

/* Etiquetas de estado */
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.ok { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }
.tag.error { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.tag.warn { background: color-mix(in srgb, var(--neg) 12%, transparent); color: var(--neg); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

/* Miembros: avatar con iniciales y filas de la lista */
.avatar {
  display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%;
  color: #fff; font-size: 13px; font-weight: 650; letter-spacing: .02em; user-select: none;
}
.avatar.small { width: 26px; height: 26px; font-size: 11px; }
.avatar.big { width: 46px; height: 46px; font-size: 17px; }
.avatars { display: flex; flex-wrap: wrap; }
.avatars .avatar { margin-right: -6px; border: 2px solid var(--surface); }
.member { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.member:last-child { border-bottom: none; }
.member > .row { gap: 2px; }

/* Miércoles: tarjetas de quedada, fecha y respuesta (voy / quizá / no) */
.page-head { display: flex; align-items: flex-start; gap: 12px; }
.page-head > div { flex: 1; min-width: 0; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 28px 0 10px; }
.meetup { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 14px; align-items: start; }
.meetup h3 { margin: 0; font-size: 17px; font-weight: 650; overflow-wrap: anywhere; }
.meetup h3 a { color: var(--text); }
.meetup.cancelled h3 { text-decoration: line-through; color: var(--muted); }
.meetup .rsvp-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.datebox { width: 54px; text-align: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent); padding: 6px 0 7px; line-height: 1.15; }
.datebox .d { display: block; font-size: 22px; font-weight: 700; }
.datebox .w, .datebox .m { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: none; border-radius: 0; padding: 7px 13px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on-si { background: color-mix(in srgb, var(--pos) 18%, transparent); color: var(--pos); }
.seg button.on-quiza { background: color-mix(in srgb, var(--maybe) 18%, transparent); color: var(--maybe); }
.seg button.on-no { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.tag.maybe { background: color-mix(in srgb, var(--maybe) 15%, transparent); color: var(--maybe); }
.history { display: grid; }
.history a { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.history a:last-child { border-bottom: none; }
.history .date { width: 92px; flex: none; }
.people { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.person { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.note { padding: 10px 0; border-bottom: 1px solid var(--border); }
.note:last-child { border-bottom: none; }
.note .text { white-space: pre-wrap; overflow-wrap: anywhere; }
textarea { width: 100%; resize: vertical; min-height: 70px; }
.modal form { display: grid; gap: 12px; }
.modal label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.modal input, .modal select, .modal textarea { width: 100%; color: var(--text); }

/* Viajes: pestañas, chat, encuestas, tareas y diario */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 0 18px; overflow-x: auto; }
.tabs a { padding: 9px 12px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { font-size: 11px; background: var(--surface-2); color: var(--muted); border-radius: 8px; padding: 0 6px; margin-left: 4px; }
.pinned { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
          background: var(--accent-soft); border-radius: 12px; color: var(--text); }
.chat { display: grid; gap: 4px; padding-bottom: 8px; }
.chat .day { text-align: center; margin: 12px 0 6px; }
.chat .day span { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 2px 10px; border-radius: 10px; }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 86%; }
.msg.mine { margin-left: auto; flex-direction: row-reverse; }
.msg .avatar { visibility: hidden; }
.msg.first .avatar { visibility: visible; }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 16px 4px; padding: 7px 11px; min-width: 0; box-shadow: var(--shadow); }
.msg.mine .bubble { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, var(--border)); border-radius: 16px 16px 4px 16px; }
.bubble .who { font-size: 12px; font-weight: 650; margin-bottom: 1px; }
.bubble .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble .meta button { padding: 0 4px; font-size: 11px; border: none; background: none; color: var(--muted); }
.linked a, .bubble .body a { overflow-wrap: anywhere; text-decoration: underline; }
.composer { position: sticky; bottom: 0; z-index: 10; display: flex; gap: 8px; align-items: flex-end; padding: 10px 0 12px;
            background: linear-gradient(to bottom, transparent, var(--bg) 14px); }
.composer textarea { flex: 1; min-height: 42px; max-height: 160px; resize: none; }
.poll { display: grid; gap: 6px; min-width: min(280px, 64vw); }
.poll-opt { position: relative; display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; overflow: hidden;
            border-radius: 10px; padding: 8px 10px; background: var(--surface); }
.poll-opt .bar { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--accent) 16%, transparent); transition: width .2s; }
.poll-opt > span:not(.bar) { position: relative; }
.poll-opt.mine { border-color: var(--accent); font-weight: 600; }
.poll-opt:disabled { opacity: 1; cursor: default; }
.small { font-size: 12px; }
.task { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: none; }
.task input[type=checkbox] { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--pos); flex: none; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .title { cursor: pointer; }
.day-card.today { border-color: var(--accent); }
.entries { display: grid; gap: 2px; margin: 6px 0 4px; }
.entry { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; }
.entry .text { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.add-inline { display: flex; gap: 8px; }
.add-inline input { flex: 1; min-width: 0; }
.trip-card { display: block; color: var(--text); }
.trip-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* Aviso destacado (p. ej. activar notificaciones) */
.notice { display: flex; align-items: center; gap: 14px; border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--accent-soft); margin-bottom: 16px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; box-shadow: var(--shadow);
  font-weight: 500; z-index: 50;
}
#global-toast[hidden] { display: none; }
.modal-bg { position: fixed; inset: 0; z-index: 40; background: rgba(10, 12, 20, .45); display: grid; place-items: center; padding: 16px; }
.modal { width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; background: var(--surface-2); border-radius: 10px; padding: 12px; margin: 0; }

/* Valor para copiar */
.copy-link { display: flex; gap: 6px; margin-top: 8px; }
.copy-link input { flex: 1; min-width: 0; font: 12px ui-monospace, monospace; }

/* Pantallas de acceso (login, alta, enlaces de acceso, PIN) */
.auth { max-width: 380px; margin: 0 auto; padding: 64px 16px; }
.auth .brand { justify-content: center; margin: 0 0 24px; font-size: 22px; }
.auth .brand-icon { width: 34px; height: 34px; border-radius: 9px; }
.auth form { display: grid; gap: 12px; }
.auth label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.auth input { width: 100%; font-size: 16px; color: var(--text); }
.auth button.primary { width: 100%; padding: 10px; font-size: 15px; }
.auth .links { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; font-size: 13px; flex-wrap: wrap; }
.auth .pin-input { text-align: center; font-size: 28px; letter-spacing: .5em; padding: 10px; }
.auth label.check { display: flex; color: var(--text); }
.auth label.check input { width: 16px; }
.code-input { font-family: ui-monospace, monospace; letter-spacing: .04em; }

/* Barra inferior y hoja «Más» (solo móvil) */
.tabbar, .sheet { display: none; }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.offline-bar {
  position: sticky; top: 0; z-index: 45; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--neg); color: #fff; font-size: 13px; font-weight: 500; text-align: center;
}

/* ---------- Móvil ---------- */
@media (max-width: 920px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  main { padding: 20px 16px 32px; }
  h1 { font-size: 22px; }
  .sub { margin-bottom: 16px; }
  .card { padding: 16px; }

  .nav { padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .nav a.link { display: none; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
  }
  .tabbar a, .tabbar button {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 4px 2px; border: none; background: none; border-radius: 10px;
    color: var(--muted); font-size: 11px; font-weight: 500;
  }
  .tabbar .active { color: var(--accent); }
  .sheet { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(10, 12, 20, .4); }
  .sheet[hidden] { display: none; }
  .sheet-panel {
    position: absolute; left: 8px; right: 8px; bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 6px; display: grid;
  }
  .sheet-panel a { padding: 13px 14px; border-radius: 10px; color: var(--text); font-weight: 500; }
  .sheet-panel a.active { background: var(--accent-soft); color: var(--accent); }

  /* Lo fijo abajo, por encima de la barra */
  .composer { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .msg { max-width: 94%; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); left: 16px; right: 16px; transform: none; text-align: center; }

  /* Controles a todo el ancho y táctiles */
  input, select, button, textarea { font-size: 16px; }  /* evita el zoom automático de iOS/Android al enfocar */
  .form-grid { grid-template-columns: 1fr; }
  .grid > * { min-width: 0; }

  /* Tablas: desplazamiento horizontal dentro de su tarjeta, o una tarjeta por fila (table.cards) */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  table.cards { display: table; white-space: normal; }
  table.cards thead { display: none; }
  table.cards tr { display: grid; gap: 4px 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  table.cards tr:last-child { border-bottom: none; }
  table.cards td { display: block; padding: 0; border: none; min-width: 0; }
  table.cards tbody tr:hover { background: none; }
  table.cards td[data-label]:not(:empty)::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    font-size: 11px; font-weight: 500; letter-spacing: .03em; text-transform: uppercase; color: var(--muted);
  }
  /* Listas con un botón por fila (dispositivos, correos): nombre y botón arriba, los datos debajo */
  .list-table tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name action" "a b"; align-items: center; }
  .list-table td:nth-child(1) { grid-area: name; overflow-wrap: anywhere; font-weight: 500; }
  .list-table td:nth-child(2) { grid-area: a; }
  .list-table td:nth-child(3) { grid-area: b; }
  .list-table td:nth-child(4) { grid-area: action; justify-self: end; }
  .list-table td.right { text-align: left; }
}
