/* ==========================================================================
   Экран входа: вкладки «Пароль» и «Бейдж+PIN», PIN-пад, состояния ошибок.
   Минимальные размеры касания >= 48px (подпункт 2.7). Без внешних шрифтов:
   офлайн-первичность (KEEP-1).
   ========================================================================== */

:root {
  --bg: #0f1b2d;
  --panel: #16283f;
  --panel-raised: #1d3450;
  --text: #e8eef6;
  --text-dim: #9db0c6;
  --accent: #2f7df6;
  --accent-press: #1f5fc4;
  --danger: #e05252;
  --ok: #3fae63;
  --radius: 14px;
  --touch-min: 48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.auth-shell {
  max-width: 420px;
  margin: 0 auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

/* Мобильная эргономика (Этап 5, подпункт 5.2): контент не уходит под нижнюю
   навигацию и «домашний» индикатор (safe-area-inset-bottom), под notch/status
   bar сверху (safe-area-inset-top). */
main[id] { padding-left: 16px; padding-right: 16px; }

body { padding-top: env(safe-area-inset-top); }

.auth-header { text-align: center; margin-bottom: 20px; }
.auth-title { font-size: 28px; margin: 0 0 4px; }
.auth-subtitle { color: var(--text-dim); margin: 0; font-size: 14px; }

/* --- Вкладки -------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  min-height: var(--touch-min);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 16px;
  padding: 12px 8px;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--panel-raised);
  color: var(--text);
  border-color: var(--accent);
}

/* --- Панели и поля -------------------------------------------------------- */
.panel { background: var(--panel); border-radius: var(--radius); padding: 16px; }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }

input[type="text"], input[type="password"] {
  width: 100%;
  min-height: var(--touch-min);
  background: var(--panel-raised);
  border: 1px solid #2c4668;
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
}

select, input[type="date"], input[type="search"], input[type="number"], input[type="datetime-local"], textarea {
  font-size: 16px;               /* >= 16px: iOS не зумит поле при фокусе */
  min-height: var(--touch-min);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #2c4668;
  background: var(--panel-raised);
  color: var(--text);
}

input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- Кнопки --------------------------------------------------------------- */
.btn {
  width: 100%;
  min-height: var(--touch-min);
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 12px;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-press); }
.btn-secondary { background: var(--panel-raised); color: var(--text); border: 1px solid #2c4668; }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-link { background: transparent; color: var(--accent); min-height: 44px; font-weight: 500; }

.btn[disabled] { opacity: .55; cursor: default; }

/* --- PIN-пад -------------------------------------------------------------- */
.pinpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.pinpad .key {
  min-height: 60px;              /* крупнее минимума: полевые условия, перчатки */
  font-size: 22px;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid #2c4668;
  background: var(--panel-raised);
  color: var(--text);
  cursor: pointer;
}

.pinpad .key:active { background: var(--accent-press); }

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 4px;
}

.pin-dots .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
}

.pin-dots .dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-dots .dot.error { background: var(--danger); border-color: var(--danger); }

/* --- Прочее --------------------------------------------------------------- */
.nfc-prompt { text-align: center; font-size: 16px; line-height: 1.4; }
.nfc-icon { text-align: center; font-size: 42px; margin: 16px 0; }
.nfc-user { text-align: center; font-size: 18px; font-weight: 600; margin: 8px 0 2px; }
.nfc-remaining { text-align: center; color: var(--text-dim); font-size: 13px; margin: 0 0 8px; }

.hint { color: var(--text-dim); font-size: 13px; text-align: center; min-height: 18px; margin: 8px 0 0; }
.hint.error { color: var(--danger); }
.hint.ok { color: var(--ok); }

.auth-footer { margin-top: 16px; }

/* --- профиль: устройства и журнал ---------------------------------------- */
.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #243c5c;
  font-size: 15px;
}

.device-row:last-child { border-bottom: none; }

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}

.log-list li {
  padding: 10px 0;
  border-bottom: 1px solid #243c5c;
}

.log-list li:last-child { border-bottom: none; }
.log-list .log-ok { color: var(--ok); }
.log-list .log-fail { color: var(--danger); }

.divider { border: none; border-top: 1px solid #243c5c; margin: 16px 0; }

/* --- Нижняя навигация (Этап 5, подпункт 5.2) ------------------------------ */
/* Тап-таргеты >= 48px, шрифт >= 16px (без iOS-zoom), safe-area снизу. */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  background: var(--panel);
  border-top: 1px solid #243c5c;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
  flex: 1;
  min-height: var(--touch-min);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item:active { background: var(--panel-raised); }

.bottom-nav-item.is-active {
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 3px 0 var(--accent);
}

.bottom-nav-icon { font-size: 20px; line-height: 1; }
.bottom-nav-label { font-size: 16px; line-height: 1.1; }

/* Контент страниц не уходит под навигацию. */
main[id] { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

/* --- Офлайн-индикатор и счётчик очереди (подпункт 5.3) --------------------- */
.pwa-status {
  background: #fff3cd;
  color: #664d03;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}

.pwa-status--offline { background: #fff3cd; color: #664d03; }
.pwa-status--queue { background: #e7f0ff; color: #204a87; }

/* --- Тёмная тема (Этап 5, подпункт 5.5) ------------------------------------ */
/* Экран входа тёмен по умолчанию; светлые inline-секции страниц (фильтры,
   карточки, таблицы) читаемы в системной тёмной теме через prefers-color-scheme:
   минимум — не ломать читаемость, без перестройки вёрстки. */
@media (prefers-color-scheme: dark) {
  .offline-bar,
  .pwa-status--offline { background: #4a3b12; color: #ffe08a; }
  .queue-bar,
  .pwa-status--queue { background: #16324f; color: #9ec5f8; }

  .card { background: #16283f; border-color: #2c4668; }
  .badge { filter: saturate(0.85); }
  .sev-low { background: #16321f; color: #7ddba0; }
  .sev-medium { background: #3d2c0a; color: #f2c063; }
  .sev-high { background: #43160f; color: #f19a8f; }
  .sev-critical { background: #4d1119; color: #f2a5b2; }
  .st-new, .st-issued, .st-draft-only, .ev-issued { background: #16324f; color: #9ec5f8; }
  .st-in_progress, .st-draft, .ev-payload_written { background: #3d2c0a; color: #f2c063; }
  .st-resolved, .st-active, .ev-activated { background: #16321f; color: #7ddba0; }
  .st-closed, .st-revoked, .st-disabled, .ev-revoked { background: #243447; color: #9db0c6; }
  .st-lost, .ev-lost { background: #43160f; color: #f19a8f; }

  .auto-text, .final-preview { background: #16283f; border-color: #2c4668; color: #e8eef6; }
  .node { background: #16283f; border-color: #2c4668; }
  .node.archived { background: #101c2e; }
  pre.code { background: #0b1524; }

  table.hist th, table.hist td { border-bottom-color: #243c5c; }
  .tl-item { border-left-color: var(--accent); }
  .timeline { color: var(--text); }
  .tl-text { color: var(--text); }
  .tl-meta { color: var(--text-dim); }

  .modal { background: rgba(4, 10, 20, .6); }
  .modal-box { background: var(--panel); color: var(--text); }
  .modal-box .title, .modal-box .lbl { color: var(--text); }

  input.field-input, select, textarea.field-input,
  .filters select, .filters input {
    background: var(--panel-raised);
    border-color: #2c4668;
    color: var(--text);
  }

  .opt { background: var(--panel-raised); border-color: #2c4668; color: var(--text); }
  .btn-ghost { background: #1d3450; color: var(--text); }
  .btn-warn { background: #3d2c0a; color: #f2c063; }
  .btn-danger { background: #43160f; color: #f19a8f; }
  .progress { background: #243c5c; }

  .step { background: #243c5c; color: var(--text-dim); }
  .step.done { background: #16321f; color: #7ddba0; }
  .hint { color: var(--text-dim); }
  .error { color: #f19a8f; }
  .ok { color: #7ddba0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
