:root {
  --bg: #f4f5f7;
  --sidebar-bg: #16181d;
  --sidebar-fg: #c9cbd1;
  --card-bg: #ffffff;
  --border: #e4e6ea;
  --text: #1b1d21;
  --text-muted: #6b7280;
  --accent: #4f6bff;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.logo {
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  letter-spacing: 0.5px;
  padding: 6px 10px 22px;
}
.logo span { color: var(--accent); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--sidebar-fg);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.nav-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 15px; }
.sidebar-footer {
  margin-top: auto;
  font-size: 11px;
  color: #6b7280;
  padding: 10px;
}

/* Content */
.content {
  flex: 1;
  overflow: auto;
  padding: 28px 32px;
}
.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.view-header h1 {
  font-size: 22px;
  margin: 0;
}
.view-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.07); }
.btn.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border);
}

/* Kanban */
.board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 16px;
  align-items: flex-start;
}
.column {
  background: #eceef2;
  border-radius: var(--radius);
  width: 270px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 160px);
}
.column-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 8px;
  font-weight: 600;
  font-size: 13px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.column-count {
  margin-left: auto;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
}
.column-cards {
  padding: 4px 8px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40px;
}
.column-cards.drag-over { background: rgba(79,107,255,0.08); border-radius: 8px; }
.column-add {
  margin: 6px 8px 10px;
}

.card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 12px 12px 10px;
  box-shadow: var(--shadow);
  cursor: grab;
  border: 1px solid transparent;
}
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.4; }
.card-title {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 6px;
  line-height: 1.35;
}
.card-row {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}
.card-amount {
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
  margin-top: 6px;
}
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.chip {
  font-size: 11px;
  background: #f1f2f5;
  border-radius: 20px;
  padding: 3px 9px;
  color: var(--text-muted);
}
.chip.overdue { background: #fde2e2; color: #b42318; }
.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,18,22,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  width: 480px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 14px;
  padding: 22px 22px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal h2 {
  margin: 0 0 16px;
  font-size: 17px;
}
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 60px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.modal-actions-right { display: flex; gap: 8px; }
.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
}
.modal { position: relative; }

/* Tasks inside project modal */
.task-list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.task-item.done { opacity: 0.5; text-decoration: line-through; }
.task-item input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }
.task-item .task-title { flex: 1; }
.task-item .task-due { font-size: 11px; color: var(--text-muted); }
.task-item .task-del {
  background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px;
}
.add-task-row { display: flex; gap: 6px; margin-top: 8px; }
.add-task-row input { flex: 1; }

/* Dashboard */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.dash-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.dash-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dash-empty { color: var(--text-muted); font-size: 13px; padding: 8px 0; }
.dash-task {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.dash-task:last-child { border-bottom: none; }
.dash-task .dt-project { color: var(--text-muted); font-size: 11.5px; }
.stat-row { display: flex; gap: 14px; margin-bottom: 18px; }
.stat-tile {
  flex: 1;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-tile .num { font-size: 24px; font-weight: 700; }
.stat-tile .label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Calendar */
.cal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.cal-title { font-weight: 700; font-size: 15px; min-width: 180px; text-align: center; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-dow {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding-bottom: 4px;
}
.cal-day {
  background: var(--card-bg);
  border-radius: 8px;
  min-height: 86px;
  padding: 6px;
  font-size: 11.5px;
  border: 1px solid var(--border);
}
.cal-day.other-month { opacity: 0.35; }
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cal-daynum { font-weight: 700; font-size: 12px; margin-bottom: 4px; }
.cal-event {
  font-size: 10.5px;
  padding: 2px 5px;
  border-radius: 4px;
  margin-bottom: 2px;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Legend chip (calendar categories) */
.legend { display: flex; gap: 16px; margin-bottom: 14px; font-size: 12.5px; color: var(--text-muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }

/* Property-row detail view (проект / лид) */
.detail-title-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 20px;
  font-weight: 700;
  padding: 4px 0 12px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
}
.prop-list { margin: 4px 0 10px; }
.prop-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.prop-icon { width: 18px; text-align: center; flex-shrink: 0; margin-top: 7px; opacity: 0.8; }
.prop-label {
  width: 150px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 8px;
}
.prop-value { flex: 1; min-width: 0; }
.prop-value input, .prop-value select, .prop-value textarea {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
}
.prop-value input:hover, .prop-value select:hover, .prop-value textarea:hover { background: #f5f6f8; }
.prop-value input:focus, .prop-value select:focus, .prop-value textarea:focus {
  background: #fff;
  border-color: var(--accent);
  outline: none;
}
.prop-value textarea { min-height: 44px; resize: vertical; }
.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 18px 0 8px;
}
.website-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
  margin-top: 4px;
}

/* Analytics */
.month-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.month-nav .cal-title { min-width: 160px; }
.analytics-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; align-items: start; }
.funnel-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.funnel-chart { display: flex; flex-direction: column; gap: 12px; }
.funnel-row { display: flex; align-items: center; gap: 10px; }
.funnel-row .fr-label { width: 110px; font-size: 12.5px; color: var(--text-muted); flex-shrink: 0; }
.funnel-track {
  flex: 1;
  background: #eceef2;
  border-radius: 6px;
  height: 26px;
  overflow: hidden;
  position: relative;
}
.funnel-fill {
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding-left: 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  min-width: 28px;
  box-sizing: border-box;
  transition: width 0.25s ease;
}
.funnel-conv { width: 52px; text-align: right; font-size: 11.5px; color: var(--text-muted); flex-shrink: 0; }
.goal-card { margin-top: 4px; }
.goal-input-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }
.goal-input-row input { width: 160px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13.5px; }
.goal-progress-track {
  background: #eceef2;
  border-radius: 20px;
  height: 16px;
  overflow: hidden;
}
.goal-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #4f6bff);
  border-radius: 20px;
  transition: width 0.25s ease;
}
.goal-caption { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }
.big-num { font-size: 28px; font-weight: 700; }

/* Итоговая конверсия воронки */
.conv-total { display: flex; gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.conv-total .ct-item { flex: 1; text-align: center; background: #f7f8fa; border-radius: 10px; padding: 10px 8px; }
.conv-total .ct-num { font-size: 20px; font-weight: 700; color: var(--accent); }
.conv-total .ct-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Платежи по проекту (учёт оплаты по этапам) */
.payments-total { font-size: 13.5px; font-weight: 700; margin-bottom: 8px; }
.payment-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.payment-item .payment-date { color: var(--text-muted); font-size: 11.5px; width: 78px; flex-shrink: 0; }
.payment-item .payment-amount { flex: 1; font-weight: 600; }
.payment-item .payment-del { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; }
.add-payment-row { display: flex; gap: 6px; margin-top: 8px; }
.add-payment-row input[type="date"] { max-width: 150px; }
.add-payment-row input[type="number"] { flex: 1; }

/* Источники заявок */
.source-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.source-table th, .source-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
.source-table th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; }
.source-table th.num, .source-table td.num { text-align: right; }
.add-source-row { display: flex; gap: 6px; margin-top: 12px; }
.add-source-row input { flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; }
.source-chip { display: inline-block; font-size: 10.5px; background: #eef1ff; color: var(--accent); border-radius: 20px; padding: 2px 8px; margin-top: 4px; }

/* Быстрое назначение источника прямо на вкладке "Аналитика" */
.assign-source-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.assign-source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.assign-source-row .asr-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assign-source-row select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 12.5px; max-width: 200px; }

/* Toast */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #16181d;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 200;
}
#toast.show { opacity: 1; }

/* ---------- Авторизация ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
  z-index: 500;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 26px;
}
.auth-logo {
  font-weight: 700;
  font-size: 19px;
  color: var(--text);
  letter-spacing: 0.5px;
  text-align: center;
  margin-bottom: 20px;
}
.auth-logo span { color: var(--accent); }
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 18px;
}
.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}
.auth-tab.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.auth-input {
  font: inherit;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
}
.auth-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.auth-error {
  background: #fef2f2;
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
}
.auth-submit {
  margin-top: 4px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 11px;
  border-radius: 8px;
  cursor: pointer;
}
.auth-submit:disabled { opacity: 0.6; cursor: default; }
.auth-hint { margin-top: 14px; font-size: 11.5px; color: var(--text-muted); text-align: center; }

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px 2px;
}
.user-badge .avatar { flex-shrink: 0; }
.user-badge .user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  color: var(--sidebar-fg);
}
.logout-btn {
  border: none;
  background: transparent;
  color: var(--sidebar-fg);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
}
.logout-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
