:root {
  --bg: #111318;
  --card: #181c23;
  --line: #262c36;
  --border: #262c36;
  --text: #e9edf3;
  --muted: #93a0b3;
  --accent: #ff7a1a;
  --accent-soft: rgba(255, 122, 26, .12);
  --ok: #37c07a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  padding: max(12px, env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom));
}

.wrap { max-width: 560px; margin: 0 auto; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 14px;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.brand::before { content: "▮ "; color: var(--accent); }

h1 { font-size: 22px; margin: 6px 0 8px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 14px;
}

input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 13px 14px;
  font-size: 17px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

button { font: inherit; }

.primary {
  width: 100%;
  padding: 15px;
  margin: 6px 0 10px;
  font-size: 17px;
  font-weight: 600;
  color: #12140f;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
}
.primary:disabled { opacity: .5; }

.link {
  background: none; border: 0; color: var(--muted);
  font-size: 14px; padding: 8px 2px;
}

.note { color: var(--muted); font-size: 13px; margin-top: 10px; }
.hidden { display: none !important; }

.toast {
  position: fixed;
  z-index: 90;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: #232833;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 90vw;
}
.toast.err { border-color: #7a2b2b; background: #2a1a1a; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin: 0 0 14px;
}
.row { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; padding: 4px 0; }
.row span:last-child { font-weight: 600; }
.muted { color: var(--muted); }

.tip {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
  opacity: .85;
}

.group {
  margin: 18px 0 10px;
  font-size: 13px;
  letter-spacing: .3px;
  text-transform: uppercase;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 18px;
}
.tab {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}
.tab.active {
  color: var(--fg, #fff);
  border-color: var(--accent);
}

.card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin: 0 0 14px;
}

.list { display: grid; gap: 10px; margin-bottom: 14px; }

.list-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.list-item .li-main { min-width: 0; }
.list-item .li-title { font-size: 15px; margin-bottom: 4px; }
.list-item .li-sub { font-size: 13px; color: var(--muted); }
.list-item .li-sum { white-space: nowrap; font-variant-numeric: tabular-nums; }

.li-right { display: flex; align-items: center; gap: 10px; }
.li-del {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 30px; height: 30px;
  font-size: 18px; line-height: 1;
  padding: 0;
}

.row { display: flex; gap: 10px; }
.half { flex: 1; }

.total { background: rgba(255,255,255,.03); }
.total-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 4px 0; font-size: 15px; font-variant-numeric: tabular-nums;
}
.total-row b { font-size: 17px; }

.empty {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.chips { display: flex; gap: 8px; margin: 4px 0 16px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
}
.chip.active { color: var(--fg, #fff); border-color: var(--accent); }

.secondary {
  width: 100%;
  margin-top: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: inherit;
  font-size: 15px;
}

.photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
.photo-item { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.photo-item img { width: 100%; height: 96px; object-fit: cover; display: block; }
.photo-del {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; padding: 0;
  border-radius: 8px; border: 0;
  background: rgba(0,0,0,.55); color: #fff; font-size: 16px; line-height: 1;
}

.contacts { display: flex; gap: 8px; margin: 2px 0 14px; flex-wrap: wrap; }
.contacts .chip { text-decoration: none; display: inline-flex; align-items: center; }

.li-ok {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 32px; height: 32px;
  margin-right: 6px;
  font-size: 15px;
}
.note-overdue .li-sub { color: #e06a6a; }
.note-today .li-sub { color: #e0a33a; }
.note-soon .li-sub { color: var(--accent); }
.note-done .li-title { text-decoration: line-through; opacity: .6; }

.progress { height: 10px; background: rgba(255,255,255,.08); border-radius: 999px; margin: 10px 0 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .3s; }
.progress-fill.done { background: #4caf7d; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat b { font-size: 18px; }
.chart { display: flex; gap: 6px; align-items: flex-end; height: 140px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart-pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart-bar { width: 45%; max-width: 12px; border-radius: 3px 3px 0 0; }
.chart-bar.income { background: #4a7bd0; }
.chart-bar.net { background: var(--accent); }
.chart-label { font-size: 10px; color: var(--muted); margin-top: 4px; }

.toast-action {
  margin-left: 10px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
}

.offline-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #5a3a12;
  color: #ffd9a8;
  border-bottom: 1px solid #8a5a1c;
  padding: 8px 12px;
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.offline-banner .link { color: #ffd9a8; text-decoration: underline; }

/* === v29: меню, сворачиваемые разделы, смета сверху === */

/* Меню в шапке: на телефоне вместо полосы вкладок */
.menu-toggle {
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 6px 2px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.menu-toggle .caret { color: var(--accent); font-size: 13px; }
.desktop-brand { display: none; }

.menu {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 52px;
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
  display: flex;
  flex-direction: column;
}
.menu.hidden { display: none; }
.menu-item {
  background: none;
  border: 0;
  color: var(--text);
  text-align: left;
  font: inherit;
  padding: 13px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.menu-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.menu-item + .menu-item { margin-top: 2px; }

/* На телефоне полоса вкладок скрыта, её заменяет меню */
#tabs { display: none; }

/* На широком экране - обычные вкладки, меню убираем */
@media (min-width: 720px) {
  .menu-toggle, .menu { display: none !important; }
  .desktop-brand { display: block; }
  #tabs { display: flex; }
}

/* Экран объекта: липкая шапка с назад, названием и статусом */
.obj-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  margin: 0 0 8px;
  background: linear-gradient(var(--bg) 78%, rgba(17, 19, 24, .85));
  backdrop-filter: blur(6px);
}
.icon-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
.obj-bar-main { min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.obj-bar-title {
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 62vw;
}
.chip.small { padding: 4px 10px; font-size: 12px; }
.chip.small.due { border-color: #e0563f; color: #ff8a74; }

/* Быстрые кнопки под сметой */
.quick-add { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 16px; }
.quick-add .secondary {
  flex: 1 1 calc(50% - 4px);
  width: auto;
  margin: 0;
  padding: 9px 10px;
  font-size: 14px;
  min-width: 120px;
}

/* Сворачиваемые разделы объекта */
details.sec {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}
details.sec > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 12px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before {
  content: "▸";
  color: var(--accent);
  margin-right: 8px;
  transition: transform .15s ease;
}
details.sec[open] > summary::before { transform: rotate(90deg); }
details.sec > summary { justify-content: flex-start; }
details.sec .sec-sum { margin-left: auto; color: var(--text); font-weight: 600; letter-spacing: 0; text-transform: none; }
details.sec > .list,
details.sec > .card,
details.sec > .photos,
details.sec > .row { margin: 0 14px 12px; }
details.sec > .card { background: transparent; border: 0; padding: 0; }

/* Группы заказчиков в списке объектов */
details.cust {
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}
details.cust > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
details.cust > summary::-webkit-details-marker { display: none; }
details.cust > summary::before { content: "▸"; color: var(--accent); }
details.cust[open] > summary::before { content: "▾"; }
.cust-name { font-weight: 600; }
.cust-meta { margin-left: auto; color: var(--muted); font-size: 13px; }
.cust-body { padding: 0 6px 8px; }
.cust-body .list-item { background: transparent; border: 0; border-top: 1px solid var(--line); border-radius: 0; }

/* Смета: разделители и акценты только на двух числах */
.divider { height: 1px; background: var(--line); margin: 10px 0; }
.total-row.strong b { font-size: 18px; }
.sum-ok { color: var(--ok); }
.sum-due { color: #ff8a74; }

/* Подсказки полей ввода (свой список вместо datalist: WebView не подставляет выбор) */
.ac-box {
  margin: -8px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.ac-box.hidden { display: none; }
.ac-item {
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 12px 14px;
  cursor: pointer;
}
.ac-item:last-child { border-bottom: 0; }
.ac-item.active, .ac-item:active { background: var(--accent-soft); color: var(--accent); }

/* Видео объекта и форма обратной связи */
textarea {
  width: 100%;
  margin-top: 6px;
  padding: 13px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  resize: vertical;
}
.video-item {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #0d0f13;
}
.video-item video { display: block; width: 100%; max-height: 60vh; background: #000; }
.video-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}

/* Скрытые input[type=file] не должны рисоваться: глобальное правило input перебивает [hidden] */
[hidden], input[hidden] { display: none !important; }

/* Маркер статуса в списке объектов */
.li-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; min-width: 0; }
.li-title-row .li-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.li-status {
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 20px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.li-status.st-work { color: #ffb27a; border-color: #7a4a1e; background: rgba(255, 122, 26, .10); }
.li-status.st-done { color: #8fc4ff; border-color: #2b4a6b; background: rgba(90, 160, 255, .10); }
.li-status.st-paid { color: #6fdc9c; border-color: #2c5f43; background: rgba(55, 192, 122, .10); }

/* Заказчик как ссылка в карточке объекта */
.link-client { color: #ffb27a; text-decoration: underline; cursor: pointer; }
.cl-select { width: 100%; margin-top: 6px; padding: 13px 14px; font: inherit; font-size: 16px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 12px; }

/* Скидка и наценка в смете */
.pct-row { display: flex; gap: 10px; margin: 8px 0 4px; }
.pct-row label { flex: 1; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.pct-row input { width: 100%; padding: 10px 12px; font: inherit; font-size: 15px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.total-row.dim b { color: var(--muted); font-weight: 500; }

/* Выбор шаблона сметы */
.tpl-item { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font: inherit; }
.tpl-item b { font-size: 15px; }
.tpl-item span { font-size: 12px; color: var(--muted); }

.total-row[hidden] { display: none !important; }

/* Выгрузка сметы в CSV на телефоне */
.csv-box { position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 60; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.csv-box textarea { width: 100%; height: 160px; font: 12px/1.4 ui-monospace, Consolas, monospace; color: var(--text); background: #0f1115; border: 1px solid var(--line); border-radius: 10px; padding: 8px; resize: vertical; }
.csv-box .row { display: flex; gap: 8px; margin-top: 8px; }
.csv-box a.secondary { flex: 1; display: flex; align-items: center; justify-content: center; text-decoration: none; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); color: var(--text); font: inherit; font-size: 14px; }

.plan-note {
  margin: -4px 0 12px;
  font-size: 13px;
  color: var(--muted, #8b8b8b);
}
.plan-note.warn {
  color: #d08a3f;
  padding: 8px 10px;
  border: 1px solid rgba(208, 138, 63, 0.35);
  border-radius: 8px;
  background: rgba(208, 138, 63, 0.08);
}
