:root {
  --glass: rgba(255, 255, 255, 0.74); --glass-strong: rgba(255, 255, 255, 0.9); --line: rgba(37, 42, 64, 0.1);
  --ink: #252a40; --ink-2: #555c78; --ink-3: #868ca6; --wine: #7a2446; --wine-soft: rgba(122, 36, 70, 0.1);
  --blue: #3c6fd8; --blue-soft: rgba(60, 111, 216, 0.12); --green: #1f7a55; --green-soft: rgba(31, 122, 85, 0.12);
  --shadow: 0 10px 30px rgba(70, 80, 140, 0.14);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 15px; line-height: 1.45; }
.sky { position: fixed; inset: 0; z-index: -1; background: linear-gradient(170deg, #9dbbe9 0%, #c3d3f1 40%, #efd2de 80%, #f7ddd4 100%); }
[hidden] { display: none !important; }
.glass { background: var(--glass); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3); border: 1px solid rgba(255, 255, 255, .8); box-shadow: var(--shadow); }
.muted { color: var(--ink-2); } .tiny { font-size: 12.5px; color: var(--ink-3); }
.wordmark { font-family: Georgia, "Times New Roman", serif; font-size: 34px; color: var(--wine); white-space: nowrap; }
.wordmark.small { font-size: 24px; }
.wordmark span { font-size: .6em; vertical-align: super; }
.btn { border: 0; border-radius: 999px; padding: 10px 18px; font: inherit; font-weight: 700; cursor: pointer; transition: transform .2s, filter .2s, box-shadow .2s; }
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:active { transform: scale(.97); }
.btn-wine { background: var(--wine); color: #fff; }
.btn-ok { background: var(--green); color: #fff; }
.btn-ghost { background: var(--glass-strong); color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: #fff; color: #b3261e; border: 1px solid rgba(179, 38, 30, .35); }
.btn-sm { padding: 7px 14px; font-size: 14px; }
.error { color: #b3261e; min-height: 1em; margin: 0; }
code { background: var(--wine-soft); padding: 1px 6px; border-radius: 6px; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); border-radius: 28px; padding: 28px; display: grid; gap: 12px; }
.login-card p { margin: 0; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
input, select { font: inherit; font-size: 15px; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, .85); color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--wine); box-shadow: 0 0 0 3px var(--wine-soft); }

/* шапка */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 18px; border-radius: 0 0 22px 22px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-right: auto; }
.tabs button { border: 0; background: transparent; font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 999px; cursor: pointer; color: var(--ink-2); }
.tabs button.on { background: var(--wine); color: #fff; }
.tabs button b { font-weight: 800; margin-left: 2px; }
.filters { display: flex; gap: 8px; padding: 12px 18px; flex-wrap: wrap; align-items: center; }
.filters input { flex: 1 1 240px; }
.filters select { max-width: 260px; }
.keys { margin-left: auto; }

/* список + карточка */
.layout { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 14px; padding: 0 18px 24px; align-items: start; }
.list { display: grid; gap: 8px; max-height: calc(100vh - 150px); overflow: auto; padding: 2px; }
.item { text-align: left; font: inherit; color: inherit; border-radius: 18px; padding: 12px 14px; cursor: pointer; display: grid; gap: 4px; transition: transform .2s, background-color .2s; }
.item:hover { transform: translateX(3px); background: var(--glass-strong); }
.item.on { outline: 2px solid var(--wine); background: var(--glass-strong); }
.item b { font-size: 15px; }
.item .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--ink-3); }
.item .snip { font-size: 13px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--wine-soft); color: var(--wine); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.grey { background: rgba(37, 42, 64, .07); color: var(--ink-2); }

.detail { border-radius: 26px; padding: 22px; position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; }
.empty-detail { text-align: center; padding: 40px 0; }
.d-head { display: grid; gap: 10px; }
.d-name { font-size: 22px; font-weight: 800; border: 1px dashed transparent; padding: 4px 8px; margin-left: -8px; background: transparent; width: calc(100% + 8px); }
.d-head select { max-width: 100%; }
.d-name:hover { border-color: var(--line); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; margin: 6px 0; }
.facts dt { color: var(--ink-3); } .facts dd { margin: 0; word-break: break-word; }
.facts a { color: var(--wine); font-weight: 600; }
.facts.edit { align-items: center; }
.facts.edit input, .facts.edit select, .facts.edit textarea { width: 100%; padding: 7px 11px; font-size: 14px; border-radius: 12px; }
textarea { font: inherit; border: 1px solid var(--line); background: rgba(255, 255, 255, .85); color: var(--ink); outline: none; resize: vertical; }
textarea:focus { border-color: var(--wine); box-shadow: 0 0 0 3px var(--wine-soft); }
.with-link { display: flex; gap: 8px; align-items: center; }
.with-link input { flex: 1; min-width: 0; }
.mini { font-size: 13px; white-space: nowrap; }
.alts { display: flex; gap: 6px; flex-wrap: wrap; }
.alts button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: rgba(255, 255, 255, .8); border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.alts button:hover { border-color: var(--wine); color: var(--wine); }
.actions { position: sticky; bottom: -22px; margin: 16px -22px -22px; padding: 14px 22px; background: var(--glass-strong); border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; border-radius: 0 0 26px 26px; }

/* переписка */
h3 { margin: 18px 0 8px; font-size: 16px; }
.thread { border-radius: 18px; padding: 12px; margin-bottom: 10px; background: rgba(255, 255, 255, .55); border: 1px solid var(--line); display: grid; gap: 6px; }
.thread-head { font-size: 12.5px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; }
.msg { border-radius: 14px 14px 14px 4px; padding: 8px 11px; background: #fff; max-width: 92%; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg small { display: block; font-weight: 800; font-size: 12px; margin-bottom: 2px; color: var(--ink-2); }
.msg.before { background: rgba(255, 255, 255, .6); color: var(--ink-2); }
.msg.question { background: #eef3ff; }
.msg.question small { color: var(--blue); }
.msg.advice { justify-self: end; border-radius: 14px 14px 4px 14px; background: #fdeef3; }
.msg.advice small { color: var(--wine); }
.tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; margin-left: 6px; }
.warn { color: #9a5b00; font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #252a40; color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow); z-index: 20; }

.back { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .list { max-height: none; }
  .detail { position: fixed; inset: 0; z-index: 10; border-radius: 0; max-height: none; }
  .detail.hidden-mobile { display: none; }
  .keys { display: none; }
  .back { display: inline-flex; margin-bottom: 8px; }
  .actions { gap: 6px; }
  .actions .btn { padding: 9px 13px; font-size: 14px; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}
