/* KeyNest — оформление (тёмная тема, без внешних зависимостей) */

:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --bg-card: #1b2028;
  --line: #262d38;
  --text: #e6e9ef;
  --muted: #8b95a5;
  --accent: #4f9cf9;
  --accent-dim: #2b6fd0;
  --ok: #3ecf8e;
  --warn: #f5a623;
  --err: #ef5f5f;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13.5px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 13.5px; margin: 18px 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.mono { font-family: var(--mono); font-size: 11.5px; }
.break { word-break: break-all; }
.err { color: var(--err); }
.hint { color: var(--muted); font-size: 11.5px; }

/* ---------- Бренд ---------- */

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.brand__logo { display: block; width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; }
.brand--lg .brand__logo { width: 44px; height: 44px; border-radius: 11px; }
.brand--lg .brand__text { font-size: 18px; }

/* ---------- Экраны входа ---------- */

.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth__card {
  width: 100%; max-width: 420px;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px;
}
.auth__card > p { margin: 0 0 18px; }

/* ---------- Формы ---------- */

.form { display: flex; flex-direction: column; gap: 12px; }
.form--grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form--grid .span2 { grid-column: 1 / -1; }
.form--inline {
  flex-direction: row; align-items: flex-end; flex-wrap: wrap;
  gap: 10px; padding: 12px 0;
}

label { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; color: var(--muted); }

input, select, textarea {
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-dim); }
input[type=range] { padding: 0; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }

.inputgroup { display: flex; gap: 6px; align-items: center; }
.checks { display: flex; flex-wrap: wrap; gap: 14px; }
.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Кнопки ---------- */

.btn {
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
  border-radius: 8px; padding: 9px 14px; font: inherit; cursor: pointer;
  transition: border-color .15s, background .15s, opacity .15s;
}
.btn:hover { border-color: #3a475a; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
.btn--primary:hover { background: var(--accent); border-color: var(--accent); }
.btn--danger { border-color: #5a2a2a; color: #ffb4b4; background: #241a1a; }
.btn--danger:hover { background: #33201f; }
.btn--ghost { background: transparent; }
.btn--block { width: 100%; }

.iconbtn {
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--muted);
  border-radius: 7px; padding: 6px 9px; cursor: pointer; font: inherit; line-height: 1;
}
.iconbtn:hover { color: var(--text); border-color: #3a475a; }

.linkbtn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; padding: 4px 0; text-align: left;
}
.linkbtn:hover { color: var(--accent); }
.linkbtn--danger:hover { color: var(--err); }

/* ---------- Каркас приложения ---------- */

.layout { display: grid; grid-template-columns: var(--sidebar-w, 274px) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--bg-soft); border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 14px;
  /* панель на всю высоту окна: список папок занимает всё свободное место */
  position: sticky; top: 0; height: 100vh; min-width: 0;
}

/* ручка изменения ширины на правой границе панели */
.resizer {
  position: absolute; top: 0; right: -4px; width: 8px; height: 100%;
  cursor: col-resize; z-index: 5; touch-action: none;
}
.resizer::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px;
  background: transparent; transition: background .15s;
}
.resizer:hover::after, .resizer:focus-visible::after, body.is-resizing .resizer::after { background: var(--accent); }
.resizer:focus { outline: none; }
body.is-resizing { cursor: col-resize; user-select: none; }

.folders { display: flex; flex-direction: column; gap: 2px; overflow: auto; flex: 1 1 auto; min-height: 80px; }

/* разделы «Личные / Групповые / Чужие пароли» */
.fsection { display: flex; flex-direction: column; gap: 2px; }
.fsection + .fsection { margin-top: 8px; }
.fsection__head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; cursor: pointer; font: inherit; text-align: left;
  color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  padding: 8px 10px 4px 8px; border-radius: 6px;
}
.fsection__head:hover { color: var(--text); }
.fsection__title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsection__head .badge { font-weight: 500; letter-spacing: 0; text-transform: none; }
.folder {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: none; border: none; color: var(--text);
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit; text-align: left;
}
.folder:hover { background: #1f2530; }
.folder.is-active { background: #232b38; box-shadow: inset 2px 0 0 var(--accent); }
.folder__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.folder__meta { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }

/* дерево вложенных папок: треугольник сворачивания ветки */
.folder__twisty {
  flex: 0 0 12px; width: 12px; text-align: center;
  color: var(--muted); font-size: 9px; line-height: 1; user-select: none;
}
.folder__twisty[data-toggle]:hover { color: var(--accent); }

.badge {
  background: #232a35; color: var(--muted); border-radius: 20px;
  padding: 1px 8px; font-size: 11px;
}
.tag {
  font-size: 10px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 20px; padding: 1px 7px; white-space: nowrap;
}
.tag--manage { color: #cbb2ff; border-color: #3b3358; }
.tag--write { color: #9fd8ff; border-color: #2c4459; }

/* уровень доступа и признак группы — иконками, чтобы название папки не обрезалось */
.permico { display: block; flex: 0 0 13px; color: var(--muted); }
.permico--manage { color: #cbb2ff; }
.permico--write { color: #9fd8ff; }
.permico--read { color: #8fa0b6; }
.permico--group { color: #7f8da3; }

/* верхнее меню над содержимым папки */
.menubar {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 6px 14px; border-bottom: 1px solid var(--line); background: var(--bg-soft);
}
.usermenu { position: relative; }
.usermenu__btn {
  display: flex; align-items: center; gap: 10px; padding: 5px 8px 5px 6px;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  color: inherit; cursor: pointer; font: inherit; max-width: 320px;
}
.usermenu__btn:hover, .usermenu__btn[aria-expanded="true"] { background: var(--bg); border-color: var(--line); }
.usermenu__btn:focus-visible { outline: 2px solid var(--accent-dim); outline-offset: 1px; }
.usermenu__avatar {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  color: #fff; background: linear-gradient(135deg, #4f8cff, #7a5cf0);
}
.usermenu__caret { flex: 0 0 12px; color: var(--muted); transition: transform .15s; }
.usermenu__btn[aria-expanded="true"] .usermenu__caret { transform: rotate(180deg); }
.usermenu__list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 230px;
  padding: 6px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.usermenu__list[hidden] { display: none; }
.usermenu__head {
  padding: 6px 10px 8px; color: var(--muted); font-size: 11.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.usermenu__item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: inherit; font: inherit; cursor: pointer;
}
.usermenu__item:hover, .usermenu__item:focus-visible { background: var(--bg); color: var(--accent); outline: none; }
.usermenu__item--danger:hover, .usermenu__item--danger:focus-visible { color: #ff8a8a; }
.usermenu__sep { height: 1px; background: var(--line); margin: 4px 2px; }
.who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; text-align: right; }
.who__name { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.who__role { color: var(--muted); font-size: 11px; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.search { max-width: 460px; min-width: 200px; flex: 1 1 220px; }
.topbar__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.content { padding: 18px 20px 40px; overflow: auto; min-width: 0; }

.empty { max-width: 460px; margin: 60px auto; text-align: center; }
.empty .btn { margin-top: 14px; }

/* ---------- Таблицы ---------- */

.tablewrap { width: 100%; overflow-x: auto; }
.items, .grid { width: 100%; border-collapse: collapse; }
/* фиксированная раскладка: столбцы не «разъезжаются» от длинных значений */
.items { table-layout: fixed; min-width: 620px; }
.items .col-login { width: 16%; }
.items .col-folder { width: 13%; }
.items .col-type { width: 82px; }
.items .col-date { width: 150px; }
.items .col-act { width: 186px; }
.items td, .items th { overflow: hidden; }
.items td:nth-child(4), .items td:nth-child(5) { white-space: nowrap; }
.cell-cut { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.items th, .grid th {
  text-align: left; font-size: 11px; font-weight: 600; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--line); text-transform: uppercase;
  letter-spacing: .4px;
}
.items td, .grid td { padding: 10px; border-bottom: 1px solid #1e242e; vertical-align: middle; }
.items tbody tr { cursor: pointer; }
.items tbody tr:hover { background: #181d25; }
/* ячейка остаётся table-cell: display:flex на <td> сдвигал её рамку относительно соседних */
.items__name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.items__name > .dot { display: inline-block; vertical-align: middle; margin-right: 8px; }
a.iconbtn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; vertical-align: middle; }
.iconbtn--url { color: var(--accent); }
.items__actions { text-align: right; white-space: nowrap; }
.items__actions .iconbtn { margin-left: 4px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.dot--note { background: var(--warn); }
.dot--card { background: #b07cf0; }
.dot--ssh { background: var(--ok); }
.dot--other { background: var(--muted); }

/* ---------- Модальные окна ---------- */

.overlay {
  position: fixed; inset: 0; background: rgba(7, 9, 12, .66);
  display: grid; place-items: center; padding: 20px; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 480px; max-height: 88vh; display: flex; flex-direction: column;
}
.modal--wide { max-width: 860px; }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal__head h2 { margin: 0; }
.modal__body { padding: 18px; overflow: auto; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px 12px; font: inherit; border-bottom: 2px solid transparent;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.callout {
  background: #17202b; border: 1px solid #27384a; border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 8px; margin: 12px 0;
}

.field { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; margin-bottom: 8px; }
.fields:empty { display: none; }

.strength { font-size: 11px; color: var(--muted); }
.s--0, .s--1 { color: var(--err); }
.s--2 { color: var(--warn); }
.s--3, .s--4 { color: var(--ok); }

.gen { display: flex; flex-direction: column; gap: 12px; }
.gen__out {
  background: var(--bg-soft); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 16px; font-size: 15.5px; word-break: break-all; min-height: 54px;
}

.groups { display: flex; flex-direction: column; gap: 12px; }
.groupcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.groupcard__head { display: flex; align-items: center; gap: 10px; }
.groupcard__head .linkbtn { margin-left: auto; }
.groupcard__members { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #212835; border-radius: 20px; padding: 3px 10px; font-size: 11.5px;
}
.chip__x { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; }
.chip__x:hover { color: var(--err); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat__num { font-size: 23.5px; font-weight: 700; }
.stat__label { color: var(--muted); font-size: 11px; }

/* ---------- Уведомления ---------- */

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--bg-card); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; max-width: 340px; font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); transition: opacity .35s, transform .35s;
}
.toast--ok { border-left-color: var(--ok); }
.toast--err { border-left-color: var(--err); }
.toast--out { opacity: 0; transform: translateY(6px); }

/* ---------- Адаптивность ---------- */


/* ---------- Второй фактор, служебные классы ---------- */
.is-hidden { display: none; }
.s--good { color: var(--ok); }
.tag--ok { color: var(--ok); border-color: #2a5c47; }
.row--mid { align-items: center; gap: 8px; flex-wrap: wrap; }
.btn--sm { padding: 4px 10px; font-size: 11.5px; }
.secret {
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
  letter-spacing: 0.06em;
  word-break: break-all;
  max-width: 100%;
}
.row--tight { flex-wrap: nowrap; }
.secret--uri { flex: 1 1 auto; min-width: 0; white-space: nowrap; }
.qr {
  display: block;
  width: fit-content;
  margin: 8px 0;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 0;
  max-width: 100%;
}
.qr svg { display: block; width: 240px; max-width: 100%; height: auto; }
.qr--inline { margin-top: 6px; }
.steps { margin: 0 0 12px; padding-left: 20px; line-height: 1.7; }
.steps > li + li { margin-top: 10px; }
.codes {
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  line-height: 1.8;
  letter-spacing: 0.06em;
  white-space: pre-wrap;
}

/* ---------- Шапка папки: владелец и доступы ---------- */

.finfo {
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg-soft);
  padding: 14px 16px; margin-bottom: 16px;
}
.finfo__title { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; min-width: 0; }
.finfo.is-collapsed { padding-top: 10px; padding-bottom: 10px; }
.finfo.is-collapsed .finfo__title { margin-bottom: 0; }
.finfo__title h2 { margin: 0; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finfo__grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; align-items: center; }
.finfo__grid dt { color: var(--muted); font-size: 11.5px; }
.finfo__grid dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  font-size: 11px; color: var(--text); background: #1f2530;
  border: 1px solid var(--line); border-radius: 20px; padding: 2px 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip svg { flex: 0 0 13px; }
.chip .permico { display: inline-block; }
.chip--me { color: #b9f0c9; border-color: #2d4a38; }
.chip--group { color: #9fd8ff; border-color: #2c4459; }
.chip--user { color: #e6d3a3; border-color: #4a4130; }


/* ---------- Избранное ---------- */
.folder__star { color: #f5b301; margin-right: 6px; font-size: 13px; line-height: 1; }
.favbtn {
  background: none; border: 0; padding: 0 6px 0 0; margin: 0;
  color: #5b6677; font-size: 15px; line-height: 1; cursor: pointer;
}
.favbtn:hover { color: #f5b301; }
.favbtn.is-on { color: #f5b301; }
.favbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- Только личные папки (shared_require_totp) ---------- */
.lockednote {
  margin: 8px 4px 4px; padding: 9px 10px; border-radius: 8px;
  background: rgba(245, 179, 1, 0.08); border: 1px solid rgba(245, 179, 1, 0.35);
  color: #d9c79a; font-size: 12.5px; line-height: 1.45;
}
.lockednote b { display: block; color: #f3d98b; margin-bottom: 2px; }
.lockednote .linkbtn { display: inline-block; margin-top: 6px; color: var(--accent); font-weight: 600; }

/* ---------- Письмо-приглашение ---------- */
.mailnote { margin-top: 8px; font-size: 13px; }
.mailnote--ok { color: var(--good, #4ade80); }
.mailnote--err { color: var(--danger, #f87171); }
.checkline, .form--inline .checkline {
  flex-direction: row; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text); align-self: center; white-space: nowrap; cursor: pointer;
}
.checkline input { width: auto; margin: 0; }

/* ---------- Перенос записи мышью ---------- */
.items tr[draggable="true"] { cursor: grab; }
.items tr.is-dragged td { opacity: .45; }
body.is-dragging .sidebar .folder[data-depth] { outline: 1px dashed #2c3646; outline-offset: -2px; }
.sidebar .folder.is-drop-ok { background: #16324f; outline: 2px solid var(--accent); outline-offset: -2px; }
.sidebar .folder.is-drop-denied { background: #3a1e1e; outline: 2px solid var(--err); outline-offset: -2px; cursor: not-allowed; }
.dragghost {
  position: fixed; top: -1000px; left: -1000px; z-index: 9999;
  display: flex; align-items: center; gap: 8px; max-width: 320px;
  padding: 7px 12px; border-radius: 8px; background: #232b38; color: var(--text);
  border: 1px solid var(--accent); font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.movebox { display: flex; flex-direction: column; gap: 12px; }
.movebox__item { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; }
.movebox__grid { display: grid; grid-template-columns: 70px 1fr; gap: 10px 12px; align-items: start; }
.movebox__label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding-top: 3px; }
.movebox__from, .movebox__to { padding: 8px 10px; border-radius: 8px; border: 1px solid #2a3240; background: #161b23; }
.movebox__to { border-color: #27384a; background: #17202b; }
.movebox__path { font-weight: 600; word-break: break-word; }
.movebox__meta { color: var(--muted); font-size: 12px; margin-top: 3px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.movebox .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.callout--warn { background: #2a2115; border-color: #5a4320; }
.callout--warn > span:first-child { color: #ffd59a; }
.movebox__perm { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }

/* ---------- Сведения о папке, шестерёнка, кнопка «Добавить» ---------- */
.finfo__toggle {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  background: none; border: 0; padding: 2px 4px 2px 0; margin: 0; color: var(--text); font: inherit; cursor: pointer;
}
.finfo__toggle:hover h2 { color: var(--accent); }
.finfo__toggle:focus-visible { outline: 2px solid var(--accent-dim); outline-offset: 2px; border-radius: 6px; }
.finfo__toggle .folder__twisty { color: var(--muted); width: 12px; flex: 0 0 12px; }
.finfo__gear { display: inline-flex; align-items: center; justify-content: center; padding: 5px 7px; }
.finfo__gear[aria-expanded="true"] { color: var(--accent); border-color: var(--accent-dim); }
.dropdown { position: relative; flex-shrink: 0; }
.dropdown__list { min-width: 200px; }
.dropdown__list--left { left: 0; right: auto; }
.usermenu__item:disabled { opacity: .45; cursor: not-allowed; }
.usermenu__item:disabled:hover { background: transparent; color: inherit; }
.splitbtn { display: inline-flex; }
.splitbtn__main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.splitbtn__caret {
  border-top-left-radius: 0; border-bottom-left-radius: 0; padding-left: 9px; padding-right: 9px;
  border-left: 1px solid rgba(255, 255, 255, .28);
}
.finfo__grid[hidden] { display: none; }

/* ============================ Мобильный вид (до 860 px) ============================ */

/* элементы мобильного вида на компьютере не видны */
.mbar, .mnav, .drawer-backdrop, .subrows, .items__icon, .splitbtn__fab { display: none; }

.tile {
  width: 40px; height: 40px; border-radius: 10px; flex: 0 0 40px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 17px; color: #fff; letter-spacing: 0;
}
.tile--0 { background: #3b6fd8; } .tile--1 { background: #2f9e6e; }
.tile--2 { background: #c2553a; } .tile--3 { background: #8a55d6; }
.tile--4 { background: #c9881c; } .tile--5 { background: #1f8fa8; }
.tile--6 { background: #c4467a; } .tile--7 { background: #5f6f86; }
.tile--folder { background: #233247; color: var(--accent); }

@media (max-width: 860px) {
  body { overscroll-behavior-y: none; }
  .layout { display: block; min-height: 100vh; min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .main { display: flex; flex-direction: column; min-height: 100vh; }

  /* шапка: ☰ · ‹ · название · поиск */
  .mbar {
    display: flex; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 30;
    padding: calc(6px + env(safe-area-inset-top)) 6px 6px; background: var(--bg-soft); border-bottom: 1px solid var(--line);
  }
  .mbar__title {
    flex: 1; min-width: 0; margin: 0; text-align: center; font-size: 17px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #m-back + .mbar__title { text-align: left; }
  .mbar__btn {
    width: 42px; height: 42px; flex: 0 0 42px; display: inline-flex; align-items: center; justify-content: center;
    background: none; border: 0; border-radius: 10px; color: var(--text); cursor: pointer;
  }
  .mbar__btn:active, .mbar__btn.is-on { background: #232b38; color: var(--accent); }

  /* меню пользователя открывается кнопкой «Аккаунт» снизу */
  .menubar { padding: 0; border: 0; height: 0; overflow: visible; }
  .usermenu__btn { display: none; }
  .usermenu__list {
    position: fixed; left: 10px; right: 10px; top: auto; bottom: calc(72px + env(safe-area-inset-bottom));
    min-width: 0; z-index: 60;
  }

  /* поиск — по кнопке-лупе; «Добавить» превращается в круглую кнопку «+» */
  .topbar { padding: 0; border: 0; gap: 0; }
  .topbar .search { display: none; }
  .topbar.is-msearch { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .topbar.is-msearch .search { display: block; width: 100%; max-width: none; font-size: 16px; }
  .topbar__actions { position: static; }
  .splitbtn__main, .splitbtn__ico { display: none; }
  .splitbtn__caret {
    position: fixed; right: 18px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 35;
    width: 58px; height: 58px; padding: 0; border-radius: 50%; border: 0;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 22px rgba(30, 90, 200, .45);
  }
  .splitbtn__fab { display: block; font-size: 32px; line-height: 1; font-weight: 300; margin-top: -2px; }
  #addmenu-list {
    position: fixed; right: 18px; left: auto; top: auto; bottom: calc(146px + env(safe-area-inset-bottom));
    min-width: 220px; z-index: 60;
  }

  /* выдвижная панель папок */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 45; height: auto;
    width: min(86vw, 330px); transform: translateX(-102%); transition: transform .22s ease;
    padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(14px + env(safe-area-inset-bottom));
    box-shadow: 12px 0 30px rgba(0, 0, 0, .4);
  }
  .layout.is-drawer .sidebar { transform: none; }
  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 44; background: rgba(5, 7, 10, .6);
    opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  .layout.is-drawer .drawer-backdrop { opacity: 1; pointer-events: auto; }
  .resizer { display: none; }
  .sidebar .folder { padding: 11px 10px; }

  /* содержимое */
  .content { padding: 10px 10px 90px; overflow: visible; }
  .finfo { margin-bottom: 10px; }
  .finfo__grid { grid-template-columns: 1fr; }
  .form--grid { grid-template-columns: 1fr; }
  .empty { margin: 36px auto; padding: 0 12px; }
  .empty--subs { display: none; }

  /* подпапки строками */
  .subrows { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
  .subrow {
    display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 6px;
    background: none; border: 0; border-top: 1px solid var(--line); color: var(--text); font: inherit; text-align: left; cursor: pointer;
  }
  .subrow:first-child { border-top: 0; }
  .subrow:active { background: #1a212c; }
  .subrow__text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .subrow__text b { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .subrow__text small { color: var(--muted); font-size: 12.5px; }
  .subrow__meta { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

  /* записи: плитка · название / логин · кнопки */
  .tablewrap { overflow: visible; }
  .items { min-width: 0; table-layout: auto; display: block; }
  .items colgroup, .items thead { display: none; }
  .items tbody { display: block; }
  .items tr {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "icon name act" "icon login act";
    column-gap: 12px; row-gap: 1px; align-items: center; padding: 9px 6px; border-bottom: 1px solid var(--line);
  }
  .items tr:active { background: #1a212c; }
  .items td { display: none; padding: 0; border: 0; }
  .items td.items__icon { display: block; grid-area: icon; }
  .items td.items__name { display: flex; grid-area: name; align-self: end; font-size: 15px; min-width: 0; }
  .items td.items__login { display: block; grid-area: login; align-self: start; font-family: inherit; font-size: 12.5px; color: var(--muted); }
  .items td.items__actions { display: flex; grid-area: act; gap: 6px; align-items: center; }
  .items td.items__name > span:not(.dot) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .items td.items__name .dot { display: none; }
  /* звёздочка — справа от названия, только у избранных */
  .items td.items__name .favbtn { order: 2; margin-left: 6px; }
  .items td.items__name .favbtn:not(.is-on) { display: none; }
  .items__actions .iconbtn { margin: 0; min-width: 38px; height: 38px; padding: 0 10px; justify-content: center; display: inline-flex; align-items: center; }
  .items__actions [data-copy="user"] { display: none; }
  .items tr[draggable="true"] { cursor: pointer; }

  /* окна — снизу, как «лист» */
  .overlay { place-items: end center; padding: 0; }
  .modal, .modal--wide { max-width: 100%; max-height: 94vh; max-height: 94dvh; border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  input, select, textarea { font-size: 16px; } /* без автоувеличения в iOS */

  /* нижняя навигация */
  .mnav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--bg-soft); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .mnav__tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 62px;
    background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer;
  }
  .mnav__tab.is-active { color: var(--accent); }
  .toasts { left: 12px; right: 12px; bottom: calc(150px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
}
.items__sub { display: none; }
@media (max-width: 860px) { .items__sub { display: inline; font-family: var(--font, inherit); } }

/* жест «назад»: стрелка у левого края, растёт вместе с движением пальца */
.swipeback {
  position: fixed; left: 6px; top: 50%; z-index: 70; width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
  background: #232b38; color: var(--muted); border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .4); transform: translate(0, -50%);
}
.swipeback.is-ready { background: var(--accent); color: #fff; border-color: var(--accent); }

/* приложение на экране «Домой»: статус-бар поверх страницы — отступы под «чёлку» */
.auth { padding-top: max(24px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  input, textarea, select, .secret, .mono, .gen__out { -webkit-user-select: text; user-select: text; }
}

/* ============================ Окна на телефоне ============================ */
@media (max-width: 860px) {
  /* окно — над нижней панелью, не шире экрана */
  .overlay { grid-template-columns: minmax(0, 1fr); align-items: end; }
  body:has(.mnav) .overlay { bottom: calc(62px + env(safe-area-inset-bottom)); }
  body:has(.mnav) .modal { padding-bottom: 0; max-height: calc(100dvh - 62px - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 12px); }
  .modal, .modal--wide { width: 100%; min-width: 0; }
  .modal__head { padding: 12px 14px; gap: 10px; }
  .modal__head h2 { font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .modal__close { flex: 0 0 auto; width: 36px; height: 36px; }
  .modal__body { padding: 14px; min-width: 0; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .modal__body > * { max-width: 100%; }

  /* вкладки — одной строкой с горизонтальной прокруткой */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px 14px; padding: 0 14px; gap: 2px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; white-space: nowrap; padding: 10px 12px; }

  /* формы в строку — столбиком на всю ширину */
  .form--inline { flex-direction: column; align-items: stretch; gap: 10px; }
  .form--inline > *, .form--inline label, .form--inline input, .form--inline select, .form--inline .btn { width: 100%; }
  .form--inline .checkline { align-self: flex-start; width: auto; }
  .row > .btn { flex: 1 1 auto; }
  .field { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; }
  input, select, textarea { min-width: 0; max-width: 100%; }
  .callout, .hint, p { overflow-wrap: anywhere; }
  .secret, .mono { overflow-wrap: anywhere; word-break: break-all; }
  .modal img, .modal canvas, .modal svg { max-width: 100%; height: auto; }

  /* таблицы в окнах — карточками */
  .grid { display: block; width: 100%; }
  .grid thead { display: none; }
  .grid tbody { display: block; }
  .grid tr {
    display: block; padding: 10px 12px; margin-bottom: 8px;
    border: 1px solid var(--line); border-radius: 10px; background: var(--bg-soft);
  }
  .grid td {
    display: block; padding: 3px 0; border: 0; text-align: right; min-width: 0;
    overflow-wrap: anywhere; font-size: 13px;
  }
  .grid td::after { content: ''; display: table; clear: both; }
  .grid td[data-label]::before {
    content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 11.5px; padding-top: 1px;
  }
  .grid td:first-child { text-align: left; font-size: 14px; font-weight: 600; padding-bottom: 6px; }
  .grid td:first-child::before { display: none; }
  .grid td:first-child .muted, .grid td:first-child .small { font-weight: 400; }
  .grid td:empty { display: none; }
  .grid td:last-child:not(:first-child) { padding-top: 6px; }
  .grid td select { width: auto; max-width: 62%; }
}

/* скрытый блок QR-кода не должен показываться пустым белым квадратом */
.qr.is-hidden { display: none; }
@media (max-width: 860px) {
  .grid td, .grid td * { white-space: normal; }
}

/* приложение для iOS: адрес сервера на экране входа, без выделения интерфейса */
.auth__server { margin: 14px 0 0; font-size: 12px; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.is-app body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.is-app input, .is-app textarea, .is-app select, .is-app .secret, .is-app .mono, .is-app .gen__out { -webkit-user-select: text; user-select: text; }

/* вход по Face ID (приложение для iOS) */
.bio-btn { width: 100%; }
.bio-title { margin: 22px 0 8px; font-size: 15px; padding-top: 16px; border-top: 1px solid var(--line); }
