/* ══════════════════════════════════════════════════════════════
   AI Leads Portal — Design Tokens & Styles
   Based on UI_DESIGN.md specification
   ══════════════════════════════════════════════════════════════ */

:root {
  /* Базовые */
  --color-bg:           #F8F9FB;
  --color-surface:      #FFFFFF;
  --color-border:       #E8EBF0;
  --color-border-hover: #C8CDD8;

  /* Текст */
  --color-text-primary:   #111827;
  --color-text-secondary: #6B7280;
  --color-text-muted:     #9CA3AF;

  /* Акцент — синий */
  --color-blue-50:  #EFF6FF;
  --color-blue-100: #DBEAFE;
  --color-blue-500: #3B82F6;
  --color-blue-600: #2563EB;
  --color-blue-700: #1D4ED8;

  /* Статусы */
  --color-green:  #10B981;
  --color-yellow: #F59E0B;
  --color-red:    #EF4444;
  --color-gray:   #9CA3AF;

  /* Дополнительные цвета для badge bg */
  --color-green-50:  #ECFDF5;
  --color-blue-bg:   #EFF6FF;
  --color-yellow-50: #FFFBEB;
  --color-red-50:    #FEF2F2;
  --color-gray-100:  #F3F4F6;

  /* Типографика */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Скругления */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;

  /* Тени */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.10);

  --transition: 150ms ease;
}

/* ── Reset & Base ───────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-blue-500);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover {
  color: var(--color-blue-600);
}

/* ── Layout ─────────────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 20px 16px 12px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 28px;
  height: 28px;
  background: var(--color-blue-500);
  border-radius: 8px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 10px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.nav-item.active {
  background: var(--color-blue-50);
  color: var(--color-blue-600);
  border-left: 2px solid var(--color-blue-500);
  font-weight: 600;
}

.nav-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.nav-separator {
  height: 1px;
  background: var(--color-border);
  margin: 8px 12px;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--color-border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: var(--color-blue-100);
  color: var(--color-blue-600);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.user-info {
  flex: 1;
  min-width: 0;
}

.btn-logout {
  color: var(--color-text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn-logout:hover {
  color: var(--color-red);
  background: var(--color-red-50);
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 150;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* ── Main Content ───────────────────────────────────────────── */

.main-content {
  flex: 1;
  margin-left: 220px;
  padding: 24px 28px;
  min-width: 0;
}

/* ── Page Title Bar ─────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header-left {
  flex: 1;
  min-width: 0;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0 0 4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: 0;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Cards ──────────────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-body {
  padding: 20px 24px;
}

.card-header-custom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--color-border);
}

.card-title-custom {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0;
}

/* ── Stat Cards (Dashboard) ─────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.2;
}

.stat-meta {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

/* ── Buttons ────────────────────────────────────────────────── */

.btn-primary-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-blue-500);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-primary-custom:hover {
  background: var(--color-blue-600);
  color: #fff;
}

.btn-secondary-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-secondary-custom:hover {
  background: var(--color-bg);
  border-color: var(--color-border-hover);
  color: var(--color-text-primary);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  border: none;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 400;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-ghost:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-red-50);
  color: #DC2626;
  border: 1px solid #FECACA;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-danger:hover {
  background: #FEE2E2;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

/* ── Badges / Status ────────────────────────────────────────── */

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

.badge-new {
  background: var(--color-green-50);
  color: var(--color-green);
}

.badge-in-progress {
  background: var(--color-blue-bg);
  color: var(--color-blue-500);
}

.badge-contacted {
  background: var(--color-yellow-50);
  color: #D97706;
}

.badge-archived {
  background: var(--color-gray-100);
  color: var(--color-gray);
}

.badge-active {
  background: var(--color-green-50);
  color: var(--color-green);
}

.badge-inactive {
  background: var(--color-gray-100);
  color: var(--color-gray);
}

.badge-confidence {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}

.badge-conf-green {
  background: var(--color-green-50);
  color: var(--color-green);
}

.badge-conf-blue {
  background: var(--color-blue-bg);
  color: var(--color-blue-500);
}

.badge-conf-yellow {
  background: var(--color-yellow-50);
  color: #D97706;
}

.badge-conf-red {
  background: var(--color-red-50);
  color: var(--color-red);
}

/* Pulse dot for new leads */
.pulse-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--color-green);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.5); }
}

/* ── Tables ─────────────────────────────────────────────────── */

.table-custom {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-custom thead th {
  padding: 16px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  text-align: center;
}

.table-custom tbody td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  text-align: center;
}

.table-custom tbody tr {
  transition: background var(--transition);
}

.table-custom tbody tr:hover {
  background: var(--color-bg);
}

.table-custom tbody tr:last-child td {
  border-bottom: none;
}

.table-user-link {
  font-weight: 500;
  color: var(--color-text-primary);
}

.table-meta {
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* ── Forms ──────────────────────────────────────────────────── */

.form-control-custom {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--color-text-primary);
  background: var(--color-surface);
  transition: all var(--transition);
  width: 100%;
}

.form-control-custom::placeholder {
  color: var(--color-text-muted);
}

.form-control-custom:focus {
  outline: none;
  border-color: var(--color-blue-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-label-custom {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: 4px;
  display: block;
}

textarea.form-control-custom {
  min-height: 120px;
  resize: vertical;
}

textarea.prompt-editor {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  min-height: 200px;
}

.form-select-custom {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--color-text-primary);
  background: var(--color-surface);
  transition: all var(--transition);
}

.form-select-custom:focus {
  outline: none;
  border-color: var(--color-blue-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* ── Filters bar ────────────────────────────────────────────── */

.filters-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.filter-select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: var(--font-family);
  font-size: 13px;
  color: var(--color-text-primary);
  background: var(--color-surface);
  min-width: 140px;
}

.filter-label {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-left: auto;
}

/* ── Drawer ─────────────────────────────────────────────────── */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 250;
  transform: translateX(100%);
  transition: transform 200ms ease-out;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border);
}

.drawer-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.drawer-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.drawer-close:hover {
  color: var(--color-text-primary);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.drawer-field {
  margin-bottom: 16px;
}

.drawer-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.drawer-value {
  font-size: 14px;
  color: var(--color-text-primary);
}

.drawer-message {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.6;
  border-left: 3px solid var(--color-blue-500);
}

.drawer-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

/* ── Toast Notifications ────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  animation: toast-slide-in 200ms ease-out;
  min-width: 280px;
  max-width: 400px;
}

.toast-success {
  background: var(--color-green-50);
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.toast-error {
  background: var(--color-red-50);
  color: #991B1B;
  border: 1px solid #FECACA;
}

.toast-warning {
  background: var(--color-yellow-50);
  color: #92400E;
  border: 1px solid #FDE68A;
}

.toast-info {
  background: var(--color-blue-bg);
  color: #1E40AF;
  border: 1px solid #BFDBFE;
}

.toast-close {
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  margin-left: auto;
  opacity: 0.6;
}
.toast-close:hover {
  opacity: 1;
}

@keyframes toast-slide-in {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── Empty State ────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 24px;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.3;
}

.empty-state-text {
  font-size: 15px;
  color: var(--color-text-secondary);
  margin-bottom: 16px;
}

/* ── Confidence Bar ─────────────────────────────────────────── */

.confidence-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.confidence-track {
  flex: 1;
  height: 6px;
  background: var(--color-bg);
  border-radius: 99px;
  overflow: hidden;
  max-width: 100px;
}

.confidence-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 300ms ease;
}

.confidence-fill-green { background: var(--color-green); }
.confidence-fill-blue  { background: var(--color-blue-500); }
.confidence-fill-yellow { background: var(--color-yellow); }
.confidence-fill-red   { background: var(--color-red); }

/* ── Double-column content grid ─────────────────────────────── */

.content-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
}

/* ── List items (niche list, account cards) ──────────────────── */

.list-item {
  display: flex;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

.list-item:hover {
  background: var(--color-bg);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-icon {
  font-size: 20px;
  margin-right: 14px;
  opacity: 0.6;
}

.list-item-content {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.list-item-meta {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.list-item-badge {
  margin-left: 12px;
}

/* ── Account card ───────────────────────────────────────────── */

.account-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 12px;
  transition: all var(--transition);
}

.account-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.account-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.account-card-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-card-meta {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* ── Login page ─────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 24px;
  color: var(--color-text-primary);
}

.login-error {
  background: var(--color-red-50);
  color: #991B1B;
  border: 1px solid #FECACA;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-top: 56px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-header {
    flex-direction: column;
  }

  .drawer {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .filters-bar {
    flex-direction: column;
    align-items: stretch;
  }
}
