* { box-sizing: border-box; }
html { background: #090909; color-scheme: dark; }
body { margin: 0; min-width: 300px; overflow-x: hidden; }
button, input, textarea, select, dialog { border-radius: 0 !important; }
button, a, select, summary, label[for], [role="button"], [data-clickable="true"] { cursor: pointer; }
input[type="text"], input[type="password"], input[type="url"], textarea { cursor: text; }
button, a, input, textarea, select, [role="button"] { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }

.login-backdrop {
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 34%, rgba(255,255,255,.055), transparent 30%),
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    #090909;
  background-size: auto, 34px 34px, 34px 34px, auto;
}
.login-backdrop::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(9,9,9,.12), rgba(9,9,9,.72));
}
.login-panel {
  position: relative;
  box-shadow: 0 30px 90px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.025) inset;
}
.login-panel::after {
  content: '';
  position: absolute;
  left: 22px;
  right: 22px;
  top: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  pointer-events: none;
}
.login-logo { box-shadow: 0 10px 34px rgba(0,0,0,.42); }

.bookmark-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
@media (min-width: 640px) {
  .bookmark-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
}
@media (min-width: 900px) {
  .bookmark-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
}
@media (min-width: 1024px) {
  .bookmark-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
}

.bookmark-card {
  --accent: #52525b;
  border-color: var(--accent) !important;
  isolation: isolate;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.015);
}
.bookmark-card::before {
  content: '';
  position: absolute;
  z-index: 0;
  right: -34px;
  bottom: -38px;
  width: 112px;
  height: 92px;
  background: var(--accent);
  filter: blur(36px);
  opacity: .28;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.bookmark-card:hover::before { opacity: .42; transform: translate(-4px, -3px) scale(1.06); }
.bookmark-card-content { position: relative; z-index: 1; }

.accent-swatch {
  position: relative;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.14);
  background: var(--swatch);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.accent-swatch:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.5); }
.accent-swatch.is-selected {
  border-color: #f4f4f5;
  box-shadow: 0 0 0 2px #090909, 0 0 0 3px #a1a1aa;
}
.accent-swatch.is-selected::after {
  content: '';
  position: absolute;
  inset: 7px;
  background: rgba(255,255,255,.92);
}

.image-candidates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}
.image-candidate {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #27272a;
  background: #090909;
  transition: border-color .14s ease, background .14s ease, transform .14s ease;
}
.image-candidate:hover { border-color: #71717a; background: #111113; transform: translateY(-1px); }
.image-candidate.is-selected { border-color: #e4e4e7; box-shadow: inset 0 0 0 1px #e4e4e7; }
.image-candidate img { width: 100%; height: 100%; object-fit: contain; padding: 7px; }
.image-candidate-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: none;
  width: 18px;
  height: 18px;
  place-items: center;
  border: 1px solid #d4d4d8;
  background: #f4f4f5;
  color: #09090b;
}
.image-candidate.is-selected .image-candidate-badge { display: grid; }

.dialog-shell[open] { animation: dialog-in 150ms ease-out both; }
.dialog-shell::backdrop { animation: backdrop-in 130ms ease-out both; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

.toast { opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: opacity .15s ease, transform .15s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.category-ghost { opacity: .3; }
.category-chosen { border-color: #52525b !important; }
.bookmark-ghost { opacity: .25; }
.bookmark-chosen { filter: brightness(1.12); }
.bookmark-dragging { cursor: grabbing !important; }
.bookmark-description:empty::after { content: 'Без описания'; color: #3f3f46; }
.bookmark-actions { opacity: 0; pointer-events: none; }
.bookmark-card:hover .bookmark-actions { opacity: 1; pointer-events: auto; }
.image-drop-active { border-color: #71717a !important; background: #101010 !important; }
.image-edit-overlay { opacity: 0; pointer-events: none; }
.group\/image:hover .image-edit-overlay { opacity: 1; pointer-events: auto; }

@media (hover: none), (pointer: coarse) {
  .bookmark-actions {
    opacity: 1;
    pointer-events: auto;
  }

  .image-edit-overlay {
    opacity: 1;
    pointer-events: auto;
    background: linear-gradient(to top, rgba(0,0,0,.65), transparent 48%);
    align-items: end;
    padding-bottom: 10px;
  }
}

@media (max-width: 639px) {
  .dialog-shell { max-height: calc(100dvh - 12px); overflow: auto; }
  .bookmark-grid { gap: 7px; }
  .bookmark-description { display: none; }
  .bookmark-link { padding: 9px; }
  .bookmark-title { font-size: 10px; line-height: 13px; }
  .bookmark-host { font-size: 8px; }
  .bookmark-actions { border-right: 0; border-top: 0; }
  .image-candidates-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 360px) {
  .bookmark-grid { grid-template-columns: 1fr; }
  .image-candidates-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}


/* Stable touch D&D: the drag handle owns the gesture instead of browser pan/zoom. */
.bookmark-drag,
.category-drag {
  touch-action: none !important;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: contain;
}

html.dnd-active,
html.dnd-active body {
  overscroll-behavior: none;
}

html.dnd-active .bookmark-link,
html.dnd-active .add-card {
  pointer-events: none;
}

.sortable-fallback {
  opacity: .96 !important;
  pointer-events: none !important;
  box-shadow: 0 18px 46px rgba(0,0,0,.48) !important;
}

.category-dragging,
.bookmark-dragging {
  cursor: grabbing !important;
}

/* D&D v11: moving clone must track the pointer immediately. */
.bookmark-fallback,
.category-fallback {
  transition: none !important;
  animation: none !important;
  pointer-events: none !important;
  will-change: transform;
  z-index: 2147483000 !important;
  box-shadow: 0 20px 52px rgba(0,0,0,.58) !important;
}

.bookmark-fallback {
  opacity: .98 !important;
}

/* A category drag preview is intentionally header-only. It can only be sorted
   between category sections and never looks like a card inside a bookmark grid. */
.category-fallback {
  height: auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  background: #0b0b0b !important;
  border: 1px solid #3f3f46 !important;
  padding: 8px 10px !important;
}
.category-fallback .bookmark-grid {
  display: none !important;
}
.category-fallback .category-heading {
  border-bottom: 0 !important;
  padding-bottom: 0 !important;
}

/* While a category is being moved, bookmark drop zones do not participate in
   hit-testing. This prevents even a temporary visual insertion into a card grid. */
html.dnd-category-active .bookmark-grid {
  pointer-events: none !important;
}

html.dnd-category-active .bookmark-card,
html.dnd-category-active .add-card {
  pointer-events: none !important;
}

/* D&D v12 — custom Pointer Events implementation.
   The original element is a layout placeholder; a fixed clone follows the pointer. */
.pointer-dnd-running {
  cursor: grabbing !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  overscroll-behavior: none;
}
.pointer-dnd-running * {
  cursor: grabbing !important;
}
.pointer-dnd-origin {
  opacity: .16 !important;
  filter: grayscale(.75) brightness(.8);
}
.pointer-dnd-preview {
  position: fixed !important;
  inset: 0 auto auto 0 !important;
  margin: 0 !important;
  z-index: 2147483000 !important;
  pointer-events: none !important;
  transition: none !important;
  animation: none !important;
  will-change: transform;
  opacity: .98 !important;
  box-shadow: 0 20px 54px rgba(0,0,0,.62) !important;
}
.pointer-bookmark-preview {
  transform-origin: top left;
}
.pointer-category-preview {
  height: auto !important;
  max-height: 58px !important;
  overflow: hidden !important;
  background: #0b0b0b !important;
  border: 1px solid #52525b !important;
}
.pointer-category-preview .bookmark-grid {
  display: none !important;
}
.pointer-category-preview .category-heading {
  border-bottom: 0 !important;
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

/* A category can never visually participate in bookmark hit testing. */
html.dnd-category-active .bookmark-grid,
html.dnd-category-active .bookmark-grid * {
  pointer-events: none !important;
}
