:root {
  --bg: #0d0d0f;
  --surface: #16161a;
  --border: #2a2a2e;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --accent: #dc145c;
  --accent-dim: rgba(220, 20, 92, 0.25);
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --font: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
}

/* Главный экран */
.home-screen {
  text-align: center;
  padding: 24px 0 32px;
}

.home-logo-wrap {
  margin-bottom: 28px;
}

.home-logo-avatar-wrap {
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
}

.home-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.home-logo-avatar {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #dc145c 0%, #e11d48 100%);
}

.home-logo {
  font-size: 2.5rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #dc145c 0%, #e11d48 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
}

.home-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 320px;
  margin: 0 auto;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 280px;
  margin: 0 auto;
}

.home-btn {
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.home-btn-primary {
  background: linear-gradient(135deg, #dc145c 0%, #e11d48 100%);
  border: none;
  color: #fff;
}

.main-wrap {
  animation: fadeIn 0.25s ease;
}

.header {
  position: relative;
  text-align: center;
  padding: 16px 0 20px;
  border-bottom: 1px solid var(--border);
}

.back-to-home {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px 8px;
}
.back-to-home:hover {
  color: var(--text);
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #dc145c 0%, #e11d48 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.content {
  position: relative;
  min-height: 200px;
}

.panel {
  display: none;
  animation: fadeIn 0.25s ease;
}

.panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.filter-row label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.filter-row select {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.feed-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chats-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chat-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.chat-item:last-child {
  border-bottom: none;
}

.chat-item:hover,
.chat-item:active {
  background: var(--border);
}

.chat-item-title {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-preview {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-date {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.card-author-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}

.avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}

.hide {
  display: none !important;
}

.card-author-info {
  flex: 1;
}

.card-author-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.card-author-link {
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
}

.card-category {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
}

.card-description {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 10px;
  white-space: pre-wrap;
}

.card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.card-meta span + span::before {
  content: " · ";
  opacity: 0.7;
}

.loading, .empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.create-form label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.create-form input,
.create-form select,
.create-form textarea {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.create-form input::placeholder,
.create-form textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.create-form textarea {
  resize: vertical;
  min-height: 100px;
}

.btn {
  padding: 14px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.05s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, #dc145c 0%, #e11d48 100%);
  color: #fff;
  margin-top: 8px;
}

.btn-primary:hover {
  opacity: 0.95;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.result-message {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.95rem;
}

.result-message.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.result-message.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--danger);
  color: #fff;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.profile-view {
  padding: 8px 0;
}

.profile-view .profile-avatar-wrap {
  margin-bottom: 12px;
}

.profile-view .profile-avatar-wrap .avatar {
  width: 72px;
  height: 72px;
}

.profile-view .profile-name {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.profile-view .profile-username {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.profile-view .profile-role {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
}

.profile-view .profile-bio,
.profile-view .profile-contact {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 8px;
}

.profile-view .btn-edit {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

.profile-form {
  margin-top: 8px;
}

.profile-avatar-edit {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}

.profile-avatar-edit .avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.profile-avatar-edit .avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-url-input {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.file-upload-label {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
}

.file-upload-label input {
  display: none;
}

/* Модальное окно профиля пользователя — по умолчанию скрыто (в WebView [hidden] может не работать) */
#user-profile-modal {
  display: none !important;
}
#user-profile-modal.modal-open {
  display: flex !important;
}

#chat-modal {
  display: none !important;
}
#chat-modal.chat-modal-open {
  display: flex !important;
}

.chat-modal-content {
  max-width: 360px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
}
.chat-modal-title {
  font-size: 1rem;
  margin: 0 28px 12px 0;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-messages {
  flex: 1;
  min-height: 200px;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  word-break: break-word;
  align-self: flex-start;
  background: var(--border);
  color: var(--text);
}
.chat-msg--mine {
  align-self: flex-end;
  background: var(--accent-dim);
  color: var(--text);
}
.chat-msg-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.chat-input:focus {
  outline: none;
  border-color: var(--accent);
}
.chat-send {
  flex-shrink: 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 360px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 8px;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.modal-backdrop {
  cursor: pointer;
}

.modal-content .profile-name { font-size: 1.2rem; margin-bottom: 4px; }
.modal-content .profile-username { margin-bottom: 8px; }
.modal-content .profile-role { margin-bottom: 8px; }
.modal-content .profile-bio { margin-bottom: 8px; }
.modal-content .profile-contact { margin-bottom: 0; }
.modal-content .profile-avatar-wrap { margin-bottom: 12px; }
.modal-content .profile-avatar-wrap .avatar { width: 64px; height: 64px; }

.fatal-error-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.fatal-error-overlay .fatal-error {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  max-width: 320px;
}
.fatal-error p { margin-bottom: 12px; }
.fatal-error p:last-child { margin-bottom: 0; }
.fatal-error-detail {
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-word;
}
.fatal-error-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 16px;
}

.fatal-error-close {
  margin-top: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Отладочный лог (скрыт с экрана, пишем только в /api/debug) */
.debug-log {
  display: none !important;
}

/* Панель менеджера / администратора */
.staff-panel-wrap {
  animation: fadeIn 0.25s ease;
}
.staff-panel-wrap .staff-tabs .tab { flex: 1; }
.staff-panel-wrap .staff-tab-admin { display: none; }
.staff-panel-wrap.is-admin .staff-tab-admin { display: block; }
.staff-panel-section { display: none; min-height: 200px; }
.staff-panel-section.active { display: block; }
.staff-users-list { display: flex; flex-direction: column; gap: 8px; }
.staff-user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.staff-user-card-info { flex: 1; min-width: 0; }
.staff-user-card-name { font-weight: 600; margin-bottom: 2px; }
.staff-user-card-meta { font-size: 0.85rem; color: var(--text-muted); }
.staff-user-card-role { font-size: 0.75rem; color: var(--accent); margin-top: 4px; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.card-actions .btn { font-size: 0.9rem; padding: 8px 12px; }
