:root {
  --bg: #050509;
  --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: radial-gradient(circle at top, #020617 0, #020617 28%, #020617 40%, #020617 100%);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 20px);
  position: relative;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: -80px;
  z-index: -1;
  background:
    radial-gradient(circle at 0% 0%, rgba(220,20,92,0.16), transparent 55%),
    radial-gradient(circle at 100% 0%, rgba(59,130,246,0.18), transparent 55%),
    radial-gradient(circle at 50% 100%, rgba(236,72,153,0.16), transparent 55%);
  filter: blur(30px);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#home {
  margin-top: auto;
  margin-bottom: auto;
}

#main {
  margin-top: 0;
  margin-bottom: 0;
}

/* Главный экран */
.home-screen {
  position: relative;
  text-align: center;
  padding: 24px 0 32px;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(248, 250, 252, 0.08);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.85),
    0 0 0 1px rgba(15, 23, 42, 0.8);
}

.home-screen::before {
  content: "";
  position: absolute;
  inset: -40px;
  /* Яркое размытие логотипа на фоне */
  background:
    radial-gradient(circle at top, rgba(220,20,92,0.6), rgba(15,23,42,0.98)),
    url("/static/logo.png?v=1") center/260px 260px no-repeat;
  filter: blur(24px);
  opacity: 0.9;
  transform: scale(1.2);
  z-index: 0;
}

.home-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  /* Светлое «стекло» поверх размытого фона, более прозрачное */
  background:
    radial-gradient(circle at top, rgba(248, 250, 252, 0.12), transparent 55%),
    linear-gradient(to bottom, rgba(15, 23, 42, 0.32), rgba(15, 23, 42, 0.70));
  backdrop-filter: blur(40px) saturate(135%);
  -webkit-backdrop-filter: blur(40px) saturate(135%);
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.7);
  z-index: 0;
}

.home-logo-wrap {
  margin-bottom: 28px;
  position: relative;
  z-index: 1;
}

.home-logo-avatar-wrap {
  width: 88px;
  height: 88px;
  margin: 0 auto 18px;
  position: relative;
  border-radius: 50%;
  padding: 2px;
  background: radial-gradient(circle at 10% 0%, #f97316, #dc145c 40%, #6366f1 90%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

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

.home-logo-avatar {
  display: none;
}

.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;
  position: relative;
  z-index: 1;
}

.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-new-layout {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  padding: 16px;
}

.card-new-layout .card-left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.card-new-layout .card-profile-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.card-new-layout .card-avatar {
  flex-shrink: 0;
}

.card-new-layout .card-author-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.card-new-layout .card-author-link:hover {
  color: var(--accent);
}

.card-new-layout .card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 2px 0 6px;
  color: var(--text);
}

.card-new-layout .card-description {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-new-layout .card-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
  margin-top: auto;
}

.card-new-layout .card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.card-new-layout .card-category {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.card-new-layout .card-price {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.card-new-layout .card-chat-btn {
  margin-top: 4px;
}

.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-open */
  display: none !important;
}

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

.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; }

.tab-with-lock { display: flex; align-items: center; gap: 4px; flex: 1; }
.tab-with-lock .tab { flex: 1; }
.btn-icon.btn-lock { flex-shrink: 0; width: 40px; height: 40px; padding: 0; border-radius: 8px; font-size: 1.2rem; background: var(--surface); border: 1px solid var(--border); cursor: pointer; color: var(--text-muted); }
.btn-icon.btn-lock:hover { color: var(--text); background: var(--border); }
.home-btn-row { display: flex; align-items: center; gap: 8px; width: 100%; }
.home-btn-row .home-btn { flex: 1; }
.home-btn-row .home-lock { flex-shrink: 0; width: 44px; height: 44px; }
#access-modal { display: none !important; }
#access-modal.modal-open { display: flex !important; }
.access-modal-hint { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 16px; }
.access-after-submit { margin-top: 16px; }
.access-after-submit p { margin-bottom: 12px; }
.access-status-block { margin-top: 12px; padding: 12px; background: var(--bg); border-radius: var(--radius); font-size: 0.9rem; }
