/**
 * Dashboard Common Styles
 * Defensive IT compliant - No external dependencies
 * 
 * @author Alan Axford
 * @version 1.0
 */

/* ==========================================
   CSS VARIABLES (Design Tokens)
   ========================================== */
:root {
  /* Primary Colors */
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;

  /* Blue (distinct from primary) */
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  /* Sky Blue */
  --sky-50: #f0f9ff;
  --sky-100: #e0f2fe;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;
  --sky-700: #0369a1;

  /* Cyan */
  --cyan-50: #ecfeff;
  --cyan-100: #cffafe;
  --cyan-500: #06b6d4;
  --cyan-600: #0891b2;
  --cyan-700: #0e7490;

  /* Emerald */
  --emerald-50: #ecfdf5;
  --emerald-100: #d1fae5;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;

  /* Green (alias for success) */
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;

  /* Lime */
  --lime-50: #f7fee7;
  --lime-100: #ecfccb;
  --lime-500: #84cc16;
  --lime-600: #65a30d;
  --lime-700: #4d7c0f;

  /* Yellow */
  --yellow-50: #fefce8;
  --yellow-100: #fef9c3;
  --yellow-500: #eab308;
  --yellow-600: #ca8a04;
  --yellow-700: #a16207;

  /* Orange */
  --orange-50: #fff7ed;
  --orange-100: #ffedd5;
  --orange-500: #f97316;
  --orange-600: #ea580c;
  --orange-700: #c2410c;

  /* Red (alias for danger) */
  --red-50: #fef2f2;
  --red-100: #fee2e2;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  /* Rose */
  --rose-50: #fff1f2;
  --rose-100: #ffe4e6;
  --rose-500: #f43f5e;
  --rose-600: #e11d48;
  --rose-700: #be123c;

  /* Fuchsia */
  --fuchsia-50: #fdf4ff;
  --fuchsia-100: #fae8ff;
  --fuchsia-500: #d946ef;
  --fuchsia-600: #c026d3;
  --fuchsia-700: #a21caf;

  /* Violet */
  --violet-50: #f5f3ff;
  --violet-100: #ede9fe;
  --violet-500: #8b5cf6;
  --violet-600: #7c3aed;
  --violet-700: #6d28d9;

  /* Indigo */
  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;

  /* Status Colors */
  --success-50: #f0fdf4;
  --success-500: #22c55e;
  --success-600: #16a34a;
  --danger-50: #fef2f2;
  --danger-500: #ef4444;
  --danger-600: #dc2626;
  --warning-50: #fffbeb;
  --warning-500: #f59e0b;
  --warning-600: #d97706;
  --amber-50: #fffbeb;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --purple-50: #faf5ff;
  --purple-500: #a855f7;
  --purple-600: #9333ea;
  --teal-50: #f0fdfa;
  --teal-500: #14b8a6;
  --teal-600: #0d9488;
  --pink-50: #fdf2f8;
  --pink-500: #ec4899;
  --pink-600: #db2777;

  /* Neutral Colors */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* Typography - System font stack (no external dependencies) */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono",
    Consolas, "Liberation Mono", Menlo, Monaco, monospace;

  /* Shadows */
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1),
    0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* Border Radius */
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

/* ==========================================
   BASE STYLES
   ========================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: linear-gradient(
    135deg,
    var(--slate-100) 0%,
    var(--slate-50) 100%
  );
  color: var(--slate-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ==========================================
   HEADER STYLES
   ========================================== */
.app-header {
  background: linear-gradient(
    135deg,
    var(--primary-700) 0%,
    var(--primary-600) 100%
  );
  color: white;
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.back-btn {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateX(-2px);
}

.back-btn svg {
  width: 20px;
  height: 20px;
  stroke: white;
  stroke-width: 2;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.app-logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-logo span {
  font-size: 12px;
  opacity: 0.8;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.3);
}

.header-title h1 {
  font-size: 18px;
  font-weight: 700;
}

.header-title span {
  font-size: 12px;
  opacity: 0.8;
}

.header-actions,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ==========================================
   BUTTON STYLES
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.btn-white {
  background: white;
  color: var(--primary-600);
}

.btn-white:hover {
  background: var(--primary-50);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
  color: white;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: white;
  color: var(--slate-700);
  border: 1px solid var(--slate-300);
}

.btn-secondary:hover {
  background: var(--slate-50);
}

.btn-success {
  background: var(--success-500);
  color: white;
}

.btn-success:hover {
  background: var(--success-600);
}

.btn-danger {
  background: var(--danger-500);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-600);
}

.btn-ghost {
  background: transparent;
  color: var(--slate-600);
  padding: 8px 12px;
}

.btn-ghost:hover {
  background: var(--slate-100);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================
   MAIN CONTENT
   ========================================== */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px;
}

.page-header {
  margin-bottom: 32px;
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--slate-900);
  margin-bottom: 8px;
}

.page-subtitle {
  font-size: 16px;
  color: var(--slate-600);
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--slate-900);
  margin-bottom: 20px;
}

/* ==========================================
   MODULE GRID & CARDS
   ========================================== */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
  margin-bottom: 48px;
}

.module-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--slate-200);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.module-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.module-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
  border-color: transparent;
}

.module-content {
  padding: 24px;
}

.module-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.module-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.module-title-section {
  flex: 1;
}

.module-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--slate-900);
  margin-bottom: 4px;
}

.module-description {
  font-size: 13px;
  color: var(--slate-600);
  line-height: 1.5;
}

.module-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
}

.module-stat {
  flex: 1;
}

.module-stat-value {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--slate-800);
  line-height: 1;
}

.module-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
  margin-top: 4px;
}

.module-footer {
  padding: 16px 24px;
  background: var(--slate-50);
  border-top: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.module-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-700);
  transition: all 0.2s;
}

.module-link svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  transition: transform 0.2s;
}

.module-card:hover .module-link svg {
  transform: translateX(4px);
}

.module-badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.module-badge.success {
  background: var(--success-50);
  color: var(--success-600);
}

.module-badge.warning {
  background: var(--warning-50);
  color: var(--warning-600);
}

.module-badge.active {
  background: var(--primary-50);
  color: var(--primary-600);
}

/* ==========================================
   STATS ROW
   ========================================== */
.stats-row {
  display: flex;
  gap: 20px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 200px;
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--slate-200);
}

.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--slate-900);
  line-height: 1;
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  margin-top: 8px;
}

.stat-change.positive {
  color: var(--success-600);
}

.stat-change.negative {
  color: var(--danger-600);
}

/* ==========================================
   LOADING & EMPTY STATES
   ========================================== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--slate-200);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty-state {
  text-align: center;
  padding: 60px 40px;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--slate-700);
  margin-bottom: 8px;
}

.empty-text {
  color: var(--slate-500);
  margin-bottom: 20px;
}

/* ==========================================
   ANIMATIONS
   ========================================== */
.animate-in {
  animation: slideInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger animation delays */
.animate-in:nth-child(1) {
  animation-delay: 0.1s;
}
.animate-in:nth-child(2) {
  animation-delay: 0.2s;
}
.animate-in:nth-child(3) {
  animation-delay: 0.3s;
}
.animate-in:nth-child(4) {
  animation-delay: 0.4s;
}
.animate-in:nth-child(5) {
  animation-delay: 0.5s;
}
.animate-in:nth-child(6) {
  animation-delay: 0.6s;
}

/* ==========================================
   UTILITIES
   ========================================== */
.text-center {
  text-align: center;
}

.mb-32 {
  margin-bottom: 32px;
}

.mt-32 {
  margin-top: 32px;
}

/* ==========================================
   CRM ENTITY HEADERS
   ========================================== */
.entity-header {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  gap: 16px;
}

.entity-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary-100), var(--primary-50));
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.entity-icon.business {
  background: linear-gradient(135deg, var(--purple-100), var(--purple-50));
}

.entity-icon.person {
  background: linear-gradient(135deg, var(--primary-100), var(--primary-50));
}

.entity-info h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--slate-800);
}

.entity-meta {
  font-size: 13px;
  color: var(--slate-500);
}

/* ==========================================
   CRM CARD LISTS (Addresses, Contacts, etc)
   ========================================== */
.card-list {
  display: grid;
  gap: 16px;
}

.card-item {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--slate-200);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: start;
  transition: all 0.2s;
}

.card-item:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-300);
}

.card-item.primary {
  border-color: var(--primary-400);
  border-width: 2px;
}

.card-icon {
  width: 48px;
  height: 48px;
  background: var(--slate-100);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.card-details h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--slate-800);
}

.card-text {
  font-size: 14px;
  color: var(--slate-600);
  line-height: 1.6;
}

.card-meta {
  font-size: 12px;
  color: var(--slate-500);
  margin-top: 8px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ==========================================
   TYPE BADGES (for addresses, contacts, etc)
   ========================================== */
.type-badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

/* Color variants */
.type-badge.primary {
  background: var(--primary-50);
  color: var(--primary-600);
}
.type-badge.secondary {
  background: var(--slate-100);
  color: var(--slate-600);
}
.type-badge.purple {
  background: var(--purple-50);
  color: var(--purple-600);
}
.type-badge.success {
  background: var(--success-50);
  color: var(--success-600);
}
.type-badge.amber {
  background: var(--amber-50);
  color: var(--amber-600);
}
.type-badge.teal {
  background: var(--teal-50);
  color: var(--teal-600);
}
.type-badge.indigo {
  background: var(--indigo-50);
  color: var(--indigo-600);
}
.type-badge.pink {
  background: var(--pink-50);
  color: var(--pink-600);
}

/* ==========================================
   MODULE CARD TOP STRIPE COLOR VARIANTS
   Use these classes to add colored top stripes to module cards
   Example: <div class="module-card blue">...</div>
   ========================================== */

/* Blue Variants */
.module-card.blue::before {
  background: linear-gradient(90deg, var(--blue-500), var(--blue-600));
}

.module-card.primary::before {
  background: linear-gradient(90deg, var(--primary-500), var(--primary-600));
}

.module-card.sky::before {
  background: linear-gradient(90deg, var(--sky-500), var(--sky-600));
}

/* Cyan & Teal */
.module-card.cyan::before {
  background: linear-gradient(90deg, var(--cyan-500), var(--cyan-600));
}

.module-card.teal::before {
  background: linear-gradient(90deg, var(--teal-500), var(--teal-600));
}

/* Green Variants */
.module-card.emerald::before {
  background: linear-gradient(90deg, var(--emerald-500), var(--emerald-600));
}

.module-card.green::before {
  background: linear-gradient(90deg, var(--green-500), var(--green-600));
}

.module-card.success::before {
  background: linear-gradient(90deg, var(--success-500), var(--success-600));
}

.module-card.lime::before {
  background: linear-gradient(90deg, var(--lime-500), var(--lime-600));
}

/* Yellow & Orange */
.module-card.yellow::before {
  background: linear-gradient(90deg, var(--yellow-500), var(--yellow-600));
}

.module-card.amber::before {
  background: linear-gradient(90deg, var(--amber-500), var(--amber-600));
}

.module-card.warning::before {
  background: linear-gradient(90deg, var(--warning-500), var(--warning-600));
}

.module-card.orange::before {
  background: linear-gradient(90deg, var(--orange-500), var(--orange-600));
}

/* Red & Pink */
.module-card.red::before {
  background: linear-gradient(90deg, var(--red-500), var(--red-600));
}

.module-card.danger::before {
  background: linear-gradient(90deg, var(--danger-500), var(--danger-600));
}

.module-card.rose::before {
  background: linear-gradient(90deg, var(--rose-500), var(--rose-600));
}

.module-card.pink::before {
  background: linear-gradient(90deg, var(--pink-500), var(--pink-600));
}

/* Purple Variants */
.module-card.fuchsia::before {
  background: linear-gradient(90deg, var(--fuchsia-500), var(--fuchsia-600));
}

.module-card.purple::before {
  background: linear-gradient(90deg, var(--purple-500), var(--purple-600));
}

.module-card.violet::before {
  background: linear-gradient(90deg, var(--violet-500), var(--violet-600));
}

.module-card.indigo::before {
  background: linear-gradient(90deg, var(--indigo-500), var(--indigo-600));
}

/* Neutral */
.module-card.slate::before {
  background: linear-gradient(90deg, var(--slate-500), var(--slate-600));
}

.module-card.gray::before {
  background: linear-gradient(90deg, var(--slate-500), var(--slate-600));
}

/* Additional type badge variants for new colors */
.type-badge.sky {
  background: var(--sky-50);
  color: var(--sky-600);
}
.type-badge.cyan {
  background: var(--cyan-50);
  color: var(--cyan-600);
}
.type-badge.emerald {
  background: var(--emerald-50);
  color: var(--emerald-600);
}
.type-badge.lime {
  background: var(--lime-50);
  color: var(--lime-600);
}
.type-badge.yellow {
  background: var(--yellow-50);
  color: var(--yellow-600);
}
.type-badge.orange {
  background: var(--orange-50);
  color: var(--orange-600);
}
.type-badge.red {
  background: var(--red-50);
  color: var(--red-600);
}
.type-badge.rose {
  background: var(--rose-50);
  color: var(--rose-600);
}
.type-badge.fuchsia {
  background: var(--fuchsia-50);
  color: var(--fuchsia-600);
}
.type-badge.violet {
  background: var(--violet-50);
  color: var(--violet-600);
}
.type-badge.blue {
  background: var(--blue-50);
  color: var(--blue-600);
}
.type-badge.green {
  background: var(--green-50);
  color: var(--green-600);
}