:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #1a1d26;
  --muted: #6b7183;
  --border: #e1e4ec;
  --accent: #4f6bed;
  --accent-soft: #e6eafd;
  --accent-text: #ffffff;
  --red: #d93036;
  --red-soft: #fde8e8;
  --orange: #d9730d;
  --orange-soft: #fdf0e1;
  --yellow: #a68a00;
  --yellow-soft: #fbf5d8;
  --green: #1f9d55;
  --green-soft: #e1f5e9;
  --event: #0b8a8a;
  --event-soft: #ddf3f3;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #242833;
    --text: #e8eaf0;
    --muted: #9298a8;
    --border: #2c303b;
    --accent: #7b8ff5;
    --accent-soft: #262d4d;
    --accent-text: #0e1020;
    --red: #ff6b6f;
    --red-soft: #3a1c1f;
    --orange: #f5a35c;
    --orange-soft: #3a2a19;
    --yellow: #e3c74a;
    --yellow-soft: #34301a;
    --green: #4fd18b;
    --green-soft: #173325;
    --event: #4cc9c9;
    --event-soft: #163333;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

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

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--red); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Splash y login ---------- */
.splash { position: fixed; inset: 0; display: grid; place-items: center; }
.splash img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(400px, 100%); text-align: center; background: var(--surface);
  padding: 40px 28px; border-radius: 20px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 30px; margin-top: 12px; }
.login-card p { color: var(--muted); margin: 8px 0 28px; }
.btn.google { width: 100%; min-height: 48px; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.nav {
  position: sticky; top: 0; height: 100vh; padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { margin-left: auto; font-size: 12px; min-width: 22px; text-align: center; padding: 1px 6px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.nav .count:empty { display: none; }
.nav .count.alert { background: var(--red); color: #fff; }

.main { width: 100%; max-width: 860px; margin: 0 auto; padding: 28px 24px 48px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.top h1 { font-size: 28px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .nav {
    position: fixed; z-index: 10; inset: auto 0 0 0; height: auto; flex-direction: row; justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .brand { display: none; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; flex: 1; position: relative; }
  .nav a.active { background: transparent; }
  .nav .count { position: absolute; top: 0; left: 50%; margin-left: 6px; font-size: 10px; min-width: 18px; padding: 0 5px; }
  .main { padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
  .top h1 { font-size: 24px; }
}

/* ---------- Alta rápida ---------- */
.quick {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 22px;
  position: sticky; top: 0; z-index: 5; padding: 8px 0; background: var(--bg);
}
.quick input {
  min-width: 0; height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; box-shadow: var(--shadow);
}
.quick input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.quick .btn { width: 48px; height: 48px; padding: 0; border-radius: 12px; }
.chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.overdue { background: var(--red-soft); color: var(--red); }
.chip.due-today { background: var(--orange-soft); color: var(--orange); }
.chip.due-soon { background: var(--yellow-soft); color: var(--yellow); }
.chip.high { background: var(--red-soft); color: var(--red); }
.chip.event { background: var(--event-soft); color: var(--event); }
.chip.source { background: transparent; padding: 2px 0; }

/* ---------- Listas de tareas ---------- */
.group { margin-bottom: 26px; }
.group-title {
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 4px 8px;
}
.group-title .n { font-weight: 600; opacity: .8; }
.group-title.overdue { color: var(--red); }
.group-title.due-today { color: var(--orange); }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.task {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start;
  padding: 12px 14px; border-top: 1px solid var(--border); cursor: pointer;
}
.task:first-child { border-top: 0; }
.task:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.task .title { font-weight: 550; overflow-wrap: anywhere; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.task .meta:empty { display: none; }
.task .notes { color: var(--muted); font-size: 13px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task.leaving { animation: leave .35s ease forwards; }
@keyframes leave { to { opacity: 0; transform: translateX(16px); } }

.check {
  width: 24px; height: 24px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--border);
  background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0; color: transparent;
}
.check svg { width: 14px; height: 14px; stroke-width: 3; }
.check:hover { border-color: var(--green); color: var(--green); }
.task.p2 .check { border-color: var(--red); }
.task.done .check { background: var(--green); border-color: var(--green); color: #fff; }

.event-row { display: grid; grid-template-columns: 56px 1fr; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); text-decoration: none; color: inherit; }
.event-row:first-child { border-top: 0; }
.event-row .time { color: var(--event); font-weight: 700; font-size: 13px; padding-top: 1px; }
.event-row .title::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--event); margin-right: 8px; vertical-align: 1px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------- Agenda ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head h2 { font-size: 18px; margin-right: auto; }
.cal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 22px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-dow { padding: 8px 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; border-bottom: 1px solid var(--border); }
.cal-day {
  min-height: 92px; padding: 6px; border: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column; gap: 3px;
}
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day:hover { background: var(--surface-2); }
.cal-day.other { color: var(--muted); opacity: .55; }
.cal-day .num { font-size: 13px; font-weight: 700; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .num { background: var(--accent); color: var(--accent-text); }
.cal-day.selected { background: var(--accent-soft); }
.cal-item { font-size: 11px; line-height: 1.3; padding: 1px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--accent-soft); color: var(--accent); }
.cal-item.ev { background: var(--event-soft); color: var(--event); }
.cal-item.dl { background: var(--orange-soft); color: var(--orange); }
.cal-item.overdue { background: var(--red-soft); color: var(--red); }
.cal-item.done { text-decoration: line-through; opacity: .6; }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.dots { display: none; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.dots i.ev { background: var(--event); }
.dots i.dl { background: var(--orange); }
@media (max-width: 760px) {
  .cal-day { min-height: 52px; align-items: center; padding: 4px 2px; }
  .cal-item, .cal-more { display: none; }
  .dots { display: flex; }
}

/* ---------- Ajustes ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card h2 { font-size: 17px; display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.card p { color: var(--muted); margin: 6px 0 14px; }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.status.ok { background: var(--green-soft); color: var(--green); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--border); }
.setting:first-of-type { border-top: 0; }
.setting small { display: block; color: var(--muted); }
.code {
  font: 600 15px/1 ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--surface-2);
  padding: 10px 12px; border-radius: 10px; user-select: all; overflow-wrap: anywhere;
}
.steps { margin: 0 0 14px; padding-left: 20px; color: var(--muted); }
.steps li { margin: 4px 0; }
select, .sheet input, .sheet textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
}

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: relative; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--border); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Editor ---------- */
.sheet {
  width: min(520px, calc(100% - 24px)); border: 0; border-radius: 18px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
.sheet::backdrop { background: rgb(10 12 20 / 45%); }
.sheet form { padding: 18px 20px 20px; display: grid; gap: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 18px; }
.sheet label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.sheet input, .sheet textarea { width: 100%; font-size: 15px; font-weight: 400; }
.sheet textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { border: 0; padding: 0; margin: 0; display: flex; gap: 6px; }
.seg legend { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
.seg label { display: block; flex: 1; }
.seg input { position: absolute; opacity: 0; width: 1px; }
.seg span { display: block; text-align: center; padding: 8px; border-radius: 10px; border: 1px solid var(--border); color: var(--text); cursor: pointer; font-weight: 600; }
.seg input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.sheet-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
@media (max-width: 760px) {
  .sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .row2 { grid-template-columns: 1fr; }
}

/* ---------- Aviso ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 500;
}
.toast button { background: none; border: 0; color: var(--accent-soft); font: inherit; font-weight: 700; cursor: pointer; padding: 0; }
@media (max-width: 760px) { .toast { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); } }
