/* ============================================================
   Mi Calendario — estilos
   Estilo "rejilla" claro (inspirado en Calendar Shifter)
   Cromo monocromo · bloques de color pastel · sin sombras pesadas
   ============================================================ */

:root {
  --bg: #f3f3f5;
  --surface: #ffffff;
  --surface-2: #f4f4f6;
  --text: #1c1c1e;
  --text-soft: #8a8a8f;
  --line: #e6e6ea;
  --line-strong: #d6d6dc;

  --primary: #1c1c1e;       /* cromo monocromo */
  --primary-press: #3a3a3c;
  --on-primary: #ffffff;
  --today: #ff3b30;         /* hoy en rojo */

  --radius: 16px;
  --radius-sm: 11px;
  --bar-h: 17px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html[data-theme="dark"] {
  --bg: #0c0d10;
  --surface: #16171b;
  --surface-2: #1e1f24;
  --text: #f1f1f3;
  --text-soft: #8a8a90;
  --line: #2a2b31;
  --line-strong: #34353c;

  --primary: #f1f1f3;
  --primary-press: #d2d2d6;
  --on-primary: #16171b;
  --today: #ff453a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior-y: none;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 16px; line-height: 1.4;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }
.muted { color: var(--text-soft); font-weight: 400; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px;
  background: var(--bg);
}
.splash-logo { line-height: 0; animation: pop .5s ease; }
.splash-logo img { border-radius: 24%; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

/* ============================================================
   Autenticación
   ============================================================ */
.auth {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-top: calc(24px + var(--safe-top));
  background: var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 36px 26px; text-align: center;
  animation: rise .4s ease;
}
.auth-logo { margin-bottom: 14px; line-height: 0; }
.auth-logo img { border-radius: 24%; }
.auth-card h1 { font-size: 23px; margin: 4px 0 2px; letter-spacing: -.3px; }
.auth-card form { margin-top: 22px; text-align: left; }

.field { margin-bottom: 16px; }
.field label, .field-label {
  display: block; font-size: 13px; font-weight: 600;
  margin-bottom: 7px; color: var(--text-soft);
}
input[type="text"], input[type="password"], input[type="date"],
input[type="time"], textarea {
  width: 100%; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); padding: 13px 14px;
  font-size: 16px; font-family: inherit; outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; }

.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 46px; }
.pass-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 8px;
  color: var(--text-soft);
}
.pass-toggle svg { width: 20px; height: 20px; }
.auth-error {
  color: #d70015; font-size: 13.5px; margin: 4px 0 14px;
  background: #ff3b3015; padding: 9px 12px; border-radius: 10px;
}

/* ============================================================
   Botones
   ============================================================ */
.btn {
  border: none; border-radius: var(--radius-sm);
  padding: 13px 18px; font-size: 15.5px; font-weight: 600;
  font-family: inherit; cursor: pointer;
  transition: transform .08s, background .15s, opacity .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-grow { flex: 1; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:active { background: var(--primary-press); }
.btn-ghost {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); margin-bottom: 10px;
}
.btn-danger-ghost {
  background: transparent; color: #d70015;
  border: 1px solid #ff3b3050;
}
.btn-ico { display: inline-flex; line-height: 0; }
.btn-ico svg { width: 18px; height: 18px; }

/* ============================================================
   Estructura app
   ============================================================ */
.app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top);
}
.topbar-row {
  display: flex; align-items: center; gap: 3px;
  padding: 9px 8px;
}
.month-title {
  font-size: 20px; font-weight: 700; background: none; border: none;
  color: var(--text); cursor: pointer; text-transform: capitalize;
  padding: 4px 4px; letter-spacing: -.4px;
  flex: 0 1 auto; min-width: 0; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.topbar-spacer { flex: 1; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: none; background: transparent; color: var(--text);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .08s;
}
.icon-btn:active { background: var(--surface-2); transform: scale(.92); }
.icon-btn svg { width: 22px; height: 22px; }
.today-btn {
  border: 1px solid var(--line-strong); background: transparent;
  color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 6px 11px; border-radius: 999px; font-family: inherit;
  transition: transform .08s; flex: 0 0 auto;
}
.today-btn:active { transform: scale(.94); }
.add-btn {
  width: 36px; height: 36px; border-radius: 11px;
  background: var(--primary); color: var(--on-primary); border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .1s, background .15s; margin-left: 2px;
}
.add-btn:active { transform: scale(.9); background: var(--primary-press); }
.add-btn svg { width: 21px; height: 21px; }
.paint-btn {
  width: 36px; height: 36px; border-radius: 11px;
  background: var(--surface-2); color: var(--text); border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .1s, background .15s, color .15s;
}
.paint-btn svg { width: 20px; height: 20px; }
.paint-btn:active { transform: scale(.9); }
.paint-btn.active { background: var(--primary); color: var(--on-primary); }

/* ---------- Vistas ---------- */
.view { display: none; padding: 12px 12px 0; animation: fade .22s ease; }
.view.active {
  display: block; flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 18px;
}
/* La vista de calendario NO hace scroll: la rejilla se estira para llenar */
#view-calendar.active {
  display: flex; flex-direction: column; overflow: hidden; padding-bottom: 10px;
}
@keyframes fade { from { opacity: 0; transform: translateY(5px); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* ============================================================
   Calendario — rejilla con líneas finas (sin huecos)
   ============================================================ */
.weekdays {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 0 1px; margin-bottom: 6px;
}
.weekdays span {
  text-align: center; font-size: 11px; font-weight: 600;
  color: var(--text-soft); padding: 2px 0;
  text-transform: uppercase; letter-spacing: .5px;
}

.calendar {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden;
}
.week {
  position: relative;
  flex: 1 1 0; min-height: 56px;
  display: grid; grid-template-columns: repeat(7, 1fr);
}
.day {
  position: relative; min-height: 0;
  padding: 4px 5px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
  transition: background .12s;
}
.week .day:nth-child(7) { border-right: none; }
.calendar .week:last-child .day { border-bottom: none; }
.day.other { background: var(--surface-2); }
.day.other .daynum { color: var(--text-soft); opacity: .65; }
.daynum {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 23px; height: 23px; padding: 0 5px;
  font-size: 13px; font-weight: 600; line-height: 1; color: var(--text);
}
.day.today .daynum {
  background: var(--today); color: #fff; border-radius: 999px; font-weight: 700;
}
.day.sel { box-shadow: inset 0 0 0 2px var(--primary); }
.day.paint-hover { background: color-mix(in srgb, var(--primary) 9%, var(--surface)); }

/* Modo pintar: los días NO hacen scroll al arrastrar, y las barras dejan
   pasar el puntero (si no, al arrastrar sobre un evento se pierde el día). */
body.painting .day { touch-action: none; }
body.painting .bar { pointer-events: none; }

/* Barras de eventos (bloques de color continuos) */
.bars {
  position: absolute; left: 0; right: 0; top: 26px; bottom: 3px;
  pointer-events: none;
}
.bar {
  position: absolute; height: var(--bar-h);
  border-radius: 6px; font-size: 11.5px; font-weight: 600;
  line-height: var(--bar-h); padding: 0 7px; letter-spacing: -.1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: auto;
}
.bar.cont-left { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.cont-right { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.more-pill {
  position: absolute; right: 4px; bottom: 2px;
  font-size: 10px; font-weight: 700; color: var(--text-soft);
}

/* Modal "Pintar" */
.paint-list { display: flex; flex-direction: column; gap: 8px; }
.paint-opt {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 2px solid transparent;
  font-size: 15.5px; font-weight: 600; color: var(--text); cursor: pointer;
  font-family: inherit; text-align: left;
  transition: transform .08s, border-color .12s;
}
.paint-opt:active { transform: scale(.99); }
.paint-opt .swatch { width: 17px; height: 17px; border-radius: 5px; flex: 0 0 auto; }
.paint-opt .name { flex: 1; }
.paint-opt.on { border-color: var(--primary); background: var(--surface); }
.paint-opt .chk { display: inline-flex; color: var(--primary); }
.paint-opt .chk svg { width: 19px; height: 19px; }

.paint-banner {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(74px + var(--safe-bottom));
  background: var(--primary); color: var(--on-primary);
  border-radius: 13px; padding: 11px 14px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 600; z-index: 30;
  animation: rise .22s ease;
}
.paint-banner .close { margin-left: auto; cursor: pointer; opacity: .85; font-size: 18px; line-height: 1; }
.paint-banner .swatch { width: 13px; height: 13px; border-radius: 4px; }

/* ============================================================
   Agenda
   ============================================================ */
.agenda-head, .summary-head, .settings-head { padding: 4px 2px 12px; }
.agenda-head h2, .summary-head h2, .settings-head h2 { margin: 0; font-size: 25px; letter-spacing: -.4px; }
.agenda-list { display: flex; flex-direction: column; gap: 8px; }
.agenda-day-label {
  font-size: 12px; font-weight: 700; color: var(--text-soft);
  margin: 14px 2px 2px; text-transform: uppercase; letter-spacing: .4px;
}
.agenda-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; cursor: pointer;
  transition: transform .08s;
}
.agenda-item:active { transform: scale(.99); }
.agenda-stripe { width: 6px; align-self: stretch; border-radius: 6px; }
.agenda-main { flex: 1; min-width: 0; }
.agenda-title { font-weight: 600; font-size: 15.5px; }
.agenda-meta { font-size: 13px; color: var(--text-soft); }
.agenda-when {
  font-size: 12.5px; font-weight: 700; color: var(--text-soft);
  text-align: right; white-space: nowrap;
}
.empty { text-align: center; color: var(--text-soft); padding: 54px 20px; font-size: 15px; }
.empty .big { display: inline-flex; margin-bottom: 12px; color: var(--text-soft); opacity: .5; }
.empty .big svg { width: 46px; height: 46px; stroke-width: 1.5; }

/* ============================================================
   Resumen
   ============================================================ */
.summary-head { display: flex; align-items: center; justify-content: space-between; }
.year-switch { display: flex; align-items: center; gap: 4px; font-weight: 700; }
.summary-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px; position: relative; overflow: hidden;
}
.sum-card.wide { grid-column: 1 / -1; }
.sum-ico { color: var(--text-soft); line-height: 0; }
.sum-ico svg { width: 21px; height: 21px; }
.sum-dot { width: 15px; height: 15px; border-radius: 5px; }
.sum-num { font-size: 29px; font-weight: 800; margin-top: 8px; line-height: 1; letter-spacing: -.5px; }
.sum-label { font-size: 12.5px; color: var(--text-soft); margin-top: 4px; }
.sum-card .accent-strip { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.sum-bar-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.sum-bar-row .lbl { width: 100px; font-size: 13px; font-weight: 600; flex: 0 0 auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-bar-dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; vertical-align: middle; }
.sum-bar-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.sum-bar-fill { height: 100%; border-radius: 8px; }
.sum-bar-val { font-size: 13px; font-weight: 700; width: 32px; text-align: right; }

/* ============================================================
   Ajustes
   ============================================================ */
.settings-group {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.settings-group-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-soft); margin-bottom: 12px;
}
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; gap: 12px; }
.category-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.cat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer;
}
.cat-row .swatch { width: 16px; height: 16px; border-radius: 5px; flex: 0 0 auto; }
.cat-row .swatch.lg { width: 20px; height: 20px; border-radius: 6px; }
.cat-row .name { flex: 1; font-weight: 600; }
.cat-row .count { font-size: 13px; color: var(--text-soft); }
.cat-row .chev { color: var(--text-soft); display: inline-flex; }
.cat-row .chev svg { width: 18px; height: 18px; }
.app-version { text-align: center; font-size: 12.5px; padding: 6px; }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: none; color: var(--text-soft);
  font-size: 13.5px; font-weight: 600; padding: 7px 13px;
  border-radius: 8px; cursor: pointer; font-family: inherit;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* Switch */
.switch { position: relative; display: inline-block; width: 50px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; cursor: pointer; background: var(--line-strong); border-radius: 30px; transition: .2s; }
.slider::before {
  content: ""; position: absolute; height: 24px; width: 24px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%;
  transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ============================================================
   Leyenda de categorías
   ============================================================ */
.legend {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: 6px 13px; padding: 8px 14px;
  max-height: 86px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--text-soft);
}
.legend-item .dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }

/* ============================================================
   Navegación inferior
   ============================================================ */
.bottomnav {
  flex: 0 0 auto; z-index: 24;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.nav-btn {
  border: none; background: none; cursor: pointer;
  padding: 9px 0 8px; display: flex; flex-direction: column;
  align-items: center; gap: 3px; color: var(--text-soft);
  font-size: 11px; font-weight: 600; font-family: inherit;
  transition: color .15s;
}
.nav-btn .nav-ico { display: inline-flex; transition: transform .15s; }
.nav-btn .nav-ico svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--primary); }
.nav-btn.active .nav-ico { transform: translateY(-1px); }

/* ============================================================
   Hojas inferiores (bottom sheets)
   ============================================================ */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.32);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadebg .2s ease;
}
@keyframes fadebg { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 540px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,.16);
  animation: slideup .28s cubic-bezier(.16,1,.3,1);
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet-handle { width: 38px; height: 4px; border-radius: 5px; background: var(--line-strong); margin: 6px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; font-size: 18px; letter-spacing: -.3px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text-soft); }

.cat-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.cat-opt {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: 999px;
  background: var(--surface-2); border: 2px solid transparent;
  font-size: 13.5px; font-weight: 600; color: var(--text); cursor: pointer;
}
.cat-opt .swatch { width: 11px; height: 11px; border-radius: 3px; }
.cat-opt.on { border-color: var(--primary); background: var(--surface); }

.day-events { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.day-ev {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 11px 12px; cursor: pointer;
}
.day-ev .stripe { width: 6px; align-self: stretch; border-radius: 6px; }
.day-ev .info { flex: 1; min-width: 0; }
.day-ev .t { font-weight: 600; }
.day-ev .m { font-size: 12.5px; color: var(--text-soft); }

.color-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; margin-bottom: 6px; }
.color-dot { aspect-ratio: 1; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: transform .08s; }
.color-dot:active { transform: scale(.9); }
.color-dot.on { border-color: var(--text); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--safe-bottom)); z-index: 60;
  background: var(--primary); color: var(--on-primary);
  padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); animation: rise .25s ease;
  max-width: 90vw; text-align: center;
}

@media (min-width: 560px) {
  .view, .topbar-row { max-width: 620px; margin-left: auto; margin-right: auto; }
}
