:root {
  --bg: #f8f9fb;
  --bg2: #ffffff;
  --bg3: #f1f3f5;
  --bg4: #e9ecef;
  --border: #dee2e6;
  --text: #212529;
  --text2: #495057;
  --text3: #868e96;
  --accent: #2563eb;
  --accent2: #1d4ed8;
  --green: #059669;
  --green-bg: #d1fae5;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --orange: #d97706;
  --orange-bg: #fef3c7;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --pink: #db2777;
  --pink-bg: #fce7f3;
  --cyan: #0891b2;
  --cyan-bg: #cffafe;
  --blue-bg: #dbeafe;
  --gray-bg: #f1f3f5;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

#app { display: flex; height: 100vh; }

#sidebar {
  width: 250px;
  min-width: 250px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  z-index: 10;
}

.sidebar-logo {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
}

.sidebar-logo h1 { font-size: 16px; font-weight: 700; color: var(--text); }
.sidebar-logo small { font-size: 11px; color: var(--text3); display: block; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

.nav-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text3);
  padding: 16px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text2);
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }

.nav-item .icon { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; }
.nav-item .icon svg { width: 18px; height: 18px; }
.nav-item.active .icon svg { stroke: #fff; }

.nav-item .badge {
  margin-left: auto;
  background: var(--bg4);
  color: var(--text3);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
}

.nav-item.active .badge { background: rgba(255,255,255,0.25); color: #fff; }

#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#topbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
}

#topbar h2 { font-size: 18px; font-weight: 600; }
#topbar .actions { display: flex; gap: 8px; }

.btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover { background: var(--bg3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }

#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: 60px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-card .label { font-size: 12px; color: var(--text3); margin-bottom: 4px; font-weight: 500; }
.stat-card .value { font-size: 24px; font-weight: 700; color: var(--text); }
.stat-card .sub { font-size: 12px; color: var(--text3); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 24px; }

.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-card h3 .chart-subtitle { font-size: 12px; color: var(--text3); font-weight: 400; }

.pipeline-board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; min-height: 400px; }

.pipeline-col {
  min-width: 210px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}

.pipeline-col-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
}

.pipeline-col-header .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.pipeline-col-header .count { font-size: 10px; color: var(--text3); font-weight: 400; }

.pipeline-col-body { flex: 1; overflow-y: auto; padding: 6px; }

.pipeline-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 5px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}

.pipeline-card:hover { border-color: var(--accent); box-shadow: 0 2px 6px rgba(37,99,235,0.12); }
.pipeline-card .deal-name { font-size: 12px; font-weight: 600; margin-bottom: 3px; color: var(--text); }
.pipeline-card .deal-company { font-size: 11px; color: var(--text3); margin-bottom: 5px; }
.pipeline-card .deal-footer { display: flex; justify-content: space-between; align-items: center; }
.pipeline-card .deal-value { font-size: 12px; font-weight: 700; color: var(--green); }
.pipeline-card .deal-source { font-size: 10px; color: var(--text3); background: var(--bg4); padding: 1px 5px; border-radius: 3px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}

.data-table td { padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); color: var(--text2); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }
.data-table .primary { color: var(--text); font-weight: 600; }

.tag { display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 4px; margin: 1px 2px; font-weight: 600; }
.tag-klient-aktywny { background: #d1fae5; color: #065f46; }
.tag-przetarg { background: #fef3c7; color: #92400e; }
.tag-specyfikacja-BHP { background: #ede9fe; color: #5b21b6; }
.tag-projekt-2025 { background: #dbeafe; color: #1e40af; }
.tag-referencja { background: #fce7f3; color: #9d174d; }

.stage-badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.role-badge { display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.role-decydent { background: #fef3c7; color: #92400e; }
.role-wpływający { background: #f1f3f5; color: #495057; }

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

.modal h3 { font-size: 18px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }
.modal h3 .close-btn { background: none; border: none; color: var(--text3); font-size: 20px; cursor: pointer; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-field label { font-size: 11px; color: var(--text3); display: block; }
.detail-field .val { font-size: 14px; color: var(--text); font-weight: 500; }

.detail-section { margin-bottom: 20px; }
.detail-section h4 { font-size: 13px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }

.timeline { list-style: none; }
.timeline-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }

.timeline-icon {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.timeline-icon svg { width: 16px; height: 16px; }
.timeline-icon.wizyta { background: var(--blue-bg); color: var(--accent); }
.timeline-icon.telefon { background: var(--green-bg); color: var(--green); }
.timeline-icon.email { background: var(--purple-bg); color: var(--purple); }
.timeline-icon.oferta { background: var(--orange-bg); color: var(--orange); }
.timeline-icon.zadanie { background: var(--orange-bg); color: var(--orange); }
.timeline-icon.notatka { background: var(--gray-bg); color: var(--text3); }

.timeline-body { flex: 1; }
.timeline-body .tl-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; color: var(--text); }
.timeline-body .tl-meta { font-size: 11px; color: var(--text3); }
.timeline-body .tl-desc { font-size: 12px; color: var(--text2); margin-top: 4px; }

.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar select, .filter-bar input { padding: 6px 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; }
.search-input { flex: 1; min-width: 200px; }

.link { color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

.alert-badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 3px; text-transform: uppercase; }
.alert-badge.red { background: var(--red-bg); color: var(--red); }
.alert-badge.orange { background: var(--orange-bg); color: var(--orange); }
.alert-badge.green { background: var(--green-bg); color: var(--green); }

.service-ticket { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin-bottom: 6px; }
.service-ticket .st-status { font-size: 10px; font-weight: 700; text-transform: uppercase; }

.upsell-card { background: var(--pink-bg); border: 1px solid rgba(219,39,119,0.2); border-radius: 6px; padding: 12px; margin-bottom: 8px; }
.upsell-card .uc-label { font-size: 11px; color: var(--pink); font-weight: 700; text-transform: uppercase; margin-bottom: 4px; }
.upsell-card .uc-note { font-size: 13px; color: var(--text2); }

.funnel-step { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.funnel-bar-wrap { flex: 1; }
.funnel-bar { height: 28px; border-radius: 4px; display: flex; align-items: center; padding: 0 10px; font-size: 12px; font-weight: 600; color: #fff; transition: width 0.6s ease; }
.funnel-label { width: 120px; font-size: 12px; font-weight: 600; color: var(--text2); text-align: right; }
.funnel-count { width: 80px; font-size: 12px; color: var(--text3); text-align: right; }
.funnel-conv { width: 60px; font-size: 11px; font-weight: 600; text-align: right; }

.rep-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 20px;
  margin-bottom: 12px;
}

.rep-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.rep-info { flex: 1; }
.rep-info h3 { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.rep-info .rep-role { font-size: 12px; color: var(--text3); margin-bottom: 8px; }
.rep-info .rep-region { font-size: 11px; color: var(--text3); margin-bottom: 12px; }

.rep-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.rep-stat-label { font-size: 10px; color: var(--text3); text-transform: uppercase; font-weight: 600; }
.rep-stat-value { font-size: 16px; font-weight: 700; color: var(--text); }

.quota-bar-wrap { background: var(--bg4); border-radius: 4px; height: 8px; overflow: hidden; }
.quota-bar { height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.quota-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text3); margin-top: 4px; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.calendar-header { background: var(--bg3); padding: 8px 4px; text-align: center; font-size: 11px; font-weight: 700; color: var(--text3); text-transform: uppercase; }
.calendar-day { background: var(--bg2); min-height: 80px; padding: 4px 6px; }
.calendar-day.today { background: var(--blue-bg); }
.calendar-day .day-num { font-size: 11px; font-weight: 600; color: var(--text3); margin-bottom: 3px; }
.calendar-day.today .day-num { color: var(--accent); font-weight: 800; }
.cal-event { font-size: 10px; padding: 2px 4px; border-radius: 3px; margin-bottom: 2px; font-weight: 600; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event.wizyta { background: var(--blue-bg); color: var(--accent); }
.cal-event.telefon { background: var(--green-bg); color: var(--green); }
.cal-event.email { background: var(--purple-bg); color: var(--purple); }
.cal-event.oferta { background: var(--orange-bg); color: var(--orange); }
.cal-event.zadanie { background: #fef3c7; color: #92400e; }
.cal-event.notatka { background: var(--gray-bg); color: var(--text3); }

.leaderboard-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.leaderboard-item:last-child { border-bottom: none; }
.leaderboard-rank { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; flex-shrink: 0; }
.leaderboard-rank.gold { background: #fef3c7; color: #92400e; }
.leaderboard-rank.silver { background: #e9ecef; color: #495057; }
.leaderboard-rank.bronze { background: #fde2c8; color: #9a3412; }
.leaderboard-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); }
.leaderboard-value { font-size: 14px; font-weight: 700; color: var(--green); }

.source-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.source-label { width: 100px; font-size: 12px; font-weight: 600; color: var(--text2); text-align: right; }
.source-bar-wrap { flex: 1; background: var(--bg4); border-radius: 4px; height: 24px; overflow: hidden; }
.source-bar { height: 100%; border-radius: 4px; display: flex; align-items: center; padding: 0 8px; font-size: 11px; font-weight: 600; color: #fff; transition: width 0.6s ease; }
.source-count { width: 30px; font-size: 12px; color: var(--text3); text-align: right; }

.product-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.product-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.product-name { width: 160px; font-size: 12px; color: var(--text2); }
.product-bar-wrap { flex: 1; background: var(--bg4); border-radius: 3px; height: 18px; overflow: hidden; }
.product-bar { height: 100%; border-radius: 3px; transition: width 0.6s ease; }
.product-count { width: 40px; font-size: 12px; color: var(--text3); text-align: right; }

.mini-chart { display: flex; align-items: flex-end; gap: 2px; height: 40px; }
.mini-chart .bar { width: 6px; border-radius: 2px; transition: height 0.3s ease; }

.notifications-panel { z-index: 1001; }
.notifications-panel:hover { box-shadow: -4px 4px 30px rgba(0,0,0,0.15); }

.notification-dot { width: 8px; height: 8px; border-radius: 50%; position: absolute; top: -2px; right: -2px; }

.health-good { color: var(--green); }
.health-warn { color: var(--orange); }
.health-bad { color: var(--red); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
