/* PManager — тёмная тема. Без внешних ресурсов, без инлайн-стилей в HTML
   (CSP: style-src 'self'). Динамику через CSSOM (el.style.*) задаёт app.js. */

:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --surface-3: #262b36;
  --border: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #4f8cff;
  --accent-dim: #2f5bb0;
  --danger: #f28b82;
  --danger-dim: #7a3c38;
  --success: #81c995;
  --success-dim: #2f5b3a;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100%; }

.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Кнопки ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.btn-block { display: flex; width: 100%; justify-content: center; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3f7bf0; }
.btn-danger { background: transparent; border-color: var(--danger-dim); color: var(--danger); }
.btn-danger:hover { background: var(--danger-dim); color: #fff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  padding: 3px 7px;
  font-size: 13px;
}
.icon-btn:hover { color: var(--text); background: var(--surface-3); }

/* ── Формы ──────────────────────────────────────────────── */
.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
textarea.input { resize: vertical; min-height: 56px; }
.input:focus { outline: none; border-color: var(--accent); }
.input:disabled { opacity: .7; }
.input.small { padding: 4px 7px; font-size: 12px; width: auto; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; color: var(--muted); }
.readonly { padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); }

.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }

/* ── Экраны входа / PIN ─────────────────────────────────── */
.centered {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.auth-logo { font-size: 42px; }
.auth-title { margin: 0; font-size: 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }

/* ── Header ─────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-size: 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.search-wrap { display: flex; gap: 8px; flex: 1 1 260px; min-width: 180px; max-width: 560px; }
.search-wrap:empty { display: none; }
.search { flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: wrap; }
.topnav { display: flex; gap: 4px; }
.navlink {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}
.navlink:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.navlink.active { background: var(--surface-3); color: var(--text); }

.pin-ind {
  font-size: 13px;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--surface-2);
  font-family: var(--mono);
  white-space: nowrap;
}
.pin-ind.unlocked { color: var(--success); }
.pin-ind.locked { color: var(--muted); }

.user-menu { position: relative; }
.user-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  padding: 4px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.menu-item {
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.menu-item:hover { background: var(--surface-3); }
.menu-item.danger { color: var(--danger); }

/* ── Layout ─────────────────────────────────────────────── */
.layout { display: block; }
.layout.with-sidebar {
  display: grid;
  grid-template-columns: 260px 1fr;
  align-items: start;
}
.sidebar {
  padding: 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 57px;
  max-height: calc(100vh - 57px);
  overflow-y: auto;
}
.content { padding: 18px; min-width: 0; }

.sidebar-section { display: flex; flex-direction: column; gap: 8px; }
.sidebar-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.col-list { display: flex; flex-direction: column; gap: 2px; }
.col-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: none;
  background: none;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  width: 100%;
}
.col-item:hover { background: var(--surface-2); }
.col-item.active { background: var(--surface-3); }
.col-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-count { color: var(--muted); font-size: 12px; flex: 0 0 auto; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Чипы / бейджи ──────────────────────────────────────── */
.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.chip.small { padding: 2px 8px; cursor: default; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

/* ── Список записей ─────────────────────────────────────── */
.entry-list { display: flex; flex-direction: column; gap: 10px; }
.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.entry-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.entry-title {
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  text-align: left;
}
.entry-title:hover { color: var(--accent); }
.entry-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); }
.entry-meta .login { color: var(--text); }
.entry-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.reveal-area {
  padding: 4px 8px;
  background: var(--surface-3);
  border-radius: 6px;
  color: var(--success);
  word-break: break-all;
}
.entry-url { word-break: break-all; }
.entry-url a { color: var(--accent); }
.entry-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.loading { color: var(--muted); padding: 16px; }

/* ── Модалы ─────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal { width: 100%; max-width: 520px; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
}
.modal-title { margin: 0; font-size: 18px; }
.entry-form { display: flex; flex-direction: column; gap: 12px; }
.pass-row { display: flex; gap: 6px; align-items: center; }
.pass-row .input { flex: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ── Таблицы админки ────────────────────────────────────── */
.subnav { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.admin-body { display: flex; flex-direction: column; gap: 14px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form .input { width: auto; flex: 1 1 140px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--surface-2); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--surface-2); }
.row-actions { display: flex; gap: 6px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 18px; }

/* ── Прогресс / статусы ─────────────────────────────────── */
.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin: 6px 0; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s; }
.offb-card.done .progress-fill { background: var(--success); }

.status-badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.status-badge.done { background: var(--success-dim); color: var(--success); }
.status-badge.in_progress { background: var(--accent-dim); color: #cfe0ff; }

/* ── Оффбординг ─────────────────────────────────────────── */
.offb-list { display: flex; flex-direction: column; gap: 10px; }
.offb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.offb-card:hover { border-color: var(--accent); }
.offb-card.done { border-color: var(--success-dim); }
.offb-user { font-weight: 600; }
.offb-status { color: var(--muted); font-size: 13px; }

.hint {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  margin: 14px 0;
  font-size: 13px;
}
.offb-items { display: flex; flex-direction: column; gap: 10px; }
.offb-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.offb-item.status-rotated { border-left: 3px solid var(--success); }
.offb-item.status-skipped { border-left: 3px solid var(--muted); }
.offb-item.status-pending { border-left: 3px solid var(--accent); }
.offb-item-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.offb-item-title { font-weight: 600; }
.offb-item-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.offb-item-actions .input { flex: 1 1 160px; width: auto; }
.offb-item-done { color: var(--success); font-size: 13px; }
.offb-item.status-skipped .offb-item-done { color: var(--muted); }

.reason-badge { padding: 2px 8px; border-radius: 6px; font-size: 11px; white-space: nowrap; }
.reason-copied { background: var(--danger-dim); color: #ffd7d2; }
.reason-viewed { background: #6b4e1e; color: #ffe6b0; }
.reason-authored { background: var(--accent-dim); color: #cfe0ff; }
.reason-had_access { background: var(--surface-3); color: var(--muted); }

/* ── Тосты ──────────────────────────────────────────────── */
.toast-wrap {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  padding: 11px 14px;
  border-radius: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  animation: toast-in .2s ease;
}
.toast.leaving { opacity: 0; transition: opacity .3s; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--accent); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 760px) {
  /* Шапка: ряд 1 «бренд · PIN · юзер», ряд 2 навигация, ряд 3 поиск.
     display: contents распускает .topbar-right, чтобы порядок задавался order. */
  .topbar { gap: 8px 10px; padding: 8px 12px; }
  .topbar-right { display: contents; }
  .brand { order: 1; margin-right: auto; }
  .pin-ind { order: 2; padding: 7px 9px; }
  .user-menu { order: 3; }
  .topnav { order: 4; flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; }
  .topnav::-webkit-scrollbar { display: none; }
  .search-wrap { order: 5; flex: 1 1 100%; max-width: none; }
  .navlink { padding: 9px 12px; white-space: nowrap; }
  .user-btn { max-width: 160px; padding: 8px 10px; }
  /* Якорь дропдауна — вся шапка (sticky = containing block), а не кнопка:
     при заворачивании флекса кнопка может оказаться слева, right:0 от неё уезжает за экран */
  .user-menu { position: static; }
  .menu-dropdown { right: 12px; max-width: calc(100vw - 24px); }

  /* iOS Safari зумит страницу при фокусе поля с font-size < 16px */
  .input, select.input, textarea.input, .input.small { font-size: 16px; }

  /* Сайдбар → компактная фильтр-панель: коллекции и теги горизонтальными скролл-рядами */
  .layout.with-sidebar { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px;
    gap: 12px;
  }
  .col-list { flex-direction: row; overflow-x: auto; gap: 6px; scrollbar-width: none; }
  .col-list::-webkit-scrollbar { display: none; }
  .col-item {
    flex: 0 0 auto;
    width: auto;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
  }
  .col-item.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
  .col-item.active .col-count { color: #cfe0ff; }
  .tag-cloud { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tag-cloud::-webkit-scrollbar { display: none; }
  .tag-cloud .chip { flex: 0 0 auto; padding: 9px 13px; }
  .entry-title { padding: 5px 0; }

  /* Тап-таргеты ≥ ~40px */
  .btn { padding: 10px 14px; }
  .btn.small { padding: 8px 11px; }
  .icon-btn { padding: 7px 10px; }
  .menu-item { padding: 11px 12px; }

  .content { padding: 12px; }
  .subnav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .subnav::-webkit-scrollbar { display: none; }
  .overlay { padding: 12px 10px calc(12px + env(safe-area-inset-bottom)); }
  .modal-box { padding: 16px 14px; }
  .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
  .pass-row { flex-wrap: wrap; }
  .pass-row .input { flex: 1 1 140px; }
  .toast-wrap { left: 12px; right: 12px; max-width: none; }
}
@media (max-width: 400px) {
  .user-btn { max-width: 120px; }
  .brand { font-size: 15px; }
}
