:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e2230;
  --border: #2a2f3f;
  --text: #e7e9ee;
  --text-dim: #9aa1b2;
  --accent: #6366f1;
  --danger: #ef4444;
  --radius: 10px;

  --status-backlog: #8b5cf6;
  --status-backlog-tint: rgba(139, 92, 246, 0.18);
  --status-todo: #64748b;
  --status-todo-tint: rgba(100, 116, 139, 0.18);
  --status-in_progress: #3b82f6;
  --status-in_progress-tint: rgba(59, 130, 246, 0.18);
  --status-on_hold: #f59e0b;
  --status-on_hold-tint: rgba(245, 158, 11, 0.18);
  --status-done: #22c55e;
  --status-done-tint: rgba(34, 197, 94, 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Login */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0 0 8px; font-size: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  font-size: 14px;
}
.error { color: var(--danger); font-size: 13px; margin: 0; }

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  border-radius: 6px;
  font-size: 14px;
}
.btn-primary { background: var(--accent); color: white; padding: 10px 16px; }
.btn-primary:hover { opacity: 0.9; }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); padding: 9px 14px; }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 9px 14px; margin-right: auto; }
.btn-icon { background: var(--panel-2); color: var(--text); width: 28px; height: 28px; border-radius: 6px; font-size: 16px; }

/* App shell */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-dim); }

.topbar-nav { display: flex; align-items: center; gap: 4px; margin-left: 24px; margin-right: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.topbar-nav-item {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.topbar-nav-item:hover { color: var(--text); }
.topbar-nav-item.active { color: #fff; background: var(--accent); box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35); }

.project-filter-wrap { position: relative; }
.project-filter-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.project-filter-btn:hover { border-color: var(--accent); }
.project-filter-btn::after { content: '▾'; font-size: 10px; color: var(--text-dim); }
.project-filter-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 8px;
  z-index: 20;
}
.project-filter-options { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.project-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.project-filter-option:hover { background: var(--panel-2); }
.project-filter-option:has(input:checked) { background: var(--panel-2); }
.project-filter-option input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
.project-filter-option .project-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.project-filter-option .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-filter-option .project-edit-btn { opacity: 0; background: none; color: var(--text-dim); font-size: 12px; }
.project-filter-option:hover .project-edit-btn { opacity: 1; }
.project-filter-empty { padding: 10px 8px; font-size: 13px; color: var(--text-dim); }
.project-filter-actions { display: flex; gap: 6px; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.btn-ghost-small { background: transparent; color: var(--text-dim); border: none; padding: 6px 8px; font-size: 12px; }
.btn-ghost-small:hover { color: var(--text); }

.board-wrap { flex: 1; padding: 20px 24px; overflow: auto; display: flex; flex-direction: column; min-width: 0; }
.board-header { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 16px; }
.board-header h2 { margin: 0; font-size: 18px; margin-right: auto; }

.board-search-wrap { flex: 0 1 300px; }
#board-search {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
#board-search:focus { outline: none; border-color: var(--accent); }
#board-search::placeholder { color: var(--text-dim); }

/* Funnel overview */
.board-funnel { display: flex; align-items: stretch; height: 38px; border-radius: 8px; overflow: hidden; margin-bottom: 18px; gap: 2px; }
.board-funnel-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 12px;
  min-width: 44px;
  cursor: pointer;
  border-radius: 6px;
  transition: filter 0.15s ease, transform 0.15s ease;
}
.board-funnel-segment:hover { filter: brightness(1.15); transform: translateY(-1px); }

.badge-project { display: inline-flex; align-items: center; gap: 4px; background: var(--panel); border-radius: 999px; padding: 2px 8px 2px 6px; }
.badge-project .project-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.empty-hint { color: var(--text-dim); font-size: 14px; }

.board { display: flex; gap: 16px; flex: 1; align-items: flex-start; overflow-x: auto; padding-bottom: 4px; }
.board::-webkit-scrollbar { height: 8px; }
.board::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.column[data-status="backlog"] { --status-color: var(--status-backlog); --status-tint: var(--status-backlog-tint); }
.column[data-status="todo"] { --status-color: var(--status-todo); --status-tint: var(--status-todo-tint); }
.column[data-status="in_progress"] { --status-color: var(--status-in_progress); --status-tint: var(--status-in_progress-tint); }
.column[data-status="on_hold"] { --status-color: var(--status-on_hold); --status-tint: var(--status-on_hold-tint); }
.column[data-status="done"] { --status-color: var(--status-done); --status-tint: var(--status-done-tint); }

.column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--status-color);
  border-radius: var(--radius);
  flex: 1 1 260px;
  min-width: 260px;
  max-width: 360px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
}
.column-head { display: flex; align-items: center; justify-content: space-between; }
.column-head-title { display: flex; align-items: center; gap: 8px; }
.column-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status-color); box-shadow: 0 0 0 3px var(--status-tint); flex-shrink: 0; }
.column h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.column-head-actions { display: flex; align-items: center; gap: 6px; }
.column-count {
  background: var(--status-tint);
  color: var(--status-color);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}
.column-add-btn {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.column-add-btn:hover { color: var(--status-color); border-color: var(--status-color); }

.column-cards { display: flex; flex-direction: column; gap: 8px; min-height: 40px; flex: 1; max-height: calc(100vh - 300px); overflow-y: auto; padding-right: 2px; }
.column-cards::-webkit-scrollbar { width: 6px; }
.column-cards::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.column-cards.drag-over { background: var(--panel-2); border-radius: 8px; }

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  font-size: 13px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35); }
.card:active { cursor: grabbing; }
.card-title { font-weight: 600; margin-bottom: 6px; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--text-dim); }
.badge { padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border); }
.badge-priority-low { color: #4ade80; border-color: #4ade8055; background: rgba(74, 222, 128, 0.08); }
.badge-priority-medium { color: #facc15; border-color: #facc1555; background: rgba(250, 204, 21, 0.08); }
.badge-priority-high { color: #f87171; border-color: #f8717155; background: rgba(248, 113, 113, 0.08); }
.badge-overdue { color: #f87171; border-color: #f8717155; background: rgba(248, 113, 113, 0.12); font-weight: 700; }

/* Roadmap */
.roadmap-view { display: flex; flex-direction: column; gap: 20px; max-width: 860px; }
.roadmap-phase { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.roadmap-phase-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.roadmap-phase-header h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.roadmap-progress { font-size: 12px; color: var(--text-dim); border: 1px solid var(--border); border-radius: 10px; padding: 2px 8px; }
.roadmap-items { display: flex; flex-direction: column; gap: 8px; }
.roadmap-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
}
.roadmap-item:hover { border-color: var(--accent); }
.roadmap-item.done { opacity: 0.55; }
.roadmap-item.done .roadmap-item-title { text-decoration: line-through; }
.roadmap-check { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.roadmap-item-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.roadmap-item-title { font-weight: 600; font-size: 14px; }
.roadmap-item-descr { font-size: 13px; color: var(--text-dim); line-height: 1.45; white-space: pre-line; }

/* Marketing */
.marketing-view { display: flex; flex-direction: column; gap: 20px; max-width: 960px; }
.marketing-subnav { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 3px; width: fit-content; }
.marketing-subnav-item { background: transparent; color: var(--text-dim); border: 1px solid transparent; padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 500; }
.marketing-subnav-item:hover { color: var(--text); }
.marketing-subnav-item.active { color: #fff; background: var(--accent); }
.marketing-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.marketing-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.marketing-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.marketing-card-head h3 { margin: 0; font-size: 14px; }
.marketing-card-row { font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.marketing-card-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); opacity: 0.7; margin-bottom: 2px; }
.marketing-status-done { color: #4ade80; border-color: #4ade8055; background: rgba(74, 222, 128, 0.08); }
.marketing-status-planned { color: #facc15; border-color: #facc1555; background: rgba(250, 204, 21, 0.08); }

/* Image generation panel */
.images-panel { display: flex; flex-direction: column; gap: 16px; max-width: 1400px; }
.images-header { display: flex; flex-wrap: wrap; gap: 24px; font-size: 13px; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.images-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.images-stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.images-stat-value { font-size: 20px; font-weight: 700; color: #fff; }
.images-stat-label { font-size: 12px; color: var(--text-dim); }
.images-stat-note { font-size: 12px; color: var(--text-dim); opacity: 0.75; }
.images-section-title { margin: 4px 0 -4px; font-size: 14px; }
.images-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.images-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.images-table th, .images-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.images-table th { color: var(--text-dim); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; background: var(--panel); }
.images-table tr:last-child td { border-bottom: none; }
.images-row-active td:first-child { color: #fff; font-weight: 600; }
.images-muted { color: var(--text-dim); opacity: 0.75; font-size: 12px; }
.images-hint { margin: -6px 0 0; }

.social-matrix td.social-cell { min-width: 110px; padding: 0; }
.social-cell-status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.social-cell-empty { cursor: pointer; padding: 8px 10px; }
.social-cell-empty:hover { background: var(--panel-2); }
.social-cell-filled .images-muted a { color: var(--text-dim); }
.social-cell-entry { cursor: pointer; padding: 8px 10px; }
.social-cell-entry:hover { background: var(--panel-2); }
.social-cell-entry + .social-cell-entry { border-top: 1px solid var(--border); }

.social-section-row td { background: var(--panel); color: var(--text-dim); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; }
.social-row-done td { background: rgba(34, 197, 94, 0.16); }
.social-row-done:hover td { background: rgba(34, 197, 94, 0.24); }
.social-row-done .social-cell-empty:hover, .social-row-done .social-cell-entry:hover { background: rgba(34, 197, 94, 0.28); }

/* Analytics dashboard */
.analytics-filter-bar { display: flex; gap: 6px; }
.analytics-filter-btn { background: var(--panel-2); color: var(--text-dim); border: 1px solid var(--border); padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 500; cursor: pointer; }
.analytics-filter-btn:hover { color: var(--text); }
.analytics-filter-btn.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.analytics-stat-head { display: flex; align-items: center; gap: 6px; }
.analytics-stat-icon { color: var(--accent); flex-shrink: 0; }
.analytics-chart-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; height: 260px; }
.analytics-chart-card canvas { width: 100% !important; height: 100% !important; }
.images-questions { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-dim); line-height: 1.6; }

/* Channel posts */
.post-item { align-items: stretch; }
.post-text { max-height: 120px; overflow: hidden; }
.post-actions { display: flex; align-items: center; flex-shrink: 0; }
.post-actions .btn-primary { padding: 8px 12px; font-size: 13px; }
.post-status-draft { color: #facc15; border-color: #facc1555; }
.post-status-published { color: #4ade80; border-color: #4ade8055; }
.post-status-failed { color: #f87171; border-color: #f8717155; }

/* Modal */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  width: 420px;
  max-width: 90vw;
}
.modal-wide { width: 640px; }
.modal::backdrop { background: rgba(0,0,0,0.6); }
.modal-form { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-form h2 { margin: 0 0 4px; font-size: 18px; }
.modal-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.modal-form input, .modal-form textarea, .modal-form select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.field-row { display: flex; gap: 10px; }
.field-row label { flex: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

.task-extra { display: flex; gap: 20px; margin-top: 10px; padding-top: 16px; border-top: 1px solid var(--border); }
.task-extra-col { flex: 1; min-width: 0; }
.task-extra-col h3 { font-size: 12px; text-transform: uppercase; color: var(--text-dim); margin: 0 0 8px; }
.comment-list, .history-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow-y: auto; font-size: 13px; }
.comment-list li { background: var(--panel-2); border-radius: 6px; padding: 6px 8px; }
.comment-list .comment-time, .history-list .history-time { display: block; font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.history-list li { color: var(--text-dim); }
.comment-add { display: flex; gap: 6px; }
.comment-add input { flex: 1; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px; color: var(--text); }

/* --- Telegram (personal account) --- */
.telegram-view {
  height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
}

.tg-auth-panel {
  max-width: 420px;
  margin: auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.tg-auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tg-auth-form input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 6px;
  width: 100%;
}

.tg-auth-hint {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 16px;
}

.tg-chat-panel {
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  display: flex;
}

.tg-sidebar {
  width: 300px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.tg-sidebar-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tg-sync-status {
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 16px;
}

.tg-chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.tg-chat-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.tg-chat-item:hover {
  background: var(--panel-2);
}

.tg-chat-item.active {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.tg-chat-item-title {
  display: flex;
  gap: 6px;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-chat-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.tg-chat-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.tg-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.tg-thread-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tg-thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tg-thread-empty {
  margin: auto;
  color: var(--text-dim);
  font-size: 13px;
}

.tg-message {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  align-self: flex-start;
  word-break: break-word;
}

.tg-message-out {
  align-self: flex-end;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.tg-message-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.tg-message-text {
  font-size: 14px;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.4;
}

.tg-message-time {
  display: block;
  text-align: right;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

.tg-media-photo {
  max-width: 260px;
  border-radius: 8px;
  display: block;
  margin-top: 4px;
}

.tg-media-file {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--accent);
  margin-top: 4px;
  text-decoration: none;
}

.tg-media-missing {
  font-size: 12px;
  color: var(--text-dim);
}

.tg-send-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.tg-send-form input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 6px;
}

@media (max-width: 768px) {
  .tg-chat-panel {
    flex-direction: column;
  }

  .tg-sidebar {
    width: 100%;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .tg-message, .tg-message-out {
    max-width: 85%;
  }
}
.tg-account-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.tg-account-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tg-account-tab { background: var(--panel); border: 1px solid var(--border); color: var(--text-dim); padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.tg-account-tab:hover { color: var(--text); }
.tg-account-tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }

.tg-search-input { margin: 0 12px 8px; padding: 8px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; }
.tg-search-input:focus { outline: none; border-color: var(--accent); }
.tg-chat-filters { display: flex; gap: 4px; padding: 0 12px 8px; flex-wrap: wrap; }
.tg-chat-filter { background: transparent; border: 1px solid var(--border); color: var(--text-dim); padding: 4px 10px; border-radius: 999px; font-size: 12px; cursor: pointer; }
.tg-chat-filter:hover { color: var(--text); }
.tg-chat-filter.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.tg-chat-item { display: flex; align-items: center; gap: 10px; }
.tg-chat-item-body { flex: 1; min-width: 0; }
.tg-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.tg-avatar-fallback { display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; }
.tg-avatar-small { width: 20px; height: 20px; vertical-align: middle; margin-right: 4px; }
.tg-thread-head { gap: 10px; }
.tg-thread-head .tg-avatar { width: 32px; height: 32px; }

.tg-media-download { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; background: var(--panel); border: 1px solid var(--border); color: var(--accent); padding: 5px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.tg-media-download:hover { border-color: var(--accent); }
.tg-media-download:disabled { opacity: 0.6; cursor: default; }

.tg-attached-file { padding: 6px 14px; font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.tg-inline-keyboard { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.tg-inline-keyboard-row { display: flex; gap: 4px; }
.tg-inline-btn { flex: 1; background: var(--panel); border: 1px solid var(--border); color: var(--accent); padding: 6px 10px; border-radius: 6px; font-size: 12px; text-align: center; cursor: pointer; text-decoration: none; }
.tg-inline-btn:hover { border-color: var(--accent); }
.tg-inline-btn:disabled { opacity: 0.6; cursor: default; }

.tg-pinned-keyboard { padding: 8px 14px 0; margin-top: 0; }
.tg-pinned-keyboard .tg-inline-keyboard-row { margin-bottom: 4px; }

.tg-menu-btn { color: var(--accent); font-weight: 600; }

/* --- CRM: бейдж этапа в списке чатов и панель лида в шапке диалога --- */
.crm-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 17px;
  white-space: nowrap;
  color: #fff;
  background: var(--crm-color, #6366f1);
}

/* Метка «переписка оседает в базе». Приглушённая: это состояние, а не
   предупреждение, и рядом с бейджем этапа она не должна перетягивать взгляд. */
.badge-keep {
  color: #6ee7b7;
  border: 1px solid rgba(110, 231, 183, 0.4);
  background: rgba(110, 231, 183, 0.12);
}

/* Переключатель в шапке диалога. Выключенное состояние — нейтральное, потому
   что «не хранить» здесь норма по умолчанию, а не проблема. */
.keep-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  line-height: 18px;
  white-space: nowrap;
  cursor: pointer;
}

.keep-toggle:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-dim);
}

.keep-toggle:disabled {
  opacity: 0.6;
  cursor: default;
}

.keep-toggle.is-on {
  color: #6ee7b7;
  border-color: rgba(110, 231, 183, 0.5);
  background: rgba(110, 231, 183, 0.12);
}

/* Чат клиента: флаг стоит из-за привязки к карточке, снять его здесь нельзя —
   поэтому не кнопка, а подпись. */
.keep-toggle.is-auto {
  cursor: default;
  color: #6ee7b7;
  border-color: rgba(110, 231, 183, 0.5);
  background: rgba(110, 231, 183, 0.12);
}

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

.crm-stage-select,
.crm-next-action {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line, #2a2f3a);
  background: var(--surface, #171a21);
  color: inherit;
  font-size: 13px;
}

.crm-bar-status {
  font-size: 12px;
  opacity: 0.75;
}

.crm-bar-status.ok { color: #22c55e; }
.crm-bar-status.err { color: #ef4444; opacity: 1; }

/* --- Лиды -------------------------------------------------------------- */
/* Раздел рассчитан на телефон: одна колонка, крупные цели для пальца,
   карточка сделки раскрывается на весь экран. */

.leads-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 0 40px;
}

.leads-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.leads-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.leads-filter {
  border: 1px solid var(--border, #2a2a3c);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.leads-filter.active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}

.leads-empty {
  opacity: 0.7;
  padding: 24px 4px;
}

/* Предупреждение об отставшем синке. Янтарный, а не красный: работать можно,
   но списку доверять на сто процентов нельзя. */
.leads-stale {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: rgba(245, 158, 11, 0.1);
  color: #fbbf24;
  font-size: 13px;
  line-height: 1.45;
}

.leads-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-card {
  border: 1px solid var(--border, #2a2a3c);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  background: var(--card, rgba(255, 255, 255, 0.03));
}

.lead-card:hover { border-color: #6366f1; }

/* Просроченные отбиты слева полосой, а не цветом фона: на телефоне при ярком
   солнце заливка теряется, полоса видна всегда. */
.lead-card-overdue { border-left: 4px solid #ef4444; }

.lead-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.lead-stage {
  color: #fff;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}

.lead-age { font-size: 12px; opacity: 0.6; }

.lead-title { margin: 0 0 6px; font-size: 17px; }

.lead-meta { margin: 0; font-size: 14px; opacity: 0.75; }
.lead-meta-overdue { color: #f87171; opacity: 1; }

.lead-note { margin: 6px 0 0; font-size: 14px; opacity: 0.8; }

.lead-gap {
  margin: 8px 0 0;
  font-size: 13px;
  color: #fbbf24;
}

.deal-sheet {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 20, 0.72);
  z-index: 60;
  overflow-y: auto;
  padding: 24px 16px;
}

.deal-sheet-inner {
  box-sizing: border-box;
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg, #14131f);
  border: 1px solid var(--border, #2a2a3c);
  border-radius: 16px;
  padding: 20px;
}

.deal-sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.deal-sheet-head h2 { margin: 0; font-size: 20px; }
.deal-sheet-sub { margin: 4px 0 0; font-size: 13px; opacity: 0.7; }

.deal-sheet-body { display: flex; flex-direction: column; gap: 14px; }

.deal-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  /* В колонке карточки поля не должны тянуться по высоте: flex-grow здесь
     раздувал каждое поле на треть экрана. Растягиваются они только внутри
     .deal-row, где стоят парами. */
  flex: 0 0 auto;
}

.deal-row .deal-field { flex: 1 1 220px; }
.deal-field span { font-size: 13px; opacity: 0.7; }

.deal-field input,
.deal-field select,
.deal-sheet-body textarea,
.deal-actions input,
.deal-template {
  /* Без border-box ширина 100% складывается с полями и выносит поле за край. */
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border, #2a2a3c);
  border-radius: 10px;
  padding: 10px 12px;
  color: inherit;
  font: inherit;
  font-size: 15px;   /* меньше 16px — iOS зумит страницу при фокусе */
  width: 100%;
}

.deal-row { display: flex; flex-wrap: wrap; gap: 12px; }

.deal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.deal-actions input { flex: 1 1 160px; width: auto; }

.deal-block {
  border-top: 1px solid var(--border, #2a2a3c);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.deal-block h3 { margin: 0; font-size: 15px; opacity: 0.8; }

.deal-msg { margin: 0; font-size: 13px; opacity: 0.75; }
.deal-msg-error { color: #f87171; opacity: 1; }

.deal-tasks { display: flex; flex-direction: column; gap: 8px; }

.deal-task {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}

.deal-task em { margin-left: auto; font-size: 12px; opacity: 0.6; font-style: normal; }
.deal-task-done span { opacity: 0.45; text-decoration: line-through; }

.deal-activities {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

.deal-activities span { opacity: 0.5; font-size: 12px; margin-right: 6px; }

@media (max-width: 640px) {
  .deal-sheet { padding: 0; }
  .deal-sheet-inner {
    min-height: 100%;
    border: 0;
    border-radius: 0;
    padding: 16px;
  }
  .leads-toolbar { flex-direction: column; align-items: stretch; }
}

/* --- Раздел «Лиды»: список слева, памятка справа ----------------------- */
/* Раньше список был одной колонкой по центру, и на мониторе две трети
   экрана пустовали. Памятка занимает это место: порядок работы и тексты
   сообщений всегда на виду, а не в документации, куда никто не заглядывает
   в момент разговора с клиентом. */

.leads-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (min-width: 1000px) {
  .leads-view { max-width: 1120px; }
  .leads-layout { grid-template-columns: minmax(0, 1fr) 340px; }
  .leads-guide {
    position: sticky;
    top: 16px;           /* прокручивая длинный список, памятку не теряем */
    max-height: calc(100vh - 32px);
    overflow-y: auto;
  }
}

.leads-guide {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.guide-block {
  border: 1px solid var(--border, #2a2a3c);
  border-radius: 14px;
  padding: 16px;
  background: var(--card, rgba(255, 255, 255, 0.03));
}

.guide-block h3 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
  opacity: .65;
}

.guide-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guide-step {
  display: flex;
  gap: 10px;
  font-size: 14px;
  line-height: 1.4;
}

.guide-step-num {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.guide-step b { display: block; }

.guide-step-action {
  display: block;
  opacity: .8;
}

.guide-step-hint {
  display: block;
  font-size: 13px;
  opacity: .55;
}

/* Шаг с гейтом выделен: именно его пропускали во всех живых диалогах. */
.guide-step-gate .guide-step-action { color: #fbbf24; opacity: 1; }

.guide-step-gate-note {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: #fbbf24;
  opacity: .8;
}

.guide-finals {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border, #2a2a3c);
  font-size: 13px;
  opacity: .7;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.guide-templates { display: flex; flex-direction: column; gap: 8px; }

.guide-tpl {
  border: 1px solid var(--border, #2a2a3c);
  border-radius: 10px;
  padding: 10px 12px;
}

.guide-tpl summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  min-height: 24px;
}

.guide-tpl-body {
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.5;
  opacity: .8;
}

/* Переключатель языка шаблонов. Сегменты, а не выпадающий список: вариантов
   всего два, и видно сразу, на каком языке сейчас тексты. */
.tpl-lang {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}

.tpl-lang-btn {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 500;
  min-height: 36px;
}

.tpl-lang-btn:hover { color: var(--text); }
.tpl-lang-btn.active { background: var(--accent); color: #fff; }

/* Счётчик вариантов у названия группы: видно, что внутри их несколько, ещё
   до раскрытия. */
.guide-tpl-count {
  float: right;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.tpl-variants {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  counter-reset: tpl;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tpl-variants li {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.tpl-variants li:first-child { border-top: 0; padding-top: 0; }

/* Номер варианта — чтобы в разговоре с собой («отправил второй») было к чему
   привязаться, и чтобы не отправить дважды один и тот же текст. */
.tpl-variants li::before {
  counter-increment: tpl;
  content: counter(tpl);
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
}

.tpl-variants .guide-tpl-body { margin: 0 0 8px; }

/* Выпадашка шаблонов в карточке: 70 текстов в одном списке читаются только
   группами, а на телефоне ещё и должны влезать по ширине. */
.deal-template { max-width: 100%; }
.deal-template optgroup { font-size: 13px; }

/* Следующее действие прямо на карточке — чтобы не открывать её ради того,
   чтобы вспомнить, что делать. */
.lead-next {
  margin: 8px 0 0;
  font-size: 13px;
  opacity: .7;
}

/* --- Мобильная раскладка ------------------------------------------------
   Панель открывают с телефона, чтобы пройти по лидам между делами, — это
   основной сценарий, а не запасной. До этого блока шапка была нерастяжимой
   строкой (заголовок + 5 кнопок + фильтр + выход) шириной 775px: на экране
   412px документ уезжал вправо, и правый край всех экранов обрезался.
   Лечим причину — шапку, а не симптом через overflow-x: hidden. */

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 10px 14px;
  }

  /* Заголовок съёживается первым и режется многоточием: он опознавательный,
     а не рабочий элемент. */
  /* flex-basis: 0 — не «auto»: при переносе строк браузер измеряет базовый
     размер, и заголовок шириной со свой текст сталкивал кнопку «Выйти» на
     отдельную строку. С нулевой базой он занимает только остаток места. */
  .topbar h1 {
    flex: 1 1 0;
    min-width: 0;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .project-filter-wrap { order: 2; }
  .topbar-right { order: 3; gap: 8px; }

  /* Разделы уходят на свою строку и прокручиваются вбок: пять вкладок в
     412px не помещаются ни при каком кегле, а прятать их в «бургер» —
     лишний тап на каждом переключении. */
  .topbar-nav {
    order: 4;
    width: 100%;
    margin: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .topbar-nav::-webkit-scrollbar { display: none; }

  .topbar-nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 40px;
    padding: 9px 14px;
  }

  .project-filter-btn { min-height: 40px; }

  /* Выпадашка проектов привязана к правому краю кнопки: у левого края экрана
     фиксированные 260px вылезали бы за вьюпорт. */
  .project-filter-panel {
    width: 280px;
    max-width: calc(100vw - 28px);
  }

  .board-wrap { padding: 16px 14px; }
  .board-header { flex-wrap: wrap; }
  .board-search-wrap { flex: 1 1 100%; order: 3; }
}

@media (max-width: 520px) {
  /* Имя пользователя на телефоне не несёт информации — он и так знает, под
     кем вошёл; освободившееся место отдаём заголовку. */
  #username-label { display: none; }
  .btn-ghost { padding: 9px 12px; }
}

@media (max-width: 640px) {
  /* Кнопка сводки растягивалась на всю ширину и без рамки читалась как
     подпись, а не как действие. */
  #leads-digest-btn {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 11px 14px;
    font-size: 13px;
  }

  /* Пальцу нужно 44px, иначе соседний фильтр ловит тап. */
  .leads-filter {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .leads-view { padding: 0 0 32px; }
  .leads-layout { gap: 16px; }

  .field-row { flex-wrap: wrap; }
  .field-row label { flex: 1 1 100%; }
  .modal-form { padding: 18px; }
  .task-extra { flex-direction: column; gap: 14px; }
}

@media (max-width: 640px) {
  /* Карточка сделки — главный экран телефона, но её кнопки («+3 дня»,
     «Сгенерировать», «Скопировать») были высотой 28px и без рамки: читались
     как подписи и не попадали под палец. */
  /* Кнопка копирования варианта в памятке — то же самое: без рамки и 28px
     высотой она не читается как кнопка и мажет мимо пальца. */
  .guide-tpl-copy {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
  }

  .deal-sheet .btn-ghost-small {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text);
  }

  .deal-sheet .btn-primary { min-height: 44px; }

  /* «Закрыть» не растягиваем — иначе съедает строку с названием лида. */
  .deal-sheet-head .btn-ghost-small { flex: 0 0 auto; padding: 10px 12px; }

  .deal-actions .btn-ghost-small { flex: 1 1 auto; }

  .deal-task input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 auto; }
}

/* --- Воронка в карточке сделки ------------------------------------------ */
/* Полоса заменила выпадашку «Этап»: из списка не было видно ни где сделка,
   ни куда её двигать. Шаги кликабельны — вернуть назад или перескочить
   вперёд приходится чаще, чем кажется. */

.funnel {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.funnel::-webkit-scrollbar { display: none; }

.funnel-step {
  flex: 1 0 auto;
  min-width: 92px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-dim);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}

.funnel-step:hover { border-color: var(--accent); color: var(--text); }

.funnel-num {
  font-size: 11px;
  font-weight: 700;
  opacity: .7;
}

.funnel-name { font-size: 12.5px; line-height: 1.25; }

/* Пройденные шаги приглушены, текущий — единственный яркий элемент полосы. */
.funnel-step.is-done { color: var(--text); border-color: var(--border); opacity: .65; }
.funnel-step.is-now {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  opacity: 1;
}
.funnel-step.is-now .funnel-num { opacity: .85; }

.stage-now {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--panel-2);
}

.stage-now-label {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stage-now-action { margin: 0; font-size: 16px; font-weight: 600; }
.stage-now-hint { margin: 4px 0 0; font-size: 13px; color: var(--text-dim); }

.stage-now-gate {
  margin: 8px 0 0;
  font-size: 13px;
  color: #fbbf24;
}

/* Пока гейт не пройден, блок красится в предупреждение: кнопка «дальше»
   в это время выключена, и причина должна быть видна рядом с ней. */
.stage-now-blocked { border-left-color: #f59e0b; }

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

#deal-advance { min-height: 44px; padding: 10px 18px; }
#deal-advance:disabled { opacity: .5; cursor: not-allowed; }

.stage-final {
  min-height: 44px;
  border: 1px solid var(--final, var(--border));
  color: var(--final, var(--text-dim));
  border-radius: 10px;
  padding: 10px 14px;
}
.stage-final:hover { background: var(--final); color: #fff; }

/* --- Доска воронки ------------------------------------------------------ */
/* Список лидов отвечает на вопрос «кому писать сегодня». Когда все сроки
   уехали на завтра, он пустеет — и раздел выглядит так, будто сделок нет
   вовсе. Доска показывает их всегда и целиком. */

.funnel-board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  align-items: flex-start;
}

.fcol {
  flex: 0 0 210px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Финальные колонки притушены: в них не работают, в них смотрят. */
.fcol-final { opacity: .75; }

.fcol-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--stage, var(--border));
}

.fcol-name { font-size: 13px; font-weight: 600; }

.fcol-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.fcol-body { display: flex; flex-direction: column; gap: 8px; }

.fcol-empty {
  margin: 4px 0;
  font-size: 12px;
  color: var(--text-dim);
  opacity: .6;
}

.fcard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  color: var(--text);
  cursor: pointer;
}

.fcard:hover { border-color: var(--accent); }

/* Просроченная сделка помечена той же красной линией, что и в списке:
   один и тот же сигнал в обоих представлениях. */
.fcard-late { border-left: 3px solid var(--danger); }

.fcard-title { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.fcard-due { font-size: 11.5px; color: var(--text-dim); }
.fcard-late .fcard-due { color: var(--danger); }
.fcard-note { font-size: 12px; color: var(--text-dim); line-height: 1.35; }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* В режиме воронки памятка прячется: 340px справа ужимали доску так, что
   последние колонки уходили за край экрана. */
@media (min-width: 1000px) {
  .leads-layout-wide { grid-template-columns: minmax(0, 1fr); }
  .leads-layout-wide .leads-guide { display: none; }
  .leads-view:has(.leads-layout-wide) { max-width: none; }
}

.modal-hint { margin: -4px 0 0; font-size: 12.5px; color: var(--text-dim); }
#password-btn { padding: 9px 12px; }

/* --- Настройки ---------------------------------------------------------- */
/* Раздел, а не кнопка в шапке: рядом с «Выйти» смена пароля читалась как
   второй выход, а на телефоне занимала место, которого и так нет. */

.settings-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 560px;
  padding: 4px 0 40px;
}

.settings-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}

.settings-card h2 { margin: 0 0 8px; font-size: 18px; }

.settings-note {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
}

.settings-form { display: flex; flex-direction: column; gap: 14px; }

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.settings-form input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  min-height: 44px;
}

.settings-form input:focus { outline: none; border-color: var(--accent); }
.settings-form .btn-primary { align-self: flex-start; min-height: 44px; padding: 11px 20px; }

.settings-hint { margin: -4px 0 0; font-size: 12.5px; color: var(--text-dim); }

.settings-msg {
  margin: 0;
  font-size: 14px;
  color: var(--danger);
}

/* Успех красим зелёным: та же строка служит и ошибкой, и подтверждением,
   и различать их только по тексту неудобно. */
.settings-msg-ok { color: #22c55e; }

.settings-list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 18px;
  font-size: 14px;
}

.settings-list dt { color: var(--text-dim); }
.settings-list dd { margin: 0; }

@media (max-width: 560px) {
  .settings-card { padding: 18px 16px; }
  .settings-form .btn-primary { align-self: stretch; }
}
