/* CRM — Стили */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --error: #dc2626;
  --sidebar-bg: #1e293b;
  --sidebar-width: 240px;
  --header-h: 60px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: #1e293b;
  background: #f1f5f9;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.login-box {
  background: #fff;
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 360px;
}

.login-logo-wrap {
  background: #1e293b;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0 auto 1.5rem;
  text-align: center;
}
.login-logo {
  display: block;
  max-width: 180px;
  max-height: 64px;
  margin: 0 auto;
  object-fit: contain;
}

.login-box h1 {
  margin: 0 0 .25rem;
  font-size: 1.5rem;
  color: #0f172a;
  font-family: var(--font);
}

.login-subtitle {
  margin: 0 0 1.5rem;
  color: #64748b;
  font-size: .9rem;
}

.login-contact {
  margin: 1.25rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid #e2e8f0;
  font-size: 0.75rem;
  color: #94a3b8;
  text-align: center;
  line-height: 1.4;
}

/* Language switcher */
.lang-switcher-wrap {
  font-size: 0.85rem;
}
.lang-switcher-login {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 10;
}
.lang-switcher-login .lang-link {
  color: rgba(255,255,255,.85);
  text-decoration: none;
}
.lang-switcher-login .lang-link:hover,
.lang-switcher-login .lang-link.active {
  color: #fff;
  text-decoration: underline;
}
.lang-switcher-login .lang-sep {
  color: rgba(255,255,255,.5);
  margin: 0 .35rem;
}
.lang-switcher-sidebar {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.lang-switcher-sidebar .lang-link {
  color: #94a3b8;
  text-decoration: none;
  font-size: .8rem;
}
.lang-switcher-sidebar .lang-link:hover {
  color: #fff;
}
.lang-switcher-sidebar .lang-link.active {
  color: #fff;
  font-weight: 600;
}
.lang-switcher-sidebar .lang-sep {
  color: #64748b;
  margin: 0 .25rem;
  font-size: .8rem;
}

/* Layout: Sidebar + Main */
.mobile-header {
  display: none;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 10002;
  background: var(--sidebar-bg);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.sidebar-logo {
  display: block;
  max-width: 100%;
  max-height: 48px;
  margin: 1rem 1rem 0;
  padding: 0 0.5rem;
  object-fit: contain;
}

.sidebar-nav {
  flex: 1;
  padding: 1.5rem 0;
}

.sidebar-nav a {
  display: block;
  padding: .75rem 1.5rem;
  color: #94a3b8;
  text-decoration: none;
  transition: background .2s, color .2s;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,.05);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-feedback {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: #94a3b8;
  line-height: 1.4;
}

.logout-link {
  color: #94a3b8;
  text-decoration: none;
  font-size: .9rem;
}

.logout-link:hover {
  color: #fff;
}

.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: 0.75rem 1.5rem 1.5rem;
}

.main-content h1:first-of-type {
  margin-top: 0;
  margin-bottom: 1rem;
}

.main-content .page-subtitle {
  font-size: 1.1rem;
  color: #64748b;
  margin: -0.5rem 0 1rem;
  font-weight: 500;
}

/* Alerts */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: .5rem 1rem;
  font-size: .95rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background .2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: #64748b;
  color: #fff;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-sm {
  padding: .25rem .5rem;
  font-size: .85rem;
}

.btn-edit,
.btn-icon.btn-edit {
  background: #3b82f6;
  color: #fff;
}

.btn-delete,
.btn-icon.btn-delete {
  background: #dc2626;
  color: #fff;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .35rem;
  min-width: 32px;
  min-height: 32px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  vertical-align: middle;
}

.btn-icon .icon {
  display: block;
}

.col-checkbox {
  width: 2.5rem;
  text-align: center;
}

.col-actions {
  white-space: nowrap;
}

.col-actions .btn-icon + .inline-form,
.col-actions .inline-form {
  margin-left: .25rem;
}

.inline-form {
  display: inline;
  margin-left: .25rem;
}

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: #fff;
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.kpi-label {
  font-size: .9rem;
  color: #64748b;
}

/* Dashboard */
.dashboard-section {
  background: #fff;
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.dashboard-section h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: #334155;
}

.conversion-block {
  display: flex;
  align-items: baseline;
  gap: .5rem;
}

.conversion-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--success);
}

.conversion-detail {
  color: #64748b;
  font-size: .95rem;
}

.status-stats {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
}

.status-stat-item {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.status-count {
  font-weight: 600;
  color: #334155;
}

.bar-chart {
  display: grid;
  gap: .75rem;
  margin-bottom: 1rem;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 220px) 1fr 56px;
  gap: .75rem;
  align-items: center;
}

.bar-label,
.bar-value {
  font-size: .9rem;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-value {
  text-align: right;
  font-weight: 600;
}

.bar-track {
  height: 12px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb 0%, #60a5fa 100%);
}

.stats-split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.stats-table {
  table-layout: auto;
}

@media (max-width: 640px) {
  .bar-row {
    grid-template-columns: 1fr;
    gap: .35rem;
  }

  .bar-value {
    text-align: left;
  }
}

/* Badges */
.badge {
  display: inline-block;
  padding: .2rem .5rem;
  font-size: .8rem;
  border-radius: 4px;
  white-space: nowrap;
}

.status-new { background: #e2e8f0; color: #475569; }
.status-progress { background: #dbeafe; color: #1d4ed8; }
.status-callback { background: #fef3c7; color: #b45309; }
.status-done { background: #d1fae5; color: #059669; }
.status-refused { background: #fee2e2; color: #dc2626; }
.status-sale { background: #d1fae5; color: #047857; font-weight: 600; }
.status-default { background: #f1f5f9; color: #64748b; }

/* CRM */
.crm-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.crm-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-left: auto;
}

.crm-filters input,
.crm-filters select {
  padding: .5rem .75rem;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius);
  font-size: .95rem;
}

.crm-filters input {
  min-width: 200px;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  padding: .75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.data-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  font-size: .9rem;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.cell-comment {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pagination a {
  color: var(--primary);
  text-decoration: none;
}

.pagination a:hover {
  text-decoration: underline;
}

.pagination-info {
  color: #64748b;
  font-size: .9rem;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: .35rem;
  font-weight: 500;
  color: #334155;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
}

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

.form-hint {
  font-size: 0.85rem;
  color: #64748b;
  margin: 0 0 1rem;
}

.mock-hint {
  margin-top: 0;
}

input.input-readonly,
input[readonly] {
  background: #f1f5f9;
  color: #475569;
  cursor: not-allowed;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: #fff;
  padding: 1.5rem;
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-content-wide {
  max-width: 640px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .form-row {
    grid-template-columns: 1fr;
  }

  .lead-view-grid {
    grid-template-columns: 1fr;
  }
}

.history-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 0.75rem;
  background: #f8fafc;
  margin-bottom: 0.5rem;
}

.history-item + .history-item {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e2e8f0;
}

.history-meta {
  font-size: 0.75rem;
  color: #64748b;
  margin-bottom: 0.25rem;
}

.history-text {
  font-size: 0.9rem;
  color: #1e293b;
  white-space: pre-wrap;
}

.history-empty {
  margin: 0;
  color: #94a3b8;
  font-size: 0.85rem;
}

.lead-view-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.lead-view-item {
  padding: 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  background: #f8fafc;
}

.lead-view-item span {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.8rem;
  color: #64748b;
}

.lead-view-item strong {
  display: block;
  color: #1e293b;
  font-size: 0.95rem;
  line-height: 1.4;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: #64748b;
  line-height: 1;
}

.modal-close:hover {
  color: #1e293b;
}

.modal-content h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

/* Mobile */
@media (max-width: 768px) {
  .mobile-header {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    z-index: 99999;
    background: transparent;
    padding: 0 0 0 0.5rem;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    top: auto;
    left: auto;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    box-shadow: var(--shadow);
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .3s;
    z-index: 10001;
    top: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding-top: 52px;
    position: relative;
    z-index: 0;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .crm-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .crm-toolbar .btn-export {
    display: block;
    text-align: center;
  }

  .crm-filters {
    margin-left: 0;
  }

  .crm-filters input {
    min-width: 100%;
  }

  .data-table th,
  .data-table td {
    padding: .5rem;
    font-size: .9rem;
  }

  .cell-comment {
    max-width: 120px;
  }

  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tbody tr.lead-row {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 0.25rem 0;
    cursor: pointer;
  }

  .data-table tbody tr.lead-row:hover {
    background: #f8fafc;
  }

  .data-table tbody tr.lead-row td {
    display: none;
    border-bottom: none;
    padding: 0;
  }

  .data-table tbody tr.lead-row td.mobile-phone-cell {
    display: block;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
  }

  .data-table tbody tr.lead-row td.mobile-phone-cell::after {
    content: '›';
    float: right;
    color: #94a3b8;
    font-size: 1.2rem;
  }

  .data-table tbody tr:not(.lead-row) td {
    display: table-cell;
  }
}
