/* ====== Todoodd: лёгкий планировщик задач ====== */
:root {
  --bg: #f2f4fb;
  --panel: #ffffff;
  --col-bg: #e9ecf6;
  --text: #1e2433;
  --muted: #6b7280;
  --border: #e3e6f0;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-soft: #eef0fe;
  --danger: #ef4444;
  --ok: #10b981;
  --warn: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 24, 40, .07), 0 6px 18px rgba(20, 24, 40, .06);
  --shadow-lg: 0 10px 40px rgba(20, 24, 40, .18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button { font: inherit; }
input, textarea, select { font: inherit; color: inherit; }

.hidden, [hidden] { display: none !important; }

/* ====== Кнопки ====== */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f6f7fd; }
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn-ghost { border: none; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fdecec; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

/* ====== Авторизация ====== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(700px 400px at 15% 10%, #dbe4ff 0%, transparent 60%),
    radial-gradient(700px 500px at 90% 90%, #e9d5ff 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 380px;
  max-width: 100%;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 32px 30px 26px;
}
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-logo h1 { margin: 0; font-size: 26px; letter-spacing: -.5px; }
.auth-tabs { display: flex; background: var(--col-bg); border-radius: 11px; padding: 4px; margin-bottom: 20px; }
.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.auth-tab.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth-card input {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfbfe;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }
.auth-hint { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; border-radius: 9px; font-size: 13px; padding: 8px 12px; margin: 0 0 14px; }

/* ====== Топбар ====== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.3px; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.user-chip {
  margin-left: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
}
@media (max-width: 640px) { .hide-sm { display: none; } }

/* ====== Layout: сайдбар + основная область ====== */
.layout { display: flex; min-height: calc(100vh - 58px); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sidebar {
  width: 240px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.side-group { display: flex; flex-direction: column; gap: 2px; }
.side-title {
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  padding: 0 8px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.side-title .btn { padding: 1px 8px; line-height: 1.4; }
.side-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  border: none;
  background: transparent;
  color: var(--text);
  width: 100%;
  text-align: left;
}
button.side-item { cursor: pointer; font: inherit; }
.side-item:hover { background: var(--accent-soft); }
.side-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.side-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  background: #f1f3fa;
  padding: 1px 7px;
  border-radius: 999px;
}
.side-item.active .side-count { background: #dfe3fb; color: var(--accent); }
.side-item.danger-item .side-count { background: #fee2e2; color: #b91c1c; }
.side-item.danger-item.active { background: #fee2e2; color: #b91c1c; }
.side-item.today-item .side-count { background: #dbeafe; color: #1d4ed8; }
.side-item.today-item.active { background: #dbeafe; color: #1d4ed8; }
.side-item.tomorrow-item .side-count { background: #ede9fe; color: #6d28d9; }
.side-item.tomorrow-item.active { background: #ede9fe; color: #6d28d9; }
.side-item.archive-item .side-count { background: #e5e7eb; color: #4b5563; }
.side-item.archive-item.active { background: #e5e7eb; color: #374151; }
.folder-actions { margin-left: 4px; display: flex; gap: 1px; opacity: 0; transition: opacity .12s; }
.side-item:hover .folder-actions { opacity: 1; }
.folder-actions button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 5px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.3;
}
.folder-actions button:hover { background: #e8ebf7; color: var(--text); }

/* ====== Тулбар доски (поиск) ====== */
.board-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px 0;
  flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 220px; max-width: 480px; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: .55; }
.search-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  padding: 9px 12px 9px 34px;
  background: var(--panel);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.board-toolbar .filter-count { margin-left: auto; }

/* ====== Панель фильтров ====== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.6);
}
.filter-input {
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 5px 9px;
  background: #fbfbfe;
  font-size: 13.5px;
  outline: none;
  max-width: 180px;
}
.filter-input:focus { border-color: var(--accent); }
.filter-date { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }
.filter-date .filter-input { max-width: 150px; }
.filter-check { display: flex; align-items: center; gap: 5px; font-size: 13.5px; color: var(--muted); cursor: pointer; user-select: none; }
.filter-check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.filter-sep { color: var(--border); font-weight: 700; }
.filter-count { font-size: 12.5px; color: var(--muted); margin-left: auto; white-space: nowrap; }

.badge.folder { background: #ede9fe; color: #6d28d9; }
.badge.controlled { background: #fef9c3; color: #854d0e; }

/* Галочка «На контроле» в панели задачи */
.control-label {
  display: flex;
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}
.control-label > span:first-child { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }

/* ====== Доска ====== */
.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
  align-items: start;
  max-width: 1400px;
  margin: 0;
  min-height: calc(100vh - 58px);
}
@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .side-group { flex-direction: row; align-items: center; gap: 4px; flex: none; }
  .side-title { padding: 0 6px 0 2px; white-space: nowrap; }
  .side-item { white-space: nowrap; width: auto; }
  .folder-actions { opacity: 1; }
  .filter-bar { padding: 8px 12px; }
  .filter-count { margin-left: 0; width: 100%; order: 99; }
  .board-toolbar { padding: 10px 12px 0; }
}
@media (max-width: 960px) {
  .board { display: flex; overflow-x: auto; padding-bottom: 30px; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
  .column { flex: 0 0 300px; scroll-snap-align: start; }
}

/* ====== Мобильная оптимизация (тач-устройства) ====== */
@media (pointer: coarse) {
  /* Увеличенные тач-зоны */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
  .card-icon-btn { padding: 6px 12px; }
  .filter-input { min-height: 38px; font-size: 16px; } /* 16px — не зумит input на iOS */
  .search-input { min-height: 42px; font-size: 16px; }
  .composer textarea, .desc-area, .chat-form textarea { font-size: 16px; }
  .prop-grid select, .prop-grid input, .modal input, .modal select { min-height: 40px; font-size: 16px; }
  .chip { padding: 8px 14px 8px 10px; }
  .reorder-btns { display: inline-flex; }
  .side-item { padding: 10px 12px; }
}
@media (pointer: fine) {
  .reorder-btns { display: none; } /* на десктопе есть drag-n-drop */
}

/* Safe area (вырезы iPhone) */
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  .board { padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); }
  .toast { bottom: max(24px, env(safe-area-inset-bottom)); }
  .chat-form { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (max-width: 640px) {
  .drawer { width: 100vw; }
  .modal { width: calc(100vw - 24px); }
  .chat-modal { width: 100vw; height: 100vh; height: 100dvh; max-width: 100vw; border-radius: 0; }
  .brand span { font-size: 16px; }
  .user-chip { display: none; }
}

/* ====== Архив ====== */
.archive-col { max-width: 720px; margin: 0 auto; width: 100%; }
.unarchive-btn { color: var(--ok); }
.unarchive-btn:hover { background: #d1fae5; color: #047857; }
.column {
  background: var(--col-bg);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
}
.column-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 10px;
  font-weight: 700;
  font-size: 14px;
}
.column-count {
  background: #dfe3f2;
  border-radius: 999px;
  font-size: 12px;
  padding: 1px 8px;
  color: var(--muted);
}
.col-dot { width: 9px; height: 9px; border-radius: 50%; }
.col-dot.todo { background: #94a3b8; }
.col-dot.doing { background: var(--warn); }
.col-dot.done { background: var(--ok); }
.col-progress {
  height: 4px;
  background: #dfe3f2;
  border-radius: 999px;
  overflow: hidden;
  margin: 0 6px 10px;
}
.col-progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #34d399, var(--ok));
  border-radius: 999px;
  transition: width .3s ease;
}
.column-empty {
  text-align: center;
  color: #97a0b8;
  font-size: 12.5px;
  padding: 14px 6px 10px;
  border: 1.5px dashed #ccd3ea;
  border-radius: 10px;
  margin-bottom: 6px;
}

.cards { flex: 1; display: flex; flex-direction: column; gap: 8px; min-height: 40px; border-radius: 8px; transition: background .12s; }
.cards.drop-active { background: #dfe4fb; outline: 2px dashed #b9c1ee; outline-offset: -2px; }

/* ====== Карточка ====== */
.card {
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  cursor: grab;
  position: relative;
  border-left: 4px solid transparent;
  transition: box-shadow .15s, transform .1s;
}
.card:hover { box-shadow: 0 3px 8px rgba(20,24,40,.1), 0 10px 24px rgba(20,24,40,.08); }
.card.dragging { opacity: .45; transform: rotate(1.5deg); cursor: grabbing; }
.card.is-done .card-title { text-decoration: line-through; color: var(--muted); }
.card.prio-0 { border-left-color: #94a3b8; }
.card.prio-1 { border-left-color: #3b82f6; }
.card.prio-2 { border-left-color: var(--warn); }
.card.prio-3 { border-left-color: var(--danger); }

.card-title { font-weight: 600; word-break: break-word; }
.card-desc {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.badge {
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  background: #f1f3fa;
  color: var(--muted);
}
.badge.due { background: #e0f2fe; color: #0369a1; }
.badge.due-soon { background: #fef3c7; color: #92400e; }
.badge.due-over { background: #fee2e2; color: #b91c1c; }
.badge.assignee { background: var(--accent-soft); color: var(--accent); }
.card-icons { margin-left: auto; display: flex; gap: 6px; color: var(--muted); font-size: 12.5px; align-items: center; }
.card-icon-btn {
  border: none;
  background: #f1f3fa;
  border-radius: 999px;
  padding: 2px 9px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  transition: background .12s, color .12s;
}
.card-icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.card-icon-btn.has-unread { background: var(--accent); color: #fff; }
.card-icon-btn.has-unread:hover { filter: brightness(1.1); }

/* Чипы участников */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px 4px 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: #fbfbfe;
  transition: border-color .12s, background .12s, color .12s;
  user-select: none;
}
.chip input { accent-color: var(--accent); margin: 0; cursor: pointer; }
.chip:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.section-hint { font-weight: 500; text-transform: none; letter-spacing: 0; color: #9aa2b8; }

/* История изменений */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
.history-item {
  background: #f8f9fd;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 13px;
}
.history-action { display: block; word-break: break-word; }
.history-meta { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ====== Inline-композер ====== */
.add-task {
  margin-top: 8px;
  border-radius: 10px;
}
.add-btn {
  width: 100%;
  text-align: left;
  border: 1.5px dashed #c3cae8;
  background: transparent;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: border-color .15s, color .15s;
}
.add-btn:hover { border-color: var(--accent); color: var(--accent); }
.composer {
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer textarea {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  resize: none;
  min-height: 60px;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer-row { display: flex; gap: 6px; align-items: center; }
.composer-row select { flex: 1; }

/* ====== Drawer (панель задачи) ====== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 40, .35);
  z-index: 40;
  animation: fade .18s;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 100vw;
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  z-index: 41;
  display: flex;
  flex-direction: column;
  animation: slide-in .2s ease-out;
}
@media (max-width: 640px) { .drawer { width: 100vw; } }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.drawer-head input.task-title {
  flex: 1;
  border: none;
  outline: none;
  font-size: 18px;
  font-weight: 700;
  background: transparent;
  padding: 4px 6px;
  border-radius: 8px;
}
.drawer-head input.task-title:focus { background: var(--accent-soft); }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 16px; }

.prop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .prop-grid { grid-template-columns: 1fr; } }
.prop-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.prop-grid select, .prop-grid input[type="datetime-local"] {
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  background: #fbfbfe;
  outline: none;
}
.prop-grid select:focus, .prop-grid input:focus { border-color: var(--accent); }

.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 0 0 8px; }
.desc-area {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  min-height: 70px;
  resize: vertical;
  background: #fbfbfe;
  outline: none;
}
.desc-area:focus { border-color: var(--accent); }

/* Файлы */
.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8f9fd;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13.5px;
}
.file-item a { color: var(--accent); text-decoration: none; font-weight: 600; word-break: break-all; }
.file-item a:hover { text-decoration: underline; }
.file-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.file-item .btn-ghost { padding: 4px 8px; margin-left: auto; }
.dropzone {
  border: 1.5px dashed #c3cae8;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Чат по задаче (общие элементы) */
.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-form { display: flex; gap: 8px; }
.chat-form textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  resize: none;
  height: 44px;
  outline: none;
  background: #fbfbfe;
}
.chat-form textarea:focus { border-color: var(--accent); }
.chat-form button { border: none; }

.drawer-footer { padding: 10px 18px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.drawer-meta { font-size: 12px; color: var(--muted); }

/* ====== Модальное окно чата ====== */
.chat-modal {
  width: 580px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  height: min(640px, calc(100vh - 60px));
}
.chat-modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #fbfbfe;
  flex: none;
}
.chat-head-icon {
  width: 38px;
  height: 38px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 11px;
  font-size: 18px;
}
.chat-head-info { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.chat-modal-head .chat-task-title { font-weight: 700; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-modal-head .close-x {
  margin-left: auto;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 8px;
  flex: none;
}
.chat-modal-head .close-x:hover { background: var(--accent-soft); color: var(--text); }
.chat-modal .chat-list { flex: 1; max-height: none; min-height: 0; padding: 16px 20px 8px; }
.chat-modal .chat-form { padding: 10px 20px 16px; margin-top: 0; border-top: 1px solid var(--border); flex: none; }

/* Сообщения чата с аватарами */
.chat-msg { max-width: 85%; display: flex; gap: 9px; align-items: flex-end; }
.chat-msg .avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}
.chat-msg .msg-content { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.chat-msg .msg-meta { font-size: 11.5px; color: var(--muted); padding-left: 2px; }
.chat-msg .msg-body {
  background: #f1f3fa;
  border-radius: 4px 14px 14px 14px;
  padding: 8px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(20,24,40,.05);
}
.chat-msg.own { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.own .msg-content { align-items: flex-end; }
.chat-msg.own .msg-meta { padding-right: 2px; }
.chat-msg.own .msg-body { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-radius: 14px 4px 14px 14px; }
.chat-date-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 6px 0;
}
.chat-date-sep::before, .chat-date-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.chat-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 0; }

/* ====== Модальные окна ====== */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,24,40,.4); z-index: 50; animation: fade .15s; }
.modal {
  position: fixed;
  z-index: 51;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 22px 24px;
}
.modal h2 { margin: 0 0 16px; font-size: 19px; }
.modal .close-x {
  float: right;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 8px;
}
.modal .close-x:hover { background: var(--accent-soft); color: var(--text); }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.modal input, .modal select {
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 8px 11px;
  background: #fbfbfe;
  outline: none;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }
.modal .form-row { display: flex; gap: 10px; }
.modal .form-row > * { flex: 1; }

.tg-box { background: #f8f9fd; border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin: 6px 0 12px; }
.tg-code {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 9px;
  padding: 8px 14px;
  display: inline-block;
  margin: 8px 0;
}
.tg-steps { margin: 0 0 6px; padding-left: 18px; color: var(--muted); font-size: 13.5px; }
.tg-steps li { margin-bottom: 4px; }
.tg-ok { color: var(--ok); font-weight: 700; }
.tg-link { color: var(--accent); }

.users-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 16px; }
.users-table th, .users-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.users-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.role-badge { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.role-badge.admin { background: #fef3c7; color: #92400e; }
.role-badge.user { background: #f1f3fa; color: var(--muted); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
.toggle-row span { font-weight: 600; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: #d6dae8;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .15s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: #1e2433;
  color: #fff;
  padding: 11px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 14px;
  animation: fade .2s;
  max-width: calc(100vw - 40px);
}
.toast.error { background: var(--danger); }

/* Скроллбары */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cdd3e6; border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: #b4bcd8; }
::-webkit-scrollbar-track { background: transparent; }
