@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg-grad-start: #0d6efd;
  --bg-grad-end: #0b5ed7;
  --wa-bg: #efe7dd;
  --wa-bubble: #ffffff;
  --wa-sent: #dcf8c6;
  
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 72px;
  --topbar-height: 64px;

  /* Light Theme Tokens */
  --bg-body: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #2563eb;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --topbar-bg: #ffffff;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

[data-theme="dark"] {
  --bg-body: #090d16;
  --bg-card: #0f172a;
  --bg-sidebar: #060911;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #2563eb;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
  --topbar-bg: #0f172a;
  --input-bg: #1e293b;
  --input-border: #334155;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.6);
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Layout Wrapper */
.wrapper {
  display: flex;
  width: 100%;
  align-items: stretch;
}

/* Guest / Login Layout (No Scrollbar, Clean Dark Theme) */
.guest-wrapper {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  margin: 0;
  padding: 0;
  background-color: #060911;
}

.login-page-dark {
  height: 100vh;
  max-height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, #1e293b 0%, #060911 75%);
  position: relative;
  margin: 0;
  padding: 0;
}

/* Clean White Card for Login Modal */
.login-card-white {
  max-width: 440px;
  width: 92%;
  background: #ffffff;
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
  color: #0f172a;
  padding: 36px 30px;
}

/* Sidebar Styling */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--sidebar-text);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 100vh;
  z-index: 1000;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.12);
}

#sidebar .sidebar-header {
  height: var(--topbar-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

#sidebar .sidebar-header .brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
}

#sidebar .sidebar-header img {
  max-height: 36px;
  width: auto;
  object-fit: contain;
}

.sidebar-pin-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94a3b8;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.sidebar-pin-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

#sidebar ul.components {
  padding: 14px 10px;
  margin: 0;
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

#sidebar ul li {
  margin-bottom: 4px;
}

#sidebar ul li a {
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 500;
  color: #94a3b8;
  text-decoration: none;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 14px;
  border-radius: 10px;
  white-space: nowrap;
}

#sidebar ul li a i {
  font-size: 1.2rem;
  width: 24px;
  min-width: 24px;
  text-align: center;
  color: #94a3b8;
  transition: transform 0.2s ease, color 0.2s ease;
}

#sidebar ul li a:hover {
  background: var(--bg-sidebar-hover);
  color: #ffffff;
}

#sidebar ul li a:hover i {
  color: #ffffff;
  transform: scale(1.1);
}

/* ACTIVE MENU SELECTION STYLING - HIGH CONTRAST & LEGIBILITY */
#sidebar ul li.active > a {
  background: #2563eb !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45) !important;
}

#sidebar ul li.active > a i,
#sidebar ul li.active > a span,
#sidebar ul li.active > a .menu-text {
  color: #ffffff !important;
  opacity: 1 !important;
}

#sidebar .sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 12px 14px;
}

/* STRICT COLLAPSED SIDEBAR RULES - ZERO TEXT BLEED */
#sidebar.collapsed {
  width: var(--sidebar-collapsed-width) !important;
  min-width: var(--sidebar-collapsed-width) !important;
  overflow: hidden !important;
}

#sidebar.collapsed .sidebar-header {
  padding: 0 10px !important;
  justify-content: center !important;
}

#sidebar.collapsed .sidebar-header .brand-title,
#sidebar.collapsed .sidebar-header img {
  display: none !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
}

#sidebar.collapsed .sidebar-pin-btn i {
  transform: rotate(180deg);
}

#sidebar.collapsed ul li a {
  padding: 12px 0 !important;
  justify-content: center !important;
  gap: 0 !important;
  text-align: center !important;
}

#sidebar.collapsed ul li a .menu-text,
#sidebar.collapsed ul li a span {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

#sidebar.collapsed ul li a i {
  font-size: 1.3rem !important;
  width: 100% !important;
  margin: 0 !important;
  text-align: center !important;
}

#sidebar.collapsed .sidebar-divider {
  margin: 10px 8px !important;
}

/* Main Content Area */
#content {
  width: 100%;
  padding-left: var(--sidebar-width);
  min-height: 100vh;
  transition: padding-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

#content.collapsed {
  padding-left: var(--sidebar-collapsed-width) !important;
}

/* Topbar Header */
.topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 999;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.sidebar-toggle-btn {
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle-btn:hover {
  background: var(--bg-sidebar-hover);
  color: #ffffff;
  border-color: var(--bg-sidebar-hover);
  transform: scale(1.05);
}

.theme-toggle-btn {
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.theme-toggle-btn:hover {
  transform: rotate(15deg) scale(1.05);
  background: var(--border-color);
}

/* Mobile Responsiveness */
@media (max-width: 991.98px) {
  #sidebar {
    left: calc(-1 * var(--sidebar-width));
    width: var(--sidebar-width) !important;
    min-width: var(--sidebar-width) !important;
    transition: left 0.3s ease;
  }
  
  #sidebar.mobile-open {
    left: 0;
  }

  #sidebar.collapsed {
    width: var(--sidebar-width) !important;
    min-width: var(--sidebar-width) !important;
  }

  #sidebar.collapsed ul li a .menu-text {
    display: inline !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: auto !important;
    height: auto !important;
  }

  #sidebar.collapsed ul li a {
    justify-content: flex-start !important;
    padding: 10px 14px !important;
    gap: 14px !important;
  }

  #sidebar.collapsed .sidebar-header .brand-title,
  #sidebar.collapsed .sidebar-header img {
    display: inline !important;
    visibility: visible !important;
    width: auto !important;
    height: auto !important;
  }

  #content {
    padding-left: 0 !important;
  }
  
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }
}

/* UI Cards and Components */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  color: var(--text-main);
  transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
}

.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.card-header {
  background-color: transparent;
  border-bottom: 1px solid var(--border-color);
  padding: 18px 24px;
}

.card-body {
  padding: 24px;
}

/* Enhanced KPI Cards */
.kpi-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--kpi-accent, #3b82f6);
  border-radius: 4px 0 0 4px;
}

.kpi-icon-box {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: var(--kpi-bg, rgba(59, 130, 246, 0.1));
  color: var(--kpi-accent, #3b82f6);
}

.kpi-title {
  font-size: 0.825rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

/* Dashboard Filter Bar */
.filter-glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

/* Form Controls Dark Mode Compatibility */
.form-control, .form-select {
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text-main);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
  background-color: var(--input-bg);
  color: var(--text-main);
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .form-control::placeholder {
  color: #64748b;
}

/* Modals */
.modal-content {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  border-bottom: 1px solid var(--border-color);
}

.modal-footer {
  border-top: 1px solid var(--border-color);
}

[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* Tables */
.table {
  color: var(--text-main);
  border-color: var(--border-color);
  vertical-align: middle;
}

.table th {
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  background-color: rgba(0, 0, 0, 0.02);
  border-bottom-width: 1px;
}

[data-theme="dark"] .table th {
  background-color: rgba(255, 255, 255, 0.02);
  color: #94a3b8;
}

[data-theme="dark"] .table td {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}

/* Dropdowns */
.dropdown-menu {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}

.dropdown-item {
  color: var(--text-main);
  border-radius: 8px;
  padding: 9px 16px;
  transition: background-color 0.2s ease;
}

.dropdown-item:hover {
  background-color: var(--bg-sidebar-hover);
  color: #ffffff;
}

[data-theme="dark"] .dropdown-divider {
  border-color: var(--border-color);
}

/* WhatsApp Preview Component */
.wa-preview-container {
  background-color: var(--wa-bg);
  background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
  border-radius: 14px;
  padding: 20px;
  min-height: 380px;
  display: flex;
  flex-direction: column;
  font-family: Helvetica, Arial, sans-serif;
}

.wa-bubble {
  background-color: var(--wa-bubble);
  border-radius: 7.5px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  max-width: 90%;
  padding: 8px 10px;
  position: relative;
  margin-bottom: 10px;
  align-self: flex-start;
  color: #111b21;
}
