:root {
  --bg: #f4f6f9; --card: #fff; --ink: #18202c; --muted: #6b7686; --line: #e3e7ed; --line2: #eef1f5;
  --accent: #2563eb; --ok: #0f9d6a; --bad: #d92d20; --warn: #d97706;
  --booking: #1d4ed8; --airbnb: #e0475b; --expedia: #b45309; --vrbo: #0e7490; --direct: #0f9d6a;
  --hold: #8a93a3; --sel: #2563eb;
  --w: 46px; --name: 170px; --row: 48px; --drawer: 440px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #10141b; --card: #1a2029; --ink: #e8ecf2; --muted: #8e99aa; --line: #2b3441; --line2: #222a35; --accent: #5b8cff; --sel: #5b8cff; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; width: 100%; min-width: 0; }
input:disabled, select:disabled, textarea:disabled { background: var(--line2); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pad { padding: 8px 10px; }
.empty { padding: 28px; color: var(--muted); text-align: center; }

/* ---------- верхняя панель ---------- */
.top { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); position: relative; z-index: 30; }
.views { display: flex; gap: 2px; background: var(--line2); padding: 3px; border-radius: 10px; }
.tab { border: 0; background: transparent; padding: 5px 10px; border-radius: 8px; }
.tab.on { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.nav.off { display: none; }
.nav input, .nav select { width: auto; }
.search { position: relative; flex: 1 1 220px; max-width: 360px; }
.qres { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.16); max-height: 60vh; overflow: auto; z-index: 40; }
.qres button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line2); border-radius: 0; padding: 8px 10px; white-space: normal; }
.actions { display: flex; gap: 6px; align-items: center; margin-left: auto; position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.16); min-width: 220px; z-index: 45; padding: 4px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; padding: 8px 10px; }
.menu button:hover { background: var(--line2); }
.pill.ok { border-color: var(--ok); color: var(--ok); }
.pill.warn { border-color: var(--warn); color: var(--warn); }
.pill.bad { border-color: var(--bad); color: var(--bad); }

.freebar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 6px 12px; background: color-mix(in srgb, var(--ok) 12%, var(--card)); border-bottom: 1px solid var(--line); }
.freebar .chk { display: flex; gap: 6px; align-items: center; }
.freebar .chk input { width: auto; }
.freebar #frX { margin-left: auto; }

/* ---------- шахматка ---------- */
.cal { flex: 1; overflow: auto; background: var(--card); user-select: none; -webkit-user-select: none; }
.grid { position: relative; min-width: max-content; }
.hrow, .row { display: flex; }
.hrow { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
.name { flex: 0 0 var(--name); width: var(--name); position: sticky; left: 0; z-index: 6; background: var(--card); border-right: 1px solid var(--line); padding: 0 8px 0 12px; display: flex; align-items: center; gap: 6px; font-weight: 600; box-shadow: inset 4px 0 0 var(--pc, transparent); }
.name .pname { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.notready { margin-right: 4px; }
.hrow .name { z-index: 15; color: var(--muted); font-weight: 500; height: 46px; }
.day { flex: 0 0 var(--w); width: var(--w); text-align: center; border-right: 1px solid var(--line2); position: relative; }
.hrow .day { height: 46px; padding-top: 4px; font-size: 11px; color: var(--muted); line-height: 1.15; }
.hrow .day b { display: block; font-size: 14px; color: var(--ink); }
.hrow .day i { font-style: normal; font-size: 10px; }
.day.we { background: color-mix(in srgb, var(--line) 30%, transparent); }
.hrow .day.today { background: var(--accent); color: #fff; border-radius: 8px 8px 0 0; }
.hrow .day.today b { color: #fff; }
.day.frange { background: color-mix(in srgb, var(--ok) 14%, transparent); }
.row { position: relative; border-bottom: 1px solid var(--line2); height: var(--row); }
.row.dim { opacity: .38; }
.row .day { cursor: cell; }
.row .day.past { background-image: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--line) 45%, transparent) 6px 7px); }
.row .day:hover { background-color: color-mix(in srgb, var(--accent) 10%, transparent); }
.row .day .pr { position: absolute; left: 0; right: 0; top: 16px; font-size: 11px; color: var(--muted); }
.row .day.custom .pr { color: var(--ink); font-weight: 600; }
.row .day .ms { position: absolute; right: 3px; bottom: 2px; font-size: 9px; color: var(--warn); font-weight: 700; }
.row .day.stop { background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--bad) 10%, transparent) 0 5px, transparent 5px 10px); }
.row .day.stop .pr { color: var(--bad); text-decoration: line-through; }
.row .day.cta::before { content: ""; position: absolute; left: 2px; top: 3px; border: 4px solid transparent; border-left-color: var(--bad); }
.row .day.ctd::after { content: ""; position: absolute; right: 2px; top: 3px; border: 4px solid transparent; border-right-color: var(--bad); }
.row .day.sel { background: color-mix(in srgb, var(--sel) 26%, transparent) !important; }
.row .day.start { background: color-mix(in srgb, var(--sel) 45%, transparent) !important; }
.fchip { margin-left: auto; font-size: 11px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--ok); color: var(--ok); background: var(--card); font-weight: 700; }
.fchip.busy { border-color: var(--line); color: var(--muted); font-weight: 500; }

/* полосы броней: начинаются в середине дня заезда и кончаются в середине дня выезда */
.bar { position: absolute; top: 6px; height: 26px; border-radius: 6px; color: #fff; padding: 0 6px 0 4px; display: flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; overflow: hidden; cursor: pointer; z-index: 3; background: var(--bc, var(--direct)); box-shadow: 0 1px 2px rgba(0,0,0,.18); transform: skewX(-12deg); }
.bar > * { transform: skewX(12deg); }
.bar.clipl { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.clipr { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.bar:hover { filter: brightness(1.08); box-shadow: 0 2px 6px rgba(0,0,0,.25); z-index: 4; }
.bar .bl { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; font-weight: 600; }
.bar .marks { display: flex; gap: 3px; align-items: center; font-size: 11px; }
.bar.src-booking:not(.custom-color) { --bc: var(--booking); }
.bar.src-airbnb:not(.custom-color) { --bc: var(--airbnb); }
.bar.src-expedia:not(.custom-color) { --bc: var(--expedia); }
.bar.src-vrbo:not(.custom-color) { --bc: var(--vrbo); }
.bar.hold { background: repeating-linear-gradient(45deg, #8a93a3 0 6px, #7b8494 6px 12px); color: #fff; }
.bar.hold-tentative { background: repeating-linear-gradient(45deg, #b7791f 0 6px, #a86b12 6px 12px); }
.bar.hold-owner { background: repeating-linear-gradient(45deg, #6d5bd0 0 6px, #5f4dc2 6px 12px); }
.bar.inquiry { background: color-mix(in srgb, var(--bc, var(--direct)) 18%, var(--card)); color: var(--ink); border: 1.5px dashed var(--bc, var(--direct)); box-shadow: none; }
.bar.inquiry.low { top: auto; bottom: 2px; height: 12px; font-size: 9px; z-index: 5; }
.bar.inquiry.low .ic { display: none; }
.bar.conflict { outline: 2px solid var(--bad); outline-offset: 1px; }
.ic { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 3px; border-radius: 4px; background: rgba(255,255,255,.22); font-size: 10px; font-weight: 800; flex: none; }
.ic-booking { font-family: Georgia, serif; }
.qres .ic, .dhead .ic, .agenda .ic, .note .ic { background: var(--line2); color: var(--ink); }
.mk-pay { width: 8px; height: 8px; border-radius: 50%; background: #fecaca; box-shadow: 0 0 0 1.5px #fff; display: inline-block; }
.mk-pay.unpaid { background: #ef4444; }
.mk-pay.partial { background: #f59e0b; }
.exp { background: rgba(0,0,0,.25); border-radius: 4px; padding: 0 4px; }

/* ---------- всплывающее меню выделения ---------- */
.pop { position: fixed; z-index: 60; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.22); padding: 12px; width: min(320px, calc(100vw - 16px)); }
.pop .ph { margin-bottom: 6px; }
.pop .pq { font-size: 13px; margin-bottom: 10px; }
.pop .pb { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pop label { display: block; font-size: 12px; color: var(--muted); margin: 6px 0 2px; }
.ok { color: var(--ok); font-weight: 700; }
.no { color: var(--bad); font-weight: 700; }
.warn { color: var(--warn); }

/* ---------- боковая панель ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--drawer), 100vw); background: var(--card); border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(0,0,0,.15); z-index: 50; overflow: auto; padding: 16px 16px 90px; }
.dclose { position: absolute; top: 10px; right: 10px; font-size: 20px; line-height: 1; width: 34px; height: 34px; padding: 0; }
.dhead h2 { margin: 0 40px 6px 0; font-size: 19px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.badge { font-size: 11.5px; padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--bad); border-color: var(--bad); }
.badge.inq { color: var(--accent); border-color: var(--accent); border-style: dashed; }
.alert { background: color-mix(in srgb, var(--bad) 12%, var(--card)); color: var(--bad); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.dsec { border-top: 1px solid var(--line2); padding: 10px 0; }
.dsec h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.drawer label, .box label { display: block; margin: 8px 0 3px; color: var(--muted); font-size: 12.5px; }
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.span2 { grid-column: span 2; }
.colors { display: flex; gap: 6px; flex-wrap: wrap; }
.sw { width: 30px; height: 26px; border-radius: 6px; border: 1px solid var(--line); display: grid; place-items: center; font-size: 9px; color: var(--muted); margin: 0 !important; cursor: pointer; position: relative; }
.sw input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.sw:has(input:checked) { outline: 2px solid var(--ink); outline-offset: 2px; }
.types { display: flex; flex-wrap: wrap; gap: 6px; }
.tbtn { display: flex !important; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 0 !important; color: var(--ink) !important; cursor: pointer; }
.tbtn input { width: auto; }
.tbtn:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.note { background: var(--line2); border-radius: 8px; padding: 8px 10px; margin: 6px 0; white-space: pre-wrap; }
.nmeta { font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.dErr, .err { color: var(--bad); min-height: 1.2em; margin-top: 8px; }
.dfoot { position: fixed; bottom: 0; right: 0; width: min(var(--drawer), 100vw); padding: 12px 16px; background: var(--card); border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- заезды и выезды ---------- */
.agenda { flex: 1; overflow: auto; padding: 12px 16px 40px; }
.atools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.atools input { width: auto; }
.atools .on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.atools .grow { flex: 1; }
.aday { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
.aday h3 { margin: 0; padding: 10px 12px; font-size: 15px; border-bottom: 1px solid var(--line2); text-transform: capitalize; }
.aday h3 .muted { text-transform: none; font-weight: 400; font-size: 13px; }
.aday table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.aday td:nth-child(1) { width: 64px; }
.aday td:nth-child(2) { width: 140px; }
.aday td:nth-child(3) { width: 26%; }
.aday td:nth-child(5) { width: 90px; }
.aday td:nth-child(6) { width: 120px; }
.aday td:nth-child(7) { width: 130px; text-align: right; }
.aday td:nth-child(3), .aday td:nth-child(4) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aday td { padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.aday tr:last-child td { border-bottom: 0; }
.aday tr { cursor: pointer; }
.aday tr:hover td { background: var(--line2); }
.aday td.t { width: 56px; font-variant-numeric: tabular-nums; color: var(--muted); }
.ev { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.ev.in { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.ev.out { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.ev.hold { background: var(--line2); color: var(--muted); }
.rdy { font-size: 12px; padding: 3px 8px; }
.rdy.yes { color: var(--ok); border-color: var(--ok); }
.rdy.no { color: var(--warn); border-color: var(--warn); }

/* ---------- модальные окна ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 70; padding: 12px; }
.modal.hidden, .toast.hidden { display: none; }
.box { background: var(--card); border-radius: 14px; padding: 18px; width: min(560px, 100%); max-height: 92vh; overflow: auto; }
.box h2 { margin: 0 0 10px; font-size: 18px; }
.box h3 { margin: 16px 0 4px; font-size: 14px; }
.box .btns { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; flex-wrap: wrap; }
.chk { display: flex !important; align-items: center; gap: 8px; color: var(--ink) !important; }
.chk input { width: auto; }
.plist { display: grid; gap: 4px; max-height: 42vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.prow { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 4px 2px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.log { font-size: 12px; color: var(--muted); max-height: 160px; overflow: auto; margin-top: 8px; }
.log.tall { max-height: 62vh; }
.log .bad { color: var(--bad); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 90; max-width: calc(100vw - 24px); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 700px) {
  :root { --w: 40px; --name: 104px; --row: 46px; }
  .top { padding: 6px 8px; gap: 6px; }
  .views { order: 1; }
  .actions { order: 2; }
  .nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .nav #jump { display: none; }
  .search { order: 4; flex-basis: 100%; max-width: none; }
  #syncPill { display: none !important; }
  .aday td:nth-child(1) { width: 48px; }
  .aday td:nth-child(2) { width: 84px; }
  .aday td:nth-child(7) { width: 96px; }
  .name { padding: 0 4px 0 8px; }
  .name .pname { font-size: 12px; }
  .fchip { position: absolute; right: 2px; bottom: 2px; font-size: 10px; padding: 0 4px; }
  .g2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .agenda { padding: 8px; }
  .aday td:nth-child(5), .aday td:nth-child(6) { display: none; }
}
@media print {
  body { overflow: visible; display: block; background: #fff; }
  .top, .freebar, .cal, .drawer, .pop, .atools, .toast, .rdy { display: none !important; }
  .agenda { display: block !important; overflow: visible; padding: 0; }
  .aday { break-inside: avoid; border-color: #999; }
}

/* ---------- список броней и доход ---------- */
.ltotal { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.tablewrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: auto; margin-bottom: 12px; }
.ltable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ltable th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); white-space: nowrap; }
.ltable td { padding: 7px 10px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.ltable tbody tr { cursor: pointer; }
.ltable tbody tr:hover td { background: var(--line2); }
.ltable tr.cancelled td { color: var(--muted); text-decoration: line-through; }
.ltable tr.inquiry td { color: var(--muted); }
.ltable tfoot td { font-weight: 700; border-top: 1px solid var(--line); border-bottom: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.st, .pay { font-size: 11.5px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); }
.st.confirmed { color: var(--ok); border-color: var(--ok); }
.st.inquiry { color: var(--accent); border-color: var(--accent); border-style: dashed; }
.pay.unpaid { color: var(--bad); border-color: var(--bad); }
.pay.partial { color: var(--warn); border-color: var(--warn); }
.pay.paid { color: var(--ok); border-color: var(--ok); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpis div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.kpis span { display: block; color: var(--muted); font-size: 12.5px; }
.kpis b { font-size: 20px; }
.occ { display: inline-block; min-width: 64px; padding: 1px 6px; border-radius: 6px; background: linear-gradient(90deg, color-mix(in srgb, var(--ok) 22%, transparent) var(--o), transparent var(--o)); }
.rtitle { font-size: 16px; min-width: 130px; text-align: center; }
.atools .chk { display: flex; align-items: center; gap: 6px; }
.atools select, .atools input[type="search"], .atools input[type="month"] { width: auto; }

/* ---------- цены по дням недели, данные квартиры ---------- */
.wdays { display: flex; gap: 4px; flex-wrap: wrap; }
.wd { display: flex !important; align-items: center; gap: 4px; margin: 0 !important; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; color: var(--ink) !important; cursor: pointer; }
.wd input { width: auto; }
.wd.we { background: color-mix(in srgb, var(--line) 35%, transparent); }
.wd:has(input:checked) { border-color: var(--accent); }
.kv { display: flex; gap: 10px; justify-content: space-between; padding: 3px 0; }
.kv span { color: var(--muted); }
.kv b { text-align: right; overflow-wrap: anywhere; }
.btnlink { display: inline-flex; align-items: center; border: 1px solid #25d366; color: #128c4a; border-radius: 8px; padding: 6px 11px; text-decoration: none; }
.gtl.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
@media (max-width: 700px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .views { flex-wrap: wrap; }
}
