/* Стиль взят с семантического завода Adonis (Semantic Factory, Штаб:3030)
   по решению руководителя 01.09.2026: внешний вид должен совпадать.
   Чужой код - правим по минимуму, только то, чего у них нет под наши данные.
   Источник: http://87.199.202.204:3030/static/css/app.css, снят 01.09.2026 */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-alt: #f9fafb;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-contrast: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 8px rgba(0, 0, 0, 0.04);
    --tofu: #0369a1; --mofu: #b45309; --bofu: #b91c1c;
    --approved: #059669; --maybe: #d97706; --rejected: #dc2626; --pending: #9ca3af;
    --approved-bg: #d1fae5; --maybe-bg: #fef3c7; --rejected-bg: #fee2e2; --pending-bg: #f3f4f6;
}
[data-theme="dark"] {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-alt: #20242d;
    --text: #e6e8eb;
    --text-muted: #9aa0aa;
    --border: #2c313c;
    --accent: #4f8cff;
    --accent-contrast: #0f1115;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
    --approved-bg: #103a2c; --maybe-bg: #3a2f12; --rejected-bg: #3a1414; --pending-bg: #20242d;
}
* { box-sizing: border-box; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 0.92rem;
    max-width: 1500px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 4rem;
    color: var(--text);
    background: var(--bg);
    transition: background 0.15s ease, color 0.15s ease;
}
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0.25rem 0 0.25rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }
.sub { color: var(--text-muted); font-size: 0.88rem; }

header.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.05rem; }
.brand-sub { color: var(--text-muted); font-size: 0.8rem; font-weight: 400; }
nav { display: flex; gap: 0.25rem; margin-bottom: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.35rem; box-shadow: var(--shadow); flex-wrap: wrap; }
nav a { text-decoration: none; color: var(--text-muted); font-weight: 500; padding: 0.4rem 0.85rem; border-radius: 7px; font-size: 0.92rem; }
nav a:hover, nav a.active { background: var(--surface-alt); color: var(--text); }
.theme-toggle { cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 0.4rem 0.7rem; font-size: 0.95rem; box-shadow: var(--shadow); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 1rem 1.25rem; margin-bottom: 1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

button, select, input[type=text], textarea, a.btn {
    font-family: inherit; cursor: pointer; padding: 0.35rem 0.75rem; border-radius: 7px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.88rem;
}
a.btn { display: inline-block; text-decoration: none; line-height: 1.5; }
button.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--rejected-bg); color: var(--rejected); border-color: var(--rejected); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
form.inline { display: inline; }

/* ─── Карточки проектов ─── */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.project-card { display: block; text-decoration: none; color: inherit; }
.project-card .name { font-weight: 700; font-size: 1.02rem; margin-bottom: 0.15rem; }
.project-card .client { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.6rem; }
.project-card .meta-row { display: flex; gap: 0.75rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.6rem; }
.project-card .pct-bar { height: 6px; border-radius: 999px; background: var(--pending-bg); overflow: hidden; }
.project-card .pct-bar > div { height: 100%; background: var(--approved); }

/* ─── Статистика ─── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.75rem; margin: 0.75rem 0 1rem; }
.stat-card { text-align: center; background: var(--surface-alt); border-radius: 8px; padding: 0.6rem; }
.stat-card .value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .label { color: var(--text-muted); font-size: 0.75rem; margin-top: 0.15rem; }

/* ─── Этапы (progress bar) ─── */
.stage-bar { display: flex; gap: 0.4rem; margin: 0.75rem 0 1rem; flex-wrap: wrap; }
.stage-step { flex: 1; min-width: 110px; text-align: center; padding: 0.5rem 0.4rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--text-muted); font-size: 0.82rem; font-weight: 600; }
.stage-step.current { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.stage-step button { all: unset; cursor: pointer; display: block; width: 100%; }

/* ─── Панель инструментов / фильтры / поиск ─── */
.toolbar { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1 1 240px; max-width: 320px; }
#search { width: 100%; }
.search-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; display: none; }
.search-results.open { display: block; }
.search-results .item { padding: 0.45rem 0.7rem; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.search-results .item:hover { background: var(--surface-alt); }
.search-results .item small { color: var(--text-muted); display: block; }

/* ─── Кластеры (аккордеон) ─── */
details.cluster { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 0.6rem; box-shadow: var(--shadow); }
details.cluster[hidden] { display: none; }
details.cluster summary { list-style: none; cursor: pointer; padding: 0.7rem 1rem; display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
details.cluster summary::-webkit-details-marker { display: none; }
details.cluster summary .cname { font-weight: 700; flex: 1 1 240px; }
details.cluster summary .cmeta { color: var(--text-muted); font-size: 0.82rem; }
.cluster-pct { font-size: 0.78rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--surface-alt); }
.cluster-body { padding: 0 1rem 1rem; }

/* ─── Строки ключей ─── */
tr.kw-row.filtered-out { display: none; }
.kw-text { cursor: pointer; }
.kw-text:hover { text-decoration: underline; }
.badge-funnel { font-size: 0.72rem; font-weight: 700; padding: 0.1rem 0.4rem; border-radius: 5px; color: #fff; }
.badge-funnel.ToFu { background: var(--tofu); }
.badge-funnel.MoFu { background: var(--mofu); }
.badge-funnel.BoFu { background: var(--bofu); }
.decision-buttons { display: flex; gap: 0.25rem; }
.decision-buttons button { padding: 0.2rem 0.45rem; font-size: 0.95rem; line-height: 1; border-radius: 6px; }
.decision-buttons button.active { border-color: var(--accent); background: var(--accent); }
.decision-buttons button[data-decision=approved].active { background: var(--approved); border-color: var(--approved); }
.decision-buttons button[data-decision=maybe].active { background: var(--maybe); border-color: var(--maybe); }
.decision-buttons button[data-decision=rejected].active { background: var(--rejected); border-color: var(--rejected); }
.decision-current { font-size: 0.78rem; color: var(--text-muted); }

/* ─── Боковая панель ключа ─── */
#kw-panel { position: fixed; top: 0; right: -360px; width: 340px; height: 100%; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow); padding: 1.25rem; overflow-y: auto; transition: right 0.2s ease; z-index: 50; }
#kw-panel.open { right: 0; }
#kw-panel .close-btn { float: right; }
#kw-panel dl { margin: 1rem 0; }
#kw-panel dt { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; margin-top: 0.6rem; }
#kw-panel dd { margin: 0.1rem 0 0; font-size: 0.92rem; }

/* ─── Приоритет (ручная очередь заказчика, светофор 1-5) ─── */
.priority-chips { display: flex; gap: 0.2rem; }
.priority-chips button { width: 22px; height: 22px; padding: 0; font-size: 0.72rem; line-height: 1; border-radius: 5px; opacity: 0.45; }
.priority-chips button.active, .priority-chips button:hover { opacity: 1; }
.priority-chips button.prio-1 { background: #86efac; color: #14532d; border-color: #86efac; }
.priority-chips button.prio-2 { background: #4ade80; color: #14532d; border-color: #4ade80; }
.priority-chips button.prio-3 { background: #16a34a; color: #fff; border-color: #16a34a; }
.priority-chips button.prio-4 { background: #14532d; color: #fff; border-color: #14532d; }

/* ─── Порядок работы (канбан по приоритету) ─── */
.priority-board { display: grid; gap: 0.75rem; padding-bottom: 1rem; align-items: start; }
.priority-col { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; max-height: 75vh; box-shadow: var(--shadow); }
.priority-col-header { padding: 0.6rem 0.8rem; border-radius: 10px 10px 0 0; font-weight: 700; display: flex; justify-content: space-between; align-items: center; color: #fff; }
.priority-col-header.prio-col-1 { background: #86efac; color: #14532d; }
.priority-col-header.prio-col-2 { background: #4ade80; color: #14532d; }
.priority-col-header.prio-col-3 { background: #16a34a; }
.priority-col-header.prio-col-4 { background: #14532d; }
.priority-col-header.prio-col-none { background: var(--text-faint, #9ca3af); }
.priority-col-header .count { background: rgba(255,255,255,0.28); border-radius: 999px; padding: 0.05rem 0.55rem; font-size: 0.8rem; }
.priority-col-body { padding: 0.5rem; overflow-y: auto; flex: 1; min-height: 60px; }
.priority-col-body.drag-over { background: var(--surface-alt); }
.priority-card { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 7px; padding: 0.45rem 0.6rem; margin-bottom: 0.4rem; cursor: grab; font-size: 0.82rem; }
.priority-card.dragging { opacity: 0.4; }
.pc-kw { font-weight: 600; }
.pc-meta { color: var(--text-muted); font-size: 0.72rem; margin-top: 0.15rem; }

/* ─── Массовые действия ─── */
#bulk-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 0.6rem 0.9rem; display: none; align-items: center; gap: 0.6rem; z-index: 40; flex-wrap: wrap; }
#bulk-bar.open { display: flex; }

/* ─── Клиентский вид ─── */
.client-decision-buttons button { padding: 0.3rem 0.6rem; }
.discuss-field { margin-top: 0.4rem; display: none; }
.discuss-field.open { display: block; }

/* ─── Требуют внимания ─── */
.attention-item { border-bottom: 1px solid var(--border); padding: 0.5rem 0; }
.attention-item:last-child { border-bottom: none; }
.attention-item .comment { color: var(--text-muted); font-style: italic; margin-top: 0.15rem; }

@media (max-width: 768px) {
    body { padding: 1rem 0.75rem 3rem; }
    table { display: block; overflow-x: auto; white-space: nowrap; }
    #kw-panel { width: 100%; right: -100%; }
    .priority-board { display: flex; overflow-x: auto; }
    .priority-col { flex: 0 0 260px; }
}
