:root {
  --bg: #000000;
  --bg-elevated: #0c0c0e;
  --surface: #1c1c1e;
  --surface-elevated: #2c2c2e;
  --surface-hover: #3a3a3c;
  --border: rgba(255, 255, 255, 0.08);
  --separator: rgba(255, 255, 255, 0.06);
  --text: #ffffff;
  --muted: #8e8e93;
  --accent: #5e5ce6;
  --accent-hover: #7d7aff;
  --danger: #ff453a;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  --shell-max: 430px;
  --fab-size: 3.5rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  background: #050506;
  color: var(--text);
  line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

.device-shell {
  position: relative;
  width: 100%;
  max-width: var(--shell-max);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (min-width: 480px) {
  .device-shell {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.06),
      0 32px 80px rgba(0, 0, 0, 0.65);
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
}

/* —— Cabecera fija (título + filtros) —— */
.app-chrome {
  flex-shrink: 0;
  z-index: 40;
  margin: 0 calc(-1rem - var(--safe-left)) 0 calc(-1rem - var(--safe-right));
  padding: var(--safe-top) calc(1rem + var(--safe-right)) 0 calc(1rem + var(--safe-left));
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
}

.app-header__bar {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 0.35rem;
}

.app-header__title {
  margin: 0;
  padding: 0 0.15rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.stats {
  margin: 0.35rem 0 0;
  padding: 0 0.15rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--muted);
}

/* —— Filters —— */
.filters {
  position: relative;
  padding: 0.5rem 0 0.75rem;
}

.search {
  position: relative;
  margin-bottom: 0.65rem;
}

.search__icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  display: flex;
}

.search__input {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.6rem 1rem 0.6rem 2.55rem;
  border-radius: 10px;
  border: none;
  background: var(--surface-elevated);
  color: var(--text);
  font: inherit;
  font-size: 1.0625rem;
}

.search__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chip-scroller {
  margin: 0 -0.25rem;
  padding: 0 0.25rem 0.15rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chip-scroller::-webkit-scrollbar {
  display: none;
}

.chip-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  width: max-content;
  padding-right: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.25rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: none;
  background: var(--surface-elevated);
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.chip--active {
  color: #fff;
  background: var(--chip-color, var(--accent));
}

.chip__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--chip-color, var(--accent));
}

.field--filter-desktop {
  display: none;
}

/* —— Lista con scroll propio —— */
.main {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-top: 0.35rem;
  padding-bottom: calc(var(--fab-size) + 1.5rem + var(--safe-bottom));
}

.list-sentinel {
  height: 1px;
  width: 100%;
  pointer-events: none;
}

.list-loading {
  margin: 0.75rem 0 0;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}

.link-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.link-row {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.link-row__tap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0.85rem 0.85rem 1rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.link-row__tap:active {
  background: var(--surface-hover);
}

.link-row__avatar {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--avatar-color) 88%, white),
    var(--avatar-color)
  );
}

.link-row__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.link-row__title {
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  font-size: 0.8125rem;
}

.link-row__cat {
  font-weight: 600;
  color: var(--cat-color);
}

.link-row__catalog {
  color: var(--muted);
}

.link-row__catalog::before {
  content: '·';
  margin-right: 0.35rem;
  color: var(--muted);
}

.link-row__url {
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-row__chevron {
  flex-shrink: 0;
  color: var(--muted);
  opacity: 0.55;
  display: flex;
}

.link-row__toolbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--separator);
  background: color-mix(in srgb, var(--surface-elevated) 55%, var(--surface));
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  border: none;
  background: transparent;
  color: var(--accent-hover);
  cursor: pointer;
}

.toolbar-btn:active {
  background: var(--surface-hover);
}

.toolbar-btn--danger {
  color: var(--danger);
}

.toolbar-btn + .toolbar-btn {
  border-left: 1px solid var(--separator);
}

/* —— Buttons —— */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  min-height: 2.75rem;
  padding: 0.65rem 1rem;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn--block {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--secondary {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
}

.btn--copy {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  color: #e0e7ff;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  font-weight: 700;
}

.btn--danger {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: #fda4af;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
}

.btn--action {
  padding: 0.55rem 0.5rem;
  font-size: 0.875rem;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: none;
  border-radius: 999px;
  background: var(--surface-elevated);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn--ghost {
  background: transparent;
}

.icon-btn:active {
  background: var(--surface-hover);
}

/* —— FAB —— */
.fab {
  position: fixed;
  right: max(calc(1rem + var(--safe-right)), calc(50% - var(--shell-max) / 2 + 1rem));
  bottom: calc(1.15rem + var(--safe-bottom));
  z-index: 50;
  width: var(--fab-size);
  height: var(--fab-size);
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  box-shadow:
    0 4px 16px color-mix(in srgb, var(--accent) 45%, transparent),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab:active {
  transform: scale(0.94);
}

/* —— Empty —— */
.empty {
  text-align: center;
  padding: 2.5rem 1.25rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
}

.empty__emoji {
  margin: 0 0 0.5rem;
  font-size: 2.5rem;
}

.empty__title {
  margin: 0 0 0.35rem;
  font-size: 1.125rem;
  font-weight: 700;
}

.empty__text {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

/* —— Modals / bottom sheets —— */
.modal {
  border: none;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 100%;
  max-height: min(92dvh, 720px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
}

.modal--sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: var(--safe-bottom);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(6px);
}

.home-indicator {
  pointer-events: none;
  position: fixed;
  bottom: calc(0.45rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 8.5rem;
  max-width: 36%;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  z-index: 45;
  opacity: 0.85;
}

.sheet-handle {
  width: 2.5rem;
  height: 4px;
  margin: 0.65rem auto 0;
  border-radius: 999px;
  background: var(--border);
}

.modal__form {
  padding: 0.85rem 1.15rem 1.15rem;
  overflow-y: auto;
  max-height: calc(min(92dvh, 720px) - 1rem);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal__header h2 {
  margin: 0;
  font-size: 1.125rem;
}

.modal__footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.modal__footer--stack .btn {
  min-height: 3rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.field__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.field__select,
.field input[type='text'],
.field input[type='url'],
.field select {
  min-height: 3rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  width: 100%;
}

.field input[type='color'] {
  width: 100%;
  height: 3rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.modal--wide {
  max-width: 100%;
}

.category-manage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 50dvh;
  overflow-y: auto;
}

.category-manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.category-manage-item__info {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.category-manage-item__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.category-manage-item__name {
  font-weight: 600;
  font-size: 0.9375rem;
}

.category-manage-item__count {
  font-size: 0.75rem;
  color: var(--muted);
}

.category-manage-item__actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.category-manage-item__actions .btn {
  min-height: 2.5rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.8125rem;
}

.menu-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.menu-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  min-height: 3.25rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.menu-item:active {
  background: var(--surface-hover);
}

.menu-item__label {
  font-weight: 600;
  font-size: 1rem;
}

.menu-item__hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: calc(var(--fab-size) + 1.5rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.75rem 1.15rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 60;
}

/* —— Tablet / desktop: keep phone shell —— */
@media (min-width: 640px) {
  .toast {
    bottom: calc(1.5rem + var(--safe-bottom));
  }

  .modal--sheet {
    inset: auto;
    position: fixed;
    left: 50%;
    right: auto;
    bottom: max(1rem, calc(50% - min(46dvh, 360px)));
    transform: translateX(-50%);
    border-radius: var(--radius-lg);
    max-width: min(var(--shell-max), calc(100vw - 2rem));
    padding-bottom: 0;
  }

  .modal--wide.modal--sheet {
    max-width: min(var(--shell-max), calc(100vw - 2rem));
  }

  .visually-hidden-desktop {
    position: static !important;
    width: auto !important;
    height: auto !important;
    margin: 0 0 0.65rem !important;
    clip: auto !important;
    overflow: visible !important;
  }

  .field--filter-desktop {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }

  .field--filter-desktop .field__select {
    flex: 1;
  }
}
