:root {
  --bg: #0f172a;
  --surface: rgba(30, 41, 59, .86);
  --surface-solid: #1e293b;
  --surface-2: #243449;
  --border: rgba(148, 163, 184, .18);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --radius: 14px;
  --radius-cards: 14px;
  --radius-modals: 16px;
  --radius-fields: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,.35);
  --card-shadow: 0 8px 26px rgba(0,0,0,.45);
  --bg-overlay: rgba(15, 23, 42, .55);

  /* Apariencia global (se sobreescriben dinámicamente desde app.js) */
  --link-bg: #243449;
  --link-fg: #e2e8f0;
  --folder-bg: rgba(30, 41, 59, .86);
  --folder-opacity: 1;
}
[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: rgba(255,255,255,.9);
  --surface-solid: #fff;
  --surface-2: #f8fafc;
  --border: rgba(15,23,42,.12);
  --text: #0f172a;
  --text-dim: #64748b;
  --accent: #4f46e5;
  --accent-hover: #6366f1;
  --shadow: 0 4px 20px rgba(15,23,42,.12);
  --card-shadow: 0 4px 20px rgba(15,23,42,.07), 0 0 18px 2px rgba(255,255,255,.95);
  --bg-overlay: rgba(241,245,249,.55);
  --link-bg: #f8fafc;
  --link-fg: #0f172a;
  --folder-bg: rgba(255,255,255,.9);
}

[data-theme="light"] .folder {
  border: none !important;
  box-shadow: 0 4px 20px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
}
[data-theme="light"] .folder-head {
  border-bottom: none !important;
}

[data-theme="light"] .logo span {
  color: #000000 !important;
  text-shadow: none !important;
  -webkit-text-stroke: 0 !important;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Montserrat', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color .3s, color .3s;
}
body::before {
  content: ''; position: fixed; inset: 0;
  background: var(--bg-overlay);
  pointer-events: none; z-index: -1;
}
button { font-family: inherit; }

.field { margin-bottom: 15px; text-align: left; }
.field label {
  display: block; font-size: 12px; font-weight: 600;
  margin-bottom: 6px; color: var(--text-dim);
  letter-spacing: .3px; text-transform: uppercase;
}
.field input, .field select, .field textarea,
.btn, .btn-ghost, .btn-solid,
.icon-btn,
.add-form input, .add-form button,
.link,
.bg-tab,
.dropdown-item,
input[type=file], input[type=file]::file-selector-button {
  border-radius: var(--radius-fields, 10px) !important;
}

.folder {
  border-radius: var(--radius-cards, 14px) !important;
}

.modal {
  border-radius: var(--radius-modals, 16px) !important;
}

.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color .2s;
  max-width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field input[type=checkbox] { width: auto; }

.btn {
  width: 100%; padding: 13px; border-radius: var(--radius-fields, 10px); border: none;
  background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .2s, transform .1s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.98); }
.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 10px; min-height: 18px; font-weight: 500; }

.app { display: none; min-height: 100vh; }
.app[data-active="1"] { display: block; }

header {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
}
.logo {
  font-size: 20px; font-weight: 700; letter-spacing: -.5px;
  /*background: linear-gradient(135deg, var(--accent-hover), #c084fc);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;*/
  white-space: nowrap; display: flex; align-items: center; gap: 8px;
}
.logo i { -webkit-text-fill-color: initial; color: var(--accent); }
.logo span { color:white !important; }
.add-form { flex: 1; display: flex; gap: 8px; min-width: 260px; max-width: 760px; }
.add-form input {
  padding: 10px 13px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 13.5px; font-family: inherit;
}
.add-form input:focus { outline: none; border-color: var(--accent); }
.add-form input[type=url] { flex: 2; }
.add-form input[type=text] { flex: 1; }
.add-form button {
  padding: 10px 16px; border-radius: 9px; border: none;
  background: var(--accent); color: #fff; font-weight: 600;
  cursor: pointer; font-size: 13.5px; white-space: nowrap;
}
.add-form button:hover { background: var(--accent-hover); }

.header-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, border-color .2s, color .2s;
}
.icon-btn:hover { background: rgba(99,102,241,.22); border-color: var(--accent); }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px; border-radius: 100px;
  background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.user-chip:hover {
  background: rgba(99,102,241,.22); border-color: var(--accent);
}
.user-chip img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.user-chip span {
  font-size: 12.5px; font-weight: 500;
  max-width: 120px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* -------- BOARD & COLUMNS -------- */
.board {
  padding: 22px;
  display: flex;
  gap: 18px;
  align-items: flex-start;
  min-height: calc(100vh - 68px);
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.board-column {
  flex: 1 1 0px;
  min-width: var(--col-min-width, 240px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-sizing: border-box;
}
.board-column.drag-target {
  background: rgba(99, 102, 241, 0.06);
  border-radius: var(--radius-cards, 14px);
}

/* -------- FOLDER -------- */
.folder {
  background: var(--folder-bg);
  opacity: var(--folder-opacity);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius-cards, 14px) !important;
  box-shadow: var(--card-shadow);
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s;
}
.folder.folder-transparent {
  background: transparent !important;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.folder.drag-over { border-color: var(--accent-hover); box-shadow: 0 0 0 2px var(--accent), var(--card-shadow); }

.folder-head {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; cursor: grab; user-select: none;
  border-bottom: 1px solid var(--border);
  position: relative;
  height: 48px;
  min-height: 48px;
  max-height: 48px;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.folder-head:active { cursor: grabbing; }
.folder-title {
  flex: 1; font-weight: 600; font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 48px;
  height: 48px;
  padding: 0 4px;
  display: block;
  min-width: 0;
  box-sizing: border-box;
}
.folder-title[contenteditable="true"] {
  outline: none; background: rgba(255,255,255,.25);
  border-radius: 6px; cursor: text; padding: 2px 6px;
  line-height: normal;
  height: auto;
  display: block !important;
}
.folder-count {
  font-size: 10.5px; font-weight: 700;
  padding: 3px 8px; border-radius: 20px; flex-shrink: 0;
  opacity: 0; pointer-events: none;
  transition: opacity .15s ease-in-out;
}
.folder-actions {
  display: none;
  gap: 4px;
  flex: 1;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
  justify-content: flex-end;
  align-items: center;
}
.folder-head:hover .folder-title:not([contenteditable="true"]),
.folder-head:focus-within .folder-title:not([contenteditable="true"]) {
  display: none;
}
.folder-head:hover .folder-actions,
.folder-head:focus-within .folder-actions {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}
.folder-head:hover .folder-count,
.folder-head:focus-within .folder-count {
  opacity: 1; pointer-events: auto;
}
@media (hover: none) {
  .folder-head .folder-title { display: block !important; }
  .folder-head .folder-actions { display: flex !important; opacity: 1; pointer-events: auto; }
  .folder-head .folder-count { opacity: 1; pointer-events: auto; }
}
.folder-btn {
  width: 28px; height: 28px; border-radius: var(--radius-fields, 7px); border: none;
  background: rgba(255,255,255,.12); cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.folder-btn:hover { background: rgba(255,255,255,.28); }

.folder-drop-placeholder {
  border: 2px dashed var(--accent);
  border-radius: var(--radius-cards, 14px);
  min-height: 70px;
  margin: 4px 0;
  opacity: 0.75;
}

.folder-body {
  padding: 8px 10px 10px;
  display: flex; flex-direction: column; gap: 5px;
  max-height: 480px; overflow-y: auto;
}
.folder.folder-noscroll .folder-body { max-height: none; overflow-y: visible; }
.folder-body::-webkit-scrollbar { width: 6px; }
.folder-body::-webkit-scrollbar-thumb { background: rgba(148,163,184,.3); border-radius: 3px; }

/* -------- LINK (con fondo y texto globales) -------- */
.link {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 9px; border-radius: 9px;
  background: var(--link-bg);
  color: var(--link-fg);
  border: 1px solid transparent;
  cursor: grab; transition: border-color .15s, filter .15s;
}
.link:hover { border-color: var(--border); filter: brightness(1.06); }
.link:active { cursor: grabbing; }
.link.dragging { opacity: .35; }
.link .favicon {
  width: 20px; height: 20px; border-radius: 5px; flex-shrink: 0;
  background: rgba(148,163,184,.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--text-dim); overflow: hidden;
}
.link .favicon img { width: 100%; height: 100%; object-fit: contain; border-radius: 5px; }
.link .link-name {
  flex: 1; font-size: 13px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.link .link-name a { color: inherit; text-decoration: none; }
.link .link-name a:hover { text-decoration: underline; }
.link-actions { display: flex; gap: 1px; opacity: 0; transition: opacity .15s; }
.link:hover .link-actions { opacity: 1; }
.link-actions button {
  width: 24px; height: 24px; border-radius: 6px; border: none;
  background: transparent; color: inherit; cursor: pointer;
  font-size: 11px; display: flex; align-items: center; justify-content: center;
  opacity: .7;
}
.link-actions button:hover { background: rgba(148,163,184,.22); opacity: 1; }
.link-actions button.del:hover { background: rgba(239,68,68,.22); color: #f87171; }

.empty-msg { padding: 14px 10px; text-align: center; color: var(--text-dim); font-size: 12px; }
.drop-placeholder { border: 2px dashed var(--accent); border-radius: 9px; height: 36px; margin: 3px 0; }

/* -------- MODALES (igual que antes) -------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-modals, 16px); padding: 26px; width: 100%; max-width: min(480px, calc(100vw - 28px));
  box-shadow: 0 25px 60px rgba(0,0,0,.65);
  color: var(--text); max-height: 90vh; overflow-y: auto;
  box-sizing: border-box;
}
.modal h3 { font-size: 17px; margin-bottom: 18px; font-weight: 700; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.btn-ghost {
  padding: 10px 16px; border-radius: var(--radius-fields, 9px);
  border: 1px solid var(--border); background: transparent;
  color: var(--text); cursor: pointer; font-weight: 500; font-size: 13px;
}
.btn-ghost:hover { background: rgba(148,163,184,.12); }
.btn-solid {
  padding: 10px 16px; border-radius: var(--radius-fields, 9px); border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  font-weight: 600; font-size: 13px;
}
.btn-solid:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #f87171; }

.bg-preview {
  width: 100%; height: 110px; border-radius: 10px;
  object-fit: cover; margin-bottom: 14px;
  border: 1px solid var(--border); display: block;
}
.bg-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.bg-tab {
  flex: 1; padding: 8px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.bg-tab.active { background: rgba(99,102,241,.22); border-color: var(--accent); color: var(--text); }

.grid-slider-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.grid-slider-row input[type=range] { flex: 1; }
.grid-slider-val { font-weight: 700; font-size: 13px; min-width: 60px; text-align: right; color: var(--accent-hover); }

.color-row {
  display: flex; gap: 6px; padding: 4px 0 6px; flex-wrap: wrap;
}
.swatch {
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
  transition: transform .12s, border-color .12s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: #fff; transform: scale(1.15); }
.swatch.transparent {
  background: repeating-linear-gradient(45deg, #999 0 4px, #fff 4px 8px);
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-solid); border: 1px solid var(--accent);
  color: var(--text); padding: 12px 20px; border-radius: 10px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow);
  z-index: 2000;
  display: flex; align-items: center; gap: 9px;
}
.toast i { color: var(--accent); }

/* Dropdown menu for tablet/laptop/mobile */
.header-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 16px;
  background: var(--surface-solid);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-modals, 16px);
  padding: 8px;
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 150;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 32px));
  animation: dropdownIn .15s ease-out;
}
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-fields, 10px);
  color: var(--text);
  background: transparent;
  border: none;
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.dropdown-item:hover {
  background: rgba(99, 102, 241, .15);
  color: var(--accent-hover);
}
.dropdown-item i {
  width: 18px;
  text-align: center;
  color: var(--accent);
}
.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

#menuBtn { display: none; }
#toggleAddFormBtn { display: none; }

@media (max-width: 1500px) {
  .action-desktop { display: none !important; }
  #menuBtn { display: flex !important; }
}

@media (max-width: 1120px) {
  #toggleAddFormBtn { display: flex !important; }
  .add-form {
    display: none !important;
    width: 100% !important;
    max-width: 100% !important;
    order: 10;
    flex-basis: 100%;
    margin-top: 8px;
    padding: 4px 0;
    flex-wrap: wrap !important;
    gap: 8px !important;
    box-sizing: border-box;
  }
  .add-form.open {
    display: flex !important;
  }
  .add-form input[type=url] {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  .add-form input[type=text] {
    flex: 1 1 calc(50% - 4px) !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  .add-form button {
    flex: 1 1 100% !important;
    box-sizing: border-box;
  }
  .user-chip {
    padding: 3px !important;
    gap: 0 !important;
    border-radius: 50% !important;
    width: 38px !important;
    height: 38px !important;
    justify-content: center !important;
  }
  .user-chip span {
    display: none !important;
  }
}

@media (max-width: 640px) {
  header { padding: 10px 12px; gap: 8px; }
  .board { padding: 12px; gap: 12px; }
  .logo span { display: inline-block !important; }
  .login-card { padding: 28px 16px; }
  .modal { padding: 20px 14px; }
  /* En móvil la fila de añadir enlace de cabecera es innecesaria y se oculta */
  #toggleAddFormBtn { display: none !important; }
  .add-form { display: none !important; }
}

/* Fix field overflows */
.field input, .field select, .field textarea {
  max-width: 100%;
  box-sizing: border-box;
}
.grid-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  width: 100%;
  box-sizing: border-box;
}
.grid-slider-row input[type=range] {
  flex: 1;
  min-width: 0;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-2);
  border-radius: 6px;
  outline: none;
  margin: 0;
  padding: 0;
  cursor: pointer;
}
.grid-slider-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface-solid);
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  transition: transform .1s, background-color .15s;
}
.grid-slider-row input[type=range]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  background: var(--accent-hover);
}
.grid-slider-row input[type=range]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface-solid);
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.grid-slider-num {
  width: 72px !important;
  padding: 6px 8px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  text-align: center !important;
  background: var(--surface-2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: var(--radius-fields, 8px) !important;
  flex: 0 0 72px !important;
  box-sizing: border-box !important;
}
.color-row {
  display: flex;
  gap: 6px;
  padding: 4px 0 6px;
  flex-wrap: wrap;
  max-width: 100%;
}
.column-placeholder {
  border: 2px dashed var(--accent);
  border-radius: var(--radius-cards, 14px);
  min-height: 120px;
  flex: 0 0 auto;
  opacity: .75;
  box-sizing: border-box;
}

input[type=file] {
  width: 100%; padding: 10px; border-radius: var(--radius-fields, 9px);
  border: 1px dashed var(--border); background: var(--surface-2);
  color: var(--text-dim); font-size: 12.5px; font-family: inherit;
  box-sizing: border-box;
}
input[type=file]::file-selector-button {
  padding: 6px 12px; border-radius: var(--radius-fields, 7px); border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  font-weight: 600; font-size: 12px; margin-right: 8px; font-family: inherit;
}