:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --text: #16181d;
  --muted: #6b7180;
  --line: #e2e5ec;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d93036;
  --ok: #30a46c;
  --warn: #f59e0b;
  --shadow: 0 6px 24px rgba(20, 24, 40, 0.12);
  --radius: 14px;
  --tabs-h: 60px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1b1e25;
    --surface-2: #252932;
    --text: #eceef2;
    --muted: #979daa;
    --line: #2d313b;
    --accent: #5b8cff;
    --accent-text: #0b0d12;
    --danger: #ff6369;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { 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 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }
a { color: var(--accent); }

.link {
  background: none; border: 0; padding: 8px 4px; color: var(--accent); font-size: 16px;
}
.link.strong { font-weight: 600; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-logo { border-radius: 18px; }
.login h1 { margin: 12px 0 4px; font-size: 28px; }
.login-buttons { display: grid; gap: 10px; margin-top: 28px; }
.login-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 50px; padding: 0 16px; border-radius: 12px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.login-btn svg { width: 20px; height: 20px; stroke: none; }
.login-btn.github { background: var(--text); color: var(--bg); border-color: var(--text); }
.login-btn.plain { background: transparent; }
.login-btn:active { transform: scale(0.98); }

/* ---------- Estructura ---------- */
.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 2px;
  padding: env(safe-area-inset-top) 8px 0 16px;
  min-height: calc(56px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.topbar h1 { flex: 1; margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.sync-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--muted);
  transition: background 0.2s;
}
#sync-btn[data-state="ok"] .sync-dot { background: var(--ok); }
#sync-btn[data-state="local"] .sync-dot { background: var(--muted); }
#sync-btn[data-state="syncing"] .sync-dot { background: var(--accent); animation: pulse 1s infinite alternate; }
#sync-btn[data-state="offline"] .sync-dot { background: var(--warn); }
#sync-btn[data-state="auth"] .sync-dot,
#sync-btn[data-state="error"] .sync-dot { background: var(--danger); }
@keyframes pulse { to { opacity: 0.3; } }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 4px 16px 8px; padding: 8px 8px 8px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface)); font-size: 14px;
}

.view { padding: 0 16px calc(var(--tabs-h) + 96px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; gap: 8px;
  padding: 6px 16px env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; max-width: 200px; height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 600;
}
.tabs button.active { color: var(--accent); }

.fab {
  position: fixed; z-index: 6;
  right: max(16px, calc(50vw - 320px + 16px));
  bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }
.fab:active { transform: scale(0.95); }

/* ---------- Agenda ---------- */
.search { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 4; padding: 4px 0 8px; background: var(--bg); }
.search input {
  width: 100%; height: 40px; padding: 0 14px; border-radius: 10px;
  border: 0; background: var(--surface-2); font-size: 16px; -webkit-appearance: none; appearance: none;
}
.more {
  display: block; width: 100%; margin: 4px 0; padding: 10px; border: 0; background: none;
  color: var(--accent); font-size: 14px; font-weight: 600;
}
.day { margin: 10px 0 18px; }
.day h3 { margin: 0 0 6px; font-size: 14px; font-weight: 500; color: var(--muted); text-transform: none; }
.day h3 strong { color: var(--text); font-weight: 700; }
.day.today h3 strong { color: var(--accent); }
.empty { color: var(--muted); margin: 6px 2px; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.event {
  width: 100%; display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 12px 14px 12px 12px; border: 0; border-radius: var(--radius);
  background: var(--surface); box-shadow: 0 1px 0 var(--line);
  border-left: 4px solid var(--c);
}
.event:active { background: var(--surface-2); }
.event .time { flex: 0 0 auto; min-width: 88px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.event .body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.event .ttl { font-weight: 600; overflow-wrap: anywhere; }
.event .nts { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event .rep { color: var(--muted); font-weight: 400; }

/* ---------- Mes ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 -8px 4px; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.grid { gap: 2px; touch-action: pan-y; }
.cell {
  aspect-ratio: 1 / 1.05; border: 0; border-radius: 12px; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; padding-top: 6px;
}
.cell .n { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.cell.out { color: var(--muted); opacity: 0.5; }
.cell.today .n { color: var(--accent); font-weight: 700; }
.cell.sel .n { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.cell:active { background: var(--surface-2); }
.dots { display: flex; gap: 3px; align-items: center; height: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }
.dots b { font-size: 10px; line-height: 1; color: var(--muted); }

/* ---------- Hojas (dialog) ---------- */
dialog.sheet {
  width: 100%; max-width: 640px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--text);
  box-shadow: var(--shadow); overflow: auto;
}
dialog.sheet[open] { animation: up 0.22s ease-out; }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
@keyframes up { from { transform: translateY(40px); opacity: 0.6; } }
@media (min-width: 700px) {
  dialog.sheet { margin: auto; border-radius: 20px; }
}
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.sheet-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }

.big-input, .notes {
  width: 100%; border: 0; border-radius: 12px; background: var(--surface); padding: 12px 14px;
}
.big-input { font-size: 20px; font-weight: 600; }
.notes { resize: vertical; min-height: 90px; font-size: 16px; }
.big-input:focus, .notes:focus, .group input:focus, .group select:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.group { background: var(--surface); border-radius: 12px; overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; padding: 6px 14px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row.wrap { min-height: 0; padding-top: 0; }
.row input:not([type=checkbox]):not([type=radio]), .row select {
  border: 0; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; min-height: 36px; font-size: 16px;
  max-width: 62%; text-align: right;
}
.row input[name=repo], .row input[name=token] { text-align: left; flex: 1; max-width: none; }
.btn-row { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--accent); text-align: left; justify-content: flex-start; }

.switch {
  -webkit-appearance: none; appearance: none; width: 50px; height: 30px; border-radius: 15px;
  background: var(--surface-2); position: relative; transition: background 0.2s; margin: 0; flex: 0 0 auto;
  border: 1px solid var(--line);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s;
}
.switch:checked { background: var(--ok); border-color: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.swatch { width: 28px; height: 28px; border-radius: 50%; background: var(--c); display: grid; place-items: center; }
.swatch input { -webkit-appearance: none; appearance: none; margin: 0; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; }
.swatch input:checked { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--c); }

.danger-btn {
  width: 100%; min-height: 48px; border: 0; border-radius: 12px; background: var(--surface);
  color: var(--danger); font-weight: 600;
}

/* ---------- Aviso ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 90px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; transition: 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
