/* ========================================================================
   ФРИДОМ 360 · Управление недвижимостью — единый стиль (v2)
   ======================================================================== */

:root {
  --bg:          #f4f6fb;
  --bg-panel:   #ffffff;
  --border:     #e4e7ef;
  --text:       #1a2236;
  --text-muted: #6b7280;
  --text-soft:  #8b93a7;
  --primary:    #2563eb;
  --primary-h:  #1d4ed8;
  --danger:     #dc2626;
  --warning:    #f59e0b;
  --success:    #16a34a;
  --sidebar:    #1a2236;
  --sidebar-hover: #243050;
  --radius:     10px;
  --radius-sm:   6px;
  --shadow-sm: 0 1px 2px rgba(20,27,45,.04);
  --shadow:    0 2px 8px rgba(20,27,45,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
/* Плавный scroll к якорю + отступ чтобы topbar не закрывал заголовок
   секции при переходе на «/objects/X/#channels» и т.п. */
html { scroll-behavior: smooth; }
:target, details.card[id]:target, .card[id]:target {
  scroll-margin-top: 70px;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Ссылки-кнопки не подчёркиваются на hover. Цвет текста задаётся
   модификатором (.btn-primary/.btn-secondary/...). Используем `:where()`,
   чтобы специфичность этого правила была 0 и не перекрыла модификатор. */
:where(a.btn, a.btn:hover, a.btn:visited) { text-decoration: none; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #cbd5e1;
  padding: 1.2rem 0;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0 1.2rem 1rem;
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: .2px;
  border-bottom: 1px solid #2b355a;
  margin-bottom: 1rem;
}
.sidebar-brand small {
  display: block;
  font-weight: 400;
  font-size: .75rem;
  color: #8591b3;
  margin-top: .15rem;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 .6rem; }
.sidebar-section {
  color: #6e7a9e;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 1rem .6rem .4rem;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .75rem;
  color: #c7d1e8;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  transition: background .15s ease;
}
.sidebar nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--primary);
  color: #fff;
}
.sidebar nav a .icon {
  font-size: 1rem;
  width: 18px;
  display: inline-block;
  text-align: center;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
}
.topbar h1 {
  font-size: 1rem;
  font-weight: 600;
}
.topbar .spacer { flex: 1; }
.topbar .user-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--text-muted);
  font-size: .85rem;
}
.topbar .user-chip strong { color: var(--text); font-weight: 600; }

.main { display: flex; flex-direction: column; min-width: 0; }
.content {
  padding: 1.5rem;
  max-width: 1280px;
  width: 100%;
}

/* ---------- Cards ---------- */

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}

.card h2, .card h3 {
  font-weight: 600;
  color: var(--text);
  margin-bottom: .6rem;
}
.card h2 { font-size: 1.15rem; }
.card h3 { font-size: 1rem; }

.card + .card { margin-top: 1.25rem; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}
.card-header h2, .card-header h3 { margin-bottom: 0; }
.card-header .actions { display: flex; gap: .5rem; }

/* ── Аккордеон (на основе <details>) ──────────────────────────────
   Используется для крупных табличных блоков на карточках объектов.
   Сохраняет внешний вид .card, но контент сворачивается.
   ----------------------------------------------------------------- */
details.card { padding: 0; }                /* отступы переносим внутрь */
details.card > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.4rem;
  cursor: pointer;
  list-style: none;                         /* убираем стандартный треугольник */
  user-select: none;
  border-radius: var(--radius);
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before {
  content: '▸';
  display: inline-block;
  font-size: .85rem;
  color: var(--muted, #6b7280);
  transition: transform .15s ease;
  margin-right: .25rem;
  flex-shrink: 0;
}
details[open].card > summary::before { transform: rotate(90deg); }
details.card > summary:hover { background: var(--bg-hover, #f6f8fb); }
details.card > summary h2,
details.card > summary h3 { margin: 0; flex: 1; }
details.card > summary .summary-meta {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--muted, #6b7280);
  font-weight: 400;
}
details.card > .accordion-body {
  padding: 0 1.4rem 1.25rem 1.4rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
details.card > .accordion-body > .accordion-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-bottom: .75rem;
}
details.card > .accordion-body > .accordion-actions:empty { display: none; }

/* Компактная колонка действий в табличных журналах (собственники, обременения,
   ЛС, поставщики). Все кнопки — одного размера и шрифта; выстроены в столбик. */
/* Кнопки-действий в строках таблиц: горизонтально, без растяжения,
   с переносом на узких экранах. */
.row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}
.row-actions .row-actions__btn {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
  text-align: center;
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
}
.row-actions .row-actions__btn--danger {
  color: var(--color-error, #DD1717);
  border-color: var(--color-error-bg, #F4D8D8);
  background: #fff;
}
.row-actions .row-actions__btn--danger:hover {
  background: var(--color-error-bg, #F4D8D8);
  border-color: var(--color-error, #DD1717);
}

/* Унификация шрифта в журналах под одну плотность: контент ячейки чуть
   мельче, чтобы длинные документы и реквизиты помещались, а заголовки
   таблицы оставались стандартными. */
.owners-table tbody td,
.encumbrances-table tbody td {
  font-size: .82em;
  line-height: 1.4;
  vertical-align: top;
}
.owners-table code,
.encumbrances-table code {
  font-size: .95em;          /* code не выглядел крупнее обычного текста */
  word-break: break-all;     /* длинный кадастровый/рег. номер не вылезает */
}

/* Grid cards (dashboard) */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow-sm);
  display: block;
  transition: box-shadow .15s ease, transform .05s ease;
  color: inherit;
}
.stat-card:hover { box-shadow: var(--shadow); text-decoration: none; }
.stat-card .icon { font-size: 1.6rem; margin-bottom: .6rem; }
.stat-card .label { font-size: .85rem; color: var(--text-muted); }
.stat-card strong { display: block; font-size: 1.02rem; font-weight: 600; color: var(--text); }

/* ---------- Tables ---------- */

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: .7rem .95rem;
  text-align: left;
  vertical-align: middle;
  font-size: .9rem;
}
.table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: #f9fafe; }
.table a:not(.btn) { color: var(--primary); font-weight: 500; }
/* Внутри таблицы `.table a` побеждал по специфичности над `.btn-primary`/`.btn-danger`
   (цвет текста становился синим на синем). Исключаем .btn, чтобы кнопки-ссылки
   («Заменить», «Править» и т.п.) рендерились как настоящие кнопки. */
.table a.btn-primary, .table a.btn-danger { color: #fff; }
.table a.btn-secondary { color: var(--text); }

.table-empty { padding: 2rem; text-align: center; color: var(--text-muted); font-size: .9rem; }

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem 1.4rem;
}
label { display: block; font-size: .8rem; color: var(--text-muted); margin-bottom: .3rem; font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="tel"], input[type="search"], select, textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { min-height: 90px; resize: vertical; }

.form-actions {
  display: flex;
  gap: .5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: .88rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f5f7fb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.2;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-gray   { background: #f1f2f7; color: #525a72; }
.badge-orange { background: #fef3c7; color: #92400e; }
.badge-red    { background: #fee2e2; color: #991b1b; }
/* Bootstrap-style алиасы — используются во всех KYC-шаблонах для
   единообразного «светофора»: ✓ чисто = зелёный, ⚠ = жёлтый,
   ⛔ = красный, неизвестно = серый, info = синий. */
.badge-success   { background: #d1fae5; color: #065f46; font-weight: 600; }
.badge-danger    { background: #fee2e2; color: #991b1b; font-weight: 600; }
.badge-warning   { background: #fef3c7; color: #92400e; font-weight: 600; }
.badge-info      { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f1f2f7; color: #525a72; }

/* Универсальный «дисэйбл-стиль» для записей, помеченных на удаление.
   Применяется к строкам таблиц справочников (.row-deleted), карточкам
   (.card-deleted) и плашке-предупреждению на детальной (.deleted-banner).
   Цель — сразу визуально отделить «помечена на удаление» от «живой». */
.row-deleted,
.row-deleted a,
.row-deleted .badge {
  color: #6b7280 !important;
  opacity: .65;
}
.row-deleted td { background: #f9fafb !important; }
.row-deleted .badge { background: #f1f2f7 !important; color: #6b7280 !important; }
.row-deleted a { text-decoration: line-through; }

.deleted-banner {
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #92400e;
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  font-size: .92rem;
}
.deleted-banner strong { color: #78350f; }

/* ---------- Messages ---------- */

.messages { list-style: none; margin-bottom: 1rem; }
.messages li {
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: .5rem;
  font-size: .9rem;
  border: 1px solid transparent;
}
.messages li.success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.messages li.error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.messages li.warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.messages li.info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ---------- Utilities ---------- */

.muted { color: var(--text-muted); }
.small { font-size: .82rem; }
.row { display: flex; gap: 1rem; align-items: center; }
.space-between { justify-content: space-between; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.mb-0 { margin-bottom: 0 !important; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

/* ---------- Login screen ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a2236 0%, #2b3968 100%);
  padding: 2rem;
}
.login-card {
  background: #fff;
  width: 100%;
  max-width: 400px;
  border-radius: 14px;
  padding: 2.2rem 2rem;
  box-shadow: 0 15px 40px rgba(10,15,30,.25);
}
.login-card .brand {
  text-align: center;
  font-size: 1rem;
  color: var(--text-muted);
  letter-spacing: .2px;
  margin-bottom: .2rem;
}
.login-card h1 {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.4rem;
  color: var(--text);
}
.login-card .dev-link {
  display: block;
  text-align: center;
  margin-top: 1rem;
  font-size: .78rem;
  color: var(--text-soft);
}

/* ---------- Requisites validation ---------- */
.rq-feedback { margin-top: .3rem; font-size: .82rem; line-height: 1.3; }
.rq-ok-box  { color: #065f46; }
.rq-err-box { color: #991b1b; }
input.rq-ok  { border-color: #86efac; }
input.rq-err { border-color: #fca5a5; background: #fff5f5; }

/* ---------- Duplicate warning ---------- */
.dup-warn { margin-top: .35rem; }
.dup-warn .dup-box {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: .45rem .7rem;
  border-radius: 6px;
  font-size: .82rem;
  line-height: 1.4;
}
.dup-warn a { color: #92400e; text-decoration: underline; font-weight: 600; }

/* ---------- Progress bar (NPD limit etc.) ---------- */

.progress {
  height: 8px;
  background: #eef2f7;
  border-radius: 99px;
  overflow: hidden;
  margin-top: .35rem;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--success);
  transition: width .25s ease;
}
.progress.warn > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }

/* ---------- Accordion / details ---------- */
details.section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin-bottom: 1rem;
}
details.section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .95rem;
  list-style: none;
  color: var(--text);
}
details.section[open] summary { margin-bottom: .75rem; }

/* ---------- Numeric readings ---------- */
.mono-num {
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-variant-numeric: tabular-nums;
  font-size: .97rem;
  letter-spacing: .01em;
  color: var(--text);
}
