/* ============================================================
   Components — переиспользуемые UI-примитивы:
   Top bar · Tab bar · Buttons · Inputs · Lists · Sheets · etc.
   ============================================================ */

/* ════════════════════════════════════
   TOP BAR
   ════════════════════════════════════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 12px;
  gap: 10px;
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar.with-border { border-bottom: 1px solid var(--border-soft); }
/* Края шапки делят свободное место поровну (flex 1 1 0), поэтому заголовок
   стоит ровно по центру экрана, даже когда справа пусто, а слева кнопка
   «назад». Раньше заголовок центрировался между неравными краями и уезжал
   вправо на полкнопки. */
.topbar .tb-left,
.topbar .tb-right { display: flex; align-items: center; gap: 4px; flex: 1 1 0; }
.topbar .tb-right { justify-content: flex-end; }
.topbar .tb-icon {
  width: 40px; height: 40px;
  border-radius: var(--r-sm);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: background var(--motion-fast) var(--ease);
}
.topbar .tb-icon:active { background: var(--bg-tertiary); }
.topbar .tb-text-btn {
  padding: 0 10px;
  height: 40px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border-radius: var(--r-sm);
}
.topbar .tb-text-btn.primary { color: var(--accent-dark); }
.topbar .tb-title {
  flex: 0 1 auto;
  text-align: center;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.topbar .tb-title .main {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.topbar .tb-title .sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  margin-top: 2px;
}

/* ════════════════════════════════════
   BOTTOM TAB BAR (4 tabs)
   ════════════════════════════════════ */
.tabbar {
  display: flex;
  align-items: stretch;
  padding: 6px 8px calc(14px + var(--safe-bottom));
  gap: 4px;
  background: var(--bg-primary);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.tabbar .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  background: transparent;
  color: var(--text-2);
  font-size: 10px;
  font-weight: 500;
  border-radius: var(--r-sm);
}
.tabbar .tab i { font-size: 22px; line-height: 1; }
.tabbar .tab.active { color: var(--accent-dark); }
.tabbar .tab .ind {
  width: 4px; height: 4px;
  border-radius: 999px;
  background: var(--accent-dark);
  margin-top: 1px;
  opacity: 0;
}
.tabbar .tab.active .ind { opacity: 1; }

/* ════════════════════════════════════
   BUTTONS
   ════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: var(--r-sm);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  transition: transform var(--motion-fast) var(--ease),
              background var(--motion-fast) var(--ease);
  -webkit-user-select: none;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--text-on-acc); }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
/* Та же ловушка, что была в тосте: --dark-deep тёмная тема не переопределяет,
   а --bg-primary затемняет — получался тёмный текст на тёмном фоне. */
.btn.dark { background: #2a2520; color: #f5efe0; }
.theme-dark .btn.dark { background: #3a332c; color: var(--text); }
.btn.danger { background: var(--error); color: #fff; }
.btn.danger-soft { background: rgba(178, 76, 49, 0.12); color: var(--error); }
.btn.full { width: 100%; }
.btn.lg { padding: 14px 20px; font-size: 16px; }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

/* ════════════════════════════════════
   FORM CONTROLS
   ════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input, .textarea, .select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--motion-fast) var(--ease);
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  outline: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input[readonly], .textarea[readonly] { background: var(--bg-secondary); }
.input.with-icon-right { padding-right: 44px; }
.textarea { min-height: 100px; resize: none; line-height: 1.55; }
.select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'><path d='M1 1l5 5 5-5' stroke='%236c6359' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px;
  padding-right: 36px;
}

.input-wrap { position: relative; }
.input-wrap .input-action {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  background: transparent;
}

/* ── Чекбокс с акцентной галочкой ── */
.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.5;
}
.checkbox input { position: absolute; opacity: 0; pointer-events: none; }
.checkbox .box {
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
  transition: background var(--motion-fast) var(--ease),
              border-color var(--motion-fast) var(--ease);
}
.checkbox .box i {
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: scale(0.5);
  transition: all var(--motion-fast) var(--ease);
}
.checkbox input:checked ~ .box {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox input:checked ~ .box i {
  opacity: 1;
  transform: scale(1);
}

/* ── Силомер пароля ── */
.password-meter {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.password-meter > div {
  flex: 1;
  height: 3px;
  border-radius: 999px;
  background: var(--border);
  transition: background var(--motion-fast) var(--ease);
}
.password-meter[data-strength="1"] > div:nth-child(-n+1),
.password-meter[data-strength="2"] > div:nth-child(-n+2),
.password-meter[data-strength="3"] > div:nth-child(-n+3),
.password-meter[data-strength="4"] > div:nth-child(-n+4) {
  background: var(--success);
}
.password-meter[data-strength="1"] > div:nth-child(1) { background: var(--error); }
.password-meter[data-strength="2"] > div:nth-child(-n+2) { background: #b28b58; }

.form-hint  { font-size: 11px; color: var(--text-2); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--error); margin-top: 4px; }
.form-success { font-size: 11px; color: var(--success); margin-top: 4px; }

/* ════════════════════════════════════
   LIST (iOS-стиль)
   ════════════════════════════════════ */
.list {
  background: var(--bg-tertiary);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border-soft);
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  position: relative;
}
.list .row + .row::before {
  content: "";
  position: absolute;
  top: 0; left: 50px; right: 0;
  height: 1px;
  background: var(--border-soft);
}
.row .row-icon {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  color: var(--text-on-acc);
  background: var(--accent);
}
.row .row-icon.gray     { background: #8a8175; }
.row .row-icon.green    { background: #6c9b6c; }
.row .row-icon.blue     { background: #5d8eb4; }
.row .row-icon.purple   { background: #8d7ab2; }
.row .row-icon.peach    { background: var(--accent); }
.row .row-icon.brown    { background: #955c36; }
.row .row-icon.charcoal { background: #3a3228; }
/* Цвет плиток постоянный, а --text-on-acc у каждой темы свой: в ночной
   Матче он тёмно-зелёный, и значок на коричневой или тёмной плитке пропадал.
   На постоянных цветах значок всегда белый. Плитка акцента (peach) идёт за
   темой вместе со своим --text-on-acc. */
.row .row-icon.gray, .row .row-icon.green, .row .row-icon.blue,
.row .row-icon.purple, .row .row-icon.brown, .row .row-icon.charcoal { color: #fff; }
/* Тёмная плитка на тёмном фоне не видна (контраст 1,11–1,13) — ночью
   берём приглушённый тон текста темы. */
.theme-dark .row .row-icon.charcoal { background: var(--text-faint); }

.row .label { flex: 1; min-width: 0; }
.row .label .label-sub {
  display: block;
  font-size: 11px;
  color: var(--text-2);
  font-weight: 400;
  margin-top: 2px;
}
.row .value {
  color: var(--text-2);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.row .chev { color: var(--text-faint); font-size: 18px; }
.list-group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-2);
  font-weight: 600;
  padding: 0 4px 8px;
}

/* ════════════════════════════════════
   CARDS
   ════════════════════════════════════ */
.card {
  background: var(--bg-tertiary);
  border-radius: var(--r-md);
  border: 1px solid var(--border-soft);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: transform var(--motion-fast) var(--ease);
}
.card:active { transform: scale(0.98); }
.card .avatar {
  width: 48px; height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--text-on-acc);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-head);
  font-size: 22px;
  font-weight: 600;
  overflow: hidden;
}
.card .avatar.lg { width: 96px; height: 96px; border-radius: 24px; font-size: 40px; }
.card .body { flex: 1; min-width: 0; }
.card .name {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 18px;
  line-height: 1.2;
}
.card .meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.card .preview {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ════════════════════════════════════
   SHEETS (bottom sheets) + Modal centred
   ════════════════════════════════════ */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 37, 32, 0.42);
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  animation: fadeIn var(--motion-normal) var(--ease);
}
.sheet-backdrop.closing { animation: fadeOut var(--motion-normal) var(--ease) forwards; }
.sheet-backdrop.center { justify-content: center; align-items: center; padding: 24px; }
.sheet {
  background: var(--bg-primary);
  border-radius: 28px 28px 0 0;
  padding: 8px 0 calc(28px + var(--safe-bottom));
  box-shadow: 0 -8px 30px -10px rgba(0, 0, 0, 0.3);
  max-height: 86%;
  display: flex;
  flex-direction: column;
  animation: slideUp var(--motion-normal) var(--ease);
}
.sheet-backdrop.center .sheet {
  border-radius: 22px;
  padding: 20px;
  max-width: 360px;
  width: 100%;
  animation: scaleIn var(--motion-normal) var(--ease);
}
.sheet-backdrop.closing .sheet { animation: slideDown var(--motion-normal) var(--ease) forwards; }
/* Ночью лист был того же цвета, что экран, а тёплое затемнение поверх
   тёмного фона почти ничего не меняет: окно сливалось с экраном (контраст
   1,00–1,08 во всех ночных темах). Поднимаем лист на «поверхность» темы,
   затемняем экран сильнее и обводим край. */
.theme-dark .sheet-backdrop { background: rgba(0, 0, 0, 0.6); }
.theme-dark .sheet {
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-bottom: 0;
}
.theme-dark .sheet-backdrop.center .sheet { border-bottom: 1px solid rgba(255, 255, 255, 0.10); }
.sheet .grip {
  width: 38px; height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 4px auto 12px;
  flex-shrink: 0;
}
.sheet .sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.sheet .sheet-title {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.sheet .sheet-body {
  padding: 14px 20px 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Системная полоса прокрутки в листе выглядит инородно: серый прямоугольник
     во всю высоту поверх тёплой бумаги. Рисуем свою — тонкую и в цвете темы.
     Firefox понимает scrollbar-*, WebKit/Blink — псевдоэлементы. */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  overscroll-behavior: contain;
}
.sheet .sheet-body::-webkit-scrollbar {
  width: 6px;
}
.sheet .sheet-body::-webkit-scrollbar-track {
  background: transparent;
}
.sheet .sheet-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.sheet .sheet-body::-webkit-scrollbar-thumb:active {
  background: var(--text-faint);
}

/* ════════════════════════════════════
   MISC: chips, switches, badges, FAB
   ════════════════════════════════════ */
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 16px 4px;
  margin: 0 -16px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
}
.chip.active {
  background: var(--text);
  color: var(--bg-primary);
  border-color: var(--text);
}

.switch {
  width: 44px; height: 26px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background var(--motion-fast) var(--ease);
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--motion-fast) var(--ease);
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }

.pro-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--text-on-acc);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.pro-pill i { font-size: 11px; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(80px + var(--safe-bottom));
  width: 56px; height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--text-on-acc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow:
    0 8px 24px -4px rgba(var(--accent-dark-rgb), 0.5),
    0 2px 6px -1px rgba(74, 65, 57, 0.2);
  z-index: 9;
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 28px;
  color: var(--text-2);
}
.empty > .empty-icon {
  font-size: 56px;
  color: var(--accent-light);
  margin-bottom: 14px;
}
.empty > .empty-title {
  font-family: var(--font-head);
  font-size: 22px;
  color: var(--text);
  margin-bottom: 6px;
}
.empty > .empty-text {
  font-size: 14px;
  line-height: 1.55;
  max-width: 280px;
}

/* ════════════════════════════════════
   ANIMATIONS
   ════════════════════════════════════ */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to   { opacity: 0; } }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes slideDown {
  to { transform: translateY(100%); }
}
@keyframes scaleIn {
  from { transform: scale(0.94); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
