/* ============================================================
   Superior CRM — Dashboard Styles
   Place at: your_app/static/css/crmstyle.css
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
  --crm-bg: #f4f6f9;
  --crm-card: #ffffff;
  --crm-border: #e8ecf2;
  --crm-border2: #d1d8e3;
  --crm-text: #1a2332;
  --crm-text2: #4e5d74;
  --crm-text3: #8a96a8;
  --crm-accent: #0c8fe6;
  --crm-accent2: #0070c4;
  --crm-green: #16a34a;
  --crm-green-bg: #f0fdf4;
  --crm-green-text: #15803d;
  --crm-amber: #d97706;
  --crm-amber-bg: #fffbeb;
  --crm-amber-text: #b45309;
  --crm-red: #dc2626;
  --crm-red-bg: #fef2f2;
  --crm-red-text: #b91c1c;
  --crm-blue-bg: #eff6ff;
  --crm-blue-text: #1d4ed8;
  --crm-teal: #0d9488;
  --crm-teal-bg: #f0fdfa;
  --crm-radius: 10px;
  --crm-radius-lg: 14px;
  --crm-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --crm-shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

/* ---- Dashboard Layout ---- */
.crm-dashboard {
  background: var(--crm-bg);
  padding: 0;
  min-height: 100%;
}

.crm-content {
  padding: 24px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1400px;
}

/* ---- NCR Banner ---- */
.crm-ncr-banner {
  background: var(--crm-red-bg);
  border: 1px solid #fecaca;
  border-radius: var(--crm-radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: crmFadeUp 0.3s ease both;
}

.crm-ncr-icon {
  width: 36px;
  height: 36px;
  background: #fee2e2;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--crm-red);
  flex-shrink: 0;
}

.crm-ncr-text { flex: 1; }

.crm-ncr-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--crm-red-text);
  margin-bottom: 2px;
}

.crm-ncr-desc {
  font-size: 12px;
  color: #9ca3af;
}

.crm-ncr-btn {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 7px;
  border: 1px solid #fca5a5;
  background: transparent;
  color: var(--crm-red-text);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.crm-ncr-btn:hover {
  background: #fee2e2;
  color: var(--crm-red-text);
}

/* ---- Section label ---- */
.crm-section-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--crm-text3);
  margin-bottom: 10px;
}

/* ---- KPI Row ---- */
.crm-kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}

@media (max-width: 1200px) {
  .crm-kpi-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .crm-kpi-row { grid-template-columns: repeat(2, 1fr); }
  .crm-content { padding: 16px; }
}

.crm-kpi {
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-lg);
  padding: 18px 20px;
  box-shadow: var(--crm-shadow);
  position: relative;
  overflow: hidden;
  animation: crmFadeUp 0.4s ease both;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.crm-kpi:hover {
  box-shadow: var(--crm-shadow-md);
  border-color: var(--crm-border2);
}

.crm-kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--kpi-color, transparent);
  border-radius: var(--crm-radius-lg) var(--crm-radius-lg) 0 0;
}

.crm-kpi:nth-child(1) { animation-delay: 0.05s; --kpi-color: #0c8fe6; }
.crm-kpi:nth-child(2) { animation-delay: 0.10s; --kpi-color: #d97706; }
.crm-kpi:nth-child(3) { animation-delay: 0.15s; --kpi-color: #16a34a; }
.crm-kpi:nth-child(4) { animation-delay: 0.20s; --kpi-color: #0d9488; }
.crm-kpi:nth-child(5) { animation-delay: 0.25s; --kpi-color: #dc2626; }

.crm-kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  margin-bottom: 14px;
  background: var(--kpi-icon-bg, #f1f5f9);
  color: var(--kpi-icon-color, var(--crm-text3));
}

.crm-kpi-label {
  font-size: 11px;
  color: var(--crm-text3);
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-bottom: 5px;
}

.crm-kpi-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--crm-text);
  font-family: 'DM Mono', monospace;
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 7px;
}

.crm-kpi-value.is-danger { color: var(--crm-red); }
.crm-kpi-value.is-success { color: var(--crm-green); }

.crm-kpi-delta {
  font-size: 11px;
  color: var(--crm-text3);
  display: flex;
  align-items: center;
  gap: 4px;
}

.crm-kpi-delta.up { color: var(--crm-green-text); }
.crm-kpi-delta.down { color: var(--crm-red-text); }
.crm-kpi-delta.warn { color: var(--crm-amber-text); }

/* ---- Grid layouts ---- */
.crm-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.crm-grid-3col {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.85fr;
  gap: 16px;
}

@media (max-width: 1100px) {
  .crm-grid-2 { grid-template-columns: 1fr; }
  .crm-grid-3col { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .crm-grid-3col { grid-template-columns: 1fr; }
}

/* ---- Card ---- */
.crm-card {
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius-lg);
  padding: 20px 22px;
  box-shadow: var(--crm-shadow);
  animation: crmFadeUp 0.45s ease both;
  transition: box-shadow 0.2s;
}

.crm-card:hover { box-shadow: var(--crm-shadow-md); }

.crm-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.crm-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--crm-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.crm-card-title i {
  font-size: 14px;
  color: var(--crm-text3);
}

.crm-card-action {
  font-size: 12px;
  color: var(--crm-accent);
  text-decoration: none;
  font-weight: 500;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.crm-card-action:hover { opacity: 1; color: var(--crm-accent2); }

/* ---- Pipeline ---- */
.crm-pipe-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.crm-pipe-row:last-of-type { margin-bottom: 0; }

.crm-pipe-stage {
  font-size: 12px;
  color: var(--crm-text2);
  width: 78px;
  flex-shrink: 0;
}

.crm-pipe-track {
  flex: 1;
  height: 7px;
  background: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
}

.crm-pipe-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.9s cubic-bezier(.4,0,.2,1);
}

.crm-pipe-count {
  font-size: 12px;
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  color: var(--crm-text);
  width: 22px;
  text-align: right;
}

.crm-pipe-eur {
  font-size: 11px;
  color: var(--crm-text3);
  width: 48px;
  text-align: right;
  font-family: 'DM Mono', monospace;
}

.crm-conversion-row {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--crm-border);
}

.crm-conversion-label {
  font-size: 11px;
  color: var(--crm-text3);
  margin-bottom: 7px;
}

.crm-conv-bar-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.crm-conv-track {
  flex: 1;
  height: 8px;
  background: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
}

.crm-conv-fill {
  height: 100%;
  background: var(--crm-green);
  border-radius: 4px;
}

.crm-conv-pct {
  font-size: 13px;
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  color: var(--crm-green-text);
}

/* ---- Badges ---- */
.crm-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.02em;
  font-family: 'DM Mono', monospace;
  display: inline-flex;
  align-items: center;
}

.crm-badge-red    { background: var(--crm-red-bg);   color: var(--crm-red-text); border: 1px solid #fecaca; }
.crm-badge-amber  { background: var(--crm-amber-bg); color: var(--crm-amber-text); border: 1px solid #fde68a; }
.crm-badge-green  { background: var(--crm-green-bg); color: var(--crm-green-text); border: 1px solid #bbf7d0; }
.crm-badge-blue   { background: var(--crm-blue-bg);  color: var(--crm-blue-text); border: 1px solid #bfdbfe; }
.crm-badge-gray   { background: #f8fafc; color: var(--crm-text3); border: 1px solid var(--crm-border); }

/* ---- Alert rows ---- */
.crm-alert-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--crm-border);
  cursor: pointer;
  transition: opacity 0.15s;
}

.crm-alert-item:last-child { border-bottom: none; padding-bottom: 0; }
.crm-alert-item:first-child { padding-top: 0; }
.crm-alert-item:hover { opacity: 0.75; }

.crm-alert-name {
  flex: 1;
  font-size: 12px;
  color: var(--crm-text);
}

.crm-alert-meta {
  font-size: 11px;
  color: var(--crm-text3);
  font-family: 'DM Mono', monospace;
}

/* ---- Materials ---- */
.crm-mat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--crm-border);
}

.crm-mat-item:last-child { border-bottom: none; }

.crm-mat-name {
  flex: 1;
  font-size: 12px;
  color: var(--crm-text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-mat-track {
  width: 72px;
  height: 6px;
  background: #f1f5f9;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}

.crm-mat-fill { height: 100%; border-radius: 3px; }

/* ---- Fleet ---- */
.crm-fleet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--crm-border);
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
}

.crm-fleet-item:last-child { border-bottom: none; }
.crm-fleet-item:first-child { padding-top: 0; }
.crm-fleet-item:hover { opacity: 0.75; }

.crm-fleet-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--crm-text3);
  flex-shrink: 0;
}

.crm-fleet-info { flex: 1; }
.crm-fleet-reg { font-size: 12px; font-weight: 600; font-family: 'DM Mono', monospace; color: var(--crm-text); }
.crm-fleet-name { font-size: 11px; color: var(--crm-text3); }

/* ---- Activity feed ---- */
.crm-activity-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--crm-border);
}

.crm-activity-item:last-child { border-bottom: none; padding-bottom: 0; }
.crm-activity-item:first-child { padding-top: 0; }

.crm-act-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

.crm-act-text {
  flex: 1;
  font-size: 12px;
  color: var(--crm-text2);
  line-height: 1.6;
}

.crm-act-text strong {
  color: var(--crm-text);
  font-weight: 600;
}

.crm-act-time {
  font-size: 11px;
  color: var(--crm-text3);
  font-family: 'DM Mono', monospace;
  white-space: nowrap;
  margin-top: 2px;
}

/* ---- Installer workload ---- */
.crm-inst-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--crm-border);
}

.crm-inst-item:last-child { border-bottom: none; }

.crm-inst-av {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.crm-inst-name {
  flex: 1;
  font-size: 12px;
  color: var(--crm-text);
  font-weight: 500;
}

.crm-inst-track {
  width: 72px;
  height: 5px;
  background: #f1f5f9;
  border-radius: 3px;
  overflow: hidden;
}

.crm-inst-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--crm-accent);
}

.crm-inst-count {
  font-size: 11px;
  font-family: 'DM Mono', monospace;
  color: var(--crm-text2);
  width: 38px;
  text-align: right;
}

.crm-hrs-summary {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--crm-border);
}

.crm-hrs-label {
  font-size: 11px;
  color: var(--crm-text3);
  margin-bottom: 4px;
}

.crm-hrs-value {
  font-size: 22px;
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  color: var(--crm-text);
}

.crm-hrs-value span {
  font-size: 12px;
  color: var(--crm-text3);
  font-weight: 400;
}

/* ---- Job types / Doughnut panel ---- */
.crm-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--crm-text2);
  margin-bottom: 5px;
}

.crm-legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}

.crm-legend-pct {
  margin-left: auto;
  font-family: 'DM Mono', monospace;
  font-weight: 600;
  color: var(--crm-text);
}

.crm-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--crm-border);
}

.crm-stat-row:last-child { border-bottom: none; }
.crm-stat-label { font-size: 12px; color: var(--crm-text2); }
.crm-stat-val { font-size: 13px; font-weight: 600; font-family: 'DM Mono', monospace; color: var(--crm-text); }
.crm-stat-val.warn { color: var(--crm-amber-text); }

/* ---- Chart wrapper ---- */
.crm-chart-wrap {
  position: relative;
  width: 100%;
  height: 200px;
}

.crm-chart-legend {
  display: flex;
  align-items: center;
  gap: 16px;
}

.crm-chart-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--crm-text3);
}

.crm-chart-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ---- Live dot ---- */
.crm-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--crm-green);
  display: inline-block;
  position: relative;
}

.crm-live-dot::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid var(--crm-green);
  animation: crmPulse 2s ease infinite;
}

/* ---- Animations ---- */
@keyframes crmFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes crmPulse {
  0%   { transform: scale(0.8); opacity: 0.6; }
  70%  { transform: scale(1.6); opacity: 0; }
  100% { opacity: 0; }
}