:root {
  --bg: #f7f4fb;
  --card: #ffffff;
  --text: #241c33;
  --muted: #6d6480;
  --line: #e6dff0;
  --brand: #7a4bd6;
  --brand-soft: #efe7fc;
  --brand-text: #ffffff;
  --danger: #c2334d;
  --ok: #2f8f5b;
  --p1: #c2334d;
  --p2: #d9822b;
  --p3: #4a78c9;
  --p4: #8b8f99;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(36, 28, 51, 0.07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15111d;
    --card: #211b2d;
    --text: #f1ecf8;
    --muted: #a99fbb;
    --line: #342b44;
    --brand: #a57cf0;
    --brand-soft: #2d2342;
    --brand-text: #15111d;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.loading { text-align: center; color: var(--muted); padding: 40vh 16px 0; }

/* ---------- Estructura ---------- */
.shell { max-width: 760px; margin: 0 auto; min-height: 100vh; padding: 0 16px calc(88px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 12px; padding: calc(14px + env(safe-area-inset-top)) 0 10px; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--brand), #d46bb3);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.topbar h1 { font-size: 19px; margin: 0; line-height: 1.2; }
.ai-badge { font-size: 12px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; color: var(--muted); font-size: 14px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav .inner { display: flex; width: 100%; max-width: 760px; }
.bottomnav button {
  flex: 1; background: none; border: 0; padding: 6px 2px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted);
}
.bottomnav button .ico { font-size: 21px; line-height: 1; }
.bottomnav button[aria-current="page"] { color: var(--brand); background: var(--brand-soft); font-weight: 600; }

h2 { font-size: 22px; margin: 14px 0 4px; }
.sub { color: var(--muted); margin: 0 0 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.error { color: var(--danger); }
.notice { background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }

/* ---------- Listas ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.tabs button { flex: none; border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 999px; font-size: 14px; }
.tabs button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-text); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 10px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .check { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--line); background: none; display: grid; place-items: center; font-size: 14px; margin-top: 1px; }
.item.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.item.done .title { text-decoration: line-through; color: var(--muted); }
.item .body { flex: 1; min-width: 0; }
.item .title { overflow-wrap: anywhere; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.item .notes { font-size: 14px; color: var(--muted); white-space: pre-wrap; margin-top: 4px; overflow-wrap: anywhere; }
.item .del { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 0 4px; }
.prio { font-weight: 600; }
.prio-1 { color: var(--p1); } .prio-2 { color: var(--p2); } .prio-3 { color: var(--p3); } .prio-4 { color: var(--p4); }
.overdue { color: var(--danger); font-weight: 600; }

/* ---------- Formularios ---------- */
form.add { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; min-width: 0; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px;
}
textarea { resize: vertical; min-height: 90px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 8px; }
label.inline input { width: auto; }
.btn { border: 0; border-radius: 12px; padding: 10px 16px; background: var(--brand); color: var(--brand-text); font-weight: 600; }
.btn.secondary { background: var(--brand-soft); color: var(--text); }
.btn.danger { background: none; border: 1px solid var(--danger); color: var(--danger); }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- Conversación ---------- */
.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--brand); color: var(--brand-text); border-bottom-right-radius: 6px; }
.bubble.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.thinking { color: var(--muted); font-style: italic; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 9;
  display: flex; justify-content: center; padding: 8px 16px; background: linear-gradient(transparent, var(--bg) 30%);
}
.composer form { display: flex; gap: 8px; width: 100%; max-width: 728px; }
.composer input { flex: 1; border-radius: 999px; background: var(--card); }
.mic { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 20px; }
.mic.listening { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
.send { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-text); font-size: 19px; }
.chat-space { height: 70px; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* ---------- Acceso ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: 10vh 16px 32px; }
.auth .avatar { width: 72px; height: 72px; font-size: 32px; margin: 0 auto 12px; }
.auth h1 { text-align: center; margin: 0 0 4px; }
.auth p { text-align: center; color: var(--muted); margin: 0 0 20px; }
.small { font-size: 13px; color: var(--muted); }
.error:empty, [role="status"]:empty { display: none; }
button.card { width: 100%; text-align: left; font: inherit; }

/* ---------- Campanita ---------- */
.bell { position: relative; background: none; border: 1px solid var(--line); border-radius: 999px; width: 40px; height: 40px; font-size: 18px; }
.bell .badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.panel { position: fixed; z-index: 20; top: calc(64px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(728px, calc(100% - 32px)); max-height: 70vh; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 12px 14px; }
.panel .item.unread .title { font-weight: 700; }
.panel header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; color: var(--text); }
.chips input { width: auto; }
.soon { opacity: .65; }
