/* ============================================================
   TreatExpert CRM - Core Glassmorphism CSS Architecture
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Sora:wght@400;500;600;700;800&display=swap');

:root {
  --bg-base: #080c14;
  --bg-surface: #0d1117;
  --bg-elevated: #161b22;
  --bg-card: rgba(255, 255, 255, 0.035);
  --bg-card-hover: rgba(255, 255, 255, 0.065);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-violet: #7c3aed;
  --accent-violet-light: #a855f7;
  --accent-teal: #06b6d4;
  --accent-gold: #f59e0b;
  --accent-red: #ef4444;
  --accent-green: #10b981;

  --sidebar-width: 270px;
  --topbar-height: 68px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-glass: 0 10px 40px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 25px rgba(124, 58, 237, 0.25);

  --font-heading: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
}

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

html, body {
  height: 100%;
  width: 100%;
  font-family: var(--font-body);
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* App Container Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
  background: radial-gradient(circle at 80% 0%, rgba(124, 58, 237, 0.06), transparent 50%),
              radial-gradient(circle at 10% 90%, rgba(6, 182, 212, 0.06), transparent 50%);
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: rgba(13, 17, 23, 0.95);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  height: var(--topbar-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo-badge {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-violet), var(--accent-teal));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.logo-badge svg { width: 20px; height: 20px; }

.logo-text {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
}
.logo-text span {
  background: linear-gradient(90deg, var(--accent-violet-light), var(--accent-teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-toggle {
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  border: none;
}
.sidebar-toggle:hover { color: #fff; background: rgba(255,255,255,0.05); }

/* Sidebar Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Sidebar Nav Item Styling Matching Image 1 ERP Aesthetics */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: #0b0f19;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.nav-item:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.nav-item.active {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border-left: none;
  border-radius: 12px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.25);
}

.nav-item.active svg {
  color: #38bdf8;
}

.nav-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #cbd5e1;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.nav-group-header:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.04);
}

.nav-group-items {
  display: none;
  flex-direction: column;
  gap: 2px;
  padding-left: 0.75rem;
  margin-top: 2px;
}

.nav-group.open .nav-group-items { display: flex; }
.nav-group.open .group-chevron { transform: rotate(180deg); }

.group-chevron {
  width: 14px;
  height: 14px;
  transition: transform 0.2s;
  flex-shrink: 0;
  color: #64748b;
}

/* Icon-Only Collapsed Sidebar Styling */
.sidebar.collapsed {
  width: 72px !important;
  min-width: 72px !important;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .sidebar-nav .nav-item span,
.sidebar.collapsed .nav-group-header span,
.sidebar.collapsed .group-chevron,
.sidebar.collapsed .nav-group-items {
  display: none !important;
}

.sidebar.collapsed .sidebar-header {
  padding: 1rem 0.5rem;
  justify-content: center;
}

.sidebar.collapsed .logo-badge {
  margin: 0 auto;
}

.sidebar.collapsed .sidebar-nav {
  padding: 1rem 0.4rem;
  align-items: center;
}

.sidebar.collapsed .nav-item,
.sidebar.collapsed .nav-group-header {
  justify-content: center;
  padding: 0.75rem 0;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin: 2px auto;
  position: relative;
}

.sidebar.collapsed .nav-item svg,
.sidebar.collapsed .nav-group-header svg {
  width: 22px;
  height: 22px;
  margin: 0;
}

/* Main Content Wrapper */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* Topbar */
.topbar {
  width: 100%;
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 90;
  box-sizing: border-box;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  max-width: 480px;
}

.mobile-toggle {
  display: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
}

.topbar-search {
  position: relative;
  width: 100%;
}
.topbar-search input {
  width: 100%;
  background: #ffffff !important;
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.55rem 1rem 0.55rem 2.5rem;
  color: #000000 !important;
  font-weight: 600 !important;
  font-size: 0.875rem;
  transition: all 0.2s;
}
.topbar-search input:focus {
  border-color: var(--accent-violet);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}
.topbar-search .search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: #475569;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-left: auto;
  flex-shrink: 0;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.icon-btn svg { width: 18px; height: 18px; }

.badge-notification {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent-red);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  line-height: 1;
}

.lang-select {
  background: #ffffff !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #000000 !important;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 700 !important;
  cursor: pointer;
  outline: none;
}
.lang-select option { background: #ffffff !important; color: #000000 !important; }

/* User Profile Badge */
.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.95rem 0.35rem 0.45rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 99px;
  white-space: nowrap;
}

.avatar-pill {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-violet), var(--accent-teal));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.avatar-pill svg { width: 16px; height: 16px; }

.user-details { display: flex; flex-direction: column; text-align: left; }
.user-name { font-size: 0.82rem; font-weight: 600; color: #fff; line-height: 1.1; }
.user-role { font-size: 0.68rem; color: var(--accent-teal); font-weight: 500; }

/* Main Content Area */
.main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.page-wrapper {
  height: 100%;
  overflow-y: auto;
  padding: 1rem 1.1rem;
}

.page-section { display: none; }
.page-section.active { display: block; animation: fadeIn 0.3s ease; }

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

/* Modals & Loaders */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-box {
  background: rgba(13, 17, 23, 0.95);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-glass);
}
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 850px; }

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 1.1rem; color: #fff; }

.close-modal {
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  padding: 4px;
  border: none;
}
.close-modal:hover { color: #fff; background: rgba(255,255,255,0.08); }

.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.loading-overlay.hidden { display: none !important; }

.spinner-lg svg { width: 36px; height: 36px; color: var(--accent-violet-light); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Sidebar Collapsed State */
.sidebar {
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
  width: 72px !important;
  min-width: 72px !important;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-group-header span,
.sidebar.collapsed .group-chevron,
.sidebar.collapsed .nav-group-items {
  display: none !important;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 1rem 0.5rem;
}

.sidebar.collapsed .logo-container {
  gap: 0;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 0.75rem 0;
  border-left: none;
}

.sidebar.collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

/* Mobile & Tablet Responsiveness */
@media (max-width: 992px) {
  .mobile-toggle {
    display: flex !important;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 6px;
    cursor: pointer;
    border-radius: 6px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
  }

  .sidebar.open, .sidebar.active {
    transform: translateX(0) !important;
    width: 260px !important;
  }

  .topbar {
    padding: 0 1rem;
  }

  .topbar-left {
    max-width: 100%;
  }

  .main-content {
    padding: 1rem;
  }

  .grid-cols-4, .md-grid-cols-4, .kpi-grid-5 {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) !important;
  }
}

@media (max-width: 600px) {
  .topbar-search {
    width: 100%;
  }

  .user-details {
    display: none;
  }
}
