/* ========================================================================
   Editorial Luxury — административный кабинет (Asymmetrical Bento)
   ======================================================================== */

:root {
  --bg: #FDFBF7;
  --bg-deep: #F5F1E8;
  --bg-card: #FFFFFF;
  --bg-shell: rgba(28, 26, 23, 0.04);
  --ink: #1C1A17;
  --ink-soft: #4A4540;
  --ink-deep: #1C1A17;
  --primary: #6B6053;
  --primary-top: #7C7164;
  --primary-bottom: #5A5147;
  --primary-hover: #524A40;
  --muted: #6B6356;
  --hairline: rgba(28, 26, 23, 0.08);
  --hairline-strong: rgba(28, 26, 23, 0.14);
  --sage: #3D5A40;
  --sage-soft: #E8EEE5;
  --tan: #8B6F47;
  --tan-soft: #F2EBDF;
  --rust: #8B3A2C;
  --rust-soft: #F5E5E0;
  --shell-pad: 0.375rem;
  --shell-radius: 1.75rem;
  --core-radius: calc(var(--shell-radius) - var(--shell-pad));
  --ease-fluid: cubic-bezier(0.32, 0.72, 0, 1);

  --serif: "Iowan Old Style", "Palatino Linotype", "Palatino", "Book Antiqua", Georgia, serif;
  --sans: "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  position: relative;
  min-height: 100dvh;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
  opacity: 0.5;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
}

@media (max-width: 768px) {
  main { padding: 1.5rem 1rem 3rem; }
}

/* ---- Typography ---- */

h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2rem, 4.5vw, 3rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin: 0;
  color: var(--ink);
}

h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.5rem;
  letter-spacing: -0.005em;
  margin: 0 0 1rem;
}

h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 500;
  margin: 2rem 0 0.875rem;
}

p, label, small, input, textarea, button, select { font-family: var(--sans); }

small {
  color: var(--muted);
  font-size: 0.875rem;
  letter-spacing: 0.01em;
}

.eyebrow {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-deep);
  border: 1px solid var(--hairline);
  font-size: 0.625rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

/* ---- Top bar (floating glass pill) ---- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 2.5rem;
  padding: 0.5rem 0.5rem 0.5rem 1.25rem;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 14px 40px -22px rgba(28, 26, 23, 0.18);
}

.top h1 {
  font-size: 1.15rem;
  font-family: var(--sans);
  font-weight: 500;
  letter-spacing: -0.01em;
}

.top nav {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.top nav a {
  display: inline-block;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 999px;
  transition: background 500ms var(--ease-fluid), color 500ms var(--ease-fluid);
}

.top nav a:hover { background: var(--bg-deep); color: var(--ink); }

.top nav form { display: inline; margin: 0; }

.top nav button {
  font-size: 0.95rem;
  padding: 0.6rem 1rem;
  background: var(--bg-deep);
  color: var(--ink-soft);
  border: 1px solid var(--hairline);
  box-shadow: none;
  margin: 0;
}
.top nav button:hover { background: var(--primary); color: var(--bg); }

@media (max-width: 768px) {
  .top { flex-direction: column; align-items: stretch; border-radius: 1.5rem; padding: 1rem; }
  .top nav { justify-content: flex-end; }
}

/* ---- Flash messages ---- */

.flash { list-style: none; margin: 0 0 1.5rem; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.flash li {
  padding: 0.9rem 1.2rem;
  border-radius: 0.875rem;
  font-size: 0.95rem;
  border: 1px solid transparent;
  animation: fade-up 600ms var(--ease-fluid) both;
}
.flash-success { background: var(--sage-soft); color: var(--sage); border-color: rgba(61, 90, 64, 0.18); }
.flash-error   { background: var(--rust-soft); color: var(--rust); border-color: rgba(139, 58, 44, 0.18); }
.flash-info    { background: var(--bg-deep);   color: var(--ink-soft); border-color: var(--hairline); }

/* ---- "Создать ссылку" — большая editorial-карточка ---- */

.new-link {
  background: var(--bg-shell);
  padding: var(--shell-pad);
  border-radius: var(--shell-radius);
  border: 1px solid var(--hairline);
  margin: 0 0 2.5rem;
}

.new-link > * {
  background: var(--bg-card);
  border-radius: var(--core-radius);
  padding: 2rem 2.25rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 18px 40px -24px rgba(28, 26, 23, 0.15);
}

.new-link > h2 {
  margin: 0;
  font-size: 1.6rem;
  border-radius: var(--core-radius) var(--core-radius) 0 0;
  padding-bottom: 0.5rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.new-link form {
  border-radius: 0 0 var(--core-radius) var(--core-radius);
  padding-top: 1rem;
  margin: 0;
}

.new-link form p { margin: 0 0 1.25rem; }

@media (max-width: 768px) {
  .new-link > h2 { padding: 1.5rem 1.25rem 0.5rem; font-size: 1.3rem; }
  .new-link form { padding: 1rem 1.25rem 1.5rem; }
}

/* ---- Dashboard bento (asymmetric grid) ---- */

.dashboard {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 960px) {
  .dashboard { grid-template-columns: 1fr; }
}

/* ---- Left column: link list ---- */

.link-list {
  background: var(--bg-shell);
  padding: var(--shell-pad);
  border-radius: var(--shell-radius);
  border: 1px solid var(--hairline);
  position: sticky;
  top: 1rem;
}

.filters {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-card);
  padding: 0.3rem;
  border-radius: 999px;
  margin-bottom: var(--shell-pad);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  flex-wrap: wrap;
}

.filters a {
  flex: 1;
  text-align: center;
  padding: 0.65rem 0.6rem;
  border-radius: 999px;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-decoration: none;
  transition: background 500ms var(--ease-fluid), color 500ms var(--ease-fluid);
}

.filters a:hover { color: var(--ink); }
.filters a.active {
  background: linear-gradient(180deg, var(--primary-top) 0%, var(--primary-bottom) 100%);
  color: var(--bg);
  box-shadow: 0 6px 16px -8px rgba(28, 26, 23, 0.35);
}

.links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--shell-pad);
}

.link-card a {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name status"
    "meta badge";
  align-items: center;
  gap: 0.45rem 0.75rem;
  background: var(--bg-card);
  padding: 1rem 1.125rem;
  border-radius: var(--core-radius);
  text-decoration: none;
  color: var(--ink);
  border: 1px solid transparent;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 8px 20px -14px rgba(28, 26, 23, 0.12);
  transition: transform 500ms var(--ease-fluid), border-color 500ms var(--ease-fluid), box-shadow 500ms var(--ease-fluid);
}

.link-card a strong {
  grid-area: name;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.3rem;
  letter-spacing: -0.005em;
  line-height: 1.1;
}

.link-card a:hover { transform: translateX(2px); border-color: var(--hairline); }

.link-card.selected a {
  background: linear-gradient(180deg, var(--primary-top) 0%, var(--primary-bottom) 100%);
  color: var(--bg);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 14px 30px -16px rgba(28, 26, 23, 0.4), 0 1px 0 rgba(255, 255, 255, 0.08) inset;
}
.link-card.selected a small { color: rgba(253, 251, 247, 0.65); }
.link-card.selected a strong { color: var(--bg); }

.link-card a small {
  grid-area: meta;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
  font-style: italic;
}

/* ---- Status chip ---- */

.status {
  grid-area: status;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-weight: 500;
  display: inline-block;
}
.status-active  { background: #C8E0BE; color: #1F3A22; border: 1px solid rgba(31, 58, 34, 0.18); }
.status-expired { background: #F4D89E; color: #5C4419; border: 1px solid rgba(92, 68, 25, 0.2); }
.status-closed  { background: #F2C5BC; color: #6B2418; border: 1px solid rgba(107, 36, 24, 0.2); }

.link-card.selected a .status { border-color: rgba(255, 255, 255, 0.18); }
.link-card.selected a .status-active  { background: #93C28A; color: #142919; }
.link-card.selected a .status-expired { background: #E2B86F; color: #3F2C0E; }
.link-card.selected a .status-closed  { background: #DEA095; color: #3F1308; }

/* ---- Unread badge ---- */

.badge {
  grid-area: badge;
  justify-self: end;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  min-width: 1.6rem;
  text-align: center;
}
.link-card.selected a .badge { background: var(--bg); color: var(--ink); }

/* ---- Right column: dialog ---- */

.dialog {
  background: var(--bg-shell);
  padding: var(--shell-pad);
  border-radius: var(--shell-radius);
  border: 1px solid var(--hairline);
  min-height: 24rem;
}

.dialog > * {
  background: var(--bg-card);
  border-radius: var(--core-radius);
  padding: 2rem 2.25rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 18px 40px -24px rgba(28, 26, 23, 0.15);
}

.dialog .empty {
  font-style: italic;
  padding: 6rem 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-radius: var(--core-radius) var(--core-radius) 0 0;
  margin-bottom: var(--shell-pad);
}

.dialog-head h2 {
  font-size: 2.1rem;
  margin: 0;
  flex: 1;
}

.dialog-head small { font-size: 0.9rem; letter-spacing: 0.02em; }

/* ---- Link info: copy URL row ---- */

.link-info {
  display: flex;
  align-items: end;
  gap: 0.75rem;
  border-radius: 0;
  margin-bottom: var(--shell-pad);
}

.link-info label {
  flex: 1;
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.link-info input {
  margin-top: 0.4rem;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Source Code Pro", monospace;
  font-size: 0.95rem;
  background: var(--bg-deep);
  border-color: var(--hairline);
}

.link-info button {
  margin-top: 0;
  flex-shrink: 0;
  padding: 0.75rem 1.2rem;
  font-size: 0.95rem;
}

@media (max-width: 768px) {
  .link-info { flex-direction: column; align-items: stretch; }
  .link-info button { width: 100%; }
}

/* ---- Actions row ---- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
  border-radius: 0;
  margin-bottom: var(--shell-pad);
}

.actions form { margin: 0; display: inline; }
.actions form input[type="hidden"] { display: none; }

.actions details {
  flex: 1;
  min-width: 14rem;
  background: var(--bg-deep);
  border: 1px solid var(--hairline);
  border-radius: 1rem;
  padding: 0.6rem 1rem;
}

.actions details summary {
  cursor: pointer;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  list-style: none;
  padding: 0.3rem 0;
  user-select: none;
}
.actions details summary::-webkit-details-marker { display: none; }
.actions details summary::before { content: "+ "; color: var(--muted); }
.actions details[open] summary::before { content: "− "; }

.actions details form { display: block; padding-top: 0.75rem; }
.actions details label { display: inline-flex; align-items: center; gap: 0.4rem; margin-right: 0.85rem; font-size: 0.95rem; }

.actions > form button {
  background: var(--rust-soft);
  color: var(--rust);
  border: 1px solid rgba(139, 58, 44, 0.2);
  margin-top: 0;
  box-shadow: none;
  padding: 0.75rem 1.2rem;
  font-size: 0.95rem;
}
.actions > form button:hover { background: var(--rust); color: var(--bg); transform: translateY(-1px); }

/* ---- Thread (dialog conversation) ---- */

.dialog .thread {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  border-radius: 0;
  margin-bottom: var(--shell-pad);
}

.dialog .msg {
  max-width: 80%;
  padding: 0.85rem 1.15rem;
  border-radius: 1.125rem;
  font-size: 1rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.dialog .msg small {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.dialog .msg-recipient {
  background: var(--bg-deep);
  align-self: flex-start;
  border: 1px solid var(--hairline);
  border-bottom-left-radius: 0.375rem;
}

.dialog .msg-admin {
  background: linear-gradient(180deg, var(--primary-top) 0%, var(--primary-bottom) 100%);
  color: var(--bg);
  align-self: flex-end;
  border-bottom-right-radius: 0.375rem;
  box-shadow: 0 10px 22px -14px rgba(28, 26, 23, 0.35);
}
.dialog .msg-admin small { color: rgba(253, 251, 247, 0.55); }

/* ---- Photos in admin ---- */

.dialog .photos {
  border-radius: 0;
  margin-bottom: var(--shell-pad);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.875rem;
}

.photo-card {
  margin: 0;
  background: var(--bg-shell);
  padding: var(--shell-pad);
  border-radius: 1.125rem;
  border: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: var(--shell-pad);
}

.photo-card img {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: calc(1.125rem - var(--shell-pad));
  background: var(--bg-deep);
}

.photo-card figcaption {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.625rem 0.75rem 0.75rem;
  background: var(--bg-card);
  border-radius: calc(1.125rem - var(--shell-pad));
}

.photo-card figcaption small { font-size: 0.8rem; }

.photo-card figcaption a {
  font-size: 0.9rem;
  color: var(--ink);
  text-decoration: none;
  padding: 0.55rem 0.85rem;
  background: var(--bg-deep);
  border-radius: 999px;
  text-align: center;
  transition: background 500ms var(--ease-fluid), color 500ms var(--ease-fluid);
}
.photo-card figcaption a:hover { background: var(--ink); color: var(--bg); }

.photo-card figcaption form { margin: 0; display: block; }
.photo-card figcaption form button {
  width: 100%;
  margin: 0;
  font-size: 0.9rem;
  padding: 0.55rem 0.85rem;
  background: transparent;
  color: var(--rust);
  border: 1px solid rgba(139, 58, 44, 0.25);
  box-shadow: none;
}
.photo-card figcaption form button:hover { background: var(--rust); color: var(--bg); }

/* ---- Reply form (in dialog) ---- */

.dialog .reply {
  border-radius: 0 0 var(--core-radius) var(--core-radius);
}

.reply form { margin: 0; }

/* ---- Form base ---- */

textarea, input[type="text"], input[type="password"] {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--bg-card);
  border: 1px solid var(--hairline-strong);
  border-radius: 0.875rem;
  padding: 0.85rem 1rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition: border-color 500ms var(--ease-fluid), box-shadow 500ms var(--ease-fluid);
}
textarea { resize: vertical; min-height: 5.5rem; }

textarea:focus, input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 0 0 4px rgba(28, 26, 23, 0.05);
}

label { display: block; margin: 0 0 0.45rem; font-size: 0.95rem; color: var(--muted); letter-spacing: 0.01em; }

input[type="radio"] { accent-color: var(--ink); margin-right: 0.35rem; }

/* Submit button — pill */

input[type="submit"], button[type="submit"], button:not([type]) {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  background: linear-gradient(180deg, var(--primary-top) 0%, var(--primary-bottom) 100%);
  color: var(--bg);
  border: 0;
  padding: 0.85rem 1.4rem;
  border-radius: 999px;
  cursor: pointer;
  margin-top: 0.75rem;
  letter-spacing: 0.005em;
  transition: transform 500ms var(--ease-fluid), background 500ms var(--ease-fluid), box-shadow 500ms var(--ease-fluid), filter 500ms var(--ease-fluid);
  box-shadow: 0 10px 22px -14px rgba(90, 81, 71, 0.4);
  -webkit-font-smoothing: antialiased;
}

input[type="submit"]:hover, button:hover { transform: translateY(-1px); filter: brightness(0.92); }
input[type="submit"]:active, button:active { transform: scale(0.98); }

/* ---- Scroll entry ---- */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); filter: blur(4px); }
  to   { opacity: 1; transform: translateY(0);    filter: blur(0); }
}

main > * { animation: fade-up 700ms var(--ease-fluid) both; }
main > *:nth-child(2) { animation-delay: 60ms; }
main > *:nth-child(3) { animation-delay: 120ms; }
main > *:nth-child(4) { animation-delay: 180ms; }

@media (prefers-reduced-motion: reduce) {
  main > *,
  .dialog .msg,
  .flash li {
    animation: none !important;
  }
}

/* ---- Auth pages: setup + login (centered editorial card) ---- */

body.auth main {
  max-width: 460px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100dvh;
  padding: 4rem 1.5rem;
}

.auth-card {
  background: var(--bg-shell);
  padding: var(--shell-pad);
  border-radius: var(--shell-radius);
  border: 1px solid var(--hairline);
}

.auth-card > div {
  background: var(--bg-card);
  border-radius: var(--core-radius);
  padding: 2.5rem 2.25rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 26px 50px -28px rgba(28, 26, 23, 0.2);
}

.auth-card h1 {
  font-size: 2rem;
  margin: 0 0 0.625rem;
}

.auth-card p { color: var(--muted); font-size: 0.9rem; margin: 0 0 1.5rem; }

.auth-card form { margin: 0; }

.auth-card form p { margin: 0 0 1rem; color: var(--ink); }

.auth-card form input[type="submit"] { width: 100%; justify-content: center; padding: 0.85rem 1.5rem; }

.error { color: var(--rust); font-size: 0.78rem; display: block; margin-top: 0.3rem; }

/* ---- Native <dialog> modal ---- */

dialog.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(560px, 92vw);
  width: 100%;
  margin: auto;
  color: var(--ink);
}

dialog.modal::backdrop {
  background: rgba(28, 26, 23, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-card {
  background: var(--bg-shell);
  padding: var(--shell-pad);
  border-radius: var(--shell-radius);
  border: 1px solid var(--hairline);
  box-shadow: 0 30px 60px -20px rgba(28, 26, 23, 0.4);
  animation: modal-in 500ms var(--ease-fluid) both;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border-radius: var(--core-radius) var(--core-radius) 0 0;
  padding: 1.4rem 1.75rem 0.5rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.modal-head h2 {
  font-size: 1.7rem;
  margin: 0;
}

.modal-close {
  background: transparent !important;
  color: var(--muted) !important;
  border: 0;
  font-size: 1.6rem !important;
  padding: 0.2rem 0.6rem !important;
  margin: 0 !important;
  line-height: 1;
  box-shadow: none !important;
  cursor: pointer;
  border-radius: 999px;
  transition: background 300ms var(--ease-fluid), color 300ms var(--ease-fluid);
}
.modal-close:hover { background: var(--bg-deep) !important; color: var(--ink) !important; transform: none; }

.modal-body {
  background: var(--bg-card);
  border-radius: 0 0 var(--core-radius) var(--core-radius);
  padding: 1rem 1.75rem 2rem;
  margin: 0 !important;
}

.modal-body p { margin: 0 0 1.25rem; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Button variants ---- */

button.btn-primary,
.top nav button.btn-primary {
  background: linear-gradient(180deg, var(--primary-top) 0%, var(--primary-bottom) 100%);
  color: var(--bg);
  border: 0;
}

button.btn-secondary,
.top nav button.btn-secondary {
  background: var(--bg-deep);
  color: var(--ink-soft);
  border: 1px solid var(--hairline);
  box-shadow: none;
}
button.btn-secondary:hover { background: var(--primary); color: var(--bg); }

button.btn-warn {
  background: var(--tan-soft) !important;
  color: var(--tan) !important;
  border: 1px solid rgba(139, 111, 71, 0.25) !important;
  box-shadow: none !important;
  background-image: none !important;
}
button.btn-warn:hover { background: var(--tan) !important; color: var(--bg) !important; }

button.btn-danger {
  background: var(--rust-soft) !important;
  color: var(--rust) !important;
  border: 1px solid rgba(139, 58, 44, 0.25) !important;
  box-shadow: none !important;
  background-image: none !important;
}
button.btn-danger:hover { background: var(--rust) !important; color: var(--bg) !important; }

button.btn-ghost {
  background: transparent !important;
  color: var(--muted) !important;
  border: 1px solid var(--hairline) !important;
  box-shadow: none !important;
  background-image: none !important;
  font-size: 0.85rem !important;
  padding: 0.5rem 0.95rem !important;
  margin: 0 !important;
}
button.btn-ghost:hover { background: var(--bg-deep) !important; color: var(--ink) !important; }

.radio { display: inline-flex; align-items: center; gap: 0.4rem; margin-right: 0.85rem; font-size: 0.95rem; }

/* ---- Сворачиваемая инструкция ---- */

.help-panel {
  background: var(--bg-shell);
  padding: var(--shell-pad);
  border-radius: var(--shell-radius);
  border: 1px solid var(--hairline);
  margin: 0 0 1.5rem;
  max-width: 36rem;
}

.help-panel > summary {
  list-style: none;
  cursor: pointer;
  background: var(--bg-card);
  padding: 0.95rem 1.5rem;
  border-radius: var(--core-radius);
  font-family: var(--sans);
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink-soft);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition: background 400ms var(--ease-fluid);
}
.help-panel > summary::-webkit-details-marker { display: none; }
.help-panel > summary::before {
  content: "?";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  background: var(--bg-deep);
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--muted);
  flex-shrink: 0;
  border: 1px solid var(--hairline);
  transition: transform 400ms var(--ease-fluid);
}
.help-panel[open] > summary::before {
  content: "×";
  transform: rotate(90deg);
}
.help-panel > summary:hover { background: var(--bg-deep); }

.help-body {
  background: var(--bg-card);
  border-radius: var(--core-radius);
  padding: 0.5rem 2rem 1.5rem;
  margin-top: var(--shell-pad);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 14px 30px -22px rgba(28, 26, 23, 0.12);
}

.help-body ol {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.help-body ol li {
  line-height: 1.55;
  font-size: 0.97rem;
  color: var(--ink-soft);
  padding-left: 0.25rem;
}

.help-body strong {
  font-family: var(--serif);
  font-weight: 400;
  color: var(--ink);
  font-size: 1.05rem;
  letter-spacing: -0.005em;
}

.help-body em {
  font-style: normal;
  background: var(--bg-deep);
  padding: 0.05rem 0.45rem;
  border-radius: 6px;
  font-size: 0.92em;
  color: var(--ink);
  border: 1px solid var(--hairline);
}

@media (max-width: 768px) {
  .help-panel { max-width: 100%; }
  .help-body { padding: 0.5rem 1.25rem 1.25rem; }
}

/* ---- Цветные аватары пользователей ---- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 400;
  flex-shrink: 0;
  border: 1px solid rgba(28, 26, 23, 0.06);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
  text-transform: uppercase;
  letter-spacing: 0;
}

.avatar-lg {
  width: 3.2rem;
  height: 3.2rem;
  font-size: 1.5rem;
}

/* 8 приглушённых editorial-оттенков */
.avatar-0 { background: #E8EEE5; color: #3D5A40; }   /* sage */
.avatar-1 { background: #F2EBDF; color: #8B6F47; }   /* tan */
.avatar-2 { background: #F5E5E0; color: #8B3A2C; }   /* rust */
.avatar-3 { background: #E5E8EE; color: #3F4F70; }   /* dusty blue */
.avatar-4 { background: #EDE5EE; color: #6F4470; }   /* plum */
.avatar-5 { background: #F0EAD5; color: #7C6E2A; }   /* ochre */
.avatar-6 { background: #DDE7E5; color: #2D5550; }   /* deep teal */
.avatar-7 { background: #EAE3DC; color: #6B5447; }   /* warm taupe */

/* В выделенной карточке списка инвертируем для контраста */
.link-card.selected a .avatar {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset;
}

/* В списке аватар встраивается в grid в зону name перед strong */
.link-card a {
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "avatar name status"
    "avatar meta badge";
  gap: 0.45rem 0.85rem;
}
.link-card a .avatar { grid-area: avatar; align-self: center; }

/* ---- Логотип в шапке ---- */

.logo {
  width: 1.4rem;
  height: 1.4rem;
  vertical-align: -0.2rem;
  margin-right: 0.5rem;
}

/* ---- Двухколоночный лейаут диалога: фото слева, чат справа ---- */

.dialog .dialog-body {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 1.6fr;
  gap: var(--shell-pad);
  background: transparent;
  padding: 0;
  box-shadow: none;
  border-radius: 0;
}

.dialog .photos-col,
.dialog .chat-col {
  background: var(--bg-card);
  border-radius: var(--core-radius);
  padding: 1.5rem 1.5rem 1.25rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 18px 40px -24px rgba(28, 26, 23, 0.15);
  margin: 0 !important;
}

.dialog .photos-col h3,
.dialog .chat-col h3 {
  margin-top: 0;
}

.photos-empty,
.thread-empty {
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
  padding: 1.5rem 0.5rem;
  text-align: center;
}

.dialog .chat-col {
  display: flex;
  flex-direction: column;
  min-height: 28rem;
  padding-bottom: 0.75rem;
}

.dialog .chat-col .thread {
  flex: 1;
  overflow-y: auto;
  max-height: 55vh;
  padding-right: 0.5rem;
  margin-bottom: 0.75rem;
  background: transparent !important;
  padding: 0 0.5rem 0 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.dialog .chat-col .thread::-webkit-scrollbar { width: 6px; }
.dialog .chat-col .thread::-webkit-scrollbar-track { background: transparent; }
.dialog .chat-col .thread::-webkit-scrollbar-thumb {
  background: var(--hairline-strong);
  border-radius: 999px;
}

/* ---- Чат-инпут снизу как в мессенджерах ---- */

.chat-input {
  position: sticky;
  bottom: 0;
  background: var(--bg-card);
  padding-top: 0.75rem;
  border-top: 1px solid var(--hairline);
  margin: 0 !important;
}

.chat-input .reply-note {
  display: block;
  color: var(--muted);
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  font-style: italic;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
}

.chat-input-row textarea {
  flex: 1;
  margin: 0;
  resize: none;
  min-height: 2.6rem;
  padding: 0.75rem 1rem;
  border-radius: 1.25rem;
}

.chat-input-row input[type="submit"] {
  margin: 0;
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
}

.dialog .photo-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

@media (max-width: 1100px) {
  .dialog .dialog-body { grid-template-columns: 1fr; }
  .dialog .chat-col { min-height: 20rem; }
  .dialog .chat-col .thread { max-height: 50vh; }
}
