*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f5f5f5;
}
a { color: #2d6a30; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

.loading { display: flex; align-items: center; justify-content: center; min-height: 100vh; color: #999; }

/* ========== Layout ========== */
.topbar {
  background: #fff; border-bottom: 1px solid #e5e5e5; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; flex-shrink: 0; height: 55px;
}
.topbar-brand { font-size: 16px; font-weight: 700; color: #2d6a30; }
.topbar-project-select {
  border: 1px solid #ddd; border-radius: 8px; padding: 6px 10px; font-size: 14px;
  background: #fff; cursor: pointer; outline: none;
}
.topbar-project-select:focus { border-color: #2d6a30; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: #555; }
.topbar-user img { width: 28px; height: 28px; border-radius: 50%; }
.topbar-logout { background: none; border: none; color: #ef4444; font-size: 12px; }

.sidebar-layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 220px; background: #fff; border-right: 1px solid #e5e5e5;
  padding: 16px 0; flex-shrink: 0;
}
.sidebar a {
  display: flex; align-items: center; padding: 10px 20px; color: #555;
  font-size: 14px; border-left: 3px solid transparent;
}
.sidebar a:hover { background: #f8f8f8; text-decoration: none; color: #2d6a30; }
.sidebar a.active { background: #e8f5e9; border-left-color: #2d6a30; color: #2d6a30; font-weight: 500; }
.sidebar-section { padding: 12px 20px 6px; font-size: 11px; color: #999; text-transform: uppercase; font-weight: 600; letter-spacing: .5px; }

.main { flex: 1; overflow: auto; padding: 24px; }
.main h1 { font-size: 22px; font-weight: 700; margin: 0 0 16px; }
.main h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }

/* ========== Кнопки ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s;
}
.btn-primary { background: #2d6a30; color: #fff; }
.btn-primary:hover { background: #1e4a20; }
.btn-secondary { background: #fff; color: #1a1a1a; border-color: #d5d5d5; }
.btn-secondary:hover { border-color: #2d6a30; color: #2d6a30; }
.btn-danger { background: #fff; color: #dc2626; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }

/* ========== Хаб (главная) ========== */
.hub-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px; max-width: 1100px;
}
.hub-card {
  position: relative; display: block; padding: 28px 24px;
  background: #fff; border: 1px solid #e5e5e5; border-radius: 16px;
  text-decoration: none; color: inherit; cursor: pointer;
  transition: all .2s ease; overflow: hidden;
}
.hub-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent, #2d6a30); opacity: 0; transition: opacity .2s;
}
.hub-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent, #2d6a30);
  box-shadow: 0 8px 24px rgba(0,0,0,.06);
  text-decoration: none;
}
.hub-card:hover::before { opacity: 1; }
.hub-card-icon { font-size: 32px; margin-bottom: 12px; }
.hub-card h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; color: #1a1a1a; }
.hub-card p { margin: 0 0 18px; font-size: 13px; color: #666; line-height: 1.5; }
.hub-card-arrow { font-size: 13px; font-weight: 500; color: var(--accent, #2d6a30); }

/* ========== Карточки ========== */
.card {
  background: #fff; border: 1px solid #e5e5e5; border-radius: 12px; padding: 20px;
}
.card + .card { margin-top: 12px; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.project-card { display: block; padding: 18px; cursor: pointer; transition: all .15s; }
.project-card:hover { border-color: #2d6a30; text-decoration: none; }
.project-card h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; color: #1a1a1a; }
.project-card .url { font-size: 12px; color: #888; font-family: ui-monospace, Menlo, monospace; }
.project-card .mods { margin-top: 12px; display: flex; gap: 4px; flex-wrap: wrap; }
.project-card .mods span { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: #f0f0f0; color: #555; }
.project-card .mods span.on { background: #e8f5e9; color: #2d6a30; font-weight: 500; }
.project-card-new {
  border-style: dashed; display: flex; align-items: center; justify-content: center;
  color: #999; min-height: 140px; font-size: 14px;
}
.project-card-new:hover { border-color: #2d6a30; color: #2d6a30; background: #fafafa; }

/* ========== Формы ========== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: #555; font-weight: 500; margin-bottom: 4px; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; border: 1px solid #d5d5d5; border-radius: 8px; padding: 8px 12px;
  font-size: 14px; outline: none; font-family: inherit;
}
.form-group input:focus, .form-group textarea:focus { border-color: #2d6a30; }
.form-hint { font-size: 12px; color: #999; margin-top: 3px; }
.form-error { color: #dc2626; font-size: 13px; margin-top: 10px; }

/* ========== Login ========== */
.login-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f0fdf4 0%, #e8f5e9 100%);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px 36px;
  box-shadow: 0 8px 32px rgba(0,0,0,.06);
  max-width: 380px; width: 100%; text-align: center;
}
.login-card h1 { font-size: 24px; margin: 0 0 8px; color: #2d6a30; }
.login-card p { color: #666; margin: 0 0 28px; font-size: 14px; line-height: 1.6; }
.login-deny { color: #dc2626; font-size: 13px; margin-top: 16px; }

/* ========== Empty / loading ========== */
.empty-state { text-align: center; padding: 60px 20px; color: #999; }
.spinner {
  width: 24px; height: 24px; border: 3px solid #e5e5e5; border-top-color: #2d6a30;
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== SEO module ========== */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.seo-header { margin-bottom: 16px; }
.seo-tabs { display: flex; gap: 4px; border-bottom: 1px solid #e5e5e5; margin-top: 12px; }
.seo-tab {
  background: none; border: none; padding: 10px 16px; font-size: 14px;
  color: #666; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.seo-tab:hover { color: #2d6a30; }
.seo-tab.active { color: #2d6a30; border-bottom-color: #2d6a30; font-weight: 600; }

.tbl { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.tbl th { text-align: left; padding: 8px 10px; background: #fafafa; border-bottom: 1px solid #eee; font-weight: 600; color: #555; font-size: 12px; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid #f2f2f2; }
.tbl-compact td, .tbl-compact th { padding: 5px 8px; font-size: 12px; }
.tbl tr:hover td { background: #fafafa; }
.tbl .dim { color: #888; }
.tbl .truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-cell { text-align: center; color: #999; padding: 20px; }

.perf-good { color: #16a34a; font-weight: 600; }
.perf-mid  { color: #d97706; font-weight: 600; }
.perf-bad  { color: #dc2626; font-weight: 600; }
.perf-na   { color: #bbb; }

.pos-top { background: #dcfce7; color: #15803d; font-weight: 600; text-align: center; }
.pos-mid { background: #fef3c7; color: #92400e; text-align: center; }
.pos-low { color: #777; text-align: center; }
.pos-na  { color: #ccc; text-align: center; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.chip {
  background: #f4f4f4; border: 1px solid transparent; border-radius: 14px;
  padding: 4px 12px; font-size: 12px; color: #555;
}
.chip:hover { background: #eaeaea; }
.chip.active { background: #e8f5e9; color: #2d6a30; border-color: #2d6a30; font-weight: 500; }

.kw-list { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.kw-pill { background: #f4f4f4; padding: 4px 10px; border-radius: 12px; font-size: 12px; }
.kw-pill.inactive { opacity: .4; }
.cluster-title { font-size: 12px; color: #777; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }

.live-log {
  background: #111; color: #ddd; font-family: ui-monospace, Menlo, monospace;
  font-size: 12px; padding: 12px; border-radius: 8px; min-height: 300px;
  max-height: 500px; overflow: auto; margin-top: 10px;
}
.log-line { padding: 2px 0; white-space: pre-wrap; }
.log-success { color: #86efac; }
.log-warn { color: #fbbf24; }
.log-error { color: #fca5a5; }
.log-info { color: #cbd5e1; }

/* ========== AI-detect score pills ========== */
.score-good { background: #dcfce7; color: #15803d; border-color: #86efac; }
.score-mid  { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.score-bad  { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; max-width: 820px; width: 100%;
  max-height: 90vh; overflow: auto; padding: 28px 32px; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-close {
  position: absolute; top: 10px; right: 14px; background: none; border: none;
  font-size: 26px; line-height: 1; color: #888; cursor: pointer; padding: 4px 10px;
}
.modal-close:hover { color: #1a1a1a; }
.modal-body .md-preview h1 { font-size: 20px; margin: 18px 0 10px; }
.modal-body .md-preview h2 { font-size: 17px; margin: 16px 0 8px; }
.modal-body .md-preview h3 { font-size: 15px; margin: 14px 0 6px; }
.modal-body .md-preview p { margin: 8px 0; line-height: 1.65; }
.modal-body .md-preview ul { margin: 8px 0 8px 20px; }
.modal-body .md-preview code { background: #f4f4f4; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.modal-body .md-preview pre { background: #111; color: #ddd; padding: 10px; border-radius: 8px; overflow: auto; }
.modal-body .md-preview pre code { background: none; color: inherit; padding: 0; }
