:root {
  --bg: #f3f6f9; --card: #fff; --text: #1d2733; --muted: #657285; --line: #d9e0e8;
  --primary: #1f5fa8; --primary-dark: #174a86; --ok: #1c7c3c; --ok-bg: #e2f4e8;
  --bad: #b3261e; --bad-bg: #fde8e6; --warn-bg: #fff4d6; --top: #1f3a56;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); }
h1 { font-size: 1.4rem; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }

.topbar {
  background: var(--top); color: #fff; display: flex; flex-wrap: wrap; gap: .5rem 1rem;
  align-items: center; justify-content: space-between;
  padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
}
.topbar a, .topbar .linklike { color: #fff; }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.nav { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.inline { display: inline; margin: 0; }
.linklike { background: none; border: 0; padding: .5rem 0; font: inherit; text-decoration: underline; cursor: pointer; color: var(--primary); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 440px; margin: 2rem auto; }
.card.empty { text-align: center; color: var(--muted); }
.page-head { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.page-head h1 { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.hint { color: var(--muted); font-size: .85rem; }

/* кнопки: минимум 44 px для нажатия пальцем */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #eef3f8; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--bad); border-color: #e9b8b4; }
.btn-small { min-height: 44px; padding: .3rem .8rem; font-size: .92rem; }
.btn-block { width: 100%; margin-top: 1rem; }
.btn[disabled] { opacity: .6; cursor: default; }

/* формы */
.form label { display: block; font-weight: 600; margin: .9rem 0 .3rem; }
.form input[type=text], .form input[type=password], .form input[type=date], .form input[type=search],
.form textarea, .form select, .filter-grid input, .filter-grid select {
  width: 100%; min-height: 46px; padding: .6rem .75rem; font: inherit; /* 16px — iOS не увеличивает масштаб */
  border: 1px solid #b9c4d0; border-radius: 10px; background: #fff; color: var(--text);
}
.form input:focus, .form textarea:focus, .filter-grid input:focus, .filter-grid select:focus { outline: 3px solid #9cc3ee; border-color: var(--primary); }
.form fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 1rem 0 0; padding: .6rem .9rem .9rem; }
.form legend { font-weight: 700; padding: 0 .3rem; }
.choice { display: flex !important; align-items: center; gap: .6rem; font-weight: 500 !important; min-height: 44px; margin: .2rem 0 !important; }
.choice input { width: 22px; height: 22px; flex: none; }
.compliance { display: grid; gap: .3rem; }
.field-error { color: var(--bad); font-size: .9rem; margin-top: .25rem; }
.file-list { list-style: none; padding: 0; margin: .8rem 0 .3rem; display: grid; gap: .5rem; }
.file-list li { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line); border-radius: 10px; padding: .4rem; }
.file-list img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }
.file-list .ficon { width: 56px; text-align: center; font-size: 1.8rem; flex: none; }
.file-list .fname { flex: 1; word-break: break-all; font-size: .9rem; }
.progress { position: relative; height: 28px; background: #e3e9f0; border-radius: 8px; overflow: hidden; margin-top: 1rem; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .85rem; font-weight: 600; mix-blend-mode: difference; color: #fff; }

.msg { padding: .7rem .9rem; border-radius: 10px; margin-bottom: .8rem; background: #e7effa; }
.msg-success { background: var(--ok-bg); }
.msg-error { background: var(--bad-bg); color: #7a1914; }
.msg-warning { background: var(--warn-bg); }

.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .85rem; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }

.filters summary { cursor: pointer; font-weight: 700; min-height: 32px; }
.filter-grid { display: grid; gap: .6rem; margin-top: .8rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.filter-grid label { font-size: .9rem; color: var(--muted); }
.export-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .6rem 0 1rem; color: var(--muted); }

.queue { border: 2px dashed #e0a800; background: var(--warn-bg); border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; }
.queue h2 { margin: 0 0 .5rem; }
.queue-item { padding: .5rem 0; border-top: 1px solid #ecd9a0; }
.queue-item:first-of-type { border-top: 0; }
.queue-item.status-error .q-status { color: var(--bad); }

/* таблица (десктоп) */
table.registry { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.registry th { background: #e8eef5; text-align: left; font-size: .85rem; padding: .6rem; }
.registry td { padding: .6rem; border-top: 1px solid var(--line); vertical-align: top; }
.registry tr.row-bad td:first-child { box-shadow: inset 4px 0 0 var(--bad); }
.registry .actions { white-space: nowrap; }
.registry .actions .btn { margin: 0 .15rem .25rem 0; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* карточка записи */
.props { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: .6rem 0 1rem; }
.props dt { color: var(--muted); }
.props dd { margin: 0; word-break: break-word; }
.pre { white-space: pre-wrap; }
.gallery { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.file { margin: 0; padding: .6rem; }
.file img { width: 100%; height: 200px; object-fit: cover; border-radius: 8px; display: block; background: #eef2f6; }
.pdf-tile { display: grid; place-items: center; height: 200px; border-radius: 8px; background: #eef2f6; font-size: 1.6rem; text-decoration: none; }
.file figcaption { margin-top: .5rem; }
.file .fname { display: block; font-weight: 600; word-break: break-all; }

/* телефон: таблица превращается в карточки */
@media (max-width: 800px) {
  .container { padding: .7rem; }
  table.registry, .registry tbody, .registry tr, .registry td { display: block; width: 100%; }
  table.registry { background: none; border: 0; }
  .registry thead { display: none; }
  .registry tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .8rem; padding: .4rem .8rem; }
  .registry tr.row-bad { border-left: 5px solid var(--bad); }
  .registry td { border: 0; padding: .3rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .registry td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex: none; }
  .registry td.actions { display: flex; flex-wrap: wrap; justify-content: flex-start; padding-top: .6rem; }
  .registry td.actions::before { content: none; }
  .registry td.desc { text-align: right; }
  .btn-primary.page-add { width: 100%; }
  .page-head .btn-primary { width: 100%; }
  .props { grid-template-columns: 1fr; gap: 0; }
  .props dt { margin-top: .5rem; font-size: .85rem; }
}

/* чат */
.chat-link { position: relative; }
.chat-badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: #e53935; color: #fff; font-size: .78rem; font-weight: 700; text-align: center; line-height: 20px; }
.chat-log { display: flex; flex-direction: column; gap: .5rem; margin: .8rem 0; max-height: 60vh; overflow-y: auto; }
.chat-msg { align-self: flex-start; max-width: 85%; background: #eef2f6; border-radius: 12px; padding: .45rem .75rem; }
.chat-msg.mine { align-self: flex-end; background: #dcebfb; }
.chat-msg .meta { font-size: .85rem; }
.chat-msg .meta .linklike { font-size: .8rem; color: var(--bad); padding: 0 .3rem; min-height: 32px; }
.chat-msg .text { white-space: pre-wrap; word-break: break-word; }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 46px; padding: .6rem .75rem; font: inherit; border: 1px solid #b9c4d0; border-radius: 10px; resize: vertical; }
@media (max-width: 800px) { .chat-msg { max-width: 94%; } .chat-form { flex-direction: column; align-items: stretch; } }
