@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300;1,9..40,400&display=swap');

:root {
  /* --accent: #F8568D; */
  --accent: #F8568D;
  --accent-light: #F8568D22;
  --accent-mid: #F8568D44;
  --bg: #fcfcfc;
  --dot-color: #d1d4d8;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --text-faint: #d1d5db;
  --surface: #f9fafb;
  --surface-hover: #f3f4f6;
  --white: #ffffff;
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 250px;
  --toolbar-bg: rgba(255,255,255,0.92);
  --toolbar-shadow: 0 2px 20px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(circle, var(--dot-color) 1.2px, transparent 1.2px);
  background-size: 47.6px 47.6px;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 4px; }

/* ─── LAYOUT ─── */
#app { display: flex; height: 100vh; width: 100%; }

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--white); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  transition: width .2s, min-width .2s;
  flex-shrink: 0; z-index: 10;
}
.sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; border-right: none; }
.sidebar.collapsed .sidebar-content { display: none; }
.sidebar.collapsed .sidebar-header { display: none; }

.sidebar-header {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 10px 12px 0; flex-shrink: 0;
}
.sidebar-close-btn {
  width: 30px; height: 30px;
  border: none; background: transparent; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s; color: var(--text-secondary);
}
.sidebar-close-btn:hover { background: var(--surface-hover); }
.sidebar-close-btn svg { width: 16px; height: 16px; }

/* Floating panel toggle button (ignite-style, left edge, vertically centered) */
.panel-toggle-btn {
  position: fixed;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9;
}
.panel-toggle-btn button {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.06);
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--toolbar-shadow);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.panel-toggle-btn button:hover { background: #f0eeeb; }
.panel-toggle-btn button svg { width: 18px; height: 18px; color: var(--text); }

.sidebar-content {
  display: flex; flex-direction: column; padding: 0 12px 16px;
  overflow-y: auto; overflow-x: hidden; flex: 1;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 4px 14px; border-bottom: 1px solid var(--border-light); margin-bottom: 10px;
}
.sidebar-logo-text {
  font-size: 13px; font-weight: 600; letter-spacing: .08em; color: var(--text); white-space: nowrap;
}
.sidebar-logo-text sup { font-weight: 300; font-size: 7px; letter-spacing: .02em; }

.sidebar-section { margin-bottom: 6px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 4px;
}
.section-title {
  font-size: 10px; font-weight: 500; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
}
.section-add-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px; display: flex; align-items: center; border-radius: 4px;
}
.section-add-btn:hover { color: var(--accent); }

.collection-item {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  border: none; background: transparent; cursor: pointer;
  font-size: 12.5px; color: var(--text); width: 100%; text-align: left; font-family: inherit;
  transition: background .1s;
}
.collection-item:hover { background: var(--surface-hover); }
.collection-item.active { background: var(--surface-hover); font-weight: 500; }
.collection-icon { margin-right: 6px; font-size: 11px; opacity: .5; }

/* Collection drag handle (compact 6-dot vertical grip) */
.collection-drag-handle {
  display: flex; align-items: center; justify-content: center;
  width: 12px; flex-shrink: 0; cursor: grab;
  color: transparent; transition: color 0.15s;
  margin-left: -2px; margin-right: 2px;
}
.collection-drag-handle:active { cursor: grabbing; }
.collection-item:hover .collection-drag-handle { color: #c0bdb8; }
.collection-item.active .collection-drag-handle { color: var(--accent); opacity: 0.45; }
.collection-item:hover.active .collection-drag-handle { opacity: 0.7; }

/* Collection name */
.collection-name {
  flex: 1; text-align: left; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* Collection hover action buttons */
.collection-actions {
  display: flex; align-items: center; gap: 1px;
  flex-shrink: 0; margin-left: auto;
}
.collection-action-btn {
  width: 22px; height: 22px; border: none; background: transparent;
  border-radius: 5px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.12s, background 0.12s;
  flex-shrink: 0; color: var(--text-muted); padding: 0;
}
.collection-item:hover .collection-action-btn { opacity: 1; }
.collection-action-btn:hover { background: var(--accent-light); color: var(--accent); }
.collection-action-btn svg { width: 10px; height: 10px; }
.collection-delete-btn:hover { background: #fef2f2; color: #ef4444; }

/* Collection inline rename */
.collection-rename-input {
  flex: 1; padding: 1px 4px; border: 1px solid var(--accent);
  border-radius: 3px; font-size: 12px; outline: none;
  background: var(--white); color: var(--text); font-family: inherit;
  min-width: 0;
}

/* Collection sortable states */
.collection-sortable-ghost { opacity: 0.4; background: var(--accent-light); border-radius: var(--radius-sm); }
.collection-sortable-chosen .collection-drag-handle { color: var(--accent); cursor: grabbing; }

.tag-list { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 6px; }
.tag-pill {
  display: inline-flex; align-items: center;
  padding: 1px 7px; font-size: 10px; font-weight: 400;
  border-radius: 20px; border: 1px solid;
  cursor: pointer; font-family: inherit;
  line-height: 1.2; transition: all .12s;
  white-space: nowrap;
}
.tag-pill:hover { opacity: .85; }
.tag-pill.active { color: #fff; }

.inline-add { padding: 4px 6px; }
.inline-input {
  width: 100%; padding: 5px 8px; border: 1px dashed var(--text-faint);
  border-radius: var(--radius-sm); font-size: 12px; outline: none;
  background: var(--surface); color: var(--text); font-family: inherit;
}
.inline-input:focus { border-color: var(--accent); }

/* ─── MAIN AREA ─── */
.main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; position: relative; min-width: 0;
}

/* ─── FLOATING TOP BAR ─── */
.topbar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  padding: 6px 8px;
  box-shadow: var(--toolbar-shadow);
  border: 1px solid rgba(0,0,0,0.05);
  z-index: 1000;
  max-width: calc(100vw - 32px);
}

.search-box {
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,0.04); border: none;
  border-radius: 8px; padding: 5px 10px;
}
.search-input {
  border: none; background: transparent; outline: none;
  font-size: 12.5px; color: var(--text); min-width: 140px; font-family: inherit;
}
.search-input::placeholder { color: var(--text-faint); }
.clear-search {
  background: none; border: none; cursor: pointer; color: var(--text-muted); display: flex; padding: 0;
}

.topbar-divider {
  width: 1px; height: 18px; background: rgba(0,0,0,0.08); flex-shrink: 0;
}
.sidebar-backdrop { display: none; }
.snippet-count { font-size: 11px; color: var(--text-muted); white-space: nowrap; padding: 0 4px; }

.add-card-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 12px; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; cursor: pointer;
  font-size: 12px; font-weight: 500; font-family: inherit; white-space: nowrap;
}
.add-card-btn:hover { opacity: .9; }

/* ─── FILTERS ─── */
.active-filters {
  display: none; align-items: center; gap: 6px; padding: 6px 16px;
  background: rgba(255,255,255,.6); border-radius: 10px;
  flex-wrap: wrap; flex-shrink: 0; margin-bottom: 10px;
}
.active-filters.visible { display: flex; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 8px; border-radius: var(--radius-sm);
  background: var(--surface-hover); color: var(--text-secondary); border: 1px solid var(--border);
}
.filter-remove {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; padding: 0; margin-left: 2px;
}
.clear-filters {
  background: none; border: none; cursor: pointer;
  font-size: 11px; color: var(--accent); font-family: inherit;
}
.clear-filters:hover { text-decoration: underline; }

/* ─── WALL ─── */
.wall {
  flex: 1; overflow: auto;
  padding: 60px 20px 20px;
}

#wall-grid {
  position: relative;
  margin: 0 auto;
  padding: 0 0 60px;
}

.wall-item {
  display: block;
  position: absolute;
  width: 280px;
  margin: 10px;
  z-index: 1;
  -webkit-user-select: auto !important;
  user-select: auto !important;
}

.wall-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; padding: 60px;
  text-align: center;
}

/* ─── CARD ─── */
.card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; position: relative;
  transition: box-shadow .15s, border-color .15s;
  overflow: hidden;
  animation: cardIn .2s ease;
  min-height: 80px;
}
.card:hover { border-color: var(--text-faint); }
.card.expanded { box-shadow: 0 2px 12px rgba(0,0,0,.06); border-color: var(--text-faint); }

/* Drag handle — horizontal grip (3×2 dots) */
.card-drag-handle {
  display: flex; align-items: center; justify-content: center;
  padding: 8px 0 4px; cursor: grab; flex-shrink: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
.card-drag-handle:active { cursor: grabbing; }
.grip-icon { color: #d1d4d8; transition: color .15s; }
.card:hover .grip-icon { color: var(--text-muted); }

.card-image {
  width: 100%; max-height: 140px; object-fit: cover; display: block; flex-shrink: 0;
}

.card-body {
  padding: 6px 12px 4px; display: flex; flex-direction: column; gap: 5px; flex: 1;
  overflow-y: auto; overflow-x: hidden;
  -webkit-user-select: text; user-select: text; cursor: default;
}
.card-top { display: flex; align-items: center; gap: 4px; min-height: 14px; }
.card-pin-icon { color: var(--accent); display: flex; align-items: center; }
.card-collection-label {
  font-size: 9.5px; color: var(--text-muted);
  display: flex; align-items: center; gap: 3px;
}
.card-actions {
  margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .15s;
}
.card:hover .card-actions { opacity: 1; }
.card-action-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px; display: flex; align-items: center; border-radius: 3px;
}
.card-action-btn:hover { color: var(--accent); }

.card-text {
  font-size: 12px; line-height: 1.55; color: var(--text);
  white-space: pre-wrap; word-break: break-word; overflow: hidden; flex: 1;
}
.card-text.clamped {
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
/* Markdown */
.card-text.md h1 { font-size: 14px; font-weight: 600; margin: 4px 0 2px; }
.card-text.md h2 { font-size: 13px; font-weight: 600; margin: 3px 0 2px; }
.card-text.md h3 { font-size: 12px; font-weight: 600; margin: 2px 0 1px; }
.card-text.md p { margin: 2px 0; white-space: normal; }
.card-text.md ul, .card-text.md ol { padding-left: 18px; margin: 2px 0; }
.card-text.md li { margin: 1px 0; }
.card-text.md code {
  background: var(--surface-hover); padding: 1px 4px; border-radius: 3px;
  font-size: 11px; font-family: 'SF Mono', 'Fira Code', monospace;
}
.card-text.md pre { background: var(--surface-hover); padding: 6px 8px; border-radius: 4px; overflow-x: auto; margin: 4px 0; }
.card-text.md pre code { background: none; padding: 0; }
.card-text.md blockquote {
  border-left: 2px solid var(--accent); padding-left: 8px;
  color: var(--text-secondary); margin: 4px 0; font-style: italic;
}
.card-text.md strong { font-weight: 600; }
.card-text.md em { font-style: italic; }
.card-text.md a { color: var(--accent); text-decoration: none; }
.card-text.md hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

.card-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.card-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 400;
  border-radius: 20px;
  border: 1px solid;
  white-space: nowrap;
  line-height: 1.2;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  cursor: default;
}

.card-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 2px 10px 6px; flex-shrink: 0;
}
.char-count { font-size: 9px; color: var(--text-faint); font-weight: 300; }
.md-toggle {
  width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  border-radius: 3px; border: 1px solid var(--border); background: var(--white);
  cursor: pointer; font-size: 9px; font-weight: 600; font-family: inherit;
  color: var(--text-faint); transition: all .12s; line-height: 1; padding: 0;
}
.md-toggle:hover { border-color: var(--text-muted); color: var(--text-muted); }
.md-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Vertical resize handle (bottom of card) */
.card-resize {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 14px;
  cursor: ns-resize;
  opacity: 0;
  transition: opacity .15s;
  z-index: 5;
}
.card:hover .card-resize { opacity: 1; }
.card-resize::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: var(--text-faint);
}

/* Muuri drag states */
.wall-item.muuri-item-dragging { z-index: 10; }
.wall-item.muuri-item-dragging .card { box-shadow: 0 8px 28px rgba(0,0,0,.12); border-color: var(--text-faint); }
.wall-item.muuri-item-releasing { z-index: 9; }
.wall-item.muuri-item-hidden { z-index: 0; }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.18);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
  backdrop-filter: blur(2px); animation: fadeIn .15s ease;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--white); border-radius: 12px; padding: 20px; width: 420px;
  max-width: 92vw; max-height: 85vh; overflow: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  display: flex; flex-direction: column; gap: 14px; animation: modalIn .18s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 14px; font-weight: 500; }
.modal-close {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; padding: 4px; border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--surface-hover); }
.modal-textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px; outline: none; resize: vertical;
  color: var(--text); line-height: 1.5; min-height: 80px; background: var(--surface); font-family: inherit;
}
.modal-textarea:focus { border-color: var(--accent); }

.image-upload-area {
  border: 1px dashed var(--text-faint); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; cursor: pointer; position: relative;
  min-height: 56px; transition: border-color .12s, background .12s;
}
.image-upload-area:hover { border-color: var(--accent); background: var(--accent-light); }
.image-upload-area input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.image-upload-text { font-size: 11px; color: var(--text-muted); }
.image-preview-wrap { position: relative; }
.image-preview { width: 100%; max-height: 150px; object-fit: cover; border-radius: var(--radius-sm); }
.image-remove-btn {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,.5); color: #fff; border: none; border-radius: 50%;
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 12px;
}
.image-remove-btn:hover { background: rgba(0,0,0,.7); }

.modal-field { display: flex; flex-direction: column; gap: 6px; }
.modal-label {
  font-size: 10px; font-weight: 500; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
}
.modal-options { display: flex; flex-wrap: wrap; gap: 4px; }
.modal-option {
  font-size: 11px; padding: 4px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  font-family: inherit; color: var(--text); background: transparent; transition: all .1s;
}
.modal-option:hover { background: var(--surface-hover); }
.modal-option.active { background: var(--surface-hover); border-color: var(--text-faint); font-weight: 500; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.cancel-btn {
  padding: 6px 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--white); cursor: pointer; font-size: 12px;
  color: var(--text-secondary); font-family: inherit;
}
.cancel-btn:hover { background: var(--surface-hover); }
.save-btn {
  padding: 6px 16px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  font-size: 12px; font-weight: 500; font-family: inherit;
}
.save-btn:hover { opacity: .9; }
.save-btn:disabled { opacity: .4; cursor: default; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes cardIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================
   RESPONSIVE – MOBILE
   ============================================ */
/* ─── SIDEBAR USER SECTION ─── */
.sidebar-user {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.sidebar-user-info {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px 8px;
}
.sidebar-user-name {
  font-size: 12px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-role-badge {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  flex-shrink: 0;
}
.badge-owner { background: #ffe0ec; color: #F8568D; }
.badge-admin { background: #e0e7ff; color: #4f46e5; }
.badge-member { background: #f0eeeb; color: #6b7280; }
.sidebar-user-actions {
  display: flex; gap: 2px; padding: 0 2px 4px;
}
.sidebar-action-link {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 8px; border-radius: var(--radius-sm);
  font-size: 11.5px; color: var(--text-secondary);
  text-decoration: none; border: none; background: transparent;
  cursor: pointer; font-family: inherit; transition: background .1s;
}
.sidebar-action-link:hover { background: var(--surface-hover); color: var(--text); }

/* ============================================
   RESPONSIVE – MOBILE
   ============================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 50; box-shadow: 4px 0 20px rgba(0,0,0,.08);
    width: var(--sidebar-w); min-width: var(--sidebar-w);
  }
  .sidebar.collapsed {
    box-shadow: none;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.2);
    z-index: 49;
  }

  .topbar {
    top: 12px;
  }
  .search-input { min-width: 80px; font-size: 13px; }
  .add-card-btn span { display: none; }
  .add-card-btn { padding: 6px 8px; }

  .wall {
    padding: 56px 10px 20px;
  }
  .wall-item { width: 80vw !important; }
  #wall-grid { padding: 0 0 40px; }
}
