:root {
  --bg: #f6f2ea; --card: #fffdf9; --ink: #1f2a2e; --muted: #6b7378; --teal: #24505c; --teal-ink: #fff;
  --oak: #c08a4a; --line: #e4ddd0; --floor: #ebe6dc; --yard: #dfe8d6; --soft: #f1ece2;
  --ok: #2f7d4f; --warn: #b7791f; --bad: #b3412f; --shadow: 0 6px 24px rgba(31, 42, 46, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14191b; --card: #1c2326; --ink: #ece7de; --muted: #9aa3a7; --teal: #5fa3b3; --teal-ink: #0d1416;
    --oak: #d6a266; --line: #2c3539; --floor: #232b2e; --yard: #1f2b22; --soft: #232b2e;
    --ok: #5fbf85; --warn: #e0a94a; --bad: #e07a66; --shadow: 0 6px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14191b; --card: #1c2326; --ink: #ece7de; --muted: #9aa3a7; --teal: #5fa3b3; --teal-ink: #0d1416;
  --oak: #d6a266; --line: #2c3539; --floor: #232b2e; --yard: #1f2b22; --soft: #232b2e;
  --ok: #5fbf85; --warn: #e0a94a; --bad: #e07a66; --shadow: 0 6px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 Manrope, system-ui, sans-serif; font-feature-settings: "locl" 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal); }
h1, h2, h3 { letter-spacing: -0.01em; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- обвивка ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.brand { font-weight: 800; font-size: 20px; padding: 0 8px; }
.brand span { color: var(--teal); }
.side select { width: 100%; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: inherit; text-decoration: none; font-weight: 600; }
.nav a:hover { background: var(--soft); }
.nav a.on { background: var(--teal); color: var(--teal-ink); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .who { margin-top: auto; font-size: 13px; color: var(--muted); padding: 0 8px; overflow-wrap: anywhere; }
.main { padding: 26px 28px 80px; min-width: 0; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 26px; margin-right: auto; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .topbar .brand { padding: 0; font-size: 18px; }
  .main { padding: 18px 16px 80px; }
  .page-head h1 { font-size: 22px; }
}

/* ---------- контроли ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; text-decoration: none; color: inherit; white-space: nowrap; }
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); color: var(--teal-ink); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 6px 9px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=month], input[type=url],
input[type=search], input[type=datetime-local], input:not([type]), select, textarea {
  border: 1px solid var(--line); background: var(--card); border-radius: 9px; padding: 7px 10px; min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
textarea { min-height: 70px; resize: vertical; }
label.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar select, .toolbar input { width: auto; }
.toolbar input[type=search] { min-width: 180px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 700; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--teal); }

/* ---------- карти и плочки ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 17px; margin-bottom: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 22px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); }
.tile.accent { background: var(--teal); color: var(--teal-ink); border-color: transparent; }
.tile.accent .k, .tile.accent .s { color: inherit; opacity: .8; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(110px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar .track { height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--teal); border-radius: 999px; }
.bar .val { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---------- таблици ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--soft); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
tr.group td { background: var(--soft); font-weight: 800; }
tr.group .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }
tr.total td { font-weight: 800; border-top: 2px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td input.qty { width: 74px; text-align: right; padding: 4px 6px; }
td select.inline { width: auto; padding: 3px 6px; font-size: 13px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.badge.teal { background: color-mix(in srgb, var(--teal) 16%, transparent); color: var(--teal); }

/* мобилни таблици → карти */
@media (max-width: 700px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.cards tr.group { padding: 0; }
  table.cards td { border: 0; padding: 3px 10px; }
  table.cards td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: 12px; }
  table.cards td.num { text-align: left; }
}

/* ---------- матрица план/факт ---------- */
.matrix td, .matrix th { padding: 6px 8px; font-size: 13px; }
.matrix td.cell { text-align: right; cursor: pointer; font-variant-numeric: tabular-nums; white-space: nowrap; }
.matrix td.cell:hover { background: var(--soft); }
.matrix td.cell.plan { color: var(--muted); }
.matrix td.cell.paid { color: var(--ok); font-weight: 700; }
.matrix td.cell.unpaid { color: var(--warn); font-weight: 700; }
.matrix td.cell.zero { color: var(--line); }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; min-width: 180px; }
.matrix th:first-child { background: var(--soft); }

/* ---------- модален прозорец ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 15, .5); z-index: 100; display: grid; place-items: start center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 18px; width: min(640px, 100%); box-shadow: var(--shadow); }
.modal.wide { width: min(1000px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; margin-right: auto; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }
.form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.form .f { display: flex; flex-direction: column; gap: 4px; }
.form .f.full { grid-column: 1 / -1; }
.form .f > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.form .f small { color: var(--muted); font-size: 12px; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } .overlay { padding: 12px 8px; } }
.section-title { font-weight: 800; margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }
.section-title .btn { margin-left: auto; }
.perm-grid { display: grid; grid-template-columns: 1fr repeat(3, auto); gap: 6px 14px; align-items: center; }
.perm-grid .h { font-size: 12px; color: var(--muted); font-weight: 700; text-align: center; }
.perm-grid label { justify-self: center; }

.offer-best { outline: 2px solid var(--ok); outline-offset: -2px; }
.offer-sel td { background: color-mix(in srgb, var(--teal) 8%, transparent); }
.offer-expired td { opacity: .55; }

/* ---------- съобщения ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; font-size: 14px; }
.toast.err { background: var(--bad); color: #fff; }
.note { background: var(--soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.note.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--ink); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(400px, 100%); padding: 28px; }
.login h1 { font-size: 26px; margin-bottom: 6px; }
.login h1 span { color: var(--teal); }
.login form { display: grid; gap: 12px; margin-top: 18px; }
.login input.code { font-size: 28px; letter-spacing: 10px; text-align: center; font-weight: 800; }
.login .btn { justify-content: center; padding: 11px; }
.linkbtn { background: none; border: 0; color: var(--teal); cursor: pointer; padding: 0; font-weight: 600; }

/* ---------- галерия (пренесена от предишната страница) ---------- */
.gal { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start; }
.gal .plan { position: sticky; top: 16px; }
.gal #plan { width: 100%; height: auto; max-height: 62vh; display: block; margin: 0 auto; }
#plan .outline, #miniplan .outline { fill: var(--floor); stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
#plan .yard, #miniplan .yard { fill: var(--yard); stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
#plan .door, #miniplan .door { stroke: var(--oak); stroke-width: 6; }
#plan .room, #miniplan .room { fill: none; stroke: var(--muted); stroke-width: 1.5; }
#plan .wc, #miniplan .wc { fill: var(--line); }
#plan .desk, #miniplan .desk { fill: var(--oak); opacity: .55; }
#plan .sofa, #miniplan .sofa { fill: #6f8b6a; opacity: .7; }
#plan .rug, #miniplan .rug { fill: var(--oak); opacity: .18; }
#plan .lbl { font-size: 13px; fill: var(--muted); text-anchor: middle; font-weight: 600; }
#miniplan .lbl { display: none; }
#plan .route, #miniplan .route { fill: none; stroke: var(--oak); stroke-width: 2.5; stroke-dasharray: 6 6; opacity: .8; }
.mk { cursor: pointer; }
.mk .cone { fill: var(--teal); opacity: .22; transition: opacity .2s; }
.mk circle { fill: var(--teal); stroke: var(--card); stroke-width: 3; }
.mk text { fill: #fff; font-size: 14px; font-weight: 800; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.mk.on .cone { opacity: .5; fill: var(--oak); }
.mk.on circle { fill: var(--oak); }
.gal .legend { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }
.gal .legend a { display: flex; align-items: center; padding: 5px 6px; border-radius: 8px; color: inherit; text-decoration: none; font-size: 14px; }
.gal .legend a:hover, .gal .legend a.on { background: var(--soft); }
.nbadge { display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--teal); color: #fff; font-size: 12px; font-weight: 800; margin-right: 10px; }
.legend a.on .nbadge { background: var(--oak); }
.gal section { scroll-margin-top: 16px; }
.gal section h2 { display: flex; align-items: center; font-size: 20px; margin-bottom: 4px; }
.gal section p { margin: 0 0 12px; color: var(--muted); }
.ba { position: relative; width: 100%; aspect-ratio: 3 / 2; border-radius: 12px; overflow: hidden; user-select: none; touch-action: pan-y; cursor: ew-resize; background: #000; --pos: 50%; }
.ba img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.ba .after { clip-path: inset(0 0 0 var(--pos)); }
.ba .handle { position: absolute; top: 0; bottom: 0; left: var(--pos); width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25), 0 0 12px rgba(0,0,0,.35); pointer-events: none; }
.ba .knob { position: absolute; top: 50%; left: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.35); display: grid; place-items: center; color: #24505c; font-weight: 800; letter-spacing: -2px; }
.ba .tag { position: absolute; bottom: 52px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: rgba(20,25,27,.72); color: #fff; pointer-events: none; }
.ba .tag.l { left: 12px; } .ba .tag.r { right: 12px; background: rgba(36,80,92,.9); }
.ba input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: ew-resize; }
@media (max-width: 900px) { .gal { grid-template-columns: 1fr; } .gal .plan { position: static; } }

.tour { position: fixed; inset: 0; z-index: 150; background: #0b0f10; color: #fff; overflow: hidden; }
.t-stage { position: absolute; inset: 0; touch-action: pan-y; }
.t-layer { position: absolute; inset: 0; opacity: 0; transition: opacity 1.1s ease; }
.t-layer.in { opacity: 1; }
.t-layer img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scale(1.02); }
.t-layer.in img { animation: kb 9s ease-out forwards; }
.t-layer .t-a { opacity: 0; }
.t-layer.in .t-a { animation: kb 9s ease-out forwards, reveal 9s ease forwards; }
.tour.paused .t-layer img { animation-play-state: paused; }
.tour.peek .t-layer .t-a { opacity: 0 !important; animation: none; }
@keyframes kb { from { transform: scale(1.02); } to { transform: scale(1.12) translateY(-1.5%); } }
@keyframes reveal { 0%, 28% { opacity: 0; } 48%, 100% { opacity: 1; } }
.t-layer .tag { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); padding: 5px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; background: rgba(20,25,27,.75); }
.t-layer .tag.r { background: rgba(36,80,92,.92); opacity: 0; }
.t-layer.in .tag.l { animation: tagOut 9s forwards; }
.t-layer.in .tag.r { animation: tagIn 9s forwards; }
@keyframes tagOut { 0%, 35% { opacity: 1; } 45%, 100% { opacity: 0; } }
@keyframes tagIn { 0%, 40% { opacity: 0; } 50%, 100% { opacity: 1; } }
.t-progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: rgba(255,255,255,.15); }
.t-progress i { display: block; height: 100%; width: 0; background: #d6a266; }
.t-close { position: absolute; top: 14px; right: 14px; width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 18px; cursor: pointer; }
.t-mini { position: absolute; top: 14px; left: 14px; width: 120px; padding: 8px; border-radius: 12px; background: rgba(12,16,17,.72); }
.t-mini svg { width: 100%; height: auto; display: block; }
#miniplan { --floor: #232b2e; --yard: #1f2b22; --ink: #ece7de; --muted: #9aa3a7; --line: #2c3539; --card: #1c2326; }
.t-panel { position: absolute; left: 0; right: 0; bottom: 0; padding: 60px 24px 18px; background: linear-gradient(transparent, rgba(0,0,0,.82)); display: grid; grid-template-columns: 1fr auto; gap: 8px 24px; align-items: end; }
.t-title { font-size: clamp(20px, 3vw, 30px); font-weight: 800; display: flex; align-items: center; }
.t-desc { max-width: 760px; color: rgba(255,255,255,.82); font-size: 15px; margin-top: 4px; }
.t-ctrl { display: flex; align-items: center; gap: 8px; }
.t-ctrl button { width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #fff; font-size: 22px; cursor: pointer; }
.t-ctrl .t-play { font-size: 14px; background: #24505c; border-color: transparent; }
.t-step { font-size: 13px; color: rgba(255,255,255,.7); min-width: 40px; text-align: right; }
.t-hint { grid-column: 1 / -1; font-size: 12px; color: rgba(255,255,255,.5); }
@media (max-width: 640px) { .t-panel { grid-template-columns: 1fr; padding: 40px 16px 14px; } .t-mini { width: 82px; } .t-hint { display: none; } }
.page-head select { width: auto; }
