:root {
  --bg: #F2F4F5; --card: #FFFFFF; --ink: #14262A; --mut: #4A5A5C; --soft: #8FA3A1; --line: #E4E9EA; --mint: #E6F6F3;
  --side: #14262A; --side-ink: #C9DADB; --teal: #19D3C0; --deep: #0E6B66; --acc: #0E6B66; --gold: #FFC94A; --red: #D9534F; --green: #1D9E75;
  --shadow: 0 6px 24px rgba(20, 38, 42, .12); --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1C1E; --card: #172A2D; --ink: #E7F1F1; --mut: #9DB3B5; --soft: #6F8789; --line: #26403F; --mint: #173B37;
    --side: #0A1416; --side-ink: #9DB3B5; --acc: #7FE6DA; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1C1E; --card: #172A2D; --ink: #E7F1F1; --mut: #9DB3B5; --soft: #6F8789; --line: #26403F; --mint: #173B37;
  --side: #0A1416; --side-ink: #9DB3B5; --acc: #7FE6DA; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--soft); }
button.primary { background: var(--teal); border-color: var(--teal); color: #14262A; font-weight: 500; }
button.primary:hover { filter: brightness(.95); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--mint); }
button.danger { color: var(--red); }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 60px; }
label { display: block; font-size: 12px; color: var(--mut); margin: 10px 0 4px; }
.hidden { display: none !important; }
.muted { color: var(--mut); }
.small { font-size: 12px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* Вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--card); padding: 28px; border-radius: 16px; width: 100%; max-width: 340px; box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; color: var(--deep); }
:root[data-theme="dark"] .login h1 { color: var(--teal); }
.login button { width: 100%; margin-top: 16px; padding: 10px; }

/* Каркас */
.app { display: grid; grid-template-columns: 210px minmax(0, 1fr); height: 100%; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 14px 10px; overflow-y: auto; }
.brand { font-size: 18px; font-weight: 700; color: var(--teal); padding: 2px 10px 16px; letter-spacing: .2px; }
.brand span { color: var(--side-ink); font-weight: 400; font-size: 14px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-ink); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: rgba(255, 255, 255, .06); }
.nav a.on { background: var(--teal); color: #14262A; font-weight: 500; }
.nav svg { width: 18px; height: 18px; flex: none; }
.badge { margin-left: auto; background: var(--gold); color: #14262A; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.badge.red { background: var(--red); color: #fff; }
.shift { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 13px; }
.shift b { color: var(--teal); font-weight: 500; }
.shift .warn { color: var(--gold); font-size: 12px; margin-top: 4px; }
.shift button { width: 100%; margin-top: 8px; background: transparent; border-color: rgba(255, 255, 255, .2); color: var(--side-ink); }
.shift button.primary { background: var(--teal); color: #14262A; border-color: var(--teal); }
.me { font-size: 12px; padding: 8px 10px 0; display: flex; justify-content: space-between; align-items: center; }
.me button { padding: 2px 6px; color: var(--side-ink); background: transparent; border: 0; text-decoration: underline; }

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.top { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--line); }
.top h2 { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; }
.top .search { max-width: 260px; margin-left: auto; }
.top .menu-btn { display: none; }
.view { flex: 1; overflow: auto; padding: 16px 18px; }

/* Доска */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 10px; height: 100%; min-height: 400px; }
.col { background: rgba(127, 127, 127, .06); border-radius: var(--r); display: flex; flex-direction: column; min-height: 0; }
.col.drop { outline: 2px dashed var(--teal); }
.col-head { --c: var(--teal); background: var(--c); color: #14262A; padding: 8px 14px 8px 12px; font-weight: 500; font-size: 13px;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%); border-radius: var(--r) 0 0 0; display: flex; justify-content: space-between; }
.col-head.light { color: #fff; }
.col-body { padding: 8px; overflow-y: auto; flex: 1; }
.deal { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; cursor: pointer; }
.deal:hover { border-color: var(--teal); }
.deal[draggable="true"] { cursor: grab; }
.deal .name { font-weight: 500; }
.deal .row { font-size: 12px; color: var(--mut); margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--mint); color: var(--deep); }
:root[data-theme="dark"] .tag { color: var(--acc); }
.tag.warn { background: rgba(255, 201, 74, .25); color: #7a5800; }
.tag.bad { background: rgba(217, 83, 79, .15); color: var(--red); }
.tag.ok { background: rgba(29, 158, 117, .15); color: var(--green); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tag { color: var(--acc); } :root:not([data-theme="light"]) .tag.warn { color: var(--gold); } }
:root[data-theme="dark"] .tag.warn { color: var(--gold); }
.empty { color: var(--soft); font-size: 12px; text-align: center; padding: 14px 0; }

/* Таблицы и списки */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.item { display: flex; gap: 12px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 500; }
.item.click { cursor: pointer; }
.item.click:hover { background: var(--mint); }
.check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--soft); background: transparent; padding: 0; flex: none; }
.check:hover { border-color: var(--teal); background: var(--mint); }
.overdue { color: var(--red); }
.section-title { font-size: 13px; font-weight: 600; color: var(--mut); margin: 18px 0 8px; text-transform: none; }
.section-title:first-child { margin-top: 0; }

/* Дашборд */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.kpi .l { font-size: 12px; color: var(--mut); }
.kpi .n { font-size: 28px; font-weight: 600; margin-top: 2px; }
.kpi .s { font-size: 12px; color: var(--mut); }
.kpi.alert .n { color: var(--red); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.panel h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.bar { display: grid; grid-template-columns: 150px 1fr 40px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.bar .t { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bar .t i { --w: 0%; --c: var(--teal); display: block; height: 100%; width: var(--w); background: var(--c); border-radius: 5px; }
.bar .v { text-align: right; font-weight: 500; }
.banner { background: rgba(255, 201, 74, .2); border: 1px solid var(--gold); border-radius: var(--r); padding: 10px 14px; margin-bottom: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }

/* Карточка сделки */
.overlay { position: fixed; inset: 0; background: rgba(10, 20, 22, .45); display: flex; justify-content: flex-end; z-index: 20; }
.sheet { background: var(--bg); width: min(1100px, 100%); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow); animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(40px); opacity: .6; } }
.sheet-head { background: var(--card); padding: 14px 18px; border-bottom: 1px solid var(--line); }
.sheet-head .t { display: flex; align-items: center; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 600; flex: 1; }
.stages { display: flex; gap: 3px; margin-top: 12px; flex-wrap: wrap; }
.stage { --c: var(--line); flex: 1; min-width: 92px; border: 0; border-radius: 0; padding: 7px 14px 7px 12px; font-size: 12px; background: var(--line); color: var(--mut);
  clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%, 9px 50%); text-align: center; }
.stage:first-child { clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%); }
.stage.done { background: var(--c); color: #14262A; }
.stage.light.done { color: #fff; }
.stage:hover { filter: brightness(.95); }
.stage.lostbtn { flex: none; min-width: 0; background: transparent; color: var(--red); clip-path: none; border: 1px solid var(--line); border-radius: 8px; }
.sheet-body { flex: 1; overflow: auto; display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 14px; padding: 14px 18px; align-items: start; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 14px; }
.box h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.box label:first-of-type { margin-top: 4px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 8px; font-size: 13px; }
.kv dt { color: var(--mut); }
.kv dd { margin: 0; }
.visits { font-size: 12px; margin-top: 8px; }
.visits div { padding: 4px 0; border-top: 1px dashed var(--line); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: -4px -4px 10px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; padding: 8px 12px; color: var(--mut); }
.tabs button.on { border-bottom-color: var(--teal); color: var(--ink); font-weight: 500; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; height: 42px; }
.composer .opts { display: flex; gap: 8px; margin-top: 8px; }
.chat { max-height: 380px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px 10px; }
.msg { max-width: 78%; padding: 7px 11px; border-radius: 12px; background: var(--mint); white-space: pre-wrap; word-wrap: break-word; font-size: 13px; }
.msg.out { align-self: flex-end; background: var(--teal); color: #14262A; }
.msg.auto { opacity: .65; }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 3px; }
.feed { margin-top: 6px; }
.ev { display: grid; grid-template-columns: 28px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.ev .ic { --c: var(--soft); width: 26px; height: 26px; border-radius: 50%; background: var(--c); display: grid; place-items: center; color: #fff; font-size: 12px; }
.ev .meta { font-size: 11px; color: var(--mut); }
.task-line { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--gold); border-radius: 8px; margin-bottom: 6px; background: rgba(255, 201, 74, .1); font-size: 13px; }
.task-line .grow { flex: 1; }

/* Окна */
.dialog { position: fixed; inset: 0; background: rgba(10, 20, 22, .45); display: grid; place-items: center; z-index: 30; padding: 16px; }
.dialog form { background: var(--card); border-radius: 14px; padding: 20px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.dialog h3 { margin: 0 0 6px; font-size: 17px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { padding: 4px 10px; font-size: 13px; }
.chips button.on { background: var(--teal); border-color: var(--teal); color: #14262A; }

/* График */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal .dow { font-size: 12px; color: var(--mut); text-align: center; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px; min-height: 74px; font-size: 12px; }
.day.today { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.day .d { font-weight: 600; }
.day select { margin-top: 4px; padding: 3px 4px; font-size: 12px; }
.day .fact { margin-top: 3px; }
.day.off { visibility: hidden; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 40; font-size: 13px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 25; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .top { padding: 10px 12px; flex-wrap: wrap; }
  .top .menu-btn { display: inline-block; }
  .top .search { max-width: none; order: 5; flex-basis: 100%; }
  .view { padding: 12px; }
  .sheet-body { grid-template-columns: 1fr; padding: 12px; }
  .board { grid-auto-columns: 82%; }
  .bar { grid-template-columns: 110px 1fr 32px; }
}
.panel h3.mt { margin-top: 16px; }

/* Аренда */
.mt12 { margin-top: 12px; }
.vbars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 16px; }
.vb { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.vb i { --h: 0%; display: block; width: 100%; max-width: 46px; height: var(--h); background: var(--line); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.vb.on i, .vbars.hours .vb i { background: var(--teal); }
.vb .vl { font-size: 11px; color: var(--mut); margin-top: 4px; white-space: nowrap; }
.vb .vv { font-size: 11px; font-weight: 600; margin-bottom: 3px; }
.vbars.hours { gap: 3px; height: 130px; }
.rooms .rr { display: grid; grid-template-columns: minmax(0, 1.4fr) 110px 60px minmax(120px, 1.3fr); gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.rooms .rr.head { border-top: 0; font-size: 12px; color: var(--mut); padding-top: 0; }
.rooms .t { display: flex; align-items: center; gap: 8px; }
.rooms .t i { --w: 0%; --c: var(--teal); height: 10px; width: var(--w); max-width: 100%; background: var(--c); border-radius: 5px; flex: none; }
.rooms .t em { font-style: normal; font-size: 12px; color: var(--mut); }
.bar span:first-child { min-width: 0; }
@media (max-width: 860px) { .rooms .rr { grid-template-columns: minmax(0, 1fr) 90px 70px; } .rooms .rr > span:nth-child(3) { display: none; } }
.legend { font-size: 11px; font-weight: 400; color: var(--mut); display: inline-flex; gap: 6px; align-items: center; margin-left: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.lg-rent { background: var(--teal); }
.lg-school, .s-school { background: var(--gold); }
.vb .stack { --h: 0%; display: flex; flex-direction: column-reverse; width: 100%; max-width: 46px; height: var(--h); background: var(--line); border-radius: 6px 6px 2px 2px; overflow: hidden; min-height: 2px; }
.vb.on .stack { background: var(--teal); }
.vb .stack i { --h: 0%; display: block; height: var(--h); width: 100%; max-width: none; border-radius: 0; min-height: 0; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.tbl th { font-weight: 500; color: var(--mut); font-size: 12px; text-align: right; padding: 4px 8px; }
.tbl th.grp { text-align: center; border-bottom: 1px solid var(--line); color: var(--ink); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td { padding: 8px; border-top: 1px solid var(--line); text-align: right; }
.tbl tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
.tbl .t { display: inline-flex; align-items: center; gap: 6px; width: 110px; }
.tbl .t i { --w: 0%; --c: var(--teal); display: block; height: 8px; width: calc(var(--w) * 0.6); background: var(--c); border-radius: 4px; }
.tbl .t em { font-style: normal; font-size: 12px; color: var(--mut); }
.kv dd .small { margin-top: 1px; }
.vb .stack i.s-school { background: var(--gold); }
.kv { grid-template-columns: max-content 1fr; column-gap: 14px; }

/* Таблица по филиалам */
.tbl col.c-rent { background: rgba(25, 211, 192, .07); }
.tbl col.c-school { background: rgba(255, 201, 74, .10); }
.tbl col.c-sum { background: rgba(127, 127, 127, .06); }
.tbl th.g-rent { color: var(--deep); border-bottom: 2px solid var(--teal); }
.tbl th.g-school { color: #8a6200; border-bottom: 2px solid var(--gold); }
:root[data-theme="dark"] .tbl th.g-rent { color: var(--teal); }
:root[data-theme="dark"] .tbl th.g-school { color: var(--gold); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tbl th.g-rent { color: var(--teal); } :root:not([data-theme="light"]) .tbl th.g-school { color: var(--gold); } }
.tbl .b-l { border-left: 1px solid var(--line); }
.tbl td.sub { font-weight: 600; }
.tbl td.sum { font-weight: 700; }
.tbl tbody.branch { border-top: 10px solid transparent; }
.tbl tr.b-row td { background: var(--mint); border-top: 1px solid var(--line); font-size: 14px; }
.tbl tr.b-row td:first-child { border-radius: 8px 0 0 8px; }
.tbl tr.b-row td:last-child { border-radius: 0 8px 8px 0; }
.tbl tr.r-row td { font-size: 13px; color: var(--ink); }
.tbl tr.r-row td:first-child b { font-weight: 500; }
.tbl .indent { display: inline-block; width: 18px; border-left: 2px solid var(--line); height: 14px; margin: 0 6px -2px 6px; }
.tbl tr.t-row td { background: var(--side); color: #fff; border-top: 0; }
.tbl tr.t-row td .muted { color: #C9DADB; }

/* Сотрудники */
.panel form button.primary { margin-top: 12px; }
.invite-box { margin-top: 14px; padding: 12px; border: 1px solid var(--teal); border-radius: var(--r); background: var(--mint); }
.invite-box input { margin: 8px 0; font-size: 13px; }
.list.flat { border: 0; }
.list.flat .item { padding: 10px 0; }
.item.off .title { color: var(--soft); text-decoration: line-through; }
