/* Портал ТСЖ — светлая тема. Все цвета проверены на контраст (см. contrast.py). */
:root {
  --bg: #FFFFFF;
  --surface: #F8F9FD;      /* заливка блока вместо рамки */
  /* тень плотная и короткая + тонкий кант: разделяет края, не размазывает фон */
  --shadow: 0 1px 3px rgba(23,32,74,0.05), 0 0 0 1px rgba(23,32,74,0.035);
  --shadow-card: 0 1px 2px rgba(23,32,74,0.06), 0 0 0 1px rgba(23,32,74,0.045);
  --surface-2: #EEF1F8;    /* вложенный элемент, ховер */
  --line: #E8EBF2;
  --text: #16181D;
  --muted: #6C727C;
  --accent: #3A4CB0;
  --accent-soft: #EEF0FC;
  --green: #08845B;
  --ok-bg: #E9F8F1;   --ok-fg: #0B6B47;
  --warn-bg: #FFF4E0; --warn-fg: #8A5A00;
  --err-bg: #FDECE8;  --err-fg: #9E3520;
  --r-block: 20px;
  --r-inner: 16px;
  --r-pill: 999px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Golos Text', 'Segoe UI', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* ——— каркас ——— */
.shell { width: 100%; max-width: 1440px; min-height: 100vh; margin: 0 auto; display: flex; flex-direction: column; }
.header { height: 76px; flex-shrink: 0; display: flex; align-items: center; gap: 28px; padding: 0 40px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: #FFF; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }
.brand .name { font-size: 15px; font-weight: 600; line-height: 1.25; }
.brand .sub { font-size: 12px; color: var(--muted); line-height: 1.3; }
.nav { display: flex; align-items: center; gap: 4px; flex-grow: 1; }
.nav a { font-size: 15px; font-weight: 500; color: var(--muted); text-decoration: none; padding: 9px 14px; border-radius: var(--r-pill); }
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.on { color: var(--text); font-weight: 600; }
.main { flex-grow: 1; padding: 8px 40px 48px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.page-head .where { font-size: 14px; color: var(--muted); }
.row { display: flex; gap: 20px; align-items: flex-start; }
.col { display: flex; flex-direction: column; gap: 20px; }
.grow { flex-grow: 1; min-width: 0; }

/* ——— блоки ——— */
.block { background: var(--surface); border-radius: var(--r-block); padding: 24px; box-shadow: var(--shadow); }
.block.plain { background: var(--bg); padding: 0; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.block-title { font-size: 17px; font-weight: 600; }
.card { background: var(--bg); border-radius: var(--r-inner); padding: 18px; box-shadow: var(--shadow-card); }
.link { font-size: 14px; font-weight: 500; color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ——— кнопки ——— */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; height: 48px; padding: 0 22px; border: none; border-radius: var(--r-pill); font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-green { background: var(--green); color: #FFF; }
.btn-accent { background: var(--accent); color: #FFF; }
.btn-outline { background: var(--bg); color: var(--accent); box-shadow: inset 0 0 0 1.5px #D5DAEC; }
.btn-ghost { background: var(--surface-2); color: var(--accent); }
.btn-sm { height: 40px; padding: 0 16px; font-size: 14px; }
.icon-btn { width: 48px; height: 48px; border: none; border-radius: var(--r-pill); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.icon-btn .dot { position: absolute; top: 12px; right: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.select { display: inline-flex; align-items: center; gap: 10px; height: 48px; padding: 0 18px; border: none; border-radius: var(--r-pill); background: var(--surface); font-family: inherit; font-size: 15px; font-weight: 600; color: var(--text); cursor: pointer; }

/* ——— мелочи ——— */
.badge { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; border-radius: var(--r-pill); padding: 5px 12px; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-err { background: var(--err-bg); color: var(--err-fg); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.badge-mute { background: var(--surface-2); color: var(--muted); }
.amount { font-size: 46px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.05; }
.stat { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.label { font-size: 14px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; }
.banner { border-radius: var(--r-inner); padding: 18px 22px; font-size: 15px; font-weight: 500; }
.banner-ok { background: var(--ok-bg); color: var(--ok-fg); }

.dl { margin: 0; display: flex; flex-direction: column; gap: 12px; }
.dl > div { display: flex; justify-content: space-between; gap: 16px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 600; text-align: right; }

.feed { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
.feed li { display: flex; flex-direction: column; gap: 4px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: none; padding-bottom: 0; }
.feed li:first-child { padding-top: 0; }
.feed .t { font-size: 14px; font-weight: 500; line-height: 1.4; }
.feed .d { font-size: 13px; color: var(--muted); }

/* ——— админский каркас: светлый сайдбар ——— */
.layout { display: flex; min-height: 100vh; }
.side { width: 264px; flex-shrink: 0; background: var(--surface); padding: 24px 16px; display: flex; flex-direction: column; gap: 28px; }
.side .brand { padding: 0 8px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a { font-size: 15px; font-weight: 500; color: var(--muted); text-decoration: none; padding: 11px 14px; border-radius: 12px; }
.side-nav a:hover { background: var(--bg); color: var(--text); }
.side-nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .who { margin-top: auto; background: var(--bg); border-radius: var(--r-inner); padding: 14px 16px; box-shadow: var(--shadow-card); }
.side .who b { display: block; font-size: 14px; font-weight: 600; }
.side .who span { font-size: 13px; color: var(--muted); }
.content { flex-grow: 1; min-width: 0; padding: 28px 36px 48px; display: flex; flex-direction: column; gap: 20px; }
.toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

/* ——— вкладки, поиск, фильтры ——— */
.tabs { display: flex; gap: 6px; }
.tab { font-size: 15px; font-weight: 500; color: var(--muted); text-decoration: none; padding: 10px 16px; border-radius: var(--r-pill); }
.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.search { flex-grow: 1; height: 48px; border: none; border-radius: var(--r-pill); background: var(--surface); box-shadow: var(--shadow); padding: 0 22px; font-family: inherit; font-size: 15px; color: var(--text); }
.search::placeholder { color: var(--muted); }
.filter { display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 20px; border: none; border-radius: var(--r-pill); background: var(--surface); box-shadow: var(--shadow); font-family: inherit; font-size: 15px; font-weight: 500; color: var(--text); cursor: pointer; }

/* ——— таблица ——— */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 13px; font-weight: 500; color: var(--muted); padding: 0 16px 14px; }
.tbl td { padding: 16px; border-top: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:hover td { background: var(--bg); }
.tbl tr.hot td { background: var(--err-bg); }
.tbl tr.me td { background: var(--accent-soft); }
.tbl .num { font-weight: 600; }
.tbl .right { text-align: right; }
.tbl tfoot td { border-top: 1px solid var(--line); font-weight: 700; font-size: 15px; }

/* ——— журнал / ход работы ——— */
.timeline { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 20px; }
.timeline li { position: relative; padding-left: 26px; }
.timeline li::before { content: ""; position: absolute; left: 0; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.timeline li.wait::before { background: var(--bg); box-shadow: inset 0 0 0 2px #C7CCD6; }
.timeline li.now::before { background: var(--warn-fg); }
.timeline .t { font-size: 15px; font-weight: 600; line-height: 1.35; }
.timeline .d { font-size: 13px; color: var(--muted); line-height: 1.5; }
.timeline .say { margin-top: 8px; background: var(--bg); border-radius: 12px; padding: 12px 14px; font-size: 13px; line-height: 1.5; }

/* ——— фотоплейсхолдеры ——— */
.slots { display: flex; gap: 12px; flex-wrap: wrap; }
.slot { width: 128px; height: 96px; border-radius: var(--r-inner); background: var(--bg); box-shadow: inset 0 0 0 1.5px var(--line); display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; color: var(--muted); padding: 8px; }
.slot.add { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px #CFD6F5; color: var(--accent); font-weight: 600; flex-direction: column; gap: 4px; }

/* ——— телефон исполнителя ——— */
.phone-page { min-height: 100vh; background: #EDEFF5; display: flex; align-items: center; justify-content: center; padding: 24px; }
.phone { width: 390px; height: 844px; background: var(--bg); border-radius: 32px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 18px 50px rgba(23,32,74,0.16); }
.phone-head { background: var(--surface); padding: 20px 20px 18px; display: flex; flex-direction: column; gap: 16px; flex-shrink: 0; }
.phone-body { flex-grow: 1; overflow: hidden; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.phone-foot { padding: 12px 16px 20px; display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.chips { display: flex; gap: 8px; }
.chip { font-size: 13px; font-weight: 600; color: var(--muted); background: var(--bg); border-radius: var(--r-pill); padding: 8px 14px; }
.chip.on { background: var(--accent); color: #FFF; }
.task { background: var(--surface); border-radius: var(--r-inner); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.task .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.task .t { font-size: 16px; font-weight: 600; line-height: 1.3; }
.tbl .nw { white-space: nowrap; }
.row.even { align-items: stretch; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* карточка заявки в списке */
.ticket { background: var(--surface); border-radius: var(--r-inner); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.ticket.on { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px #CFD6F5; }
.ticket .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ticket .no { font-size: 13px; font-weight: 600; color: var(--muted); }
.ticket .t { font-size: 15px; font-weight: 600; line-height: 1.35; }

/* ——— подсказка у заголовка блока ——— */
.titled { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hint {
  display: inline-flex; align-items: center; justify-content: center;
  width: 19px; height: 19px; flex-shrink: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--muted);
  font-size: 12px; font-weight: 700; font-style: normal; line-height: 1;
  cursor: help; position: relative;
}
.hint:hover, .hint:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.hint::after {
  content: attr(data-hint);
  position: absolute; left: 50%; top: calc(100% + 10px); transform: translateX(-50%);
  width: 300px; max-width: 70vw;
  background: var(--text); color: var(--bg);
  font-size: 13px; font-weight: 400; line-height: 1.5; text-align: left;
  padding: 11px 14px; border-radius: 12px;
  opacity: 0; visibility: hidden; pointer-events: none; z-index: 30;
  transition: opacity 0.12s ease;
  box-shadow: 0 8px 28px rgba(23,32,74,0.18);
}
.hint::before {
  content: ""; position: absolute; left: 50%; top: calc(100% + 4px);
  transform: translateX(-50%); border: 6px solid transparent;
  border-bottom-color: var(--text);
  opacity: 0; visibility: hidden; z-index: 30; transition: opacity 0.12s ease;
}
.hint:hover::after, .hint:focus-visible::after,
.hint:hover::before, .hint:focus-visible::before { opacity: 1; visibility: visible; }
/* у правого края всплывающая подсказка ушла бы за экран */
.hint.left::after { left: auto; right: -8px; transform: none; }
.hint.left::before { left: auto; right: 4px; transform: none; }
@media (prefers-reduced-motion: reduce) { .hint::after, .hint::before { transition: none; } }

/* ─────────────────────────── телефон и планшет ───────────────────────────
   Жильцы заходят с телефона, поэтому это не украшение, а рабочий режим.
   ponytail: ширины блоков заданы инлайном в шаблонах, поэтому здесь !important —
   переписывать полсотни шаблонов ради трёх правил не стоит.
*/
@media (max-width: 900px) {
  /* кабинет жильца */
  .shell { min-height: 100dvh; }
  .header { height: auto; flex-wrap: wrap; padding: 14px 16px; gap: 10px; }
  .brand .name { font-size: 14px; }
  .nav {
    order: 5; width: 100%; flex-wrap: nowrap; overflow-x: auto; gap: 2px;
    padding-bottom: 2px; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; font-size: 14px; padding: 8px 12px; }
  .select, .icon-btn { height: 42px; }
  .icon-btn { width: 42px; }
  .main { padding: 6px 16px 40px; gap: 16px; }

  /* панель управления: боковое меню становится верхней лентой */
  .layout { flex-direction: column; }
  .side {
    width: 100%; flex-direction: row; align-items: center; gap: 14px;
    padding: 12px 16px; overflow-x: auto; scrollbar-width: none;
    /* без min-width флекс-элемент не даёт себя сжать, и вся страница
       становится шире экрана вместо того, чтобы прокручиваться меню */
    min-width: 0;
  }
  .layout > *, .content, .main, .row > *, .col > * { min-width: 0; }
  /* ponytail: страницу режем по ширине экрана, прокрутка остаётся внутри
     меню и таблиц. Точечно ловить каждый вылезающий блок дороже, чем польза */
  .layout, .shell { max-width: 100vw; overflow-x: hidden; }
  .side::-webkit-scrollbar { display: none; }
  .side .brand { flex-shrink: 0; }
  .side-nav { flex-direction: row; gap: 4px; }
  .side-nav a { white-space: nowrap; padding: 9px 14px; font-size: 14px; }
  .side .who { margin-top: 0; flex-shrink: 0; padding: 10px 14px; }
  .content { padding: 18px 16px 40px; }

  /* колонки складываются в одну */
  .row, .col { flex-direction: column; }
  .row > *, .col > * { width: 100% !important; max-width: 100% !important; }
  .row.even { align-items: stretch; }

  /* заголовки и суммы соразмерно экрану */
  .page-head { gap: 6px; }
  .page-head h1 { font-size: 24px; }
  .toolbar h1 { font-size: 24px !important; }
  .amount { font-size: 34px; }
  .stat { font-size: 22px; }
  .block { padding: 18px; border-radius: 16px; }
  .block-head { flex-wrap: wrap; gap: 8px; }

  /* таблицы прокручиваются внутри себя, а не растягивают страницу */
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex-shrink: 0; }
  .tbl { display: block; overflow-x: auto; white-space: nowrap; }
  .tbl td, .tbl th { padding: 12px 10px; }

  /* подсказка не должна вылезать за край экрана */
  .hint::after { width: 260px; max-width: 78vw; }

  /* кнопки в столбик на всю ширину */
  .btn { width: 100%; }
  .toolbar > div:last-child { width: 100%; display: flex; flex-direction: column; gap: 8px; }
}

@media (max-width: 520px) {
  .brand .sub { display: none; }
  .page-head .where { font-size: 13px; }
  .amount { font-size: 30px; }
  .slot { width: 100% !important; }
}

/* ——— периоды с раскрытием: детализация открывается на месте, а не уводит ——— */
.шапка-периода,
.период > summary {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) repeat(4, minmax(90px, 140px));
  gap: 12px;
  align-items: center;
}
.шапка-периода { padding: 0 44px 12px 16px; font-size: 13px; }
.период { border-top: 1px solid var(--line); }
.период > summary {
  padding: 16px 16px 16px 40px;
  cursor: pointer;
  list-style: none;
  position: relative;
  font-size: 14px;
}
.период > summary::-webkit-details-marker { display: none; }
.период > summary::before {
  content: "›";
  position: absolute;
  left: 16px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  transition: transform 0.15s ease;
}
.период[open] > summary::before { transform: rotate(90deg); }
.период > summary:hover { background: var(--bg); }
.период > summary .месяц { font-weight: 600; }
.период[open] > summary { background: var(--accent-soft); }

@media (max-width: 900px) {
  .шапка-периода { display: none; }
  .период > summary {
    grid-template-columns: 1fr auto;
    row-gap: 4px;
    padding-left: 34px;
  }
  .период > summary .месяц { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .период > summary::before { transition: none; }
}
