/* ---------------------------------------------------------------------
   Очаг — дизайн-токены
   Идея: тёплый дом в тёмное время суток. Тёмно-синяя ночь снаружи,
   тёплый янтарный свет внутри. Один яркий акцент, всё остальное — тихое.
------------------------------------------------------------------------ */
:root {
  --bg: #12141c;
  --panel: #191c28;
  --panel-alt: #1e2230;
  --bubble-in: #262b3d;
  --bubble-out: #e8a33d;
  --bubble-out-text: #241a06;
  --border: #2a2e42;
  --text-primary: #edeff5;
  --text-secondary: #9aa3b8;
  --text-faint: #6b7488;
  --accent: #e8a33d;
  --accent-strong: #f2b658;
  --danger: #e1604d;
  --danger-strong: #ea7c6b;
  --success: #6fcf97;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.screen {
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* ---------------------------------------------------------------------
   Кнопки
------------------------------------------------------------------------ */
.btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: var(--bubble-out-text);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-faint); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #1a0d0a; }

.btn-block { width: 100%; }
.btn-small { padding: 6px 12px; font-size: 0.82rem; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--panel-alt); color: var(--text-primary); }

.mobile-only { display: none; }

/* ---------------------------------------------------------------------
   Экран входа
------------------------------------------------------------------------ */
#login-screen {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.login-glow {
  position: absolute;
  width: 640px;
  height: 640px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 163, 61, 0.22) 0%, rgba(232, 163, 61, 0.06) 45%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: 40px 32px;
  text-align: center;
}

.brand {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}

.brand-sub {
  color: var(--text-secondary);
  margin: 0 0 32px;
  font-size: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  margin-bottom: 16px;
}

.field span {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.field input, .modal-field input {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.98rem;
}

.field input:focus, .modal-field input:focus {
  border-color: var(--accent);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 4px 0 16px;
}

.form-error {
  color: var(--danger-strong);
  font-size: 0.85rem;
  margin: -6px 0 14px;
  text-align: left;
}

/* ---------------------------------------------------------------------
   Основной экран: сайдбар + чат
------------------------------------------------------------------------ */
#app-screen {
  display: flex;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
}

.brand-mini {
  font-weight: 700;
  font-size: 1.15rem;
}

.sidebar-actions {
  display: flex;
  gap: 4px;
}

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.room-list-empty {
  color: var(--text-secondary);
  font-size: 0.88rem;
  padding: 24px 12px;
  line-height: 1.5;
}

.room-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 2px;
  text-align: left;
}

.room-item:hover { background: var(--panel-alt); }

.room-item.active {
  background: var(--panel-alt);
  box-shadow: inset 3px 0 0 var(--accent);
}

.room-item-name {
  font-size: 0.96rem;
  font-weight: 600;
}

.room-item-code {
  font-size: 0.78rem;
  color: var(--text-faint);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.me-name {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--panel-alt);
  min-width: 0;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.95rem;
  padding: 24px;
  text-align: center;
}

.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header h2 {
  font-size: 1.05rem;
  margin: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row {
  display: flex;
  justify-content: flex-start;
}

.msg-row.mine { justify-content: flex-end; }

.bubble {
  max-width: min(72%, 480px);
  background: var(--bubble-in);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 9px 13px 7px;
  font-size: 0.94rem;
  line-height: 1.42;
}

.msg-row.mine .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
}

.msg-sender {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-time {
  font-size: 0.68rem;
  opacity: 0.6;
  text-align: right;
  margin-top: 3px;
}

.msg-image, .msg-video {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
}

.msg-audio {
  display: block;
  margin-bottom: 6px;
  max-width: 240px;
}

.msg-file {
  display: block;
  color: inherit;
  text-decoration: underline;
  margin-bottom: 4px;
  word-break: break-all;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.95rem;
  max-height: 140px;
  line-height: 1.4;
}

.composer textarea:focus { border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: var(--bubble-out-text);
}
.send-btn:hover { background: var(--accent-strong); }

#mic-btn.recording {
  color: var(--danger-strong);
  background: rgba(225, 96, 77, 0.15);
}

/* ---------------------------------------------------------------------
   Админка
------------------------------------------------------------------------ */
#admin-screen {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.admin-header h2 { margin: 0; font-size: 1.1rem; }

.admin-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.admin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.admin-card-header h3 { margin: 0; font-size: 1rem; }

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

.storage-track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--panel-alt);
  overflow: hidden;
}

.storage-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}

.storage-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.stat-row {
  display: flex;
  gap: 10px;
}

.stat-chip {
  flex: 1;
  background: var(--panel-alt);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}

.stat-chip span {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
}

.stat-chip label {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-alt);
  border-radius: var(--radius-md);
  flex-wrap: wrap;
}

.admin-row-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-row-name {
  font-weight: 600;
  font-size: 0.92rem;
}

.admin-badge {
  font-size: 0.76rem;
  color: var(--text-secondary);
  background: var(--panel);
  border-radius: 20px;
  padding: 3px 10px;
}

.admin-row-actions {
  display: flex;
  gap: 6px;
}

.admin-empty {
  color: var(--text-faint);
  font-size: 0.88rem;
  padding: 8px 4px;
}

/* ---------------------------------------------------------------------
   Модальные окна и уведомления
------------------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 14, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel-alt);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.modal h3 {
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.modal-section { margin-bottom: 4px; }

.modal-divider {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.8rem;
  margin: 14px 0;
  position: relative;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  max-width: 90%;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger-strong);
}

/* ---------------------------------------------------------------------
   Мобильная раскладка
------------------------------------------------------------------------ */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .chat-pane { display: none; }
  body.room-open .sidebar { display: none; }
  body.room-open .chat-pane { display: flex; }
  .mobile-only { display: inline-flex; }
  .bubble { max-width: 84%; }
}
