/* ===========================================================================
   Mi Calendario — estilos
   Paleta suave, diseño moderno y responsive.
   =========================================================================== */

/* Paleta pautada: AZUL (acentos/acciones), BLANCO (fondos), GRIS (texto/bordes).
   Los tipos de evento se distinguen con tonos de azul y gris (no colores ajenos).
   El tema oscuro reusa los mismos roles redefiniendo los tokens. */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-soft: #475569;
  --text-mute: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  /* "Peligro" sin salir de la paleta: gris fuerte (la confirmación protege). */
  --danger: #334155;
  --danger-soft: #e2e8f0;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.16);
  --radius: 14px;
  --radius-sm: 9px;

  /* Tipos de evento: variaciones de azul y gris */
  --c-clase: #2563eb;   --c-clase-soft: #dbeafe;
  --c-cita: #0ea5e9;    --c-cita-soft: #e0f2fe;
  --c-reunion: #1e40af; --c-reunion-soft: #dbe4fb;
  --c-tarea: #64748b;   --c-tarea-soft: #e2e8f0;
  --c-otro: #94a3b8;    --c-otro-soft: #f1f5f9;
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #16203a;
  --border: #243150;
  --text: #e2e8f0;
  --text-soft: #94a3b8;
  --text-mute: #64748b;
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --primary-soft: #16243f;
  --danger: #cbd5e1;
  --danger-soft: #243150;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);

  --c-clase: #60a5fa;   --c-clase-soft: #1e3a5f;
  --c-cita: #38bdf8;    --c-cita-soft: #0c4a6e;
  --c-reunion: #93c5fd; --c-reunion-soft: #1e2f57;
  --c-tarea: #94a3b8;   --c-tarea-soft: #2a3550;
  --c-otro: #64748b;    --c-otro-soft: #1f2940;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ----------------------------- Topbar ----------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon { font-size: 30px; }
.brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: 12.5px; color: var(--text-mute); }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ----------------------------- Botones ---------------------------------- */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--surface-2); color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover { background: #eef1f6; color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--border); color: var(--text); }
.btn-icon {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-soft);
  width: 38px; height: 38px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: #eef1f6; color: var(--text); }

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
}
.badge-muted { background: var(--surface-2); color: var(--text-mute); border: 1px solid var(--border); }
.badge-ok { background: var(--primary-soft); color: var(--primary-dark); }
.badge-off { background: var(--danger-soft); color: var(--text-soft); }

/* ----------------------------- Layout ----------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  padding: 20px 28px 40px;
  max-width: 1400px;
  margin: 0 auto;
}
.calendar-panel, .sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.calendar-panel { padding: 18px; }
.sidebar { padding: 18px; align-self: start; position: sticky; top: 90px; }

/* --------------------------- Toolbar calendario ------------------------- */
.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.nav-group { display: flex; align-items: center; gap: 6px; }
.period-label {
  font-size: 19px;
  font-weight: 700;
  text-transform: capitalize;
  letter-spacing: -0.01em;
  flex: 1;
  text-align: center;
  min-width: 180px;
}
.view-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.view-btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.view-btn.is-active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ----------------------------- Vista mes -------------------------------- */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekday-head {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 0 8px;
}
.day-cell {
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  min-height: 96px;
  padding: 6px;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.day-cell:hover { border-color: var(--primary); background: var(--primary-soft); }
.day-cell.is-other-month { opacity: 0.45; }
.day-cell.is-today { background: var(--primary-soft); border-color: var(--primary); }
.day-number { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.is-today .day-number {
  background: var(--primary); color: #fff;
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.day-events { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.event-chip {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 3px solid;
  display: flex;
  align-items: center;
  gap: 4px;
}
.event-chip .chip-time { font-weight: 500; opacity: 0.8; font-size: 10.5px; }
.event-chip.done { text-decoration: line-through; opacity: 0.55; }
.more-chip { font-size: 11px; color: var(--text-mute); font-weight: 600; padding: 1px 6px; }

/* Colores por tipo aplicados a chips */
.event-chip.type-clase   { background: var(--c-clase-soft);   color: var(--text); border-color: var(--c-clase); }
.event-chip.type-cita    { background: var(--c-cita-soft);    color: var(--text); border-color: var(--c-cita); }
.event-chip.type-reunion { background: var(--c-reunion-soft); color: var(--text); border-color: var(--c-reunion); }
.event-chip.type-tarea   { background: var(--c-tarea-soft);   color: var(--text); border-color: var(--c-tarea); }
.event-chip.type-otro    { background: var(--c-otro-soft);    color: var(--text); border-color: var(--c-otro); }

/* ----------------------- Vistas semana / día --------------------------- */
.timed-view { display: flex; flex-direction: column; overflow-x: auto; }
.week-head {
  display: grid;
  grid-template-columns: 56px repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.day-head {
  display: grid;
  grid-template-columns: 56px 1fr;
}
.week-head .col-head, .day-head .col-head {
  text-align: center;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
}
.col-head .dh-day { font-size: 11px; color: var(--text-mute); text-transform: uppercase; }
.col-head .dh-num {
  font-size: 17px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; margin-top: 2px;
}
.col-head.is-today .dh-num { background: var(--primary); color: #fff; }
.col-head.corner { background: transparent; }

.time-grid {
  display: grid;
  grid-auto-rows: 48px;
  position: relative;
  max-height: 62vh;
  overflow-y: auto;
}
.week-body { grid-template-columns: 56px repeat(7, 1fr); }
.day-body { grid-template-columns: 56px 1fr; }
.hour-label {
  font-size: 11px;
  color: var(--text-mute);
  text-align: right;
  padding: 2px 8px 0 0;
  border-top: 1px solid var(--border);
  transform: translateY(-7px);
}
.grid-cell {
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.grid-cell:hover { background: var(--primary-soft); }
.timed-event {
  margin: 2px 4px;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  border-left: 3px solid;
  overflow: hidden;
  cursor: pointer;
  min-height: 22px;
}
.timed-event .te-time { font-weight: 500; font-size: 11px; opacity: 0.85; display: block; }
.timed-event.done { text-decoration: line-through; opacity: 0.55; }
.timed-event.type-clase   { background: var(--c-clase-soft);   color: var(--text); border-color: var(--c-clase); }
.timed-event.type-cita    { background: var(--c-cita-soft);    color: var(--text); border-color: var(--c-cita); }
.timed-event.type-reunion { background: var(--c-reunion-soft); color: var(--text); border-color: var(--c-reunion); }
.timed-event.type-tarea   { background: var(--c-tarea-soft);   color: var(--text); border-color: var(--c-tarea); }
.timed-event.type-otro    { background: var(--c-otro-soft);    color: var(--text); border-color: var(--c-otro); }

/* ----------------------------- Leyenda ---------------------------------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-soft); }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.type-clase { background: var(--c-clase); }
.dot.type-cita { background: var(--c-cita); }
.dot.type-reunion { background: var(--c-reunion); }
.dot.type-tarea { background: var(--c-tarea); }
.dot.type-otro { background: var(--c-otro); }

/* --------------------------- Próximos eventos --------------------------- */
.sidebar-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.upcoming-list { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow-y: auto; }
.upcoming-card {
  border: 1px solid var(--border);
  border-left: 4px solid;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  background: var(--surface-2);
  cursor: pointer;
  transition: all 0.12s;
}
.upcoming-card:hover { box-shadow: var(--shadow); transform: translateX(-2px); }
.upcoming-card.done { opacity: 0.55; }
.upcoming-card.type-clase { border-left-color: var(--c-clase); }
.upcoming-card.type-cita { border-left-color: var(--c-cita); }
.upcoming-card.type-reunion { border-left-color: var(--c-reunion); }
.upcoming-card.type-tarea { border-left-color: var(--c-tarea); }
.upcoming-card.type-otro { border-left-color: var(--c-otro); }
.uc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.uc-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uc-title.done { text-decoration: line-through; }
.uc-when { font-size: 12px; color: var(--text-mute); margin-top: 3px; }
.uc-meta { display: flex; align-items: center; gap: 6px; margin-top: 7px; }
.uc-tag {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 7px; border-radius: 5px;
}
.uc-tag.type-clase { background: var(--c-clase-soft); color: var(--text); }
.uc-tag.type-cita { background: var(--c-cita-soft); color: var(--text); }
.uc-tag.type-reunion { background: var(--c-reunion-soft); color: var(--text); }
.uc-tag.type-tarea { background: var(--c-tarea-soft); color: var(--text); }
.uc-tag.type-otro { background: var(--c-otro-soft); color: var(--text); }
.uc-bell { font-size: 11px; color: var(--text-mute); display: inline-flex; align-items: center; gap: 3px; }
.uc-bell .icon { width: 13px; height: 13px; }
.complete-toggle {
  margin-left: auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; color: transparent;
  transition: all 0.12s;
  flex-shrink: 0;
}
.complete-toggle:hover { border-color: var(--primary); }
.complete-toggle.checked { background: var(--primary); border-color: var(--primary); color: #fff; }
.empty-state { color: var(--text-mute); font-size: 13px; text-align: center; padding: 24px 8px; }

/* ----------------------------- Modal ------------------------------------ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(31, 41, 55, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px;
  max-height: 92vh; overflow-y: auto;
  animation: pop 0.18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 17px; font-weight: 700; }
.event-form { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  transition: border 0.12s, box-shadow 0.12s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; }
.form-error {
  background: var(--danger-soft); color: var(--text);
  border-left: 3px solid var(--primary);
  font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm);
}
.form-error ul { margin: 0; padding-left: 18px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.modal-actions .spacer { flex: 1; }

/* ----------------------------- Toast ------------------------------------ */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  animation: slideUp 0.25s ease;
}
.toast.toast-error { background: #334155; }
.toast.toast-ok { background: var(--primary); }
@keyframes slideUp { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

.hidden { display: none !important; }

/* ------------------------ Sesión (chip de usuario) ---------------------- */
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 3px 3px 3px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  max-width: 260px;
}
.user-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.user-name {
  font-size: 13px; font-weight: 600; color: var(--text-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip .btn-icon { width: 32px; height: 32px; border-radius: 50%; }
.user-chip .btn-icon .icon { width: 16px; height: 16px; }

/* ------------------------ Puerta de acceso (Google) --------------------- */
.auth-gate {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 55; padding: 16px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 420px;
  padding: 36px 28px 28px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  animation: pop 0.18s ease;
}
.auth-icon {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--primary-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.auth-card h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; }
.auth-text { font-size: 14px; color: var(--text-soft); max-width: 340px; }
.google-btn { min-height: 44px; margin-top: 8px; display: flex; justify-content: center; width: 100%; }
.auth-note { font-size: 12px; color: var(--text-mute); margin-top: 6px; }
.auth-card .form-error { width: 100%; text-align: left; }
body.is-locked { overflow: hidden; }

/* --------------------- Filtro de tipos (leyenda) ------------------------ */
.legend-item { cursor: pointer; user-select: none; transition: opacity 0.12s; }
.legend-item.is-off { opacity: 0.4; text-decoration: line-through; }

/* ----------------------------- Buscador --------------------------------- */
.search-box {
  width: 100%;
  font: inherit; font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 12px;
  background: var(--surface);
  color: var(--text);
}
.search-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ------------------------- Skeleton de carga ---------------------------- */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
.skeleton-card { height: 74px; margin-bottom: 10px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ----------------------- Icono SVG en botones --------------------------- */
.icon { width: 18px; height: 18px; display: inline-block; vertical-align: -3px; }
.btn .icon { vertical-align: -4px; }
.btn-icon .icon { width: 20px; height: 20px; }
.brand-icon .icon { width: 28px; height: 28px; color: var(--primary); }
.theme-toggle .icon { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline-block; }

/* ----------------------------- Responsive ------------------------------- */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; order: -1; }
  .upcoming-list { max-height: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .brand h1 { font-size: 17px; }
  .subtitle { display: none; }
  .layout { padding: 14px 14px 32px; }
  .calendar-panel { padding: 12px; }
  .period-label { font-size: 16px; min-width: 0; order: -1; width: 100%; }
  .calendar-toolbar { justify-content: space-between; }
  .day-cell { min-height: 70px; padding: 4px; }
  .day-events .event-chip { font-size: 10px; padding: 2px 4px; }
  .event-chip .chip-time { display: none; }
  /* Semana: ancho mínimo usable + scroll horizontal dentro del panel
     (evita columnas diminutas y el desbordamiento del body). */
  .week-head, .week-body { grid-template-columns: 40px repeat(7, 1fr); min-width: 600px; }
  .col-head .dh-day { font-size: 9.5px; }
  .field-row { grid-template-columns: 1fr; }
  .subtitle { display: none; }
  .user-chip { max-width: 160px; }
  .auth-card { padding: 28px 18px 22px; }
}
