/* ═══════════════════════════════════════════════════════════
   Safety Journal — Design System v16
   ПРАВИЛО: нет хардкодов цветов — только CSS custom properties.
   Тёмная/светлая тема: [data-theme="dark|light"] на <html>.
   Базовые значения здесь — перекрываются theme-vars из app.py.
   
   Исключение: цвета для iOS form controls задаются через JS
   (applyCtrlBg), т.к. iOS Safari игнорирует CSS vars на inputs.
═══════════════════════════════════════════════════════════ */

/* ── Базовые переменные тёмной темы ── */
:root, [data-theme="dark"] {
  --bg:     #041a34;
  --s2:     #0f0d1e;
  --s3:     #16122a;
  --s4:     #1e1840;
  --a:      #1d83e2;
  --a2:     #58c3d9;
  --ar:     157,132,245;
  --text:   #e8f6ff;
  --text2:  rgba(236,234,248,.52);
  --text3:  rgba(236,234,248,.34);
  --hbg:    rgba(9,8,15,.94);
  --mbg:    #0f0d1e;

  --border:   rgba(255,255,255,.13);
  --border-f: rgba(var(--ar),.7);
  --surface:  rgba(255,255,255,.055);
  --orb:      .26;

  --bg-g:   rgba(255,255,255,.08);
  --bd-g:   rgba(255,255,255,.14);
  --txt-g:  rgba(236,234,248,.75);

  --op-bg:  rgba(239,68,68,.12);
  --op-bd:  rgba(239,68,68,.40);
  --op-t:   #f87171;
  --cl-bg:  rgba(34,197,94,.10);
  --cl-bd:  rgba(34,197,94,.36);
  --cl-t:   #4ade80;
  --nw-bg:  rgba(234,179,8,.11);
  --nw-bd:  rgba(234,179,8,.34);
  --nw-t:   #fbbf24;
  --at-bg:  rgba(var(--ar),.10);
  --at-bd:  rgba(var(--ar),.22);
  --at-t:   rgba(236,234,248,.6);
  --cm-bg:  rgba(96,165,250,.10);
  --cm-bd:  rgba(96,165,250,.22);
  --cm-t:   #7ab8fa;
  --sc:     rgba(var(--ar),.20);
  --ov:     rgba(4,3,12,.86);
}

/* ── Базовые переменные светлой темы ── */
[data-theme="light"] {
  --bg:     #eaf7ff;
  --s2:     #ffffff;
  --s3:     #e8e3f5;
  --s4:     #ddd7ee;
  --a:      #0f56a6;
  --a2:     #1d83e2;
  --ar:     92,53,200;
  --text:   #103a66;
  --text2:  rgba(26,19,48,.55);
  --text3:  rgba(26,19,48,.36);
  --hbg:    rgba(240,238,250,.95);
  --mbg:    #ffffff;

  --border:   rgba(92,53,200,.16);
  --border-f: rgba(92,53,200,.6);
  --surface:  rgba(255,255,255,.88);
  --orb:      .09;

  --bg-g:   rgba(92,53,200,.07);
  --bd-g:   rgba(92,53,200,.20);
  --txt-g:  rgba(26,19,48,.70);

  --op-bg:  rgba(185,28,28,.08);
  --op-bd:  rgba(185,28,28,.28);
  --op-t:   #991b1b;
  --cl-bg:  rgba(20,120,55,.08);
  --cl-bd:  rgba(20,120,55,.28);
  --cl-t:   #166534;
  --nw-bg:  rgba(146,98,10,.09);
  --nw-bd:  rgba(146,98,10,.28);
  --nw-t:   #7c4c07;
  --at-bg:  rgba(92,53,200,.08);
  --at-bd:  rgba(92,53,200,.20);
  --at-t:   rgba(26,19,48,.60);
  --cm-bg:  rgba(29,78,216,.08);
  --cm-bd:  rgba(29,78,216,.20);
  --cm-t:   #1d4ed8;
  --sc:     rgba(92,53,200,.18);
  --ov:     rgba(15,10,35,.52);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }
html { color-scheme: dark light }
body {
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background .22s, color .22s;
}
::-webkit-scrollbar { width: 4px; height: 4px }
::-webkit-scrollbar-thumb { background: var(--sc); border-radius: 4px }

/* ── Орбы ── */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none }
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(110px); animation: drift linear infinite;
  will-change: transform; contain: strict;
}
.o1 { width: clamp(200px,60vw,540px); height: clamp(200px,60vw,540px);
      background: radial-gradient(circle,#1d83e2,transparent 70%);
      opacity: var(--orb); top: -15%; left: -10%; animation-duration: 25s }
.o2 { width: clamp(160px,50vw,460px); height: clamp(160px,50vw,460px);
      background: radial-gradient(circle,#0f56a6,transparent 70%);
      opacity: var(--orb); bottom: -10%; right: -8%; animation-duration: 32s; animation-direction: reverse }
.o3 { width: clamp(130px,38vw,360px); height: clamp(130px,38vw,360px);
      background: radial-gradient(circle,#0d9488,transparent 70%);
      opacity: var(--orb); top: 40%; left: 44%; animation-duration: 20s; animation-delay: -7s }
/* На мобиле: меньше blur, отключаем анимацию орбов для плавности UI */
@media(max-width:600px) {
  .orb { filter: blur(60px); animation: none }
}
@keyframes drift { 0%,100%{transform:translate(0,0)} 33%{transform:translate(28px,-22px)} 66%{transform:translate(-18px,34px)} }
.page { position: relative; z-index: 1 }

/* ── Шапка ── */
header {
  position: sticky; top: 0; z-index: 80;
  background: var(--hbg);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  transition: background .22s, border-color .22s;
}
.hi { max-width: 960px; margin: 0 auto; padding: 0 14px; height: 52px; display: flex; align-items: center; gap: 7px }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; flex-shrink: 0; margin-right: auto; min-width: 0; overflow: hidden }
.logo-i { flex-shrink: 0; width: 40px; height: 40px; border-radius: 13px; display: flex; align-items: center; justify-content: center; font-size: 18px; background: linear-gradient(135deg,var(--a),var(--a2)); box-shadow: 0 0 24px rgba(var(--ar),.26); overflow: hidden }
.logo-i.logo-i--icon { width: 40px; height: 40px; border-radius: 13px; background: linear-gradient(135deg,var(--a),var(--a2)) }
.logo-i img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: 10px }
.logo-t { font-family: var(--font-heading, "Segoe UI", "Helvetica Neue", Arial, sans-serif); font-weight: 800; font-size: .9rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
[data-theme="dark"] .logo-t { background: linear-gradient(90deg,var(--text) 20%,var(--a)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text }
@media(max-width:360px) { .logo-t { display: none } }
.ha { display: flex; align-items: center; gap: 6px; flex-shrink: 0 }

/* Кнопки шапки — единый стиль */
.uc, .hbtn, .theme-btn {
  width: 34px; height: 34px; min-width: 34px; max-width: 34px;
  border-radius: 9px; background: var(--s3); border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .18s, border-color .18s, color .18s;
  text-decoration: none; color: var(--text2);
  font-size: 17px; line-height: 1; padding: 0; overflow: hidden;
}
.uc:hover, .hbtn:hover, .theme-btn:hover { background: var(--s4); color: var(--text); border-color: var(--border-f) }

/* ── Мобильная шапка ── */
/* На detail-странице на мобиле убираем лишние кнопки из шапки */
@media(max-width:600px) {
  .ha--detail .theme-btn,
  .ha--detail .uc,
  .ha--detail .hbtn-secondary { display: none !important }
  /* Кнопка "Назад к журналу" в шапке admin на мобиле — только иконка */
  .ha--admin .btn-back-text { display: none }
  .ha--admin .btn-back-icon { display: inline }
}
@media(min-width:601px) {
  .ha--admin .btn-back-icon { display: none }
}

.uc-name { display: none }
.rd { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0 }
.rd-admin     { background: #58c3d9; box-shadow: 0 0 6px rgba(88,195,217,.5) }
.rd-moderator { background: #60a5fa; box-shadow: 0 0 6px rgba(96,165,250,.5) }
.rd-user      { background: #34d399; box-shadow: 0 0 6px rgba(52,211,153,.5) }

/* ── Кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 22px; border-radius: 50px; border: none;
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif); font-size: .84rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none; line-height: 1.2;
  transition: opacity .18s, transform .15s;
  -webkit-tap-highlight-color: transparent; -webkit-appearance: none; appearance: none;
}
.btn:hover  { opacity: .85 }
.btn:active { transform: scale(.95) }
.btn:disabled { opacity: .38; cursor: not-allowed }
.btn-sm  { padding: 8px 18px; font-size: .78rem }
.btn-xs  { padding: 5px 11px; font-size: .72rem }
.btn-ico { width: 36px; height: 36px; min-width: 36px; padding: 0; border-radius: 10px; font-size: 1rem; line-height: 1; flex-shrink: 0 }
/* Цвета кнопок — перекрываются theme-vars */
.btn-p { color: #fff; background: linear-gradient(135deg,var(--a),var(--a2)); box-shadow: 0 3px 16px rgba(var(--ar),.28) }
.btn-g { color: var(--txt-g); background: var(--bg-g); border: 1.5px solid var(--bd-g) }
.btn-g:hover { color: var(--text) }
.btn-s { color: #fff; background: linear-gradient(135deg,#059669,#065f46) }
.btn-d { color: #fff; background: linear-gradient(135deg,#dc2626,#9b1c1c) }
.btn-w { color: var(--text); background: var(--bg-g); border: 1.5px solid var(--border) }
.btn-w:hover { background: var(--s4) }

/* ── Карточки ── */
.gc {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: background .22s, border-color .22s;
}
/* Убираем тяжёлый backdrop-filter на слабых мобилах */
@media(max-width:600px) {
  .gc { backdrop-filter: none; -webkit-backdrop-filter: none }
}
.sep { height: 1px; background: var(--border); margin: 16px 0 }

/* ── Формы ── */
.fg { margin-bottom: 15px }
.fl { display: block; margin-bottom: 6px; font-size: .64rem; font-weight: 700; letter-spacing: .9px; text-transform: uppercase; color: var(--text2) }

/* ══ Контролы ══
   background через var() для современных браузеров.
   Для iOS Safari — JS applyCtrlBg() проставит inline style.
   НЕ МЕНЯТЬ: дублирование намеренное. */
.fi, .fs, .ft {
  display: block; width: 100%;
  background: var(--s3);
  border: 1.5px solid var(--border); border-radius: 10px;
  padding: 11px 14px; color: var(--text);
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif); font-size: .88rem; line-height: 1.4;
  outline: none; transition: border-color .2s, background .2s;
  -webkit-appearance: none; appearance: none; box-sizing: border-box;
}
.fi::placeholder, .ft::placeholder { color: var(--text3) }
.fi:focus, .fs:focus, .ft:focus { border-color: var(--border-f); background: var(--s4) }
.fs {
  cursor: pointer; padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='6'%3E%3Cpath d='M0 0l5.5 6L11 0z' fill='rgba(157%2C132%2C245%2C.7)'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
}
[data-theme="light"] .fs {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='6'%3E%3Cpath d='M0 0l5.5 6L11 0z' fill='rgba(92%2C53%2C200%2C.65)'/%3E%3C/svg%3E");
}
.fs option, .sw select option { background: var(--s2); color: var(--text) }
.ft { resize: vertical; min-height: 82px; line-height: 1.6 }

/* Поиск */
.srch {
  display: flex; align-items: center; gap: 8px;
  background: var(--s3); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 10px 13px;
  transition: border-color .2s, background .2s;
}
.srch:focus-within { border-color: var(--border-f) }
.srch svg { flex-shrink: 0; color: var(--text2) }
.srch input { background: transparent; border: none; outline: none; color: var(--text); font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif); font-size: .88rem; width: 100%; min-width: 0 }
.srch input::placeholder { color: var(--text3) }

/* Тулбар-select */
.sw { display: block }
.sw select {
  display: block; width: 100%;
  background: var(--s3);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='6'%3E%3Cpath d='M0 0l5.5 6L11 0z' fill='rgba(157%2C132%2C245%2C.7)'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
  border: 1.5px solid var(--border); border-radius: 10px;
  padding: 11px 38px 11px 13px; color: var(--text);
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif); font-size: .82rem;
  outline: none; cursor: pointer; -webkit-appearance: none; appearance: none;
  box-sizing: border-box; transition: border-color .2s, background .2s;
}
[data-theme="light"] .sw select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='6'%3E%3Cpath d='M0 0l5.5 6L11 0z' fill='rgba(92%2C53%2C200%2C.65)'/%3E%3C/svg%3E");
}
.sw select:focus { border-color: var(--border-f) }

/* ══ Бейджи ══ */
.st-open, .st-closed, .badge, .new-badge, .att-chip, .cmt-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 6px;
  font-size: .69rem; font-weight: 700; line-height: 1.5;
  white-space: nowrap; flex-shrink: 0; border: 1px solid transparent;
}
.st-open   { background: var(--op-bg); border-color: var(--op-bd); color: var(--op-t) }
.st-open::before { content: "●"; font-size: .38rem; animation: pulse-dot 1.8s ease-in-out infinite; margin-right: 1px }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:.15} }
.st-closed { background: var(--cl-bg); border-color: var(--cl-bd); color: var(--cl-t) }
.st-closed::before { content: "✓"; font-size: .7rem }
.badge   { border: 1px solid }
.dot     { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0 }
.dot3    { width: 3px; height: 3px; border-radius: 50%; background: var(--text2); display: inline-block }
.new-badge { background: var(--nw-bg); border-color: var(--nw-bd); color: var(--nw-t) }
.att-chip  { background: var(--at-bg); border-color: var(--at-bd); color: var(--at-t); font-weight: 600 }
.cmt-chip  { background: var(--cm-bg); border-color: var(--cm-bd); color: var(--cm-t); font-weight: 600 }

/* ══ Радио статуса ══ */
.st-radio-group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px }
.st-radio-lbl   { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 13px 16px; border-radius: 12px; border: 2px solid; transition: all .2s; user-select: none }
.st-radio-icon  { font-size: 1.2rem; flex-shrink: 0; line-height: 1 }
.st-radio-txt   { font-size: .86rem; font-weight: 600 }
.open-opt       { border-color: var(--op-bd); background: var(--op-bg) }
.open-opt.active { border-color: var(--op-t); box-shadow: 0 0 0 2px var(--op-bd) }
.open-opt .st-radio-txt { color: var(--op-t) }
.closed-opt     { border-color: var(--cl-bd); background: var(--cl-bg) }
.closed-opt.active { border-color: var(--cl-t); box-shadow: 0 0 0 2px var(--cl-bd) }
.closed-opt .st-radio-txt { color: var(--cl-t) }

/* ── Модалки ── */
.ov { display: none; position: fixed; inset: 0; z-index: 200; align-items: flex-end; justify-content: center; background: var(--ov); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px) }
.ov.on { display: flex }
@media(max-width:600px) { .ov { backdrop-filter: none; -webkit-backdrop-filter: none } }
@media(min-width:600px) { .ov { align-items: center } }
.modal {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--mbg); border: 1px solid var(--border);
  border-radius: 22px 22px 0 0; padding: 20px 18px 32px;
  box-shadow: 0 -10px 50px rgba(0,0,0,.2);
  animation: mSlide .28s cubic-bezier(.32,0,.67,0); transition: background .22s;
}
@media(min-width:600px) { .modal { border-radius: 22px; animation: mIn .22s ease; padding-bottom: 24px } }
@keyframes mSlide { from{transform:translateY(100%)} to{transform:none} }
@keyframes mIn    { from{opacity:0;transform:translateY(16px) scale(.97)} to{opacity:1;transform:none} }
.modal::-webkit-scrollbar { width: 4px }
.modal::-webkit-scrollbar-thumb { background: var(--sc); border-radius: 4px }
.modal-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 22px }
@media(min-width:600px) { .modal-handle { display: none } }
.mh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 8px }
.mt { font-family: var(--font-heading, "Segoe UI", "Helvetica Neue", Arial, sans-serif); font-weight: 800; font-size: 1.06rem; color: var(--text); flex: 1 }
.mx { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-g); border: 1px solid var(--border); color: var(--text2); cursor: pointer; font-size: .75rem; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: all .18s }
.mx:hover { background: rgba(220,38,38,.18); color: #ef4444; transform: rotate(90deg) }
.ma { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap }

/* ── Загрузка ── */
.drop-z { border: 2px dashed var(--border); border-radius: 12px; padding: 20px; text-align: center; cursor: pointer; color: var(--text2); transition: all .2s }
.drop-z:hover, .drop-z.drag-on { border-color: var(--a); background: rgba(var(--ar),.07); color: var(--a) }
.drop-z input { display: none }
#pg { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px }
.pi { width: 66px; height: 54px; border-radius: 9px; overflow: hidden; position: relative; flex-shrink: 0; border: 1px solid var(--border) }
.pi img, .pi video { width: 100%; height: 100%; object-fit: cover }
.pi-heic { width: 66px; height: 54px; border-radius: 9px; flex-shrink: 0; background: rgba(var(--ar),.1); border: 1px solid rgba(var(--ar),.3); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 9px; color: var(--a); gap: 2px }
.prm { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,.75); border: none; color: #fff; font-size: 9px; cursor: pointer; display: flex; align-items: center; justify-content: center }

/* ── Лайтбокс ── */
.lb { display: none; position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.96); backdrop-filter: blur(10px); align-items: center; justify-content: center }
.lb.on { display: flex }
.lbx { position: absolute; top: 16px; right: 16px; width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); color: #fff; font-size: .85rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .18s }
.lbx:hover { background: rgba(239,68,68,.3) }
#lbc { max-width: 96vw; max-height: 94vh; overflow: auto }

/* ── Progress / Toast ── */
#pgbar { position: fixed; top: 0; left: 0; height: 2px; z-index: 999; background: linear-gradient(90deg,var(--a),var(--a2)); width: 0; transition: width .3s; pointer-events: none }
.toast {
  position: fixed; bottom: max(24px,env(safe-area-inset-bottom,24px));
  left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--mbg); border: 1px solid var(--border);
  border-radius: 50px; padding: 11px 24px; font-size: .83rem; color: var(--text);
  backdrop-filter: blur(18px); z-index: 500;
  transition: transform .3s cubic-bezier(.34,1.5,.64,1), background .22s;
  pointer-events: none; white-space: nowrap;
  max-width: calc(100vw - 28px); overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}
.toast.on  { transform: translateX(-50%) translateY(0) }
.toast.ok  { border-color: var(--cl-bd); color: var(--cl-t) }
.toast.err { border-color: var(--op-bd); color: var(--op-t) }

/* ── Быстрое закрытие ── */
.qc-btn { flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px; background: var(--cl-bg); border: 1.5px solid var(--cl-bd); color: var(--cl-t); font-size: 1.1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .18s; line-height: 1 }
.qc-btn:hover { box-shadow: 0 0 0 2px var(--cl-bd) }

/* ── FAB ── */
.fab {
  position: fixed; bottom: max(22px,env(safe-area-inset-bottom,22px)); right: 18px;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(135deg,var(--a),var(--a2));
  color: #fff; font-size: 1.7rem; cursor: pointer; z-index: 60;
  box-shadow: 0 4px 24px rgba(var(--ar),.4);
  display: flex; align-items: center; justify-content: center;
  line-height: 1; transition: transform .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none; padding: 0;
}
.fab:hover  { transform: scale(1.08); box-shadow: 0 6px 32px rgba(var(--ar),.55) }
.fab:active { transform: scale(.94) }
