:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --line: #dfe4ea;
  --accent: #1f4e79;
  --accent-2: #2f6fa8;
  --accent-soft: #e6eef7;
  --ok: #1e7a46;
  --warn: #b25b00;
  --danger: #b3261e;
  --input: #ffffff;
  --radius: 10px;
  --brand: #1f4e79;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --card: #1b2129; --text: #e6eaef; --muted: #9aa5b3; --line: #2c3540;
    --accent: #6fa8dc; --accent-2: #8bbbe6; --accent-soft: #1f2d3c; --input: #141a21;
    --ok: #5cc28a; --warn: #f0a24a; --danger: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --card: #1b2129; --text: #e6eaef; --muted: #9aa5b3; --line: #2c3540;
  --accent: #6fa8dc; --accent-2: #8bbbe6; --accent-soft: #1f2d3c; --input: #141a21;
  --ok: #5cc28a; --warn: #f0a24a; --danger: #ff8a80;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 720px; }

/* Верхняя панель кабинета */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: #fff;
}
.top .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.top .brand { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .spacer { flex: 1; }
.top select { max-width: 180px; }
.top button { background: rgba(255,255,255,.15); color: #fff; border-color: transparent; }
.nav { background: var(--card); border-bottom: 1px solid var(--line); }
.nav .wrap { display: flex; gap: 4px; overflow-x: auto; padding-top: 6px; padding-bottom: 6px; scrollbar-width: none; }
.nav a {
  text-decoration: none; color: var(--text); padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f > span { font-weight: 500; }
label.chk { display: flex; gap: 8px; align-items: center; cursor: pointer; }
input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--input);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
input[type="checkbox"] { min-height: 0; width: 18px; height: 18px; accent-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
button { cursor: pointer; background: var(--card); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; }
button:disabled { opacity: .55; cursor: default; }

/* Таблицы */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.total td { font-weight: 700; border-bottom: 0; font-size: 16px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }
table.edit input, table.edit select { width: 100%; min-width: 70px; padding: 6px 8px; min-height: 34px; }
table.edit td { padding: 4px; }
table.edit input.w-s { min-width: 60px; }
table.edit input.w-l { min-width: 260px; }

.total-big { font-size: 26px; font-weight: 700; color: var(--accent); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: var(--accent-soft); color: var(--accent); }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.msg { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; background: var(--accent-soft); }
.msg.err { color: var(--danger); }
.stub {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted);
}

/* Открытая часть */
.hero { background: var(--brand); color: #fff; }
.hero .wrap { padding-top: 20px; padding-bottom: 20px; }
.hero h1 { color: #fff; }
.hero a { color: #fff; }

.login { max-width: 380px; margin: 60px auto; }

@media (max-width: 600px) {
  .wrap { padding: 12px 16px; }
  .card { padding: 12px; }
  .total-big { font-size: 22px; }
  .hide-sm { display: none; }
}

/* Не даём длинным спискам и fieldset раздвигать страницу на телефоне */
select { max-width: 100%; }
fieldset { min-width: 0; }
.tbl-wrap { max-width: 100%; }

/* Несколько типов свай в расчёте */
.pile-group { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px dashed var(--line); }
.pile-group:last-of-type { border-bottom: 0; margin-bottom: 0; }

/* Встраивание на сайт: без фона и шапки */
body.embed { background: transparent; }
body.embed .wrap { padding: 0; }
/* Поле-ловушка для ботов */
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* Кнопка-выбор файла (камера / галерея) */
label.btnlike {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-height: 38px; background: var(--card);
}
label.btnlike:active { background: var(--accent-soft); }

/* Плитки анализа */
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 16px; }
.tile { margin-bottom: 0; }
.tile .tv { font-size: 22px; font-weight: 700; margin: 4px 0; }

/* Панель действий вверху страницы: «Сохранить» и др. — закреплена под шапкой при прокрутке */
.actionbar {
  position: sticky; top: var(--top-h, 60px); z-index: 6;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--bg); padding: 8px 0 10px; margin-bottom: 8px; border-bottom: 1px solid var(--line);
}

/* ---------- Телефоны (iPhone, Android) ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, label.btnlike, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* Вырез экрана и полоска «домой» у iPhone: шапка под строкой состояния, отступы по краям */
.top { padding-top: env(safe-area-inset-top); }
body { padding-bottom: env(safe-area-inset-bottom); }
@supports (padding: max(0px)) {
  .wrap { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
}
/* Сенсорный экран: шрифт полей 16px — iPhone не увеличивает страницу при вводе; кнопки под палец */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
  input, select, button, label.btnlike { min-height: 44px; }
  button.link { min-height: 36px; padding: 6px 8px; }
  input[type="checkbox"] { min-height: 0; width: 22px; height: 22px; }
  table.edit input, table.edit select { font-size: 16px; min-height: 40px; }
  .nav a { padding: 10px 14px; }
}
@media (max-width: 600px) {
  h2 { font-size: 17px; }
  th, td { padding: 6px; }
  /* панель действий — одной строкой, листается вбок: не занимает пол-экрана */
  .actionbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 6px 0; }
  .actionbar button { flex: 0 0 auto; min-height: 40px; padding: 6px 12px; }
}

/* План свайного поля у прораба */
.plan-img { display: block; max-width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
/* Аванс и остаток на руках */
table.settle td { vertical-align: top; }
table.settle td.num { width: 1%; padding-left: 12px; }
a.btnlike {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-height: 38px; background: var(--card);
}
