/* TERRA CRM — стилі. Дві теми: світла і темна (data-theme на <html>). */
:root, [data-theme="light"] {
  --bg: #F6F6F4; --surface: #FFFFFF; --text: #131313; --muted: #5F6168; --line: #E4E4E0;
  --chip: #F0F0EC; --rail: #0A0A0A; --rail-active: #1E1F23; --rail-text: #A8AAB0;
  --gold: #C2A06A; --gold-text: #86692F; --sel: #F3EEE4;
  --debt-bg: #F9E5E1; --debt-fg: #9B2A1B; --warn-bg: #F7EFDC; --warn-fg: #6E5113; --ok-bg: #E5F0E8; --ok-fg: #2C6142;
  --mark: rgba(19,19,19,.16); --map-filter: grayscale(.85) contrast(1.05);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #111113; --surface: #1C1D21; --text: #F3F3F1; --muted: #A2A4AA; --line: #2B2C31;
  --chip: #26272C; --rail: #0A0A0A; --rail-active: #1E1F23; --rail-text: #A8AAB0;
  --gold: #C9A86E; --gold-text: #D8BD8A; --sel: #26231D;
  --debt-bg: #3A201C; --debt-fg: #F0A79B; --warn-bg: #3A3120; --warn-fg: #E6C987; --ok-bg: #1E3226; --ok-fg: #94CDA6;
  --mark: rgba(255,255,255,.14); --map-filter: grayscale(1) invert(.9) contrast(.9) brightness(.95);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, .num { font-family: Montserrat, Inter, sans-serif; }
.muted { color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* --- каркас --- */
.shell { display: flex; min-height: 100vh; }
.rail { width: 84px; flex: 0 0 84px; background: var(--rail); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 0; position: sticky; top: 0; height: 100vh; }
.rail img.logo { width: 64px; margin-bottom: 16px; }
.rail a, .rail button { width: 68px; padding: 10px 0; border: 0; border-radius: 12px; background: none; color: var(--rail-text); text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; position: relative; }
.rail a.on { background: var(--rail-active); color: var(--gold); font-weight: 600; }
.rail .badge { position: absolute; top: 4px; right: 10px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--gold); color: #131313; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.rail .spacer { flex: 1; }
.rail .me { width: 44px; height: 44px; border-radius: 50%; background: #2E2F35; color: #fff; font-weight: 600; display: flex; align-items: center; justify-content: center; }
main.page { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 24px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.search { margin-left: auto; height: 40px; width: 300px; max-width: 100%; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.btn { height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.btn.gold { background: var(--gold); color: #131313; border-color: var(--gold); font-weight: 700; }
.btn.dark { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 700; }
.btn:disabled { opacity: .5; cursor: default; }
.chips { display: flex; gap: 8px; padding: 12px 24px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.chip { height: 32px; padding: 0 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tag.debt { background: var(--debt-bg); color: var(--debt-fg); }
.tag.warn { background: var(--warn-bg); color: var(--warn-fg); }
.tag.ok { background: var(--ok-bg); color: var(--ok-fg); }
.tag.none { color: var(--muted); }

/* --- список + карта --- */
.split { display: flex; flex: 1; min-height: 0; flex-wrap: wrap; }
.list { flex: 1 1 440px; min-width: 0; overflow-y: auto; max-height: calc(100vh - 130px); }
.row { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 24px; border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; background: none; text-align: left; }
.row.on { background: var(--sel); border-left-color: var(--gold); }
.row img, .row .noimg { width: 76px; height: 58px; object-fit: cover; border-radius: 8px; flex: 0 0 76px; background: var(--chip); }
.row .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .addr { font-weight: 700; }
.row .sub { color: var(--muted); font-size: 13px; }
.row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.row .price { font-family: Montserrat, sans-serif; font-weight: 700; font-size: 15px; white-space: nowrap; }
.mapbox { flex: 1 1 480px; min-width: 300px; padding: 16px; display: flex; flex-direction: column; gap: 12px; border-left: 1px solid var(--line); }
#map { height: 460px; border-radius: 14px; overflow: hidden; background: var(--surface); }
#map .leaflet-tile-pane { filter: var(--map-filter); }
.pin { padding: 4px 8px; border-radius: 10px 10px 10px 2px; background: #131313; color: #fff; font-weight: 700; font-size: 11px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.35); transform: translate(-50%, -100%); display: inline-block; }
.pin.on { background: var(--gold); color: #131313; font-size: 13px; }
.leaflet-div-icon.pinwrap { background: none; border: 0; }
.panel { background: var(--surface); border-radius: 14px; padding: 14px 16px; }
.panel h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--gold-text); }
.near { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px 16px; font-size: 13px; }
.near div { display: flex; justify-content: space-between; gap: 8px; }
.note { padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-fg); font-size: 13px; }

/* --- картка --- */
.card { max-width: 760px; width: 100%; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; position: relative; }
.card .back { align-self: flex-start; }
.card .price { font-family: Montserrat, sans-serif; font-weight: 800; font-size: 28px; letter-spacing: -.01em; }
.card .addr { font-weight: 700; font-size: 17px; }
.callrow { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.callrow .btn, .callrow a.btn { height: 50px; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: 16px; }
.gallery img { height: 300px; max-width: 92%; object-fit: cover; border-radius: 16px; scroll-snap-align: start; flex: 0 0 auto; background: var(--chip); }
.section { background: var(--surface); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.section h3 { margin: 0; font-size: 14px; font-family: Inter, sans-serif; font-weight: 700; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 4px 9px; border-radius: 8px; background: var(--chip); font-size: 12px; }
.results { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; }
.results button { height: 42px; border-radius: 10px; border: 0; background: var(--chip); font-size: 13px; }
.results button.ok { background: var(--ok-bg); color: var(--ok-fg); font-weight: 700; }
.desc { white-space: pre-line; color: var(--text); }
.watermark { position: fixed; inset: 0; pointer-events: none; z-index: 50; display: flex; flex-wrap: wrap; align-content: space-around; justify-content: space-around; overflow: hidden; }
.watermark span { transform: rotate(-20deg); color: var(--mark); font-weight: 700; font-size: 14px; letter-spacing: .06em; padding: 40px; user-select: none; }

/* --- продз --- */
.prodz { padding: 22px 28px; display: flex; flex-direction: column; gap: 16px; max-width: 1180px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.stat { background: var(--surface); border-radius: 12px; padding: 10px 16px; min-width: 96px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat .v { font-family: Montserrat, sans-serif; font-weight: 800; font-size: 22px; }
.stat.debt { background: var(--debt-bg); } .stat.debt .k, .stat.debt .v { color: var(--debt-fg); }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress div { height: 100%; background: var(--gold); }
.group { background: var(--surface); border-radius: 16px; overflow: hidden; }
.group.debt { border: 1px solid var(--debt-bg); }
.group .head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.item { display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.item:last-child { border-bottom: 0; }
.item img { width: 56px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--chip); }
.item .t { flex: 1; min-width: 220px; text-decoration: none; }
.item .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.item .acts button { height: 36px; padding: 0 12px; border-radius: 9px; border: 0; background: var(--chip); }
.item .acts button.ok { background: var(--ok-bg); color: var(--ok-fg); font-weight: 700; }
h2.sec { margin: 4px 0 0; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
h2.sec.debt { color: var(--debt-fg); }

/* --- вхід --- */
.login { min-height: 100vh; display: grid; place-items: center; background: #0A0A0A; padding: 16px; }
.login form { width: 100%; max-width: 380px; background: #1C1D21; color: #F3F3F1; border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login img { width: 200px; margin: 0 auto 10px; }
.login input { height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid #2B2C31; background: #111113; color: #F3F3F1; }
.login .muted { color: #A2A4AA; font-size: 13px; }
.login .linkbtn { background: none; border: 0; color: #C9A86E; text-decoration: underline; padding: 0; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #131313; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; }

/* --- телефон --- */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .rail { width: 100%; height: 64px; flex: 0 0 64px; flex-direction: row; justify-content: space-around; padding: 0 8px; position: fixed; top: auto; bottom: 0; z-index: 60; }
  .rail img.logo, .rail .spacer { display: none; }
  .rail .me { width: 36px; height: 36px; }
  main.page { padding-bottom: 72px; }
  .topbar { padding: 12px 16px; }
  .search { width: 100%; margin-left: 0; }
  .chips { padding: 10px 16px; overflow-x: auto; flex-wrap: nowrap; }
  .chip { flex: 0 0 auto; }
  .row { padding: 10px 16px; }
  .list { max-height: none; }
  .mapbox { border-left: 0; padding: 12px 16px; }
  #map { height: 320px; }
  .gallery img { height: 240px; }
  .results { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .prodz { padding: 16px; }
}
