/**
 * CRM Platform v3.1 — Custom Theme Bundle
 * Replaces Keenthemes Rider template assets
 * Based on: docs/t4d-ui.md + data/rider-analysis.html
 *
 * Sections:
 *  1. CSS Custom Properties    7. Badge System         13. AI Widget
 *  2. Typography & Base        8. Drawer System        14. User Avatar
 *  3. Sidebar Layout           9. Kanban Board         15. Symbol Group
 *  4. Menu System             10. Notification Dropdown 16. Progress Bars
 *  5. Header                  11. Card System          17. Plugin Overrides
 *  6. Content Area            12. Page Utilities       18. Responsive
 */

/* ═══════════════════════════════════════════════════════════════════
   1. CSS CUSTOM PROPERTIES
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --crm-primary:  #1a56db;
  --crm-success:  #059669;
  --crm-danger:   #dc2626;
  --crm-warning:  #d97706;
  --crm-info:     #0284c7;
  --crm-purple:   #7c3aed;
  --crm-teal:     #0d9488;
  --crm-neutral:  #64748b;

  --app-sidebar-bg:      #1e3a5f;
  --app-sidebar-text:    #cbd5e1;
  --app-sidebar-active:  #1a56db;
  --app-sidebar-width:   265px;
  --app-sidebar-width-collapsed: 75px;
  --app-header-height:   64px;
  --app-content-max-width: 1400px;
  --app-border-radius:   0.625rem;
}

[data-bs-theme="dark"] {
  --crm-primary:  #3b82f6;
  --crm-success:  #34d399;
  --crm-danger:   #f87171;
  --crm-warning:  #fbbf24;
  --crm-info:     #38bdf8;
  --crm-purple:   #a78bfa;
  --crm-teal:     #2dd4bf;
  --app-sidebar-bg: #0f1e30;
}

/* ═══════════════════════════════════════════════════════════════════
   2. TYPOGRAPHY & BASE
   ═══════════════════════════════════════════════════════════════════ */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0;
  overflow-x: hidden;
}

/* Rider-compatible font size utilities */
.fs-2hx { font-size: 2.5rem !important; }
.fs-7 { font-size: 0.8rem !important; }
.fs-8 { font-size: 0.75rem !important; }
.fw-semibold { font-weight: 600 !important; }

/* Flex utility */
.flex-row-fluid { flex: 1; }

/* ═══════════════════════════════════════════════════════════════════
   3. SIDEBAR LAYOUT
   ═══════════════════════════════════════════════════════════════════ */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--app-sidebar-width);
  background: var(--app-sidebar-bg);
  color: var(--app-sidebar-text);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, transform 0.3s ease;
}

.app-sidebar-logo {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 64px;
}
.app-sidebar-logo img { height: 40px; }
.app-sidebar-logo .logo-text {
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
}
.app-sidebar-logo .logo-compact { display: none; }

.app-sidebar-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.app-sidebar-wrapper::-webkit-scrollbar { width: 4px; }
.app-sidebar-wrapper::-webkit-scrollbar-track { background: transparent; }
.app-sidebar-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1039;
}
.sidebar-overlay.show { display: block; }

/* Collapsed sidebar state */
body[data-kt-app-sidebar-minimize="on"] .app-sidebar {
  width: var(--app-sidebar-width-collapsed);
}
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .menu-title,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .menu-section,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .menu-arrow,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .logo-text,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .sidebar-footer .user-info {
  display: none;
}
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .logo-compact { display: block; }
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .menu-link {
  justify-content: center;
  padding: 0.65rem 0;
}
body[data-kt-app-sidebar-minimize="on"] .app-sidebar .menu-icon {
  width: auto;
  font-size: 1.25rem;
}
body[data-kt-app-sidebar-minimize="on"] .app-wrapper {
  margin-left: var(--app-sidebar-width-collapsed);
}

/* Hover expand collapsed sidebar */
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover {
  width: var(--app-sidebar-width);
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
}
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover .menu-title,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover .menu-section,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover .menu-arrow,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover .logo-text,
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover .sidebar-footer .user-info {
  display: block;
}
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover .logo-compact { display: none; }
body[data-kt-app-sidebar-minimize="on"] .app-sidebar:hover .menu-link {
  justify-content: flex-start;
  padding: 0.65rem 1rem;
}

/* ═══════════════════════════════════════════════════════════════════
   4. MENU SYSTEM
   ═══════════════════════════════════════════════════════════════════ */
.menu.menu-column { display: flex; flex-direction: column; }

.menu-item { padding: 0 0.75rem; }

.menu-link {
  display: flex;
  align-items: center;
  padding: 0.65rem 1rem;
  color: var(--app-sidebar-text);
  text-decoration: none;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  gap: 0.75rem;
  cursor: pointer;
}
.menu-link:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.menu-link.active {
  background: var(--app-sidebar-active);
  color: #fff;
}

.menu-icon {
  width: 24px;
  text-align: center;
  font-size: 1.1rem;
  opacity: 0.7;
  flex-shrink: 0;
}
.menu-link.active .menu-icon,
.menu-link:hover .menu-icon { opacity: 1; }

.menu-title { flex: 1; }

.menu-arrow {
  width: 16px;
  text-align: center;
  font-size: 0.7rem;
  opacity: 0.5;
  transition: transform 0.2s;
}
.menu-item.show > .menu-link > .menu-arrow { transform: rotate(90deg); }

.menu-section {
  padding: 1.25rem 1.75rem 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(203,213,225,0.5);
  font-weight: 600;
}

/* Accordion submenu */
.menu-sub.menu-sub-accordion {
  display: none;
  padding-left: 1rem;
}
.menu-item.show > .menu-sub.menu-sub-accordion { display: block; }

/* Dropdown submenu (header context menus) */
.menu-sub.menu-sub-dropdown {
  display: none;
  position: absolute;
  background: var(--bs-body-bg, #fff);
  border: 1px solid var(--bs-border-color, #e2e8f0);
  border-radius: var(--app-border-radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  min-width: 200px;
  z-index: 1060;
  padding: 0.5rem 0;
}
.menu-item.show > .menu-sub.menu-sub-dropdown { display: block; }

/* ═══════════════════════════════════════════════════════════════════
   5. HEADER
   ═══════════════════════════════════════════════════════════════════ */
.app-wrapper {
  margin-left: var(--app-sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  height: var(--app-header-height);
  background: var(--bs-body-bg, #fff);
  border-bottom: 1px solid var(--bs-border-color, #e2e8f0);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 1030;
  transition: height 0.2s, box-shadow 0.2s;
}
.app-header.app-header-minimize {
  height: 50px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.app-header .header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.app-header .header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hamburger-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--bs-body-color);
  padding: 0.25rem;
}

.breadcrumb-text {
  font-size: 0.85rem;
  color: var(--crm-neutral);
}

/* Header icon buttons */
.header-icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  color: var(--bs-body-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: background 0.2s;
}
.header-icon-btn:hover { background: var(--bs-tertiary-bg, #f1f5f9); }

.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--crm-danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.notification-badge.d-none { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════
   6. CONTENT AREA
   ═══════════════════════════════════════════════════════════════════ */
.app-content {
  flex: 1;
  padding: 1.5rem;
}
.app-container {
  max-width: var(--app-content-max-width);
  margin: 0 auto;
}
.app-container.container-xxl { max-width: var(--app-content-max-width); }

/* ═══════════════════════════════════════════════════════════════════
   7. BADGE SYSTEM (light + solid variants)
   ═══════════════════════════════════════════════════════════════════ */
.badge-light-primary { background: rgba(26,86,219,0.12); color: #1a56db; }
.badge-light-success { background: rgba(5,150,105,0.12); color: #059669; }
.badge-light-danger  { background: rgba(220,38,38,0.12); color: #dc2626; }
.badge-light-warning { background: rgba(217,119,6,0.12); color: #d97706; }
.badge-light-info    { background: rgba(2,132,199,0.12); color: #0284c7; }
.badge-light-purple  { background: rgba(124,58,237,0.12); color: #7c3aed; }
.badge-light-teal    { background: rgba(13,148,136,0.12); color: #0d9488; }

.badge-purple { background: var(--crm-purple); color: #fff; }
.badge-teal   { background: var(--crm-teal); color: #fff; }
.badge-info   { background: var(--crm-info); color: #fff; }

[data-bs-theme="dark"] .badge-light-primary { background: rgba(59,130,246,0.15); color: #93bbfd; }
[data-bs-theme="dark"] .badge-light-success { background: rgba(52,211,153,0.15); color: #6ee7b7; }
[data-bs-theme="dark"] .badge-light-danger  { background: rgba(248,113,113,0.15); color: #fca5a5; }
[data-bs-theme="dark"] .badge-light-warning { background: rgba(251,191,36,0.15); color: #fcd34d; }
[data-bs-theme="dark"] .badge-light-info    { background: rgba(56,189,248,0.15); color: #7dd3fc; }
[data-bs-theme="dark"] .badge-light-purple  { background: rgba(167,139,250,0.15); color: #c4b5fd; }
[data-bs-theme="dark"] .badge-light-teal    { background: rgba(45,212,191,0.15); color: #5eead4; }

/* ═══════════════════════════════════════════════════════════════════
   8. DRAWER SYSTEM
   ═══════════════════════════════════════════════════════════════════ */
.drawer-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1049;
}
.drawer-overlay.show { display: block; }

.drawer {
  position: fixed;
  top: 0;
  right: -100%;
  bottom: 0;
  background: var(--bs-body-bg, #fff);
  z-index: 1050;
  transition: right 0.3s ease;
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
}
.drawer.show { right: 0; }
.drawer-600 { width: 100%; max-width: 600px; }
.drawer-420 { width: 100%; max-width: 420px; }

/* ═══════════════════════════════════════════════════════════════════
   9. KANBAN BOARD
   ═══════════════════════════════════════════════════════════════════ */
.kanban-board {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  scroll-snap-type: x proximity;
}
.kanban-column {
  flex-shrink: 0;
  width: 280px;
  scroll-snap-align: start;
}
.kanban-cards {
  min-height: 200px;
  padding: 4px;
  border-radius: 8px;
  background: var(--bs-tertiary-bg, #f8f9fa);
  transition: background 0.2s, outline 0.2s;
}
.kanban-cards.drag-highlight {
  background: rgba(26, 86, 219, 0.08) !important;
  outline: 2px dashed var(--crm-primary);
  outline-offset: -2px;
}
.kanban-card {
  transition: opacity 0.15s, box-shadow 0.15s;
  cursor: grab;
}
.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.kanban-card:active { cursor: grabbing; }

/* ═══════════════════════════════════════════════════════════════════
   10. NOTIFICATION DROPDOWN
   ═══════════════════════════════════════════════════════════════════ */
.notif-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  width: 360px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bs-body-bg, #fff);
  border: 1px solid var(--bs-border-color, #e2e8f0);
  border-radius: 0.75rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  z-index: 1050;
  display: none;
}
.notif-dropdown.show { display: block; }
.notif-dropdown-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.notif-item {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color, #f1f5f9);
  cursor: pointer;
  transition: background 0.15s;
}
.notif-item:hover { background: var(--bs-tertiary-bg, #f8fafc); }
.notif-item.unread { background: rgba(26,86,219,0.04); }
.notif-item .notif-title { font-size: 0.85rem; font-weight: 600; }
.notif-item .notif-time { font-size: 0.75rem; color: var(--crm-neutral); }

/* ═══════════════════════════════════════════════════════════════════
   11. CARD SYSTEM (Rider-compatible)
   ═══════════════════════════════════════════════════════════════════ */
.card { border-radius: var(--app-border-radius); }

.card-flush {
  border-left: 0;
  border-right: 0;
  border-radius: 0;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 50px;
  padding: 0.75rem 1.25rem;
}
.card-title { margin-bottom: 0; }
.card-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ═══════════════════════════════════════════════════════════════════
   12. PAGE UTILITIES
   ═══════════════════════════════════════════════════════════════════ */
.page-loader {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4rem;
}
.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.theme-toggle-btn { font-size: 1.1rem; }

/* Selection bubble (hidden by default, for DataTable multi-select) */
.selection-bubble {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1060;
}

/* ═══════════════════════════════════════════════════════════════════
   13. AI WIDGET
   ═══════════════════════════════════════════════════════════════════ */
#kt_ai_widget_btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1050;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--crm-purple);
  color: #fff;
  border: none;
  box-shadow: 0 4px 16px rgba(124,58,237,0.4);
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
#kt_ai_widget_btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(124,58,237,0.5);
}

.ai-drawer-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.ai-msg {
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  max-width: 90%;
}
.ai-msg-user {
  background: var(--crm-primary);
  color: #fff;
  align-self: flex-end;
}
.ai-msg-bot {
  background: var(--bs-tertiary-bg, #f1f5f9);
  align-self: flex-start;
}
.ai-input-area {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--bs-border-color);
  display: flex;
  gap: 0.5rem;
}
.ai-input-area input {
  flex: 1;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}
.ai-input-area button {
  background: var(--crm-purple);
  color: #fff;
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════
   14. USER AVATAR
   ═══════════════════════════════════════════════════════════════════ */
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--crm-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
}

/* ═══════════════════════════════════════════════════════════════════
   15. SYMBOL GROUP (avatar stack)
   ═══════════════════════════════════════════════════════════════════ */
.symbol-group { display: flex; flex-direction: row; }
.symbol {
  border-radius: 50%;
  border: 2px solid #fff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-tertiary-bg, #f1f5f9);
}
.symbol + .symbol { margin-left: -10px; }
.symbol-25px { width: 25px; height: 25px; font-size: 0.6rem; }
.symbol-35px { width: 35px; height: 35px; font-size: 0.75rem; }
.symbol-45px { width: 45px; height: 45px; font-size: 0.85rem; }
.symbol-50px { width: 50px; height: 50px; font-size: 0.9rem; }

.symbol-group-hover:hover .symbol + .symbol { margin-left: 2px; transition: margin 0.2s; }

/* ═══════════════════════════════════════════════════════════════════
   16. PROGRESS BAR VARIANTS
   ═══════════════════════════════════════════════════════════════════ */
.progress.h-6px { height: 6px; }
.progress.h-8px { height: 8px; }
.progress-bar.rounded { border-radius: 4px; }

/* ═══════════════════════════════════════════════════════════════════
   17. PLUGIN STYLE OVERRIDES
   ═══════════════════════════════════════════════════════════════════ */
/* TomSelect */
.ts-control {
  border-color: var(--bs-border-color, #dee2e6) !important;
  border-radius: var(--app-border-radius) !important;
  font-size: 0.875rem;
}
.ts-dropdown {
  border-radius: var(--app-border-radius) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1) !important;
}

/* SweetAlert2 */
.swal2-popup {
  border-radius: var(--app-border-radius) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 0.9rem !important;
}
.swal2-title { font-size: 1.2rem !important; }
.swal2-confirm { border-radius: 0.5rem !important; }
.swal2-cancel { border-radius: 0.5rem !important; }

/* DataTables */
.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: 0.375rem !important;
}
.dataTables_wrapper .dataTables_filter input {
  border-radius: var(--app-border-radius);
  border: 1px solid var(--bs-border-color, #dee2e6);
  padding: 0.375rem 0.75rem;
}

/* Flatpickr */
.flatpickr-calendar {
  border-radius: var(--app-border-radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

/* ═══════════════════════════════════════════════════════════════════
   18. RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
  }
  .app-wrapper {
    margin-left: 0 !important;
  }
  .hamburger-btn {
    display: flex;
  }
  .drawer-600 { max-width: 100%; }
}

@media (max-width: 767.98px) {
  .app-content { padding: 1rem; }
  .notif-dropdown { width: 300px; right: -1rem; }
  .kanban-column { width: 260px; }
}

@media (max-width: 575.98px) {
  .app-content { padding: 0.75rem; }
  .app-header { padding: 0 1rem; }
  .notif-dropdown { width: calc(100vw - 2rem); right: -0.5rem; }
}
