/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --accent: #059669;
  --accent-hover: #047857;
  --accent-light: #d1fae5;
  --border: #e5e7eb;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* --- Header --- */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

#header h1 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }

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

.btn-danger {
  background: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: #fef2f2; }

.btn-small {
  padding: 5px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  transition: all 0.15s ease;
}
.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-icon.danger:hover { background: #fef2f2; color: var(--danger); }

/* --- Admin bar --- */
.admin-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 32px;
  background: var(--accent-light);
  border-bottom: 1px solid #a7f3d0;
}

.admin-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  background: white;
  padding: 3px 10px;
  border-radius: 20px;
  margin-right: auto;
}

.admin-divider {
  width: 1px;
  height: 20px;
  background: #a7f3d0;
  margin: 0 4px;
}

.admin-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.admin-select {
  padding: 3px 8px;
  border: 1px solid #a7f3d0;
  border-radius: 4px;
  font-size: 0.8rem;
  background: white;
  cursor: pointer;
  outline: none;
}
.admin-select:focus { border-color: var(--accent); }

.admin-color-picker {
  width: 28px;
  height: 28px;
  border: 1px solid #a7f3d0;
  border-radius: 4px;
  padding: 1px;
  cursor: pointer;
  background: white;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal h2 {
  font-size: 1.15rem;
  margin-bottom: 16px;
}

.modal input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 8px;
  outline: none;
  transition: border-color 0.15s;
}
.modal input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* --- Links grid --- */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  padding: 14px 32px;
  max-width: 1600px;
  margin: 0 auto;
}

/* --- Category card --- */
.category-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s;
}
.category-card:hover {
  box-shadow: var(--shadow-md);
}
.category-card[draggable="true"] {
  cursor: grab;
}
.category-card.dragging {
  opacity: 0.4;
  cursor: grabbing;
}
.category-card.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.link-item[draggable="true"] {
  cursor: grab;
}
.link-item.dragging {
  opacity: 0.3;
}
.link-item.drag-over-link {
  border-top: 2px solid var(--accent);
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 2px solid var(--accent-light);
}

.category-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
}

.category-header .admin-controls {
  display: flex;
  gap: 2px;
}

.category-links {
  padding: 4px 0;
  list-style: none;
}

.category-links li {
  position: relative;
}

.category-links a {
  display: block;
  padding: 3px 18px;
  color: var(--link-color, var(--accent));
  text-decoration: none;
  font-size: var(--link-font-size, 0.9rem);
  font-weight: var(--link-font-weight, 400);
  transition: all 0.1s ease;
}
.category-links a:hover {
  background: var(--accent-light);
  color: var(--link-color-hover, var(--accent-hover));
  filter: brightness(0.85);
}

.link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
}

.link-item .link-admin-controls {
  display: flex;
  gap: 1px;
  opacity: 0;
  transition: opacity 0.15s;
}
.link-item:hover .link-admin-controls {
  opacity: 1;
}

.add-link-btn {
  display: block;
  width: 100%;
  padding: 8px 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.add-link-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.more-link {
  display: block;
  padding: 8px 18px;
  text-align: right;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-top: 1px solid var(--border);
  transition: all 0.15s;
}
.more-link:hover {
  color: var(--accent);
  background: var(--accent-light);
}

/* --- Inline edit --- */
.inline-edit {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  align-items: center;
}

.inline-edit input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  outline: none;
}
.inline-edit input:focus { border-color: var(--accent); }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 80px 32px;
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* --- Utility --- */
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 640px) {
  #header { padding: 12px 16px; }
  .admin-bar { padding: 8px 16px; flex-wrap: wrap; }
  .links-grid { padding: 8px; gap: 7px; grid-template-columns: 1fr; }
}
