/* client-base.css — база клиентского приложения (index.html): токены, кнопки, оболочка с сайдбаром.
   Отчёты (serp-report, backlinks-report, report) грузят старый app.css — его не трогать, чтобы отчёты
   не менялись. Клиентские экраны поверх этой базы — в client.css. */
:root {
  --color-bg:            #f8fafc;
  --color-surface:       #ffffff;
  --color-border:        #e2e8f0;
  --color-border-muted:  #f1f5f9;
  --color-text:          #1e293b;
  --color-text-muted:    #64748b;
  --color-text-strong:   #0f172a;
  --color-primary:       #1575E6;
  --color-primary-hover: #1260c4;
  --color-danger:        #ef4444;
  --color-danger-hover:  #dc2626;
  --color-success:       #16a34a;
  --radius-sm:           6px;
  --radius-md:           8px;
  --radius-lg:           12px;
  --font-family:         'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --max-width:           640px;

  /* Система из DESIGN.md: заливки и тексты уровня AA */
  --brand:        #1575E6;  /* графики, точки, фокус */
  --brand-fill:   #1468d4;  /* заливка кнопок, текст ссылок (5.3:1) */
  --brand-hover:  #1260c4;
  --brand-soft:   #eff6ff;
  --brand-line:   #93c5fd;
  --input-line:   #8794a8;
  --muted-strong: #475569;
  --ok:   #15803d; --ok-bg:   #f0fdf4; --ok-line:   #bbf7d0; --ok-dot:   #16a34a;
  --warn: #b45309; --warn-bg: #fffbeb; --warn-line: #fcd34d; --warn-dot: #f59e0b;
  --err:  #b91c1c; --err-bg:  #fef2f2; --err-line:  #fecaca; --err-dot:  #ef4444;
  --run:  #1d4ed8; --run-bg:  #eff6ff; --run-dot:   #1575E6;
  --shadow-edge: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-pop:  0 16px 40px -12px rgba(15, 23, 42, .28), 0 2px 8px rgba(15, 23, 42, .08);
  --ring:        0 0 0 3px rgba(21, 117, 230, .35);
}

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

body {
  font-family: var(--font-family);
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  overflow-x: hidden;
}

::selection { background: #cfe1fb; color: var(--color-text-strong); }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem;
}

h1, h2, h3 {
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--color-text-strong);
}

input, textarea, button, select {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
  cursor: pointer;
  width: auto;
  margin-bottom: 0;
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-edge);
  border: 1px solid var(--color-border-muted);
}

.section { display: none; }
.section.active { display: block; }
.hidden { display: none !important; }

/* Сообщения */
.alert {
  background: var(--err-bg);
  color: var(--err);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border: 1px solid var(--err-line);
}
.alert.success {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-line);
}

/* Кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  text-align: center;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  font-size: 0.9rem;
  line-height: 1.3;
  padding: 0.6rem 1rem;
  text-decoration: none;
  width: auto;
  margin: 0;
}
.btn:focus-visible,
.icon-btn:focus-visible,
.sidebar-item:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand-fill);
  color: #fff;
}
.btn.primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn.secondary {
  background: var(--color-surface);
  color: var(--color-text-strong);
  border-color: var(--color-border);
}
.btn.secondary:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: #cbd5e1;
}

.btn.danger {
  background: var(--err);
  color: #fff;
}
.btn.danger:hover:not(:disabled) { background: #991b1b; }

.btn.link {
  background: none;
  border: 0;
  color: var(--brand-fill);
  padding: 0;
  font-size: 0.875rem;
}
.btn.link:hover { text-decoration: underline; text-underline-offset: 2px; }

.btn.full { width: 100%; }
.btn.small { padding: 0.45rem 0.8rem; font-size: 0.85rem; }

/* Лоадер на весь экран */
#loader {
  position: fixed;
  inset: 0;
  background: var(--color-surface);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}
#loader.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border-muted);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

/* Каркас страницы: шапка / контент / подвал */
html, body { height: 100%; }
body {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  grid-template-rows: auto 1fr auto;
}
main.container {
  min-width: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ===== Режим приложения (сайдбар) ===== */
body.in-app { grid-template-rows: 1fr; }
body.in-app header,
body.in-app footer { display: none; }
body.in-app main.container {
  max-width: none !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}
#app-section.active {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== Сайдбар ===== */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 220px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.75rem;
  gap: 1rem;
  z-index: 50;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0.25rem 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border-muted);
}
.sidebar-brand img {
  display: block;
  pointer-events: none;
  user-select: none;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  flex: 1;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 38px;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-strong);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  width: 100%;
  transition: background 0.15s, color 0.15s;
  margin: 0;
}
.sidebar-item:hover {
  background: var(--color-bg);
  color: var(--color-text-strong);
}
.sidebar-item.active,
.sidebar-item[aria-current="page"] {
  background: var(--brand-soft);
  color: var(--brand-fill);
}
.sidebar-item svg { flex-shrink: 0; }
.sidebar-item[hidden] { display: none; }

.sidebar-profile {
  border-top: 1px solid var(--color-border-muted);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.sidebar-profile .btn.full { margin: 0; }
.sidebar-profile-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.125rem;
}
.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-fill);
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid #bfdbfe;
}
.sidebar-user { flex: 1; min-width: 0; }
.sidebar-email {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}
.credit-icon {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== Контентная область ===== */
.app-content {
  margin-left: 220px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.5rem;
  background: var(--color-bg);
}

/* Иконка-кнопка */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-strong);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--color-border-muted);
  color: var(--color-text-strong);
}
.icon-btn.danger:hover,
.icon-btn.danger-hover:hover {
  background: var(--err-bg);
  color: var(--err);
}

/* Цвета по доменному типу — 20 типов (бары интента в карточке; в отчёте свои из app.css) */
.t-mkt         { background: #ede9fe; color: #5b21b6; } /* Маркетплейс       — фиолетовый  */
.t-apps        { background: #dbeafe; color: #1d4ed8; } /* Маг. приложений   — синий       */
.t-chain       { background: #ddd6fe; color: #4c1d95; } /* Розничная сеть    — тёмно-фиолетовый */
.t-brand       { background: #e0e7ff; color: #3730a3; } /* Бренд             — индиго      */
.t-service     { background: #f1f5f9; color: #475569; } /* Сервис            — серый       */
.t-store       { background: #dcfce7; color: #166534; } /* Магазин           — зелёный     */
.t-corp        { background: #f0fdf4; color: #15803d; } /* Корп. сайт        — светло-зелёный */
.t-portal      { background: #ccfbf1; color: #115e59; } /* Портал            — бирюзовый   */
.t-classifieds { background: #d1fae5; color: #065f46; } /* Объявления        — изумрудный  */
.t-aggregator  { background: #ecfccb; color: #3f6212; } /* Нишевый агрегатор — лайм        */
.t-gig         { background: #cffafe; color: #164e63; } /* Биржа услуг       — голубой     */
.t-geo         { background: #e0f2fe; color: #0369a1; } /* Геокаталог        — синий       */
.t-price       { background: #bae6fd; color: #075985; } /* Агрегатор цен     — тёмно-синий */
.t-review      { background: #fce7f3; color: #be185d; } /* Агрегатор отзывов — розовый     */
.t-media       { background: #ffedd5; color: #9a3412; } /* СМИ               — оранжевый   */
.t-ugc         { background: #fef9c3; color: #854d0e; } /* UGC               — жёлтый      */
.t-blog        { background: #fef08a; color: #713f12; } /* Блог / инфосайт   — янтарный    */
.t-video       { background: #fee2e2; color: #b91c1c; } /* Видео             — красный     */
.t-forum       { background: #fecaca; color: #991b1b; } /* Форум             — тёмно-красный */
.t-social      { background: #fbcfe8; color: #9d174d; } /* Соцсеть           — малиновый   */
.t-unknown     { background: #f1f5f9; color: #64748b; } /* Неизвестно        — светло-серый */

/* ===== Мобильная нижняя навигация ===== */
@media (max-width: 768px) {
  body.in-app { overflow: auto; }

  #app-section.active {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .app-sidebar {
    position: fixed;
    top: auto;
    bottom: 0; left: 0; right: 0;
    width: auto;
    height: 60px;
    flex-direction: row;
    align-items: center;
    padding: 0;
    border-right: none;
    border-top: 1px solid var(--color-border);
    z-index: 100;
    gap: 0;
    background: var(--color-surface);
  }

  .sidebar-brand,
  .sidebar-profile { display: none; }

  .sidebar-nav {
    flex-direction: row;
    flex: 1;
    gap: 0;
    height: 100%;
  }

  .sidebar-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 0.375rem 0.25rem;
    border-radius: 0;
    font-size: 0.6875rem;
    height: 100%;
    width: auto;
    min-width: 0;
  }
  .sidebar-item span {
    line-height: 1.2;
    text-align: center;
  }

  .app-content {
    margin-left: 0;
    padding: 1rem;
    padding-bottom: calc(60px + 1rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .spinner { animation: spin 1.6s linear infinite !important; }
}
