:root {
  color-scheme: light;
  --ink: #172321;
  --muted: #66736f;
  --line: #dfe6e2;
  --line-strong: #c7d2ce;
  --paper: #fffefa;
  --canvas: #f3f5f1;
  --forest: #173f3a;
  --forest-hover: #0f332f;
  --mint: #e7f2ee;
  --gold: #d5a657;
  --gold-soft: #f7edda;
  --danger: #9e3f3f;
  --danger-soft: #f8e8e5;
  --white: #fff;
  --shadow-sm: 0 2px 8px rgba(19, 48, 44, 0.06);
  --shadow-lg: 0 24px 70px rgba(16, 39, 36, 0.2);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 26px;
  --max-width: 1160px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 4%, rgba(213, 166, 87, 0.10), transparent 25rem),
    var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid rgba(213, 166, 87, 0.65);
  outline-offset: 2px;
}

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(150deg, rgba(23, 63, 58, 0.96), rgba(11, 38, 35, 0.98)),
    var(--forest);
}

.login-card {
  width: min(100%, 430px);
  padding: clamp(28px, 7vw, 46px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow-lg);
}

.brand-mark {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 34px;
  color: var(--forest);
}

.brand-mark span { font-size: 17px; font-weight: 850; letter-spacing: 0.16em; }
.brand-mark strong { font-family: Georgia, serif; font-size: 43px; font-weight: 500; line-height: 1; color: var(--gold); }

.eyebrow {
  margin: 0 0 8px;
  color: var(--forest);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(30px, 8vw, 44px); line-height: 1.05; letter-spacing: -0.035em; }
h2 { margin-bottom: 0; font-size: 22px; letter-spacing: -0.02em; }
h3 { margin-bottom: 0; font-size: 17px; }

.login-copy { margin-bottom: 28px; color: var(--muted); line-height: 1.55; }
.stack-form { display: grid; gap: 10px; }
.stack-form label, .form-field label { font-size: 13px; font-weight: 750; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 52px; }
.password-wrap .icon-button { position: absolute; top: 50%; right: 7px; transform: translateY(-50%); }

input, select, textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select { appearance: none; padding-right: 42px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-size: 5px 5px; background-repeat: no-repeat; }
textarea { min-height: 92px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--forest); outline: 0; box-shadow: 0 0 0 3px rgba(23, 63, 58, 0.1); }

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 10px 17px;
  font-size: 14px;
  font-weight: 780;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, color 0.15s, border-color 0.15s;
}

.button:active { transform: translateY(1px); }
.button svg, .icon-button svg { width: 19px; height: 19px; }
.button-primary { background: var(--forest); color: var(--white); }
.button-primary:hover { background: var(--forest-hover); }
.button-secondary { border: 1px solid var(--line-strong); background: var(--white); color: var(--forest); }
.button-secondary:hover { border-color: var(--forest); background: var(--mint); }
.button-quiet { background: transparent; color: var(--muted); }
.button-quiet:hover { background: rgba(255, 255, 255, 0.1); color: var(--white); }
.button-danger { border: 1px solid #e5c2be; background: var(--danger-soft); color: var(--danger); }
.button-small { min-height: 38px; padding: 8px 13px; font-size: 13px; }
.button-wide { width: 100%; margin-top: 8px; }

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover { background: var(--mint); color: var(--forest); }
.form-error { margin: 3px 0 0; color: var(--danger); font-size: 13px; font-weight: 650; }

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.privacy-note svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 1px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: rgba(23, 63, 58, 0.97);
  color: var(--white);
  box-shadow: 0 4px 18px rgba(9, 42, 37, 0.15);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  width: min(100% - 28px, var(--max-width));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 13px;
}

.compact-brand { display: flex; align-items: baseline; gap: 3px; white-space: nowrap; }
.compact-brand span { font-size: 11px; font-weight: 850; letter-spacing: .1em; }
.compact-brand strong { color: var(--gold); font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.topbar-title { display: grid; min-width: 0; line-height: 1.25; }
.topbar-title strong { font-size: 15px; }
.topbar-title span { overflow: hidden; color: rgba(255,255,255,.68); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-action { margin-left: auto; color: rgba(255,255,255,.78); }

.content { width: min(100% - 28px, var(--max-width)); margin: 0 auto; padding: 34px 0 calc(72px + env(safe-area-inset-bottom)); }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.hero h1 { margin-bottom: 8px; }
.hero p:last-child { margin-bottom: 0; color: var(--muted); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 26px; }
.stat-card { min-height: 105px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: rgba(255, 254, 250, 0.9); box-shadow: var(--shadow-sm); }
.stat-value { display: block; margin-bottom: 6px; color: var(--forest); font-family: Georgia, serif; font-size: 32px; line-height: 1; }
.stat-label { color: var(--muted); font-size: 13px; line-height: 1.25; }
.stat-card.is-attention .stat-value { color: var(--danger); }

.registry-tools { position: sticky; top: calc(68px + env(safe-area-inset-top)); z-index: 15; margin: 0 -7px 23px; padding: 10px 7px 12px; background: linear-gradient(var(--canvas) 78%, rgba(243,245,241,0)); }
.search-box { position: relative; display: block; }
.search-box > svg { position: absolute; left: 16px; top: 50%; width: 20px; height: 20px; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
.search-box input { min-height: 54px; padding-left: 48px; padding-right: 46px; border-color: var(--line); box-shadow: var(--shadow-sm); }
.clear-search { position: absolute; right: 8px; top: 50%; width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 25px; line-height: 1; transform: translateY(-50%); cursor: pointer; }

.filter-row { display: flex; gap: 8px; margin-top: 10px; padding-bottom: 2px; overflow-x: auto; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip { min-height: 38px; flex: 0 0 auto; border: 1px solid var(--line-strong); border-radius: 999px; padding: 7px 13px; background: rgba(255,255,255,.82); color: var(--muted); font-size: 13px; font-weight: 730; cursor: pointer; }
.filter-chip.is-active { border-color: var(--forest); background: var(--forest); color: var(--white); }

.list-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 13px; }
.list-heading span { color: var(--muted); font-size: 13px; }
.registry-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }

.unit-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 255px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.unit-card:hover { border-color: var(--line-strong); box-shadow: 0 10px 28px rgba(17, 52, 47, 0.09); transform: translateY(-1px); }
.unit-card.is-attention { border-color: #e9c5bf; }
.unit-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.unit-card h3 { margin-bottom: 4px; color: var(--forest); font-size: 20px; }
.cadastral { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.area-badge { flex: 0 0 auto; border-radius: 999px; padding: 6px 9px; background: var(--mint); color: var(--forest); font-size: 12px; font-weight: 760; }

.owner-preview { margin: 18px 0; }
.owner-preview-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
.owner-name { display: flex; align-items: flex-start; gap: 8px; margin-top: 6px; font-size: 14px; line-height: 1.35; }
.owner-name svg { width: 17px; height: 17px; flex: 0 0 auto; margin-top: 1px; color: var(--forest); }
.owner-name.is-missing { color: var(--danger); font-weight: 720; }
.more-owners { margin: 7px 0 0 25px; color: var(--muted); font-size: 12px; }

.unit-card-footer { display: flex; align-items: center; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.mini-fact { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.mini-fact svg { width: 16px; height: 16px; }
.open-card { margin-left: auto; min-height: 38px; gap: 4px; padding-right: 8px; color: var(--forest); }
.open-card svg { width: 17px; height: 17px; }

.empty-state { padding: 65px 20px; text-align: center; color: var(--muted); }
.empty-state > svg { width: 42px; height: 42px; margin-bottom: 16px; color: var(--line-strong); }
.empty-state h2 { margin-bottom: 7px; color: var(--ink); }

dialog { padding: 0; border: 0; background: transparent; color: var(--ink); }
dialog::backdrop { background: rgba(5, 21, 19, 0.58); backdrop-filter: blur(3px); }
.sheet-dialog { width: min(720px, calc(100% - 28px)); max-height: calc(100vh - 40px); border-radius: var(--radius-lg); }
.sheet-frame, .form-frame { max-height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; border-radius: var(--radius-lg); background: var(--paper); box-shadow: var(--shadow-lg); }
.sheet-header { flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 22px 22px 18px; border-bottom: 1px solid var(--line); }
.sheet-header .eyebrow { margin-bottom: 5px; }
.sheet-header .icon-button { flex: 0 0 auto; margin: -7px -7px 0 0; }
.sheet-content { padding: 20px 22px 28px; overflow-y: auto; overscroll-behavior: contain; }

.unit-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 24px; }
.meta-box { padding: 13px; border-radius: var(--radius-sm); background: var(--canvas); }
.meta-box span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.meta-box strong { display: block; color: var(--forest); font-size: 14px; overflow-wrap: anywhere; }
.full-address { margin: -12px 0 24px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 24px 0 11px; }
.section-head:first-of-type { margin-top: 0; }
.section-head h3 { font-size: 16px; }
.people-list { display: grid; gap: 11px; }
.person-card { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--white); }
.person-card.is-missing { border-color: #e9c5bf; background: #fffafa; }
.person-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.person-name { margin-bottom: 4px; font-size: 15px; font-weight: 790; line-height: 1.3; }
.person-name.is-missing { color: var(--danger); }
.role-badge { display: inline-flex; border-radius: 999px; padding: 4px 8px; background: var(--mint); color: var(--forest); font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.role-badge.user { background: var(--gold-soft); color: #805c20; }
.person-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.detail-list { display: grid; gap: 7px; margin: 13px 0 0; }
.detail-row { display: grid; grid-template-columns: minmax(110px, .65fr) 1.35fr; gap: 10px; font-size: 12px; line-height: 1.4; }
.detail-row dt { color: var(--muted); }
.detail-row dd { margin: 0; overflow-wrap: anywhere; }

.contacts, .vehicles { display: grid; gap: 7px; margin-top: 14px; }
.contact-row, .vehicle-row { display: flex; align-items: center; gap: 10px; padding: 10px 11px; border-radius: 11px; background: var(--canvas); }
.contact-row > svg, .vehicle-row > svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--forest); }
.contact-main, .vehicle-main { min-width: 0; flex: 1; display: grid; line-height: 1.25; }
.contact-main a, .vehicle-main strong { color: var(--ink); font-size: 13px; font-weight: 750; overflow-wrap: anywhere; }
.contact-main a { text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.contact-main span, .vehicle-main span { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.contact-actions, .vehicle-actions { display: flex; }
.contact-actions .icon-button, .vehicle-actions .icon-button { width: 34px; height: 34px; }
.contact-actions svg, .vehicle-actions svg { width: 16px; height: 16px; }

.form-dialog { width: min(540px, calc(100% - 28px)); max-height: calc(100vh - 40px); border-radius: var(--radius-lg); }
.form-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding: 20px 22px 8px; overflow-y: auto; }
.form-field { display: grid; align-content: start; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.checkbox-field { grid-column: 1 / -1; display: flex; align-items: flex-start; gap: 10px; padding: 12px; border-radius: var(--radius-sm); background: var(--canvas); font-size: 13px; line-height: 1.4; cursor: pointer; }
.checkbox-field input { width: 18px; min-height: 18px; flex: 0 0 auto; margin: 1px 0 0; }
.form-dialog .form-error { padding: 0 22px; }
.form-actions { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 9px; padding: 17px 22px calc(17px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }

.toast { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 100; max-width: min(390px, calc(100% - 36px)); padding: 13px 17px; border-radius: var(--radius-sm); background: var(--ink); color: var(--white); box-shadow: var(--shadow-lg); font-size: 13px; line-height: 1.4; }
.toast.is-error { background: var(--danger); }

.skeleton { min-height: 255px; border: 1px solid var(--line); border-radius: var(--radius-md); background: linear-gradient(100deg, #eef1ed 25%, #fafbf8 40%, #eef1ed 55%); background-size: 220% 100%; animation: shimmer 1.25s infinite; }
@keyframes shimmer { to { background-position-x: -220%; } }

@media (max-width: 760px) {
  .content { width: min(100% - 22px, var(--max-width)); padding-top: 25px; }
  .topbar-inner { width: calc(100% - 22px); }
  .topbar-title span { display: none; }
  .topbar-action span { display: none; }
  .topbar-action { width: 42px; padding: 0; }
  .hero { align-items: flex-start; }
  .hero .button { min-width: 44px; width: 44px; padding: 0; overflow: hidden; font-size: 0; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card { min-height: 92px; padding: 15px; }
  .stat-value { font-size: 28px; }
  .registry-grid { grid-template-columns: 1fr; }
  .registry-tools { margin-left: -4px; margin-right: -4px; padding-left: 4px; padding-right: 4px; }
  .unit-card { min-height: 235px; }
  .unit-meta { grid-template-columns: 1fr 1fr; }
  .unit-meta .meta-box:last-child { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .login-shell { place-items: stretch; padding: 0; background: var(--paper); }
  .login-card { width: 100%; min-height: 100vh; padding: calc(52px + env(safe-area-inset-top)) 24px calc(28px + env(safe-area-inset-bottom)); border: 0; border-radius: 0; box-shadow: none; }
  .brand-mark { margin-bottom: 62px; }
  .hero { gap: 10px; }
  .hero h1 { font-size: 31px; }
  .hero p:last-child { font-size: 13px; line-height: 1.45; }
  .sheet-dialog, .form-dialog { width: 100%; max-width: none; max-height: calc(100vh - 22px); margin: auto 0 0; border-radius: 24px 24px 0 0; }
  .sheet-frame, .form-frame { max-height: calc(100vh - 22px); border-radius: 24px 24px 0 0; }
  .sheet-header { padding: 19px 17px 15px; }
  .sheet-content { padding: 17px 17px calc(24px + env(safe-area-inset-bottom)); }
  .form-fields { grid-template-columns: 1fr; padding: 17px 17px 8px; }
  .form-field.full, .checkbox-field { grid-column: 1; }
  .form-dialog .form-error { padding: 0 17px; }
  .form-actions { padding-left: 17px; padding-right: 17px; }
  .form-actions .button { flex: 1; }
  .detail-row { grid-template-columns: 100px 1fr; }
  .person-actions .button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
