/* Ключница — стальной шкаф с латунными бирками для ключей. */

:root {
  --bg: #e4e9ed;
  --surface: #f6f8f9;
  --surface-2: #eef2f4;
  --ink: #1b2730;
  --muted: #566774;
  --line: #c6d0d7;
  --brass: #8a6420;          /* текст и акценты — контраст ≥ 4.5:1 на surface */
  --brass-fill: #c39a48;     /* заливка бирок и главной кнопки */
  --brass-ink: #22190a;
  --ok: #2b6a5c;
  --warn: #9a5b12;
  --danger: #a1372a;
  --focus: #2d6fa3;
  --digit: #2b6a9e;
  --symbol: #a1372a;

  --tag-0: #c39a48; --tag-1: #8fa98a; --tag-2: #9bb1c4;
  --tag-3: #c7a29a; --tag-4: #b3a6c4; --tag-5: #a9b8a3;

  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas, "DejaVu Sans Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171c;
    --surface: #182129;
    --surface-2: #1e2932;
    --ink: #e0e7ec;
    --muted: #94a5b2;
    --line: #2c3a45;
    --brass: #d7b067;
    --brass-fill: #c9a253;
    --brass-ink: #1b1305;
    --ok: #6fb8a5;
    --warn: #e0a457;
    --danger: #e48273;
    --focus: #7ab4e2;
    --digit: #7ab4e2;
    --symbol: #e48273;
    --tag-0: #b8913f; --tag-1: #6f8a6a; --tag-2: #6f8aa2;
    --tag-3: #a57d74; --tag-4: #8c7fa3; --tag-5: #7f9278;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brass); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.015em; margin: 0 0 .5rem; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 650; margin: 0 0 .5rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

/* ---------- Верхняя панель ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .75rem max(16px, calc((100vw - 920px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: 1.05rem; color: var(--ink); text-decoration: none;
}
.brand-mark { width: 28px; height: 28px; color: var(--brass); }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a {
  color: var(--muted); text-decoration: none; padding: .35rem .6rem; border-radius: var(--radius);
}
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--brass-fill); border-radius: 0; }
.logout { display: flex; align-items: center; gap: .5rem; margin: 0; }
.who { color: var(--muted); font-size: .9rem; }

.main { max-width: 920px; margin: 0 auto; padding: 2rem 16px 4rem; }
.lead { color: var(--muted); max-width: 62ch; margin: 0 0 1.5rem; }
.hint { color: var(--muted); font-size: .9rem; max-width: 62ch; margin: 0 0 1rem; }
.aside { color: var(--muted); margin-top: 1.25rem; }
.back { margin: 0 0 .75rem; }
.back a { color: var(--muted); text-decoration: none; }
.back a:hover { color: var(--ink); }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; padding: .45rem .9rem;
  font: inherit; font-size: .95rem; font-weight: 550; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brass-fill); border-color: var(--brass-fill); color: var(--brass-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--brass-fill); }
.btn-danger { color: var(--danger); border-color: currentColor; background: transparent; }
.btn-danger:hover { background: var(--danger); color: var(--surface); border-color: var(--danger); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }
.btn-quiet-danger:hover { color: var(--danger); }
.btn-wide { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--muted); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.icon-btn:hover { color: var(--ink); background: var(--surface-2); border-color: var(--line); }
.icon-btn[aria-pressed="true"] { color: var(--brass); }

/* ---------- Сообщения ---------- */
.flash {
  padding: .65rem .9rem; border-radius: var(--radius); margin: 0 0 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--muted);
}
.flash-ok { border-left-color: var(--ok); }
.flash-error { border-left-color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px);
  padding: .6rem 1rem; border-radius: var(--radius);
  background: var(--ink); color: var(--surface); font-size: .95rem;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Формы ---------- */
.form { display: grid; gap: 1rem; max-width: 560px; }
.field { display: grid; gap: .3rem; }
.field > span, .field > label { font-weight: 550; font-size: .95rem; }
.field small { color: var(--muted); font-size: .85rem; }
input[type="text"], input[type="password"], input[type="search"], textarea {
  width: 100%; min-height: 42px; padding: .5rem .7rem;
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
input:hover, textarea:hover { border-color: var(--muted); }
input:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
textarea { resize: vertical; line-height: 1.45; }
input.mono { font-family: var(--mono); letter-spacing: .02em; }
.pw-wrap { display: flex; gap: .5rem; }
.pw-wrap input { flex: 1; min-width: 0; }
.form-actions { display: flex; gap: .5rem; margin-top: .5rem; }

/* ---------- Вход ---------- */
.auth { max-width: 440px; margin: 3rem auto 0; }
.auth h1 { font-size: 2rem; }

/* ---------- Хранилище ---------- */
.vault-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; }
.vault-head h1 { margin: 0; }
.count { margin: .2rem 0 0; color: var(--muted); }
.warn-text { color: var(--warn); }

.filters { display: grid; gap: .75rem; margin-bottom: 1rem; }
.search { font-size: 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  font: inherit; font-size: .9rem; padding: .25rem .75rem; min-height: 32px;
  color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--muted); }
.chip[aria-pressed="true"] { color: var(--ink); background: var(--surface); border-color: var(--brass-fill); }

.entries {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.entry {
  display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 280px);
  align-items: center; gap: 1rem; padding: .85rem 1rem;
}
.entry + .entry { border-top: 1px solid var(--line); }
.entry:hover { background: var(--surface-2); }

/* Бирка для ключа: срезанные верхние углы и отверстие под кольцо */
.tag {
  position: relative; display: grid; place-items: end center;
  width: 40px; height: 50px; padding-bottom: 6px;
  clip-path: polygon(28% 0, 72% 0, 100% 24%, 100% 100%, 0 100%, 0 24%);
  background: var(--tag-0); color: var(--brass-ink);
  font-weight: 750; font-size: 1.15rem; line-height: 1;
}
.tag::before {
  content: ""; position: absolute; top: 7px; left: 50%; width: 9px; height: 9px; margin-left: -4.5px;
  border-radius: 50%; background: var(--surface); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .25);
}
.entry:hover .tag::before { background: var(--surface-2); }
.tag-c1 { background: var(--tag-1); } .tag-c2 { background: var(--tag-2); }
.tag-c3 { background: var(--tag-3); } .tag-c4 { background: var(--tag-4); }
.tag-c5 { background: var(--tag-5); }

.entry-title { display: block; font-weight: 650; color: var(--ink); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-title:hover { text-decoration: underline; }
.entry-meta { display: flex; flex-wrap: wrap; gap: .15rem .75rem; font-size: .875rem; color: var(--muted); }
.entry-meta a { color: var(--muted); }
.entry-meta a:hover { color: var(--brass); }
.folder::before { content: "▸ "; color: var(--line); }
.badge-warn { color: var(--warn); font-weight: 550; }

.cred { display: grid; gap: .1rem; }
.cred-row { display: flex; align-items: center; gap: .1rem; min-width: 0; }
.cred-value {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: .9rem; color: var(--muted);
}
.secret { font-family: var(--mono); letter-spacing: .08em; }
.secret.revealed { color: var(--ink); letter-spacing: .02em; }

.empty {
  padding: 3rem 1.5rem; text-align: center;
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty p { color: var(--muted); max-width: 48ch; margin: 0 auto 1.25rem; }
.empty .empty-title { color: var(--ink); font-size: 1.2rem; font-weight: 650; margin-bottom: .4rem; }
.empty-search { color: var(--muted); padding: 1.5rem 0; }

/* ---------- Генератор ---------- */
.gen {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; max-width: 720px;
}
.gen-box { max-width: 720px; }
.gen-box .gen { border-color: var(--brass-fill); }
.gen-display { border-bottom: 1px solid var(--line); padding-bottom: 1rem; margin-bottom: 1rem; }
.gen-out {
  display: block; min-height: 1.3em;
  font-family: var(--mono); font-size: clamp(1.15rem, 3.2vw, 1.7rem); line-height: 1.3;
  word-break: break-all; letter-spacing: .03em;
  user-select: all;
}
.ch-d { color: var(--digit); }
.ch-s { color: var(--symbol); }
.gen-buttons { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }

.gen-meter { display: grid; gap: .35rem; margin-top: .75rem; }
.gen-meter-bar {
  height: 6px; border-radius: 3px; background: var(--surface-2); position: relative; overflow: hidden;
}
.gen-meter-bar::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px;
  background: var(--danger); transition: width .25s, background-color .25s;
}
.gen-meter[data-level="1"] .gen-meter-bar::after { width: 25%; background: var(--danger); }
.gen-meter[data-level="2"] .gen-meter-bar::after { width: 50%; background: var(--warn); }
.gen-meter[data-level="3"] .gen-meter-bar::after { width: 75%; background: var(--ok); }
.gen-meter[data-level="4"] .gen-meter-bar::after { width: 100%; background: var(--ok); }
.gen-meter-text { font-size: .85rem; color: var(--muted); }
.strength.gen-meter { margin-top: -.5rem; max-width: 560px; }
.field .strength.gen-meter { margin-top: .25rem; }

.gen-options { display: grid; gap: 1rem; }
.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.seg legend { font-weight: 550; font-size: .95rem; margin-bottom: .4rem; padding: 0; }
.seg label, .gen-checks label { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.gen-row { display: flex; align-items: center; gap: .9rem; }
.gen-row label { font-weight: 550; min-width: 3.5rem; }
.gen-row input[type="range"] { flex: 1; max-width: 360px; accent-color: var(--brass-fill); }
.gen-len { font-family: var(--mono); font-weight: 650; min-width: 2ch; }
.gen-checks { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brass-fill); width: 1.05rem; height: 1.05rem; }

/* ---------- Настройки и админка ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1.5rem; margin-bottom: 1.25rem;
}
.panel > p { max-width: 62ch; }
.panel-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.panel-danger h2 { color: var(--danger); }

.entry-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  max-width: 560px; margin-top: 2rem; padding-top: 1.25rem; border-top: 1px solid var(--line);
}
.dates { color: var(--muted); font-size: .9rem; margin: 0; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.users { width: 100%; border-collapse: collapse; font-size: .95rem; }
.users th, .users td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users th { font-weight: 600; color: var(--muted); font-size: .875rem; }
.users tr:last-child td { border-bottom: 0; }
.users .num { font-variant-numeric: tabular-nums; }
.users .actions-in { display: flex; gap: .25rem; justify-content: flex-end; }
.users .actions-in form { margin: 0; }
.role { font-size: .8rem; color: var(--brass); margin-left: .35rem; }

/* ---------- Мобильные ---------- */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: .5rem 1rem; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; margin: 0 -8px; }
  .nav a { padding: .35rem .5rem; font-size: .95rem; white-space: nowrap; }
  .logout { margin-left: auto; }
  .who { display: none; }
  .main { padding-top: 1.25rem; }
  .vault-head { flex-direction: column; align-items: stretch; }
  .entry { grid-template-columns: auto minmax(0, 1fr); gap: .25rem .9rem; }
  .cred { grid-column: 2; }
  .pw-wrap { flex-wrap: wrap; }
  .pw-wrap input { flex-basis: 100%; }
  .gen-row { flex-wrap: wrap; }
  .users .actions-in { justify-content: flex-start; flex-wrap: wrap; }
}

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