/* ============================================================
   WAAPI - Enterprise WhatsApp Platform
   Main Stylesheet - Indian Flag Inspired Theme
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  /* Indian Flag Theme */
  --saffron: #FF9933;
  --saffron-light: #FFB366;
  --saffron-dark: #E67300;
  --green: #138808;
  --green-light: #1AAD0A;
  --green-dark: #0E6606;
  --navy: #000080;
  --navy-light: #0000CC;
  --white: #FFFFFF;

  /* Gradients */
  --grad-primary: linear-gradient(135deg, #FF9933 0%, #FF7700 100%);
  --grad-success: linear-gradient(135deg, #138808 0%, #0E6606 100%);
  --grad-brand: linear-gradient(135deg, #FF9933 0%, #138808 100%);
  --grad-navy: linear-gradient(135deg, #000080 0%, #0000CC 100%);
  --grad-glass: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));

  /* 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;

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

  /* Transitions */
  --transition: all 0.2s ease;
  --transition-slow: all 0.4s ease;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-xl: 0 25px 50px -12px rgba(0,0,0,0.25);
  --shadow-brand: 0 4px 20px rgba(255,153,51,0.3);
  --shadow-green: 0 4px 20px rgba(19,136,8,0.3);

  /* Z-index */
  --z-sidebar: 100;
  --z-topbar: 90;
  --z-modal: 200;
  --z-toast: 300;
  --z-dropdown: 150;
}

/* ── Dark Theme ────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-primary: #0D0F14;
  --bg-secondary: #161B22;
  --bg-tertiary: #1C2128;
  --bg-card: #1E242D;
  --bg-hover: #252D38;
  --bg-active: #2A3445;
  --bg-input: #1A2030;
  --bg-sidebar: #10141A;
  --bg-glass: rgba(255,255,255,0.04);

  --text-primary: #E6EDF3;
  --text-secondary: #8B9AB0;
  --text-muted: #4D5B6E;
  --text-accent: #FF9933;

  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);
  --border-active: rgba(255,153,51,0.5);

  --scrollbar-track: #1C2128;
  --scrollbar-thumb: #2A3445;
}

/* ── Light Theme ───────────────────────────────────────────── */
[data-theme="light"] {
  --bg-primary: #F6F8FA;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F0F3F7;
  --bg-card: #FFFFFF;
  --bg-hover: #F3F6FA;
  --bg-active: #E8EFF8;
  --bg-input: #FFFFFF;
  --bg-sidebar: #FFFFFF;
  --bg-glass: rgba(0,0,0,0.02);

  --text-primary: #1A2233;
  --text-secondary: #4A5568;
  --text-muted: #9AA5B4;
  --text-accent: #E67300;

  --border: rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.15);
  --border-active: rgba(230,115,0,0.5);

  --scrollbar-track: #F0F3F7;
  --scrollbar-thumb: #CBD5E0;
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
  height: 100%;
}

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

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ── Loading Screen ─────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-logo {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.logo-icon svg { width: 80px; height: 80px; }

.loading-brand {
  font-size: 2rem;
  font-weight: 800;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

.loading-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.loading-bar {
  width: 200px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--space-4);
}

.loading-progress {
  height: 100%;
  background: var(--grad-brand);
  border-radius: 2px;
  animation: loadingAnim 2s ease-in-out infinite;
}

@keyframes loadingAnim {
  0% { width: 0%; margin-left: 0; }
  50% { width: 70%; margin-left: 0; }
  100% { width: 0%; margin-left: 100%; }
}

/* ── Layout ─────────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }
#main-app { display: flex; width: 100%; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  left: 0;
  height: 100vh;
  overflow: hidden;
  transition: width 0.3s ease;
  z-index: var(--z-sidebar);
  flex-shrink: 0;
}

.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .sidebar-search,
.sidebar.collapsed .user-info { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-icon { margin: 0; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  min-width: 0;
}

.brand-logo svg { width: 36px; height: 36px; flex-shrink: 0; }

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.brand-tag {
  font-size: 0.625rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-toggle svg { width: 18px; height: 18px; }

.sidebar-search {
  padding: var(--space-3) var(--space-4);
  position: relative;
}

.sidebar-search input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 12px 8px 36px;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  transition: var(--transition);
  outline: none;
}

.sidebar-search input:focus { border-color: var(--saffron); box-shadow: 0 0 0 3px rgba(255,153,51,0.1); }
.sidebar-search input::placeholder { color: var(--text-muted); }

.sidebar-search svg {
  position: absolute;
  left: calc(var(--space-4) + 10px);
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) var(--space-3);
}

.nav-section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: var(--space-4) var(--space-2) var(--space-2);
  display: block;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  font-size: 0.875rem;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(255,153,51,0.12);
  color: var(--saffron);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  height: 60%;
  width: 3px;
  background: var(--saffron);
  border-radius: 0 2px 2px 0;
}

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-badge {
  background: var(--saffron);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}

.nav-badge.green { background: var(--green); }
.nav-badge.navy { background: var(--navy); }

.nav-item-sub {
  padding-left: calc(var(--space-3) + 18px + var(--space-3));
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-3) var(--space-4);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

.user-profile:hover { background: var(--bg-hover); }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--grad-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  color: white;
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
  white-space: nowrap;
}

.user-menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: flex;
}

.user-menu-btn:hover { color: var(--text-primary); }
.user-menu-btn svg { width: 16px; height: 16px; }

/* ── Main Content ────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height: 64px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar-left { display: flex; align-items: center; gap: var(--space-4); }
.topbar-right { display: flex; align-items: center; gap: var(--space-2); }

.mob-sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.mob-sidebar-toggle svg { width: 20px; height: 20px; }

.page-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.topbar-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  position: relative;
}

.topbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.topbar-btn svg { width: 16px; height: 16px; }

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--saffron);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tenant-badge {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.tenant-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.9); }
}

/* ── Page Content ────────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Toast notifications ─────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 380px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  box-shadow: var(--shadow-xl);
  animation: slideInToast 0.3s ease;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid #EF4444; }
.toast.warning { border-left: 3px solid var(--saffron); }
.toast.info { border-left: 3px solid var(--navy); }

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

.toast-icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; font-size: 0.875rem; margin-bottom: 2px; }
.toast-msg { font-size: 0.8125rem; color: var(--text-secondary); }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px; }
.toast-close:hover { color: var(--text-primary); }

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

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: scaleIn 0.2s ease;
}

@keyframes scaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-sm { width: 400px; }
.modal-md { width: 600px; }
.modal-lg { width: 800px; }
.modal-xl { width: 1100px; }

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

.modal-title { font-size: 1.125rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: flex;
}

.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-close svg { width: 20px; height: 20px; }

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

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

/* ── Command Palette ─────────────────────────────────────────── */
.cmd-palette {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: min(600px, 90vw);
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,153,51,0.2);
  z-index: var(--z-modal);
  overflow: hidden;
  animation: scaleIn 0.15s ease;
}

.cmd-palette input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: var(--space-4) var(--space-5);
  font-size: 1rem;
  outline: none;
  border-bottom: 1px solid var(--border);
}

.cmd-palette input::placeholder { color: var(--text-muted); }

#cmdResults {
  max-height: 400px;
  overflow-y: auto;
  padding: var(--space-2);
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.875rem;
}

.cmd-item:hover, .cmd-item.active { background: var(--bg-hover); }
.cmd-item-icon { width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; }
.cmd-item-icon svg { width: 16px; height: 16px; }

/* ── Dropdown ────────────────────────────────────────────────── */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 200px;
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  overflow: hidden;
  animation: scaleIn 0.15s ease;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.875rem;
  color: var(--text-primary);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: #EF4444; }
.dropdown-item.danger:hover { background: rgba(239,68,68,0.08); }
.dropdown-item svg { width: 15px; height: 15px; color: var(--text-muted); }
.dropdown-divider { height: 1px; background: var(--border); margin: var(--space-1) 0; }

/* ── Auth Container ──────────────────────────────────────────── */
#auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: var(--space-4);
  position: relative;
  overflow: hidden;
}

#auth-container::before {
  content: '';
  position: absolute;
  top: -40%;
  left: -20%;
  width: 60%;
  height: 80%;
  background: radial-gradient(circle, rgba(255,153,51,0.06) 0%, transparent 70%);
  pointer-events: none;
}

#auth-container::after {
  content: '';
  position: absolute;
  bottom: -30%;
  right: -20%;
  width: 60%;
  height: 80%;
  background: radial-gradient(circle, rgba(19,136,8,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-xl);
  position: relative;
  z-index: 1;
}

.auth-logo {
  text-align: center;
  margin-bottom: var(--space-8);
}

.auth-logo svg { width: 56px; height: 56px; }

.auth-logo-name {
  font-size: 1.75rem;
  font-weight: 800;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-top: var(--space-3);
}

.auth-title { font-size: 1.5rem; font-weight: 700; margin-bottom: var(--space-2); }
.auth-subtitle { color: var(--text-secondary); margin-bottom: var(--space-8); font-size: 0.9375rem; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    transition: left 0.3s ease;
    box-shadow: var(--shadow-xl);
  }
  .sidebar.mobile-open { left: 0; }
  .main-content { margin-left: 0; }
  .mob-sidebar-toggle { display: flex; }
  .page-content { padding: var(--space-4); }
  .topbar { padding: 0 var(--space-4); }
}
