/* Mobile-first styles using palette: #3d008b (violet), #F5C042 (yellow), #57BF5F (green), background white */
:root {
  --violet: #3d008b;
  --yellow: #F5C042;
  --green: #57BF5F;
  --bg: #ffffff;
  --text: #1f1f1f;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg-soft: #fafafa;
  --violet-600: #4d019b;
  --violet-700: #2c0066;
  --ring: rgba(61, 0, 139, 0.35);
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 200ms ease;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.5; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0 0 12px; }
small, .muted { color: var(--muted); }

.topbar {
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  padding: 0 16px; 
  border-bottom: 1px solid var(--border);
  position: sticky; 
  top: 0; 
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  z-index: 100;
  height: 80px;
  min-height: 80px;
}
.topbar h1 { margin: 0; font-size: 18px; color: var(--violet); }
#sidebar-toggle {
  display: none !important;
}
.badge { background: var(--yellow); color: #000; padding: 4px 8px; border-radius: 999px; font-size: 12px; }
.badge-success { background: var(--green); color: #fff; }
.badge-warn { background: var(--yellow); color: #111; }
.badge-neutral { background: #eef2ff; color: var(--violet); }

.container { padding: 12px; max-width: 920px; margin: 0 auto; }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 16px; background: #fff; }
.card h2 { margin: 0 0 12px; font-size: 16px; color: var(--violet); }
.hint { color: var(--muted); font-size: 13px; margin-bottom: 8px; }

.row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.two-cols { gap: 12px; }
.two-cols > div { flex: 1; }
label { font-size: 13px; color: var(--muted); }
input[type="text"], input[type="url"], input[type="tel"], input[type="number"], input[type="password"], textarea, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 15px; outline: none; background:#fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--violet);
  box-shadow: 0 0 0 4px rgba(61, 0, 139, 0.08);
}
input::placeholder, textarea::placeholder { color: #9aa0a6; }

.btn {
  background: var(--violet);
  color: #fff; border: none; border-radius: 12px; padding: 9px 13.5px;
  font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none;
  box-shadow: 0 4px 12px rgba(61, 0, 139, 0.25);
  transition: all 0.3s ease;
}
.btn:hover { 
  transform: translateY(-2px); 
  box-shadow: 0 6px 16px rgba(61, 0, 139, 0.35);
  background: #4d019b;
}
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(61, 0, 139, 0.15), 0 6px 16px rgba(61, 0, 139, 0.25); }
.btn-secondary { background: transparent; color: var(--violet); border: 1px solid var(--border); box-shadow: none; }
.btn-secondary:hover { background: var(--violet); color: #fff; border-color: var(--violet); }
.topbar .btn, .topbar a.btn { text-decoration: none; }
.topbar .btn-secondary:hover { background: var(--violet); color: #fff; border-color: var(--violet); transform: none; }
.btn-accent { background: var(--green); color: #fff; box-shadow: 0 4px 12px rgba(87, 191, 95, 0.25); }
.btn-accent:hover { background: #4aaf57; }
.btn-primary { 
  background: var(--violet); 
  color: #fff; 
  box-shadow: 0 4px 12px rgba(61, 0, 139, 0.25);
}
.btn-primary:hover { background: #4d019b; }
.btn-danger { background: #dc2626; color: #fff; box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 10.5px; font-size: 11.25px; }
/* New button variants */
.btn-outline { background: #fff; color: var(--violet); border: 1px solid var(--violet); box-shadow: none; }
.btn-outline:hover { background: rgba(61,0,139,0.06); }
.btn-ghost { background: transparent; color: var(--violet); border: none; box-shadow: none; }
.btn-ghost:hover { background: rgba(61,0,139,0.06); }
.btn-link { background: transparent; color: var(--violet); border: none; padding: 0; box-shadow: none; }
.btn-link:hover { text-decoration: underline; background: transparent; transform: none; box-shadow: none; }

/* Новые стили для контактов */
.contact-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  cursor: pointer;
}

.contact-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.contact-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.contact-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-name {
  font-weight: 600;
  color: var(--violet);
  font-size: 16px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-phone {
  color: #666;
  font-size: 14px;
  margin-bottom: 2px;
}

.contact-last-msg {
  color: #999;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.action-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.action-btn:hover {
  transform: scale(1.05);
}

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

.action-btn svg {
  width: 18px;
  height: 18px;
}

.wa-btn {
  background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
}

.tg-btn {
  background: linear-gradient(135deg, #0088cc 0%, #005580 100%);
}

.email-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.contact-groups, .contact-tags {
  margin-top: 8px;
  font-size: 12px;
}

.groups-label, .tags-label {
  color: #666;
  margin-right: 8px;
}

.group-tag, .tag {
  display: inline-block;
  background: #f0f0f0;
  color: #666;
  padding: 2px 6px;
  border-radius: 8px;
  margin-right: 4px;
  margin-bottom: 2px;
  font-size: 11px;
}

.group-tag {
  background: #e8f4f8;
  color: #0066cc;
}

.tag {
  background: #f8e8f0;
  color: #cc0066;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
  .contact-card {
    padding: 12px;
  }

  .contact-header {
    gap: 10px;
  }

  .contact-avatar {
    width: 50px;
    height: 50px;
    font-size: 18px;
  }

  .contact-name {
    font-size: 15px;
  }

  .contact-phone {
    font-size: 13px;
  }

  .contact-last-msg {
    font-size: 12px;
  }

  .action-btn {
    width: 32px;
    height: 32px;
  }

  .action-btn svg {
    width: 16px;
    height: 16px;
  }
}

.log { background: #0b0b0b; color: #f5f5f5; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; padding: 10px; border-radius: 10px; max-height: 220px; overflow: auto; }
.footer { padding: 16px; text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 80px; }

/* Card Grid Layout (bemulti-style) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.card-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
  min-height: 140px;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
}

.card-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(61, 0, 139, 0.12);
  border-color: var(--violet);
}

.card-item-disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.card-icon {
  font-size: 40px;
  margin-bottom: 8px;
  line-height: 1;
}

.card-icon-svg {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  display: block;
}

.card-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--violet);
  word-break: break-word;
}

.card-desc {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}

/* Adjust main content - no bottom nav */
.container {
  padding-bottom: 20px;
}

/* Larger screens */
@media (min-width: 640px) {
  .container { padding: 16px; }
}

/* Mobile: адаптация меню */
@media (max-width: 768px) {
  .topbar-nav {
    gap: 4px;
    padding-right: 8px;
    height: 80px;
    max-height: 80px;
  }
  .topbar-nav-link {
    padding: 6px 10px;
    font-size: 12px;
    height: 80px;
    max-height: 80px;
  }
  .topbar-logo {
    margin: 0 8px;
    height: 40px;
    width: 40px;
  }
  .topbar-logo img {
    height: 40px;
    width: 40px;
  }
  .topbar-logo strong {
    display: none;
  }
}

/* Top Navigation Menu */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  height: 80px;
  max-height: 80px;
}
.topbar-nav::-webkit-scrollbar {
  display: none;
}
.topbar-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--violet);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  height: 80px;
  max-height: 80px;
  box-sizing: border-box;
}
.topbar-nav-link:hover {
  background: rgba(61, 0, 139, 0.06);
  border-color: rgba(61, 0, 139, 0.1);
}
.topbar-nav-link.active {
  background: rgba(61, 0, 139, 0.12);
  color: var(--violet);
  border-color: rgba(61, 0, 139, 0.2);
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin: 0 16px;
  height: 40px;
  width: 40px;
  justify-content: center;
}
.topbar-logo img {
  height: 40px;
  width: 40px;
  border-radius: 8px;
  object-fit: contain;
}
.topbar-logo strong {
  font-size: 14px;
  color: var(--violet);
  font-weight: 600;
  display: none; /* Скрываем текст, оставляем только логотип 40x40 */
}

/* Sidebar - скрыт */
body.has-sidebar #sidebar {
  display: none;
}
body.has-sidebar.sidebar-open #sidebar { 
  display: none;
}
body.has-sidebar.sidebar-open { 
  margin-left: 0;
}

/* Sidebar footer with account info */
.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.account-info {
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-bottom: 8px;
}

.account-email {
  font-weight: 600;
  color: var(--violet);
  font-size: 14px;
  margin-bottom: 4px;
  word-break: break-all;
}

.account-time {
  font-size: 12px;
  color: var(--muted);
}

.logout-btn {
  width: 100%;
  background: #dc2626 !important;
  color: white !important;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s;
}

.logout-btn:hover {
  background: #b91c1c !important;
}

.logout-btn .nav-icon {
  font-size: 16px;
}

.logout-btn .nav-label {
  font-size: 14px;
}

/* Topbar navigation always visible */
body.has-sidebar .topbar .btn-secondary { display: none; }
#sidebar-toggle { display: none !important; }

#sidebar .nav-link { 
  display: flex; 
  align-items: center; 
  padding: 12px 16px; 
  border-radius: 8px; 
  color: var(--violet); 
  text-decoration: none; 
  font-weight: 600; 
  margin-bottom: 4px;
  transition: all 0.2s;
}
#sidebar .nav-link:hover { background: rgba(61,0,139,0.06); }
#sidebar .nav-link.active { background: rgba(61,0,139,0.12); }

#sidebar .nav-icon {
  font-size: 18px;
  margin-right: 12px;
  width: 20px;
  text-align: center;
}

#sidebar .nav-label {
  font-size: 14px;
  line-height: 1.2;
}

/* Kanban styles */
.kanban-column {
  min-width: 280px;
  max-width: 320px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 140px);
}

.kanban-header {
  padding: 12px 16px;
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.kanban-cards {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100px;
}

.kanban-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: move;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.kanban-card:hover {
  box-shadow: 0 4px 6px rgba(0,0,0,0.15);
  transform: translateY(-2px);
}

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

/* Mobile kanban */
@media (max-width: 768px) {
  .kanban-column {
    min-width: 260px;
    max-width: 280px;
  }
}

/* Chats list styles */
.chat-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  align-items: center;
}

.chat-item:hover {
  background: #f9fafb;
}

.chat-item:active {
  background: #f3f4f6;
}

.chat-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--violet);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
}

.chat-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.chat-name.unread {
  font-weight: 600;
  color: var(--violet);
}

.chat-time {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.chat-preview {
  display: flex;
  gap: 4px;
  align-items: center;
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-preview .unread {
  color: var(--text);
  font-weight: 500;
}

.chat-channel {
  font-size: 12px;
  flex-shrink: 0;
}

/* Mobile chat bubbles - улучшенное отображение */
@media (max-width: 768px) {
  .chat-bubble {
    max-width: calc(85vw - 32px) !important;
    font-size: 15px !important;
    line-height: 1.4 !important;
    white-space: pre-wrap !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
  }
  
  .chat-image {
    max-width: min(250px, 70vw) !important;
    max-height: 250px !important;
  }
  
  .message-container {
    margin: 12px 16px !important;
  }
  
  /* Улучшенные отступы для элементов сообщений */
  .hint {
    font-size: 11px !important;
    color: #8e8e93 !important;
  }
}

/* Tabs styles */
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 0;
}

.tab-btn:hover {
  color: var(--violet);
  background: rgba(61,0,139,0.04);
}

.tab-btn.active {
  color: var(--violet);
  border-bottom-color: var(--violet);
  background: rgba(61,0,139,0.08);
}

.tab-content {
  animation: fadeIn 0.3s;
}

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

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* Utilities: spacing & layout (mobile-first) */
.stack-xs > * + * { margin-top: 6px; }
.stack-sm > * + * { margin-top: 10px; }
.stack-md > * + * { margin-top: 14px; }
.stack-lg > * + * { margin-top: 18px; }
.section { padding: 16px 0; }
.surface-soft { background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius-md); }
.radius-sm { border-radius: var(--radius-sm) !important; }
.radius-md { border-radius: var(--radius-md) !important; }
.radius-lg { border-radius: var(--radius-lg) !important; }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow-md { box-shadow: var(--shadow-md) !important; }
.divider { height: 1px; background: var(--border); width: 100%; }

/* Larger screens polish */
@media (min-width: 1024px) {
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
}
