/* Design tokens */
:root {
  --bg: #f6f7fb; --surface: #fff; --surface-2: #f9fafb; --text: #111827; --muted: #6b7280;
  --border: #e5e7eb; --border-strong: #d1d5db; --primary: #4f46e5; --primary-hover: #4338ca;
  --primary-soft: #eef2ff; --on-primary: #fff; --growth: #ea580c;
  --success: #15803d; --success-bg: #dcfce7; --warning: #b45309; --warning-bg: #fef3c7;
  --danger: #b91c1c; --danger-bg: #fee2e2; --info-bg: #eef2ff;
  --radius: 10px; --radius-lg: 14px; --shadow: 0 1px 2px rgba(17,24,39,.05), 0 1px 3px rgba(17,24,39,.06);
  --shadow-lg: 0 10px 30px rgba(17,24,39,.10);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Nirmala UI", "Noto Sans Devanagari", "Noto Sans Bengali", sans-serif; font-variant-numeric: tabular-nums; }
.hint { display: inline-block; position: relative; vertical-align: middle; line-height: 1; }
.hint .hint-btn { position: relative; display: inline-flex; width: 20px; height: 20px; min-height: 0; padding: 0; border: 1px solid var(--border-strong); border-radius: 50%; background: transparent; color: var(--muted); font-size: 13px; font-weight: normal; }
.hint-bubble { display: none; position: absolute; z-index: 30; bottom: calc(100% + 8px); left: 0; width: max-content; max-width: 280px; padding: 12px; background: white; color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 13px; line-height: 1.4; font-weight: normal; text-align: left; }
.hint.open .hint-bubble { display: block; }
/* Пузырь стоит внутри подписей плиток и заголовков таблиц: не наследуем их мелкий серый шрифт. */
.hint > .hint-bubble { font-size: 13px !important; color: var(--text) !important; font-weight: 400 !important; text-transform: none !important; letter-spacing: normal !important; white-space: normal !important; }
@media (hover: hover) { .hint:hover .hint-bubble, .hint:focus-within .hint-bubble { display: block; } }
@media (max-width: 640px) { .hint .hint-btn::after { content: ''; position: absolute; inset: -6px; } .hint-bubble { position: fixed; left: 12px; right: 12px; bottom: 70px; width: auto; max-width: none; z-index: 19; } }
.language-form label { display: flex; align-items: center; gap: 8px; }
.language-form select { width: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
h1 { font-size: 24px; line-height: 1.25; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); overflow-wrap: anywhere; }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
main { max-width: 1384px; margin: auto; padding: 32px; min-width: 0; overflow-wrap: anywhere; }
body:has(.sidebar) main { margin-left: 240px; }
main svg, .otp-qr { max-width: 100%; height: auto; }

/* Navigation */
.sidebar { position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; width: 240px; padding: 22px 12px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; z-index: 10; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; display: inline-grid; place-items: center; background: var(--primary); border-radius: 8px; flex: none; }
.brand-mark::after { content: ''; border-left: 10px solid white; border-top: 6px solid transparent; border-bottom: 6px solid transparent; margin-left: 2px; }
.sidebar > .brand { margin: 0 8px 20px; }
.side-nav { display: flex; flex: 1 0 auto; flex-direction: column; gap: 2px; }
.side-nav > strong { padding: 18px 12px 5px; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.side-nav a, .side-user button { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; }
.side-nav a:hover, .side-user button:hover { background: var(--surface-2); color: var(--primary); }
.side-nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.side-nav svg { flex: none; }
.side-user { border-top: 1px solid var(--border); margin-top: auto; padding-top: 20px; }
.side-user button { margin: 0; }
.mobile-header, .tabbar { display: none; }
.auth-brand { text-align: center; padding: 24px 16px 0; }
.auth-card { max-width: 400px; margin: 8vh auto 2rem; }
.auth-card-brand { margin-bottom: 24px; }

/* Components */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-header h1 { margin: 0; }
.page-subtitle { color: var(--muted); margin: 5px 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.btn, button, input[type=submit] { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--primary); border-radius: 8px; background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer; text-align: center; }
.btn:hover, button:hover { background: var(--primary-hover); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text); border-color: transparent; }
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-small { min-height: 36px; padding: 6px 10px; font-size: .875rem; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-block { width: 100%; }
.card, .finding-card { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 1rem; }
.card-title { margin: 0; }
.card-subtitle { color: var(--muted); margin: 4px 0 0; }
.stack > * + * { margin-top: .75rem; }
.grid-2, .grid-3, .finding-grid, .kpis { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.kpis { grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); margin: 1rem 0; }
.kpi { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow); }
.kpi strong { display: block; font-size: 22px; white-space: nowrap; letter-spacing: -.01em; }
.muted, .kpi span, .kpi-label { color: var(--muted); font-size: .9em; }
.kpi-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.flat { color: var(--muted); }
.badge, .network { display: inline-block; border-radius: 999px; padding: .2rem .6rem; font-size: .8rem; font-weight: 650; background: var(--info-bg); }
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }
.badge-error { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); }
.badge-muted { background: var(--bg); color: var(--muted); }
.alert { padding: 1rem; border-left: 4px solid var(--primary); border-radius: var(--radius); margin: 1rem 0; }
.alert-info { background: var(--info-bg); }
.alert-warn { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.chips-row, .feed-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip, .feed-chips a { display: inline-flex; align-items: center; gap: 5px; min-height: 32px; padding: 4px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); text-decoration: none; color: var(--text); }
.chip.active, .feed-chips a.active { background: var(--primary); border-color: var(--primary); color: white; }
.chip small { font-size: .75em; opacity: .8; }
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 0; color: var(--muted); text-decoration: none; }
.tab.active { border-bottom: 2px solid var(--primary); color: var(--primary); }

/* Forms and tables */
label { display: block; }
input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea { display: block; width: 100%; max-width: 36rem; min-width: 0; min-height: 40px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; vertical-align: middle; accent-color: var(--primary); }
form p { max-width: 36rem; }
form button { margin-top: .5rem; }
fieldset { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); margin: 1rem 0; }
.error, .errorlist { color: var(--danger); }
.chips label { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem; margin: .2rem; min-height: 44px; }
main > form:not(.feed-tools) { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 20px; margin: 1rem 0; }
.chips label:has(input:checked) { background: var(--info-bg); border-color: var(--primary); }
.table-wrap { overflow-x: auto; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 13px; color: var(--muted); background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }
.period-form, .query-tools, .review-actions, .history-actions { display: flex; flex-wrap: wrap; align-items: end; gap: .5rem; }
.period-form button, .query-tools button { margin: 0; }

/* Findings */
.finding-grid { grid-template-columns: 1fr; margin-top: 1rem; align-items: start; }
.finding-card { position: relative; padding: 14px; }
.finding-main { display: flex; gap: 12px; min-width: 0; }
.finding-body { min-width: 0; flex: 1; }
.finding-preview { width: 96px; height: 128px; flex: none; overflow: hidden; border-radius: 8px; background: var(--bg); }
.finding-preview img, .finding-placeholder { width: 100%; height: 100%; object-fit: cover; }
.finding-placeholder { display: grid; place-items: center; }
.finding-placeholder[hidden] { display: none; }
.finding-card h2 { margin: 0 30px 5px 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 1rem; }
.finding-author, .finding-badges, .engagement { margin: 4px 0; font-size: .85rem; }
.finding-author { color: var(--muted); }
.finding-metrics { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 9px; font-size: .85rem; font-weight: 600; }
.finding-metrics span { display: inline-flex; align-items: center; gap: 3px; }
.growth { color: var(--growth); }
.engagement-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 4px; }
.engagement.strong .engagement-dot { background: var(--success); }
.engagement.medium .engagement-dot { background: #eab308; }
.favorite-form { position: absolute; right: 12px; top: 12px; }
.favorite-button { min-width: 40px; min-height: 40px; padding: 8px; margin: 0; background: var(--surface); border: 0; color: var(--muted); }
.favorite-button:hover, .favorite-button.is-favorite { color: var(--danger); background: var(--danger-bg); }
.favorite-button.is-favorite svg { fill: currentColor; }
.finding-story { margin: 0 40px 10px 0; font-size: .85rem; }
.finding-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.finding-actions .finding-more { margin-left: auto; }
.finding-body .finding-translation { margin: 0 0 4px; color: var(--muted); font-size: .8rem; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.more-panel select { width: auto; max-width: 160px; min-height: 36px; font-size: .85rem; }
.finding-actions form { display: flex; flex-wrap: wrap; gap: 4px; }
.finding-actions button { margin: 0; }
.finding-actions select { width: auto; max-width: 130px; min-height: 36px; font-size: .85rem; }
.finding-more, .filter-menu { position: relative; }
summary { cursor: pointer; }
.finding-more summary, .filter-menu summary { list-style: none; }
.more-panel, .filter-panel { position: absolute; z-index: 8; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 14px; min-width: 240px; }
.more-panel { right: 0; }
.more-panel form, .more-panel a { margin: 4px 0; }
.finding-details { margin-top: 10px; color: var(--muted); font-size: .85rem; }
.finding-details p { margin: 6px 0; }
.feed-tools { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.feed-tools > label { font-size: .85rem; color: var(--muted); }
.feed-count { margin: 0 0 8px auto; }
.filter-panel { left: 0; width: min(600px, 90vw); }
.filters { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: .5rem .75rem; align-items: end; }
.filters label { font-size: .85rem; color: var(--muted); }

/* Existing page helpers */
.caption { white-space: pre-wrap; overflow-wrap: anywhere; font-family: monospace; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.task-card { display: block; color: var(--text); text-decoration: none; }
.task-card:hover { border-color: var(--primary); color: var(--text); }
.owner-publications-cards { display: none; }
.view-count { font-size: 1.35rem; }
.yt-download { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; font-size: .9rem; }
.finding-translation { overflow-wrap: anywhere; }
.review-item { padding: .75rem 0; border-top: 1px solid var(--border); }
.review-item ul { margin: .4rem 0; }
.review-actions { margin-top: .5rem; }
.payout-table table { min-width: 46rem; }
.earning-card h2 { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: 0 0 .5rem; }
.earning-card p { margin: .25rem 0; }
#id_languages, #id_default_search_languages { display: flex; flex-wrap: wrap; gap: .35rem; max-height: 14rem; overflow: auto; width: 100%; min-width: 0; }
#id_languages > div, #id_default_search_languages > div { max-width: 100%; }
#id_languages > div[hidden], #query-file[hidden] { display: none; }
.query-tools { margin: .25rem 0; }
.chips .query-tools label { cursor: pointer; margin: 0; background: var(--surface); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.js-suggestion.is-added { background: var(--success-bg); color: var(--success); border-color: var(--success); }
#id_query_text { width: 100%; }
.chips label[for=id_query_text] { display: block; border: 0; padding: 0; margin: 0; min-height: 0; }
.query-suggest { margin: 0 0 1rem; }
.suggestions { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .5rem; }
.suggestions .btn { white-space: normal; text-align: left; height: auto; }
.suggestions .muted { display: block; font-size: .85rem; margin-top: .15rem; }
.query-comparison { min-width: 1100px; }
.search-history { min-width: 980px; }
.query-comparison th, .query-comparison td, .search-history th, .search-history td, .search-history a { overflow-wrap: normal; word-break: normal; }
.query-comparison td:nth-child(2), .search-history td:nth-child(2) { min-width: 15rem; overflow-wrap: anywhere; }
.chart-scroll { overflow-x: auto; }
.chart-scroll svg { display: block; width: 100%; height: auto; }
@media (min-width: 720px) { .finding-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media (min-width: 1100px) { .finding-grid { grid-template-columns: repeat(3,minmax(0,1fr)); } }
@media (min-width: 1400px) { .finding-grid { grid-template-columns: repeat(4,minmax(0,1fr)); } }
@media (max-width: 1023px) {
  .sidebar { display: none; }
body:has(.sidebar) main { margin-left: auto; }
.mobile-header { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .mobile-menu { position: relative; }
.mobile-menu summary { display: flex; align-items: center; gap: 5px; min-height: 44px; cursor: pointer; list-style: none; }
.menu-panel { position: absolute; z-index: 20; right: 0; top: 100%; width: min(320px,90vw); max-height: 80vh; overflow: auto; padding: 12px; background: var(--surface); box-shadow: var(--shadow-lg); border: 1px solid var(--border); border-radius: var(--radius); }
}
@media (max-width: 719px) {
  body { font-size: 16px; }
main { padding: 16px; }
.page-actions { width: 100%; margin-left: 0; }
.btn, button, input[type=submit] { min-height: 44px; }
.grid-2, .grid-3 { grid-template-columns: 1fr; }
  .employee main { padding-bottom: 5.5rem; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 9; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { min-height: 56px; display: flex; align-items: center; justify-content: center; flex-direction: column; color: var(--muted); text-decoration: none; font-size: .7rem; line-height: 1.1; text-align: center; }
.tabbar a.active { color: var(--primary); font-weight: 700; }
.tabbar svg { width: 22px; height: 22px; margin-bottom: 3px; }
  .owner-publications-table { display: none; }
.owner-publications-cards { display: block; }
.period-form > * { flex: 1 1 9rem; }
  .general-hashtags, .general-hashtags tbody, .general-hashtags tr, .general-hashtags td { display: block; width: 100%; }
.general-hashtags thead { display: none; }
.general-hashtags tr { border-bottom: 1px solid var(--border); padding: .5rem 0; }
.general-hashtags td { border: 0; padding: .2rem 0; overflow-wrap: anywhere; }
.general-hashtags td[data-label]::before { content: attr(data-label) ': '; color: var(--muted); }
}

/* Телефон: чипы — одной прокручиваемой строкой, крупные числа плиток не ломаются на две строки. */
@media (max-width: 719px) {
  .chips-row, .feed-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
  .chips-row::-webkit-scrollbar, .feed-chips::-webkit-scrollbar { display: none; }
  .chip, .feed-chips a { flex: none; }
  .kpi strong { font-size: 1.2rem; }
}
