:root {
    --bg: #f4f6f8;
    --surface: #fff;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #1f2933;
    --muted: #64748b;
    --soft: #475569;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #2f8f5b;
    --accent-dark: #277a4d;
    --danger: #b06a6a;
    --danger-dark: #9b4a4a;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-md: 0 8px 28px rgba(15, 23, 42, .12);
    --ring: 0 0 0 3px rgba(37, 99, 235, .30);
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 18px 0 14px; letter-spacing: -.2px; }
h2 { font-size: 15px; margin: 24px 0 10px; color: #334155; }

/* Доступный фокус для клавиатуры */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: none; border-color: var(--primary); box-shadow: var(--ring); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
input, select, textarea { font-family: inherit; transition: border-color .12s ease, box-shadow .12s ease; }

/* Лёгкая глубина у поверхностей-карточек */
.card, .panel, .filters, .form-grid, .trend, .user-new, table.grid { box-shadow: var(--shadow-sm); }

.topbar {
    display: flex; align-items: center; gap: 24px;
    background: #1e293b; color: #fff; padding: 12px 24px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.brand a { color: #fff; }
.brand a:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 16px; align-items: center; flex-wrap: nowrap; }
.topbar nav a { color: #cbd5e1; padding: 4px 1px; transition: color .12s ease; white-space: nowrap; }
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a.active { color: #fff; box-shadow: inset 0 -2px 0 #6f9ae6; }
.brand { flex-shrink: 0; }

/* Выпадающие группы в шапке («Отчёты», «Управление») */
.nav-group { position: relative; display: flex; align-items: center; }
.nav-top { background: none; border: none; color: #cbd5e1; font: inherit; cursor: pointer;
    padding: 4px 1px; white-space: nowrap; transition: color .12s ease;
    display: inline-flex; align-items: center; gap: 4px; }
.nav-top:hover { color: #fff; }
.nav-top.active { color: #fff; box-shadow: inset 0 -2px 0 #6f9ae6; }
.nav-menu { display: none; position: absolute; top: 100%; left: 0; min-width: 190px;
    background: #1e293b; border: 1px solid #334155; border-radius: 8px; padding: 6px;
    box-shadow: var(--shadow-md); z-index: 60; flex-direction: column; gap: 2px; }
.nav-group:hover .nav-menu, .nav-group:focus-within .nav-menu { display: flex; }
.nav-menu a { color: #cbd5e1; padding: 7px 12px; border-radius: 6px; white-space: nowrap; }
.nav-menu a:hover { background: #334155; color: #fff; text-decoration: none; }
.nav-menu a.active { color: #fff; background: #334155; box-shadow: none; }

.btn-add { background: #2f8f5b; color: #fff !important; padding: 6px 12px; border-radius: 6px;
    white-space: nowrap; flex-shrink: 0; }
.btn-add:hover { background: #277a4d; }

main { max-width: 1240px; margin: 0; padding: 18px 24px 60px; }

/* Карточки сводки */
.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.card {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
    padding: 14px 18px; min-width: 150px; flex: 1;
    border-left: 4px solid #cbd5e1;
}
.card-num { font-size: 26px; font-weight: 700; }
.card-lbl { color: #64748b; font-size: 13px; margin-top: 2px; }
.card.attn-soon { border-left-color: #d8b365; }
.card.attn-expired { border-left-color: #c98a8a; }

/* Таблицы */
table.grid { width: 100%; border-collapse: collapse; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
    font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 10px 14px; text-align: left; border-bottom: 1px solid #eef2f6; vertical-align: top; }
.grid th { background: #f8fafc; font-size: 12px; text-transform: uppercase;
    letter-spacing: .4px; color: var(--muted); }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { background: #eef2f6; color: #334155; }
.grid th .sort-ind { color: var(--accent); }
.grid th.r, .grid td.r { text-align: right; }
.grid td.r { font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid tbody tr:nth-child(even) { background: #fafbfd; }
.grid tbody tr:hover { background: #eef3f8; }
.grid tr.row-stale > td:first-child { border-left: 3px solid #d8b365; padding-left: 9px; }
.stale-login { color: #8a6d2f; }
.grid tfoot th { background: #f8fafc; font-weight: 700; color: #334155; padding: 9px 12px;
    text-align: left; border-top: 2px solid #e2e8f0; text-transform: none; letter-spacing: 0; font-size: 13px; }
.grid tfoot th.r { text-align: right; }
.vat-table { max-width: 760px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ellipsis.addr-col { max-width: 190px; }
.table-wrap { overflow-x: auto; }
.map-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
/* Карта во всю ширину окна и почти на весь экран */
.map-full { width: 100vw; margin-left: -24px; height: calc(100vh - 195px);
    min-height: 460px; border-top: 1px solid #e2e8f0; border-bottom: 1px solid #e2e8f0; }
.leaflet-popup-content a { font-weight: 600; }
/* Топ аренд: компактнее, чтобы все столбцы (включая сумму) влезали */
.top-table th, .top-table td { padding-left: 8px; padding-right: 8px; }
.top-table td.ellipsis { max-width: 140px; }
.top-table .cno { max-width: 120px; }
.rowlink { cursor: pointer; }
.cno { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; vertical-align: middle; }

/* Подсветка строк по сроку — мягко, только проблемные */
tr.st-expired td:first-child { box-shadow: inset 3px 0 0 #c98a8a; }
tr.st-soon td:first-child { box-shadow: inset 3px 0 0 #d8b365; }

/* Метки и «пилюли» */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.soon { background: #f4ecd6; color: #8a6d2f; }
.pill.expired { background: #f5e1e1; color: #9b4a4a; }
.tag-ds { display: inline-block; padding: 1px 6px; border-radius: 4px;
    background: #e2e8f0; color: #475569; font-size: 10px; font-weight: 600; vertical-align: 1px; }

/* Метки компаний холдинга — мягкие тона */
.co { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
    font-weight: 600; white-space: nowrap; }
.co-ФТО { background: #dbe4f0; color: #3a5273; }
.co-ФТ  { background: #dde8df; color: #3d6b49; }
.co-ФДЦ { background: #efe3d4; color: #7a5a32; }
.card-co { margin-bottom: 4px; }
.card-sub { font-size: 12px; margin-top: 4px; }

/* Фильтры */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 12px; }
.filters select, .filters input { padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px; }
.filters input[name="q"] { flex: 1; min-width: 240px; }
.count { color: #64748b; margin: 12px 2px; }
button { cursor: pointer; padding: 7px 14px; border: none; border-radius: var(--radius-sm);
    background: var(--primary); color: #fff; font-size: 14px; font-weight: 500;
    transition: background .12s ease, box-shadow .12s ease, transform .04s ease; }
button:hover { background: var(--primary-dark); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.secondary { background: #eef2f6; color: var(--soft); }
button.secondary:hover { background: #e2e8f0; }
.reset { color: var(--muted); }

/* Карточка договора */
.back { margin: 6px 0; }
.card-head { display: flex; align-items: baseline; gap: 12px; }
.note-link { background: #eef4fb; border: 1px solid #d6e4f5; color: #1e3a5f;
    padding: 8px 12px; border-radius: 8px; font-size: 13px; margin: 6px 0; }

.banner { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin: 8px 0 4px; }
.banner.soon { background: #f7f1e0; border: 1px solid #e6d6a8; color: #7a6224; }
.banner.expired { background: #f7e7e7; border: 1px solid #e3bcbc; color: #8a3f3f; }
.banner.prolonged { background: #eef2f5; border: 1px solid #d6dde3; color: #51606b; }

/* Призыв на сводке */
.cta { margin: 14px 0 4px; }
.cta a { font-weight: 600; }

/* Страница контроля сроков */
.bucket-h { display: flex; align-items: center; gap: 10px; padding-left: 10px; border-left: 4px solid #cbd5e1; }
.bucket-h.expired { border-left-color: #c98a8a; }
.bucket-h.soon { border-left-color: #d8b365; }
.bucket-h.later { border-left-color: #9bb4cc; }
.bucket-n { font-size: 12px; font-weight: 600; color: #64748b; background: #eef2f6; border-radius: 999px; padding: 1px 9px; }
.empty { margin: 6px 0 4px 12px; }
td .neg { color: #9b4a4a; font-weight: 600; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 18px;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; }
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: #475569; gap: 4px; }
.form-grid label.wide { grid-column: span 3; }
.fld-lbl { color: #64748b; font-size: 12px; }
.req { color: #b06a6a; font-weight: 700; }
/* Подсветка пустых обязательных полей — мягко */
.form-grid input.missing, .form-grid select.missing, .form-grid textarea.missing {
    background: #fbf6e6; border-color: #ddc77a; }
.form-grid label.lbl-missing .fld-lbl { color: #8a6d2f; }
.form-grid input, .form-grid select, .form-grid textarea {
    padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px; color: #1f2933; }
.form-grid textarea { resize: vertical; font-family: inherit; }

.actions { margin: 20px 0; display: flex; gap: 12px; align-items: center; }
.btn-ghost { color: #64748b; }

.history th, .history td { font-size: 12px; }

/* Документы (вложения) */
.docs { max-width: 760px; }
.upload-form { display: flex; align-items: center; gap: 12px; margin-top: 12px;
    background: #fff; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 12px; }
.small-btn { padding: 3px 9px; font-size: 12px; }
button.danger.small-btn { margin: 0; }

/* Экспорт */
.export-link { margin-left: 14px; font-size: 13px; }

/* Стадия оформления — «пилюля» */
.stage { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
    font-weight: 600; white-space: nowrap; background: #e6edf5; color: #3f5670; }
.stage-Действует { background: #dde8df; color: #3d6b49; }

/* Воронка оформления */
.funnel { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; max-width: 920px; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 56px 160px; align-items: center;
    gap: 14px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow-sm); color: var(--text); }
.funnel-row:hover { text-decoration: none; background: #f7f9fc; }
.funnel-name { font-weight: 600; }
.funnel-bar { height: 14px; background: #eef2f6; border-radius: 7px; overflow: hidden; }
.funnel-fill { display: block; height: 100%; background: #7fa6c9; border-radius: 7px; min-width: 2px; }
.funnel-fill.none { background: #cbd5e1; }
.funnel-n { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.funnel-sum { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

/* Контроль рисков */
.flagbar { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 6px; }
.flag { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 8px 14px; color: var(--soft); box-shadow: var(--shadow-sm); font-size: 13px; }
.flag:hover { text-decoration: none; background: #f7f9fc; }
.flag b { color: var(--text); font-size: 16px; margin-right: 4px; }
.panel h2:not(:first-of-type) { margin-top: 22px; }
.grid tr.grp > td { background: #eef2f6; font-weight: 600; color: #334155; }
.grid tr.grp-start > td { border-top: 2px solid #d9e1ea; }
.bf-bar { position: relative; display: inline-block; width: 180px; height: 12px;
    background: #eef2f6; border-radius: 6px; vertical-align: middle; overflow: hidden; }
.bf-fill { position: absolute; left: 0; top: 0; height: 100%; background: #7fa6c9; border-radius: 6px; }
.bf-exp { position: absolute; top: -2px; width: 2px; height: 16px; background: #9b4a4a; }

/* Полоса доли (дашборд исполнителей) */
.pbar { display: inline-block; width: 160px; height: 10px; background: #eef2f6;
    border-radius: 5px; overflow: hidden; vertical-align: middle; }
.pbar-fill { display: block; height: 100%; background: #7fa6c9; border-radius: 5px; }
.topcities { font-size: 13px; color: #334155; white-space: nowrap; }

/* Итоги недели */
.week-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.week-nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.week-range { font-weight: 600; color: #334155; }
.week-quick { display: flex; gap: 8px; margin: 6px 0 14px; }
.week-quick a { padding: 5px 12px; border: 1px solid #cbd5e1; border-radius: 6px;
    font-size: 13px; color: #475569; background: #fff; }
.week-quick a.active { background: #2f8f5b; color: #fff; border-color: #2f8f5b; }
.small { font-size: 13px; font-weight: 400; }
.delta { font-size: 12px; margin-top: 4px; }
.delta.up { color: #2f8f5b; }
.delta.down { color: #9b4a4a; }

.trend { display: flex; align-items: flex-end; gap: 10px; background: #fff;
    border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px 18px 10px; height: 150px; }
.trend-bar { flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: flex-end; gap: 3px; height: 100%; text-decoration: none; }
.trend-bar:hover { text-decoration: none; }
.trend-n { font-size: 12px; color: #64748b; }
.trend-fill { width: 60%; max-width: 38px; background: #aebfd4; border-radius: 4px 4px 0 0; min-height: 2px; }
.trend-bar:hover .trend-fill { background: #8aa1c2; }
.trend-bar.sel .trend-fill { background: #2f8f5b; }
.trend-bar.sel .trend-n { color: #2f8f5b; font-weight: 700; }
.trend-x { font-size: 11px; color: #94a3b8; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; margin-top: 16px; }
.panel h2 { margin-top: 0; }
.panel .grid { border: none; }
.panel .grid td { border-bottom: 1px solid #f1f5f9; }

/* Пользователь в шапке и роли */
.whoami { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; flex-shrink: 0; }
.whoami .me { color: #fff; font-weight: 600; }
.whoami .logout { color: #cbd5e1; }
.whoami .logout:hover { color: #fff; }
.role-badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.role-admin { background: #e7dca8; color: #6b5512; }
.role-editor { background: #c4d4e8; color: #2f4a6b; }
.role-viewer { background: #e2e8f0; color: #475569; }
.readonly-note { background: #f3f1e8; border: 1px solid #e3dcc4; color: #6b5b2e;
    padding: 8px 12px; border-radius: 8px; font-size: 13px; }

/* Вход */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: #1e293b; margin: 0; }
.login-card { background: #fff; border-radius: 12px; padding: 28px 30px; width: 320px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-brand { font-size: 19px; font-weight: 700; text-align: center; margin-bottom: 18px; color: #1e293b; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #475569; }
.login-card input { padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px; }
.login-card button { padding: 10px; font-size: 15px; }
.login-error { background: #f5e1e1; color: #9b4a4a; padding: 8px 10px; border-radius: 6px; font-size: 13px; }

/* Управление пользователями */
.user-new { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 14px; }
.user-new > label, .user-new .field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #475569; }
.user-new input, .user-new select, .user-row input, .user-row select {
    padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px; }
.user-new button { margin-top: 20px; }
.user-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.user-row .chk { font-size: 13px; color: #475569; display: flex; align-items: center; gap: 4px; }
.user-row .city-field { display: flex; flex-direction: column; gap: 3px; }
.city-checks { display: grid; grid-template-columns: repeat(4, max-content); gap: 3px 16px;
    border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px 10px; background: #fafcff; }
.city-checks label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #334155; font-weight: 400; cursor: pointer; }
.city-checks input { width: auto; padding: 0; }
button.danger { background: #b06a6a; margin-top: 8px; margin-right: 8px; }
button.danger:hover { background: #9b4a4a; }
.del-list { display: flex; flex-wrap: wrap; gap: 0; }

/* Модальное окно (удаление с передачей договоров) */
dialog.modal { border: none; border-radius: 10px; padding: 0; max-width: 480px; width: 92%;
    box-shadow: 0 12px 48px rgba(15,23,42,.28); color: #1f2933; }
dialog.modal::backdrop { background: rgba(15,23,42,.45); }
dialog.modal form { padding: 20px 22px; }
dialog.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal-field { display: block; margin: 16px 0 4px; font-size: 13px; color: #475569; }
.modal-field select, .modal-field input { display: block; width: 100%; margin-top: 5px; padding: 8px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions button.danger { margin: 0; }

/* Сворачиваемые действия-инструменты над списком */
.tools { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
details.tool { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
details.tool > summary { cursor: pointer; list-style: none; padding: 9px 16px; font-weight: 500;
    color: var(--soft); user-select: none; border-radius: var(--radius); }
details.tool > summary::-webkit-details-marker { display: none; }
details.tool > summary::before { content: "▸ "; color: var(--muted); }
details.tool[open] > summary::before { content: "▾ "; }
details.tool[open] { padding-bottom: 14px; box-shadow: var(--shadow-sm); }
details.tool[open] > summary { border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; margin-bottom: 12px; }
details.tool .user-new { border: none; box-shadow: none; padding: 0 16px; }
details.tool > form { padding: 0 16px; }

/* Компактный список пользователей */
.field-cap { font-size: 12px; color: var(--muted); }
.cities-sum { display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; vertical-align: bottom; }
.acts { white-space: nowrap; }
.acts .secondary.small-btn { margin-right: 6px; }
.acts form { display: inline; }

/* Широкая модалка редактирования */
dialog.modal.modal-wide { max-width: 680px; }
.modal-row { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.modal-row .modal-field.inline { margin: 6px 0; }
.modal-row .modal-field.inline select { width: auto; }
.modal-row .chk { font-size: 13px; color: var(--soft); display: flex; align-items: center; gap: 5px; }
.modal-cities { margin: 14px 0; }
.modal-cities .field-cap { display: block; margin-bottom: 6px; }
