/* TG Assistant — mobile-first, тёмная Telegram-like тема */
:root {
  --bg: #0e1621;
  --card: #17212b;
  --accent: #2b5278;
  --accent-2: #5288c1;
  --text: #f5f5f5;
  --text-dim: #8b9cad;
  --danger: #e05555;
  --ok: #4fae4f;
  --warn: #d9a13b;
  --radius: 12px;
  --tabbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--text);
  padding: 10px 16px;
  transition: background 0.15s, opacity 0.15s;
}
button:hover { background: var(--accent-2); }
button:disabled { opacity: 0.5; cursor: default; }
button.btn-ghost { background: transparent; color: var(--accent-2); padding: 6px 10px; }
button.btn-ghost:hover { background: rgba(82, 136, 193, 0.12); }
button.btn-danger { background: transparent; color: var(--danger); padding: 6px 10px; }
button.btn-danger:hover { background: rgba(224, 85, 85, 0.12); }

input, select, textarea {
  font: inherit;
  background: #0e1621;
  border: 1px solid #2b3a4a;
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; color: var(--text-dim); font-size: 13px; margin-bottom: 4px; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Экран авторизации / setup ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 22px;
  width: 100%;
  max-width: 420px;
}
.auth-logo {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 18px;
}
.auth-logo span { color: var(--accent-2); }
.auth-steps {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 18px;
}
.auth-steps .step-dot {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 999px;
  background: #0e1621;
}
.auth-steps .step-dot.active { background: var(--accent); color: var(--text); }
.auth-card h2 { margin: 0 0 12px; font-size: 18px; }
.auth-card p.hint { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }
.auth-card ol.instructions {
  color: var(--text-dim);
  font-size: 13px;
  padding-left: 20px;
  margin: 0 0 16px;
}
.auth-card ol.instructions li { margin-bottom: 6px; }
.auth-card button[type="submit"] { width: 100%; margin-top: 4px; }
.auth-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 1em; }

/* ---------- Оболочка ---------- */
.app-shell { min-height: 100vh; }
.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}

/* Шапка со статусом */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid #1c2a38;
  padding: 10px 14px;
}
.header-title { font-weight: 700; font-size: 17px; }
.header-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}
.header-status .st-ok { color: var(--ok); }
.header-status .st-bad { color: var(--danger); }

/* ---------- Нижний tab-bar (мобильные) ---------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid #1c2a38;
  display: flex;
  z-index: 30;
}
.tab-bar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-dim);
  font-size: 11px;
  text-decoration: none;
}
.tab-bar a.active { color: var(--accent-2); }
.tab-bar a svg { width: 22px; height: 22px; }

/* Боковая навигация (десктоп) */
.side-nav { display: none; }

@media (min-width: 768px) {
  .tab-bar { display: none; }
  .app-shell { display: flex; }
  .side-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 220px;
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid #1c2a38;
    padding: 20px 10px;
    position: sticky;
    top: 0;
    height: 100vh;
  }
  .side-nav .nav-brand {
    font-weight: 700;
    font-size: 17px;
    padding: 6px 12px 18px;
  }
  .side-nav .nav-brand span { color: var(--accent-2); }
  .side-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-dim);
    text-decoration: none;
  }
  .side-nav a svg { width: 20px; height: 20px; }
  .side-nav a.active { background: var(--accent); color: var(--text); }
  .main-column { flex: 1; min-width: 0; }
  .view { padding-bottom: 40px; }
}

/* ---------- Карточки ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-weight: 600; margin-bottom: 4px; }
.card-meta { color: var(--text-dim); font-size: 12px; margin-bottom: 8px; }
.card-text { white-space: normal; word-wrap: break-word; }
.card-text ul { margin: 6px 0; padding-left: 20px; }
.card-text p { margin: 6px 0; }
.card-text strong { color: var(--text); }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--text);
  margin-right: 6px;
}
.badge.badge-muted { background: #253446; color: var(--text-dim); }
.badge.badge-high { background: var(--danger); }
.badge.badge-low { background: #253446; color: var(--text-dim); }

/* Фильтры / вкладки */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar select, .toolbar input { width: auto; flex: 1; min-width: 0; }

.tabs {
  display: flex;
  gap: 4px;
  background: #101a24;
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
}
.tabs button {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  padding: 8px;
}
.tabs button.active { background: var(--accent); color: var(--text); }

/* ---------- Задачи ---------- */
.task-card { display: flex; gap: 10px; align-items: flex-start; }
.task-card input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--accent-2);
  flex-shrink: 0;
}
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; }
.task-card.done .task-title { text-decoration: line-through; color: var(--text-dim); }
.task-details { color: var(--text-dim); font-size: 13px; margin-top: 2px; word-wrap: break-word; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.task-meta .due.overdue { color: var(--danger); font-weight: 600; }
.task-actions { display: flex; flex-direction: column; gap: 2px; }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  background: var(--accent-2);
  z-index: 25;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
@media (min-width: 768px) { .fab { bottom: 24px; right: 24px; } }

/* Модальное окно */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
@media (min-width: 768px) { .modal-overlay { align-items: center; } }
.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
}
@media (min-width: 768px) { .modal { border-radius: var(--radius); } }
.modal h3 { margin: 0 0 14px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ---------- Диалоги ---------- */
.dialog-row { display: flex; align-items: center; gap: 10px; }
.dialog-info { flex: 1; min-width: 0; }
.dialog-info .card-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.dialog-controls select { width: auto; padding: 6px 8px; font-size: 13px; }

.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: #253446;
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--text); }

/* ---------- Настройки ---------- */
.settings-section { margin-bottom: 22px; }
.settings-section h3 { margin: 0 0 10px; font-size: 15px; color: var(--accent-2); }
.status-line { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }

/* ---------- Пустые состояния ---------- */
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 48px 20px;
  font-size: 14px;
}
.empty .empty-icon { font-size: 36px; margin-bottom: 10px; }

/* ---------- Скелетоны ---------- */
.skeleton {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.skeleton .sk-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #1c2a38 25%, #253446 50%, #1c2a38 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  margin-bottom: 10px;
}
.skeleton .sk-line:last-child { margin-bottom: 0; }
.sk-w40 { width: 40%; }
.sk-w70 { width: 70%; }
.sk-w100 { width: 100%; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Toast ---------- */
.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}
.toast {
  background: #253446;
  border-left: 3px solid var(--accent-2);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease-out;
}
.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-ok { border-left-color: var(--ok); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.load-more-wrap { text-align: center; margin: 6px 0 20px; }
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--text-dim);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
