* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f5f6f8;
  color: #1f2430;
  line-height: 1.4;
}

.topbar {
  padding: 16px 24px;
  background: #1f2430;
  color: #fff;
  display: flex;
  align-items: baseline;
  gap: 16px;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .hint { opacity: .7; font-size: 13px; flex: 1; }
.topbar .balance {
  background: rgba(255,255,255,0.08);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.topbar .balance.low { background: #e53e3e; }
.topbar .nav-link {
  color: #fff; opacity: 0.85; font-size: 13px;
  text-decoration: none; border: 1px solid rgba(255,255,255,0.25);
  padding: 4px 10px; border-radius: 14px; white-space: nowrap;
}
.topbar .nav-link:hover { opacity: 1; background: rgba(255,255,255,0.08); }

.queue-controls { margin-bottom: 8px; }
.batch-item { display: block !important; cursor: default !important; padding: 10px 8px !important; }
.batch-item .batch-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.batch-item .batch-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.batch-item .batch-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #e5e8ee; color: #2a3340; white-space: nowrap;
}
.batch-running .batch-badge { background: #bee3f8; color: #2c5282; }
.batch-queued  .batch-badge { background: #edf2f7; color: #4a5568; }
.batch-done    .batch-badge { background: #c6f6d5; color: #276749; }
.batch-error   .batch-badge { background: #fed7d7; color: #c53030; }
.batch-expired .batch-badge { background: #fefcbf; color: #744210; }
.batch-item .progress-bar { height: 10px; margin-top: 6px; }
.batch-item .progress-label { font-size: 10px; }
.batch-item .batch-msg { font-size: 11px; color: #606773; margin-top: 4px; }
.batch-item .batch-error { font-size: 12px; color: #c53030; margin-top: 4px; }
.batch-item .batch-meta { font-size: 11px; color: #868b97; margin-top: 4px; }
.batch-item .batch-link { font-size: 12px; color: #2b6cb0; text-decoration: none; display: inline-block; margin-top: 6px; }
.batch-item .batch-link:hover { text-decoration: underline; }
.runs-list-empty { color: #868b97; font-size: 13px; padding: 8px !important; }

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  padding: 16px;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.panel label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #d0d4dc;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}
.row { display: flex; gap: 12px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.row label { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.row.actions { margin-top: 14px; }
.checkbox { font-weight: 400 !important; }

button {
  padding: 8px 14px;
  border: 1px solid #d0d4dc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}
button:hover { background: #f1f3f8; }
button.primary { background: #2b6cb0; color: #fff; border-color: #2b6cb0; }
button.primary:hover { background: #225a95; }
button.ghost { background: transparent; border-color: transparent; color: #606773; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

select, input[type="text"], input[type="password"], input:not([type]) {
  padding: 6px 10px;
  border: 1px solid #d0d4dc;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.estimate {
  margin-top: 10px;
  padding: 8px 10px;
  background: #f1f5fa;
  border-left: 3px solid #2b6cb0;
  border-radius: 4px;
  font-size: 12px;
  color: #2a3340;
  min-height: 18px;
}
.estimate.warn { background: #fff4e6; border-color: #d69e2e; color: #744210; }
.estimate.error { background: #fff5f5; border-color: #e53e3e; color: #742a2a; }
.estimate .num { font-weight: 600; font-variant-numeric: tabular-nums; }
.phrase-block .export-btn { float: right; font-size: 12px; padding: 4px 10px; }
.status { margin-top: 10px; font-size: 13px; color: #606773; min-height: 18px; }
.status.error { color: #c53030; }
.progress-bar {
  position: relative;
  height: 18px;
  background: #eef1f6;
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4a90e2, #2b6cb0);
  transition: width 0.3s ease;
}
.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #1f2430;
  mix-blend-mode: normal;
}
.progress-msg { color: #606773; font-size: 12px; }

.runs-list { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow: auto; }
.runs-list li {
  padding: 8px;
  border-bottom: 1px solid #eef0f4;
  cursor: pointer;
  font-size: 13px;
}
.runs-list li:hover { background: #f5f7fb; }
.runs-list li .meta { color: #606773; font-size: 11px; }

.tables { padding: 0 16px 40px; }
.tables-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; gap: 12px; flex-wrap: wrap;
}
.mode-toggle { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.mode-toggle-label { font-size: 12px; color: #606773; margin-right: 6px; }
.mode-btn {
  padding: 6px 10px; font-size: 12px;
  background: #fff; border: 1px solid #d0d4dc; border-radius: 6px;
  cursor: pointer;
}
.mode-btn:hover { background: #f1f3f8; }
.mode-btn.active { background: #2b6cb0; color: #fff; border-color: #2b6cb0; }
.snapshot-chip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 6px 0 10px; font-size: 12px;
}
.snapshot-label { color: #606773; margin-right: 4px; }
.snapshot-pill {
  display: inline-flex; gap: 6px; align-items: baseline;
  padding: 3px 8px; border-radius: 12px;
  background: #f1f3f8; color: #2a3340; border: 1px solid transparent;
}
.snapshot-pill.active { background: #e3edf9; border-color: #2b6cb0; }
.snapshot-pill .snapshot-mode { opacity: 0.7; }
.snapshot-pill .snapshot-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.phrase-block { margin-bottom: 24px; background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.phrase-block h3 { margin: 0 0 10px; font-size: 16px; }
.phrase-block .meta { color: #606773; font-size: 12px; margin-bottom: 8px; }
.phrase-block--total { border: 2px solid #2b6cb0; background: #f8fbff; }
.phrase-block--total h3 { color: #2b6cb0; }
.phrase-block--total h3::before { content: "Σ  "; opacity: 0.6; }

table.matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.matrix th, table.matrix td {
  border: 1px solid #e5e8ee;
  padding: 6px 8px;
  text-align: right;
  white-space: nowrap;
}
table.matrix th:first-child, table.matrix td:first-child {
  text-align: left;
  font-weight: 600;
  background: #f5f7fb;
}
table.matrix thead th { background: #f5f7fb; font-weight: 600; }
table.matrix .cell .val { display: block; font-variant-numeric: tabular-nums; }
table.matrix .cell .pct { display: block; font-size: 11px; opacity: 0.9; margin-top: 2px; }
table.matrix td.missing { color: #aab0bc; }
table.matrix td.preview { color: #8a8f9c; font-style: italic; background: transparent !important; }
table.matrix td.preview .pct { opacity: 0.85; }
table.matrix td.sum { font-weight: 600; background: #fafbfe; }

/* Модалки */
.modal { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.45); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal.hidden { display: none; }
.modal-card {
  background: #fff;
  border-radius: 10px;
  width: min(520px, 92vw);
  max-height: 90vh;
  overflow: auto;
  padding: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-card h3 { margin: 0; }
.modal-card .close { background: transparent; border: none; font-size: 22px; cursor: pointer; }
.modal-card .hint { color: #606773; font-size: 13px; margin: 0 0 12px; }
.modal-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; }

.cities-list, .suggest-list { list-style: none; padding: 0; margin: 0 0 12px; }
.cities-list li, .suggest-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #eef0f4; }
.cities-list li span { flex: 1; }
.suggest-list li input { margin-right: 6px; }
.suggest-list li label { flex: 1; cursor: pointer; }
.suggest-list .suggest-freq {
  color: #606773;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  min-width: 60px;
  text-align: right;
}
.suggest-list { max-height: 50vh; overflow-y: auto; }

.add-city-form { display: flex; gap: 8px; }
.add-city-form input { flex: 1; }

/* Top-10 по городам */
.top-results { margin: 20px 16px; }
.top-header { margin-bottom: 14px; }
.top-header h2 { margin: 0 0 4px; font-size: 18px; }
.top-hint { font-size: 12px; color: #606773; }
.top-phrase-block {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.top-phrase-block h3 { margin: 0 0 10px; font-size: 15px; }
.top-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 900px) { .top-grid { grid-template-columns: 1fr; } }
.top-col { border: 1px solid #eef0f3; border-radius: 6px; padding: 8px; background: #fafbfc; }
.top-col-head { margin-bottom: 6px; }
.top-city { display: block; font-weight: 600; font-size: 13px; }
.top-query { display: block; font-size: 11px; color: #8a92a0; }
.top-list { margin: 0; padding-left: 22px; font-size: 12px; }
.top-item {
  padding: 3px 6px;
  margin: 2px -6px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.3;
  word-break: break-all;
}
.top-host { font-weight: 600; color: #1f2937; }
.top-url { color: #5b6472; text-decoration: none; font-size: 11px; }
.top-url:hover { text-decoration: underline; }
.top-empty { list-style: none; color: #8a92a0; font-style: italic; }

/* ── Публичный режим ── */
.pub-main { max-width: none; margin: 0; padding: 16px; }
.pub-card { margin-bottom: 16px; }

/* Формы (вход / проекты / новый проект) — узкие, по центру */
#screenLogin, #screenProjects, #screenEditor {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}
/* Просмотр проекта — во всю ширину экрана */
#screenView #viewTables { padding: 0; }
/* Таблица занимает всю ширину; на узких экранах — горизонтальный скролл */
#viewTables .phrase-block { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#viewTables table.matrix { min-width: 900px; }

@media (max-width: 600px) {
  .pub-main { padding: 10px; }
  .topbar { flex-wrap: wrap; gap: 6px 12px; padding: 12px 16px; }
  .topbar h1 { font-size: 16px; }
  .topbar .hint { flex-basis: 100%; order: 3; font-size: 12px; }
}
.pub-h2 { margin: 0 0 4px; font-size: 18px; }
.pub-sub { color: #606773; font-size: 13px; margin: 0 0 14px; }
.pub-row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.pub-actions { display: inline-flex; gap: 8px; }
.pub-count { color: #606773; font-size: 13px; font-weight: 400; }
.pub-login-form { display: flex; gap: 8px; flex-wrap: wrap; }
.pub-login-form #loginInput { flex: 1; min-width: 180px; }
.pub-login-form .pub-pin { width: 130px; flex: 0 0 auto; }
.pub-counter { font-size: 12px; color: #606773; font-variant-numeric: tabular-nums; margin-left: auto; }
.pub-counter.over { color: #c53030; font-weight: 600; }

/* Кнопка во время сбора — читаемая, не «выцветшая» */
.pub-card button.primary:disabled {
  opacity: 1;
  background: #8fb1d8;
  border-color: #8fb1d8;
  color: #fff;
  cursor: progress;
}
/* Отступ прогресс-бара от кнопки (только когда он есть) */
#editorProgress:not(:empty),
#viewProgress:not(:empty) { margin-top: 16px; }
/* Прогресс в публичном режиме — чуть выше и контрастнее */
.pub-card .progress-bar { height: 22px; border-radius: 11px; background: #e8edf5; }
.pub-card .progress-label { color: #1f2430; }
.pub-card .progress-msg { margin-top: 2px; }
