/* ==========================================================================
   Zend — Sistema de diseño (UI/UX Pro Max: "Calendar & Scheduling App", dark)
   Base flat + micro-interacciones; glassmorphism solo en navegación/overlays.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Paleta (tokens semánticos del design system) */
  --color-background: #0F172A;
  --color-background-deep: #0A1020;
  --color-card: #111827;
  --color-card-raised: #162033;
  --color-muted: #1E293B;
  --color-foreground: #F8FAFC;
  --color-muted-foreground: #CBD5E1;
  --color-subtle-foreground: #94A3B8;
  --color-border: #334155;
  --color-border-soft: rgba(148, 163, 184, 0.16);
  --color-primary: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-on-primary: #FFFFFF;
  --color-primary-text: #60A5FA;
  --color-primary-tint: rgba(37, 99, 235, 0.16);
  --color-secondary: #3B82F6;
  --color-accent: #059669;
  --color-accent-hover: #047857;
  --color-on-accent: #FFFFFF;
  --color-accent-text: #34D399;
  --color-accent-tint: rgba(5, 150, 105, 0.16);
  --color-warning-text: #FBBF24;
  --color-warning-tint: rgba(245, 158, 11, 0.14);
  --color-destructive: #DC2626;
  --color-destructive-text: #F87171;
  --color-destructive-tint: rgba(220, 38, 38, 0.14);
  --color-ring: #60A5FA;

  /* Glass (solo navegación, composer y overlays) */
  --glass-bg: rgba(15, 23, 42, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
  --blur-amount: 15px;

  /* Tipografía */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --text-xs: 0.8125rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  /* Espaciado (ritmo 4/8) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Radios */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 999px;

  /* Movimiento (tokens por contexto) */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --dur-fast: 150ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;

  /* Layout */
  --sidebar-w: 248px;
  --bottom-nav-h: 68px;
  --touch: 44px;
  --hour-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-foreground);
  background: var(--color-background);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body::before {
  /* Fondo con color suficiente para que el glass tenga qué difuminar */
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60vmax 50vmax at 85% -10%, rgba(37, 99, 235, 0.18), transparent 60%),
    radial-gradient(50vmax 40vmax at -10% 110%, rgba(5, 150, 105, 0.12), transparent 60%),
    var(--color-background);
}
h1, h2, h3, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.9em; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-4); top: -100px; z-index: 100;
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm);
  background: var(--color-primary); color: var(--color-on-primary); text-decoration: none;
}
.skip-link:focus { top: calc(var(--space-4) + var(--safe-top)); }

:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }

.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--blur-amount)) saturate(140%);
  backdrop-filter: blur(var(--blur-amount)) saturate(140%);
  border: 1px solid var(--glass-border);
}

.muted { color: var(--color-subtle-foreground); font-size: var(--text-sm); }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: flex; flex-direction: column; gap: var(--space-6);
  padding: calc(var(--space-6) + var(--safe-top)) var(--space-4) var(--space-4);
  border-width: 0 1px 0 0;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-2); }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--radius-md); background: var(--color-primary);
}
.brand-mark svg, .reply-avatar svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand-name { font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.02em; }

.side-nav { display: flex; flex-direction: column; gap: var(--space-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--touch); padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-muted-foreground); text-decoration: none; font-weight: 500;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.nav-item:hover { background: var(--color-muted); color: var(--color-foreground); }
.nav-item[aria-current="page"] { background: var(--color-primary-tint); color: var(--color-primary-text); }
.nav-badge {
  margin-left: auto; min-width: 24px; height: 24px; padding: 0 var(--space-2);
  display: inline-grid; place-items: center; border-radius: var(--radius-full);
  background: var(--color-primary); color: var(--color-on-primary);
  font-size: var(--text-xs); font-weight: 600; font-variant-numeric: tabular-nums;
}

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-3); }
.wake-card {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg); background: var(--color-card); border: 1px solid var(--color-border-soft);
}
.wake-card-text { display: flex; flex-direction: column; min-width: 0; }
.wake-title { font-weight: 600; font-size: var(--text-sm); }
.wake-sub { font-size: var(--text-xs); color: var(--color-subtle-foreground); }
.wake-card.is-listening .wake-sub { color: var(--color-accent-text); }
.wake-card.is-unsupported { opacity: 0.7; }

.conn-pill {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-full);
  font-size: var(--text-xs); color: var(--color-subtle-foreground);
  background: var(--color-card); border: 1px solid var(--color-border-soft);
}
.conn-pill.is-online { color: var(--color-accent-text); }
.conn-pill.is-offline { color: var(--color-warning-text); }

.main {
  position: relative;
  display: flex; flex-direction: column;
  min-width: 0; height: 100dvh;
  overflow-y: auto; overscroll-behavior: contain;
  padding: calc(var(--space-6) + var(--safe-top)) clamp(var(--space-4), 3vw, var(--space-8)) 0;
  scroll-padding-bottom: 140px;
}
.main:focus { outline: none; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.eyebrow { font-size: var(--text-sm); color: var(--color-subtle-foreground); }
.greeting { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; text-wrap: balance; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }
.conn-dot {
  display: none; width: 10px; height: 10px; border-radius: 50%;
  background: var(--color-warning-text); box-shadow: 0 0 0 4px var(--color-warning-tint);
}
.conn-dot.is-online { background: var(--color-accent-text); box-shadow: 0 0 0 4px var(--color-accent-tint); }

.view { flex: 1 0 auto; padding-bottom: var(--space-6); animation: view-in var(--dur-slow) var(--ease-out); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-title { font-size: var(--text-xl); font-weight: 600; margin-bottom: var(--space-4); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--touch); padding: 0 var(--space-4);
  border-radius: var(--radius-md); border: 1px solid transparent;
  font-weight: 600; font-size: var(--text-sm); white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.8; }
.btn:disabled, .icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn-success { background: var(--color-accent); color: var(--color-on-accent); }
.btn-success:hover:not(:disabled) { background: var(--color-accent-hover); }
.btn-ghost { background: transparent; border-color: var(--color-border); color: var(--color-foreground); }
.btn-ghost:hover:not(:disabled) { background: var(--color-muted); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--color-destructive-text); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--color-destructive-tint); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--touch); height: var(--touch); flex: none;
  border-radius: var(--radius-md); border: 1px solid transparent; background: transparent;
  color: var(--color-muted-foreground);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover:not(:disabled) { background: var(--color-muted); color: var(--color-foreground); }
.icon-btn-sm { width: 36px; height: 36px; }
.icon-btn-sm::after { content: ""; position: absolute; inset: -4px; }
.icon-btn-sm { position: relative; }

.link { color: var(--color-primary-text); font-size: var(--text-sm); font-weight: 500; text-decoration: none; padding: var(--space-2) 0; }
.link:hover { text-decoration: underline; }

/* ---------- Tarjetas / paneles ---------- */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-lg);
}
.panel { padding: var(--space-5); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.panel-title { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-lg); font-weight: 600; }
.panel-title .icon { color: var(--color-primary-text); }
.panel-sub { font-size: var(--text-sm); color: var(--color-subtle-foreground); }

.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
}
.chip-primary { background: var(--color-primary-tint); color: var(--color-primary-text); }
.chip-success { background: var(--color-accent-tint); color: var(--color-accent-text); }
.chip-warning { background: var(--color-warning-tint); color: var(--color-warning-text); }
.chip-muted { background: var(--color-muted); color: var(--color-muted-foreground); }

/* ---------- Vista Hoy ---------- */
.today-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  grid-template-areas: "next stats" "upcoming day";
}
.next-card { grid-area: next; padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-3);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.22), rgba(17, 24, 39, 0.9) 60%), var(--color-card);
  border-color: rgba(96, 165, 250, 0.25); }
.next-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.next-countdown { font-size: var(--text-sm); font-weight: 600; color: var(--color-primary-text); font-variant-numeric: tabular-nums; }
.next-title { font-size: var(--text-xl); font-weight: 700; line-height: 1.3; text-wrap: balance; overflow-wrap: anywhere; }
.next-meta { color: var(--color-muted-foreground); font-size: var(--text-sm); }
.next-actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); flex-wrap: wrap; }

.stats { grid-area: stats; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.stat {
  display: flex; flex-direction: column; justify-content: center; gap: var(--space-1);
  padding: var(--space-5); border-radius: var(--radius-lg);
  background: var(--color-card); border: 1px solid var(--color-border-soft);
}
.stat-value { font-size: var(--text-2xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-xs); color: var(--color-subtle-foreground); }
.upcoming-panel { grid-area: upcoming; }
.day-panel { grid-area: day; }

/* ---------- Lista de tareas ---------- */
.task-list { display: flex; flex-direction: column; gap: var(--space-2); }
.task-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 64px; padding: var(--space-3);
  border-radius: var(--radius-md); background: var(--color-card-raised);
  border: 1px solid transparent;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
  animation: item-in var(--dur-slow) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
.task-item:hover { border-color: var(--color-border); }
@keyframes item-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.task-check {
  display: grid; place-items: center; flex: none;
  width: var(--touch); height: var(--touch); margin: calc(var(--space-2) * -1) 0;
  border: 0; background: transparent; border-radius: var(--radius-full); color: var(--color-subtle-foreground);
}
.task-check-ring {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--color-border);
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.task-check-ring .icon { width: 14px; height: 14px; opacity: 0; transition: opacity var(--dur-fast) var(--ease-out); }
.task-check:hover .task-check-ring { border-color: var(--color-accent-text); }
.task-check:hover .task-check-ring .icon { opacity: 1; color: var(--color-accent-text); }
.task-item.is-done .task-check-ring { background: var(--color-accent); border-color: var(--color-accent); }
.task-item.is-done .task-check-ring .icon { opacity: 1; color: #fff; }
.task-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
}
.task-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-item.is-done .task-title { text-decoration: line-through; color: var(--color-subtle-foreground); }
.task-meta { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  font-size: var(--text-xs); color: var(--color-subtle-foreground); }
.task-meta .icon { width: 14px; height: 14px; }
.task-side { display: flex; align-items: center; gap: var(--space-1); flex: none; }

.group-title {
  display: flex; align-items: center; gap: var(--space-2);
  margin: var(--space-5) 0 var(--space-2); font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-subtle-foreground);
}
.group-title:first-child { margin-top: 0; }
.group-count { font-variant-numeric: tabular-nums; color: var(--color-muted-foreground); }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  padding: var(--space-8) var(--space-4); text-align: center; color: var(--color-subtle-foreground);
}
.empty .icon { width: 32px; height: 32px; color: var(--color-border); }
.empty-title { color: var(--color-muted-foreground); font-weight: 600; }

.skeleton {
  height: 64px; border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--color-card-raised) 25%, var(--color-muted) 50%, var(--color-card-raised) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.segmented { display: inline-flex; padding: 3px; border-radius: var(--radius-md); background: var(--color-muted); }
.segment {
  min-height: 38px; padding: 0 var(--space-4); border: 0; border-radius: 9px; background: transparent;
  color: var(--color-muted-foreground); font-size: var(--text-sm); font-weight: 600;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.segment[aria-selected="true"] { background: var(--color-card); color: var(--color-foreground); }

/* ---------- Agenda / línea de tiempo ---------- */
.agenda-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.agenda-nav { display: flex; align-items: center; gap: var(--space-1); }

.week-strip {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.week-day {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 64px; padding: var(--space-2) 0;
  border: 1px solid var(--color-border-soft); border-radius: var(--radius-md);
  background: var(--color-card-raised); color: var(--color-muted-foreground);
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.week-day:hover { border-color: var(--color-border); }
.week-day-name { font-size: var(--text-xs); text-transform: capitalize; }
.week-day-num { font-size: var(--text-lg); font-weight: 700; color: var(--color-foreground); font-variant-numeric: tabular-nums; }
.week-day-dots { display: flex; gap: 3px; height: 6px; }
.week-day-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--color-primary-text); }
.week-day.is-today .week-day-num { color: var(--color-primary-text); }
.week-day[aria-selected="true"] { background: var(--color-primary); border-color: var(--color-primary); color: rgba(255,255,255,0.85); }
.week-day[aria-selected="true"] .week-day-num { color: #fff; }
.week-day[aria-selected="true"] .week-day-dots i { background: #fff; }

.timeline {
  position: relative;
  max-height: min(64vh, 720px);
  overflow-y: auto; overscroll-behavior: contain;
  border-radius: var(--radius-md);
  scroll-behavior: smooth;
}
.timeline-compact { --hour-h: 52px; max-height: 420px; }
.timeline-grid { position: relative; padding-top: 12px; }
.hour-row {
  position: relative; display: flex; height: var(--hour-h);
  border-top: 1px solid var(--color-border-soft);
}
.hour-row:first-child { border-top-color: transparent; }
.hour-label {
  width: 56px; flex: none; padding-right: var(--space-2);
  transform: translateY(-0.6em); text-align: right;
  font-size: var(--text-xs); color: var(--color-subtle-foreground); font-variant-numeric: tabular-nums;
}
.hour-slot {
  flex: 1; border: 0; background: transparent; border-radius: var(--radius-sm);
  transition: background-color var(--dur-fast) var(--ease-out);
}
.hour-slot:hover { background: rgba(96, 165, 250, 0.06); }
.hour-slot:focus-visible { outline-offset: -2px; }
.hour-row.is-past .hour-label { opacity: 0.6; }

.events-layer { position: absolute; inset: 12px 0 0 64px; pointer-events: none; }
.event {
  position: absolute; pointer-events: auto;
  display: flex; flex-direction: row; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm); border: 0; border-left: 3px solid var(--color-primary-text);
  background: var(--color-primary-tint); color: var(--color-foreground);
  text-align: left; overflow: hidden;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  animation: item-in var(--dur-slow) var(--ease-out) both;
}
.event:hover { background: rgba(37, 99, 235, 0.28); }
.event-title { min-width: 0; font-size: var(--text-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-time { flex: none; font-size: var(--text-xs); color: var(--color-muted-foreground); font-variant-numeric: tabular-nums; }
.event.is-overdue { border-left-color: var(--color-warning-text); background: var(--color-warning-tint); }
.event.is-done { border-left-color: var(--color-accent-text); background: var(--color-accent-tint); }
.event.is-done .event-title { text-decoration: line-through; color: var(--color-muted-foreground); }

.now-line {
  position: absolute; left: 56px; right: 0; height: 2px; z-index: 2; pointer-events: none;
  background: var(--color-destructive-text);
}
.now-line::before {
  content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--color-destructive-text);
}
.now-line span {
  position: absolute; right: 0; top: -22px; padding: 1px var(--space-2);
  font-size: var(--text-xs); font-weight: 600; border-radius: var(--radius-sm);
  background: var(--color-destructive-tint); color: var(--color-destructive-text);
}

/* ---------- Ajustes ---------- */
.settings-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); padding-bottom: var(--space-4); }
.pair-body { display: flex; gap: var(--space-5); align-items: flex-start; flex-wrap: wrap; }
.qr-box {
  display: grid; place-items: center; width: 168px; height: 168px; flex: none; padding: var(--space-2);
  border-radius: var(--radius-md); background: #fff; color: #0F172A; text-align: center;
}
.qr-box .muted { color: #334155; font-size: var(--text-xs); }
.qr-box img { width: 100%; height: 100%; }
.pair-info { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: var(--space-3); }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-2) var(--space-3); align-items: center; }
.kv dt { font-size: var(--text-xs); color: var(--color-subtle-foreground); }
.kv dd { display: flex; align-items: center; gap: var(--space-1); min-width: 0; font-size: var(--text-sm); }
.kv dd code { overflow-wrap: anywhere; padding: 2px var(--space-2); border-radius: 6px; background: var(--color-muted); }
.kv-grid dd { color: var(--color-muted-foreground); }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-3) 0; border-top: 1px solid var(--color-border-soft);
}
.setting-row:first-of-type { border-top: 0; }
.setting-name { font-weight: 500; }
.ntfy-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.setting-desc { font-size: var(--text-xs); color: var(--color-subtle-foreground); }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; min-width: var(--touch); min-height: var(--touch); justify-content: center; cursor: pointer; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  width: 44px; height: 26px; border-radius: var(--radius-full); background: var(--color-border);
  position: relative; transition: background-color var(--dur-base) var(--ease-out);
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform var(--dur-base) var(--ease-spring);
}
.switch input:checked + .switch-track { background: var(--color-accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--color-ring); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.4; }

/* ---------- Composer ---------- */
.composer {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; flex-direction: column; gap: var(--space-2);
  margin: auto calc(clamp(var(--space-4), 3vw, var(--space-8)) * -1) 0;
  padding: var(--space-3) clamp(var(--space-4), 3vw, var(--space-8)) calc(var(--space-3) + var(--safe-bottom));
  border-width: 1px 0 0;
}
.composer-form { display: flex; align-items: flex-start; gap: var(--space-2); }
.composer-field { flex: 1; min-width: 0; }
.composer-field input {
  width: 100%; min-height: 48px; padding: 0 var(--space-4);
  border-radius: var(--radius-md); border: 1px solid var(--color-border);
  background: var(--color-card); color: var(--color-foreground);
  transition: border-color var(--dur-fast) var(--ease-out);
}
.composer-field input::placeholder { color: var(--color-subtle-foreground); }
.composer-field input:focus { border-color: var(--color-ring); outline: none; box-shadow: 0 0 0 3px rgba(96,165,250,0.25); }
.composer-preview { min-height: 1.25em; margin-top: var(--space-1); padding-left: var(--space-1); font-size: var(--text-xs); color: var(--color-primary-text); }
.composer-preview:empty { min-height: 0; margin: 0; }
.mic-btn, .send-btn { width: 48px; height: 48px; border-radius: var(--radius-md); }
.send-btn { background: var(--color-primary); color: #fff; }
.send-btn:hover:not(:disabled) { background: var(--color-primary-hover); color: #fff; }
.mic-btn { background: var(--color-muted); color: var(--color-foreground); }
.mic-btn[aria-pressed="true"] { background: var(--color-destructive); color: #fff; }

.reply {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3); border-radius: var(--radius-md);
  background: var(--color-card); border: 1px solid var(--color-border-soft);
  animation: item-in var(--dur-base) var(--ease-out);
}
.reply-avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 10px; background: var(--color-primary); }
.reply-avatar svg { width: 16px; height: 16px; }
.reply-body { flex: 1; min-width: 0; }
.reply-you { font-size: var(--text-xs); color: var(--color-subtle-foreground); }
.reply-you:empty { display: none; }
.reply-text { font-size: var(--text-sm); color: var(--color-foreground); }
.reply.is-error .reply-avatar { background: var(--color-warning-tint); }

/* ---------- Navegación inferior ---------- */
.bottom-nav { display: none; }

/* ---------- Capa de escucha ---------- */
.listening {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--space-4);
  background: rgba(2, 6, 23, 0.7);
  animation: fade-in var(--dur-base) var(--ease-out);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.listening-card {
  width: min(420px, 100%); padding: var(--space-8) var(--space-6); border-radius: var(--radius-xl);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3); text-align: center;
}
.orb { position: relative; width: 120px; height: 120px; display: grid; place-items: center; margin-bottom: var(--space-2); --level: 0; }
.orb-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.45), rgba(37, 99, 235, 0) 70%);
  transform: scale(calc(0.85 + var(--level) * 0.6));
  transition: transform 90ms linear;
}
.orb-core {
  position: relative; display: grid; place-items: center; width: 76px; height: 76px; border-radius: 50%;
  background: var(--color-primary); color: #fff;
}
.orb-core .icon { width: 30px; height: 30px; }
.orb.is-processing .orb-core { background: var(--color-muted); }
.orb.is-processing .orb-ring { animation: pulse 1.2s var(--ease-out) infinite; }
@keyframes pulse { 0% { transform: scale(0.85); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
.listening-title { font-size: var(--text-lg); font-weight: 600; }
.listening-sub { font-size: var(--text-sm); color: var(--color-subtle-foreground); }
.listening-actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); }

/* ---------- Modales ---------- */
.modal {
  width: min(560px, calc(100% - 2 * var(--space-4)));
  max-height: calc(100dvh - 2 * var(--space-4));
  padding: 0; border: 0; border-radius: var(--radius-xl);
  background: transparent; color: var(--color-foreground);
}
.modal::backdrop { background: rgba(2, 6, 23, 0.72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal[open] { animation: modal-in var(--dur-slow) var(--ease-out); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-card {
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-6); border-radius: var(--radius-xl);
  background: var(--color-card); border: 1px solid var(--color-border);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.modal-title { font-size: var(--text-xl); font-weight: 700; }
.modal-foot { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.spacer { flex: 1; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field label, .field .label { font-size: var(--text-sm); font-weight: 600; color: var(--color-muted-foreground); }
.optional { font-weight: 400; color: var(--color-subtle-foreground); }
.field input, .field textarea {
  width: 100%; min-height: var(--touch); padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md); border: 1px solid var(--color-border);
  background: var(--color-background); color: var(--color-foreground);
  transition: border-color var(--dur-fast) var(--ease-out);
}
.field textarea { resize: vertical; min-height: 72px; }
.field input:focus, .field textarea:focus { border-color: var(--color-ring); outline: none; box-shadow: 0 0 0 3px rgba(96,165,250,0.25); }
.field input[aria-invalid="true"] { border-color: var(--color-destructive-text); }
.field input::-webkit-calendar-picker-indicator { filter: invert(0.8); cursor: pointer; }
.field-help { font-size: var(--text-xs); color: var(--color-subtle-foreground); }
.field-error { font-size: var(--text-xs); color: var(--color-destructive-text); font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip-toggle { position: relative; }
.chip-toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip-toggle span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--space-4);
  border-radius: var(--radius-full); border: 1px solid var(--color-border);
  font-size: var(--text-sm); font-weight: 500; color: var(--color-muted-foreground);
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.chip-toggle input:checked + span { background: var(--color-primary-tint); border-color: var(--color-primary-text); color: var(--color-primary-text); }
.chip-toggle input:checked + span::before { content: ""; width: 6px; height: 6px; margin-right: var(--space-2); border-radius: 50%; background: currentColor; }
.chip-toggle input:focus-visible + span { outline: 2px solid var(--color-ring); outline-offset: 2px; }

/* ---------- Alerta a pantalla ---------- */
.alert-overlay {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: var(--space-4);
  background: rgba(2, 6, 23, 0.82);
  animation: fade-in var(--dur-base) var(--ease-out);
}
.alert-card {
  width: min(460px, 100%); padding: var(--space-8) var(--space-6);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3); text-align: center;
  border-radius: var(--radius-xl); background: var(--color-card); border: 1px solid rgba(96, 165, 250, 0.35);
  animation: modal-in var(--dur-slow) var(--ease-spring);
}
.alert-icon {
  display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%;
  background: var(--color-primary); color: #fff; animation: ring 1.2s var(--ease-out) 2;
}
.alert-icon .icon { width: 28px; height: 28px; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); } 45% { transform: rotate(8deg); } 60% { transform: rotate(-4deg); } }
.alert-kicker { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-primary-text); }
.alert-overlay.is-missed .alert-icon { background: var(--color-warning-text); color: #0F172A; }
.alert-overlay.is-missed .alert-kicker { color: var(--color-warning-text); }
.alert-title { font-size: var(--text-xl); font-weight: 700; overflow-wrap: anywhere; }
.alert-text { color: var(--color-muted-foreground); }
.alert-actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; justify-content: center; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 90; right: var(--space-4); bottom: calc(var(--space-4) + var(--safe-bottom));
  display: flex; flex-direction: column; gap: var(--space-2); width: min(380px, calc(100% - 2 * var(--space-4)));
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--space-3); pointer-events: auto;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--color-card-raised); border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  animation: toast-in var(--dur-base) var(--ease-out);
}
.toast.is-leaving { animation: toast-out var(--dur-fast) var(--ease-out) forwards; }
.toast .icon { color: var(--color-primary-text); }
.toast.is-success .icon { color: var(--color-accent-text); }
.toast.is-error .icon { color: var(--color-destructive-text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
  .today-grid { grid-template-columns: 1fr; grid-template-areas: "next" "stats" "upcoming" "day"; }
}

@media (max-width: 1023px) {
  :root { --sidebar-w: 80px; }
  .sidebar { padding-left: var(--space-3); padding-right: var(--space-3); align-items: center; }
  .brand-name, .nav-item span:not(.nav-badge), .wake-card-text, .conn-pill span { display: none; }
  .nav-item { justify-content: center; width: 52px; padding: 0; position: relative; }
  .nav-badge { position: absolute; top: 2px; right: 0; min-width: 20px; height: 20px; font-size: 11px; }
  .wake-card { padding: var(--space-2); justify-content: center; }
  .conn-pill { justify-content: center; padding: var(--space-2); }
}

@media (max-width: 767px) {
  :root { --hour-h: 56px; }
  body { overflow: hidden; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main {
    padding: calc(var(--space-4) + var(--safe-top)) calc(var(--space-4) + var(--safe-right)) 0 calc(var(--space-4) + var(--safe-left));
    height: 100dvh;
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
  }
  .topbar { margin-bottom: var(--space-4); align-items: center; }
  .greeting { font-size: var(--text-xl); }
  .btn-primary#btn-new span { display: none; }
  .btn-primary#btn-new { width: var(--touch); padding: 0; }
  .conn-dot { display: inline-block; }
  .stats { gap: var(--space-2); }
  .stat { padding: var(--space-3); }
  .stat-value { font-size: var(--text-xl); }
  .panel { padding: var(--space-4); }
  .next-card { padding: var(--space-5); }
  .timeline { max-height: none; overflow: visible; }
  .week-strip { gap: var(--space-1); }
  .week-day { min-height: 58px; }
  .composer {
    margin-left: calc(-1 * (var(--space-4) + var(--safe-left)));
    margin-right: calc(-1 * (var(--space-4) + var(--safe-right)));
    padding: var(--space-2) calc(var(--space-4) + var(--safe-right)) var(--space-2) calc(var(--space-4) + var(--safe-left));
  }
  .composer .mic-btn { display: none; }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    border-width: 1px 0 0;
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    height: 100%; min-height: 48px; text-decoration: none; color: var(--color-subtle-foreground);
    font-size: 11px; font-weight: 600; -webkit-tap-highlight-color: transparent;
    transition: color var(--dur-fast) var(--ease-out);
  }
  .tab[aria-current="page"] { color: var(--color-primary-text); }
  .tab:active { opacity: 0.7; }
  .tab-fab {
    justify-self: center; display: grid; place-items: center;
    width: 56px; height: 56px; margin-top: -20px; border: 0; border-radius: 50%;
    background: var(--color-primary); color: #fff;
    box-shadow: 0 0 0 6px var(--color-background);
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  }
  .tab-fab:active { transform: scale(0.94); }
  .tab-fab .icon { width: 24px; height: 24px; }
  .toasts { bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 76px); left: var(--space-4); right: var(--space-4); width: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { width: 100%; max-width: none; margin: auto 0 0; max-height: 92dvh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  .modal-card { border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding-bottom: calc(var(--space-6) + var(--safe-bottom)); max-height: 92dvh; overflow-y: auto; }
  .modal-foot .btn { flex: 1; }
  .modal-foot .spacer { display: none; }
  .pair-body { flex-direction: column; align-items: center; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr 1fr 1fr; }
  .stat-label { font-size: 11px; }
  .week-day-name { font-size: 11px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .listening-card { padding: var(--space-4); }
  .orb { width: 88px; height: 88px; }
  .orb-core { width: 56px; height: 56px; }
}

@media (hover: none) {
  .task-item:hover, .week-day:hover { border-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .orb-ring { transform: none !important; }
}

@media (forced-colors: active) {
  .btn, .icon-btn, .chip-toggle span, .week-day { border: 1px solid ButtonText; }
}
