/* PWA «Главный инженер» — оформление в цветах Android-приложения.
   Телефон в приоритете: нижняя панель вкладок, safe-area для iPhone,
   крупные кнопки под палец. На широком экране контент центрируется. */

:root {
  --navy: #0D3B66;
  --dark: #051A32;
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --text: #1A2532;
  --muted: #6B7A90;
  --hint: #9AA7B8;
  --accent: #E8A33D;
  --clause: #2F5F8F;
  --divider: #D7DEE8;
  --chapter: #EEF3F9;
  --ok: #2E7D32;
  --warn: #EF6C00;
  --err: #C62828;
  --shadow: 0 1px 4px rgba(5, 26, 50, .08);
  --radius: 12px;
  --tabbar: 58px;
  --header: 52px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: fixed;          /* iOS: без «резинового» прокручивания всей страницы */
  inset: 0;
  font-size: 15px;
  line-height: 1.35;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--clause); }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- Шапка ---------- */
#top {
  flex: none;
  background: var(--navy);
  color: #fff;
  padding: calc(var(--sat) + 8px) 8px 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: calc(var(--header) + var(--sat));
}
#top .title { font-weight: 700; font-size: 19px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .back { width: 40px; height: 40px; margin-left: -8px; color: #fff; font-size: 26px; line-height: 1; display: none; align-items: center; justify-content: center; }
#top.has-back .back { display: flex; }
#balance {
  background: rgba(255, 255, 255, .16);
  padding: 6px 12px;
  border-radius: 16px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
#balance:active { background: rgba(255, 255, 255, .28); }
#more { width: 40px; height: 40px; color: #fff; font-size: 22px; border-radius: 20px; }
#more:active { background: rgba(255, 255, 255, .2); }

/* ---------- Вкладки ---------- */
main { flex: 1; position: relative; overflow: hidden; }
.tab { position: absolute; inset: 0; display: none; flex-direction: column; }
.tab.active { display: flex; }
.pane {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 12px calc(12px + 8px);
}
.wide { max-width: 760px; margin: 0 auto; width: 100%; }

/* Подэкран поверх вкладки (как Activity поверх фрагмента) */
.screen {
  position: absolute; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } }

/* ---------- Нижняя панель ---------- */
#tabbar {
  flex: none;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--divider);
  padding-bottom: var(--sab);
  height: calc(var(--tabbar) + var(--sab));
}
#tabbar button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  padding-top: 6px;
}
#tabbar button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabbar button.active { color: var(--navy); font-weight: 600; }
#tabbar button .dot {
  position: relative;
}
#tabbar button .badge {
  position: absolute; top: -4px; right: -10px;
  background: var(--err); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Базовые элементы ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card.pressable:active { background: #F5F7FA; }
.card h3 { color: var(--navy); font-size: 16px; margin-bottom: 4px; }
.card p { color: var(--muted); font-size: 14px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  background: var(--navy);
  color: #fff;
  width: 100%;
  text-decoration: none;
}
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .45; }
.btn.outline { background: var(--surface); color: var(--navy); border: 1.5px solid var(--navy); font-weight: 600; }
.btn.text { background: none; color: var(--navy); min-height: 40px; width: auto; }
.btn.danger { background: var(--err); }
.btn.accent { background: var(--accent); color: var(--dark); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 13px; width: auto; }
.btn.big { min-height: 60px; font-size: 17px; }
.btn.tall { min-height: 72px; font-size: 17px; flex-direction: column; gap: 2px; }
.btn .hint { font-weight: 400; font-size: 12px; opacity: .85; }
.row-btns { display: flex; gap: 8px; margin-top: 8px; }
.row-btns .btn { flex: 1; width: auto; padding-left: 8px; padding-right: 8px; }

.input, textarea.input {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  border: 1px solid #C4CEDB;
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px;               /* 16px — iOS не зумит поле при фокусе */
}
textarea.input { resize: none; line-height: 1.35; }
.input:focus, textarea.input:focus { outline: none; border-color: var(--navy); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input-row { display: flex; gap: 6px; align-items: center; }
.input-row .input { flex: 1; }
.iconbtn {
  width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 22px; color: var(--navy); font-size: 22px;
}
.iconbtn:active { background: rgba(13, 59, 102, .1); }
.iconbtn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.hint { font-size: 13px; color: var(--muted); }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.divider { height: 1px; background: var(--divider); margin: 14px 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; line-height: 1.45; }
.section-title { font-weight: 700; color: var(--navy); margin: 16px 0 8px; font-size: 15px; }
.chip { display: inline-block; background: var(--chapter); color: var(--navy); border-radius: 14px; padding: 4px 10px; font-size: 13px; margin: 2px 4px 2px 0; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-warn { color: var(--warn); font-weight: 600; }
.status-err { color: var(--err); font-weight: 600; }
.status-muted { color: var(--muted); }

.toolbar {
  flex: none;
  display: flex; gap: 8px; align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
}
.toolbar .title { font-weight: 700; color: var(--navy); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bottombar {
  flex: none;
  background: var(--surface);
  border-top: 1px solid var(--divider);
  padding: 10px 12px;
  display: flex; gap: 8px; align-items: center;
}
.bottombar .btn { flex: 1; width: auto; }

/* ---------- Свайп-строки (проверки, замечания) ---------- */
.swipe { position: relative; overflow: hidden; border-radius: var(--radius); margin-bottom: 10px; }
.swipe .under {
  position: absolute; top: 0; bottom: 0; width: 76px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 26px;
}
.swipe .under.left { left: 0; background: var(--navy); }
.swipe .under.right { right: 0; background: var(--err); }
.swipe .fg {
  position: relative;
  background: var(--surface);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  touch-action: pan-y;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;   /* долгое нажатие — наше, а не меню iOS */
}
.swipe .fg.anim { transition: transform .15s ease-out; }
.swipe .fg h4 { font-size: 15px; margin-bottom: 4px; color: var(--text); }
.swipe .fg .cl { color: var(--clause); font-size: 13px; }
.swipe .fg .meta { font-size: 13px; margin-top: 4px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.swipe .fg .marks { color: var(--muted); font-size: 13px; }

/* ---------- Диалоги ---------- */
dialog { border: 0; padding: 0; background: transparent; max-width: none; max-height: none; color: var(--text); }
dialog::backdrop { background: rgba(5, 26, 50, .45); }
dialog.modal { margin: auto; width: min(92vw, 420px); }
dialog.modal .box { background: var(--surface); border-radius: 16px; padding: 20px 20px 12px; max-height: 84vh; display: flex; flex-direction: column; }
dialog .box h2 { font-size: 18px; color: var(--navy); margin-bottom: 8px; }
dialog .box .msg { color: var(--text); font-size: 15px; white-space: pre-wrap; overflow-y: auto; }
dialog .box .acts { display: flex; justify-content: flex-end; gap: 4px; margin-top: 14px; flex-wrap: wrap; }
dialog .box .acts .btn { width: auto; min-height: 42px; padding: 8px 14px; }
dialog.sheet { margin: auto 0 0 0; width: 100vw; }
dialog.sheet .box {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 12px 8px calc(12px + var(--sab));
  max-height: 86vh; overflow-y: auto;
}
dialog.sheet .box h2 { padding: 6px 12px 10px; }
.menu-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 14px 12px; border-radius: 10px; font-size: 16px;
}
.menu-item:active { background: var(--bg); }
.menu-item .ic { width: 28px; text-align: center; font-size: 20px; flex: none; }
.menu-item.danger { color: var(--err); }
.menu-item:disabled { opacity: .4; }
.menu-item .sub { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.check-item { display: flex; align-items: center; gap: 12px; padding: 12px; font-size: 16px; }
.check-item input { width: 22px; height: 22px; accent-color: var(--navy); }
dialog.full { margin: 0; width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; background: #000; }
dialog.full::backdrop { background: #000; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  border: 3px solid rgba(13, 59, 102, .18); border-top-color: var(--navy);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-line { display: flex; align-items: center; gap: 12px; padding: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--sab) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(26, 37, 50, .94); color: #fff;
  padding: 10px 18px; border-radius: 22px; font-size: 14px;
  /* width: max-content — иначе у fixed-элемента с left:50% ширина ограничена
     правой половиной экрана и текст ломается на строки раньше времени */
  width: max-content; max-width: 88vw; text-align: center;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50;
}
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.on.act { pointer-events: auto; }
/* Кнопка действия в тосте («Сохранено в заметки — Открыть»), как у Snackbar */
#toast .toast-act { background: none; border: 0; color: #FFC02E; font: inherit; font-weight: 700; margin-left: 14px; padding: 0; cursor: pointer; }

/* Просмотр фото: горизонтальный пейджер */
.pager { display: flex; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
.pager .page { flex: none; width: 100vw; height: 100%; scroll-snap-align: center; display: flex; align-items: center; justify-content: center; overflow: auto; }
.pager img { max-width: 100vw; max-height: 100vh; object-fit: contain; transition: transform .15s; }
.pager-bar { position: fixed; top: calc(var(--sat) + 8px); left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 12px; color: #fff; z-index: 2; }
.pager-bar button { color: #fff; font-size: 28px; width: 44px; height: 44px; }
.pager-bar .count { font-size: 14px; background: rgba(0, 0, 0, .5); padding: 4px 10px; border-radius: 12px; }

/* Миниатюры фото */
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; background: #DDE3EA; }
.thumbs .add { width: 84px; height: 84px; border-radius: 8px; border: 1.5px dashed #C4CEDB; display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--muted); }

/* Чат */
.msg { max-width: 88%; padding: 11px 14px; border-radius: 14px; margin-bottom: 10px; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; line-height: 1.4; }
.msg.user { background: var(--navy); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.msg.bot { background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 4px; }
.msg.info { background: none; color: var(--muted); font-size: 13px; text-align: center; max-width: 100%; }
.msg img { max-height: 200px; border-radius: 8px; display: block; margin-bottom: 6px; }
.msg a.cl { color: inherit; text-decoration: underline; font-weight: 600; }
/* Таблицы из пунктов в ответах ассистента и заметках — как в читалке документов */
table.rt { display: block; overflow-x: auto; max-width: 100%; white-space: normal; border-collapse: collapse; margin: 6px 0; -webkit-overflow-scrolling: touch; }
table.rt th, table.rt td { max-width: 240px; padding: 5px; font-size: 13px; border: 1px solid #C9D4E2; text-align: left; vertical-align: top; }
table.rt th { background: #EEF3F9; font-weight: 700; }
.msg.bot a.cl { color: var(--navy); }
.suggestion {
  display: block; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--divider); border-radius: 12px;
  padding: 12px 14px; margin-top: 8px; font-size: 15px; color: var(--text);
}
.suggestion:active { background: var(--chapter); }

/* Документы/читалка */
.clause { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #E6EBF2; font-size: 14px; }
.clause .num { color: var(--clause); font-weight: 700; min-width: 60px; flex: none; }
.clause .txt { white-space: pre-line; min-width: 0; flex: 1; }
.clause table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; white-space: normal; }
.clause th, .clause td { border: 1px solid #C9D4E2; padding: 4px 8px; text-align: left; vertical-align: top; min-width: 52px; }
.clause th { background: var(--chapter); font-weight: 600; color: var(--navy); }
.clause img.climg { display: inline-block; max-width: 100%; margin: 6px 4px; padding: 5px; background: #fff; border: 1px solid #E3E9F1; border-radius: 8px; vertical-align: middle; }
.clause mark { background: #FFE8A0; }
.clause mark.cur { background: #F5A623; font-weight: 700; }
.clause.hl { background: #FFF7DF; }
.chapter { font-weight: 700; color: var(--navy); margin: 16px 0 6px; font-size: 15px; }
.star { font-size: 24px; color: #C4CEDB; padding: 4px; line-height: 1; flex: none; }
.star.on { color: var(--accent); }

/* Тренажёр */
.opt { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid #C4CEDB; border-radius: 10px; padding: 12px 14px; font-size: 15px; margin-bottom: 8px; color: var(--text); }
.opt.right { background: #C8E6C9; border-color: var(--ok); }
.opt.wrong { background: #FFCDD2; border-color: var(--err); }
.opt.picked { border-color: var(--navy); border-width: 2px; }
.explain { background: var(--surface); border-radius: 12px; padding: 14px 16px; margin-top: 10px; font-size: 14px; box-shadow: var(--shadow); white-space: pre-wrap; }
.timer { font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; font-size: 16px; }
.timer.low { color: var(--err); }

/* Шарик ИИ */
ai-orb { display: inline-block; width: 48px; height: 48px; vertical-align: middle; }
ai-orb.big { width: 104px; height: 104px; }
ai-orb.small { width: 38px; height: 38px; }
.orb-btn { position: relative; flex: 1; }
.orb-btn ai-orb { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); }
.orb-btn .btn { display: flex; width: 100%; padding-right: 62px; justify-content: flex-start; }

/* Полоска «Установить приложение» под шапкой и пошаговая подсказка */
#installBar { flex: none; display: flex; align-items: center; background: var(--dark); color: #fff; padding-right: 4px; }
#installBar [data-go] { flex: 1; text-align: left; color: #fff; font-weight: 600; font-size: 14px; padding: 11px 16px; }
#installBar [data-x] { color: #fff; width: 40px; height: 40px; font-size: 18px; opacity: .8; }
.install-sheet h2 { font-size: 19px; }
.install-sheet .hint { padding: 0 12px 6px; font-size: 14px; line-height: 1.4; }
.install-sheet ol { list-style: none; padding: 4px 12px 0; }
.install-sheet li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; font-size: 15px; line-height: 1.4; border-top: 1px solid var(--divider); }
.install-sheet li .n { flex: none; width: 28px; height: 28px; border-radius: 14px; background: var(--navy); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.install-sheet svg { width: 22px; height: 22px; vertical-align: -5px; fill: none; stroke: var(--navy); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin: 0 2px; }
.install-sheet .btn { margin: 12px 12px 0; width: calc(100% - 24px); }

/* Широкий экран: контент по центру, как планшет */
@media (min-width: 800px) {
  .pane { padding-left: max(12px, calc((100vw - 760px) / 2)); padding-right: max(12px, calc((100vw - 760px) / 2)); }
  .toolbar, .bottombar { padding-left: max(12px, calc((100vw - 760px) / 2)); padding-right: max(12px, calc((100vw - 760px) / 2)); }
  dialog.sheet { margin: auto; width: 480px; }
  dialog.sheet .box { border-radius: 16px; }
  .pager .page { width: 100%; }
}
