:root {
  --navy:   #1a1a2e;
  --blue:   #16213e;
  --accent: #0f3460;
  --red:    #e74c3c;
  --dkred:  #c0392b;
  --orange: #f39c12;
  --green:  #27ae60;
  --dkgreen:#1e8449;
  --bg:     #f0f2f5;
  --card:   #ffffff;
  --text:   #1a1a2e;
  --muted:  #6c757d;
  --border: #e0e0e0;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
       background: var(--bg); color: var(--text); overscroll-behavior: none; }

/* ── Header ── */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--navy); color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}
.header-inner { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 18px; font-weight: 700; flex: 1; white-space: nowrap;
                overflow: hidden; text-overflow: ellipsis; }
.header-sub   { font-size: 13px; color: rgba(255,255,255,.6); }
.back-btn     { background: none; border: none; color: #fff; font-size: 22px;
                cursor: pointer; padding: 0 4px; line-height: 1; flex-shrink: 0; }

/* ── Main ── */
.app-main {
  margin-top: calc(48px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(64px + var(--safe-bottom) + 16px);
  min-height: 100vh;
}

/* ── Bottom Nav — always sticky ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 8px 0; background: none; border: none; cursor: pointer;
  color: var(--muted); transition: color .15s;
}
.tab.active { color: var(--navy); }
.tab-icon   { font-size: 20px; line-height: 1; }
.tab-label  { font-size: 10px; margin-top: 3px; }

/* ── Cards ── */
.card {
  background: var(--card); border-radius: var(--radius);
  margin: 12px 12px 0; padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.card-title { font-size: 12px; font-weight: 700; color: var(--muted);
              text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; }

/* ── KPI grid ── */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 12px 0; }
.kpi-grid + .kpi-grid { padding-top: 10px; }
.kpi-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.kpi {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); text-align: center;
}
.kpi.tappable { cursor: pointer; transition: transform .1s; }
.kpi.tappable:active { transform: scale(.97); }
.kpi-value  { font-size: 24px; font-weight: 800; line-height: 1; }
.kpi-grid-3 .kpi-value { font-size: 18px; }
.kpi-label  { font-size: 11px; color: var(--muted); margin-top: 4px; }
.kpi.red    { border-top: 3px solid var(--red); }
.kpi.orange { border-top: 3px solid var(--orange); }
.kpi.green  { border-top: 3px solid var(--green); }
.kpi.blue   { border-top: 3px solid var(--accent); }

/* ── Alert ── */
.alert {
  margin: 10px 12px 0; padding: 12px 14px; border-radius: var(--radius);
  display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500;
}
.alert.tappable { cursor: pointer; }
.alert.tappable:active { opacity: .8; }
.alert.danger { background: #fdecea; color: #c0392b; border-left: 4px solid var(--red); }
.alert.warn   { background: #fef9e7; color: #9a7d0a; border-left: 4px solid var(--orange); }
.alert.ok     { background: #eafaf1; color: #1e8449; border-left: 4px solid var(--green); }
.alert-icon   { font-size: 18px; flex-shrink: 0; }

/* ── Collapsible sections ── */
.collapsible-wrap { border-radius: var(--radius); overflow: hidden;
                    box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.collapsible-hdr {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: var(--card); cursor: pointer;
  font-size: 14px; font-weight: 600;
}
.collapsible-hdr:active { background: #f5f6fa; }
.col-arrow { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.collapsible-body { background: var(--card); }

/* ── List items ── */
.list-item {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--card); transition: background .1s;
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: #f5f6fa; }
.list-body  { flex: 1; min-width: 0; }
.list-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.list-title { font-size: 14px; font-weight: 600; white-space: nowrap;
              overflow: hidden; text-overflow: ellipsis; }
.list-sub   { font-size: 12px; color: var(--muted); margin-top: 2px;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-meta  { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }

/* ── Tags ── */
.tag {
  display: inline-block; padding: 2px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.tag.red    { background: #fdecea; color: var(--dkred); }
.tag.orange { background: #fef9e7; color: #9a7d0a; }
.tag.green  { background: #eafaf1; color: #1e8449; }
.tag.gray   { background: #f0f2f5; color: var(--muted); }
.tag.blue   { background: #eaf0fb; color: #2471a3; }
.tag.free   { background: #fdecea; color: var(--dkred); }
.tag.booked { background: #eafaf1; color: #1e8449; }

/* ── Health badge ── */
.health-badge {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff;
}

/* ── Info banner ── */
.info-banner {
  margin: 8px 12px 0; padding: 10px 14px; border-radius: var(--radius);
  background: #eaf0fb; color: #2471a3; font-size: 12px; line-height: 1.5;
}

/* ── Calendar ── */
.cal-month { margin: 12px 12px 0; }
.cal-title {
  font-size: 15px; font-weight: 700; padding: 8px 2px 4px;
  text-transform: capitalize;
}
.cal-dow-row {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
  margin-bottom: 2px;
}
.cal-dow {
  text-align: center; font-size: 10px; font-weight: 600; color: var(--muted);
  padding: 3px 0;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: calc((100vw - 36px) / 7);
  gap: 2px;
  width: 100%;
}
.cal-cell {
  aspect-ratio: 1;
  min-width: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: 5px; cursor: pointer; position: relative;
  overflow: hidden;
}
.cal-cell:active { opacity: .75; }
.cal-cell.empty   { background: transparent; cursor: default; pointer-events: none; }
.cal-cell.no-data { background: #e0e0e0; }
.cal-day  { font-size: 9px; color: rgba(255,255,255,.8); font-weight: 500; line-height: 1; }
.cal-pct  { font-size: 12px; font-weight: 800; color: #fff; line-height: 1.2; }
.cal-cell.no-data .cal-day { color: var(--muted); }
.cal-cell.no-data .cal-pct { color: var(--muted); font-size: 10px; }
.cal-cell.today { box-shadow: 0 0 0 2px var(--navy), 0 0 0 3px #fff; }

/* ── Issues — grouped ── */
.group-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,.08); margin-bottom: 10px; overflow: hidden;
}
.group-hdr {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.group-hdr:active { background: #f5f6fa; }
.group-hdr-body { flex: 1; min-width: 0; }
.group-title { font-size: 14px; font-weight: 700; white-space: nowrap;
               overflow: hidden; text-overflow: ellipsis; }
.group-addr  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.group-badge {
  background: var(--red); color: #fff; border-radius: 50%;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; flex-shrink: 0;
}
.group-issues { padding: 8px 0; }
.issue-sub {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
}
.issue-sub:last-child { border-bottom: none; }
.issue-sub-body { flex: 1; min-width: 0; }
.issue-sub-cat  { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.issue-text { font-size: 12px; color: var(--muted); line-height: 1.4;
              display: -webkit-box; -webkit-line-clamp: 2;
              -webkit-box-orient: vertical; overflow: hidden; }

/* ── Issue items (unit detail) ── */
.issue-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--card);
}
.issue-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.issue-item:last-child  { border-bottom: none; border-radius: 0 0 var(--radius) var(--radius); }
.issue-item:only-child  { border-radius: var(--radius); }
.issue-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.issue-cat    { font-size: 13px; font-weight: 700; }
.issue-days   { font-size: 12px; color: var(--muted); margin-left: auto; }
.issue-footer { display: flex; justify-content: flex-end; margin-top: 8px; }

/* ── Buttons ── */
.btn {
  padding: 7px 16px; border-radius: 20px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 600; transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn-resolve { background: var(--green); color: #fff; }
.btn-reopen  { background: #e0e0e0; color: var(--text); }
.btn-sm      { padding: 4px 10px; font-size: 12px; flex-shrink: 0; }
.tappable    { cursor: pointer; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; }
.dot.open { background: var(--red); }
.dot.done { background: var(--green); }

/* ── Finance bars ── */
.fin-bar-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.fin-bar-row:last-child { border-bottom: none; }
.fin-bar-row.tappable:active { background: #f5f6fa; }
.fin-bar-label { font-size: 12px; flex: 0 0 88px; overflow: hidden;
                 text-overflow: ellipsis; color: var(--text); }
.fin-bar-wrap  { flex: 1; background: #f0f2f5; border-radius: 4px; height: 8px; }
.fin-bar-fill  { height: 100%; border-radius: 4px; background: var(--accent); transition: width .4s; }
.fin-bar-val   { font-size: 11px; font-weight: 600; flex: 0 0 64px; text-align: right;
                 color: var(--muted); }

/* ── Search ── */
.search-wrap {
  padding: 8px 12px 0;
}
.search-input {
  width: 100%; padding: 9px 14px; border-radius: 20px;
  border: 1.5px solid var(--border); background: var(--card);
  font-size: 13px; color: var(--text); outline: none;
  -webkit-appearance: none;
}
.search-input:focus { border-color: var(--navy); }

/* ── Finance hint ── */
.fin-hint {
  font-size: 11px; color: var(--muted); margin-bottom: 10px; line-height: 1.4;
}

/* ── Filter row ── */
.filter-row {
  display: flex; gap: 8px; padding: 12px 12px 0; overflow-x: auto;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-btn {
  flex-shrink: 0; padding: 7px 14px; border-radius: 20px; border: 1.5px solid var(--border);
  background: var(--card); font-size: 12px; font-weight: 600; cursor: pointer;
  color: var(--muted); transition: all .15s; white-space: nowrap;
}
.filter-btn.active { border-color: var(--navy); background: var(--navy); color: #fff; }

/* ── Bottom sheet ── */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 200; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: all; }
.bottom-sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 201;
  background: var(--card); border-radius: 20px 20px 0 0;
  max-height: 85vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.32,0,.67,0);
  padding-bottom: var(--safe-bottom);
}
.bottom-sheet.open { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; background: #ddd; border-radius: 2px; margin: 10px auto 0; }
.sheet-content { overflow-y: auto; padding: 0; flex: 1; }
.sheet-header  { padding: 12px 16px; font-size: 15px; font-weight: 700;
                 border-bottom: 1px solid var(--border); }

/* ── Section header ── */
.section-header {
  padding: 16px 12px 4px; font-size: 12px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
}

/* ── Loading / empty ── */
.loading { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 15px; }
.empty   { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 15px; }

/* ── Unit detail ── */
.detail-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 9px 0; border-bottom: 1px solid var(--border); gap: 12px;
}
.detail-row:last-child { border-bottom: none; }
.detail-key { font-size: 13px; color: var(--muted); flex-shrink: 0; }
.detail-val { font-size: 13px; font-weight: 500; text-align: right; }

/* ── Mini calendar ── */
.mini-cal { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; }
.mini-cell {
  aspect-ratio: 1; min-width: 0; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 600;
}
.mini-cell.avail  { background: #eafaf1; color: #1e8449; }
.mini-cell.booked { background: var(--navy); color: #fff; }
.mini-cell.empty  { background: transparent; }
.mini-cell.past   { background: #f0f2f5; color: #bbb; }
.mini-legend { display: flex; gap: 12px; margin-top: 8px; padding-top: 8px;
               border-top: 1px solid var(--border); }
.mini-leg { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.mini-leg.avail  { background: #eafaf1; color: #1e8449; }
.mini-leg.booked { background: var(--navy); color: #fff; }
.mini-leg.past   { background: #f0f2f5; color: #bbb; }

/* ── Reviews ── */
.review-item { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--card); }
.review-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.review-item:last-child  { border-bottom: none; border-radius: 0 0 var(--radius) var(--radius); }
.review-item:only-child  { border-radius: var(--radius); }
.review-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.review-author { font-size: 13px; font-weight: 600; }
.review-date   { font-size: 11px; color: var(--muted); }
.review-stars  { color: #f39c12; font-size: 13px; letter-spacing: 1px; margin-bottom: 4px; }
.review-text   { font-size: 13px; line-height: 1.5; color: var(--text); }

/* ── Avito link ── */
.avito-link {
  display: block; text-align: center; padding: 16px;
  color: var(--accent); font-weight: 600; font-size: 14px; text-decoration: none;
}
