:root {
  --bg:        #f4f5f4;
  --panel:     #ffffff;
  --border:    #e2e5e2;
  --text:      #2b2f2c;
  --muted:     #6c736e;
  --accent:    #2f8f5b;   /* приглушённый зелёный Freedom */
  --accent-dk: #266f48;

  /* статусы — приглушённые */
  --s-none:    #9aa0a6;
  --s-progress:#d2a23f;
  --s-done:    #4a9c6d;
  --s-problem: #c46a6a;
  --s-na:      #c4c9c5;

  --shadow: 0 2px 10px rgba(0,0,0,.08);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); align-self: center;
}
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; }
.brand .subtitle { color: var(--muted); font-size: 12px; }

.summary { display: flex; gap: 16px; margin-left: auto; }
.summary .stat { text-align: center; line-height: 1.1; }
.summary .stat b { font-size: 17px; display: block; }
.summary .stat span { font-size: 11px; color: var(--muted); }
.summary .stat.warn b { color: var(--s-problem); }

/* ---------- Layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.map { flex: 1; min-width: 0; }
.sidebar {
  width: 380px; background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border); }
.sidebar-head input { flex: 1; }
input, select, textarea {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Table ---------- */
.table-wrap { overflow-y: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; background: #fafbfa;
  text-align: left; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap;
}
thead th:hover { color: var(--text); }
thead th.sorted-asc::after { content: " ▲"; font-size: 9px; }
thead th.sorted-desc::after { content: " ▼"; font-size: 9px; }
tbody tr { cursor: pointer; border-bottom: 1px solid #f0f2f0; }
tbody tr:hover { background: #f6f8f6; }
tbody td { padding: 8px 10px; vertical-align: middle; }
.st-badge { font-size: 16px; }

.bar { height: 6px; background: #eceeec; border-radius: 4px; overflow: hidden; min-width: 54px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.pct-cell { display: flex; align-items: center; gap: 6px; }
.pct-cell small { color: var(--muted); width: 30px; text-align: right; }

/* ---------- Buttons ---------- */
.btn {
  padding: 7px 13px; border: 1px solid var(--border); border-radius: 7px;
  background: #fff; cursor: pointer; font: inherit; color: var(--text);
}
.btn:hover { background: #f3f5f3; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dk); }
.btn-danger { color: var(--s-problem); border-color: #e6cccc; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,25,22,.4); }
.modal-panel {
  position: relative; background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); width: 460px; max-width: 94vw;
  max-height: 90vh; overflow-y: auto; padding: 20px;
}
.modal-wide { width: 620px; }

/* ---------- Карточка опоры: боковая панель (drawer) ---------- */
#cardModal { align-items: stretch; justify-content: flex-end; }
#cardModal .modal-backdrop { background: rgba(20,25,22,.28); }
#cardModal .modal-panel {
  width: min(1320px, 97vw); max-width: none;
  height: 100vh; max-height: 100vh; border-radius: 0;
  padding: 0; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: -6px 0 24px rgba(0,0,0,.16);
  animation: drawer-in .22s ease;
}
@keyframes drawer-in { from { transform: translateX(48px); opacity: .4; } to { transform: none; opacity: 1; } }

#cardModal .card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 22px; border-bottom: 1px solid var(--border); margin: 0; flex: none;
}
#cardModal .card-head h2 { margin: 0 0 3px; font-size: 19px; }
#cardModal .card-meta { margin: 0; }
.card-col-stages { overflow-x: auto; }

#cardModal .card-body {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
}
.card-col { overflow-y: auto; padding: 18px 22px; }
.card-col-info { border-right: 1px solid var(--border); background: #fcfdfc; }
.card-col-info .passport { grid-template-columns: 1fr; }
#cardModal .card-footer {
  flex: none; display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 22px; border-top: 1px solid var(--border); background: var(--panel);
}

@media (max-width: 880px) {
  #cardModal .modal-panel { width: 100vw; }
  #cardModal .card-body { display: block; overflow-y: auto; }
  .card-col { overflow: visible; }
  .card-col-info { border-right: none; border-bottom: 1px solid var(--border); }
}

.card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.card-head h2 { margin: 0; font-size: 18px; flex: 1; }
.card-meta { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.card-meta b { color: var(--text); font-weight: 600; }

.passport { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-bottom: 16px;
  font-size: 13px; background: #fafbfa; padding: 12px; border-radius: 8px; }
.passport div span { color: var(--muted); }

/* ---------- Земля (ГЗУ/ЧЗУ) ---------- */
.land-block { background: #fafbfa; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px; }
.land-block h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); }
.land-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.land-row:last-child { margin-bottom: 0; }
.land-row.chzu { padding-top: 6px; border-top: 1px dashed var(--border); }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #ececec; color: var(--muted); }
.tag-ok { background: #e6f3ec; color: var(--accent-dk); }
.tag-bad { background: #f6e4e4; color: var(--s-problem); }
.tag-rent { background: #f3ecd9; color: #8a6d23; }
.land-docs { font-size: 12px; color: var(--muted); }
.form-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; margin-top: 2px; }
.alt-icon { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff;
  background: #d2a23f; color: #fff; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0,0,0,.35); }

/* ---------- Фото локации ---------- */
.photos-block { margin-bottom: 18px; }
.photos-head h3, .stages-block > h3 { font-size: 14px; margin: 0 0 8px; }
.photos-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-thumb { position: relative; width: 92px; height: 70px; border-radius: 7px;
  overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; display: block; }
.photo-del { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  border-radius: 50%; border: none; background: rgba(20,25,22,.6); color: #fff;
  font-size: 13px; line-height: 1; cursor: pointer; display: flex;
  align-items: center; justify-content: center; }
.photo-del:hover { background: var(--s-problem); }
.photo-add { width: 92px; height: 70px; border: 1px dashed var(--border); border-radius: 7px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--muted); font-size: 13px; background: #fafbfa; }
.photo-add:hover { border-color: var(--accent); color: var(--accent-dk); }

/* ---------- Этапы (таблица как в FWA-трекере) ---------- */
.stages-block { margin-bottom: 6px; }
.stages-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.exec-legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.exec-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.exec-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
/* Цвета исполнителей: ФТО — зелёный, GR — синий, Подрядчик — янтарный */
.exec-dot.exec-fto  { background: #5b9e77; }
.exec-dot.exec-gr   { background: #6b8fc4; }
.exec-dot.exec-podr { background: #c79a55; }
.stage-tr.exec-fto  .st-name,
.stage-tr.exec-gr   .st-name,
.stage-tr.exec-podr .st-name { padding-left: 11px; border-radius: 4px 0 0 4px; }
.stage-tr.exec-fto  .st-name { box-shadow: inset 3px 0 0 #5b9e77; background: #f2f8f4; }
.stage-tr.exec-gr   .st-name { box-shadow: inset 3px 0 0 #6b8fc4; background: #f2f5fa; }
.stage-tr.exec-podr .st-name { box-shadow: inset 3px 0 0 #c79a55; background: #faf6ee; }
.stages-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stages-table thead th { position: static; background: none; text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  padding: 4px 6px; border-bottom: 1px solid var(--border); cursor: default; }
.stages-table tbody td { padding: 5px 5px; border-bottom: 1px solid #f0f2f0; vertical-align: middle; }
.stages-table { table-layout: auto; }
.stage-tr .st-name { font-weight: 550; white-space: nowrap; padding-right: 12px; }
.st-base { color: var(--muted); font-size: 11px; white-space: nowrap; }
.stage-date { padding: 4px 5px; font-size: 12px; width: 116px; }
.stage-date.overdue { background: #fdf0f0; border-color: #e6cccc; }
.stage-date.late    { background: #fbf3e6; border-color: #e8d9bd; }
.st-delta { font-weight: 600; text-align: center; }
.st-delta.d-pos { color: var(--s-problem); }
.st-delta.d-neg { color: var(--s-done); }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 11px; white-space: nowrap; display: inline-block; }
.b-noplan  { background: #faf6dd; color: #8a7d23; }
.b-overdue { background: #f6e0e0; color: var(--s-problem); }
.b-late    { background: #fbe7d4; color: #a9701f; }
.b-ontime  { background: #e6f3ec; color: var(--accent-dk); }
.b-plan    { background: #ececec; color: var(--muted); }
.st-cmt { width: 44px; text-align: center; }
.cmt-toggle { position: relative; background: none; border: none; font-size: 15px;
  line-height: 1; cursor: pointer; padding: 4px 6px; opacity: .35; filter: grayscale(1);
  border-radius: 6px; }
.cmt-toggle:hover { opacity: .85; filter: none; background: #f0f2f0; }
.cmt-toggle.has { opacity: 1; filter: none; }
.cmt-count { position: absolute; top: -4px; right: -5px; min-width: 15px; height: 15px;
  padding: 0 3px; border-radius: 8px; background: var(--accent-dk); color: #fff;
  font-size: 9.5px; font-weight: 700; line-height: 15px; }
/* последний комментарий под названием этапа */
.st-name .st-title { font-weight: 550; }
.st-last-comment { font-weight: 400; font-size: 11.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px;
  margin-top: 1px; }
.st-last-comment::before { content: "💬 "; font-size: 10px; }
.stage-detail-row { display: flex; gap: 10px; padding: 4px 2px 8px; }
.stage-detail-row label { display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; color: var(--muted); }
.stage-detail-row label.grow { flex: 1; }
.stage-detail-row input { font-size: 12px; }
/* история комментариев этапа */
.cmt-add { display: flex; gap: 8px; padding: 2px 2px 8px; }
.cmt-add input { flex: 1; font-size: 12px; }
.cmt-send { font-size: 12px; padding: 5px 12px; white-space: nowrap; }
.cmt-history { padding: 0 2px 10px; max-height: 220px; overflow-y: auto; }
.cmt-item { padding: 6px 10px; margin-bottom: 6px; background: #f7f9f7;
  border-radius: 8px; border: 1px solid #eef1ee; }
.cmt-meta { display: flex; gap: 8px; align-items: baseline; font-size: 11px;
  color: var(--muted); margin-bottom: 2px; }
.cmt-meta b { color: var(--text); font-size: 11.5px; }
.cmt-text { font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
.cmt-empty { font-size: 12px; color: var(--muted); padding: 2px 2px 8px; }

/* ---------- Пользователи ---------- */
.users-list { margin: 6px 0 14px; }
.users-row { display: flex; align-items: center; gap: 12px; padding: 8px 4px;
  border-bottom: 1px solid #f0f2f0; }
.users-name { flex: 1; font-size: 14px; }
.users-admin-chk { display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.users-btn { font-size: 12px; padding: 4px 10px; }
.users-btn-danger { color: #b04a4a; border-color: #e0c5c5; }
.users-btn-danger:hover { background: #fdf0f0; }
.users-add { display: flex; align-items: center; gap: 10px; padding-top: 12px;
  border-top: 1px solid var(--border); }
.users-add input[type="text"], .users-add input[type="password"] {
  flex: 1; min-width: 0; font-size: 13px; }
.users-id { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.users-id .users-name { flex: none; }
.users-login { font-size: 11px; color: var(--muted); }

/* ---------- Журнал изменений ---------- */
.log-toolbar { display: flex; align-items: center; gap: 12px; margin: 6px 0 10px; }
.log-author { font-size: 13px; padding: 5px 8px; }
.log-total { font-size: 12px; color: var(--muted); }
.log-list { max-height: 62vh; overflow-y: auto; }
.log-item { padding: 7px 10px; border-bottom: 1px solid #f0f2f0; }
.log-meta { display: flex; gap: 10px; align-items: baseline; font-size: 11.5px;
  color: var(--muted); margin-bottom: 2px; }
.log-meta b { color: var(--text); font-size: 12px; }
.log-site { color: var(--accent-dk); cursor: pointer; text-decoration: underline;
  text-decoration-style: dotted; }
.log-site:hover { text-decoration-style: solid; }
.log-action { font-size: 12.5px; word-break: break-word; }
.log-pager { display: flex; align-items: center; gap: 12px; justify-content: center;
  padding-top: 10px; }

/* ---------- Form ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 12px; }

/* ---------- Map markers ---------- */
.marker-pin {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.marker-label { transform: rotate(45deg); color:#fff; font-size:10px; font-weight:700;
  display:flex; align-items:center; justify-content:center; height:100%; }
.search-zone-icon {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px dashed var(--accent); background: rgba(47,143,91,.12);
  color: var(--accent-dk); font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #2b2f2c; color: #fff; padding: 9px 16px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 3000; font-size: 13px;
}
.toast.hidden { display: none; }

h2 .close, .modal .close {
  background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1;
}

/* ---------- Топбар: пользователь ---------- */
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-name { color: var(--text); font-weight: 550; }
.logout { color: var(--muted); text-decoration: none; font-size: 12px; }
.logout:hover { color: var(--s-problem); text-decoration: underline; }

/* ---------- Подписи к фото ---------- */
.photo-figure { display: flex; flex-direction: column; gap: 4px; width: 92px; }
.photo-cap { width: 92px; font-size: 11px; padding: 3px 5px; }

/* ---------- Страница входа ---------- */
.login-body { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg); }
.login-card { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px;
  width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login-brand { display: flex; align-items: center; gap: 8px; }
.login-brand h1 { font-size: 19px; margin: 0; }
.login-brand .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.login-sub { color: var(--muted); font-size: 13px; margin: -6px 0 4px; }
.login-card label { display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted); }
.login-btn { margin-top: 6px; padding: 9px; }
.login-error { background: #f6e0e0; color: var(--s-problem); padding: 8px 10px;
  border-radius: 7px; font-size: 13px; }


/* ---------- Топбар: покрытие / внимание ---------- */
.cover-toggle { display: flex; align-items: center; gap: 5px; font-size: 13px;
  color: var(--muted); cursor: pointer; white-space: nowrap; }
.cover-toggle input { accent-color: var(--accent); }
.attn-count { display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--s-progress); color: #fff; font-size: 11px; font-weight: 700; }
.attn-count.has-overdue { background: var(--s-problem); }
.attn-count.hidden { display: none; }

/* ---------- Панель «Внимание» ---------- */
#panelContent .card-head { display: flex; justify-content: space-between;
  align-items: flex-start; margin-bottom: 14px; }
#panelContent .card-head h2 { margin: 0; font-size: 19px; }
.attn-section { margin-bottom: 16px; }
.attn-section h3 { font-size: 13px; margin: 0 0 8px; color: var(--text); }
.attn-empty { color: var(--muted); font-size: 13px; padding: 2px 0 6px; }
.attn-item { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 6px; cursor: pointer; }
.attn-item:hover { background: #f6f8f6; border-color: var(--accent); }
.attn-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.attn-main b { font-size: 13px; }
.attn-stage { font-size: 12px; color: var(--muted); }
.attn-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; white-space: nowrap; }
.attn-date { font-size: 11px; color: var(--muted); }
.attn-allgood { background: #e6f3ec; color: var(--accent-dk); padding: 12px;
  border-radius: 8px; font-size: 14px; text-align: center; }

/* ---------- Дашборд ---------- */
.dash-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 8px; }
.dash-stat { background: #fafbfa; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; text-align: center; }
.dash-stat b { font-size: 24px; display: block; line-height: 1.1; }
.dash-stat span { font-size: 11px; color: var(--muted); }
.dash-stat.s-none b { color: var(--s-none); }
.dash-stat.s-prog b { color: var(--s-progress); }
.dash-stat.s-done b { color: var(--s-done); }
.dash-stat.s-bad  b { color: var(--s-problem); }
.dash-h { font-size: 13px; margin: 18px 0 8px; color: var(--text); }
.dash-empty { color: var(--muted); font-size: 13px; }
.dash-bar-multi { display: flex; height: 30px; border-radius: 7px; overflow: hidden; gap: 2px; }
.seg { display: flex; align-items: center; justify-content: center; color: #fff;
  font-size: 12px; font-weight: 600; min-width: 24px; }
.seg-ok { background: var(--s-done); }
.seg-late { background: var(--s-progress); }
.seg-bad { background: var(--s-problem); }
.dash-land { display: flex; flex-wrap: wrap; gap: 8px; }
.dash-land .tag { font-size: 12px; padding: 4px 10px; }
.dash-funnel { display: flex; flex-direction: column; gap: 4px; }
.funnel-row { display: grid; grid-template-columns: 210px 1fr 46px; align-items: center; gap: 10px; }
.funnel-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.funnel-bar { height: 14px; background: #eceeec; border-radius: 4px; overflow: hidden; }
.funnel-bar > i { display: block; height: 100%; background: var(--accent); }
.funnel-num { font-size: 12px; color: var(--muted); text-align: right; }
