.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(800px 400px at 10% 0%, rgba(184,134,60,.18), transparent 55%),
    linear-gradient(160deg, #10120f, #1a1c18 55%, #1e221c);
}
/* display:* на .auth-gate/.app перебивает атрибут hidden — без этого экран входа «залипает» */
.auth-gate[hidden],
.app[hidden],
.auth-form[hidden],
[hidden] {
  display: none !important;
}
.auth-card {
  width: min(420px, 100%);
  background: #f4f3ec;
  border: 1px solid rgba(255,255,255,.08);
  padding: 28px 24px 24px;
  color: #1c211b;
}
.auth-brand {
  font-family: "Oswald", sans-serif;
  font-size: 28px;
  letter-spacing: .04em;
  font-weight: 600;
}
.auth-brand span { color: #b8863c; }
.auth-lead {
  margin: 8px 0 18px;
  color: #5b615a;
  font-size: 15px;
  line-height: 1.4;
}
.auth-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.auth-tab {
  appearance: none; border: 1px solid #d9d6c8; background: transparent;
  font: inherit; font-weight: 700; padding: 8px 12px; cursor: pointer; color: #5b615a;
}
.auth-tab.is-on { background: #1c211b; color: #fff; border-color: #1c211b; }
.auth-label {
  font-size: 13px; font-weight: 650; color: #5b615a; margin-bottom: 6px;
}
.login-user-list {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px;
  max-height: 220px; overflow: auto;
}
.login-user-btn {
  appearance: none; width: 100%; text-align: left;
  border: 1px solid #d9d6c8; background: #fff; color: #1c211b;
  font: inherit; font-weight: 650; padding: 12px 14px; cursor: pointer;
}
.login-user-btn:hover { border-color: #8a8778; }
.login-user-btn.is-on {
  background: #1c211b; color: #fff; border-color: #1c211b;
}
#login-user-name {
  background: #f7f6f0;
  font-weight: 650;
}
.auth-form label {
  display: block; font-size: 13px; font-weight: 650; color: #5b615a; margin-bottom: 10px;
}
.auth-form input, .auth-form select {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; padding: 10px 12px; border: 1px solid #d9d6c8; background: #fff;
}
.auth-form .btn { width: 100%; margin-top: 8px; }
.auth-hint { min-height: 1.2em; color: #b3492f; font-size: 14px; margin: 8px 0 0; }
.auth-note { margin: 0 0 10px; color: #5b615a; font-size: 13px; line-height: 1.35; }
.access-view-note {
  margin: 0; padding: 12px 16px 16px; color: #5b615a; font-size: 14px;
  border-top: 1px solid #d9d6c8; background: #fff;
}

.admin-panel {
  display: flex; flex-direction: column; height: 100%; min-height: 0;
  background: #f4f3ec; color: #1c211b; overflow: auto;
}
.admin-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 18px 20px; border-bottom: 1px solid #d9d6c8; background: #fff;
  position: sticky; top: 0; z-index: 2;
}
.admin-head h2 { margin: 0; font-family: "Oswald", sans-serif; font-size: 26px; font-weight: 600; }
.admin-head p { margin: 4px 0 0; color: #5b615a; font-size: 14px; max-width: 52ch; }
.admin-users {
  padding: 16px 20px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.admin-card {
  background: #fff; border: 1px solid #d9d6c8; padding: 14px 16px;
}
.admin-card-top {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  margin-bottom: 12px;
}
.admin-meta { color: #5b615a; font-size: 13px; margin-top: 2px; }
.admin-fields {
  display: grid; grid-template-columns: 1fr 160px; gap: 10px; margin-bottom: 12px;
}
.admin-fields label, .admin-access-row, .admin-pin, .admin-active {
  display: block; font-size: 12px; font-weight: 650; color: #5b615a;
}
.admin-fields input, .admin-fields select,
.admin-access-row select, .admin-pin input {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; padding: 8px 10px; border: 1px solid #d9d6c8; background: #fff;
}
.admin-access {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px;
  margin-bottom: 12px;
}
.admin-note { margin: 0; color: #5b615a; font-size: 13px; }
.admin-actions {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
}
.admin-pin { flex: 1; min-width: 140px; }
.nav-admin { color: #b8863c !important; }

@media (max-width: 860px) {
  .admin-fields { grid-template-columns: 1fr; }
}

.user-card {
  margin: 0 4px;
  padding: 10px 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.06);
  display: flex; flex-direction: column; gap: 2px;
  color: rgba(255,255,255,.85);
  font-size: 13px;
  flex-shrink: 0;
}
.user-card strong { font-size: 14px; color: #fff; }
.user-card #user-title { color: rgba(236,235,228,.75); font-size: 12px; }
.user-card .linkish { margin-top: 6px; align-self: flex-start; }

.nav-item { position: relative; }
.nav-badge {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: #b8863c; color: #111;
  font-size: 11px; font-weight: 800; line-height: 18px; text-align: center;
}

.chat-panel {
  display: flex; flex-direction: column; height: 100%; min-height: 0;
  background: #f4f3ec; color: #1c211b;
}
.chat-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 18px 20px; border-bottom: 1px solid #d9d6c8; background: #fff;
}
.chat-head h2 { margin: 0; font-family: "Oswald", sans-serif; font-size: 26px; font-weight: 600; }
.chat-head p { margin: 4px 0 0; color: #5b615a; font-size: 14px; }
.chat-log {
  flex: 1; overflow: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-msg {
  max-width: min(640px, 92%);
  background: #fff; border: 1px solid #d9d6c8; padding: 10px 12px;
}
.chat-msg.is-mine {
  align-self: flex-end;
  background: #e8efe8;
  border-color: #c5d4c7;
}
.chat-msg-meta {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline;
  font-size: 12px; color: #5b615a; margin-bottom: 4px;
}
.chat-msg-meta strong { color: #1c211b; font-size: 13px; }
.chat-order {
  font-family: "IBM Plex Mono", monospace;
  background: #f1f0e8; padding: 1px 6px;
}
.chat-msg-text { font-size: 15px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.chat-compose {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid #d9d6c8; background: #fff;
}
.chat-compose-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.chat-order-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 650; color: #5b615a;
  background: #f1f0e8; border: 1px solid #d9d6c8; padding: 8px 10px;
  cursor: pointer; white-space: nowrap;
}
.chat-order-chip input { accent-color: #2f5d62; }
.chat-attach-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 52px; height: 42px; padding: 0 10px; flex-shrink: 0;
  border: 1px solid #d9d6c8; background: #f7f6f0; cursor: pointer;
  font-size: 13px; font-weight: 700; color: #1c211b; line-height: 1;
}
.chat-attach-btn:hover { border-color: #8a8778; }
.chat-attach-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.chat-compose input#chat-text {
  flex: 1; min-width: 160px; font: inherit; padding: 12px 14px; border: 1px solid #d9d6c8;
}
.chat-attach-preview {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chat-attach-chip {
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 100%;
  background: #f1f0e8; border: 1px solid #d9d6c8; padding: 6px 8px; font-size: 13px;
}
.chat-attach-chip img {
  width: 44px; height: 44px; object-fit: cover; background: #ddd;
}
.chat-attach-chip span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px;
}
.chat-attach-chip button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-weight: 700; color: #b3492f; padding: 0 4px;
}
.chat-msg-files {
  display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
}
.chat-msg-files a.chat-file-link {
  color: #2f5d62; font-weight: 650; text-decoration: underline; word-break: break-all;
}
.chat-msg-files img.chat-img {
  display: block; max-width: min(360px, 100%); max-height: 280px;
  object-fit: contain; background: #ecebe4; border: 1px solid #d9d6c8; cursor: zoom-in;
}
.chat-lightbox {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10,12,10,.88);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.chat-lightbox[hidden] { display: none !important; }
.chat-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.chat-lightbox button {
  position: absolute; top: 16px; right: 16px;
  appearance: none; border: 1px solid rgba(255,255,255,.3);
  background: rgba(0,0,0,.4); color: #fff; font: inherit; font-weight: 700;
  padding: 8px 12px; cursor: pointer;
}
.install-hint {
  margin: 18px 0 0; color: #5b615a; font-size: 14px;
}

.btn {
  appearance: none; border: 1px solid transparent;
  font: inherit; font-weight: 700; padding: 10px 14px; cursor: pointer;
}
.btn.primary { background: #2f5d62; color: #fff; }
.btn.primary:hover { background: #3d7a80; }
.btn.ghost { background: transparent; border-color: #d9d6c8; color: #1c211b; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: sticky; top: 0; z-index: 5;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    width: 100%; max-height: none; overflow: visible;
  }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
  .context-card, .user-card { display: none; }
  .chat-head { flex-direction: column; }
}
