/* =====================================================
   Affinity Residential Care - Main Stylesheet
   Supports Bootstrap 5 light/dark mode + custom theming
   ===================================================== */

/* ---- CSS Variables ---- */
:root {
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 0px;
  --topbar-height: 56px;
  --affinity-primary: #4361ee;
  --affinity-accent: #3a86ff;

  /* Light mode */
  --sidebar-bg: #1e2a3a;
  --sidebar-text: #c8d6e8;
  --sidebar-link-hover: rgba(255,255,255,0.08);
  --sidebar-active-bg: var(--affinity-primary);
  --topbar-bg: #ffffff;
  --topbar-border: #e9ecef;
  --welcome-bg: linear-gradient(135deg, #4361ee 0%, #3a86ff 100%);
  --welcome-text: #ffffff;
  --card-bg: #ffffff;
  --body-bg: #f0f2f5;
  --avatar-bg: #4361ee;
  --avatar-text: #ffffff;
}

[data-bs-theme="dark"] {
  --sidebar-bg: #111827;
  --sidebar-text: #9ca3af;
  --topbar-bg: #1f2937;
  --topbar-border: #374151;
  --welcome-bg: linear-gradient(135deg, #1e40af 0%, #1d4ed8 100%);
  --card-bg: #1f2937;
  --body-bg: #111827;
}

/* ---- Base ---- */
body {
  background-color: var(--body-bg);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
  transition: background-color 0.2s, color 0.2s;
}

/* ---- Sidebar ---- */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  transition: width 0.25s ease, transform 0.25s ease;
  overflow-x: hidden;
  overflow-y: auto;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
}

#sidebar .nav-link {
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 2px;
  font-size: 0.875rem;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

#sidebar .nav-link:hover {
  background-color: var(--sidebar-link-hover);
  color: #ffffff;
}

#sidebar .nav-link.active {
  background-color: var(--sidebar-active-bg);
  color: #ffffff;
}

#sidebar .sidebar-brand {
  text-decoration: none;
  color: #ffffff;
}

#sidebar hr {
  border-color: rgba(255,255,255,0.1);
}

#sidebar small.text-muted {
  color: rgba(255,255,255,0.35) !important;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
}

/* ---- Page Content ---- */
#page-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left 0.25s ease;
}

/* ---- Top Bar ---- */
.topbar {
  background-color: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  height: var(--topbar-height);
  position: sticky;
  top: 0;
  z-index: 1030;
  transition: background-color 0.2s;
}

/* ---- Sidebar Collapsed (Mobile) ---- */
body.sidebar-hidden #sidebar {
  transform: translateX(-100%);
}

body.sidebar-hidden #page-content {
  margin-left: 0;
}

/* Sidebar overlay on mobile */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1039;
}

body.sidebar-open #sidebar-overlay {
  display: block;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
  }
  #page-content {
    margin-left: 0 !important;
  }
  body.sidebar-open #sidebar {
    transform: translateX(0);
  }
}

/* ---- Auth Page ---- */
.auth-bg {
  background: var(--welcome-bg);
  min-height: 100vh;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  border-radius: 16px !important;
}

.auth-logo-circle {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--affinity-primary), var(--affinity-accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

/* ---- Welcome Banner ---- */
.welcome-banner {
  background: var(--welcome-bg);
  color: var(--welcome-text);
}

/* ---- Avatar ---- */
.avatar-sm {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background-color: var(--affinity-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  background-color: var(--affinity-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.avatar-xl {
  width: 72px;
  height: 72px;
  min-width: 72px;
  border-radius: 50%;
  background-color: var(--affinity-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.8rem;
}

.avatar-lg.bg-warning { background-color: #f59e0b !important; }
.avatar-lg.bg-info { background-color: #0ea5e9 !important; }

/* ---- Cards ---- */
.card {
  transition: box-shadow 0.15s;
}

.user-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.1) !important;
  transform: translateY(-1px);
  transition: all 0.15s;
}

.stat-card {
  border-radius: 12px !important;
}

/* ---- Role Badges ---- */
.role-badge-administrator { background-color: #7c3aed !important; color: white !important; }
.role-badge-manager       { background-color: #0891b2 !important; color: white !important; }
.role-badge-employee      { background-color: #059669 !important; color: white !important; }
.role-badge-resident      { background-color: #d97706 !important; color: white !important; }

/* ---- Calendar ---- */
.fc {
  font-size: 0.875rem;
}

.fc .fc-toolbar-title {
  font-size: 1rem;
  font-weight: 700;
}

.fc .fc-button {
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
}

[data-bs-theme="dark"] .fc-theme-standard td,
[data-bs-theme="dark"] .fc-theme-standard th,
[data-bs-theme="dark"] .fc-theme-standard .fc-scrollgrid {
  border-color: #374151;
}

[data-bs-theme="dark"] .fc-day-today {
  background-color: rgba(67, 97, 238, 0.15) !important;
}

[data-bs-theme="dark"] .fc-col-header-cell-cushion,
[data-bs-theme="dark"] .fc-daygrid-day-number {
  color: #e5e7eb;
}

/* ---- Event Color Dot ---- */
.event-color-dot {
  width: 10px;
  height: 10px;
  min-width: 10px;
  border-radius: 50%;
}

/* ---- Color Picker ---- */
.color-option input[type="radio"] {
  display: none;
}

.color-swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}

.color-option input[type="radio"]:checked + .color-swatch {
  border-color: #1a1a1a;
  transform: scale(1.15);
}

[data-bs-theme="dark"] .color-option input[type="radio"]:checked + .color-swatch {
  border-color: #ffffff;
}

/* ---- Utilities ---- */
.min-width-0 { min-width: 0; }

.font-monospace { font-family: 'SF Mono', 'Fira Code', monospace; }

/* ---- Sidebar Brand Logo ---- */
.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
}

/* ---- Scrollbar (Webkit) ---- */
#sidebar::-webkit-scrollbar {
  width: 4px;
}
#sidebar::-webkit-scrollbar-track {
  background: transparent;
}
#sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
}

/* ---- Tables in Dark Mode ---- */
[data-bs-theme="dark"] .table-light {
  --bs-table-bg: #374151;
  --bs-table-color: #e5e7eb;
}

/* ---- Form Controls in Dark Mode ---- */
[data-bs-theme="dark"] .accordion-button.bg-light {
  background-color: #374151 !important;
  color: #e5e7eb;
}

/* ---- Print ---- */
@media print {
  #sidebar, .topbar { display: none !important; }
  #page-content { margin-left: 0 !important; }
}
