:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e6ef;
  --text: #1d2433;
  --muted: #6b7280;
  --accent: #4f7cff;
  --transition: 0.18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRow {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
}

.header-nav-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.app-logo {
  height: 85px;
  width: auto;
  max-width: 450px;
  object-fit: contain;
}

.week-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.refresh-nav-btn {
  padding: 6px 10px;
  font-size: 15px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), border-color var(--transition), transform var(--transition);
}
.refresh-nav-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: #f0f4ff;
}

button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), transform var(--transition),
              box-shadow var(--transition);
}
button:hover {
  background: #f0f2f8;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(79,124,255,0.08);
}
button:active { transform: translateY(0); }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { background: #3a68f0; box-shadow: 0 4px 12px rgba(79,124,255,0.3); }
button.danger { background: #fff0f0; color: #c0392b; border-color: #f3c6c6; }
button.danger:hover { background: #ffe0e0; }


main { padding: 24px; }

.grid {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  animation: fadeIn 0.35s ease both;
}

.grid-header, .grid-row {
  display: grid;
  grid-template-columns: 84px repeat(var(--n-rooms, 3), minmax(150px, 1fr));
}

.grid-row {
  animation: slideInRow 0.25s ease both;
}

.grid-header > div, .grid-row > div {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 8px;
  min-height: 36px;
}

.grid-header {
  background: #fafbfe;
  font-weight: 600;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 3;
}

.day-col {
  text-align: center;
}

.time-label {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 1;
}

.grid-header .time-label,
.grid-header > div:first-child {
  background: #fafbfe;
  z-index: 4;
}

.scroll-hint {
  display: none;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px;
}

.cell {
  position: relative;
  cursor: pointer;
  min-height: 48px;
  transition: background var(--transition);
}
.cell:hover { background: #f0f4ff; }

.event-block {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 6px;
  padding: 4px 6px;
  color: white;
  font-size: 12px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
  animation: popIn 0.2s ease both;
}
.event-block:hover {
  filter: brightness(1.08);
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.event-block .ev-time { opacity: .85; font-size: 11px; }


.modal {
  position: fixed;
  inset: 0;
  background: rgba(20,24,35,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.18s ease both;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--panel);
  padding: 24px;
  border-radius: 12px;
  width: 380px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  animation: popIn 0.22s ease both;
  box-shadow: 0 8px 32px rgba(20,24,35,0.18);
}

.modal-content h2 { margin-top: 0; }

form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-top: 12px;
}

form input, form select {
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.time-row { display: flex; gap: 12px; }
.time-row label { flex: 1; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.error { color: #c0392b; font-size: 13px; }
.hidden { display: none !important; }

.suggestions {
  position: relative;
  margin-top: -8px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: var(--panel);
  max-height: 140px;
  overflow-y: auto;
  box-shadow: 0 4px 10px rgba(0,0,0,0.06);
}
.suggestions .suggestion-item {
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}
.suggestions .suggestion-item:hover,
.suggestions .suggestion-item.active {
  background: #f0f2f8;
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.view-btn {
  border: none;
  border-radius: 0;
  background: var(--panel);
}
.view-btn.active {
  background: var(--accent);
  color: white;
}

form .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  margin-top: 16px;
}
form .checkbox-label input { width: auto; margin: 0; }

#recurringOptions {
  margin-top: 8px;
  padding: 10px 12px;
  background: #fafbfe;
  border: 1px solid var(--border);
  border-radius: 8px;
}
#recurringOptions label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  margin-top: 6px;
}
#recurringOptions label:first-child { margin-top: 0; }
#recurringOptions input[type="radio"] { width: auto; }
#recurringOptions input[type="date"] { margin-top: 8px; }

.recurring-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* --- Vista mensual --- */
.month-grid {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.month-header-row, .month-week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.month-header-row > div {
  padding: 8px;
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  background: #fafbfe;
  border-bottom: 1px solid var(--border);
}
.month-day-cell {
  min-height: 100px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 6px;
  cursor: pointer;
  vertical-align: top;
}
.month-day-cell:hover { background: #f6f8ff; }
.month-day-cell.other-month { background: #fbfbfd; color: var(--muted); }
.month-day-number {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}
.month-event-chip {
  font-size: 11px;
  color: white;
  border-radius: 4px;
  padding: 2px 5px;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
#roomsList { list-style: none; padding: 0; }
#roomsList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
#roomsList .swatch {
  width: 14px; height: 14px; border-radius: 4px; display: inline-block;
}
#roomForm { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
#roomForm input[type="text"] { flex: 1; }
#roomForm input[type="color"] { width: 44px; padding: 2px; }

.subjects-list { list-style: none; padding: 0; margin: 12px 0; max-height: 45vh; overflow-y: auto; }
.subjects-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.subjects-list input[type="color"] {
  width: 34px;
  height: 34px;
  padding: 1px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.day-agenda-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  max-height: 55vh;
  overflow-y: auto;
}
.day-agenda-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.day-agenda-item:hover { background: #f6f8ff; }
.day-agenda-item .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-top: 5px;
  flex-shrink: 0;
}
.day-agenda-item .agenda-info { flex: 1; min-width: 0; }
.day-agenda-item .agenda-title {
  font-weight: 600;
  font-size: 14px;
}
.day-agenda-item .agenda-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.day-agenda-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 4px;
}

/* --- Login --- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 340px;
  max-width: 90vw;
}
.login-box h1 {
  font-size: 20px;
  margin: 0 0 2px;
}
.login-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}
.login-error {
  background: #fff0f0;
  border: 1px solid #f3c6c6;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.login-submit {
  width: 100%;
  margin-top: 20px;
}

/* --- Barra de usuario --- */
.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.role-badge.editor { background: #e6f4ea; color: #1e7e34; }
.role-badge.viewer { background: #eef1f8; color: #4a5570; }
.user-bar a { color: var(--accent); text-decoration: none; }
.user-bar a:hover { text-decoration: underline; }

/* --- Menú Hamburguesa Desplegable --- */
.menu-dropdown-container {
  position: relative;
  display: inline-block;
}

.menu-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  background: var(--panel);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.menu-dropdown-btn:hover {
  background: #f0f2f8;
  border-color: #cbd5e1;
}

.hamburger-icon {
  font-size: 16px;
  line-height: 1;
}

.menu-dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  padding: 8px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-dropdown-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 6px 10px 4px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease;
}

.menu-item:hover {
  background: #f0f3fa;
  color: var(--accent);
}

.item-icon {
  font-size: 15px;
}

.menu-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}

.menu-dropdown-user {
  padding: 6px 10px;
}

.user-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}

.user-info-row .username {
  font-weight: 600;
  font-size: 13px;
}

.logout-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: #e03131;
  text-decoration: none;
  font-weight: 500;
  padding: 4px 0;
}

.logout-link:hover {
  text-decoration: underline;
}

/* --- Responsive: celulares y pantallas angostas --- */
@media (max-width: 640px) {
  header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    gap: 8px 10px;
  }
  .header-brand {
    order: 1;
    margin-right: 0;
  }
  .app-logo {
    height: 44px;
    max-width: 170px;
  }
  .header-actions {
    order: 2;
    margin-left: auto;
    gap: 6px;
    display: flex;
    align-items: center;
  }
  #newEventBtn {
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
  }
  .menu-dropdown-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  .menu-dropdown-panel {
    top: calc(100% + 4px);
    right: 0;
    left: auto;
    width: 210px;
    z-index: 1000;
  }
  .header-nav-row {
    order: 3;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 2px;
  }
  main {
    padding: 12px;
  }
  .week-nav {
    font-size: 13px;
  }
  .scroll-hint {
    display: block;
  }
  .month-day-cell {
    min-height: 64px;
    max-height: 110px;
    overflow-y: auto;
    padding: 4px;
  }
  .month-day-number {
    font-size: 11px;
  }
  .month-event-chip {
    font-size: 10px;
    padding: 2px 4px;
  }
  .modal-content {
    width: 100%;
    max-width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }
}

/* --- Spinner de carga --- */
#loadingOverlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
}
#loadingOverlay.fade-out {
  opacity: 0;
  pointer-events: none;
}
#loadingOverlay.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 16px;
}
#loadingOverlay span {
  color: var(--muted);
  font-size: 14px;
}

/* --- Animación vista mensual --- */
.month-grid {
  animation: fadeIn 0.35s ease both;
}

/* --- Transiciones de la vista toggle --- */
.view-btn {
  transition: background var(--transition), color var(--transition);
}

/* --- Botón de Campana y Badges de Solicitudes --- */
.requests-btn {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}
.requests-btn:hover {
  background: #f0f2f8;
  transform: translateY(-1px);
}
.bell-icon {
  display: inline-block;
  transition: transform 0.2s ease;
}
.requests-btn:hover .bell-icon {
  transform: scale(1.15) rotate(12deg);
}

.requests-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #e03131;
  color: white;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  min-width: 18px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(224, 49, 49, 0.4);
  animation: popIn 0.25s ease both;
}

.requests-badge-inline {
  background: #e03131;
  color: white;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  margin-left: auto;
}

.login-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}
.login-header-btn:hover {
  background: var(--accent);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(79, 124, 255, 0.2);
}

/* --- Modales de Solicitudes --- */
.modal-content-wide {
  width: 580px;
  max-width: 95vw;
}

.requests-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  padding-bottom: 2px;
}
.tab-btn {
  border: none;
  background: none;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
}
.tab-btn:hover {
  color: var(--text);
  background: none;
  transform: none;
  box-shadow: none;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.requests-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 55vh;
  overflow-y: auto;
  padding-right: 4px;
}

.request-card {
  background: #fafbfe;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.request-card:hover {
  box-shadow: 0 3px 8px rgba(0,0,0,0.05);
}

.request-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.request-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.request-room-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: white;
}

.request-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 4px 12px;
  font-size: 12px;
  color: var(--muted);
}
.request-detail-item strong {
  color: var(--text);
}

.request-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid #edf0f7;
}

.btn-approve {
  background: #2b8a3e !important;
  color: white !important;
  border-color: #2b8a3e !important;
  padding: 6px 12px !important;
  font-size: 12px !important;
  font-weight: 600;
}
.btn-approve:hover {
  background: #237032 !important;
}

.btn-reject {
  background: #fff5f5 !important;
  color: #c92a2a !important;
  border-color: #ffc9c9 !important;
  padding: 6px 12px !important;
  font-size: 12px !important;
  font-weight: 600;
}
.btn-reject:hover {
  background: #ffe3e3 !important;
}

.req-status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.req-status-approved {
  background: #ebfbee;
  color: #2b8a3e;
}
.req-status-rejected {
  background: #fff5f5;
  color: #c92a2a;
}

.success-message {
  color: #2b8a3e;
  background: #ebfbee;
  border: 1px solid #c3fae8;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  margin-top: 10px;
}

