/* ============================================================
   CRM2 Design System — Main Stylesheet
   Bootstrap 5.3 with warm orange/red brand theme
   ============================================================ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design tokens ────────────────────────────────────────── */
:root {
  /* Brand palette */
  --crm-primary: #e05b2a;
  --crm-primary-dark: #c44a1e;
  --crm-primary-light: #f07244;
  --crm-secondary: #c0392b;
  --crm-accent: #f39c12;
  --crm-success: #27ae60;
  --crm-info: #2980b9;
  --crm-warning: #f39c12;
  --crm-danger: #c0392b;

  /* Surfaces */
  --crm-bg: #f5f5f5;
  --crm-sidebar-bg: #1e1e2d;
  --crm-sidebar-text: #a2a3b7;
  --crm-sidebar-active: rgba(224, 91, 42, 0.15);
  --crm-card-bg: #ffffff;
  --crm-card-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --crm-border: #e8e8e8;

  /* Typography */
  --crm-font: 'Inter', system-ui, sans-serif;
  --crm-text: #2c2c2c;
  --crm-text-muted: #6c757d;

  /* Layout */
  --crm-sidebar-w: 260px;
  --crm-navbar-h: 64px;
  --crm-radius: 10px;
  --crm-radius-lg: 16px;

  /* Transition */
  --crm-transition: all 0.25s cubic-bezier(.4, 0, .2, 1);
}

/* Dark theme overrides */
[data-bs-theme="dark"] {
  --crm-bg: #12121e;
  --crm-card-bg: #1e1e2d;
  --crm-card-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --crm-border: #2d2d3f;
  --crm-text: #e0e0e0;
  --crm-text-muted: #888;
  --bs-body-bg: #12121e;
  --bs-body-color: #e0e0e0;
}

/* Light theme — sidebar uses a light slate (near-white) palette so the
   whole screen looks cohesive in light mode. Without this the sidebar
   stays dark because its tokens are never overridden. */
[data-bs-theme="light"] {
  --crm-sidebar-bg: #f0f2f5;
  --crm-sidebar-text: #4a5568;
  --crm-sidebar-active: rgba(224, 91, 42, 0.12);
  --crm-bg: #f5f5f5;
  --crm-card-bg: #ffffff;
  --crm-border: #e2e8f0;
  --crm-text: #2c2c2c;
  --crm-text-muted: #6c757d;
}

/* In light mode, sidebar text and brand need dark colours */
[data-bs-theme="light"] .crm-sidebar .sidebar-brand .brand-text {
  color: #1a202c;
}

[data-bs-theme="light"] .crm-sidebar .sidebar-brand .brand-text small {
  color: #718096;
}

[data-bs-theme="light"] .sidebar-section-label {
  color: rgba(0, 0, 0, 0.35);
}

[data-bs-theme="light"] .sidebar-item {
  color: #4a5568;
}

[data-bs-theme="light"] .sidebar-item:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #1a202c;
}

[data-bs-theme="light"] .sidebar-item.active {
  color: var(--crm-primary);
}

[data-bs-theme="light"] .sidebar-user .user-name {
  color: #1a202c;
}

[data-bs-theme="light"] .sidebar-user .user-role {
  color: #718096;
}

[data-bs-theme="light"] .sidebar-user:hover {
  background: rgba(0, 0, 0, 0.05);
}

[data-bs-theme="light"] .crm-sidebar .sidebar-brand {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

[data-bs-theme="light"] .sidebar-footer {
  border-top-color: rgba(0, 0, 0, 0.08);
}

/* ── Bootstrap color overrides ──────────────────────────── */
.btn-primary,
.bg-primary {
  background-color: var(--crm-primary) !important;
  border-color: var(--crm-primary) !important;
}

.btn-primary:hover {
  background-color: var(--crm-primary-dark) !important;
  border-color: var(--crm-primary-dark) !important;
}

.text-primary {
  color: var(--crm-primary) !important;
}

.border-primary {
  border-color: var(--crm-primary) !important;
}

/* Override Bootstrap links */
a {
  color: var(--crm-primary);
}

a:hover {
  color: var(--crm-primary-dark);
}

/* ── Base ─────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: var(--crm-font);
  background: var(--crm-bg);
  color: var(--crm-text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Layout shell ─────────────────────────────────────────── */
.crm-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.crm-sidebar {
  width: var(--crm-sidebar-w);
  background: var(--crm-sidebar-bg);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: var(--crm-transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.crm-sidebar .sidebar-brand {
  height: var(--crm-navbar-h);
  /* match top navbar height (64px) */
  background: var(--crm-card-bg);
  /* same background as the top navbar */
  border-bottom: 1px solid var(--crm-border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.crm-sidebar .sidebar-brand .brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--crm-primary), var(--crm-secondary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(224, 91, 42, 0.35);
}

.crm-sidebar .sidebar-brand .brand-text {
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
}

.crm-sidebar .sidebar-brand .brand-text small {
  display: block;
  color: var(--crm-sidebar-text);
  font-size: 0.7rem;
  font-weight: 400;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.sidebar-section-label {
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 10px 24px 4px;
}

.sidebar-item {
  display: block;
  padding: 10px 20px;
  margin: 2px 8px;
  border-radius: 8px;
  color: var(--crm-sidebar-text);
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: var(--crm-transition);
}

.sidebar-item i {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
}

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

.sidebar-item.active {
  background: var(--crm-sidebar-active);
  color: var(--crm-primary-light);
  border-left: 3px solid var(--crm-primary);
  margin-left: 5px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--crm-transition);
}

.sidebar-user:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-user .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--crm-primary), var(--crm-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
}

.sidebar-user .user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user .user-name {
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user .user-role {
  color: var(--crm-sidebar-text);
  font-size: 0.7rem;
}

/* ── Top Navbar ───────────────────────────────────────────── */
.crm-navbar {
  position: fixed;
  top: 0;
  left: var(--crm-sidebar-w);
  right: 0;
  height: var(--crm-navbar-h);
  background: var(--crm-card-bg);
  border-bottom: 1px solid var(--crm-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 99;
  backdrop-filter: blur(10px);
  transition: var(--crm-transition);
}

.crm-navbar .page-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  color: var(--crm-text);
}

.crm-navbar .navbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--crm-text-muted);
  font-size: 1.1rem;
  transition: var(--crm-transition);
}

.theme-toggle:hover {
  background: var(--crm-bg);
  color: var(--crm-primary);
}

.lang-select {
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.8rem;
  background: var(--crm-card-bg);
  color: var(--crm-text);
  cursor: pointer;
}

/* ── Main content area ──────────────────────────────────────── */
.crm-main-content {
  margin-left: var(--crm-sidebar-w);
  margin-top: var(--crm-navbar-h);
  padding: 28px 28px 40px;
  flex: 1;
  min-height: calc(100vh - var(--crm-navbar-h));
}

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  color: var(--crm-text);
}

.page-header .breadcrumb {
  font-size: 0.8rem;
  margin-bottom: 4px;
}

/* ── Cards ────────────────────────────────────────────────── */
.crm-card {
  background: var(--crm-card-bg);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-lg);
  box-shadow: var(--crm-card-shadow);
  padding: 24px;
  margin-bottom: 20px;
  transition: var(--crm-transition);
}

.crm-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--crm-border);
}

.crm-card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

/* ── Stat cards ───────────────────────────────────────────── */
.stat-card {
  background: var(--crm-card-bg);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-lg);
  padding: 20px 24px;
  box-shadow: var(--crm-card-shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--crm-transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.orange {
  background: rgba(224, 91, 42, 0.12);
  color: var(--crm-primary);
}

.stat-icon.red {
  background: rgba(192, 57, 43, 0.12);
  color: var(--crm-secondary);
}

.stat-icon.green {
  background: rgba(39, 174, 96, 0.12);
  color: var(--crm-success);
}

.stat-icon.blue {
  background: rgba(41, 128, 185, 0.12);
  color: var(--crm-info);
}

.stat-icon.amber {
  background: rgba(243, 156, 18, 0.12);
  color: var(--crm-accent);
}

.stat-info {
  flex: 1;
  min-width: 0;
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--crm-text);
}

.stat-label {
  font-size: 0.78rem;
  color: var(--crm-text-muted);
  font-weight: 500;
  margin-top: 2px;
}

.stat-change {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.stat-change.up {
  background: rgba(39, 174, 96, 0.12);
  color: #1e7d4a;
}

.stat-change.down {
  background: rgba(192, 57, 43, 0.12);
  color: #a32921;
}

/* ── Tables ───────────────────────────────────────────────── */
.table {
  --bs-table-bg: transparent;
  --bs-table-striped-bg: rgba(0, 0, 0, 0.02);
}

[data-bs-theme="dark"] .table {
  --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
}

/* ── Forms ────────────────────────────────────────────────── */
.form-control,
.form-select {
  border-radius: 8px;
  border: 1px solid var(--crm-border);
  background: var(--crm-card-bg);
  color: var(--crm-text);
  transition: var(--crm-transition);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--crm-primary);
  box-shadow: 0 0 0 3px rgba(224, 91, 42, 0.15);
}

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  font-weight: 500;
  border-radius: 6px;
}

/* ── Login page ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e1e2d 0%, #2d1a0e 60%, #1a0a00 100%);
}

.login-card {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--crm-radius-lg);
  padding: 44px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-logo {
  width: 68px;
  height: 68px;
  background: linear-gradient(135deg, var(--crm-primary), var(--crm-secondary));
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px rgba(224, 91, 42, 0.4);
}

/* ── Tabs ─────────────────────────────────────────────────── */
.nav-tabs .nav-link {
  color: var(--crm-text-muted);
  border-radius: 10px 10px 0 0;
}

.nav-tabs .nav-link.active {
  color: var(--crm-primary);
  border-bottom-color: var(--crm-card-bg);
}

/* ── DataTable overrides ──────────────────────────────────── */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border-radius: 8px;
  border: 1px solid var(--crm-border);
  padding: 6px 12px;
  background: var(--crm-card-bg);
  color: var(--crm-text);
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

[data-bs-theme="dark"] ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
}

/* ── Animations ───────────────────────────────────────────── */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeSlideIn 0.3s ease both;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 992px) {
  .crm-sidebar {
    transform: translateX(-100%);
  }

  .crm-sidebar.open {
    transform: translateX(0);
  }

  .crm-navbar {
    left: 0;
  }

  .crm-main-content {
    margin-left: 0;
  }
}