/* ================================================================
   SAFA Calendar — Premium Calendar Tool Stylesheet
   ================================================================
   A world-class calendar UI with Month/Week/Day views,
   collapsible sidebar, mini-calendar, glassmorphism dark theme,
   and smooth micro-animations.
   ================================================================ */

/* ----------------------------------------------------------------
   1. CSS Custom Properties
   ---------------------------------------------------------------- */
:root {
  /* Colors — Backgrounds */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-elevated: #ffffff;

  /* Colors — Surface / Glass */
  --surface: rgba(0, 0, 0, 0.8);
  --surface-solid: #ffffff;
  --glass-bg: rgba(255, 255, 255, 0.95);
  --glass-blur: blur(20px);

  /* Colors — Borders */
  --border: rgba(0, 0, 0, 0.08);
  --border-light: rgba(0, 0, 0, 0.04);
  --border-focus: rgba(99, 102, 241, 0.5);

  /* Colors — Text */
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --text-inverse: #ffffff;

  /* Colors — Accent */
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.1);
  --accent-glow: rgba(99, 102, 241, 0.15);

  /* Colors — Semantic */
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.1);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.1);

  /* Colors — Now line */
  --now-line: #ef4444;

  /* Colors — Event Palette (vivid pastels) */
  --ev-lavender: #c4b5fd;
  --ev-mint: #6ee7b7;
  --ev-peach: #fca5a5;
  --ev-sky: #7dd3fc;
  --ev-butter: #fde68a;
  --ev-rose: #f9a8d4;
  --ev-coral: #fdba74;
  --ev-lilac: #d8b4fe;
  --ev-aqua: #67e8f9;
  --ev-sage: #86efac;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-2xs: 0.625rem;
  --font-size-xs: 0.6875rem;
  --font-size-sm: 0.75rem;
  --font-size-base: 0.875rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2rem;
  --font-size-3xl: 3rem;

  /* Border Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4), 0 6px 10px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.5), 0 12px 24px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);

  /* Layout */
  --header-height: 60px;
  --sidebar-width: 280px;
}

/* ----------------------------------------------------------------
   2. Base / Reset
   ---------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; }

/* Scrollbar — Webkit */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.35); }
::-webkit-scrollbar-corner { background: transparent; }

/* Scrollbar — Firefox */
* { scrollbar-width: thin; scrollbar-color: rgba(148,163,184,0.2) transparent; }

::selection { background: rgba(99, 102, 241, 0.3); color: #fff; }

/* ----------------------------------------------------------------
   3. Utility Classes
   ---------------------------------------------------------------- */
.hidden { display: none !important; }
.admin-only { /* JS controls visibility */ }
.editor-only { /* JS controls visibility */ }

/* ----------------------------------------------------------------
   4. Login Screen
   ---------------------------------------------------------------- */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  background: linear-gradient(-45deg, #0a0e1a, #1e1b4b, #0c1a3d, #0a0e1a, #1a103a, #0a0e1a);
  background-size: 400% 400%;
  animation: gradientShift 18s ease infinite;
}

.login-container {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: var(--space-12);
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-logo {
  font-size: var(--font-size-3xl);
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #818cf8, #a78bfa, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-1);
  line-height: 1.1;
}

.login-logo span {
  font-weight: 300;
  font-size: 0.55em;
  display: block;
  background: none;
  -webkit-text-fill-color: var(--text-secondary);
  letter-spacing: 6px;
  margin-top: 2px;
}

.login-subtitle {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: var(--space-8);
  font-weight: 500;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

#login-form .form-input {
  text-align: center;
  padding: 14px 16px;
  font-size: var(--font-size-base);
}

.login-error {
  color: var(--danger);
  font-size: var(--font-size-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 68, 68, 0.2);
  animation: slideUp 0.3s ease;
}

.btn-login {
  width: 100%;
  padding: 14px 24px !important;
  font-size: var(--font-size-md) !important;
  font-weight: 600 !important;
  margin-top: var(--space-2);
}

.login-footer {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  letter-spacing: 1px;
  margin-top: var(--space-4);
}

/* ----------------------------------------------------------------
   5. Main App Layout
   ---------------------------------------------------------------- */
#main-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ----------------------------------------------------------------
   6. Header
   ---------------------------------------------------------------- */
#app-header {
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  height: var(--header-height);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  gap: var(--space-3);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent);
}

.header-logo svg { width: 22px; height: 22px; flex-shrink: 0; }

.header-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

/* Hamburger for mobile sidebar toggle */
#btn-sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  flex-shrink: 0;
}
#btn-sidebar-toggle:hover { background: rgba(0, 0, 0,0.06); color: var(--text-primary); }

/* Center area — calendar navigation */
.header-center {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  justify-content: center;
}

.header-nav-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

#btn-today {
  padding: 6px 16px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-family);
  margin-right: var(--space-2);
}
#btn-today:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.nav-arrow {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  font-family: var(--font-family);
}
.nav-arrow:hover { background: rgba(0, 0, 0,0.06); color: var(--text-primary); }
.nav-arrow svg { width: 18px; height: 18px; }

#current-month-display {
  font-size: var(--font-size-lg);
  font-weight: 700;
  min-width: 200px;
  text-align: center;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  cursor: default;
  user-select: none;
}

/* View Selector Tabs */
.view-selector {
  display: flex;
  background: rgba(0, 0, 0,0.04);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  margin-left: var(--space-2);
}

.view-btn {
  padding: 5px 14px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: var(--font-family);
  white-space: nowrap;
}
.view-btn:hover { color: var(--text-primary); }
.view-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.4);
}

/* Header Right */
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

#user-display-name {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding-right: var(--space-1);
}

/* Role Badges */
.role-badge, .badge {
  font-size: var(--font-size-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-right: var(--space-2);
}

.badge-admin {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.15);
}

.badge-editor {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.15);
}

.badge-viewer {
  background: rgba(148, 163, 184, 0.2);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.15);
}

/* Header icon buttons */
.header-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  position: relative;
}
.header-btn:hover { background: rgba(0, 0, 0,0.06); color: var(--text-primary); }
.header-btn svg { width: 18px; height: 18px; }
.header-btn .btn-text { display: none; }

/* ----------------------------------------------------------------
   7. Sidebar
   ---------------------------------------------------------------- */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.collapsed {
  width: 0;
  margin-left: -1px;
  border-right: none;
}

/* New Event button in sidebar */
#btn-new-event-sidebar {
  margin: var(--space-4) var(--space-4) var(--space-3);
  padding: 10px 20px;
  border-radius: var(--radius-lg);
  border: none;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
#btn-new-event-sidebar:hover {
  background: linear-gradient(135deg, #818cf8, #6366f1);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}
#btn-new-event-sidebar svg { width: 18px; height: 18px; }

/* --- Mini Calendar --- */
.mini-calendar {
  padding: 0 var(--space-4) var(--space-4);
  flex-shrink: 0;
}

.mini-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
}

.mini-cal-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
  cursor: default;
}

.mini-cal-nav {
  display: flex;
  gap: 2px;
}

.mini-cal-nav button {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  font-family: var(--font-family);
}
.mini-cal-nav button:hover { background: rgba(0, 0, 0,0.06); color: var(--text-primary); }
.mini-cal-nav button svg { width: 14px; height: 14px; }

.mini-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  text-align: center;
}

.mini-cal-dow {
  font-size: var(--font-size-2xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  padding: 4px 0;
  letter-spacing: 0.5px;
}

.mini-cal-day {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: var(--font-size-xs);
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  margin: 0 auto;
}
.mini-cal-day:hover { background: rgba(0, 0, 0,0.06); color: var(--text-primary); }
.mini-cal-day.other-month { color: var(--text-tertiary); opacity: 0.4; }
.mini-cal-day.today {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.mini-cal-day.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.mini-cal-day.today.selected {
  background: var(--accent);
  color: #fff;
}
.mini-cal-day.has-events::after {
  content: '';
  position: absolute;
  bottom: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}
.mini-cal-day { position: relative; }

/* --- Sidebar Divider --- */
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-2) var(--space-4);
}

/* --- Spaces List in Sidebar --- */
.sidebar-section {
  padding: var(--space-2) var(--space-4);
  flex: 1;
  overflow-y: auto;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
  margin-bottom: var(--space-1);
}

.sidebar-section-title {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

#btn-add-space {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 1.5px dashed rgba(0, 0, 0,0.15);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  padding: 0;
}
#btn-add-space:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
#btn-add-space svg { width: 12px; height: 12px; }

.space-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
  margin-bottom: 1px;
  user-select: none;
}
.space-item:hover { background: rgba(0, 0, 0,0.04); }
.space-item.active { background: rgba(0, 0, 0,0.06); }

.space-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.space-item-name {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.space-item.active .space-item-name {
  color: var(--accent);
}

/* ----------------------------------------------------------------
   8. Calendar Container — Main Area
   ---------------------------------------------------------------- */
#calendar-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

#calendar-view-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ----------------------------------------------------------------
   9. Month View
   ---------------------------------------------------------------- */
.month-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Day-of-week header */
.month-dow-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.month-dow-cell {
  padding: 10px 12px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
  border-right: 1px solid var(--border);
}
.month-dow-cell:last-child { border-right: none; }
.month-dow-cell.weekend { color: rgba(148,163,184,0.4); }

/* Weeks grid */
.month-grid {
  flex: 1;
  display: grid;
  grid-template-rows: repeat(auto-fill, minmax(0, 1fr));
  overflow: hidden;
}

/* Each week is a row */
.month-week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  min-height: 0;
  border-bottom: 1px solid var(--border);
}
.month-week-row:last-child { border-bottom: none; }

/* Day cell */
.month-day-cell {
  border-right: 1px solid var(--border);
  padding: 4px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  min-height: 0;
}
.month-day-cell:last-child { border-right: none; }
.month-day-cell:hover { background: rgba(0, 0, 0,0.02); }
.month-day-cell.other-month { background: rgba(0,0,0,0.15); }
.month-day-cell.other-month .month-day-number { color: var(--text-tertiary); opacity: 0.4; }
.month-day-cell.weekend { background: rgba(0, 0, 0,0.01); }
.month-day-cell.today { background: rgba(99, 102, 241, 0.04); }

.month-day-number {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  margin-bottom: 2px;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.month-day-cell.today .month-day-number {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* Event pills in month view */
.month-events-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.month-event-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  font-size: var(--font-size-2xs);
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: var(--transition-fast);
  flex-shrink: 0;
  line-height: 1.6;
  min-height: 18px;
}
.month-event-pill:hover {
  filter: brightness(1.15);
  transform: scale(1.01);
}

.month-event-pill .pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.month-event-pill .pill-time {
  font-size: var(--font-size-2xs);
  font-weight: 600;
  opacity: 0.8;
  flex-shrink: 0;
}

.month-event-pill .pill-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.month-more-events {
  font-size: var(--font-size-2xs);
  color: var(--text-tertiary);
  font-weight: 600;
  padding: 0 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition-fast);
}
.month-more-events:hover { color: var(--accent); }

/* ----------------------------------------------------------------
   10. Week View
   ---------------------------------------------------------------- */
.week-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* All-day area at top */
.week-allday-area {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.week-allday-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-2xs);
  color: var(--text-tertiary);
  border-right: 1px solid var(--border);
  padding: var(--space-1);
}

/* Day headers */
.week-header {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.week-header-gutter {
  border-right: 1px solid var(--border);
}

.week-header-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px 6px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition-fast);
}
.week-header-day:last-child { border-right: none; }
.week-header-day:hover { background: rgba(0, 0, 0,0.02); }

.week-header-dow {
  font-size: var(--font-size-2xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.week-header-date {
  font-size: var(--font-size-xl);
  font-weight: 300;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: var(--transition-fast);
}

.week-header-day.today .week-header-dow { color: var(--accent); }
.week-header-day.today .week-header-date {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Scrollable body */
.week-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.week-grid {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  position: relative;
  min-height: 100%;
}

/* Time gutter */
.week-time-gutter {
  border-right: 1px solid var(--border);
}

.week-time-label {
  height: 48px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding-right: 8px;
  font-size: var(--font-size-2xs);
  font-weight: 500;
  color: var(--text-tertiary);
  transform: translateY(-6px);
  user-select: none;
}

/* Day columns */
.week-day-column {
  border-right: 1px solid var(--border);
  position: relative;
}
.week-day-column:last-child { border-right: none; }

.week-hour-slot {
  height: 48px;
  border-bottom: 1px solid rgba(0, 0, 0,0.04);
  cursor: pointer;
  transition: background 0.1s ease;
}
.week-hour-slot:hover { background: rgba(0, 0, 0,0.02); }
.week-hour-slot.half-hour { border-bottom: 1px solid rgba(0, 0, 0,0.02); }

/* Event blocks in week/day view */
.week-event-block {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: var(--font-size-xs);
  overflow: hidden;
  cursor: pointer;
  z-index: 3;
  border-left: 3px solid rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.week-event-block:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transform: scale(1.01);
  z-index: 5;
}

.week-event-title {
  font-weight: 600;
  font-size: var(--font-size-xs);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-event-time {
  font-size: var(--font-size-2xs);
  opacity: 0.75;
  font-weight: 500;
}

.week-event-org {
  font-size: var(--font-size-2xs);
  opacity: 0.6;
}

/* Now-line indicator */
.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--now-line);
  z-index: 10;
  pointer-events: none;
}
.now-line::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--now-line);
}

/* ----------------------------------------------------------------
   11. Day View
   ---------------------------------------------------------------- */
.day-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: var(--space-3);
  flex-shrink: 0;
}

.day-header-info {
  text-align: center;
}

.day-header-dow {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.day-header-date {
  font-size: var(--font-size-2xl);
  font-weight: 300;
  color: var(--text-primary);
}

.day-header-info.today .day-header-date {
  color: var(--accent);
}

.day-body {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.day-grid {
  display: grid;
  grid-template-columns: 60px 1fr;
  position: relative;
  min-height: 100%;
}

.day-time-gutter {
  border-right: 1px solid var(--border);
}

.day-column {
  position: relative;
}

.day-hour-slot {
  height: 48px;
  border-bottom: 1px solid rgba(0, 0, 0,0.04);
  cursor: pointer;
  transition: background 0.1s ease;
}
.day-hour-slot:hover { background: rgba(0, 0, 0,0.02); }

/* Events in day view use the same .week-event-block class */
.day-column .week-event-block {
  left: 4px;
  right: 4px;
}

/* ----------------------------------------------------------------
   12. Modals
   ---------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl), 0 0 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.modal-sm { max-width: 420px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 920px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.modal-close {
  flex-shrink: 0;
  opacity: 0.5;
}
.modal-close:hover { opacity: 1; }

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-body-np { padding: 0; }

.modal-footer {
  display: flex;
  align-items: center;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  gap: var(--space-3);
}

.modal-footer-spacer { flex: 1; }

/* ----------------------------------------------------------------
   13. Forms
   ---------------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-5);
}
.form-group:last-child { margin-bottom: 0; }

.form-label {
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: #1e293b;
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  width: 100%;
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: rgba(148, 163, 184, 0.4);
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.form-select option {
  background: #ffffff;
  color: var(--text-primary);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-hint {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  margin-top: 4px;
}

.form-color {
  height: 44px;
  padding: 4px;
  cursor: pointer;
}

.form-input-sm,
.form-select-sm {
  padding: 8px 12px;
  font-size: var(--font-size-sm);
}
.form-select-sm { padding-right: 32px; }

/* ----------------------------------------------------------------
   14. Color Picker
   ---------------------------------------------------------------- */
#event-color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
}

.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
  position: relative;
  outline: none;
  padding: 0;
  flex-shrink: 0;
}
.color-swatch:hover {
  transform: scale(1.2);
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.15);
}
.color-swatch.active {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.15);
}
.color-swatch.active::after {
  content: '✓';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 700;
  color: rgba(0,0,0,0.5);
}

/* ----------------------------------------------------------------
   15. Buttons
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: var(--transition);
  border: none;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  position: relative;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #818cf8, #6366f1);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}
.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.25);
}

.btn-danger {
  background: var(--danger-soft);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 8px 12px;
}
.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
}

.btn-sm { padding: 6px 12px; font-size: var(--font-size-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-icon { padding: 8px; aspect-ratio: 1; }
.btn-full { width: 100%; }

.btn.loading {
  color: transparent !important;
  pointer-events: none;
}
.btn.loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 18px; height: 18px;
  border: 2px solid rgba(0, 0, 0, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ----------------------------------------------------------------
   16. Users Modal Layout
   ---------------------------------------------------------------- */
.users-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 420px;
}

.users-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.users-sidebar-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

#users-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}

.user-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s ease;
  border-left: 3px solid transparent;
  position: relative;
}
.user-card:hover { background: rgba(0, 0, 0, 0.04); }
.user-card.active {
  background: rgba(99, 102, 241, 0.08);
  border-left-color: var(--accent);
}

.users-form-area {
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
}
.users-form-area form {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.users-actions {
  display: flex;
  gap: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ----------------------------------------------------------------
   17. Logs Table
   ---------------------------------------------------------------- */
.logs-filters {
  display: flex;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
}
.logs-filters .form-select,
.logs-filters .form-input {
  flex: 1;
  min-width: 150px;
}

.logs-table-wrapper {
  overflow-x: auto;
  max-height: 400px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.logs-table thead th {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  font-size: var(--font-size-xs);
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-light);
}

.logs-table tbody tr {
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  transition: background 0.15s ease;
}
.logs-table tbody tr:nth-child(even) { background: rgba(0, 0, 0, 0.01); }
.logs-table tbody tr:hover { background: rgba(0, 0, 0, 0.03); }

.logs-table tbody td {
  padding: 10px 14px;
  color: var(--text-primary);
  white-space: nowrap;
}

.logs-pagination {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding-top: var(--space-4);
}

/* ----------------------------------------------------------------
   18. Toast Notifications
   ---------------------------------------------------------------- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: rgba(26, 34, 52, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-light);
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  min-width: 300px;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  border-left: 4px solid var(--accent);
  font-size: var(--font-size-sm);
  font-weight: 500;
  /* La regla declaraba `color` dos veces: primero blanco y luego
     var(--text-primary), que es casi negro. Ganaba la segunda, así que
     el aviso salía en texto oscuro sobre fondo oscuro (contraste 1.09:1)
     y resultaba invisible. Se elimina la segunda para que quede el
     blanco, que sobre este fondo da 15.9:1. */
}

.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }
.toast-warning { border-left-color: var(--warning); }

/* ----------------------------------------------------------------
   19. Loading Overlay
   ---------------------------------------------------------------- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.7);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(0, 0, 0, 0.08);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ----------------------------------------------------------------
   20. Event Popover (Quick Peek)
   ---------------------------------------------------------------- */
.event-popover {
  position: fixed;
  z-index: 900;
  background: rgba(26, 34, 52, 0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  padding: var(--space-5);
  width: 320px;
  animation: popoverIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.popover-color-stripe {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  margin-bottom: var(--space-3);
}

.popover-title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.popover-detail {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}
.popover-detail svg { width: 14px; height: 14px; color: var(--text-tertiary); flex-shrink: 0; }

.popover-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

/* ----------------------------------------------------------------
   21. Keyframe Animations
   ---------------------------------------------------------------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(100%); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutRight {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(100%); }
}

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

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes popoverIn {
  from { opacity: 0; transform: scale(0.95) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ----------------------------------------------------------------
   22. Responsive Design
   ---------------------------------------------------------------- */

/* Tablet */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }

  .week-header-date { font-size: var(--font-size-lg); width: 34px; height: 34px; }
  #current-month-display { font-size: var(--font-size-md); min-width: 160px; }
  .view-btn { padding: 4px 10px; font-size: var(--font-size-xs); }
}

/* Mobile */
@media (max-width: 768px) {
  #btn-sidebar-toggle { display: flex; }

  #sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    z-index: 200;
    width: var(--sidebar-width);
    box-shadow: var(--shadow-xl);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  #sidebar.collapsed { transform: translateX(-100%); width: var(--sidebar-width); margin-left: 0; }
  #sidebar.mobile-open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0,0,0,0.4);
    z-index: 199;
  }
  .sidebar-backdrop.visible { display: block; }

  #app-header {
    flex-wrap: nowrap;
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }

  .header-center { gap: var(--space-1); }

  #current-month-display {
    font-size: var(--font-size-base);
    min-width: auto;
    font-weight: 600;
  }

  .view-selector { margin-left: 0; }
  .view-btn { padding: 4px 8px; font-size: var(--font-size-2xs); }

  .header-right { gap: 0; }
  #user-display-name { display: none; }
  .role-badge { display: none; }
  .header-btn .btn-text { display: none; }

  /* Week view adjustments */
  .week-header { grid-template-columns: 40px repeat(7, 1fr); }
  .week-grid { grid-template-columns: 40px repeat(7, 1fr); }
  .week-allday-area { grid-template-columns: 40px repeat(7, 1fr); }
  .week-header-date { font-size: var(--font-size-base); width: 28px; height: 28px; }
  .week-header-dow { font-size: 9px; }
  .week-time-label { font-size: 9px; padding-right: 4px; }

  /* Day view adjustments */
  .day-grid { grid-template-columns: 40px 1fr; }

  /* Modal adjustments */
  .modal-content { max-width: 95%; }
  .modal-lg, .modal-xl { max-width: 95%; }
  .users-layout { grid-template-columns: 1fr; min-height: auto; }
  .users-sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 200px; }
}

/* Small mobile */
@media (max-width: 480px) {
  .view-selector { display: none; }

  /* Show a compact view selector below header */
  .mobile-view-selector {
    display: flex !important;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    justify-content: center;
    gap: 2px;
  }
}

.mobile-view-selector { display: none; }

