:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f4f4f5;
  --bg-chat: #efeae2;
  --text-primary: #000000;
  --text-secondary: #707579;
  --accent: #3390ec;
  --accent-hover: #2b7fd6;
  --accent-fg: rgba(51, 144, 236, 0.08);
  --border: #dadce0;
  --border-strong: #9ca3af;
  --hover: #f4f4f5;
  --message-out: #effdde;
  --message-in: #ffffff;
  --shadow: rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.12);
  --success: #4fae4e;
  --danger: #e53935;
  --warning: #fb8c00;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.15s ease;
}

[data-theme="dark"] {
  --bg-primary: #212121;
  --bg-secondary: #181818;
  --bg-chat: #0e0e0e;
  --text-primary: #ffffff;
  --text-secondary: #aaaaaa;
  --accent: #8774e1;
  --accent-hover: #7a67d4;
  --accent-fg: rgba(135, 116, 225, 0.12);
  --border: #2f2f2f;
  --border-strong: #3d3d3d;
  --hover: #2c2c2c;
  --message-out: #2b5278;
  --message-in: #1f1f1f;
  --shadow: rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 4px 0 rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 4px 12px 0 rgba(0, 0, 0, 0.4);
  --success: #5fb760;
  --danger: #f44336;
  --warning: #ff9800;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

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

/* ─── Sidebar ─── */
.sidebar {
  width: 420px;
  min-width: 420px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  transition: margin-left 0.3s ease;
  max-width: calc(100vw - 400px); /* Защита от выхода за экран */
}

.sidebar.hidden {
  margin-left: calc(-1 * var(--sidebar-width, 420px));
}

.sidebar-resizer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 100;
  background: transparent;
  transition: background 0.2s ease;
}

.sidebar-resizer:hover {
  background: var(--accent);
  opacity: 0.5;
}

.sidebar-resizer:active {
  background: var(--accent);
  opacity: 1;
}

/* Compact mode - узкий сайдбар */
.sidebar.sidebar-compact .sidebar-header {
  padding: 12px 8px;
  justify-content: center;
}

.sidebar.sidebar-compact .search-box,
.sidebar.sidebar-compact .icon-btn:not(:first-child) {
  display: none;
}

.sidebar.sidebar-compact .chat-list {
  padding: 0;
}

.sidebar.sidebar-compact .chat-item {
  padding: 12px 8px;
  justify-content: center;
}

.sidebar.sidebar-compact .chat-info,
.sidebar.sidebar-compact .chat-meta {
  display: none;
}

.sidebar.sidebar-compact .avatar {
  margin-right: 0;
}

.sidebar.sidebar-compact .bottom-nav .nav-btn span {
  display: none;
}

.sidebar.sidebar-compact .bottom-nav .nav-btn {
  padding: 8px;
}

/* Mini mode - иконки не влезают, показываем меню */
.sidebar.sidebar-mini .sidebar-header {
  padding: 12px 8px;
  justify-content: center;
}

.sidebar.sidebar-mini .search-box,
.sidebar.sidebar-mini .icon-btn:not(:first-child) {
  display: none;
}

.sidebar.sidebar-mini .chat-list {
  padding: 0;
}

.sidebar.sidebar-mini .chat-item {
  padding: 12px 8px;
  justify-content: center;
}

.sidebar.sidebar-mini .chat-info,
.sidebar.sidebar-mini .chat-meta {
  display: none;
}

.sidebar.sidebar-mini .avatar {
  margin-right: 0;
}

.sidebar.sidebar-mini .bottom-nav .nav-btn {
  display: none;
}

.nav-menu-btn {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  transition: var(--transition);
}

.nav-menu-btn:hover {
  background: var(--hover);
  color: var(--accent);
}

.sidebar.sidebar-mini .nav-menu-btn {
  display: flex;
}

/* Nav popup menu */
.nav-popup {
  display: none;
  position: fixed;
  z-index: 10002;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  padding: 6px;
  min-width: 200px;
  flex-direction: column;
  gap: 2px;
}

.nav-popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  width: 100%;
  text-align: left;
  transition: background 0.15s;
}

.nav-popup-item:hover {
  background: var(--hover);
}

.nav-popup-item svg {
  flex-shrink: 0;
}

.sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  height: 60px;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-list-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.chat-list {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.search-box {
  flex: 1;
  min-width: 0;
  background: var(--bg-secondary);
  border: none;
  border-radius: 22px;
  padding: 9px 16px;
  color: var(--text-primary);
  outline: none;
  font-size: 14px;
  transition: var(--transition);
  font-weight: 400;
}

.search-box:focus { background: var(--hover); }
.search-box::placeholder { color: var(--text-secondary); }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--hover); color: var(--text-primary); }
.icon-btn.accent { background: var(--accent); color: white; }
.icon-btn.accent:hover { background: var(--accent-hover); }

#backButton {
  flex-shrink: 0;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  border-bottom: 1px solid var(--border);
}

.chat-item[draggable="true"] {
  cursor: grab;
}

.chat-item[draggable="true"]:active {
  cursor: grabbing;
}

.chat-item.dragging {
  opacity: 0.4;
  transform: scale(0.98);
}

.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--accent-fg); border-bottom-color: var(--border); }
.chat-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent);
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 500;
  font-size: 18px;
  margin-right: 12px;
  flex-shrink: 0;
  user-select: none;
  position: relative;
}

.avatar.status-online::after {
  content: '';
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  background: var(--success);
  border: 2px solid var(--bg-primary);
  border-radius: 50%;
}

.chat-info { flex: 1; min-width: 0; }
.chat-name {
  font-weight: 500;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px;
  line-height: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
}
.chat-preview {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  margin-left: 12px;
  flex-shrink: 0;
}

.time { font-size: 12px; color: var(--text-secondary); font-weight: 400; }
.star-btn {
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: transform 0.15s;
  user-select: none;
}
.star-btn:hover { transform: scale(1.3); }
.badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
  font-weight: 600;
  line-height: 1;
}

.bottom-nav {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 4px;
  gap: 0;
  background: var(--bg-primary);
  flex-direction: row;
  overflow: hidden;
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  transition: var(--transition);
  font-size: 10px;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.nav-btn svg {
  flex-shrink: 0;
}

.nav-btn:hover { background: var(--hover); }
.nav-btn.active { color: var(--accent); }

/* Sidebar DND drop targets */
.nav-btn.drop-target {
  position: relative;
  transition: all 0.2s ease;
  background: var(--accent-fg);
  border-radius: 8px;
  animation: dropGlow 1.5s ease-in-out infinite;
}

.nav-btn.drop-target::after {
  content: attr(data-drop-label);
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 9px;
  font-weight: 700;
  color: white;
  background: var(--accent);
  padding: 1px 6px;
  border-radius: 8px;
  line-height: 16px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  animation: dropPulse 1s ease-in-out infinite;
}

@keyframes dropGlow {
  0%, 100% { box-shadow: inset 0 0 0 1px transparent; }
  50% { box-shadow: inset 0 0 0 2px var(--accent); }
}

.nav-btn.drop-hover {
  background: var(--accent-fg);
  color: var(--accent);
  transform: scale(1.05);
  box-shadow: 0 0 12px var(--accent);
}

.nav-btn.drop-hover::after {
  content: '↓';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  animation: dropPulse 0.6s ease-in-out infinite;
}

@keyframes dropPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* ─── Main ─── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.main-header {
  padding: 12px 20px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  overflow: hidden;
}

.header-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-title { font-weight: 500; font-size: 16px; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 2px; line-height: 16px; white-space: nowrap; overflow: hidden; }

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ─── Messages ─── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius);
  position: relative;
  animation: msgIn 0.2s ease;
  font-size: 14px;
  line-height: 20px;
  word-wrap: break-word;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.in { 
  align-self: stretch;
  background: var(--message-in); 
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.message.out { 
  align-self: flex-end; 
  background: var(--message-out); 
  box-shadow: var(--shadow-sm);
  border-radius: 12px 12px 2px 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  max-width: 65%;
}
.message.system { 
  align-self: center; 
  background: var(--bg-secondary); 
  color: var(--text-secondary); 
  font-size: 13px; 
  padding: 4px 12px; 
  max-width: 80%; 
  text-align: center; 
  border-radius: 16px;
  box-shadow: none;
}

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  line-height: 1;
}

.message-time.overdue {
  color: var(--danger);
  font-weight: 600;
}

.message-title {
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 15px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Form elements inside messages */
.message .form-group {
  margin-bottom: 10px;
}

.message .form-group:last-of-type {
  margin-bottom: 0;
}

.message .form-label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  line-height: 14px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Form grid for better space usage */
.message .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.message .form-grid .form-group {
  margin-bottom: 0;
}

.message .form-input,
.message .form-input:focus {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
  line-height: 20px;
}

.message .form-input:focus {
  background: var(--bg-chat);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-fg);
}

.message .form-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

.message textarea.form-input {
  min-height: 60px;
  resize: vertical;
}

/* Quick actions in messages */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.quick-action {
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1;
  white-space: nowrap;
}

.quick-action:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.quick-action:active {
  transform: translateY(0);
}

/* ─── Input ─── */
.input-area {
  padding: 12px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.message-input {
  flex: 1;
  background: var(--bg-secondary);
  border: none;
  border-radius: 20px;
  padding: 9px 16px;
  color: var(--text-primary);
  outline: none;
  font-size: 14px;
  font-family: inherit;
  max-height: 120px;
  resize: none;
  transition: var(--transition);
  line-height: 20px;
}

.message-input:focus { background: var(--hover); }
.message-input::placeholder { color: var(--text-secondary); }

/* ─── Kanban ─── */
.kanban-wrap {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.kanban-col {
  min-width: 300px;
  width: 300px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 100%;
  transition: var(--transition);
  border: 1px solid var(--border);
}

.kanban-col.drag-over { 
  background: var(--hover); 
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-fg);
}

.kanban-col-add {
  background: var(--bg-primary);
  border: 2px dashed var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.kanban-col-add:hover {
  border-color: var(--accent);
  background: var(--accent-fg);
}

.kanban-add-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.kanban-add-content svg {
  opacity: 0.5;
}

.kanban-header {
  font-weight: 500;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  line-height: 20px;
  position: relative;
  cursor: grab;
}

.kanban-header:active {
  cursor: grabbing;
}

.leads-edit-mode .kanban-header {
  cursor: default;
  padding: 8px 32px 8px 12px;
}

.tasks-edit-mode .kanban-header {
  cursor: default;
  padding: 8px 32px 8px 12px;
}

.leads-edit-mode .kanban-header:hover {
  border-color: var(--accent);
}

.leads-edit-mode .kanban-header .field-actions {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
}

.stage-delete {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  z-index: 10;
  font-weight: 600;
}

.stage-delete:hover {
  transform: translateY(-50%) scale(1.1);
  box-shadow: 0 2px 8px rgba(229, 57, 53, 0.4);
}

.stage-delete:active {
  transform: translateY(-50%) scale(0.95);
}

.kanban-count {
  background: var(--bg-primary);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.kanban-items {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.kanban-card {
  background: var(--bg-primary);
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: grab;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  position: relative;
  border: 1px solid var(--border);
}

.kanban-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.5; }

.priority-high { border-left: 3px solid var(--danger); }
.priority-medium { border-left: 3px solid var(--warning); }
.priority-low { border-left: 3px solid var(--success); }

.card-title { font-weight: 500; margin-bottom: 6px; font-size: 14px; line-height: 18px; }
.card-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; line-height: 18px; }
.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.card-value { font-weight: 600; font-size: 14px; }
.card-date { font-size: 12px; color: var(--text-secondary); }
.card-date.overdue { color: var(--danger); font-weight: 500; }

.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
}

.tag-kl { background: #e3f2fd; color: #1565c0; }
.tag-pk { background: #fff3e0; color: #ef6c00; }
.tag-np { background: #f3e5f5; color: #6a1b9a; }
[data-theme="dark"] .tag-kl { background: #1a237e; color: #82b1ff; }
[data-theme="dark"] .tag-pk { background: #bf360c; color: #ffcc80; }
[data-theme="dark"] .tag-np { background: #4a148c; color: #ea80fc; }

/* ─── Dashboard ─── */
.dashboard {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 12px;
}

.edit-mode-grid .widget-item {
  outline: 2px dashed var(--accent);
  border-radius: var(--radius);
  transition: all 0.2s ease;
}

.edit-mode-grid .widget-item:hover {
  outline-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-fg);
}

/* Edit mode section styles */
.edit-mode-section {
  padding: 12px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.widget-item {
  position: relative;
}

.widget-item .field-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  display: flex;
  gap: 4px;
  align-items: center;
  z-index: 10;
}

.widget-item[data-width="2"] {
  grid-column: span 2;
}

.widget-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  z-index: 10;
}

.widget-delete:first-of-type {
  right: 36px;
  background: var(--accent);
}

.widget-item {
  position: relative;
}

.dashboard-edit-mode .widget-item {
  position: relative;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 2px dashed var(--border);
  transition: var(--transition);
  cursor: move;
  box-sizing: border-box;
}

.dashboard-edit-mode .panel.widget-item {
  padding: 12px 12px 12px 12px;
  grid-column: 1 / -1;
}

.dashboard-edit-mode .widget-item.field-editable {
  border: 2px dashed var(--border);
}

.widget-item .field-actions {
  position: absolute !important;
  top: 8px !important;
  right: 8px !important;
  left: auto !important;
  display: flex !important;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-primary);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.stat-card:hover { 
  transform: translateY(-2px); 
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}
.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0;
  transition: var(--transition);
}
.stat-card:hover::after { opacity: 1; }

.stat-value {
  font-size: 36px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 12px 0 4px;
  letter-spacing: -1px;
  line-height: 1;
}

.stat-label { color: var(--text-secondary); font-size: 13px; font-weight: 500; line-height: 18px; }
.stat-delta { font-size: 13px; color: var(--success); margin-top: 8px; font-weight: 400; }
.stat-delta.negative { color: var(--danger); }

.panel {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  border: 1px solid var(--border);
  position: relative;
}

.panel-title { font-weight: 500; margin-bottom: 16px; font-size: 15px; line-height: 20px; }

/* Widget delete button */
.widget-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  z-index: 10;
  font-weight: 600;
}

.widget-delete:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(229, 57, 53, 0.4);
}

.widget-delete:active {
  transform: scale(0.95);
}

.panel.widget-item {
  grid-column: 1 / -1;
}

.panel.widget-item[data-width="1"] {
  grid-column: span 1;
}

.funnel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
}

.funnel-label { width: 130px; font-size: 13px; color: var(--text-secondary); text-align: right; flex-shrink: 0; }
.funnel-track { flex: 1; background: var(--bg-secondary); border-radius: 6px; height: 32px; overflow: hidden; position: relative; }
.funnel-bar {
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: white;
  font-size: 13px;
  font-weight: 600;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  white-space: nowrap;
}
.funnel-bar span { position: relative; z-index: 2; }

/* ─── Profile ─── */
.profile-wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 40px 24px;
}

.profile-avatar-large {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--accent);
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: white;
  font-weight: 600;
  position: relative;
  cursor: pointer;
  transition: var(--transition);
}

.profile-avatar-large:hover { transform: scale(1.02); opacity: 0.9; }

.profile-name { text-align: center; font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.profile-email { text-align: center; color: var(--text-secondary); margin-bottom: 32px; font-size: 15px; }

.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 8px; color: var(--text-secondary); font-size: 13px; font-weight: 500; line-height: 16px; }
.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
  line-height: 20px;
  box-sizing: border-box;
}
.form-input:focus { background: var(--hover); }
.form-input::placeholder { color: var(--text-secondary); opacity: 0.7; }

.btn {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 20px;
  white-space: nowrap;
}

.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.98); }
.btn-outline { background: var(--bg-secondary); color: var(--text-primary); }
.btn-outline:hover { background: var(--hover); }
.btn-danger { background: var(--danger); }
.btn-success { background: var(--success); }

.btn-group { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* ─── FAB Button ─── */
.fab-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: var(--transition);
  z-index: 10;
}

.fab-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.fab-btn:active {
  transform: scale(0.95);
}

/* ─── Empty ─── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 16px;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.empty-icon { width: 140px; height: 140px; opacity: 0.25; }
.empty-title { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.empty-sub { font-size: 14px; max-width: 300px; text-align: center; line-height: 1.4; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ─── Responsive ─── */
@media (max-width: 960px) {
  .sidebar { width: 320px; min-width: 320px; }
  .header-info { min-width: 0; overflow: hidden; }
}

@media (max-width: 768px) {
  .sidebar { position: absolute; width: 100%; height: 100%; transition: transform 0.3s ease; }
  .sidebar.hidden-mobile { transform: translateX(-100%); }
  .main { width: 100%; overflow: hidden; }
  .kanban-wrap { padding: 10px; gap: 10px; }
  .kanban-col { min-width: 260px; width: 260px; }
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow: auto;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

/* ─── Field Editing ─── */
.fields-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 12px;
}

.fields-grid .form-group {
  display: flex;
  flex-direction: column;
}

.fields-grid .form-group.field-editable {
  cursor: move;
}

.fields-grid .form-group .form-label {
  margin-bottom: 4px;
}

.fields-grid .form-group .form-input {
  height: 40px;
  box-sizing: border-box;
}

.fields-grid .field-header {
  margin-bottom: 4px;
}

.fields-grid .field-editable {
  height: 100%;
  box-sizing: border-box;
}

.form-group-full {
  grid-column: span 2;
}

.form-group-half {
  grid-column: span 1;
}

.field-editable {
  position: relative;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 2px dashed var(--border);
  transition: var(--transition);
  cursor: move;
  box-sizing: border-box;
}

.field-editable:hover {
  border-color: var(--accent);
  background: var(--hover);
}

.field-editable.dragging {
  opacity: 0.5;
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.field-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.field-action-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.field-action-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.field-action-btn.field-delete:hover {
  background: var(--danger);
  border-color: var(--danger);
}

.field-required-badge {
  font-size: 10px;
  padding: 2px 6px;
  background: var(--accent-fg);
  color: var(--accent);
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field-editable .form-input {
  background: var(--bg-primary);
  cursor: not-allowed;
  opacity: 0.7;
  height: 40px;
  box-sizing: border-box;
}

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

/* ─── Command Palette ─── */
.command-palette {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 100px;
}

.command-palette-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.command-palette-content {
  position: relative;
  width: 90%;
  max-width: 600px;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  overflow: hidden;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.command-palette-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.command-search {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: all 0.2s ease;
}

.command-search:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
}

.command-palette-list {
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
}

.command-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.command-item:hover {
  background: var(--bg-secondary);
}

.command-description {
  color: var(--text-primary);
  font-size: 14px;
}

.command-shortcut {
  display: flex;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: monospace;
  background: var(--bg-secondary);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.command-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-secondary);
}

/* ─── Mobile Adaptations ─── */
@media (max-width: 768px) {
  .command-palette {
    padding-top: 60px;
  }
  
  .command-palette-content {
    width: 95%;
    max-width: none;
  }
  
  .command-palette-list {
    max-height: 60vh;
  }
}

/* Touch Mode Enhancements */
.touch-mode .command-item {
  min-height: 56px;
}

.touch-mode .command-search {
  min-height: 48px;
  font-size: 16px; /* Prevent zoom on iOS */
}

/* Mobile Sidebar Overlay */
@media (max-width: 768px) {
  .sidebar {
    z-index: 100;
  }
  
  .sidebar::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  
  .sidebar:not(.hidden)::before {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Tablet Optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: 350px;
    min-width: 350px;
  }
  
  .clients-table {
    font-size: 14px;
  }
  
  .kanban-col {
    min-width: 280px;
  }
}

/* ─── Table Customizer ─── */
.table-settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.table-settings-overlay.show {
  opacity: 1;
}

.table-settings-panel {
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.table-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.table-settings-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.table-settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h4 {
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.columns-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.column-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: move;
  transition: all 0.2s ease;
}

.column-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.column-item.dragging {
  opacity: 0.5;
}

.column-drag-handle {
  color: var(--text-secondary);
  cursor: grab;
  user-select: none;
}

.column-drag-handle:active {
  cursor: grabbing;
}

.column-checkbox {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.column-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.column-checkbox span {
  color: var(--text-primary);
  font-size: 14px;
}

.column-width {
  display: flex;
  align-items: center;
  gap: 4px;
}

.column-width input[type="number"] {
  width: 70px;
  padding: 6px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  text-align: center;
}

.column-width span {
  color: var(--text-secondary);
  font-size: 12px;
}

.settings-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

/* Custom Table */
.custom-table-wrapper {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-primary);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.custom-table thead {
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.custom-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.custom-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
}

.custom-table tbody tr {
  transition: var(--transition);
  cursor: pointer;
}

.custom-table tbody tr:hover {
  background: var(--hover);
}

.custom-table tbody tr:last-child td {
  border-bottom: none;
}

.custom-table td strong {
  font-weight: 600;
  color: var(--text-primary);
}

.cell-empty {
  color: var(--text-secondary);
  font-style: italic;
  opacity: 0.6;
}

/* Mobile Table Settings */
@media (max-width: 768px) {
  .table-settings-panel {
    width: 95%;
    max-height: 90vh;
  }
  
  .column-item {
    flex-wrap: wrap;
  }
  
  .column-width {
    width: 100%;
    justify-content: flex-end;
  }
}
  
  .form-group-full,
  .form-group-half {
    grid-column: span 1;
  }
}

/* ─── Clients Table ─── */
.clients-table-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-chat);
  min-height: 0; /* Важно для flex */
}

.table-filters {
  padding: 16px 20px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0; /* Не сжимать фильтры */
}

.filter-select {
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
  cursor: pointer;
  min-width: 140px;
}

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

.filter-search {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
}

.filter-search:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
  box-shadow: 0 0 0 2px var(--accent-fg);
}

.filter-search::placeholder {
  color: var(--text-secondary);
}

.clients-table {
  flex: 1;
  overflow: auto;
  padding: 20px;
  min-height: 0; /* Важно для flex */
}

.filter-item {
  position: relative;
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
}

.filter-item-edit {
  cursor: move;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 4px 8px 4px 4px;
  background: var(--accent-fg);
  transition: var(--transition);
}

.filter-item-edit:hover {
  background: var(--hover);
  border-color: var(--accent);
}

.filter-item-edit select,
.filter-item-edit input {
  pointer-events: none;
}

.filter-item-edit .field-actions {
  position: absolute;
  display: flex;
  gap: 4px;
  align-items: center;
  z-index: 10;
  right: -10px;
  top: -10px;
}

.filter-item-edit .field-actions button {
  pointer-events: auto;
}

.sortable-ghost .filter-select,
.sortable-ghost .filter-search {
  opacity: 0.3;
}

.clients-table {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.clients-table table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-primary);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.clients-table thead {
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.clients-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.clients-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
}

.clients-table tbody tr {
  transition: var(--transition);
}

.clients-table tbody tr:hover {
  background: var(--hover);
}

.clients-table tbody tr:last-child td {
  border-bottom: none;
}

.clients-table td strong {
  font-weight: 600;
  color: var(--text-primary);
}

/* ─── Inline table editing ─── */
.table-editable-input {
  width: 100%;
  border: none;
  background: transparent;
  padding: 2px 4px;
  font: inherit;
  font-size: 14px;
  color: var(--text-primary);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-radius: 2px;
  margin: -2px -4px;
  box-sizing: border-box;
}


.date-qbtn {
  cursor: pointer;
  font-size: 13px;
  color: var(--accent);
  white-space: nowrap;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  transition: var(--transition);
  user-select: none;
  line-height: 20px;
  box-sizing: border-box;
}
.date-qbtn:hover {
  background: var(--accent-fg);
  border-color: var(--accent);
}
}
.date-cal-btn {
  cursor: pointer;
  font-size: 16px;
  color: var(--accent);
  line-height: 20px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  transition: var(--transition);
  user-select: none;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.date-cal-btn:hover {
  background: var(--accent-fg);
  border-color: var(--accent);
}
.date-cal-btn:hover {
  color: var(--accent);
}
.date-input {
  padding-right: 32px;
}
.date-clear-btn {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  line-height: 1;
  padding: 2px;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.date-clear-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

.table-select-cell {
}
}
}
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  padding: 4px 6px;
  font: inherit;
  font-size: 14px;
  color: var(--text-primary);
  border-radius: 4px;
  cursor: pointer;
  box-sizing: border-box;
}

.table-select-cell:focus {

}
}
}
}
}
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* ─── Utils ─── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.text-secondary { color: var(--text-secondary); }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.font-semibold { font-weight: 600; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }

/* ─── SortableJS Styles (Telegram-style) ─── */
.sortable-ghost {
  opacity: 0.4;
  background: var(--bg-secondary);
}

.sortable-chosen {
  cursor: grabbing !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 1000;
}

.sortable-drag {
  opacity: 1;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}

/* Smooth transitions for all draggable elements */
.chat-item,
.kanban-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.widget-item {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Kanban column hover state */
.kanban-col {
  transition: background-color 0.15s ease;
}

.kanban-col.drag-over {
  background: var(--hover);
}

.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.quick-action {
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-primary);
  font-family: inherit;
}

.quick-action:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-primary); }

.typing {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 12px 16px;
  align-self: flex-start;
  background: var(--message-in);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px var(--shadow);
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.9);
  transition: transform 0.2s ease;
}

.modal-overlay.show .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 500;
  line-height: 24px;
}

.modal-body {
  padding: 8px 0;
  overflow-y: auto;
  max-height: 60vh;
}

.widget-option {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  transition: var(--transition);
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.widget-option:last-child {
  border-bottom: none;
}

.widget-option:hover {
  background: var(--hover);
}

.widget-option-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 180px;
}

.widget-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.widget-name {
  font-size: 15px;
  font-weight: 500;
  line-height: 20px;
}

.widget-preview {
  flex: 1;
  min-width: 0;
  opacity: 0.8;
  transform: scale(0.85);
  transform-origin: left center;
}

.widget-option svg {
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* Widget Preview Styles */
.widget-preview-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

.preview-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.preview-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  line-height: 1;
}

.preview-delta {
  font-size: 10px;
  color: var(--success);
  font-weight: 400;
}

.preview-delta.negative {
  color: var(--danger);
}

.widget-preview-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

.preview-title {
  font-size: 11px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.preview-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preview-bar {
  height: 6px;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.preview-priority {
  display: flex;
  gap: 6px;
}

.preview-priority-item {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid;
  border-radius: 4px;
  padding: 6px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preview-priority-item span:first-child {
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

.preview-priority-item span:last-child {
  font-size: 8px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* DND Trash Zone - Telegram style */
#dnd-trash {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 180px;
  background: var(--danger);
  color: white;
  text-align: center;
  z-index: 9000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-top: 6px dashed #ff6b6b;
  padding-top: 8px;
}

#dnd-trash.over {
  opacity: 1;
  border-color: #ff4444;
  border-top-width: 8px;
}

#dnd-trash.active {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

#dnd-trash.over {
  border-color: var(--accent);
  background: rgba(51, 144, 236, 0.08);
  transform: translateX(-50%) scale(1.02);
  box-shadow: 0 12px 40px rgba(51, 144, 236, 0.25);
}

#dnd-trash .trash-icon {
  font-size: 28px;
  margin-bottom: 6px;
  transition: transform 0.2s ease;
}

#dnd-trash.over .trash-icon {
  transform: scale(1.15);
}

#dnd-trash .trash-text {
  font-size: 13px;
  font-weight: 600;
}

#dnd-trash .trash-hint {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Dark theme support */
[data-theme="dark"] #dnd-trash {
  background: rgba(30, 30, 30, 0.92);
  border-color: #ef5350;
  color: var(--accent);
  box-shadow: 0 8px 32px rgba(51, 144, 236, 0.2);
}

[data-theme="dark"] #dnd-trash.over {
  background: rgba(51, 144, 236, 0.15);
  border-color: #ef5350;
}

[data-theme="dark"] #dnd-trash .trash-hint {
  color: var(--text-secondary);
}
}

#dnd-trash.over {
  transform: translateX(-50%) scale(1.1);
  background: #c62828;
  border-color: #ef5350;
}

/* Fields Panel */
.fields-panel {
  padding: 16px;
}

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

.fields-panel .panel-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.fields-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fields-list .field-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.fields-list .field-item:hover {
  background: var(--hover);
}

.fields-list .field-item.system {
  background: var(--accent-fg);
  opacity: 0.8;
}

.fields-list .field-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fields-list .field-label {
  font-weight: 500;
  font-size: 14px;
}

.fields-list .field-type {
  font-size: 12px;
  color: var(--text-secondary);
}

.fields-list .field-actions {
  display: flex;
  gap: 4px;
}

.fields-list .system-badge {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  background: var(--accent-fg);
  padding: 2px 8px;
  border-radius: 4px;
}

.fields-list .icon-btn.danger:hover {
  background: var(--danger);
  color: white;
}

/* Fields Panel Compact */
.fields-panel-compact {
  padding: 12px;
}

.fields-panel-compact .fields-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.fields-panel-compact .fields-title {
  font-size: 14px;
  font-weight: 600;
}

.fields-panel-compact .btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.field-card {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 10px;
  position: relative;
}

.field-card.system {
  background: var(--accent-fg);
  opacity: 0.8;
}

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

.field-card-label {
  font-weight: 600;
  font-size: 13px;
}

.field-card-desc {
  font-size: 11px;
  color: var(--text-secondary);
}

.field-card-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.btn-icon {
  background: transparent;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
}

.btn-icon:hover {
  background: var(--hover);
}

.btn-icon.danger:hover {
  background: var(--danger);
  color: white;
}

/* ─── Contact Autocomplete ─── */
.contact-autocomplete-dropdown {
  font-family: inherit;
}

.contact-autocomplete-item:first-child {
  border-radius: 7px 7px 0 0;
}

.contact-autocomplete-item:last-child {
  border-radius: 0 0 7px 7px;
}

.contact-autocomplete-item:hover {
  background: var(--accent-fg);
}

/* Auth Page */
.auth-page {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}



/* Telegram Web-style Auth */
.auth-page {
  background: #ffffff;
}

.auth-card {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
}

[data-theme="dark"] .auth-page {
  background: #17212b;
}

.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 360px;
  animation: authFadeIn .25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes authFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Theme toggle */
.auth-theme-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #707579;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .15s;
  z-index: 10;
}

.auth-theme-btn:hover {
  background: rgba(0,0,0,0.05);
}

[data-theme="dark"] .auth-theme-btn:hover {
  background: rgba(255,255,255,0.05);
}

.auth-theme-btn:active {
  transform: scale(.9);
}

/* Logo */
.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: #0088cc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  flex-shrink: 0;
  user-select: none;
}

/* Title */
.auth-title {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 24px;
  font-weight: 600;
  color: #000000;
  margin-top: 20px;
  text-align: center;
}

[data-theme="dark"] .auth-title {
  color: #ffffff;
}

/* Subtitle */
.auth-subtitle {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  font-weight: 400;
  color: #707579;
  max-width: 260px;
  text-align: center;
  margin-top: 8px;
  line-height: 1.4;
}

/* Contact step */
.auth-contact-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin-top: 16px;
  animation: authFadeIn .25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Input wrapper */
.auth-input-wrap {
  position: relative;
  width: 100%;
  max-width: 320px;
}

.auth-input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: #707579;
  pointer-events: none;
  opacity: 0.6;
}

/* Input */
.auth-input {
  width: 100%;
  height: 54px;
  background: #f5f5f5;
  border: none;
  border-radius: 8px;
  padding: 0 16px 0 44px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  color: #000000;
  outline: none;
  transition: outline .15s, background .15s;
  box-sizing: border-box;
}

.auth-input::placeholder {
  color: #707579;
  opacity: 0.6;
}

.auth-input:focus {
  outline: 2px solid #0088cc;
  outline-offset: -2px;
}

.auth-input.invalid {
  outline: 2px solid #e53935;
  outline-offset: -2px;
  animation: authShake .45s ease;
}

[data-theme="dark"] .auth-input {
  background: #242f3d;
  color: #ffffff;
}

[data-theme="dark"] .auth-input::placeholder {
  color: #a0a0a0;
  opacity: 0.5;
}

@keyframes authShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(1px); }
}

/* Hint */
.auth-hint,
.tg-hint {
  font-size: 13px;
  color: #707579;
  margin-top: 8px;
  min-height: 18px;
  line-height: 1.4;
  text-align: center;
  transition: color .2s;
}

.auth-hint.valid,
.tg-hint.valid {
  color: #4fae4e;
}

.auth-hint.error,
.tg-hint.error {
  color: #e53935;
}

[data-theme="dark"] .auth-hint.error,
[data-theme="dark"] .tg-hint.error {
  color: #f44336;
}

/* Button */
.auth-btn {
  width: 100%;
  max-width: 320px;
  height: 54px;
  background: #0088cc;
  border: none;
  border-radius: 10px;
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 0;
  transition: background .2s, transform .12s;
  display: block;
}

.auth-btn:hover:not(:disabled) {
  background: #0077b3;
}

.auth-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.auth-btn:disabled {
  background: #e6e6e6;
  color: #9e9e9e;
  cursor: not-allowed;
}

[data-theme="dark"] .auth-btn:disabled {
  background: #2f2f2f;
  color: #6e6e6e;
}

/* PIN step */
.auth-pin-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  animation: authFadeIn .25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.auth-pin-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  position: relative;
  margin-bottom: 24px;
}

.auth-pin-back {
  position: absolute;
  left: 0;
  color: #0088cc;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: background .2s, transform .15s;
  user-select: none;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-pin-back:hover {
  background: rgba(0, 136, 204, 0.08);
}

.auth-pin-back:active {
  transform: scale(.92);
}

.auth-pin-desc {
  font-size: 14px;
  color: #707579;
  margin-bottom: 20px;
  text-align: center;
  line-height: 1.4;
}

/* PIN digits */
.auth-pin-digits {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.tg-pin-digit {
  width: 46px;
  height: 52px;
  border: 2px solid #dadce0;
  border-radius: 10px;
  background: #f5f5f5;
  color: #000000;
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color .2s, background .2s, transform .15s;
  caret-color: #0088cc;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.tg-pin-digit:focus {
  border-color: #0088cc;
  background: #ffffff;
}

.tg-pin-digit.filled {
  border-color: #0088cc;
  background: #f0f9ff;
}

[data-theme="dark"] .tg-pin-digit {
  border-color: #3a4b5a;
  background: #242f3d;
  color: #ffffff;
}

[data-theme="dark"] .tg-pin-digit:focus {
  border-color: #0088cc;
  background: #1e2a36;
}

[data-theme="dark"] .tg-pin-digit.filled {
  border-color: #0088cc;
  background: #1a2e3e;
}

/* Help link */
.auth-help-link {
  font-size: 14px;
  color: #0088cc;
  text-decoration: none;
  margin-top: 16px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.auth-help-link:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 639px) {
  .auth-logo {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    font-size: 20px;
  }

  .auth-title {
    font-size: 22px;
  }

  .auth-input-wrap,
  .auth-input,
  .auth-btn {
    max-width: 100%;
  }
}

@media (min-width: 640px) {
  .auth-container {
    padding: 0;
  }
}

@media (min-width: 1440px) {
  .auth-form {
    max-width: 360px;
  }

  .auth-title {
    font-size: 28px;
  }

  .auth-container::before,
  .auth-container::after {
    content: '';
    position: fixed;
    top: 0;
    bottom: 0;
    width: 1px;
    background-image: radial-gradient(circle, rgba(0,0,0,0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
  }

  [data-theme="dark"] .auth-container::before,
  [data-theme="dark"] .auth-container::after {
    background-image: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
  }

  .auth-container::before {
    left: 15%;
  }

  .auth-container::after {
    right: 15%;
  }
}

/* ── Clients table checkboxes ──────────────────── */
.clients-cb {
  -webkit-appearance:none;appearance:none;
  width:16px;height:16px;
  border:2px solid var(--border);
  border-radius:3px;
  background:var(--bg);
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  margin:0;
  transition:.15s;
  flex-shrink:0;
}
.clients-cb:checked {
  background:var(--accent);
  border-color:var(--accent);
}
.clients-cb:checked::after {
  content:'✓';
  color:#fff;
  font-size:12px;
  font-weight:700;
  line-height:1;
}
.clients-cb:hover {
  border-color:var(--accent);
}
tr.row-selected {
  background:var(--accent-fg) !important;
}

/* ── Chat / Notes input bar ────────────────────── */
.chat-input-area {
  display:flex;gap:8px;padding:10px 16px;
  border-top:1px solid var(--border);
  background:var(--bg);
  position:sticky;bottom:0;
}
.note-input {
  flex:1;padding:8px 12px;border:1px solid var(--border);
  border-radius:8px;font-size:14px;outline:none;
  background:var(--surface);color:var(--text);
}
.note-input:focus { border-color:var(--accent); }