/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:           #0f1117;
  --surface:      #1a1d27;
  --surface-2:    #1e2130;
  --border:       #2a2d3d;
  --accent:       #00d4aa;
  --accent-hover: #00b894;
  --accent-dim:   rgba(0, 212, 170, 0.12);
  --text:         #e2e8f0;
  --text-muted:   #94a3b8;
  --text-faint:   #64748b;
  --danger:       #ef4444;
  --danger-dim:   rgba(239, 68, 68, 0.12);
  --warning:      #f59e0b;
  --success:      #10b981;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 2px 12px rgba(0,0,0,0.4);
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.3);
  --header-h:     56px;
  --transition:   0.15s ease;
}

/* ── Reset & base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
input, textarea, select { font: inherit; }
img { display: block; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.logo span { color: var(--text); }
.header-search {
  flex: 1;
  max-width: 420px;
  position: relative;
}
.header-search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.9rem 0.45rem 2.2rem;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition);
}
.header-search input:focus { border-color: var(--accent); }
.header-search input::placeholder { color: var(--text-faint); }
.header-search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
  font-size: 0.9rem;
}
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.user-name {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #0f1117;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid transparent;
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-icon {
  padding: 0.4rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ── Main layout ─────────────────────────────────────────────────────────────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Lock badge for "sign in to see more" ─────────────────────────────────────── */
.unlock-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.65rem 1.25rem;
  background: var(--accent-dim);
  border: 1px solid rgba(0, 212, 170, 0.25);
  border-radius: var(--radius);
  margin-bottom: 2rem;
  font-size: 0.875rem;
  color: var(--accent);
}
.unlock-bar a { font-weight: 600; text-decoration: underline; }

/* ── Category section ────────────────────────────────────────────────────────── */
.category { margin-bottom: 2.5rem; }
.category-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.category-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.category-icon img { width: 100%; height: 100%; object-fit: contain; }
.category-icon-emoji { font-size: 1.2rem; line-height: 1; }
.category-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 0.8rem;
}
.category-divider {
  flex: 1;
  height: 1px;
  background: var(--border);
  margin-left: 0.5rem;
}

/* ── Link grid ───────────────────────────────────────────────────────────────── */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

/* ── Link card ───────────────────────────────────────────────────────────────── */
.link-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.1rem 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  color: var(--text);
}
.link-card:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.link-card:hover .link-name { color: var(--accent); }

.link-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  margin-bottom: 0.6rem;
  border-radius: 8px;
}
.link-icon--favicon {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}
.link-icon--emoji { font-size: 2rem; line-height: 1; margin-bottom: 0.6rem; display: block; }
.link-icon--default { font-size: 2rem; line-height: 1; margin-bottom: 0.6rem; display: block; }

.link-name {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.2rem;
  transition: color var(--transition);
}
.link-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 5rem 2rem;
  color: var(--text-faint);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.empty-state p { font-size: 0.875rem; }
.empty-state a { color: var(--accent); }

/* ── Search no-results ───────────────────────────────────────────────────────── */
.no-results {
  display: none;
  text-align: center;
  padding: 3rem;
  color: var(--text-faint);
  font-size: 0.9rem;
}

/* ── Admin layout ────────────────────────────────────────────────────────────── */
.admin-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.admin-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 2rem;
  color: var(--text);
}
.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.admin-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.admin-section-body { padding: 1rem; }

/* ── Settings form ───────────────────────────────────────────────────────────── */
.settings-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.settings-row label {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Form elements ───────────────────────────────────────────────────────────── */
.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-weight: 500;
}
.field input[type="text"],
.field input[type="url"],
.field input[type="file"],
.field textarea,
.field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition);
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field input::placeholder, .field textarea::placeholder { color: var(--text-faint); }
.field textarea { resize: vertical; min-height: 70px; }
.field select { background-image: none; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field-hint { font-size: 0.75rem; color: var(--text-faint); margin-top: 0.25rem; }

/* ── Radio tabs ──────────────────────────────────────────────────────────────── */
.radio-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.radio-tabs input { display: none; }
.radio-tabs label {
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.radio-tabs input:checked + label {
  background: var(--accent);
  color: #0f1117;
}

/* ── Icon preview ────────────────────────────────────────────────────────────── */
.icon-preview-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.icon-preview-box {
  width: 48px;
  height: 48px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.icon-preview-box img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}
.icon-preview-box .preview-emoji { font-size: 1.8rem; }

/* ── Category list ───────────────────────────────────────────────────────────── */
.cat-list { display: flex; flex-direction: column; gap: 0.75rem; }
.cat-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cat-item-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}
.cat-item-header:hover { background: rgba(255,255,255,0.03); }
.cat-item-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cat-item-icon img { width: 100%; height: 100%; object-fit: contain; }
.cat-item-name { font-size: 0.9rem; font-weight: 600; flex: 1; }
.cat-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 20px;
  font-weight: 500;
}
.cat-badge--public { background: var(--accent-dim); color: var(--accent); }
.cat-badge--private { background: var(--surface); color: var(--text-faint); border: 1px solid var(--border); }
.cat-actions { display: flex; gap: 0.3rem; }
.cat-chevron {
  color: var(--text-faint);
  font-size: 0.75rem;
  transition: transform var(--transition);
}
.cat-item.open .cat-chevron { transform: rotate(90deg); }

.cat-links {
  display: none;
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
}
.cat-item.open .cat-links { display: block; }

.link-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.75rem 0 0; }
.link-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.link-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.link-item-icon img { width: 100%; height: 100%; object-fit: contain; }
.link-item-info { flex: 1; min-width: 0; }
.link-item-name { font-size: 0.85rem; font-weight: 500; }
.link-item-url { font-size: 0.75rem; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn 0.15s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.2rem;
  cursor: pointer;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Toast notifications ─────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast-item {
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  animation: toastIn 0.2s ease, toastOut 0.2s ease 2.8s forwards;
  pointer-events: auto;
}
.toast-item--success { background: var(--success); color: #fff; }
.toast-item--error   { background: var(--danger);  color: #fff; }
@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to   { opacity: 0; transform: translateX(20px); } }

/* ── Drag handle ─────────────────────────────────────────────────────────────── */
.drag-handle { color: var(--text-faint); cursor: grab; font-size: 1rem; padding: 0 0.2rem; }
.drag-handle:active { cursor: grabbing; }

/* ── Toggle switch ───────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.toggle-row label { font-size: 0.875rem; color: var(--text); cursor: pointer; }
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background var(--transition);
  cursor: pointer;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .header-search { max-width: none; flex: 1; }
  .user-name { display: none; }
  .links-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .field-row { grid-template-columns: 1fr; }
  .cat-item-header { flex-wrap: wrap; }
}
