/* Wishlist UI. Dark by default, light via [data-theme="light"] on <html>.
   No external fonts or stylesheets: the app works with no internet. */

:root {
  color-scheme: dark;

  --bg: #0f1115;
  --bg-elevated: #161a21;
  --bg-input: #1b2029;
  --surface: #161a21;
  --surface-hover: #1d222b;
  --border: #262c37;
  --border-strong: #333b49;

  --text: #e7eaf0;
  --text-muted: #9aa3b2;
  --text-faint: #6b7280;

  --accent: #8b9cff;
  --accent-hover: #a3b1ff;
  --accent-contrast: #0f1115;
  --danger: #ff6b6b;
  --success: #4ade80;
  --warning: #fbbf24;

  --priority-1: #6b7280;
  --priority-2: #8b9cff;
  --priority-3: #fbbf24;

  /* Badges sit on top of product images, so they carry their own surface. */
  --badge-bg: rgba(15, 17, 21, 0.72);
  --badge-text: #e7eaf0;
  --badge-on-color: #0f1115;

  /* Движение. Одна шкала на весь интерфейс: разнобой длительностей
     читается как неаккуратность быстрее, чем сама анимация как украшение. */
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;
  /* Быстрый старт, мягкое торможение: так движение ощущается отзывчивым,
     а не медленным, при той же длительности. */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --stagger: 26ms;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --sidebar-width: 250px;
  --header-height: 64px;
  --content-max: 1500px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

html[data-theme="light"] {
  color-scheme: light;

  --bg: #f6f7f9;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f0f2f6;
  --border: #e2e5ea;
  --border-strong: #cbd0d8;

  --text: #171a20;
  --text-muted: #5b6472;
  --text-faint: #8b93a1;

  --accent: #4c5fd7;
  --accent-hover: #3c4dc0;
  --accent-contrast: #ffffff;
  --danger: #d64545;
  --success: #16a34a;
  --warning: #b45309;

  --priority-1: #8b93a1;
  --priority-2: #4c5fd7;
  --priority-3: #b45309;

  --badge-bg: rgba(255, 255, 255, 0.9);
  --badge-text: #171a20;
  --badge-on-color: #ffffff;

  --shadow: 0 8px 24px rgba(15, 20, 35, 0.12);
}

* {
  box-sizing: border-box;
}

/* Several controls here are flex/grid items, whose display would otherwise
   beat the [hidden] attribute's UA rule and leave them visible. */
[hidden] {
  display: none !important;
}

/* Вестибулярные расстройства - не редкость, и человек уже сказал системе,
   что движение ему мешает. Это не «необязательная любезность»: анимации
   выключаются целиком, а не смягчаются. Ноль здесь нельзя - события
   transitionend и animationend перестали бы приходить. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

a:hover {
  text-decoration: underline;
}

/* --- Layout ------------------------------------------------------------ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--header-height) minmax(0, 1fr);
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
}

.header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -0.01em;
  margin-right: 8px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  flex: none;
  color: var(--accent);
}

.header-spacer {
  flex: 1;
}

.sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  padding: 18px 14px 32px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
}

.main {
  grid-area: main;
  overflow-y: auto;
  padding: 20px 24px 64px;
}

.main-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* --- Controls ---------------------------------------------------------- */

.search {
  position: relative;
  flex: 0 1 340px;
}

/* Typed selector, so it outranks the generic input rule further down. */
.search input[type="text"] {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.search input[type="text"]:focus {
  border-color: var(--accent);
}

.search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

/* Отклик на нажатие: кнопка «проседает» под пальцем. Это единственная
   анимация, которую замечают именно тогда, когда её нет. */
.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:hover {
  background: var(--surface-hover);
}

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

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

.btn-icon {
  padding: 7px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

select,
input[type="text"],
input[type="url"],
input[type="number"],
textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

/* A select builds its line box differently from an input, so without a shared
   height the two sit at different sizes inside the same form row. */
select,
input[type="text"],
input[type="url"],
input[type="number"] {
  height: 40px;
}

select,
input[type="text"],
input[type="url"],
input[type="number"],
input[type="password"],
textarea {
  transition: border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

textarea {
  resize: vertical;
  min-height: 74px;
}

label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}

/* --- Sidebar ----------------------------------------------------------- */

.side-section {
  margin-bottom: 26px;
}

.side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 6px 8px;
}

.side-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* The filter button and its edit/delete controls are siblings, not nested:
   a button inside a button is invalid markup and swallows the inner click. */
.side-row {
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
}

.side-row:hover {
  background: var(--surface-hover);
}

.side-row-actions {
  display: flex;
  gap: 1px;
  padding-right: 4px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.side-row:hover .side-row-actions,
.side-row:focus-within .side-row-actions {
  opacity: 1;
}

.side-row-actions .btn {
  padding: 5px;
}

.side-row-actions .btn svg {
  width: 14px;
  height: 14px;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  color: var(--text-muted);
}

.side-item .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-item {
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.side-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.side-item .dot {
  transition: transform var(--dur) var(--ease);
}

.side-item:hover .dot,
.side-item.is-active .dot {
  transform: scale(1.35);
}

.side-item.is-active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--text);
  font-weight: 600;
}

.side-item .count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: var(--accent);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px;
}

.chip {
  padding: 4px 10px;
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-muted);
}

.chip {
  transition: background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip:active {
  transform: scale(0.96);
}

.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.segmented {
  display: flex;
  padding: 3px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.segmented button {
  flex: 1;
  padding: 5px 8px;
  font-size: 13px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
}

.segmented button {
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.segmented button.is-active {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

/* --- Stats ------------------------------------------------------------- */

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  margin-bottom: 16px;
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: var(--radius);
  font-size: 14px;
}

.notice svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--warning);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.stats.is-single .stat {
  flex: 0 1 260px;
}

.stat {
  flex: 1 1 150px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  font-weight: 700;
}

.stat-value {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar select {
  width: auto;
  min-width: 150px;
}

.toolbar-label {
  font-size: 13px;
  color: var(--text-faint);
}

/* --- Cards ------------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
  /* Появление: --i ставит JS по позиции в списке. backwards нужен, чтобы
     карточка была прозрачной уже до старта своей задержки, иначе каскад
     превращается в мигание. */
  animation: card-in var(--dur-slow) var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 12%, transparent);
}

/* Картинка чуть наезжает при наведении. Кадрирование уже стоит на .card-media,
   поэтому увеличение не вылезает за скруглённый угол. */
.card-media img {
  transition: transform var(--dur-slow) var(--ease);
}

.card:hover .card-media img {
  transform: scale(1.05);
}

/* Stretched link: one real anchor covering the whole card, so clicking
   anywhere opens the shop. Tags and action buttons sit above it - nesting
   them inside the anchor would be invalid markup and would swallow their
   clicks. */
.card-cover {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.card-tags,
.card-actions {
  position: relative;
  z-index: 2;
}

.card.is-linked {
  cursor: pointer;
}

.card.is-linked:hover {
  border-color: var(--accent);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 20%, transparent);
}

.card.is-linked:hover .card-title {
  color: var(--accent);
}

.card-cover:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
  border-radius: var(--radius);
}

.card.is-purchased {
  opacity: 0.62;
}

.card.is-purchased .card-title {
  text-decoration: line-through;
}

.card-media {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-input);
  overflow: hidden;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-media .placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--text-faint);
}

.card-media .placeholder svg {
  width: 38px;
  height: 38px;
}

.badge {
  position: absolute;
  top: 10px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 650;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--border);
}

.badge-category {
  left: 10px;
}

.badge-priority {
  right: 10px;
}

.badge-bought {
  left: 10px;
  top: auto;
  bottom: 10px;
  background: var(--success);
  color: #0b1a10;
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-title {
  font-weight: 620;
  line-height: 1.35;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-title {
  transition: color var(--dur-fast) var(--ease);
}

.card-title a {
  color: inherit;
}

.card-price {
  font-size: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.card-price.is-unknown {
  color: var(--text-faint);
  font-size: 14px;
  font-weight: 500;
}

.card-notes {
  font-size: 13px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
}

.tag {
  transition: color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.tag:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.tag:active {
  transform: scale(0.94);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.card-actions .spacer {
  flex: 1;
}

.card-host {
  font-size: 12px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Developer panel --------------------------------------------------- */

.promo {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-top: 40px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.promo-logo {
  flex: none;
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.promo-logo {
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.promo-logo:hover {
  border-color: var(--accent);
  transform: translateY(-2px) rotate(-3deg);
}

.promo-logo img {
  transition: transform var(--dur-slow) var(--ease);
}

.promo-logo:hover img {
  transform: scale(1.08);
}

.promo-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.promo-body {
  min-width: 0;
}

.promo-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.promo-text {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
  max-width: 78ch;
}

.promo-badge {
  display: inline-block;
  margin: 10px 0 0;
  padding: 4px 11px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 999px;
}

.promo-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 12px;
}

.promo-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.promo-links a {
  transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.promo-links a:hover {
  color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}

.promo-links svg {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--accent);
}

@media (max-width: 560px) {
  .promo {
    flex-direction: column;
  }
}

/* --- Skeletons --------------------------------------------------------- */

/* Показываются только до первого ответа сервера. Пустая сетка на их месте
   читалась бы как «список пуст», а это другое сообщение. */
.skeleton {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.skeleton-media {
  aspect-ratio: 16 / 10;
}

.skeleton-line {
  height: 12px;
  margin: 12px 14px;
  border-radius: 6px;
}

.skeleton-line.is-short {
  width: 45%;
}

.skeleton-media,
.skeleton-line {
  background: linear-gradient(
      90deg,
      var(--bg-input) 25%,
      var(--surface-hover) 37%,
      var(--bg-input) 63%
    )
    var(--bg-input);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

/* --- Theme switch ------------------------------------------------------- */

/* Класс висит на <html> только те миллисекунды, пока идёт переключение.
   Постоянный transition на цветах сделал бы вялым каждое наведение. */
html.is-theme-switching,
html.is-theme-switching *,
html.is-theme-switching *::before,
html.is-theme-switching *::after {
  transition: background-color var(--dur-slow) var(--ease),
    color var(--dur-slow) var(--ease), border-color var(--dur-slow) var(--ease) !important;
}

#theme-toggle svg {
  transition: transform var(--dur-slow) var(--ease);
}

#theme-toggle:hover svg {
  transform: rotate(35deg);
}

/* --- Empty state ------------------------------------------------------- */

.empty {
  text-align: center;
  padding: 72px 20px;
  color: var(--text-muted);
}

.empty svg {
  width: 52px;
  height: 52px;
  color: var(--text-faint);
  margin-bottom: 14px;
}

.empty h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: var(--text);
}

.empty p {
  margin: 0 0 18px;
}

/* --- Modal ------------------------------------------------------------- */

dialog {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
}

/* Открытие и закрытие без единой строчки JS: allow-discrete позволяет
   анимировать display и overlay, а @starting-style задаёт состояние «до
   появления». Браузер без их поддержки просто показывает диалог сразу. */
dialog {
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease),
    overlay var(--dur) allow-discrete, display var(--dur) allow-discrete;
}

dialog[open] {
  opacity: 1;
  transform: none;
}

@starting-style {
  dialog[open] {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

dialog::backdrop {
  background: rgba(6, 8, 12, 0.62);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--dur) var(--ease), overlay var(--dur) allow-discrete,
    display var(--dur) allow-discrete;
}

dialog[open]::backdrop {
  opacity: 1;
}

@starting-style {
  dialog[open]::backdrop {
    opacity: 0;
  }
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.dialog-body {
  padding: 18px;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
}

.dialog-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.dialog-foot .spacer {
  flex: 1;
}

.field {
  margin-bottom: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.input-with-button {
  display: flex;
  gap: 8px;
}

.dropzone {
  position: relative;
  display: grid;
  transition: border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease),
    opacity var(--dur-fast) var(--ease);
  place-items: center;
  min-height: 150px;
  padding: 16px;
  background: var(--bg-input);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-input));
  transform: scale(1.01);
}

.dropzone.is-busy {
  opacity: 0.6;
  pointer-events: none;
}

.dropzone img {
  max-width: 100%;
  max-height: 240px;
  border-radius: 6px;
  display: block;
}

.dropzone-empty svg {
  width: 30px;
  height: 30px;
  color: var(--text-faint);
}

.dropzone-title {
  margin: 8px 0 4px;
  font-size: 13.5px;
  color: var(--text-muted);
}

.dropzone-sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-faint);
  max-width: 42ch;
}

#image-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.hint {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 5px;
}

.hint.is-error {
  color: var(--danger);
}

.hint.is-success {
  color: var(--success);
}

/* --- Toast ------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  animation: toast-in var(--dur) var(--ease);
  padding: 11px 15px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-width: 340px;
  font-size: 14px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
}

/* Уход проигрывается по классу от JS: элемент нужно убрать из DOM только
   после анимации, иначе она не успеет показаться. */
.toast.is-leaving {
  opacity: 0;
  transform: translateX(16px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

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

.toast.is-success {
  border-left-color: var(--success);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Narrow screens ---------------------------------------------------- */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    /* The header wraps to two rows here, so its track must size to content
       instead of being pinned to --header-height. */
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "header"
      "main";
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    display: none;
  }

  .sidebar.is-open {
    display: block;
    grid-area: main;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .header {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
    gap: 8px;
  }

  .search {
    flex: 1 1 100%;
    order: 5;
  }

  /* Icon-only backup buttons: their labels are what overflow a phone width. */
  #export-btn span,
  #import-btn span {
    display: none;
  }
}

@media (max-width: 420px) {
  .brand span {
    display: none;
  }

  .main {
    padding: 16px 14px 48px;
  }
}

@media (min-width: 861px) {
  .sidebar-toggle {
    display: none;
  }
}

/* Hover is not available on a touch screen, so the row controls stay put. */
@media (hover: none) {
  .side-row-actions {
    opacity: 1;
  }
}
