/* ============================================================
   Calendar+ — design tokens
   Palette: Mist (cool light bg) / Void (dark bg) / Aurora (primary
   accent, violet) / Ember (secondary accent, warm coral — reserved
   for "today" + important markers only, never decorative).
   Type: ui-rounded for day numbers & headings (distinct, native-
   feeling, zero network cost) · system-ui for body/UI chrome.
   Signature: the "today" cell — a slow conic-gradient halo ring
   around the date number, and a mini stacked bar per event instead
   of a plain dot, so category color reads clearly at a glance.
   ============================================================ */

:root {
  --mist: #F1F2F7;
  --mist-card: rgba(255, 255, 255, 0.62);
  --void: #0B0B10;
  --void-card: rgba(28, 28, 34, 0.58);
  --ink: #15151C;
  --ink-soft: #5B5B66;
  --paper-line: rgba(20, 20, 30, 0.08);

  --aurora: #6E5BFF;
  --aurora-soft: rgba(110, 91, 255, 0.14);
  --ember: #FF6B5D;

  --cat-trabajo: #6E56CF;
  --cat-personal: #0A84FF;
  --cat-estudios: #E3A008;
  --cat-salud: #2FB88E;
  --cat-familia: #FF5FA0;
  --cat-viajes: #FF8A3D;
  --cat-cumpleanos: #D6408C;
  --cat-otros: #8E8E93;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --hour-height: 56px;
  --font-scale: 1;

  --bg: var(--mist);
  --card: var(--mist-card);
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --line: var(--paper-line);
  --blur: 22px;
  --shadow: 0 8px 30px rgba(20, 20, 40, 0.08);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--void);
    --card: var(--void-card);
    --text: #F2F2F7;
    --text-soft: #9A9AA5;
    --line: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  }
}
html[data-theme="light"] {
  --bg: var(--mist); --card: var(--mist-card); --text: var(--ink);
  --text-soft: var(--ink-soft); --line: var(--paper-line); --shadow: 0 8px 30px rgba(20,20,40,.08);
}
html[data-theme="dark"] {
  --bg: var(--void); --card: var(--void-card); --text: #F2F2F7;
  --text-soft: #9A9AA5; --line: rgba(255,255,255,.08); --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'system-ui', 'Segoe UI', Roboto, sans-serif;
  font-size: calc(16px * var(--font-scale));
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

.numeric, .daynum, .wdh-label, .hour-label { font-family: ui-rounded, -apple-system, 'system-ui', sans-serif; font-variant-numeric: tabular-nums; }

/* ---------- App shell ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 640px; margin: 0 auto; position: relative; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
}
.topbar h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; text-transform: capitalize; padding: 4px 10px; border-radius: 10px; cursor: pointer; }
.topbar h1:active { background: var(--card); }
.nav-btn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); backdrop-filter: blur(var(--blur)); box-shadow: var(--shadow);
}
.topbar .nav-actions { display: flex; gap: 8px; align-items: center; }

.view-body { flex: 1; overflow: hidden; position: relative; padding: 0 10px 8px; }
.view-pane { position: absolute; inset: 0; padding: 0 6px 8px; overflow: auto; }

/* ---------- Month grid (primary screen) ---------- */
.month-grid-header { display: grid; grid-template-columns: repeat(7, 1fr); padding: 0 6px 4px; }
.wd { text-align: center; font-size: 0.72rem; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }

.month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(6, 1fr);
  gap: 5px; height: calc(100% - 22px); padding: 0 4px;
}
.day-cell {
  position: relative; border-radius: var(--radius-md); background: var(--card);
  backdrop-filter: blur(var(--blur)); display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; padding: 6px 2px 4px; overflow: hidden; transition: transform .15s ease;
  border: 1px solid transparent;
}
.day-cell:active { transform: scale(0.94); }
.day-cell.muted { opacity: 0.35; }
.day-cell.weekend .daynum { color: var(--ember); }
.day-cell.holiday { border-color: color-mix(in srgb, var(--ember) 45%, transparent); }
.day-cell.holiday-regional { border-color: color-mix(in srgb, var(--aurora) 45%, transparent); }

.daynum { font-size: 1.05rem; font-weight: 600; line-height: 1; }

.day-cell.today {
  background: var(--aurora-soft);
}
.day-cell.today .daynum {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; position: relative; z-index: 1;
}
.day-cell.today .daynum::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%; z-index: -1;
  background: conic-gradient(from 0deg, var(--aurora), var(--ember), var(--aurora));
  animation: spin 6s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .day-cell.today .daynum::before { animation: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

.badges { display: flex; gap: 2px; min-height: 12px; margin-top: 1px; }
.badge { font-style: normal; font-size: 0.55rem; line-height: 1; opacity: .85; }

.holiday-label {
  display: block; width: 100%; max-width: 100%; text-align: center; padding: 0 2px;
  font-size: 0.42rem; font-weight: 700; line-height: 1.15; color: var(--ember);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.day-cell.holiday-regional .holiday-label { color: var(--aurora); }

.bars { display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 0 5px 3px; margin-top: auto; }
.bar { display: block; width: 100%; height: 3px; border-radius: 2px; }
.bar-more { align-self: flex-end; font-size: 0.5rem; color: var(--text-soft); font-weight: 700; line-height: 1; }

/* ---------- Week view ---------- */
.week-view { display: flex; flex-direction: column; height: 100%; }
.week-headers, .week-allday { display: grid; grid-template-columns: 44px repeat(7, 1fr); }
.week-day-header { text-align: center; padding: 4px 0; font-size: 0.72rem; color: var(--text-soft); border-bottom: 2px solid transparent; }
.week-day-header.today { color: var(--aurora); font-weight: 700; }
.week-day-header.holiday { border-bottom-color: var(--ember); }
.week-day-header.holiday.regional { border-bottom-color: var(--aurora); }
.gutter { font-size: 0.55rem; color: var(--text-soft); display: flex; align-items: center; justify-content: center; }
.week-allday-cell { border-left: 1px solid var(--line); min-height: 20px; padding: 2px; }
.allday-chip { font-size: 0.62rem; border-radius: 6px; padding: 2px 5px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week-scroll { flex: 1; overflow-y: auto; display: flex; position: relative; }
.hours-gutter { width: 44px; flex-shrink: 0; }
.hour-row { height: var(--hour-height); border-top: 1px solid var(--line); position: relative; }
.hour-label { position: absolute; top: -6px; right: 4px; font-size: 0.6rem; color: var(--text-soft); }
.week-columns { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); position: relative; }
.week-day-col { border-left: 1px solid var(--line); position: relative; background-image: repeating-linear-gradient(to bottom, transparent, transparent calc(var(--hour-height) - 1px), var(--line) var(--hour-height)); }
.event-block { position: absolute; left: 2px; right: 2px; border-radius: 8px; padding: 3px 5px; overflow: hidden; font-size: 0.62rem; }
.eb-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eb-time { display: block; font-size: 0.55rem; opacity: .75; }

/* ---------- Day view ---------- */
.day-view { display: flex; flex-direction: column; height: 100%; }
.day-holiday-chip {
  margin: 4px 8px 0; padding: 6px 12px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  color: var(--ember); background: color-mix(in srgb, var(--ember) 12%, transparent); align-self: flex-start;
}
.day-holiday-chip.regional { color: var(--aurora); background: var(--aurora-soft); }
.day-allday { padding: 4px 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.day-scroll { flex: 1; overflow-y: auto; display: flex; position: relative; }
.day-column { flex: 1; position: relative; margin-left: 4px; background-image: repeating-linear-gradient(to bottom, transparent, transparent calc(var(--hour-height) - 1px), var(--line) var(--hour-height)); }
.day-block { position: absolute; left: 6px; right: 6px; border-radius: 10px; padding: 4px 8px; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--ember); }
.now-line::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--ember); }

/* ---------- Bottom nav ---------- */
.tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: var(--card); backdrop-filter: blur(var(--blur)); border-top: 1px solid var(--line);
}
.tab-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.62rem; color: var(--text-soft); padding: 4px; border-radius: 12px; }
.tab-btn.active { color: var(--aurora); }
.tab-btn .icon { font-size: 1.2rem; line-height: 1; height: 22px; display: flex; align-items: center; justify-content: center; }
.tab-btn.add .icon { color: var(--aurora); font-weight: 700; font-size: 1.35rem; }

/* ---------- Modal / sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); backdrop-filter: blur(2px); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: 26px 26px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  transform: translateY(100%); transition: transform .28s cubic-bezier(.32,.72,0,1); z-index: 41;
  max-height: 88dvh; overflow-y: auto; padding: 10px 18px max(18px, env(safe-area-inset-bottom));
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-size: 1rem; font-weight: 700; margin: 4px 0 12px; letter-spacing: -0.01em; }
.sheet, .sheet * { font-size: 0.86rem; }

.field { margin-bottom: 10px; min-width: 0; }
.field label { display: block; font-size: 0.7rem; color: var(--text-soft); margin-bottom: 4px; font-weight: 600; }
.field input[type=text], .field input[type=datetime-local], .field input[type=number], .field textarea, .field select {
  width: 100%; max-width: 100%; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 0.82rem; box-sizing: border-box;
}
.field input[type=datetime-local] { min-width: 0; }
.field textarea { resize: vertical; min-height: 46px; font-size: 0.82rem; }
.row { display: flex; gap: 8px; min-width: 0; }
.row > .field { flex: 1 1 0; min-width: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { padding: 5px 10px; border-radius: 999px; font-size: 0.72rem; border: 1px solid var(--line); background: var(--card); white-space: nowrap; }
.chip.selected { color: #fff; border-color: transparent; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 0.82rem; }
.actions-row { display: flex; gap: 8px; margin-top: 14px; }
.btn { flex: 1; padding: 10px; border-radius: var(--radius-md); text-align: center; font-weight: 600; font-size: 0.82rem; }
.btn.primary { background: var(--aurora); color: #fff; }
.btn.ghost { background: var(--card); border: 1px solid var(--line); }
.btn.danger { background: rgba(255,107,93,.15); color: var(--ember); }
.icon-btn-row { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 6px; flex-wrap: wrap; }
.icon-btn-row .btn { font-size: 0.72rem; padding: 6px 10px; }

.ym-header { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 4px 0 18px; }
.ym-year { font-size: 1.1rem; font-weight: 700; font-family: ui-rounded, -apple-system, sans-serif; font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
.ym-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding-bottom: 6px; }
.ym-month {
  aspect-ratio: 1; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card);
  display: flex; align-items: center; justify-content: center; font-size: 0.78rem; text-transform: capitalize;
}
.ym-month.current { border-color: var(--aurora); color: var(--aurora); font-weight: 700; }
.ym-month.selected { background: var(--aurora); border-color: var(--aurora); color: #fff; font-weight: 700; }

/* ---------- Today screen / search / settings / goals / stats ---------- */
.screen-title { font-size: 1.4rem; font-weight: 700; margin: 6px 6px 10px; letter-spacing: -0.02em; }
.card-list { display: flex; flex-direction: column; gap: 8px; padding: 0 6px 16px; }
.list-card { background: var(--card); backdrop-filter: blur(var(--blur)); border-radius: var(--radius-md); padding: 12px 14px; box-shadow: var(--shadow); }
.list-card h3 { margin: 0 0 8px; font-size: 0.85rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.event-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.event-row:first-of-type { border-top: none; }
.event-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.event-row .et { font-size: 0.72rem; color: var(--text-soft); width: 68px; flex-shrink: 0; line-height: 1.25; }
.event-row .et .et-date { display: block; font-weight: 600; }
.event-row .etitle { flex: 1; font-size: 0.9rem; }
.empty-hint { color: var(--text-soft); font-size: 0.85rem; padding: 10px 4px; }

.search-input-wrap { padding: 4px 6px 10px; }
.search-input-wrap input { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }

.settings-group { margin: 0 6px 18px; }
.settings-group h3 { font-size: 0.75rem; text-transform: uppercase; color: var(--text-soft); letter-spacing: .05em; margin: 0 4px 6px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 0.82rem; }
.settings-row select, .settings-row input[type=range] { max-width: 50%; font-size: 0.78rem; }
.settings-row select {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  padding: 6px 8px; border-radius: var(--radius-sm);
}
.settings-row input[type=color] { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); padding: 0; background: none; flex-shrink: 0; }
.settings-row.file-row { flex-direction: column; align-items: stretch; gap: 6px; }
.settings-row.file-row .file-row-label { font-size: 0.82rem; }
.file-input-wrap { position: relative; display: flex; align-items: center; }
.file-input-wrap input[type=file] {
  font-size: 0.72rem; width: 100%; color: var(--text-soft);
}
.file-input-wrap input[type=file]::file-selector-button {
  font-size: 0.72rem; padding: 6px 10px; border-radius: 999px; border: none;
  background: var(--aurora); color: #fff; font-weight: 600; margin-right: 8px;
}
.color-dot-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; }
.color-dot.selected { border-color: var(--text); }

.goal-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.goal-row:first-of-type { border-top: none; }
.goal-check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--aurora); display: grid; place-items: center; flex-shrink: 0; }
.goal-check.done { background: var(--aurora); color: #fff; }
.goal-streak { font-size: 0.7rem; color: var(--text-soft); }

.stat-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.stat-bar-label { width: 80px; font-size: 0.75rem; flex-shrink: 0; }
.stat-bar-track { flex: 1; height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 6px; }
.stat-number { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }

.trash-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.trash-row:first-of-type { border-top: none; }

/* Focus visibility for accessibility */
:focus-visible { outline: 2px solid var(--aurora); outline-offset: 2px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 0.85rem; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 60; display: flex; gap: 10px; align-items: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast button { color: var(--aurora); font-weight: 700; }

::-webkit-scrollbar { width: 0; height: 0; }
