/* Admin page styles.
 * Imports the shared light/dark theme from the public style.css,
 * then adds admin-specific components on top. */
@import url('/style.css');

/* ─── Toast notifications ────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 110;
  pointer-events: none;
}

@keyframes toastIn  { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; transform: none; }            to { opacity: 0; transform: translateX(16px); } }

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 0.875rem;
  color: var(--text);
  max-width: 300px;
  pointer-events: all;
  cursor: pointer;
  animation: toastIn 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
  border-left-width: 3px;
}
.toast.removing     { animation: toastOut 0.18s ease both; }
.toast-success      { border-left-color: #34c759; }
.toast-error        { border-left-color: var(--danger); }
.toast-info         { border-left-color: var(--primary); }
.toast-icon         { flex-shrink: 0; }
.toast-success .toast-icon { color: #34c759; }
.toast-error .toast-icon   { color: var(--danger); }
.toast-info .toast-icon    { color: var(--primary); }

/* ─── Multi-select dropdown (group picker in link modal) ───────────────────── */

.multi-select {
  position: relative;
  width: 100%;
}

.multi-select-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.multi-select-toggle:hover  { border-color: var(--border-strong); }
.multi-select-toggle:focus  { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12); }
.multi-select-toggle svg    { margin-left: auto; opacity: 0.55; flex-shrink: 0; transition: transform var(--transition); }
.multi-select.open .multi-select-toggle svg { transform: rotate(180deg); }

.multi-select-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.multi-select-label.placeholder { color: var(--text-muted); }

.multi-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text);
  user-select: none;
}
.multi-select-option:hover { background: var(--surface-3); }
.multi-select-option input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin: 0;
}
.multi-select-option input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.multi-select-option input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.multi-select-option .group-dot {
  width: 16px;
  height: 9px;
  border-radius: 980px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.07);
}
.multi-select-empty {
  padding: 10px 12px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
}

/* Each row in the dropdown stacks a checkbox option and an (optional) section
   picker that appears below it when the group is ticked. */
.multi-select-row {
  display: flex;
  flex-direction: column;
}

.multi-select-section {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 6px 28px; /* indent past the checkbox */
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.multi-select-section-arrow {
  font-size: 0.7rem;
  opacity: 0.5;
  flex-shrink: 0;
}
.multi-select-section-select {
  flex: 1;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--text);
  font-size: 0.8125rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.multi-select-section-select:focus { border-color: var(--primary); }

/* Multiple group badges sit nicely side by side on cards */
.link-footer { flex-wrap: wrap; }
.link-footer .group-badge + .group-badge { margin-left: 0; }

/* Group password row in the group modal */
.group-password-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.group-password-row input {
  flex: 1;
}
.form-hint {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.form-hint.protected { color: var(--primary); }

/* ─── Link/File mode tabs inside the link modal ──────────────────────────── */

.link-mode-tabs {
  display: inline-flex;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 980px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 10px;
}
.link-mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 980px;
  cursor: pointer;
  transition: all var(--transition);
}
.link-mode-tab:hover { color: var(--text); }
.link-mode-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.link-mode-tab svg { opacity: 0.7; }
.link-mode-tab.active svg { opacity: 1; }

/* File-upload control inside the File pane */
.file-upload {
  display: flex;
  gap: 8px;
  align-items: center;
}
.file-upload-trigger {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  overflow: hidden;
}
.file-upload-trigger:hover {
  border-color: var(--primary);
  color: var(--text);
}
.file-upload-trigger.has-file {
  border-style: solid;
  border-color: var(--primary);
  color: var(--text);
}
.file-upload-trigger svg { flex-shrink: 0; opacity: 0.7; }
.file-upload-trigger.has-file svg { color: var(--primary); opacity: 1; }
.file-upload-trigger #attachedFileLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Custom colour swatch in the group modal palette */
.color-swatch-custom {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.color-swatch-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}
.color-swatch-plus {
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  /* Slight shadow so the "+" stays readable on light custom colours */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

/* ─── Long-press to enter bulk mode ──────────────────────────────────────────
 *
 * While the user is pressing-and-holding a card, .long-pressing is added to
 * the wrap. The card scales down a hair (97%) and grows a soft primary-colour
 * ring over the same duration as the press timer (450 ms). Release before
 * the timer completes → snap back via the card's normal 0.18s transition.
 */
.link-card-wrap.long-pressing .link-card {
  transform: scale(0.97);
  box-shadow:
    0 0 0 3px rgba(0, 113, 227, 0.22),
    var(--shadow-sm);
  border-color: rgba(0, 113, 227, 0.45);
  transition:
    transform   0.45s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow  0.45s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}
[data-theme="dark"] .link-card-wrap.long-pressing .link-card {
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.32), var(--shadow-sm);
  border-color: rgba(10, 132, 255, 0.55);
}
/* Prevent the OS text-selection blue while the user is pressing. */
.link-card-wrap.long-pressing { -webkit-user-select: none; user-select: none; }

/* Hidden link state: faded card + "Hidden" badge in the footer */
.link-card-wrap.hidden-link .link-card { opacity: 0.55; }
.link-card-wrap.hidden-link .link-card:hover { opacity: 0.85; }

/* "Hidden" chip — colour variant of the .card-meta chip baseline (sizes come
   from the shared rule in public/style.css). */
.hidden-badge {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text-muted);
}

/* Lock icon next to protected groups in the sidebar */
.group-lock-icon {
  width: 11px;
  height: 11px;
  opacity: 0.55;
  flex-shrink: 0;
}
.group-nav-item.active .group-lock-icon { opacity: 0.9; }

/* ─── Sort select ────────────────────────────────────────────────────────────── */

.sort-select {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: all var(--transition);
}
.sort-select:focus  { border-color: var(--primary); color: var(--text); }
.sort-select option { background: var(--surface); }

/* ─── Token gate (admin-specific overrides) ────────────────────────────────── */

/* Monospace font so the token is easy to read and compare visually */
.gate-input-wrap input {
  font-family: 'SF Mono', ui-monospace, 'Fira Code', monospace;
  font-size: 0.875rem;
  letter-spacing: 0.02em;
  padding-right: 44px;
}

.gate-input-wrap input::placeholder {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  letter-spacing: normal;
}

.toggle-visibility-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  transition: color var(--transition);
}
.toggle-visibility-btn:hover { color: var(--text); }

/* ─── Admin layout ───────────────────────────────────────────────────────────── */

header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 50;
}

/* Override the public page's max-width restriction on the header */
.header-inner { max-width: unset; padding: 0 16px; }

.admin-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 980px;
  background: rgba(0, 113, 227, 0.12);
  color: var(--primary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

[data-theme="dark"] .admin-badge {
  background: rgba(10, 132, 255, 0.15);
}

.app-layout {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 40;
  transition: transform var(--transition);
  padding: 14px 10px;
  gap: 2px;
}

.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

/* ─── Top-level nav rows (All Links / Ungrouped) ─────────────────────────── */

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  transition: background var(--transition), color var(--transition);
  letter-spacing: -0.01em;
}

.nav-item:hover  { background: var(--surface-3); color: var(--text); }
.nav-item.active {
  background: rgba(0, 113, 227, 0.1);
  color: var(--primary);
  font-weight: 600;
}
[data-theme="dark"] .nav-item.active { background: rgba(10, 132, 255, 0.14); }

.nav-item svg { opacity: 0.7; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }
.nav-item span:nth-child(2) { flex: 1; }

.nav-count {
  font-size: 0.72rem;
  background: var(--surface-3);
  color: var(--text-muted);
  border-radius: 980px;
  padding: 1px 8px;
  font-weight: 600;
  min-width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.nav-item.active .nav-count {
  background: rgba(0, 113, 227, 0.16);
  color: var(--primary);
}
[data-theme="dark"] .nav-item.active .nav-count { background: rgba(10, 132, 255, 0.18); }

/* ─── Groups label + add button ──────────────────────────────────────────── */

.sidebar-groups { margin-top: 18px; }

.sidebar-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 11px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.add-group-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.add-group-btn:hover { color: var(--primary); background: rgba(0, 113, 227, 0.08); }

/* ─── Group rows ─────────────────────────────────────────────────────────── */

.groups-list { display: flex; flex-direction: column; gap: 2px; }

.group-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px 8px 6px 11px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-2);
  text-align: left;
  letter-spacing: -0.01em;
  position: relative;
  transition: background var(--transition), color var(--transition);
}
.group-nav-item:hover  { background: var(--surface-3); color: var(--text); }
.group-nav-item.active {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
}
.group-dot {
  width: 18px;
  height: 10px;
  border-radius: 980px; /* full pill — same language as the Add Link button */
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.07);
}

/* Group name + lock icon container takes remaining space */
.group-nav-item > span:nth-child(3) {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ─── Section rows inside the sidebar ─────────────────────────────────────── */

.section-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 8px 4px 14px;
  margin-left: 18px;             /* nest under the group */
  border-left: 2px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  position: relative;
  transition: background var(--transition),
              color var(--transition),
              border-left-color var(--transition);
}

/* Collapse the 2 px gap between two adjacent sections so the connector line
   reads as a single continuous bar instead of dashes. */
.section-nav-item + .section-nav-item { margin-top: -2px; }

/* Subsections: deeper indent, slimmer connector line, slightly muted name. */
.section-nav-item.subsection {
  margin-left: 38px;
  padding-left: 12px;
  font-size: 0.78rem;
  min-height: 26px;
  border-left-width: 1px;
}
.section-nav-item.subsection .section-name { color: var(--text-muted); }
.section-nav-item.subsection:hover .section-name { color: var(--text); }
.section-nav-item.subsection.active .section-name { color: var(--primary); }

/* ─── Group unlock-mode radio pills ──────────────────────────────────────── */

.group-unlock-mode .radio-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.radio-pill {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 4px 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition),
              box-shadow var(--transition);
}
.radio-pill:hover { border-color: var(--border-strong); }
.radio-pill input[type="radio"] {
  grid-row: 1 / span 2;
  margin-top: 3px;
  accent-color: var(--primary);
}
.radio-pill-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}
.radio-pill-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.radio-pill:has(input:checked) {
  border-color: var(--primary);
  background: rgba(0, 113, 227, 0.06);
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.12);
}
[data-theme="dark"] .radio-pill:has(input:checked) {
  background: rgba(10, 132, 255, 0.10);
  box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.22);
}

.section-nav-item:hover {
  background: var(--surface-3);
  color: var(--text);
  border-left-color: var(--text-muted);
}
.section-nav-item.active {
  background: rgba(0, 113, 227, 0.08);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
[data-theme="dark"] .section-nav-item.active { background: rgba(10, 132, 255, 0.12); }

/* The old tick element is replaced by the border-left connector line above. */
.section-nav-item .section-tick { display: none; }

.section-nav-item .section-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-nav-item .nav-count {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  min-width: 18px;
}
.section-nav-item.active .nav-count {
  background: rgba(0, 113, 227, 0.16);
  color: var(--primary);
}
[data-theme="dark"] .section-nav-item.active .nav-count { background: rgba(10, 132, 255, 0.18); }

/* Inline create/rename input keeps the row's visual height. */
.section-nav-item.editing {
  padding: 3px 6px 3px 10px;
  background: transparent;
}
.section-inline-input {
  flex: 1;
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--primary);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.8125rem;
  color: var(--text);
  outline: none;
  font-family: inherit;
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
}

/* ─── Hover actions: overlay the count badge ──────────────────────────────── */

/*
 * Actions are absolutely positioned at the right edge so they don't reserve
 * width when idle — the group name gets the full row. On hover the count
 * badge fades out and the buttons fade in, occupying the same slot. Zero
 * layout shift, full name visible until you actually need an action.
 */
.group-nav-item .nav-count,
.section-nav-item .nav-count {
  transition: opacity var(--transition);
}
.group-nav-item:hover .nav-count,
.section-nav-item:hover .nav-count {
  opacity: 0;
}

.group-item-actions {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 1px;
  padding: 2px;
  border-radius: 7px;
  background: var(--surface-3);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--transition);
}
.group-nav-item:hover .group-item-actions,
.section-nav-item:hover .group-item-actions,
.group-item-actions:focus-within {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.group-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.group-action-btn:hover { color: var(--text); background: rgba(0, 0, 0, 0.07); }
[data-theme="dark"] .group-action-btn:hover { background: rgba(255, 255, 255, 0.09); }
.group-action-btn.danger:hover { color: var(--danger); background: rgba(255, 59, 48, 0.09); }
.group-action-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-site-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
  letter-spacing: -0.01em;
}
.sidebar-site-link:hover { background: var(--surface-3); color: var(--text); }

/* ─── Sidebar toggle ──────────────────────────────────────────────────────────── */

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  transition: all var(--transition);
}
.sidebar-toggle:hover { color: var(--text); background: var(--surface-3); }

/* ─── Main content area ──────────────────────────────────────────────────────── */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 26px;
  transition: margin-left var(--transition);
  min-width: 0;
}

.sidebar.collapsed ~ .main-content { margin-left: 0; }

/* ─── Admin card extras (edit/delete buttons, date) ─────────────────────────── */

/* ── Premium vertical link cards (admin) ──────────────────────────────────────
 * Layout: header (icon + name/url) → description → tags → a divided footer with
 * view count + date on the left and the action buttons on the right. A uniform
 * baseline height that grows to fit content, so nothing is ever clipped. */
.link-card-wrap .link-card {
  position: relative;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  min-height: 122px;
  height: 100%;              /* fill the stretched grid row → even rows */
  padding: 16px 18px 12px;
}

/* The whole card is draggable; the dotted grip isn't needed visually. */
.link-card-wrap .drag-handle { display: none; }

/* Header row: icon + title block */
.link-card-wrap .link-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.link-card-wrap .link-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  flex-shrink: 0;
}
.link-card-wrap .link-headings {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.link-card-wrap .link-name { font-size: 0.95rem; }

/* Description: up to two lines */
.link-card-wrap .link-desc {
  -webkit-line-clamp: 2;
  line-clamp: 2;
  margin: 11px 0 0;
}

/* Tags strip wraps so every group/status pill is fully visible */
.link-card-wrap .card-meta {
  flex-wrap: wrap;
  margin-top: 12px;
}

/* Footer sticks to the bottom with a divider above it */
.link-card-wrap .link-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.link-card-wrap .link-foot-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex-wrap: nowrap;        /* never let a stat wrap to its own line */
}
.link-card-wrap .card-stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  line-height: 1;          /* fixed baseline → views sit at the same spot */
  color: var(--text-muted);
  white-space: nowrap;
}
.link-card-wrap .card-stat svg { opacity: 0.75; flex-shrink: 0; }

/* Action buttons reveal smoothly on hover. They stay in the layout (occupying
   their space even while invisible) so the footer height never changes — that
   keeps the views/date from shifting and avoids any reflow on hover. */
.link-card-wrap .link-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(2px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.link-card-wrap .link-card:hover .link-actions,
.link-card-wrap .link-card:focus-within .link-actions {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.link-card-wrap .link-actions .icon-btn {
  width: 30px;
  height: 30px;
}

/* ─── Button variants ────────────────────────────────────────────────────────── */

/* Small buttons for compact UIs like the settings modal */
.btn-sm {
  padding: 5px 12px;
  font-size: 0.8125rem;
  border-radius: 8px;
}

/* Ghost button with danger (red) colouring */
.btn-ghost-danger {
  background: none;
  color: var(--danger);
  border: 1px solid rgba(255, 59, 48, 0.35);
  border-radius: 8px;
}
.btn-ghost-danger:hover {
  background: rgba(255, 59, 48, 0.08);
  border-color: var(--danger);
}

/* ─── Settings modal ─────────────────────────────────────────────────────────── */

/* Constrain the settings modal so a long body scrolls inside the modal
   instead of pushing it off the bottom of the viewport. */
#settingsOverlay .modal {
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 720px);
}
#settingsOverlay .modal-header { flex-shrink: 0; }

.settings-body {
  padding: 16px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  /* iOS momentum scroll */
  -webkit-overflow-scrolling: touch;
  /* Keep the rounded modal corners visible against the scroll edge */
  scrollbar-gutter: stable;
  flex: 1 1 auto;
  min-height: 0;
}

.settings-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ─── Sidebar changelog (collapsible <details>) ────────────────────────────── */

.sidebar-changelog {
  margin-top: 6px;
  padding-top: 4px;
}
.sidebar-changelog > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  user-select: none;
  transition: background var(--transition), color var(--transition);
}
.sidebar-changelog > summary::-webkit-details-marker { display: none; }
.sidebar-changelog > summary:hover { background: var(--surface-3); color: var(--text); }

.sidebar-changelog .changelog-chevron {
  flex-shrink: 0;
  transition: transform var(--transition);
}
.sidebar-changelog[open] > summary .changelog-chevron { transform: rotate(90deg); }

.sidebar-changelog .changelog-version {
  position: relative;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  padding: 1px 7px;
  border-radius: 980px;
  background: rgba(0, 113, 227, 0.12);
  color: var(--primary);
}

/* Small "update available" dot rendered on the version pill. */
.changelog-update-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 5px;
  border-radius: 50%;
  background: #30d158;
  box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.45);
  animation: changelog-update-pulse 1.8s ease-out infinite;
}
@keyframes changelog-update-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(48, 209, 88, 0.55); }
  70%  { box-shadow: 0 0 0 6px rgba(48, 209, 88, 0);    }
  100% { box-shadow: 0 0 0 0   rgba(48, 209, 88, 0);    }
}

/* ─── "Update available" banner inside the changelog ─────────────────────── */

.changelog-update {
  margin: 8px 10px 4px;
  padding: 12px 12px 10px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg,
    rgba(48, 209, 88, 0.10),
    rgba(0, 113, 227, 0.08));
  border: 1px solid rgba(48, 209, 88, 0.28);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
[data-theme="dark"] .changelog-update {
  background: linear-gradient(135deg,
    rgba(48, 209, 88, 0.14),
    rgba(10, 132, 255, 0.12));
  border-color: rgba(48, 209, 88, 0.35);
}

.changelog-update-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.changelog-update-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #30d158;
  flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.55);
  animation: changelog-update-pulse 1.8s ease-out infinite;
}
.changelog-update-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.changelog-update-sub {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
}

.changelog-update-release {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.changelog-update-release + .changelog-update-release {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed rgba(0,0,0,0.08);
}
[data-theme="dark"] .changelog-update-release + .changelog-update-release {
  border-top-color: rgba(255,255,255,0.1);
}

.changelog-update-release-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
}
.changelog-update-tag {
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--text);
  padding: 1px 6px;
  border-radius: 980px;
  background: rgba(48, 209, 88, 0.18);
}
.changelog-update-date {
  color: var(--text-muted);
  font-weight: 500;
}
.changelog-update-link {
  margin-left: auto;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.7rem;
}
.changelog-update-link:hover { text-decoration: underline; }

.changelog-update-body {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-dim);
}
.changelog-update-body p     { margin: 4px 0; }
.changelog-update-body strong { color: var(--text); font-weight: 600; }
.changelog-update-list {
  margin: 4px 0 0;
  padding-left: 16px;
  list-style: disc;
}
.changelog-update-list li { margin: 2px 0; }
.changelog-update-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.72rem;
}

/* ─── Version / update-check modal ───────────────────────────────────────── */

.version-modal { max-width: 440px; }

.settings-version-inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text);
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 6px;
}

.version-body {
  padding: 18px 22px 6px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.version-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 8px 0;
}
.version-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: version-spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes version-spin { to { transform: rotate(360deg); } }

.version-summary {
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.version-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
}
.version-summary-row + .version-summary-row {
  border-top: 1px solid var(--border);
}
.version-summary-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}
.version-summary-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.version-summary-update { color: #30b558; }
[data-theme="dark"] .version-summary-update { color: #30d158; }
.version-summary-muted   { color: var(--text-muted); font-weight: 500; }

.version-status {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.version-status-title { font-weight: 600; color: var(--text); line-height: 1.2; }
.version-status-sub   { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.version-status-update {
  background: rgba(48, 209, 88, 0.10);
  border: 1px solid rgba(48, 209, 88, 0.28);
}
[data-theme="dark"] .version-status-update {
  background: rgba(48, 209, 88, 0.14);
  border-color: rgba(48, 209, 88, 0.35);
}
.version-status-update .version-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #30d158;
  margin-top: 4px;
  flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.55);
  animation: changelog-update-pulse 1.8s ease-out infinite;
}

.version-status-ok {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.version-status-ok svg { color: #30b558; flex-shrink: 0; margin-top: 2px; }
[data-theme="dark"] .version-status-ok svg { color: #30d158; }

.version-status-info {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.82rem;
}
.version-status-error {
  background: rgba(225, 29, 72, 0.08);
  border: 1px solid rgba(225, 29, 72, 0.28);
  color: var(--text);
}
.version-status-error svg { color: var(--danger, #e11d48); flex-shrink: 0; margin-top: 2px; }

.version-changes-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.version-release + .version-release {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(0,0,0,0.08);
}
[data-theme="dark"] .version-release + .version-release {
  border-top-color: rgba(255,255,255,0.1);
}
.version-release-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  margin-bottom: 4px;
}
.version-release-tag {
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text);
  padding: 1px 7px;
  border-radius: 980px;
  background: rgba(48, 209, 88, 0.18);
}
.version-release-date { color: var(--text-muted); font-weight: 500; }
.version-release-link {
  margin-left: auto;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.version-release-link:hover { text-decoration: underline; }
.version-release-body {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-dim);
}
.version-release-body p     { margin: 4px 0; }
.version-release-body strong { color: var(--text); font-weight: 600; }
.version-release-body ul {
  margin: 4px 0 0;
  padding-left: 18px;
  list-style: disc;
}
.version-release-body li { margin: 2px 0; }

.sidebar-changelog .changelog-release-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 11px 2px;
  margin-top: 6px;
  border-top: 1px solid var(--border);
}
.sidebar-changelog .changelog-release-label:first-of-type {
  border-top: none;
  margin-top: 4px;
}

.sidebar-changelog .changelog-list {
  list-style: none;
  padding: 4px 0 4px 11px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-changelog .changelog-list li {
  position: relative;
  padding: 8px 10px 8px 18px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.sidebar-changelog .changelog-list li::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 13px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
}
.sidebar-changelog .changelog-entry-title {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text);
  margin-bottom: 2px;
}
.sidebar-changelog .changelog-entry-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.sidebar-changelog .changelog-repo-link {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 2px 11px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.sidebar-changelog .changelog-repo-link:hover {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}
.sidebar-changelog .changelog-repo-link span { flex: 1; }
.sidebar-changelog .changelog-repo-link svg { flex-shrink: 0; opacity: 0.7; }
.sidebar-changelog .changelog-repo-link:hover svg { opacity: 1; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--surface-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.settings-row + .settings-row { margin-top: 8px; }

.settings-row-label {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
}

.settings-row-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.logo-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Small logo thumbnail shown in the settings row */
.logo-thumb {
  height: 30px;
  max-width: 100px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  object-fit: contain;
  padding: 3px;
}

/* Hint text shown below the logo rows */
.settings-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0 2px;
}

/* ─── Stats modal ────────────────────────────────────────────────────────────── */

/* Wider than the default modal to fit the stats tables comfortably */
.modal-lg { max-width: 560px; }

/* ─── Toggle switch (used in settings) ───────────────────────────────────────── */

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.switch-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s ease;
}
.switch input:checked + .switch-slider {
  background: var(--primary);
  border-color: var(--primary);
}
.switch input:checked + .switch-slider::before {
  transform: translate(16px, -50%);
}
.switch input:focus-visible + .switch-slider {
  box-shadow: 0 0 0 3px rgba(0,113,227,0.22);
}
[data-theme="dark"] .switch input:focus-visible + .switch-slider {
  box-shadow: 0 0 0 3px rgba(10,132,255,0.28);
}

/* ─── File editor modal ──────────────────────────────────────────────────────── */

.file-editor-modal {
  max-width: 880px;
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 800px);
  transition: max-width 0.18s ease, max-height 0.18s ease;
}

/* Expanded mode swallows nearly the whole viewport so big HTML/JSON files
   are comfortable to navigate. Click the expand button again (or hit Esc)
   to drop back to the standard size. */
.file-editor-modal.is-expanded {
  max-width: 96vw;
  max-height: 96vh;
}

.file-editor-expand-btn { margin-left: 4px; }
.file-editor-expand-btn.is-expanded svg { color: var(--primary); }

.file-editor-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.file-editor-heading svg { color: var(--text-muted); flex-shrink: 0; }
.file-editor-filename {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.file-editor-badge {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 980px;
  background: rgba(0, 113, 227, 0.14);
  color: var(--primary);
  flex-shrink: 0;
}

.file-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.file-editor-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.file-editor-toolbar-spacer { flex: 1; }
.file-editor-status {
  font-size: 0.72rem;
  color: var(--text-muted);
  transition: color 0.18s ease;
}
.file-editor-status.is-dirty   { color: #d97706; }
.file-editor-status.is-saving  { color: var(--primary); }
.file-editor-status.is-error   { color: var(--danger, #e11d48); }
[data-theme="dark"] .file-editor-status.is-dirty { color: #fbbf24; }

.file-editor-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  background: var(--surface);
}

/* The pane holds the gutter + stage. Gutter is a fixed-width column on the
   left with line numbers; stage is a positioned context where the highlight
   <pre> and the transparent <textarea> are stacked. */
.file-editor-pane {
  flex: 1;
  display: flex;
  min-height: 0;
  min-width: 0;
}
.file-editor-pane.hidden { display: none; }

.file-editor-gutter {
  flex-shrink: 0;
  width: 52px;
  padding: 16px 10px 16px 0;
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
  overflow: hidden;
  user-select: none;
  border-right: 1px solid var(--border);
}

.file-editor-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  /* iOS momentum scroll for the inner layers */
  -webkit-overflow-scrolling: touch;
}

/* Both layers share font, line-height, padding — every glyph in the
   textarea sits over the same glyph in the highlight <pre>. Diverging on any
   of these knocks the caret off the colour layer; keep them locked. */
.file-editor-highlight,
.file-editor-textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 16px 22px;
  font-family: ui-monospace, SFMono-Regular, Menlo, "Cascadia Code", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  word-break: normal;
  overflow: auto;
  border: none;
  outline: none;
  resize: none;
}
.file-editor-highlight {
  pointer-events: none;
  color: var(--text);   /* fallback for chars no token covers */
  background: var(--surface);
  overflow: hidden;     /* the textarea owns scrolling; we sync transform */
}
.file-editor-highlight code {
  font: inherit;
  display: block;
  min-height: 100%;
  color: inherit;
}
.file-editor-textarea {
  /* Strip every default browser/OS form chrome that could paint an opaque
     surface on focus and hide the highlight layer below. Re-assert
     transparency through focus/active so no UA stylesheet wins. */
  appearance: none;
  -webkit-appearance: none;
  color: transparent;
  caret-color: var(--text);
  background: transparent;
  -webkit-text-fill-color: transparent;
  box-shadow: none;
  z-index: 3;
}
.file-editor-textarea:focus,
.file-editor-textarea:focus-visible,
.file-editor-textarea:active {
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  box-shadow: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

/* Explicit z-index so the highlight stays unambiguously below the textarea
   in every browser regardless of paint order quirks. */
.file-editor-highlight { z-index: 1; }

/* Search overlay: identical layout to the highlight + textarea so each mark
   sits perfectly on top of the same character span in both layers. The text
   itself is invisible — only the <mark> backgrounds paint. */
.file-editor-search-overlay {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 16px 22px;
  font-family: ui-monospace, SFMono-Regular, Menlo, "Cascadia Code", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  word-break: normal;
  overflow: hidden;
  pointer-events: none;
  color: transparent;
  -webkit-text-fill-color: transparent;
  z-index: 2;       /* above highlight, below textarea (textarea z=3 below) */
}

.file-editor-search-overlay mark.search-match {
  background: rgba(255, 196, 0, 0.32);
  color: transparent;
  -webkit-text-fill-color: transparent;
  border-radius: 2px;
  /* slight stroke so matches read on busy syntax-coloured backgrounds too */
  box-shadow: inset 0 0 0 1px rgba(180, 130, 0, 0.45);
}
.file-editor-search-overlay mark.search-match.is-current {
  background: rgba(255, 149, 0, 0.55);
  box-shadow: inset 0 0 0 1.5px #ff9500;
}
[data-theme="dark"] .file-editor-search-overlay mark.search-match {
  background: rgba(255, 196, 0, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 196, 0, 0.55);
}
[data-theme="dark"] .file-editor-search-overlay mark.search-match.is-current {
  background: rgba(255, 159, 10, 0.45);
  box-shadow: inset 0 0 0 1.5px #ff9f0a;
}
/* Selection: paint just the translucent highlight rectangle, no text colour.
   Without forcing color (and -moz-selection for Firefox) the browser repaints
   selected glyphs in the system's white selection-foreground colour, which
   covers the highlighted <pre> underneath and the whole code reads blank. */
.file-editor-textarea::selection {
  background: rgba(0, 113, 227, 0.22);
  color: transparent;
  -webkit-text-fill-color: transparent;
}
.file-editor-textarea::-moz-selection {
  background: rgba(0, 113, 227, 0.22);
  color: transparent;
}
[data-theme="dark"] .file-editor-textarea::selection,
[data-theme="dark"] .file-editor-textarea::-moz-selection {
  background: rgba(10, 132, 255, 0.32);
}

/* ─── Find bar (Ctrl/Cmd+F) ─────────────────────────────────────────────── */

.file-editor-search {
  position: absolute;
  top: 10px;
  right: 14px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter:         saturate(180%) blur(10px);
  animation: fadeIn 0.12s ease;
}
[data-theme="dark"] .file-editor-search {
  background: color-mix(in srgb, var(--surface) 80%, transparent);
}

.file-editor-search.hidden { display: none; }

.file-editor-search-icon {
  color: var(--text-muted);
  margin-left: 4px;
  flex-shrink: 0;
}

.file-editor-search input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  padding: 4px 6px;
  width: 200px;
  font-family: inherit;
}
.file-editor-search input::placeholder { color: var(--text-muted); }

.file-editor-search-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
  min-width: 26px;
  text-align: center;
}
.file-editor-search-count.is-empty { color: var(--danger, #e11d48); }

.file-editor-search-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.file-editor-search-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}
.file-editor-search-btn:disabled { opacity: 0.4; cursor: default; }

@media (max-width: 720px) {
  .file-editor-search { top: 8px; right: 8px; left: 8px; }
  .file-editor-search input { width: 100%; flex: 1; }
}

/* ─── Syntax tokens ─────────────────────────────────────────────────────── */
.tok-tag      { color: #d73a49; }
.tok-attr     { color: #6f42c1; }
.tok-str      { color: #22863a; }
.tok-num      { color: #005cc5; }
.tok-bool     { color: #e36209; font-weight: 500; }
.tok-key      { color: #005cc5; }
.tok-comment  { color: #6a737d; font-style: italic; }
.tok-keyword  { color: #d73a49; }
.tok-property { color: #6f42c1; }
.tok-punct    { color: var(--text-muted); }
.tok-heading  { color: #005cc5; font-weight: 600; }
.tok-link     { color: #032f62; text-decoration: underline; }
.tok-code     { color: #e36209; background: rgba(0,0,0,0.04); padding: 0 2px; border-radius: 3px; }
.tok-bold     { font-weight: 700; }
.tok-em       { font-style: italic; }
.tok-bullet   { color: var(--text-muted); }

[data-theme="dark"] .tok-tag      { color: #ff7b72; }
[data-theme="dark"] .tok-attr     { color: #d2a8ff; }
[data-theme="dark"] .tok-str      { color: #a5d6ff; }
[data-theme="dark"] .tok-num      { color: #79c0ff; }
[data-theme="dark"] .tok-bool     { color: #ffa657; }
[data-theme="dark"] .tok-key      { color: #79c0ff; }
[data-theme="dark"] .tok-comment  { color: #8b949e; }
[data-theme="dark"] .tok-keyword  { color: #ff7b72; }
[data-theme="dark"] .tok-property { color: #d2a8ff; }
[data-theme="dark"] .tok-heading  { color: #79c0ff; }
[data-theme="dark"] .tok-link     { color: #a5d6ff; }
[data-theme="dark"] .tok-code     { background: rgba(255,255,255,0.07); color: #ffa657; }

.file-editor-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.file-editor-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: version-spin 0.7s linear infinite;
}
.file-editor-error-msg {
  color: var(--danger, #e11d48);
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  .file-editor-modal { max-height: calc(100vh - 18px); }
  .file-editor-toolbar { padding: 8px 14px; flex-wrap: wrap; }
  .file-editor-textarea { padding: 12px 14px; font-size: 0.82rem; }
}

/* ─── Stock icon picker (with color) ─────────────────────────────────────────── */

.icon-presets-modal {
  max-width: 720px;
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 760px);
}

.icon-presets-count {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
  background: var(--surface-3);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 10px;
}

.icon-presets-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
}

.icon-presets-search {
  position: relative;
}
.icon-presets-search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.icon-presets-search input {
  width: 100%;
  padding: 9px 12px 9px 33px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: all 0.18s ease;
}
.icon-presets-search input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}
[data-theme="dark"] .icon-presets-search input:focus {
  box-shadow: 0 0 0 3px rgba(10,132,255,0.2);
}

.icon-presets-color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.icon-presets-color-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}
.icon-presets-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}
.icon-presets-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.icon-presets-swatch:hover { transform: scale(1.12); }
.icon-presets-swatch.is-active {
  box-shadow: 0 0 0 3px rgba(0,113,227,0.18), 0 0 0 1px var(--surface);
}
[data-theme="dark"] .icon-presets-swatch.is-active {
  box-shadow: 0 0 0 3px rgba(10,132,255,0.28), 0 0 0 1px var(--surface);
}
.icon-presets-color-custom {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px dashed var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
}
.icon-presets-color-custom::after {
  content: '+';
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1;
}
.icon-presets-color-custom input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

.icon-presets-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 22px 6px;
  -webkit-overflow-scrolling: touch;
}

.icon-presets-section + .icon-presets-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
.icon-presets-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.icon-presets-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
}
.icon-presets-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
  font: inherit;
  color: inherit;
  outline: none;
}
.icon-presets-tile:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.icon-presets-tile.is-selected {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 2px rgba(0,113,227,0.16), var(--shadow-xs);
}
[data-theme="dark"] .icon-presets-tile.is-selected {
  box-shadow: 0 0 0 2px rgba(10,132,255,0.28), var(--shadow-xs);
}
.icon-presets-tile svg { display: block; }
.icon-presets-tile-name {
  font-size: 0.66rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-presets-noresults {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.icon-presets-selected {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.icon-presets-selected.is-ready { color: var(--text); }
.icon-presets-selected-preview {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-presets-selected-preview svg { display: block; }

@media (max-width: 720px) {
  .icon-presets-modal { max-height: calc(100vh - 18px); }
  .icon-presets-tiles { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .icon-presets-tile { padding: 8px 4px 6px; }
  .icon-presets-tile-name { display: none; }
  .icon-presets-selected { width: 100%; justify-content: center; margin-bottom: 6px; }
}

/* ─── Icon library modal ─────────────────────────────────────────────────────── */

.icon-library-modal { max-width: 680px; display: flex; flex-direction: column; max-height: 88vh; }

.icon-library-modal .modal-header h2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.icon-library-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
  background: var(--surface-3);
  padding: 2px 8px;
  border-radius: 999px;
}

.icon-library-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 16px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.icon-library-search {
  position: relative;
  flex: 1;
}
.icon-library-search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.icon-library-search input {
  width: 100%;
  padding: 9px 12px 9px 33px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: all 0.18s ease;
}
.icon-library-search input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}
[data-theme="dark"] .icon-library-search input:focus {
  box-shadow: 0 0 0 3px rgba(10,132,255,0.2);
}

.icon-library-body {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 22px;
  min-height: 240px;
}
.icon-library-body.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--surface);
  opacity: 0.55;
  pointer-events: none;
}

.icon-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 12px;
}

.icon-library-card {
  position: relative;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.icon-library-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.icon-library-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,113,227,0.18), var(--shadow-sm);
}
[data-theme="dark"] .icon-library-card.is-selected {
  box-shadow: 0 0 0 2px rgba(10,132,255,0.28), var(--shadow-sm);
}

.icon-library-card-pick {
  all: unset;
  display: block;
  width: 100%;
  cursor: pointer;
  text-align: left;
}

.icon-library-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(var(--surface), var(--surface)),
    repeating-conic-gradient(var(--surface-3) 0% 25%, var(--surface-2) 0% 50%) 50% / 12px 12px;
  background-blend-mode: normal;
  padding: 16px;
}
.icon-library-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.08));
}

.icon-library-meta {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-top: 1px solid var(--border);
}
.icon-library-name {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-library-usage {
  font-size: 0.69rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.icon-library-card-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.92);
  color: var(--danger, #e11d48);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.16s ease, transform 0.16s ease, background 0.16s ease;
  backdrop-filter: blur(6px);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
[data-theme="dark"] .icon-library-card-delete {
  background: rgba(40,40,42,0.95);
}
.icon-library-card:hover .icon-library-card-delete,
.icon-library-card:focus-within .icon-library-card-delete {
  opacity: 1;
  transform: scale(1);
}
.icon-library-card-delete:hover {
  background: var(--danger, #e11d48);
  color: #fff;
}

.icon-library-selected-tag {
  position: absolute;
  bottom: 6px;
  left: 6px;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--primary);
  color: #fff;
  padding: 2px 7px;
  border-radius: 999px;
  pointer-events: none;
}

.icon-library-empty {
  text-align: center;
  padding: 40px 16px 24px;
  color: var(--text-muted);
}
.icon-library-empty-art {
  width: 78px;
  height: 78px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.icon-library-empty-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.icon-library-empty-sub {
  font-size: 0.825rem;
  color: var(--text-muted);
}

.icon-library-noresults {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Picker tile + library trigger inside the link modal */
.icon-library-trigger { /* uses .icon-upload-inner base, just a hook */ }

.icon-source-badge {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--primary);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

@media (max-width: 720px) {
  .icon-library-modal { max-height: 100vh; }
  .icon-library-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
  .icon-library-toolbar { padding: 12px 16px; }
  .icon-library-body { padding: 14px 16px 18px; }
}

.stats-link-url {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.stats-body {
  padding: 16px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 72vh;
  overflow-y: auto;
}

/* Four summary boxes in a row */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat-box {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.04em;
  line-height: 1;
}

.stat-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 5px;
}

.stats-last-seen {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0;
}

.stats-section { display: flex; flex-direction: column; gap: 8px; }

/* Table of clicks or IPs */
.click-log {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.click-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--border);
}
.click-row:last-child { border-bottom: none; }
.click-row:nth-child(even) { background: var(--surface-3); }

.click-ip {
  font-family: 'SF Mono', ui-monospace, 'Fira Code', monospace;
  font-size: 0.78rem;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.click-device {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 58px;
  flex-shrink: 0;
}

.click-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Bar chart row for top IPs */
.click-bar-wrap {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.click-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  min-width: 4px;
  transition: width 0.3s ease;
}

.click-count {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  flex-shrink: 0;
  width: 64px;
  text-align: right;
}

.stats-empty {
  padding: 20px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stats-loading {
  padding: 20px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ─── Click-count chip ───────────────────────────────────────────────────────
 *
 * Lives in the same .card-meta strip as group/status chips. Borderless and
 * transparent so it reads as a quiet metric beside the more emphatic tags.
 * The hover tooltip surfaces the full "N clicks · M unique visitors" line.
 */
.card-click-count {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 3px 4px;
  font-weight: 500;
  cursor: default;
}
.card-click-count > svg { opacity: 0.7; }

/* ─── Bulk action bar ────────────────────────────────────────────────────────── */

.bulk-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 980px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  white-space: nowrap;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
}

.bulk-group-select {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  color: var(--text);
  font-size: 0.8125rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  width: 160px;
}

/* ─── Bulk select: card checkbox overlay ─────────────────────────────────────── */

.bulk-mode .link-card { cursor: pointer; }

.card-checkbox {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  pointer-events: none;
  z-index: 1;
}

.link-card-wrap {
  position: relative;
}

.link-card-wrap.selected .card-checkbox {
  background: var(--primary);
  border-color: var(--primary);
}

.link-card-wrap.selected .card-checkbox::after {
  content: '';
  display: block;
  width: 5px;
  height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.link-card-wrap.selected .link-card {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,113,227,0.2);
}
[data-theme="dark"] .link-card-wrap.selected .link-card {
  box-shadow: 0 0 0 2px rgba(10,132,255,0.25);
}

/* ─── Token rotation result display ─────────────────────────────────────────── */

.new-token-display {
  font-family: 'SF Mono', ui-monospace, 'Fira Code', monospace;
  font-size: 0.8rem;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  word-break: break-all;
  color: var(--text);
  margin-top: 8px;
  line-height: 1.6;
}

/* ─── Group drag handle in sidebar ──────────────────────────────────────────── */

.group-drag-handle {
  color: var(--text-muted);
  opacity: 0;
  cursor: grab;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  transition: opacity var(--transition);
}
.group-nav-item:hover .group-drag-handle { opacity: 0.5; }
.group-nav-item.drag-over {
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  outline: 2px solid var(--primary);
}

.section-drag-handle {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  opacity: 0;
  cursor: grab;
  flex-shrink: 0;
  transition: opacity var(--transition);
}

/* While a link card is being dragged, signal that sidebar rows are drop
   targets — outline the hovered group/section/subsection in green so the
   user knows the move will land where they're aiming. */
body.is-link-dragging .group-nav-item,
body.is-link-dragging .section-nav-item:not(.editing) {
  cursor: copy;
}
.group-nav-item.drag-over-link,
.section-nav-item.drag-over-link {
  background: rgba(48, 209, 88, 0.14);
  outline: 2px solid #30d158;
  outline-offset: -1px;
  border-radius: var(--radius-sm);
}
[data-theme="dark"] .group-nav-item.drag-over-link,
[data-theme="dark"] .section-nav-item.drag-over-link {
  background: rgba(48, 209, 88, 0.18);
}
.section-nav-item:hover .section-drag-handle { opacity: 0.5; }
.section-nav-item.drag-over {
  background: var(--surface-3);
  border-left-color: var(--primary);
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ─── Mobile overflow menu (kebab popover) ──────────────────────────────────
 *
 * The kebab button is hidden on desktop; on phones (≤480 px) it appears in
 * place of theme / settings / logout, opening this popover anchored just
 * below the header.
 */
.mobile-more-btn { display: none; }
.mobile-more-btn svg { color: var(--text-muted); }

.mobile-menu {
  position: fixed;
  top: calc(var(--header-h) + 4px);
  right: 8px;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transform-origin: top right;
  animation: mobileMenuIn 0.16s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes mobileMenuIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.mobile-menu-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.mobile-menu-item:hover,
.mobile-menu-item:focus-visible {
  background: var(--surface-3);
  outline: none;
}
.mobile-menu-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}
.mobile-menu-item:hover svg { color: var(--text); }
.mobile-menu-item.danger { color: var(--danger); }
.mobile-menu-item.danger svg { color: var(--danger); }
.mobile-menu-item.danger:hover { background: rgba(255, 59, 48, 0.08); }

.mobile-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 6px;
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  /* Sidebar slides over the main content instead of pushing it */
  .sidebar         { transform: translateX(-100%); }
  .sidebar.open    { transform: none; box-shadow: var(--shadow-md); }
  .main-content    { margin-left: 0 !important; padding: 16px 14px 80px; }
  .search-input    { width: 130px; }
  .links-grid      { grid-template-columns: 1fr; }
  .bulk-bar        { left: 16px; right: 16px; transform: none; border-radius: var(--radius-lg); flex-wrap: wrap; }
  .header-inner    { padding: 0 14px; gap: 8px; }
  .admin-badge     { display: none; }
  .sort-select     { display: none; }
}

@media (max-width: 480px) {
  body { font-size: 14px; }

  /* Header: drop power-user buttons; keep brand-icon + search + add + more */
  .header-inner   { padding: 0 10px; gap: 6px; }
  .admin-badge    { display: none; }
  .brand-label    { display: none; }  /* leave only the link-glyph SVG */
  #importBtn,
  #exportBtn,
  #bulkSelectBtn,
  .sort-select    { display: none; }

  /* The three solo icon buttons collapse into a single overflow menu */
  #themeToggle,
  #openSettingsBtn,
  #logoutBtn      { display: none; }
  .mobile-more-btn { display: inline-flex; }

  /* Let the search input fill the row */
  .search-wrap    { flex: 1 1 auto; min-width: 0; }
  .search-input,
  .search-input:focus { width: 100% !important; padding: 7px 10px 7px 30px; }

  /* Add Link collapses to an icon-only pill */
  #openAddLinkBtn         { padding: 8px 12px; gap: 0; }
  #openAddLinkBtn .add-link-label { display: none; }

  /* Theme / settings / logout — round, comfortable tap targets */
  .theme-toggle   { width: 34px; height: 34px; }

  .main-content   { padding: 14px 10px 90px; }
  .links-grid     { gap: 8px; grid-template-columns: 1fr; }

  /* Cards: card-action buttons need bigger touch targets, and on phones the
     hover state never fires — so make the action bar always visible there.
     Scoped to .link-card-wrap so it overrides the hover-hidden default. */
  .link-card-wrap .icon-btn { width: 32px; height: 32px; }
  .link-card-wrap .link-actions {
    gap: 2px;
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }
  .drag-handle              { display: none; } /* drag-to-reorder is mouse-only on phones */

  /* Modals: full-width sheet from the top edge.
     overflow-y enables scrolling when forms exceed viewport height. */
  .modal-overlay     { padding: 0; align-items: flex-start; padding-top: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal             { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-width: 100%; margin: 0 8px; }
  .modal-sm          { max-width: 100%; }
  .modal-lg          { max-width: 100%; }
  .modal-header      { padding: 16px 16px 0; }

  /* Stack form layouts and stretch action buttons */
  .form-row          { flex-direction: column !important; gap: 10px !important; }
  .form-row > *      { width: 100% !important; }
  .form-actions      { flex-direction: column-reverse; gap: 8px; padding: 14px 16px 20px; }
  .form-actions .btn { width: 100%; justify-content: center; }
  .form-group        { padding-bottom: 4px; }

  /* Settings rows stack instead of squishing into two columns */
  .settings-row      { flex-direction: column; align-items: stretch; gap: 10px; }
  .settings-row > div:last-child { display: flex; flex-wrap: wrap; gap: 6px; }
  .settings-body     { padding: 14px 16px 18px; }

  /* Bottom-sheet on phones: the modal can take the full viewport height,
     internal scroll handles long content. */
  #settingsOverlay .modal { max-height: calc(100vh - 18px); }

  /* Bulk bar: full-width pill at the bottom */
  .bulk-bar { bottom: 14px; left: 10px; right: 10px; padding: 12px 14px; gap: 10px; }
  .bulk-bar > div { width: 100%; justify-content: space-between; }
  .bulk-bar .btn { flex: 1; justify-content: center; }
  .bulk-group-select { flex: 1; width: auto; }

  /* Multi-select panel: wider on phones for easier tapping */
  .multi-select-toggle { padding: 9px 12px; font-size: 0.9rem; }
  .multi-select-option { padding: 9px 10px; font-size: 0.9rem; }
  .multi-select-option input[type="checkbox"] { width: 18px; height: 18px; }

  /* Sidebar takes most of the screen when opened */
  .sidebar          { width: min(280px, 88vw); }

  /* Toasts stay above the bottom bulk bar */
  .toast-container  { right: 10px; left: 10px; }
  .toast            { max-width: 100%; }
}

/* ─── Audit log modal ─────────────────────────────────────────────────────── */

.audit-modal {
  max-width: 680px;
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 760px);
}
.audit-count {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-3);
  padding: 2px 8px;
  border-radius: 980px;
  margin-left: 8px;
  vertical-align: middle;
}

.audit-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.audit-search { position: relative; flex: 1; min-width: 140px; }
.audit-search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.audit-search input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
.audit-search input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}
.audit-toolbar-spacer { flex: 1 1 0; }

.audit-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 14px 16px;
  -webkit-overflow-scrolling: touch;
}

.audit-loading {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 40px 0; color: var(--text-muted); font-size: 0.875rem;
}
.audit-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: version-spin 0.7s linear infinite;
}

.audit-empty { text-align: center; padding: 48px 16px; }
.audit-empty-title { font-size: 0.95rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.audit-empty-sub   { font-size: 0.825rem; color: var(--text-muted); }

.audit-list { display: flex; flex-direction: column; }

.audit-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 8px;
  border-bottom: 1px solid var(--border);
}
.audit-row:last-child { border-bottom: none; }

.audit-dot {
  width: 9px; height: 9px; border-radius: 50%;
  margin-top: 5px; flex-shrink: 0;
  background: var(--text-muted);
}
.audit-dot-create { background: #30b558; }
.audit-dot-update { background: #0a84ff; }
.audit-dot-delete { background: #e0392b; }
.audit-dot-click  { background: #8e8e93; }

.audit-main { flex: 1; min-width: 0; }
.audit-summary {
  font-size: 0.875rem;
  color: var(--text);
  font-weight: 500;
  line-height: 1.35;
}
.audit-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.audit-badge {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 7px;
  border-radius: 980px;
  background: var(--surface-3);
  color: var(--text-dim);
}
.audit-badge-link     { background: rgba(0,113,227,0.14);  color: #0a6ed1; }
.audit-badge-group    { background: rgba(175,82,222,0.14); color: #a14fd0; }
.audit-badge-section  { background: rgba(0,199,190,0.16);  color: #069b94; }
.audit-badge-icon     { background: rgba(255,149,0,0.16);  color: #c9760a; }
.audit-badge-settings { background: rgba(142,142,147,0.18);color: var(--text-dim); }
.audit-badge-auth     { background: rgba(224,57,43,0.14);  color: #d0392b; }
.audit-badge-click    { background: rgba(142,142,147,0.16);color: var(--text-dim); }
[data-theme="dark"] .audit-badge-link     { color: #6cb6ff; }
[data-theme="dark"] .audit-badge-group    { color: #d2a8ff; }
[data-theme="dark"] .audit-badge-section  { color: #5fd3cb; }
[data-theme="dark"] .audit-badge-icon     { color: #ffb761; }
[data-theme="dark"] .audit-badge-auth     { color: #ff8a80; }

.audit-action-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.audit-origin { font-size: 0.72rem; color: var(--text-muted); }

.audit-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}

.audit-more { margin: 14px auto 4px; display: block; }

@media (max-width: 720px) {
  .audit-modal { max-height: 100vh; }
  .audit-action-code { display: none; }
}

/* Audit: live toggle + new-entry highlight */
.audit-live-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.audit-live-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.audit-live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition), box-shadow var(--transition);
}
.audit-live-toggle input:checked ~ .audit-live-dot {
  background: #30b558;
  box-shadow: 0 0 0 3px rgba(48,181,88,0.18);
  animation: auditPulse 2s ease-in-out infinite;
}
@keyframes auditPulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(48,181,88,0.20); }
  50%     { box-shadow: 0 0 0 4px rgba(48,181,88,0.05); }
}

@keyframes auditRowIn {
  from { background: rgba(48,181,88,0.18); }
  to   { background: transparent; }
}
.audit-row-new {
  animation: auditRowIn 2s ease-out;
}

/* ─── Icon library bulk select ────────────────────────────────────────────── */

.icon-library-bulkbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.85rem;
  color: var(--text-dim);
}
.icon-library-bulkbar-spacer { flex: 1; }

/* In select mode the whole tile is a click target; suppress the pick cursor
   change and show a check badge in the corner. */
.icon-library-grid.select-mode .icon-library-card { cursor: pointer; }
.icon-library-grid.select-mode .icon-library-card-pick { cursor: pointer; }

.icon-library-card.is-checked {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,113,227,0.18), var(--shadow-sm);
}
[data-theme="dark"] .icon-library-card.is-checked {
  box-shadow: 0 0 0 2px rgba(10,132,255,0.28), var(--shadow-sm);
}

.icon-library-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background var(--transition), border-color var(--transition);
}
.icon-library-card.is-checked .icon-library-check {
  background: var(--primary);
  border-color: var(--primary);
}
