:root {
  --bg0: #080b14;
  --bg1: #0d1117;
  --bg2: #161b27;
  --bg3: #1e2536;
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-glow: rgba(99,102,241,0.3);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text1: #f1f5f9;
  --text2: #94a3b8;
  --text3: #475569;
  --gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --gradient-hover: linear-gradient(135deg, #4f46e5, #7c3aed);
  --card-shadow: 0 4px 24px rgba(0,0,0,0.4);
  --card-shadow-hover: 0 8px 40px rgba(0,0,0,0.6);

  /* Legacy aliases for inline styles that reference old var names */
  --bg: var(--bg0);
  --text: var(--text1);
  --accent: var(--primary);
  --accent2: #8b5cf6;
  --border2: var(--border-hover);
  --radius: 10px;
  --radius-lg: 16px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg0);
  color: var(--text1);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ── LAYOUT ── */
.layout,
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width 0.3s ease;
  overflow: hidden;
}

.sidebar-logo {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.logo-icon,
.sidebar-logo-icon {
  width: 36px; height: 36px;
  background: var(--gradient);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.logo-text,
.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-user {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text3);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-user-name {
  color: var(--text2);
  font-weight: 500;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  border-radius: 0;
  transition: all 0.2s;
  color: var(--text2);
  font-size: 14px;
  font-weight: 500;
  position: relative;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text1);
}

.nav-item.active {
  background: rgba(99,102,241,0.12);
  color: var(--primary);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gradient);
  border-radius: 0 3px 3px 0;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  margin-top: 8px;
}

.nav-group:first-child { margin-top: 0; }

.nav-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 100%;
  text-align: left;
  transition: color 0.2s, background 0.2s;
}

.nav-group-header:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text2);
}

.nav-group-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-group-title { flex: 1; }

.nav-group-chevron {
  margin-left: auto;
  font-size: 12px;
  color: var(--text3);
  transition: transform 0.2s;
  transform: rotate(0deg);
}

.nav-group.collapsed .nav-group-chevron {
  transform: rotate(-90deg);
}

.nav-group.collapsed .nav-group-items {
  display: none;
}

.nav-group-items {
  display: flex;
  flex-direction: column;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text3);
}

.sidebar-stats { display: flex; gap: 16px; }

.ss-item,
.stat-item {
  flex: 1;
  background: var(--bg2);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.ss-item span,
.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text1);
  display: block;
}

.ss-item small,
.stat-label {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── MAIN CONTENT ── */
.main-content {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
  background: var(--bg0);
  overflow-y: auto;
}

.page {
  display: none;
  padding: 32px;
  max-width: 1400px;
  animation: fadeIn 0.3s ease;
}

.page.active { display: block; }

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

/* ── PAGE HEADER ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-sub {
  font-size: 14px;
  color: var(--text2);
  margin-top: 4px;
}

/* ── CARDS ── */
.card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  transition: all 0.2s ease;
  box-shadow: var(--card-shadow);
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--card-shadow-hover);
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  margin-bottom: 16px;
}

/* ── STATS ROW ── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  transition: all 0.2s ease;
  box-shadow: var(--card-shadow);
}
.stat-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--card-shadow-hover);
}
.stat-card .label { font-size: 11px; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .value.accent { color: var(--primary); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }
.stat-card .value.danger { color: var(--danger); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  text-decoration: none;
  font-family: inherit;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.2s;
}

.btn:hover::after { background: rgba(255,255,255,0.06); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px var(--primary-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg2);
  color: var(--text1);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  background: var(--bg3);
}

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.2);
}

.btn-danger:hover {
  background: rgba(239,68,68,0.25);
}

.btn-success {
  background: rgba(34,197,94,0.15);
  color: var(--success);
  border: 1px solid rgba(34,197,94,0.2);
}

.btn-success:hover {
  background: rgba(34,197,94,0.25);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 8px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ── FORMS ── */
.form-group {
  margin-bottom: 14px;
}

.form-group label,
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-label .req { color: var(--danger); margin-left: 2px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text1);
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  background: rgba(99,102,241,0.06);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

input::placeholder, textarea::placeholder { color: var(--text3); }
textarea { resize: vertical; min-height: 90px; line-height: 1.6; }

select option {
  background: var(--bg2);
  color: var(--text1);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Layout: основная форма + боковая панель (Отправка, Парсер) */
.sender-layout { display: flex; gap: 12px; align-items: flex-start; }
.sender-main { flex: 1; min-width: 0; }
.sender-side { width: 340px; flex-shrink: 0; }

.parser-layout { display: flex; gap: 20px; align-items: flex-start; }
.parser-side { width: 320px; flex-shrink: 0; }
.parser-main { flex: 1; min-width: 0; }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-primary { background: rgba(99,102,241,0.15); color: var(--primary); }
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info { background: rgba(99,102,241,0.15); color: var(--primary); }
.badge-gray { background: var(--bg3); color: var(--text2); }

/* ── TOASTS ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  max-width: 320px;
  animation: toastIn 0.3s ease;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-success, .toast.success { background: rgba(34,197,94,0.15); border-color: rgba(34,197,94,0.3); color: var(--success); }
.toast-error, .toast.error { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.3); color: var(--danger); }
.toast-info { background: rgba(99,102,241,0.15); border-color: rgba(99,102,241,0.3); color: var(--primary); }

/* Legacy toast (single element) */
.toast.show { transform: translateY(0); opacity: 1; }

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

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 900;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--bg1);
  border: 1px solid var(--border-hover);
  border-radius: 16px;
  padding: 24px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── SKELETON LOADING ── */
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
  border-radius: 8px;
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── PROGRESS BAR ── */
.progress {
  height: 4px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 3px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill,
.progress-bar > div {
  height: 100%;
  background: var(--gradient);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.progress-fill-animated {
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent2) 50%, var(--primary) 100%);
  background-size: 200% 100%;
  animation: progressPulse 1.5s ease infinite;
}
@keyframes progressPulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
.table, table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th, th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
}

.table td, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  font-size: 13px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ── MESSAGES GRID ── */
.messages-grid { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.msg-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  transition: border-color 0.2s;
}
.msg-card:hover { border-color: var(--border-hover); }
.msg-num { font-size: 11px; color: var(--text3); margin-bottom: 5px; }
.msg-text { font-size: 13px; line-height: 1.65; color: var(--text1); }
.msg-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ── LISTINGS GRID ── */
.listings-grid { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.listing-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.2s;
}
.listing-card:hover { border-color: var(--border-hover); }
.listing-check { flex-shrink: 0; }
.listing-info { flex: 1; min-width: 0; }
.listing-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.listing-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.listing-price { font-size: 13px; font-weight: 600; color: var(--primary); flex-shrink: 0; }

/* ── INBOX ── */
.inbox-list { display: flex; flex-direction: column; gap: 4px; }

.inbox-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.inbox-item:hover { background: var(--bg2); }
.inbox-item-unread {
  background: rgba(99,102,241,0.06);
  border-color: var(--border);
}
.inbox-item-unread .inbox-sender { font-weight: 600; color: var(--text1); }
.inbox-item-unread .inbox-message-preview { color: var(--text1); }

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

.inbox-item-body { flex: 1; min-width: 0; }
.inbox-item-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.inbox-sender { font-size: 13px; font-weight: 500; }
.inbox-date { font-size: 11px; color: var(--text3); white-space: nowrap; }

.inbox-listing { margin-bottom: 2px; }
.inbox-listing a { font-size: 12px; color: var(--primary); text-decoration: none; }
.inbox-listing a:hover { text-decoration: underline; }

.inbox-message-preview {
  font-size: 13px; color: var(--text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.inbox-item-footer { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.inbox-account-tag {
  font-size: 10px; color: var(--text3);
  background: var(--bg2); padding: 2px 8px;
  border-radius: 10px;
}

.inbox-unread-counter {
  font-size: 13px; font-weight: 500;
  color: var(--primary);
}

.inbox-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-hover);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── CHECKBOX ── */
input[type=checkbox] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── RANGE ── */
input[type=range] {
  background: transparent;
  border: none;
  padding: 0;
  accent-color: var(--primary);
}

/* ── UTILS ── */
.count-row { display: flex; align-items: center; gap: 10px; }
.count-row label { font-size: 13px; color: var(--text2); white-space: nowrap; }
.count-val { font-size: 13px; font-weight: 600; min-width: 24px; text-align: right; }

.section-actions { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.mt-12 { margin-top: 12px; }

/* ── MOBILE ── */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }

  .sender-layout, .parser-layout { flex-direction: column; gap: 12px; }
  .sender-side, .parser-side, .parser-main { width: 100%; }

  .table-wrap { margin: 0 -12px; padding: 0 12px; }

  .sidebar {
    width: 100%;
    height: 64px;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    background: rgba(13,17,23,0.95);
    backdrop-filter: blur(20px);
    z-index: 1000;
  }

  .sidebar-logo,
  .sidebar-user,
  .sidebar-footer { display: none; }

  .sidebar-nav {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    padding: 0 8px;
    align-items: center;
    justify-content: space-around;
    width: 100%;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .sidebar-nav::-webkit-scrollbar { display: none; }

  /* На мобильных группировка отключена — пункты снова прямые дети sidebar-nav */
  .nav-group-header { display: none; }
  .nav-group,
  .nav-group-items,
  .nav-group.collapsed .nav-group-items {
    display: contents;
  }

  .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 6px 10px;
    font-size: 10px;
    min-width: 56px;
    max-width: 72px;
    align-items: center;
    border-radius: 10px;
    flex-shrink: 0;
  }

  .nav-item span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    text-align: center;
  }

  .nav-item.active::before { display: none; }

  .nav-item.active {
    background: rgba(99,102,241,0.15);
    color: var(--primary);
  }

  .nav-icon {
    font-size: 22px;
    width: auto;
    line-height: 1;
  }

  .main-content {
    margin-left: 0;
    padding-bottom: 64px;
  }

  .page { padding: 12px; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
  }

  .page-title { font-size: 20px; }

  .card {
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 12px;
  }

  /* Большие touch-friendly кнопки */
  .btn {
    padding: 12px 16px;
    min-height: 46px;
    border-radius: 12px;
  }

  .btn-sm {
    min-height: 38px;
    padding: 8px 12px;
  }

  /* Карточки лидов в одну колонку */
  .crm-columns {
    flex-direction: column !important;
    gap: 12px !important;
  }
  .crm-columns > div { width: 100% !important; }

  /* CRM карточки — кнопки на всю ширину */
  .crm-card-actions {
    flex-direction: column !important;
  }
  .crm-card-actions .btn,
  .crm-card-actions a {
    width: 100% !important;
    justify-content: center;
  }

  /* Work карточки — кнопки на всю ширину */
  .work-card-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
  }
  .work-card-actions .btn {
    width: 100% !important;
    min-height: 46px;
    justify-content: center;
  }

  /* Inbox — мобильный диалог поверх списка */
  .inbox-layout {
    height: calc(100vh - 80px) !important;
    border: none !important;
    border-radius: 0 !important;
  }

  #inbox-dialogs-panel {
    width: 100% !important;
    border-right: none !important;
  }

  .inbox-mobile-open #inbox-dialogs-panel {
    display: none !important;
  }

  .inbox-mobile-open > div:last-child {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 64px;
    background: var(--bg0);
    z-index: 200;
    display: flex !important;
    flex-direction: column;
  }

  /* Инпуты крупнее на мобиле */
  input, select, textarea {
    font-size: 16px !important; /* предотвращает zoom на iOS */
    padding: 12px 14px;
    min-height: 46px;
  }

  /* Таблицы скроллятся горизонтально */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Модальные формы на весь экран */
  .modal {
    margin: 0;
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 64px;
    left: 0;
    right: 0;
  }

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

@media (max-width: 380px) {
  .nav-item { min-width: 48px; padding: 6px 6px; }
  .nav-item span:last-child { display: none; }
  .nav-icon { font-size: 24px; }

  .stats-row { grid-template-columns: 1fr; }
}

/* ── ANIMATIONS ── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-pulse { animation: pulse 2s infinite; }
.animate-spin { animation: spin 0.7s linear infinite; }

/* ── GLASSMORPHISM CARDS ── */
.card-glass {
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
}

/* ── GRADIENT TEXT ── */
.gradient-text {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}

.empty-state .icon,
.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p,
.empty-state-text {
  font-size: 16px;
  color: var(--text2);
  margin-bottom: 8px;
}

.empty-state-sub {
  font-size: 14px;
  color: var(--text3);
}

/* ── DIVIDER ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── TEXT UTILS ── */
.text-sm { font-size: 12px; }
.text-muted { color: var(--text2); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

/* ── INVENTORY ── */
.inv-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.inv-tab {
  padding: 8px 14px;
  background: var(--bg2);
  color: var(--text1);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, border-color .12s;
}
.inv-tab:hover { border-color: var(--border-hover); }
.inv-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.inv-card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .12s, transform .12s;
}
.inv-card:hover { border-color: var(--border-hover); }
.inv-preview {
  aspect-ratio: 4/3;
  background: var(--bg2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.inv-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.inv-preview-empty {
  font-size: 64px;
  opacity: 0.3;
}
.inv-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.inv-cat {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.inv-title {
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.3;
}
.inv-title:hover { color: var(--primary); }
.inv-comment {
  font-size: 12px;
  color: var(--text2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.inv-prices {
  font-size: 13px;
  color: var(--success);
  font-weight: 500;
}
.inv-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 8px;
  flex-wrap: wrap;
}
.inv-actions .btn { font-size: 11px; padding: 5px 10px; }

.inv-view-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.inv-view-photos img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}
.inv-row {
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 8px;
  color: var(--text1);
}

.inv-photos-edit {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 6px;
}
.inv-photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg2);
}
.inv-photo-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.inv-photo-thumb button {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: none;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.inv-photo-thumb button:hover { background: var(--danger); }

/* ── CHAT ── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 160px);
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 80%;
}
.chat-msg.me {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.chat-bubble-wrap { min-width: 0; }
.chat-meta {
  display: flex; gap: 6px; align-items: center;
  font-size: 11px; color: var(--text3);
  margin-bottom: 3px;
}
.chat-msg.me .chat-meta { justify-content: flex-end; }
.chat-name { font-weight: 600; color: var(--text2); }
.chat-time { color: var(--text3); }
.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--bg2);
  color: var(--text1);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}
.chat-msg.me .chat-bubble {
  background: var(--primary);
  color: #fff;
}
.chat-lead-chip {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  background: rgba(99,102,241,0.15);
  border: 1px solid var(--primary);
  border-radius: 8px;
  font-size: 11px;
  color: var(--primary);
  text-decoration: none;
}
.chat-lead-chip:hover { background: rgba(99,102,241,0.25); }
.chat-lead-banner {
  padding: 10px 16px;
  background: rgba(99,102,241,0.15);
  border-top: 1px solid var(--border);
  color: var(--text1);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chat-lead-cancel {
  background: none; border: none; color: var(--text2);
  font-size: 16px; cursor: pointer; padding: 0 4px;
}
.chat-lead-cancel:hover { color: var(--text1); }
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}
.chat-input-area textarea {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg1);
  color: var(--text1);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  resize: none;
  font-family: inherit;
}
.chat-input-area textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.chat-input-area button {
  align-self: stretch;
  padding: 0 20px;
}
.chat-photos {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 4px;
  max-width: 360px;
}
.chat-photos a {
  display: block;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg2);
}
.chat-photos img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}
.chat-msg.me .chat-photos { justify-self: end; }

.chat-pending-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}
.chat-pending-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg1);
}
.chat-pending-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.chat-pending-thumb button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-pending-thumb button:hover { background: var(--danger); }

.chat-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
  color: var(--text2);
  flex-shrink: 0;
}
.chat-attach-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

@media (max-width: 640px) {
  .chat-container { height: calc(100vh - 140px); }
  .chat-msg { max-width: 92%; }
  .chat-photos { max-width: 100%; }
}

/* ── DATETIME PICKER ── */
.dt-trigger { font-weight: 500; }
.dt-value {
  font-size: 12px;
  color: var(--success);
  font-weight: 500;
}

.dt-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg1);
}
.dt-preset {
  font-size: 12px;
  padding: 5px 10px;
  background: var(--bg2);
  color: var(--text1);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.dt-preset:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.dt-ok-row {
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--bg1);
}
.dt-ok {
  width: 100%;
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}
.dt-ok:hover { background: var(--primary-dark); }

/* ── FLATPICKR DARK THEME ── */
.flatpickr-calendar {
  background: var(--bg2);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  color: var(--text1);
}
.flatpickr-calendar.arrowTop:before,
.flatpickr-calendar.arrowTop:after,
.flatpickr-calendar.arrowBottom:before,
.flatpickr-calendar.arrowBottom:after { display: none; }
.flatpickr-months,
.flatpickr-month,
.flatpickr-current-month,
.flatpickr-monthDropdown-months,
.flatpickr-weekdays,
span.flatpickr-weekday {
  background: var(--bg2);
  color: var(--text1);
  fill: var(--text1);
}
.flatpickr-current-month .numInputWrapper:hover,
.flatpickr-current-month input.cur-year { color: var(--text1); }
.flatpickr-monthDropdown-months .flatpickr-monthDropdown-month { background: var(--bg2); }
span.flatpickr-weekday { color: var(--text2); font-weight: 500; }
.flatpickr-prev-month,
.flatpickr-next-month { color: var(--text2); fill: var(--text2); }
.flatpickr-prev-month:hover svg,
.flatpickr-next-month:hover svg { fill: var(--primary); }
.flatpickr-days,
.dayContainer { background: var(--bg2); }
.flatpickr-day {
  color: var(--text1);
  border-radius: 6px;
}
.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay,
.flatpickr-day.flatpickr-disabled,
.flatpickr-day.flatpickr-disabled:hover { color: var(--text3); }
.flatpickr-day:hover,
.flatpickr-day.today:hover {
  background: var(--bg1);
  border-color: var(--border-hover);
}
.flatpickr-day.today {
  border-color: var(--primary);
  color: var(--primary);
}
.flatpickr-day.selected,
.flatpickr-day.selected:hover,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.flatpickr-time {
  background: var(--bg1);
  border-top: 1px solid var(--border);
}
.flatpickr-time input,
.flatpickr-time .flatpickr-time-separator,
.flatpickr-time .flatpickr-am-pm {
  color: var(--text1);
  background: transparent;
}
.flatpickr-time input:hover,
.flatpickr-time input:focus,
.flatpickr-time .flatpickr-am-pm:hover,
.flatpickr-time .flatpickr-am-pm:focus { background: var(--bg2); }
.flatpickr-time .numInputWrapper span.arrowUp:after { border-bottom-color: var(--text2); }
.flatpickr-time .numInputWrapper span.arrowDown:after { border-top-color: var(--text2); }

@media (max-width: 640px) {
  .flatpickr-calendar.open {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    top: 10px !important;
    width: auto !important;
    max-width: none !important;
    max-height: calc(100vh - 20px);
    overflow: auto;
    z-index: 10000;
  }
  .flatpickr-calendar.arrowTop:before,
  .flatpickr-calendar.arrowTop:after,
  .flatpickr-calendar.arrowBottom:before,
  .flatpickr-calendar.arrowBottom:after { display: none !important; }
  .dt-preset { padding: 8px 12px; font-size: 13px; }
}
