:root {
  --bg: #f6f4ff;
  --surface: #ffffff;
  --text: #1f1b33;
  --muted: #6b6785;
  --line: #e4e0f5;
  --brand: #6d4aff;
  --brand-strong: #5a35e8;
  --brand-soft: #ece7ff;
  --ok: #17a56b;
  --ok-soft: #dcf6ea;
  --warn: #e08a00;
  --danger: #d7384a;
  --danger-soft: #fde5e8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(40, 20, 100, .06), 0 4px 14px rgba(40, 20, 100, .06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14112a;
    --surface: #1e1a3a;
    --text: #f1eeff;
    --muted: #a39fc4;
    --line: #322d57;
    --brand: #8b6bff;
    --brand-strong: #a48aff;
    --brand-soft: #2c2556;
    --ok: #3ccf91;
    --ok-soft: #123d2d;
    --danger: #ff6b7d;
    --danger-soft: #45202a;
    --shadow: none;
  }
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}

#topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
}
#topbar h1 { font-size: 1.5rem; margin: 0; flex: 1; }
#topbar .back { font-size: 2rem; line-height: 1; color: var(--brand); text-decoration: none; padding: 0 8px 4px 0; }

main {
  max-width: 560px; margin: 0 auto;
  padding: 8px 16px calc(96px + env(safe-area-inset-bottom));
}
main.centered { min-height: 100dvh; display: flex; align-items: center; padding-bottom: 24px; }

nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav#tabs a {
  flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px; font-size: .72rem; font-weight: 600;
  color: var(--muted); text-decoration: none;
}
nav#tabs a span { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
nav#tabs a.active { color: var(--brand); }
nav#tabs a.active span { filter: none; opacity: 1; }

h2 { font-size: 1.05rem; margin: 24px 0 8px; }
h2:first-child { margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
}
a.card, .card.tap { display: block; color: inherit; text-decoration: none; cursor: pointer; }
.card.dim { opacity: .55; }
.card.tap.row { display: flex; }

.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: var(--brand-soft); display: grid; place-items: center; font-size: 1.6rem;
}
.name { font-weight: 700; font-size: 1.1rem; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stats { display: flex; gap: 8px; margin-top: 12px; }
.stat {
  flex: 1; background: var(--bg); border-radius: 12px; padding: 8px 6px; text-align: center;
}
.stat b { display: block; font-size: 1.15rem; }
.stat span { font-size: .72rem; color: var(--muted); }

.bar { height: 10px; border-radius: 99px; background: var(--brand-soft); overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #8b6bff, #5a35e8); border-radius: 99px; transition: width .4s; }

.pill {
  display: inline-block; font-size: .75rem; font-weight: 700;
  padding: 2px 10px; border-radius: 99px; background: var(--brand-soft); color: var(--brand);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--line); color: var(--muted); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.badge {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 99px; background: var(--danger); color: #fff; font-size: .75rem; font-weight: 700;
}

button, .btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 12px; padding: 12px 18px;
  background: var(--brand); color: #fff; cursor: pointer; min-height: 44px;
}
button:active { transform: scale(.98); }
button[disabled] { opacity: .5; }
button.secondary { background: var(--brand-soft); color: var(--brand); }
button.ghost { background: transparent; color: var(--brand); padding: 8px 10px; min-height: 36px; }
button.danger { background: var(--danger-soft); color: var(--danger); }
button.small { padding: 6px 12px; min-height: 34px; font-size: .85rem; }
button.block { width: 100%; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--brand); outline-offset: 2px;
}

.fab {
  position: fixed; right: max(16px, calc(50% - 280px + 16px)); bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; padding: 0; font-size: 1.8rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(90, 53, 232, .45); z-index: 6;
}

.task { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.check {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); display: grid; place-items: center; font-size: .9rem; color: #fff;
}
.check.done { background: var(--ok); border-color: var(--ok); }

/* Formularios */
label.field { display: block; margin-bottom: 14px; font-weight: 600; font-size: .9rem; }
label.field > span { display: block; margin-bottom: 4px; }
label.field.row { display: flex; align-items: center; gap: 10px; }
label.field.row > span { margin: 0; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); }
input[type=text], input[type=password], input[type=number], input[type=date], select {
  width: 100%; font: inherit; font-weight: 400; color: var(--text);
  background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 12px; min-height: 44px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--bg); color: var(--text); border: 1.5px solid var(--line);
  padding: 6px 14px; min-height: 38px; font-weight: 600;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips.days .chip { min-width: 40px; padding: 6px 0; text-align: center; }
.form-error { color: var(--danger); font-weight: 600; margin: 0 0 12px; min-height: 1.2em; }
.actions { display: flex; gap: 10px; margin-top: 8px; }
.actions > * { flex: 1; }

/* Hojas modales */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: 100%; max-width: 560px; margin: auto auto 0;
  border-radius: 22px 22px 0 0; max-height: 92dvh; overflow: auto;
}
dialog.sheet::backdrop { background: rgba(10, 5, 30, .5); }
.sheet-head {
  position: sticky; top: 0; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 8px;
}
.sheet-head h3 { margin: 0; font-size: 1.2rem; }
.sheet-body { padding: 8px 18px calc(24px + env(safe-area-inset-bottom)); }

.code {
  font: 700 2.6rem/1.1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .12em;
  text-align: center; padding: 18px 0; background: var(--brand-soft); color: var(--brand);
  border-radius: 16px; margin: 12px 0; user-select: all;
}

.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty .big { font-size: 3rem; }

.login { width: 100%; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; margin: 0 0 20px; }

#toasts {
  position: fixed; left: 0; right: 0; bottom: calc(84px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none;
}
.toast {
  background: #2a2350; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}
.toast.error { background: var(--danger); }

.hint { background: var(--brand-soft); color: var(--text); border-radius: 12px; padding: 10px 12px; font-size: .9rem; }
