/* ============ Base ============ */
*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --radius: 16px;
  --radius-sm: 11px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --topbar-h: 70px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #080a0f;
  --bg-grad: radial-gradient(1100px 600px at 12% -10%, rgba(124, 92, 255, .18), transparent 60%),
             radial-gradient(900px 500px at 95% 0%, rgba(34, 211, 238, .10), transparent 55%);
  --surface: #10151d;
  --surface-2: #161d28;
  --surface-3: #1d2634;
  --border: #222c3b;
  --border-soft: #1a2230;
  --text: #e9eef7;
  --muted: #8b98ad;
  --muted-2: #6b7789;
  --accent: #7c5cff;
  --accent-soft: rgba(124, 92, 255, .16);
  --accent-text: #a48cff;
  --shadow: 0 18px 44px rgba(0, 0, 0, .55);
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, .35);
  --danger: #ff6b6b;
}

:root[data-theme="light"] {
  --bg: #f5f6fb;
  --bg-grad: radial-gradient(1100px 600px at 10% -10%, rgba(124, 92, 255, .13), transparent 60%),
             radial-gradient(900px 500px at 95% 0%, rgba(34, 211, 238, .10), transparent 55%);
  --surface: #ffffff;
  --surface-2: #f4f6fb;
  --surface-3: #eaeef7;
  --border: #e2e7f1;
  --border-soft: #edf0f7;
  --text: #101828;
  --muted: #5f6b80;
  --muted-2: #8792a5;
  --accent: #6244f5;
  --accent-soft: rgba(98, 68, 245, .10);
  --accent-text: #5333e0;
  --shadow: 0 18px 40px rgba(23, 32, 56, .13);
  --shadow-sm: 0 6px 16px rgba(23, 32, 56, .07);
  --danger: #e04141;
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

::selection { background: var(--accent-soft); }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 20px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Topbar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border-soft);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(150deg, var(--accent), #22d3ee 140%);
  color: #fff;
  box-shadow: 0 8px 20px -6px var(--accent);
  flex: none;
}
.brand-mark svg { width: 21px; height: 21px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: -.2px; }
.brand-text small { color: var(--muted); font-size: 11.5px; }

.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  max-width: 560px;
  margin-inline: auto;
}
.search-icon {
  position: absolute; left: 14px;
  width: 17px; height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.search input {
  width: 100%;
  height: 42px;
  padding: 0 46px 0 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.search input::placeholder { color: var(--muted-2); }
.search input:focus {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--border));
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.search kbd {
  position: absolute; right: 11px;
  font: 600 11px/1 var(--font);
  color: var(--muted);
  padding: 5px 7px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 15px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  transition: transform .15s var(--ease), background .18s, border-color .18s, color .18s, box-shadow .18s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, #fff), var(--accent));
  color: #fff;
  box-shadow: 0 10px 24px -12px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn-primary:hover { filter: brightness(1.07); }

.btn-soft {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
}
.btn-soft:hover { background: var(--surface-3); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }

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

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

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  transition: background .18s, color .18s, border-color .18s, transform .15s;
  flex: none;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn:active { transform: scale(.95); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.boxed { width: 42px; height: 42px; }

.mini-btn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
}
.mini-btn:hover { background: var(--surface-3); color: var(--text); }
.mini-btn svg { width: 14px; height: 14px; }

:root[data-theme="dark"] .i-sun,
:root[data-theme="light"] .i-moon { display: none; }
.i-moon, .i-sun { width: 18px; height: 18px; }

/* ============ Layout ============ */
.layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: 28px;
  max-width: 1560px;
  margin: 0 auto;
  padding: 24px 24px 70px;
}

/* ============ Sidebar ============ */
.sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 18px);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 36px);
  overflow-y: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-group { display: flex; flex-direction: column; gap: 2px; }

.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 550;
  text-align: left;
  transition: background .16s, color .16s, border-color .16s;
}
.side-item:hover { background: var(--surface); color: var(--text); }
.side-item.is-active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--text);
}
.side-ico { width: 17px; height: 17px; flex: none; display: grid; place-items: center; }
.side-ico svg { width: 17px; height: 17px; }
.side-item.is-active .side-ico { color: var(--accent-text); }
.side-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted-2);
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: 20px;
  min-width: 22px;
  text-align: center;
}
.side-item.is-active .side-count { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-text); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.cat-row { display: flex; align-items: center; gap: 2px; }
.cat-row .side-item { padding-right: 4px; }
.cat-edit {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: none; border-radius: 7px;
  background: transparent; color: var(--muted-2);
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
  flex: none;
}
.cat-row:hover .cat-edit { opacity: 1; }
.cat-edit:hover { background: var(--surface-3); color: var(--text); }
.cat-edit svg { width: 13px; height: 13px; }

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 11px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.side-foot { margin-top: 12px; padding-top: 6px; border-top: 1px solid var(--border-soft); }
.backup-row { display: flex; gap: 8px; padding: 2px 11px; }
.backup-row .btn { flex: 1; height: 34px; font-size: 12.5px; }
.side-note { margin: 10px 11px 0; font-size: 11.5px; line-height: 1.5; color: var(--muted-2); }

/* ============ Main / toolbar ============ */
.main { min-width: 0; }

.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar-info h1 { margin: 0; font-size: 23px; letter-spacing: -.5px; }
.toolbar-info p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.toolbar-tools { display: flex; align-items: center; gap: 10px; }

.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 8px 0 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}
.select-wrap svg { width: 15px; height: 15px; flex: none; }
.select-wrap select {
  appearance: none;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding-right: 6px;
  cursor: pointer;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.seg-btn {
  width: 32px; height: 30px;
  display: grid; place-items: center;
  border: none; border-radius: 7px;
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.seg-btn svg { width: 15px; height: 15px; }
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--surface-3); color: var(--text); }

/* ============ Letter bar ============ */
.letterbar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 9px 0;
  margin-bottom: 6px;
  background: linear-gradient(var(--bg) 55%, transparent);
}
.letterbar:empty { display: none; }
.letter-btn {
  min-width: 26px;
  height: 26px;
  padding: 0 5px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  transition: all .15s;
}
.letter-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.letter-btn.is-current { background: var(--accent); color: #fff; border-color: transparent; }

/* ============ Letter group ============ */
.group { margin-bottom: 30px; scroll-margin-top: calc(var(--topbar-h) + 58px); }
.group-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
}
.group-letter {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 3px 9px;
  line-height: 1.4;
}
.group-line { flex: 1; height: 1px; background: linear-gradient(90deg, var(--border), transparent); }
.group-count { font-size: 11.5px; color: var(--muted-2); font-weight: 600; }

/* ============ Grid & cards ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: transform .2s var(--ease), border-color .2s, box-shadow .2s;
  animation: cardIn .35s var(--ease) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow);
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cover {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--surface-3);
  overflow: hidden;
  border-bottom: 1px solid var(--border-soft);
}
.cover img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  transition: transform .5s var(--ease), opacity .3s;
  opacity: 0;
}
.cover img.is-loaded { opacity: 1; }
.card:hover .cover img { transform: scale(1.045); }

.cover-fallback {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  font-size: 46px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.03em;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .28);
}
.cover .shade {
  position: absolute;
  inset: auto 0 0 0;
  height: 46%;
  z-index: 2;
  background: linear-gradient(to top, rgba(6, 8, 12, .55), transparent);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}

.card-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  display: flex;
  gap: 6px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .18s, transform .18s;
}
.card:hover .card-tools,
.card:focus-within .card-tools { opacity: 1; transform: none; }

.tool-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(14, 18, 26, .68);
  backdrop-filter: blur(8px);
  color: #eef2f8;
  transition: background .15s, transform .15s, color .15s;
}
.tool-btn:hover { background: rgba(14, 18, 26, .92); transform: scale(1.06); }
.tool-btn svg { width: 14px; height: 14px; }
.tool-btn.is-fav { color: #ffd166; }
.tool-btn.del:hover { color: #ff8b8b; }

.card-body { padding: 12px 14px 14px; }
.card-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -.15px;
  line-height: 1.32;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-host {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}
.card-host img { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.card-host span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-desc {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 650;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--muted);
  max-width: 100%;
}
.chip .dot { width: 6px; height: 6px; }
.chip.cat { color: var(--text); }
.tag-chip { color: var(--muted); }

/* List view */
.is-list .grid { grid-template-columns: 1fr; gap: 10px; }
.is-list .card { display: grid; grid-template-columns: 168px minmax(0, 1fr); }
.is-list .cover { aspect-ratio: auto; height: 100%; min-height: 106px; border-bottom: none; border-right: 1px solid var(--border-soft); }
.is-list .cover-fallback { font-size: 34px; }
.is-list .card-body { padding: 13px 16px; display: flex; flex-direction: column; justify-content: center; }
.is-list .card-title { -webkit-line-clamp: 1; font-size: 15px; }
.is-list .card-desc { -webkit-line-clamp: 1; margin-top: 6px; }
.is-list .card-foot { margin-top: 9px; }

@media (max-width: 620px) {
  .is-list .card { grid-template-columns: 96px minmax(0, 1fr); }
  .is-list .card-desc { display: none; }
}

/* ============ Empty ============ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 70px 20px;
  border: 1px dashed var(--border);
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.empty-art {
  width: 66px; height: 66px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent-text);
  margin-bottom: 16px;
}
.empty-art svg { width: 32px; height: 32px; }
.empty h3 { margin: 0 0 6px; font-size: 17px; }
.empty p { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; max-width: 360px; }

/* ============ Dialogs ============ */
.dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.dialog-sm { width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop {
  background: rgba(4, 6, 10, .62);
  backdrop-filter: blur(4px);
}
.dialog[open] { animation: dialogIn .22s var(--ease); }
@keyframes dialogIn { from { opacity: 0; transform: translateY(12px) scale(.985); } }

.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 14px;
}
.dialog-head h2 { margin: 0; font-size: 18px; letter-spacing: -.3px; }
.dialog-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }

.dialog-body {
  padding: 2px 22px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface-2) 60%, transparent);
}
.dialog-foot .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 12.5px; font-weight: 650; color: var(--muted); }
.field-label b { color: var(--danger); }

.field input[type="text"],
.field input[type="password"],
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  outline: none;
  font-size: 14px;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.field textarea { resize: vertical; min-height: 62px; line-height: 1.5; }
.field select { cursor: pointer; appearance: none; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--border));
  box-shadow: 0 0 0 3.5px var(--accent-soft);
  background: var(--surface);
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted-2); }

.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row > input, .input-row > select { flex: 1; min-width: 0; }
.input-row .btn { height: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.cover-field { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 14px; }
@media (max-width: 560px) { .cover-field { grid-template-columns: 1fr; } }

.cover-preview {
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--surface-2);
  overflow: hidden;
  display: grid;
  place-items: center;
  position: relative;
}
.cover-preview img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.cover-ph { font-size: 12px; color: var(--muted-2); }

.cover-controls { display: flex; flex-direction: column; gap: 8px; }
.cover-controls input {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  outline: none;
  font-size: 13px;
  width: 100%;
}
.cover-controls input:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.cover-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.cover-btns .btn { height: 32px; padding: 0 10px; font-size: 12px; }
.hint { margin: 0; font-size: 11.5px; color: var(--muted-2); line-height: 1.45; }

/* switch */
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; font-weight: 550; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 40px; height: 23px;
  border-radius: 20px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  position: relative;
  transition: background .18s, border-color .18s;
  flex: none;
}
.switch-dot {
  position: absolute;
  top: 2px; left: 2px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .18s var(--ease), background .18s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: transparent; }
.switch input:checked + .switch-track .switch-dot { transform: translateX(17px); background: #fff; }

/* swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
  width: 30px; height: 30px;
  border-radius: 9px;
  border: 2px solid transparent;
  padding: 0;
  position: relative;
  transition: transform .15s, box-shadow .15s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.is-sel { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px currentColor; }

/* ============ Toasts ============ */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-3) 92%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  font-weight: 550;
  animation: toastIn .25s var(--ease);
}
.toast.out { animation: toastOut .22s var(--ease) forwards; }
.toast .t-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.toast.err .t-dot { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ============ Responsive ============ */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; gap: 6px; padding: 16px 16px 60px; }
  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 0 0 12px;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .side-group { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .side-item { white-space: nowrap; padding: 7px 12px; border-radius: 20px; background: var(--surface); border-color: var(--border); width: auto; }
  .side-item .side-count { display: none; }
  .cat-row { display: flex; }
  .cat-row .side-item { border-radius: 20px; }
  .cat-edit { display: none; }
  .side-head, .side-foot { display: none; }
  .letterbar { top: var(--topbar-h); }
  .chip-name, .profile-chip .chev { display: none; }
  .profile-chip { padding: 0 7px; }
}

@media (max-width: 700px) {
  .topbar { padding: 0 14px; gap: 10px; flex-wrap: wrap; height: auto; padding-block: 10px; position: sticky; }
  .brand-text { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .topbar-actions { margin-left: auto; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 42px; padding: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card-body { padding: 10px 11px 12px; }
  .card-title { font-size: 13.5px; }
  .toolbar-info h1 { font-size: 19px; }
  .letterbar { position: static; }
  .group { scroll-margin-top: 90px; }
  .dialog-head, .dialog-body, .dialog-foot { padding-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}

/* ============ Pantalla de perfiles ============ */
.profiles {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
}
.profiles-wrap { width: 100%; max-width: 720px; text-align: center; }
.profiles-logo { display: flex; justify-content: center; margin-bottom: 22px; }
.profiles-logo .brand-mark { width: 54px; height: 54px; border-radius: 16px; }
.profiles-logo .brand-mark svg { width: 29px; height: 29px; }
.profiles h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -.6px; }
.profiles-sub { margin: 0 auto 34px; max-width: 450px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.profiles-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; }
.profile-card {
  position: relative;
  width: 136px;
  padding: 16px 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border-radius: 18px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  transition: background .18s, border-color .18s, transform .18s;
}
.profile-card:hover,
.profile-card:focus-visible {
  background: var(--surface);
  border-color: var(--border);
  transform: translateY(-3px);
  outline: none;
}
.avatar {
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 38px;
  line-height: 1;
  background: color-mix(in srgb, var(--c, #7c5cff) 22%, var(--surface));
  border: 2px solid color-mix(in srgb, var(--c, #7c5cff) 55%, transparent);
  box-shadow: inset 0 0 24px color-mix(in srgb, var(--c, #7c5cff) 16%, transparent);
  overflow: hidden;
  flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 30px; height: 30px; font-size: 15px; border-width: 1px; }
.avatar.xs { width: 26px; height: 26px; font-size: 14px; border-width: 1px; }
.avatar-add {
  border-style: dashed;
  border-color: var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 30px;
  font-weight: 300;
  box-shadow: none;
}
.profile-name { font-size: 13.5px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-lock {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 15px;
  height: 15px;
  color: var(--muted);
}
.profile-lock svg { width: 15px; height: 15px; }
.profile-edit {
  position: absolute;
  top: 10px;
  left: 12px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: none;
  background: var(--surface-2);
  color: var(--muted);
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.profile-card:hover .profile-edit,
.profile-edit:focus-visible { opacity: 1; }
.profile-edit:hover { color: var(--text); background: var(--surface-3); }
.profile-edit svg { width: 13px; height: 13px; }
.profile-new { border: 1px dashed var(--border); }
.profiles-foot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 34px;
  color: var(--muted-2);
  font-size: 12px;
}
.profiles-foot svg { width: 14px; height: 14px; }

/* ============ Chip de perfil y menú ============ */
.profile-wrap { position: relative; }
.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px 0 7px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  max-width: 190px;
  transition: background .16s, border-color .16s;
}
.profile-chip:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-chip .chev { width: 13px; height: 13px; color: var(--muted); flex: none; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 216px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
}
.menu button:hover { background: var(--surface-2); }
.menu-sep { height: 1px; background: var(--border-soft); margin: 5px 4px; }

/* ============ Contraseña / perfil (diálogos) ============ */
.pass-avatar {
  width: 66px;
  height: 66px;
  margin: 4px auto 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 27px;
  overflow: hidden;
  background: color-mix(in srgb, var(--c, #7c5cff) 20%, var(--surface));
  border: 2px solid color-mix(in srgb, var(--c, #7c5cff) 50%, transparent);
}
.pass-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pass-error { margin: 6px 0 0; font-size: 12.5px; color: var(--danger); }
.shake { animation: shake .34s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
.profile-preview {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  padding: 4px 0 6px;
}
.profile-preview .avatar { width: 84px; height: 84px; font-size: 36px; }
.profile-preview.is-drop .avatar {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}
.avatar-edit {
  position: absolute;
  right: -4px;
  bottom: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 5px 14px -3px rgba(0, 0, 0, .45);
  transition: transform .15s, filter .15s;
}
.avatar-edit:hover { transform: scale(1.08); filter: brightness(1.08); }
.avatar-edit svg { width: 15px; height: 15px; }
.photo-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.photo-row .btn { height: 34px; font-size: 12.5px; }
.photo-row .btn svg { width: 14px; height: 14px; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 18px;
  line-height: 1;
  transition: transform .15s, border-color .15s, background .15s;
}
.emoji-btn:hover { transform: translateY(-2px); }
.emoji-btn.is-sel { border-color: var(--accent); background: var(--accent-soft); }

/* ============ Carpetas ocultas ============ */
.lock-ico svg { width: 15px; height: 15px; }
.lock-count { background: transparent; padding: 0; font-size: 12px; }
.cat-lock {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted-2);
  flex: none;
  opacity: .8;
  transition: background .15s, color .15s, opacity .15s;
}
.cat-lock:hover { background: var(--surface-3); color: var(--text); opacity: 1; }
.cat-lock svg { width: 13px; height: 13px; }

@media (max-width: 700px) {
  .chip-name, .profile-chip .chev { display: none; }
  .profile-chip { padding: 0 7px; }
  .profiles h1 { font-size: 21px; }
  .profile-card { width: 116px; }
  .avatar { width: 70px; height: 70px; font-size: 32px; }
  .avatar.xs { width: 26px; height: 26px; font-size: 14px; }
}
