/* === TOKENS === */
:root {
  --color-primary: #2563EB;
  --color-primary-dark: #1D4ED8;
  --color-primary-light: #DBEAFE;
  --color-success: #10B981;
  --color-danger: #EF4444;
  --color-warning: #F59E0B;
  --color-text: #0F172A;
  --color-text-muted: #64748B;
  --color-bg: #F1F5F9;
  --color-surface: #FFFFFF;
  --color-border: #E2E8F0;

  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --font-size-page-title: 24px;
  --font-size-section-title: 18px;
  --font-size-body: 14px;
  --font-size-caption: 13px;
  --font-size-label: 11px;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  background: var(--color-primary);
  color: #fff;
}
.btn:hover { background: var(--color-primary-dark); }
.btn-outline {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
  padding: 8px 18px;
}
.btn-outline:hover { background: var(--color-primary-light); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-ghost { background: var(--color-bg); color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-border); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: var(--font-size-caption); }

/* === TRANSITIONS & ANIMATIONS === */
.card, .quick-action-card, .product-card {
  transition: all 0.15s ease;
}

/* Toast animation */
.toast {
  animation: slideUpFade 0.3s ease;
}
@keyframes slideUpFade {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Tab switch animation */
.tab-section {
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Active tab indicator */
.btn-ghost.active-nav {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 700;
}

/* === INPUTS === */
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  color: var(--color-text);
  background: var(--color-surface);
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.input-error { border-color: var(--color-danger); background: #FEF2F2; }

/* === CARDS === */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-lg);
}

/* === TABLES === */
table { width: 100%; border-collapse: collapse; margin-top: var(--space-md); }
th {
  text-align: left;
  font-size: var(--font-size-caption);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 2px solid var(--color-border);
}
td {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-body);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #F8FAFC; }

/* === TOAST === */
.toast {
  position: fixed;
  right: var(--space-lg);
  bottom: 80px;
  background: var(--color-text);
  color: #fff;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--font-size-body);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: none;
}

/* === HEADER (Enhanced) === */
.header {
  background: linear-gradient(135deg, #1E40AF 0%, #3B82F6 100%);
  color: #fff;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header h1 {
  font-size: var(--font-size-section-title);
  font-weight: 700;
  margin: 0;
}
.header-subtitle {
  font-size: var(--font-size-caption);
  opacity: 0.85;
}
.header-stats {
  display: flex;
  gap: var(--space-lg);
  margin-top: var(--space-xs);
}
.header-stat {
  text-align: center;
}
.header-stat-value {
  font-size: 16px;
  font-weight: 700;
}
.header-stat-label {
  font-size: 11px;
  opacity: 0.8;
}
.header .auth-status {
  font-size: var(--font-size-caption);
  opacity: 0.85;
  align-self: flex-start;
}

@media (min-width: 768px) {
  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .header-stats {
    margin-top: 0;
  }
  .header-stat-value {
    font-size: 18px;
  }
}

/* === MAIN CONTENT === */
.main-content {
  padding: var(--space-lg);
  padding-bottom: 80px;
  max-width: 960px;
  margin: 0 auto;
}

/* === AUTH CARDS === */
.auth-card { max-width: 400px; margin: var(--space-2xl) auto; }
.auth-card h2 { font-size: var(--font-size-page-title); margin-bottom: var(--space-lg); text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: var(--space-md); }
/* Шаги визарда — та же вертикальная раскладка, чтобы поля не слипались */
.auth-card form > div { display: flex; flex-direction: column; gap: var(--space-md); }
.auth-card .hint { text-align: center; font-size: var(--font-size-caption); color: var(--color-text-muted); margin-top: var(--space-md); }
.auth-card .hint a { color: var(--color-primary); text-decoration: none; font-weight: 600; }

/* === TAB SECTIONS === */
.tab-section { margin-bottom: var(--space-lg); }
.tab-section h2 { font-size: var(--font-size-page-title); font-weight: 700; margin-bottom: var(--space-lg); }
.tab-section h3 { font-size: var(--font-size-section-title); font-weight: 600; margin: var(--space-lg) 0 var(--space-md); }

/* === TAB FORMS === */
.tab-form { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-bottom: var(--space-lg); align-items: flex-end; }
.tab-form .input { flex: 1; min-width: 120px; }

/* === SEARCH & FILTERS === */
.search-bar .input {
  padding-left: 40px;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2364748B" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>') no-repeat 12px center;
}

.filter-chips {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--font-size-caption);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.chip:hover {
  background: var(--color-bg);
}
.chip-active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* Sort selector */
.sort-selector {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.sort-selector select {
  flex: 1;
}
.sort-label {
  font-size: var(--font-size-caption);
  color: var(--color-text-muted);
}

/* === QUICK ACTIONS === */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}
.quick-action-card {
  background: linear-gradient(135deg, var(--color-primary), #3B82F6);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}
.quick-action-card:active {
  transform: scale(0.98);
}
.quick-action-card.secondary {
  background: linear-gradient(135deg, var(--color-success), #34D399);
}
.quick-action-card.tertiary {
  background: linear-gradient(135deg, var(--color-warning), #FBBF24);
}
.quick-action-icon {
  font-size: 24px;
}
.quick-action-label {
  font-size: var(--font-size-caption);
  font-weight: 600;
}

/* === MINI DASHBOARD === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}
.stat-label {
  font-size: var(--font-size-label);
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 2px;
}
.stat-change {
  font-size: var(--font-size-label);
  color: var(--color-text-muted);
}
.stat-change.positive {
  color: var(--color-success);
}
.stat-change.negative {
  color: var(--color-danger);
}
.stat-change-action {
  color: var(--color-primary);
  font-weight: 600;
}

@media (min-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .stat-card {
    padding: var(--space-lg);
  }
}

/* === ORDER ITEMS === */
.item-row { display: flex; gap: var(--space-sm); align-items: center; margin-bottom: var(--space-sm); }
.item-row select, .item-row input { flex: 1; padding: 8px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-family: var(--font-family); font-size: var(--font-size-body); }
.item-row .line-total { min-width: 60px; text-align: right; font-weight: 600; color: var(--color-primary); }

/* === BOTTOM NAV === */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--color-surface);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
  display: none;
  justify-content: space-around;
  align-items: flex-end;
  padding: var(--space-sm) 0;
  z-index: 100;
  height: 56px;
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; color: var(--color-text-muted);
  background: none; border: none; cursor: pointer;
  padding: var(--space-xs); font-family: var(--font-family);
}
.bottom-nav-item.active { color: var(--color-primary); font-weight: 600; }
.bottom-nav-item .icon { font-size: 20px; }
.bottom-nav-fab {
  width: 48px; height: 48px;
  background: var(--color-primary); border-radius: 50%; border: none;
  color: #fff; font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  margin-top: -20px;
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
  cursor: pointer;
}
.bottom-nav-fab:hover { background: var(--color-primary-dark); }

/* === DESKTOP NAV === */
.desktop-nav {
  display: none;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  flex-wrap: wrap;
}

/* === BADGES === */
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-full); font-size: var(--font-size-label); font-weight: 600; }
.badge-new { background: var(--color-primary-light); color: var(--color-primary); }
.badge-progress { background: #FEF3C7; color: #92400E; }
.badge-completed { background: #D1FAE5; color: #065F46; }

/* === MODERN PRODUCT CARDS === */
.products-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.product-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-md);
  align-items: center;
  transition: box-shadow 0.15s;
}
.product-card:hover {
  box-shadow: var(--shadow-md);
}
.product-card-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.product-card-name {
  font-size: var(--font-size-body);
  font-weight: 600;
  color: var(--color-text);
}
.product-card-sku {
  font-size: var(--font-size-caption);
  color: var(--color-text-muted);
  font-family: monospace;
}
.product-card-stock {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-label);
  font-weight: 600;
}
.stock-badge-ok {
  background: #DCFCE7;
  color: #166534;
}
.stock-badge-low {
  background: #FEF3C7;
  color: #92400E;
}
.stock-badge-critical {
  background: #FEE2E2;
  color: #991B1B;
}
.stock-badge-none {
  background: var(--color-bg);
  color: var(--color-text-muted);
}
.product-card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-sm);
}
.product-card-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}
.product-card-actions {
  display: flex;
  gap: var(--space-xs);
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s;
}
.icon-btn:hover {
  background: var(--color-bg);
}
.icon-btn.danger:hover {
  background: #FEE2E2;
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* === HIDDEN === */
.hidden { display: none !important; }

/* === RESPONSIVE === */
@media (min-width: 768px) {
  .bottom-nav { display: none !important; }
  .desktop-nav { display: flex; }
  .main-content { padding-bottom: var(--space-2xl); }
  .products-cards { display: none !important; }
  .desktop-only { display: table; }
}

@media (max-width: 767px) {
  .desktop-nav { display: none !important; }
  .bottom-nav { display: flex; }
  .tab-form { flex-direction: column; }
  .tab-form .input { min-width: 100%; }
  .main-content { padding: var(--space-md); padding-bottom: 72px; }
  .desktop-only { display: none !important; }
}

/* === PRICE INTELLIGENCE === */

/* Dumping Rule Cards */
.dumping-rule-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  transition: box-shadow 0.15s;
}
.dumping-rule-card:hover {
  box-shadow: var(--shadow-sm);
}
.dumping-rule-card.enabled {
  border-left: 3px solid var(--color-success);
}
.dumping-rule-card.disabled {
  border-left: 3px solid var(--color-text-muted);
  opacity: 0.8;
}

/* Alert Cards */
.alert-card.unresolved {
  border-left: 3px solid var(--color-warning);
  background: #FFF8E1;
}
.alert-card.resolved {
  border-left: 3px solid var(--color-success);
  background: #F5F5F5;
}

/* Price History Chart Container */
#price-history-chart {
  position: relative;
  min-height: 200px;
}
#price-history-chart canvas {
  max-height: 200px;
}

/* Status Banner for Price Intel */
#price-intel-status-banner {
  display: none;
}
#price-intel-status-banner.active {
  display: block;
}
#price-intel-status-banner.success {
  background: #E8F5E9;
  color: #1B5E20;
}
#price-intel-status-banner.warning {
  background: #FFF8E1;
  color: #8D6E00;
}
#price-intel-status-banner.error {
  background: #FFEBEE;
  color: #C62828;
}

/* Competitor Price Item */
.competitor-price-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-xs);
  background: var(--color-surface);
}
.competitor-price-item.cheaper {
  background: #FFEBEE;
  border-color: #FFCDD2;
}
.competitor-price-item.cheaper .competitor-price {
  color: var(--color-danger);
}

/* Price History Table */
.price-history-table {
  width: 100%;
  font-size: var(--font-size-caption);
  border-collapse: collapse;
}
.price-history-table th,
.price-history-table td {
  padding: var(--space-xs) var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.price-history-table th {
  font-weight: 600;
  color: var(--color-text-muted);
}
.price-history-item.price-drop {
  background: #FFEBEE;
}
.price-history-item.price-rise {
  background: #E8F5E9;
}

/* Alert badge on nav button */
.price-intel-alert-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--color-danger);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
  animation: pulse 2s infinite;
}

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

/* Manual Scan Result */
#manual-scan-result {
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  margin-top: var(--space-sm);
  font-size: var(--font-size-caption);
}
#manual-scan-result.success {
  background: #E8F5E9;
  color: #1B5E20;
}
#manual-scan-result.error {
  background: #FFEBEE;
  color: #C62828;
}

/* Price Intel Details */
.details-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-caption);
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}
.details-value {
  font-weight: 600;
  color: var(--color-text);
}

/* Price History Table */
.price-history-table {
  width: 100%;
  font-size: var(--font-size-caption);
  border-collapse: collapse;
  margin-top: var(--space-sm);
}
.price-history-table th,
.price-history-table td {
  padding: var(--space-xs) var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.price-history-table th {
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-bg);
}
.price-history-item.price-drop {
  background: #FFEBEE;
}
.price-history-item.price-rise {
  background: #E8F5E9;
}

/* === 2FA Settings === */
.recovery-code {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  font-size: 13px;
  background: #F9FAFB;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #E5E7EB;
  text-align: center;
  letter-spacing: 1px;
  color: #374151;
  user-select: all;
}

.recovery-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

/* === ANALYTICS TABLE === */
/* Make analytics section full width, ignoring main-content max-width */
body[data-active-tab="analytics"] .main-content {
  max-width: 100% !important;
  padding: var(--space-lg);
}

/* Analytics mode switch (Актуальная | За полгода) */
.analytics-mode-switch {
  display: inline-flex;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  overflow: hidden;
  background: #F9FAFB;
}

.analytics-mode-switch button {
  padding: 8px 18px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.analytics-mode-switch button:hover {
  color: #2563EB;
}

.analytics-mode-switch button.active {
  background: #2563EB;
  color: #fff;
}

#tab-analytics {
  width: 100%;
  max-width: 100%;
  padding: 0;
  margin: 0;
}
#analytics-results {
  width: 100%;
  max-width: 100%;
  padding: 0;
  margin: 0;
}
.desktop-only {
  width: 100%;
}
#analytics-table {
  table-layout: fixed;
  width: 100% !important;
  max-width: 100vw !important;
}
#analytics-table th {
  padding: 8px 4px;
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#analytics-table td {
  padding: 6px 4px;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#analytics-table td:first-child,
#analytics-table th:first-child {
  text-align: left;
  padding-left: 4px;
}
#analytics-table td:nth-child(2),
#analytics-table th:nth-child(2) {
  text-align: left;
  padding-left: 4px;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.3;
  height: auto;
}
#analytics-table td:nth-child(3),
#analytics-table th:nth-child(3) {
  text-align: left;
  padding-left: 4px;
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.2;
}
#analytics-table td:nth-child(4),
#analytics-table th:nth-child(4) {
  text-align: left;
  padding-left: 4px;
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.2;
}
#analytics-table td:nth-child(5),
#analytics-table th:nth-child(5) {
  text-align: left;
  padding-left: 4px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
