/* =============================================================
   RuASO — дизайн-система
   Тёмная/светлая тема через [data-theme], без фреймворков.
   ============================================================= */

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Акцент — фиолетово-синий, ассоциируется с аналитикой и данными */
  --accent: #6C5CE7;
  --accent-hover: #7D6FF0;
  --accent-soft: rgba(108, 92, 231, .12);

  --green: #22C55E;
  --green-soft: rgba(34, 197, 94, .12);
  --red: #EF4444;
  --red-soft: rgba(239, 68, 68, .12);
  --amber: #F59E0B;
  --amber-soft: rgba(245, 158, 11, .12);
  --blue: #3B82F6;
  --blue-soft: rgba(59, 130, 246, .12);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 8px 24px rgba(16,24,40,.12);
}

[data-theme="dark"] {
  --bg: #0F1117;
  --bg-elevated: #171A23;
  --bg-card: #1A1D27;
  --bg-hover: #21242F;
  --border: #2A2E3A;
  --text: #E7E9EE;
  --text-muted: #9199AA;
  --text-faint: #656D80;
  --sidebar-bg: #12141C;
}

[data-theme="light"] {
  --bg: #F5F6FA;
  --bg-elevated: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-hover: #F0F1F6;
  --border: #E4E6EE;
  --text: #1A1D27;
  --text-muted: #656D80;
  --text-faint: #9199AA;
  --sidebar-bg: #171A23;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0 0 8px; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }
::selection { background: var(--accent); color: #fff; }
::-moz-selection { background: var(--accent); color: #fff; }

/* ---------- Скроллбар ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* =============================================================
   Каркас приложения: боковое меню + верхняя панель + контент
   ============================================================= */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #E7E9EE;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,.06);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  font-weight: 800; font-size: 18px; letter-spacing: -.02em;
}
.sidebar-brand .logo-dot {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #A78BFA);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff;
}

.sidebar-nav { flex: 1; padding: 8px 12px; }
.sidebar-group { margin-top: 18px; }
.sidebar-group:first-child { margin-top: 0; }
.sidebar-group-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: #656D80; padding: 0 12px 6px; font-weight: 700;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: #B4BACB; font-size: 13.5px; font-weight: 500;
  margin-bottom: 2px; transition: background .12s, color .12s;
}
.sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-link.active { background: var(--accent); color: #fff; }
.sidebar-link .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .9; }
.sidebar-link .badge { margin-left: auto; }

.sidebar-project-switch {
  margin: 8px 12px 4px; padding: 10px 12px;
  background: rgba(255,255,255,.05); border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.sidebar-project-switch .label { color: #656D80; font-size: 11px; text-transform: uppercase; }
.sidebar-project-switch .value { color: #fff; font-weight: 600; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-plan {
  background: linear-gradient(135deg, rgba(108,92,231,.25), rgba(167,139,250,.15));
  border: 1px solid rgba(167,139,250,.3);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12px;
}
.sidebar-plan .plan-name { font-weight: 700; color: #fff; font-size: 13px; }
.sidebar-plan .plan-usage { color: #B4BACB; margin-top: 4px; }
.sidebar-plan a { color: #C4B5FD; font-weight: 600; }

/* ---------- Основная область ---------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.topbar-search {
  flex: 1; max-width: 420px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  color: var(--text-muted); font-size: 13px;
}
.topbar-search input { border: 0; background: transparent; outline: 0; color: var(--text); flex: 1; font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border); cursor: pointer;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.user-menu { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px 4px 4px; border-radius: 999px; }
.user-menu:hover { background: var(--bg-hover); }
.avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #A78BFA);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}

.content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
.content-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.content-header h1 { font-size: 22px; }
.content-header .subtitle { color: var(--text-muted); font-size: 13.5px; }
.content-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* =============================================================
   Карточки, сетки метрик
   ============================================================= */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.card-title { font-size: 15px; font-weight: 700; }
.card-subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr);} }
@media (max-width: 680px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.metric-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.metric-label { color: var(--text-muted); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.metric-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; }
.metric-delta { display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; font-weight: 700; margin-top: 8px; }
.metric-delta.up { color: var(--green); }
.metric-delta.down { color: var(--red); }
.metric-delta.flat { color: var(--text-faint); }
.metric-spark { margin-top: 10px; height: 32px; }

/* =============================================================
   Таблицы
   ============================================================= */

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--bg-card); }
table.data-table th {
  text-align: left; padding: 11px 14px; font-weight: 600; font-size: 12px;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em;
  background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0;
}
table.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: 0; }
table.data-table tr:hover td { background: var(--bg-hover); }
table.data-table th.sortable { cursor: pointer; user-select: none; }
table.data-table th.sortable:hover { color: var(--text); }

.cell-app { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.cell-app img { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; background: var(--bg-hover); }
.cell-app .name { font-weight: 600; }
.cell-app .package { color: var(--text-faint); font-size: 11.5px; }

.pos-change { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-size: 12.5px; }
.pos-change.up { color: var(--green); }
.pos-change.down { color: var(--red); }
.pos-change.flat { color: var(--text-faint); }
.pos-change.new { color: var(--blue); }

/* =============================================================
   Бейджи, теги, статусы
   ============================================================= */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.badge-green  { background: var(--green-soft); color: var(--green); }
.badge-red    { background: var(--red-soft); color: var(--red); }
.badge-amber  { background: var(--amber-soft); color: var(--amber); }
.badge-blue   { background: var(--blue-soft); color: var(--blue); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-gray   { background: var(--bg-hover); color: var(--text-muted); }

.tag { display: inline-block; padding: 3px 9px; border-radius: var(--radius-sm); background: var(--bg-hover); font-size: 12px; color: var(--text-muted); margin: 2px; }

.progress { height: 6px; border-radius: 999px; background: var(--bg-hover); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; }
.progress-bar.warn { background: var(--amber); }
.progress-bar.danger { background: var(--red); }

/* =============================================================
   Формы
   ============================================================= */

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.form-control, select.form-control, textarea.form-control {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 13.5px; outline: 0; transition: border-color .12s;
}
.form-control:focus { border-color: var(--accent); }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: 0; }
.input-group .form-control:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .form-control:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* =============================================================
   Кнопки
   ============================================================= */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: all .12s; line-height: 1.2;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-elevated); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* =============================================================
   Пустые состояния, алерты
   ============================================================= */

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--green-soft); color: var(--green); border-color: rgba(34,197,94,.25); }
.alert-error   { background: var(--red-soft); color: var(--red); border-color: rgba(239,68,68,.25); }
.alert-info    { background: var(--blue-soft); color: var(--blue); border-color: rgba(59,130,246,.25); }
.alert-warn    { background: var(--amber-soft); color: var(--amber); border-color: rgba(245,158,11,.25); }

/* =============================================================
   Вкладки, фильтры
   ============================================================= */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 4px; margin-right: 20px; font-size: 13.5px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tab.active { color: var(--accent); border-color: var(--accent); }

.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; background: var(--bg-card);
}
.filter-chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* =============================================================
   Модалки (через Alpine.js x-show/x-transition в шаблонах)
   ============================================================= */

.modal-backdrop { position: fixed; inset: 0; background: rgba(10,12,18,.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--bg-card); border-radius: var(--radius-lg); width: 100%; max-width: 520px; padding: 24px; box-shadow: var(--shadow-lg); max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* =============================================================
   Дашборд конкурентов, аудита
   ============================================================= */

.score-ring { width: 96px; height: 96px; position: relative; display: flex; align-items: center; justify-content: center; }
.score-ring .value { font-size: 26px; font-weight: 800; }
.score-ring .max { font-size: 12px; color: var(--text-faint); }

.checklist-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.checklist-row:last-child { border-bottom: 0; }
.checklist-row .title { font-weight: 600; font-size: 13.5px; }
.checklist-row .desc { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

/* =============================================================
   Публичный сайт (посадочные, тарифы) — навигация мобильно-первая:
   по умолчанию (даже без CSS-медиазапросов) — компактный вид с
   бургер-меню, на широких экранах раскрывается в обычную строку.
   ============================================================= */

.public-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 5vw; border-bottom: 1px solid var(--border);
  position: relative; gap: 12px;
}
.public-nav-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 18px; flex-shrink: 0; color: var(--text);
}

.public-nav-burger {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-card); cursor: pointer; flex-shrink: 0; font-size: 18px;
}

.nav-panel {
  display: none;
  position: absolute; top: 100%; left: 5vw; right: 5vw; margin-top: 10px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px; box-shadow: var(--shadow-lg); z-index: 300; flex-direction: column; gap: 2px;
}
.nav-panel.open { display: flex; }
.nav-panel a { padding: 12px 14px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 14.5px; }
.nav-panel a:hover { background: var(--bg-hover); }
.nav-panel hr { border: none; border-top: 1px solid var(--border); margin: 6px 4px; }
.nav-panel .nav-auth { display: flex; flex-direction: column; gap: 8px; padding: 6px; }
.nav-panel .nav-auth .btn { width: 100%; }

.public-hero { padding: 80px 5vw 60px; text-align: center; max-width: 780px; margin: 0 auto; }
.public-hero h1 { font-size: 42px; line-height: 1.15; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; background: var(--bg-card); }
.plan-card.featured { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); position: relative; }
.plan-price { font-size: 34px; font-weight: 800; margin: 12px 0; }
.plan-price span { font-size: 14px; color: var(--text-muted); font-weight: 500; }
.plan-features li { padding: 7px 0; font-size: 13.5px; display: flex; gap: 8px; align-items: flex-start; }

/* Широкие экраны: меню разворачивается в обычную строку, бургер прячется */
@media (min-width: 901px) {
  .public-nav-burger { display: none; }
  .nav-panel {
    display: flex !important; position: static; flex-direction: row; align-items: center;
    border: none; box-shadow: none; padding: 0; margin: 0 0 0 40px; background: transparent;
    gap: 24px; flex: 1;
  }
  .nav-panel a { padding: 0; font-size: 14px; }
  .nav-panel hr { display: none; }
  .nav-panel .nav-auth { flex-direction: row; margin-left: auto; padding: 0; gap: 10px; align-items: center; }
  .nav-panel .nav-auth .btn { width: auto; padding: 10px 20px; }
  .nav-panel .nav-auth a[href="/login"] { padding: 10px 14px; }
}

/* =============================================================
   Утилиты
   ============================================================= */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.font-bold { font-weight: 700; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }

/* Глобальная защита от горизонтальной прокрутки — на всех страницах,
   не только под медиазапросом, некоторые браузеры (Яндекс.Браузер на
   Android) иначе всё равно допускали скролл вбок. */
html, body { max-width: 100%; overflow-x: hidden; }
img, video { max-width: 100%; height: auto; }
* { box-sizing: border-box; }

@media (max-width: 900px) {
  .app-shell { overflow-x: hidden; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    transform: translateX(-100%); z-index: 200;
    transition: transform .25s ease; width: 84vw; max-width: 300px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 190;
  }
  .sidebar-backdrop.open { display: block; }

  .main { width: 100%; min-width: 0; }
  .content { padding: 14px; max-width: 100%; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-search { display: none; }
  .mobile-menu-btn { display: flex !important; }

  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  table.data-table { font-size: 12px; }
  .table-wrap { max-width: 100%; overflow-x: auto; }
  .content-header { flex-direction: column; align-items: flex-start; }
  .content-actions { width: 100%; }
  .content-actions .btn, .content-actions form { width: 100%; }

  .public-hero h1 { font-size: 26px; }
}

.mobile-menu-btn { display: none; }
