/* ════════════════════════════════════════════════════════════════
   style.css  –  Bokmärken – layout & komponenter
   ════════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design-tokens ───────────────────────────────────────────── */
:root {
  --bg:           #F7F5F0;
  --surface:      #FFFFFF;
  --surface2:     #F0EDE6;
  --border:       rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.16);
  --text:         #1A1916;
  --muted:        #6B6760;
  --accent:       #2D6A4F;
  --accent-light: #E8F4EE;
  --danger:       #b91c1c;
  --danger-bg:    #fecaca;
  --shadow:       0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
}

/* ── Bas ─────────────────────────────────────────────────────── */
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 2rem 2.5rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-left h1 {
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.header-left p {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
  font-family: 'DM Mono', monospace;
}

/* ── Sök ─────────────────────────────────────────────────────── */
.search-wrap {
  flex: 1;
  max-width: 360px;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}

#search {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px 8px 34px;
  font-size: 0.85rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,106,79,0.12);
  background: var(--surface);
}

#search::placeholder { color: var(--muted); }

/* ── Filter-knappar ──────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 0.75rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn:hover { border-color: var(--border-hover); color: var(--text); }

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Statistikrad ────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 1.5rem;
  padding: 0.75rem 2.5rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
}

.stats-bar strong { color: var(--text); font-weight: 500; }

/* ── Innehåll ────────────────────────────────────────────────── */
main {
  padding: 1.5rem 2rem 6rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.5rem;
  align-items: start;
}

/* ── Kategori-sektion ────────────────────────────────────────── */
.section { margin-bottom: 0; }

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1rem;
}

/* Redigera/ta-bort-knappar på sektionshuvud */
.section-actions {
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.section-header:hover .section-actions { opacity: 1; }

/* Kollaps-pil */
.section-toggle {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.2s;
  user-select: none;
  line-height: 1;
}

.section.collapsed .section-toggle { transform: rotate(-90deg); }

.section.collapsed > .grid,
.section.collapsed > .subsection   { display: none; }

.section.collapsed.search-expanded > .grid,
.section.collapsed.search-expanded > .subsection { display: grid; }

/* Drag-handtag */
.section-drag-handle {
  font-size: 14px;
  color: var(--muted);
  cursor: grab;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
  line-height: 1;
  padding: 2px 1px;
  user-select: none;
}

.section-header:hover .section-drag-handle { opacity: 0.5; }
.section-drag-handle:hover                 { opacity: 1 !important; }

/* Sektion som dras */
.section.section-dragging {
  opacity: 0.4;
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  border-radius: 8px;
}

/* Guide-linje ovanför/nedanför vid sektion-drag */
.section.section-drop-above {
  border-top: 2px solid var(--accent);
  margin-top: -2px;
}

.section.section-drop-below {
  border-bottom: 2px solid var(--accent);
  margin-bottom: -2px;
}

.section-btn {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0;
  background: var(--surface2);
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}

.section-btn:hover          { background: var(--accent-light); color: var(--accent); }
.section-btn.del:hover      { background: var(--danger-bg);    color: var(--danger); }

/* Bekräftelsedialog för ta bort kategori */
.confirm-box {
  margin-top: 0.75rem;
  padding: 0.9rem 1rem;
  background: #fff5f5;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.5;
}

.confirm-box p { margin-bottom: 0.75rem; }

.confirm-actions { display: flex; gap: 8px; }

.btn-danger {
  background: var(--danger);
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-family: 'DM Sans', sans-serif;
  color: #fff;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s;
}

.btn-danger:hover { opacity: 0.88; }

.section-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-count {
  font-size: 0.72rem;
  font-family: 'DM Mono', monospace;
  color: var(--muted);
  opacity: 0.6;
}

.divider {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Kortgrid ────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  min-height: 10px;                /* synlig drop-zon även när tom */
  border-radius: 10px;
  transition: background 0.15s, outline 0.15s;
}

/* Drop-highlight när man drar över en sektion */
.section.drag-over .grid {
  background: var(--accent-light);
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

/* ── Kort ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s, opacity 0.2s;
  box-shadow: var(--shadow);
  position: relative;
  cursor: grab;
  user-select: none;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

/* Dras */
.card.dragging {
  opacity: 0.35;
  cursor: grabbing;
  transform: scale(0.96);
}

/* ── Favicon ─────────────────────────────────────────────────── */
.card-favicon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 1px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-favicon img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.card-favicon .placeholder {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
}

/* ── Korttext ────────────────────────────────────────────────── */
.card-content { flex: 1; min-width: 0; }

.card-title {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.card-url { display: none; }

/* ── Kortåtgärder (visas vid hover) ──────────────────────────── */
.card-actions {
  display: flex;
  flex-direction: row;
  gap: 4px;
  justify-content: flex-end;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.15s, max-height 0.15s, margin-top 0.15s;
}

.card:hover .card-actions {
  opacity: 1;
  max-height: 28px;
  margin-top: 6px;
}

.card-btn {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
  background: var(--surface2);
  color: var(--muted);
}

.card-btn:hover            { background: var(--accent-light); color: var(--accent); }
.card-btn.del:hover        { background: var(--danger-bg);    color: var(--danger); }

/* ── Dölj/visa ───────────────────────────────────────────────── */
.card.hidden    { display: none; }
.section.hidden { display: none; }

.no-results {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
  font-size: 0.9rem;
  display: none;
}

/* ── Speed-dial FAB ──────────────────────────────────────────── */
#fab-wrap {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

#fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(45,106,79,0.35), 0 2px 4px rgba(0,0,0,0.12);
  transition: box-shadow 0.15s, rotate 0.25s;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

#fab:hover { box-shadow: 0 6px 20px rgba(45,106,79,0.45); }
#fab-wrap.open #fab { rotate: 45deg; }

.fab-action {
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}

#fab-wrap.open .fab-action {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#fab-wrap.open .fab-action:nth-child(1) { transition-delay: 0.04s; }
#fab-wrap.open .fab-action:nth-child(2) { transition-delay: 0s;    }

.fab-label {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  box-shadow: var(--shadow);
  font-family: 'DM Sans', sans-serif;
}

.fab-mini {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  background: var(--surface);
}

.fab-mini:hover { transform: scale(1.08); box-shadow: var(--shadow-hover); }
#fab-link { color: var(--accent); }
#fab-cat  { color: #7c3aed;       }

/* ── Modaler – gemensam bas ──────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 300;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.75rem 2rem;
  width: 100%;
  max-width: 430px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  position: relative;
}

.modal h2 {
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
}

.modal-close:hover { color: var(--text); }

/* Fält */
.modal-field { margin-bottom: 1rem; }

.modal-field label {
  display: block;
  font-size: 0.73rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
  font-family: 'DM Mono', monospace;
}

.modal-field input,
.modal-field select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-field input:focus,
.modal-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,106,79,0.12);
  background: var(--surface);
}

/* Knappar */
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.btn-cancel {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.83rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-cancel:hover { border-color: var(--border-hover); color: var(--text); }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 0.83rem;
  font-family: 'DM Sans', sans-serif;
  color: #fff;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.88; }

.modal-msg {
  font-size: 0.78rem;
  margin-top: 0.5rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* Ny-kategori-fält (dolt som standard) */
.new-cat-wrap         { display: none; }
.new-cat-wrap.visible { display: block; }

/* ── Emoji- och färgväljare ──────────────────────────────────── */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.emoji-btn {
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 6px;
  font-size: 18px;
  padding: 4px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.12s, background 0.12s;
  line-height: 1.3;
}

.emoji-btn:hover    { background: var(--accent-light); }
.emoji-btn.selected { border-color: var(--accent); background: var(--accent-light); }

.color-grid {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  outline: none;
}

.color-swatch:hover    { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text); transform: scale(1.15); }

/* ── Flytta-modal – kategorilistning ─────────────────────────── */
#move-cat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 4px;
}

.move-cat-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.12s, border-color 0.12s;
}

.move-cat-opt:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.move-cat-opt .opt-icon {
  font-size: 16px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Underkategorier ─────────────────────────────────────────── */
.subsection {
  margin-left: 1.75rem;
  margin-top: 1rem;
  margin-bottom: 0;
  padding-left: 0.875rem;
  border-left: 2px solid var(--border);
}

.subsection .section-title { font-size: 0.73rem; }

.subsection .section-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-size: 11px;
}

.section-btn.add-sub { color: #7c3aed; }
.section-btn.add-sub:hover { background: #f5f3ff; color: #6d28d9; }

.move-cat-sub { margin-left: 1.25rem; }
.move-cat-sub .opt-icon { width: 22px; height: 22px; font-size: 13px; }

/* ── Responsiv ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  header { flex-wrap: wrap; padding: 1.25rem; }
  main   { padding: 1.25rem 1.25rem 5rem; }
  .stats-bar { padding: 0.75rem 1.25rem; flex-wrap: wrap; gap: 0.75rem; }
  .grid  { grid-template-columns: 1fr; }
}
