/* ===== MarketMetrica Design System v2 ===== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

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

:root {
  --primary:        #4F46E5;
  --primary-hover:  #4338CA;
  --primary-light:  #EEF2FF;
  --primary-text:   #3730A3;

  --teal:           #10B981;
  --teal-light:     #D1FAE5;
  --red:            #EF4444;
  --red-light:      #FEE2E2;
  --amber:          #F59E0B;
  --amber-light:    #FEF3C7;
  --amber-dark:     #92400E;
  --blue:           #3B82F6;
  --blue-light:     #DBEAFE;

  --white:          #FFFFFF;
  --bg:             #F5F6FA;
  --gray-50:        #F8FAFC;
  --gray-100:       #F0F2F8;
  --gray-200:       #E2E6F0;
  --gray-400:       #9AA3B8;
  --gray-600:       #60708B;
  --gray-900:       #0D1525;

  --text:           #0D1525;
  --text-muted:     #60708B;
  --border:         #E4E8F2;

  --purple:         var(--primary);
  --purple-light:   var(--primary-light);
  --purple-dark:    var(--primary-hover);

  --radius:         10px;
  --radius-lg:      14px;
  --radius-xl:      20px;

  --shadow:     0 1px 2px rgba(13,21,37,0.05), 0 1px 4px rgba(13,21,37,0.04);
  --shadow-md:  0 4px 20px rgba(13,21,37,0.07), 0 1px 4px rgba(13,21,37,0.04);
  --shadow-lg:  0 12px 48px rgba(13,21,37,0.10);

  font-size: 15px;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.app-layout {
  display: grid;
  grid-template-columns: 224px 1fr;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  background: #FAFBFF;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

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

.sidebar-logo span { font-size: 22px; }

.sidebar-nav {
  padding: 10px 8px;
  flex: 1;
}

.nav-section {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  margin-bottom: 1px;
  position: relative;
}

.nav-item:hover {
  background: var(--gray-100);
  color: var(--text);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon { opacity: 1; }

.sidebar-bottom {
  padding: 10px 8px 14px;
  border-top: 1px solid var(--border);
}

/* ===== Main ===== */
.main-content {
  padding: 28px 32px 48px;
  overflow-y: auto;
  min-height: 100vh;
}

/* ===== Page Header ===== */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.25;
}

.page-subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 400;
}

/* ===== Cards ===== */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 14px;
}

/* ===== Metric Cards ===== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s, transform 0.15s;
}

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

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.6px;
  line-height: 1.15;
  margin-bottom: 6px;
}

.metric-change {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
}

.metric-change.up   { color: var(--teal); }
.metric-change.down { color: var(--red);  }

/* ===== Period Selector ===== */
.period-selector {
  display: flex;
  gap: 2px;
  background: var(--gray-100);
  padding: 3px;
  border-radius: 10px;
  width: fit-content;
}

.period-btn {
  padding: 5px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.1s;
  font-family: inherit;
  letter-spacing: -0.1px;
}

.period-btn:hover { color: var(--text); }

.period-btn.active {
  background: var(--white);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ===== Tabs (finance etc) ===== */
.tab-bar {
  display: flex;
  gap: 2px;
  background: var(--gray-100);
  padding: 3px;
  border-radius: 10px;
  width: fit-content;
  margin-bottom: 20px;
}

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--gray-50);
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--text);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #FAFBFF; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green  { background: #DCFCE7; color: #166534; }
.badge-red    { background: var(--red-light);     color: #991B1B; }
.badge-amber  { background: var(--amber-light);   color: #92400E; }
.badge-gray   { background: var(--gray-100);      color: var(--gray-600); }
.badge-purple { background: var(--primary-light); color: var(--primary-text); }
.badge-blue   { background: var(--blue-light);    color: #1E40AF; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
  font-family: inherit;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: -0.1px;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(79,70,229,0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--white);
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(79,70,229,0.30);
}

.btn-secondary {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-200);
  text-decoration: none;
}

.btn-danger {
  background: var(--red);
  color: var(--white);
  border-color: var(--red);
}

.btn-danger:hover { background: #DC2626; text-decoration: none; }

.btn-sm  { padding: 5px 11px; font-size: 12px; border-radius: 7px; }
.btn-lg  { padding: 11px 22px; font-size: 15px; border-radius: 11px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 15px; }

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--white);
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.10);
}

.form-input::placeholder { color: var(--gray-400); }

.form-error { font-size: 12.5px; color: var(--red); margin-top: 4px; }
.form-hint  { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== Auth Pages ===== */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #EEF2FF 0%, #F5F6FA 55%, #F0FDF4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-logo          { text-align: center; margin-bottom: 28px; }
.auth-logo-icon     { font-size: 32px; margin-bottom: 8px; }
.auth-logo-name     { font-size: 20px; font-weight: 800; color: var(--text); letter-spacing: -0.4px; }
.auth-logo-tagline  { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.auth-title         { font-size: 20px; font-weight: 800; color: var(--text); margin-bottom: 4px; letter-spacing: -0.4px; }
.auth-subtitle      { font-size: 13.5px; color: var(--text-muted); margin-bottom: 24px; }

.auth-divider {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: 18px 0;
  position: relative;
}
.auth-divider::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: var(--border);
}
.auth-divider span {
  background: var(--white);
  padding: 0 12px;
  position: relative;
}

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

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

/* ===== Toast ===== */
.toast {
  background: var(--gray-900);
  color: var(--white);
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  animation: slideUp 0.18s ease;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  border: 1px solid rgba(255,255,255,0.08);
}

.toast.success { background: #064E3B; border-color: rgba(16,185,129,0.3); }
.toast.error   { background: #7F1D1D; border-color: rgba(239,68,68,0.3); }

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

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

/* ===== Empty States ===== */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p { font-size: 14px; line-height: 1.6; }

/* ===== Skeleton ===== */
.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  height: 14px;
}

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

/* ===== Chart ===== */
.chart-wrap { height: 220px; position: relative; }

/* ===== Sync bar ===== */
.sync-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}

.sync-info { font-size: 13px; color: var(--text-muted); }

/* ===== Notification dot ===== */
.notif-dot {
  width: 6px; height: 6px;
  background: var(--red);
  border-radius: 50%;
  display: inline-block;
  margin-left: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ===== Mobile burger button ===== */
.burger-btn {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--white);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-direction: column;
  gap: 5px;
  padding: 0;
}

.burger-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.2s;
}

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13,21,37,0.4);
  z-index: 999;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active { display: block; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .burger-btn {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: -240px;
    top: 0;
    height: 100vh;
    width: 240px;
    z-index: 1000;
    transition: left 0.25s ease;
    box-shadow: none;
  }

  .sidebar.mobile-open {
    left: 0;
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    padding: 70px 14px 40px;
  }

  .metrics-grid {
    grid-template-columns: 1fr 1fr;
  }

  .metric-value { font-size: 20px; }

  .auth-card {
    padding: 28px 20px;
  }

  .tab-bar {
    overflow-x: auto;
    width: 100%;
  }
}

/* ===== Mobile overflow fixes ===== */
@media (max-width: 768px) {
  .main-content { overflow-x: hidden; }

  /* Воронка и прогноз — полная ширина */
  .card { overflow-x: hidden; }

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

  /* Кнопки в строку не вылезают */
  .btn-group, [style*="display:flex"] { flex-wrap: wrap; }

  /* Графики не вылезают */
  canvas { max-width: 100% !important; }
}
