/* =============================================================================
   SISTEMA DE NOTAS MARKDOWN — ficha de catálogo
   Concepto: se escribe en monoespaciada (como código), se leé en serif (como un
   libro). Las notas viven como fichas de catálogo sobre una mesa de papel.
============================================================================= */

@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;1,8..60,400&display=swap");

:root {
  /* Papel — gris neutro cálido, muy desaturado (antes era demasiado kraft/marrón) */
  --paper: #f1f0ec;
  --surface: #fefdfb;
  --surface-sunken: #e6e4dd;
  --border: #dad8d0;
  --border-strong: #b7b4a8;

  /* Tinta */
  --ink: #221f1a;
  --ink-soft: #66625a;
  --ink-faint: #9a9689;

  /* Acentos semánticos */
  --accent: #2e3d5c;
  --accent-hover: #24314b;
  --accent-soft: #dde2ed;
  --gold: #a2791c;
  --gold-soft: #f1e3be;
  --danger: #8c3b2e;
  --danger-soft: #f1ddd6;
  --success: #4b7a51;
  --success-soft: #dee9dc;

  /* Forma */
  --radius-sm: 4px;
  --radius-md: 8px;
  --shadow-card: 0 1px 2px rgba(36, 33, 27, 0.08), 0 4px 10px rgba(36, 33, 27, 0.06);
  --shadow-card-hover: 0 2px 4px rgba(36, 33, 27, 0.1), 0 10px 20px rgba(36, 33, 27, 0.1);
  --shadow-sheet: 0 1px 3px rgba(36, 33, 27, 0.1), 0 8px 24px rgba(36, 33, 27, 0.08);

  /* Tipografía */
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

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

.is-hidden {
  display: none !important;
}

body {
  font-family: var(--font-mono);
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(36, 33, 27, 0.045) 1px, transparent 1px);
  background-size: 22px 22px;
  height: 100vh; /* respaldo para navegadores sin soporte de dvh/svh */
  height: 100dvh;
  height: 100svh; /* espacio mínimo garantizado: evita el salto al reaparecer la barra */
  overflow: hidden;
}

.container {
  height: 100vh; /* respaldo para navegadores sin soporte de dvh/svh */
  height: 100dvh;
  height: 100svh; /* espacio mínimo garantizado: evita el salto al reaparecer la barra */
  display: flex;
  flex-direction: column;
}

/* ----------------------------------------------------------------------------
   HEADER — banda de ledger, doble filete inferior
---------------------------------------------------------------------------- */
header {
  background-color: var(--surface);
  color: var(--ink);
  padding: 1.1rem 2rem 1rem;
  border-bottom: 3px double var(--border-strong);
}

header h1 {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

header h1::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  background-color: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}

.app-subtitle {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0.3rem 0 0.6rem 1.35rem;
}

.message {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 22rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  box-shadow: var(--shadow-card-hover);
  background-color: var(--surface);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.97);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.message:empty {
  opacity: 0;
  transform: translateY(12px) scale(0.97);
}

.message.success,
.message.error {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.message.success::before,
.message.error::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.message.success {
  color: var(--success);
  border-color: var(--success);
}

.message.success::before {
  background-color: var(--success);
}

.message.error {
  color: var(--danger);
  border-color: var(--danger);
}

.message.error::before {
  background-color: var(--danger);
}

@media (max-width: 900px) {
  .message {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    max-width: none;
  }
}

/* ----------------------------------------------------------------------------
   LAYOUT PRINCIPAL
---------------------------------------------------------------------------- */
.main-content {
  display: grid;
  grid-template-columns: 300px 1fr 1fr;
  gap: 1.25rem;
  padding: 1.25rem;
  flex: 1;
  overflow: hidden;
}

/* ----------------------------------------------------------------------------
   SIDEBAR — cajón de catálogo
---------------------------------------------------------------------------- */
.sidebar {
  background-color: var(--surface-sunken);
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  overflow: visible;
  min-height: 0;
  box-shadow: var(--shadow-card);
}

.sidebar-header {
  margin-bottom: 0.85rem;
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sidebar-header h2 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-header h2::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: var(--gold);
  border-radius: 2px;
  flex-shrink: 0;
}

.sidebar-title-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.notes-menu {
  position: relative;
}

.notes-menu-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 20;
  min-width: 13rem;
  max-width: calc(100vw - 2rem);
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card-hover);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  transform-origin: top right;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}

.notes-menu-dropdown.is-hidden {
  display: flex !important;
  opacity: 0;
  transform: scale(0.94) translateY(-4px);
  pointer-events: none;
}

.notes-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  background-color: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.notes-menu-item:hover {
  background-color: var(--surface-sunken);
  transform: translateX(2px);
}

.notes-menu-item:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.notes-menu-item-trash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.notes-menu-divider {
  height: 1px;
  margin: 0.3rem 0.2rem;
  background-image: linear-gradient(
    to right,
    var(--border-strong) 50%,
    transparent 50%
  );
  background-size: 6px 1px;
  background-repeat: repeat-x;
}

.trash-count-badge {
  flex-shrink: 0;
  min-width: 1.2rem;
  padding: 0.05rem 0.35rem;
  background-color: var(--danger-soft);
  color: var(--danger);
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}

.trash-count-badge.is-hidden {
  display: none;
}

.btn-icon {
  width: 2.3rem;
  height: 2.3rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.btn-icon:hover {
  background-color: var(--surface);
  border-color: var(--gold);
  color: var(--gold);
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: scale(0.93);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.btn-icon-primary {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
  font-weight: 600;
}

.btn-icon-primary:hover {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--surface);
}

.btn-icon-primary:focus-visible {
  outline-color: var(--accent);
}

.filters-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border-strong);
}

.filters-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.filter-chip {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  padding: 0.35rem 0.75rem;
  background-color: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.filter-chip:hover {
  border-color: var(--gold);
  color: var(--gold);
  transform: translateY(-1px);
}

.filter-chip:active {
  transform: scale(0.95);
}

.filter-chip.active {
  background-color: var(--gold-soft);
  border-color: var(--gold);
  color: #7a5c14;
}

.filter-chip:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.date-filter {
  position: relative;
}

.date-filter-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 20;
  min-width: 12rem;
  max-width: calc(100vw - 2rem);
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card-hover);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  transform-origin: top left;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}

.date-filter-dropdown.is-hidden {
  display: flex !important;
  opacity: 0;
  transform: scale(0.94) translateY(-4px);
  pointer-events: none;
}

.date-filter-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  background-color: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.date-filter-option:hover {
  background-color: var(--surface-sunken);
  transform: translateX(2px);
}

.date-filter-option:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.date-filter-option.is-selected {
  background-color: var(--gold-soft);
  color: #7a5c14;
  font-weight: 600;
}

.date-filter-custom {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.6rem 0.6rem 0.35rem;
  margin-top: 0.2rem;
  border-top: 1px dashed var(--border);
}

.date-filter-custom.is-hidden {
  display: none !important;
}

.date-filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.date-filter-field input[type="date"] {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--ink);
}

.date-filter-field input[type="date"]:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.date-filter-apply {
  align-self: flex-end;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.4rem 0.9rem;
  background-color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--surface);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.date-filter-apply:hover {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
}

.date-filter-apply:active {
  transform: scale(0.96);
}

.date-filter-apply:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.sort-filter {
  position: relative;
}

.sort-filter-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 20;
  min-width: 15rem;
  max-width: calc(100vw - 2rem);
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card-hover);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  transform-origin: top right;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}

.sort-filter-dropdown.is-hidden {
  display: flex !important;
  opacity: 0;
  transform: scale(0.94) translateY(-4px);
  pointer-events: none;
}

.sort-filter-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  background-color: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.sort-filter-option:hover {
  background-color: var(--surface-sunken);
  transform: translateX(2px);
}

.sort-filter-option:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.sort-filter-option.is-selected {
  background-color: var(--gold-soft);
  color: #7a5c14;
  font-weight: 600;
}

.btn-icon-danger:hover {
  background-color: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
}

.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background-color: transparent;
  border-color: var(--border-strong);
  color: var(--ink-soft);
  transform: none;
}

.btn-icon:disabled:hover,
.btn-icon:disabled:active {
  transform: none;
}

/* ----------------------------------------------------------------------------
   SELECCIÓN MÚLTIPLE
---------------------------------------------------------------------------- */
.bulk-actions-bar {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-block: 0.75rem;
  padding: 0.6rem 0.7rem;
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  max-height: 10rem;
  overflow: hidden;
  transition: max-height 0.25s var(--ease), opacity 0.2s var(--ease),
    margin-top 0.25s var(--ease), padding 0.25s var(--ease),
    border-width 0.2s var(--ease);
}

.bulk-actions-bar.is-hidden {
  display: flex !important;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
  pointer-events: none;
}

.bulk-actions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.bulk-actions-header #selection-count-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.bulk-actions-header .btn-icon {
  width: 1.7rem;
  height: 1.7rem;
  font-size: 0.9rem;
}

.bulk-actions-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.bulk-select-all {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.bulk-select-all input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.bulk-actions-buttons {
  display: flex;
  gap: 0.4rem;
}

.bulk-actions-buttons .btn-icon {
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
}

@keyframes checkboxFadeIn {
  from {
    opacity: 0;
    transform: translateX(-4px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.note-select-checkbox {
  display: flex;
  align-items: flex-start;
  padding-bottom: 0.5rem;
  cursor: pointer;
  animation: checkboxFadeIn 0.18s var(--ease);
}

.note-select-checkbox input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.note-item.is-selected {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background-color: var(--accent-soft);
}

.note-item.selection-mode .note-item-header,
.note-item.selection-mode .note-excerpt,
.note-item.selection-mode .note-date {
  pointer-events: none;
}

.note-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-right: 2px;
}

.note-list::-webkit-scrollbar,
.preview-container::-webkit-scrollbar {
  width: 8px;
}

.note-list::-webkit-scrollbar-thumb,
.preview-container::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border-radius: 4px;
}

/* Fichas de catálogo */
@keyframes noteItemIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.note-item {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  animation: noteItemIn 0.18s var(--ease);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease),
    border-color 0.15s var(--ease), background-color 0.15s var(--ease);
  /* Evita el menú contextual / selección de texto nativa del navegador al
     mantener presionado en mobile, para que el long-press active nuestro
     propio modo de selección en su lugar. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.note-item.is-long-pressing {
  transform: scale(0.97);
  border-color: var(--gold);
  box-shadow: var(--shadow-card);
}

.note-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--border-strong);
}

.note-item.active {
  border-color: var(--gold);
  border-left-color: var(--gold);
  background-color: var(--gold-soft);
}

.note-item h3 {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.note-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.note-item-header h3 {
  margin-bottom: 0.5rem;
  overflow-wrap: anywhere;
}

.favorite-toggle {
  width: 1.6rem;
  height: 1.6rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--ink-faint);
  transition: all 0.15s var(--ease);
}

.favorite-toggle.is-favorite {
  background-color: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

/* Cuando la nota está activa, su fondo ya es dorado — si la estrella
   favorita usara el mismo tono, se fundiría con la tarjeta. Le damos
   un fondo blanco para que el "sello" de favorita siga siendo legible. */
.note-item.active .favorite-toggle.is-favorite {
  background-color: var(--surface);
}

.favorite-toggle:hover {
  border-color: var(--gold);
  color: var(--gold);
  transform: scale(1.1);
}

.favorite-toggle:active {
  transform: scale(0.9);
}

.note-excerpt {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}

.note-date {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.empty-message {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--ink-faint);
  text-align: center;
  padding: 2.5rem 1rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

/* ----------------------------------------------------------------------------
   EDITOR Y PREVIEW — hojas de papel
---------------------------------------------------------------------------- */
.editor-section,
.preview-section {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sheet);
}

.editor-header,
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.editor-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.editor-header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex-shrink: 1;
}

/* Oculto en escritorio: la lista de notas ya está siempre visible al lado.
   Solo se muestra en mobile (ver breakpoint más abajo). */
.editor-back-button {
  display: none;
  flex-shrink: 0;
}

.editor-meta {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-header h2,
.preview-header h2 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.editor-title-group h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-header h2::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}

.preview-header h2::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: var(--gold);
  border-radius: 2px;
}

/* Nunca se encoge: así los botones conservan su tamaño y es el título
   (a la izquierda) el que se trunca con puntos suspensivos cuando el
   panel queda angosto, en vez de quedar tapado detrás de los botones. */
.editor-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.editor-actions #delete-note-button {
  margin-left: auto;
}

/* Rango intermedio: cuando el panel del editor/preview queda angosto
   (pantallas justo por encima del breakpoint mobile) los botones se
   compactan un poco para dejarle más aire al título. */
@media (min-width: 901px) and (max-width: 1150px) {
  .editor-actions {
    gap: 0.4rem;
  }

  .editor-actions .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.72rem;
  }
}

.editor-textarea {
  flex: 1;
  background-color: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.6;
  resize: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.editor-textarea::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

.editor-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.preview-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1.4rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
}

.preview-empty {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--ink-faint);
  text-align: center;
}

/* ----------------------------------------------------------------------------
   BOTONES
---------------------------------------------------------------------------- */
.btn {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.6rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease),
    background-color 0.15s var(--ease), color 0.15s var(--ease),
    border-color 0.15s var(--ease);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary {
  background-color: var(--accent);
  color: var(--surface);
  width: 100%;
  box-shadow: var(--shadow-card);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-card-hover);
}

.btn-success {
  background-color: var(--success);
  color: var(--surface);
}

.btn-success:hover {
  background-color: #3d6743;
  transform: translateY(-1px);
  box-shadow: var(--shadow-card-hover);
}

.btn-danger {
  background-color: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background-color: var(--danger);
  color: var(--surface);
}

.btn-ghost {
  background-color: transparent;
  color: var(--ink-soft);
  border-color: var(--border-strong);
}

.btn-ghost:hover {
  border-color: var(--ink-faint);
  color: var(--ink);
  background-color: var(--surface-sunken);
}

.btn-danger-solid {
  background-color: var(--danger);
  color: var(--surface);
  border-color: var(--danger);
}

.btn-danger-solid:hover {
  background-color: #6f2e24;
  border-color: #6f2e24;
}

/* ----------------------------------------------------------------------------
   DIÁLOGO DE CONFIRMACIÓN — reemplaza a confirm() nativo
---------------------------------------------------------------------------- */
.confirm-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background-color: rgba(34, 31, 26, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s var(--ease);
}

.confirm-dialog-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.confirm-dialog {
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sheet);
  padding: 1.5rem;
  max-width: 26rem;
  width: 100%;
  transform: scale(0.95) translateY(8px);
  transition: transform 0.18s var(--ease);
}

.confirm-dialog-overlay.is-visible .confirm-dialog {
  transform: scale(1) translateY(0);
}

.confirm-dialog.is-danger {
  border-top-color: var(--danger);
}

.confirm-dialog-title {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.confirm-dialog-title::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  background-color: var(--accent);
  border-radius: 2px;
}

.confirm-dialog.is-danger .confirm-dialog-title::before {
  background-color: var(--danger);
}

.confirm-dialog-message {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

@media (max-width: 640px) {
  .confirm-dialog-actions {
    flex-direction: column-reverse;
  }

  .confirm-dialog-actions .btn {
    width: 100%;
  }
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  /* Evita que :hover (background/color de .btn-danger, .btn-success, etc.)
     se siga aplicando visualmente cuando el botón está deshabilitado,
     como pasaba con "Eliminar definitivamente" en la papelera sin nada
     seleccionado. */
  pointer-events: none;
}

/* ----------------------------------------------------------------------------
   PAPELERA — modal con notas eliminadas, restaurables o borrables definitivamente
---------------------------------------------------------------------------- */
.trash-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background-color: rgba(34, 31, 26, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s var(--ease);
}

.trash-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.trash-dialog {
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--danger);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sheet);
  padding: 1.4rem;
  max-width: 34rem;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(8px);
  transition: transform 0.18s var(--ease);
}

.trash-overlay.is-visible .trash-dialog {
  transform: scale(1) translateY(0);
}

.trash-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.trash-dialog-header h3 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink);
}

.trash-dialog-hint {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin-top: 0.3rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed var(--border-strong);
}

.trash-dialog-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.75rem 0;
}

.trash-dialog-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.trash-dialog-actions .btn {
  padding: 0.45rem 0.8rem;
  font-size: 0.72rem;
}

/* ----------------------------------------------------------------------------
   ACERCA DE — reutiliza el look de .trash-dialog pero con acento dorado
   en vez de rojo (no es una acción destructiva)
---------------------------------------------------------------------------- */
.about-dialog {
  border-top-color: var(--gold);
  max-width: 26rem;
}

.about-app {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.about-app-name {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.about-version-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #7a5c14;
  background-color: var(--gold-soft);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
}

.about-app-tagline {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin-top: 0.4rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px dashed var(--border-strong);
}

.about-rows {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.9rem 0;
}

.about-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.about-row dt {
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.68rem;
  flex-shrink: 0;
}

.about-row dd {
  color: var(--ink);
  text-align: right;
}

.about-row dd a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
}

.about-row dd a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent);
}

.about-copyright {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
  text-align: center;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border-strong);
}

.trash-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.2rem 0.2rem 0.2rem 0;
  min-height: 4rem;
}

.trash-list::-webkit-scrollbar {
  width: 8px;
}

.trash-list::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border-radius: 4px;
}

.trash-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background-color: var(--surface-sunken);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  animation: noteItemIn 0.18s var(--ease);
}

.trash-item.is-selected {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background-color: var(--accent-soft);
}

.trash-item-checkbox {
  display: flex;
  align-items: center;
  padding-top: 0.15rem;
  cursor: pointer;
}

.trash-item-checkbox input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.trash-item-body {
  flex: 1;
  min-width: 0;
}

.trash-item-body h4 {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  overflow-wrap: anywhere;
  margin-bottom: 0.3rem;
}

.trash-item-body p {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.trash-item-body small {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.trash-item-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}

.trash-item-actions .btn-icon {
  width: 2rem;
  height: 2rem;
  font-size: 0.95rem;
}

.import-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background-color: var(--surface-sunken);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  animation: noteItemIn 0.18s var(--ease);
}

.import-item.is-selected {
  border-color: var(--gold);
  border-left-color: var(--gold);
  background-color: var(--gold-soft);
}

.import-item-checkbox {
  display: flex;
  align-items: center;
  padding-top: 0.15rem;
  cursor: pointer;
}

.import-item-checkbox input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.import-item-body {
  flex: 1;
  min-width: 0;
}

.import-item-body h4 {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  overflow-wrap: anywhere;
  margin-bottom: 0.3rem;
}

.import-item-body p {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.import-item-body small {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.trash-dialog-footer {
  padding-top: 0.75rem;
  margin-top: 0.5rem;
  border-top: 1px dashed var(--border-strong);
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 640px) {
  .trash-dialog-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .trash-dialog-actions {
    width: 100%;
  }

  .trash-dialog-actions .btn {
    flex: 1;
  }

  .about-row {
    flex-wrap: wrap;
  }

  .about-row dd {
    text-align: left;
  }
}

.btn:disabled:hover {
  background-color: inherit;
}

/* ----------------------------------------------------------------------------
   BÚSQUEDA
---------------------------------------------------------------------------- */
.search-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.5rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.search-input::placeholder {
  color: var(--ink-faint);
}

.search-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

/* ----------------------------------------------------------------------------
   CONTENIDO MARKDOWN RENDERIZADO
---------------------------------------------------------------------------- */
.preview-container img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1rem 0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
}

.preview-container h1,
.preview-container h2,
.preview-container h3,
.preview-container h4,
.preview-container h5,
.preview-container h6 {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink);
}

.preview-container h1 {
  font-size: 1.4rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 1.5rem 0 1rem 0;
  border-bottom: 2px solid var(--border-strong);
  padding-bottom: 0.5rem;
}

.preview-container h2 {
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 1.25rem 0 0.75rem 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
}

.preview-container h3 {
  font-size: 1.05rem;
  margin: 1rem 0 0.5rem 0;
}

.preview-container h4 {
  font-size: 0.95rem;
  margin: 1rem 0 0.5rem 0;
}

.preview-container h5 {
  font-size: 0.9rem;
  margin: 1rem 0 0.5rem 0;
}

.preview-container h6 {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 1rem 0 0.5rem 0;
}

.preview-container p {
  margin: 0.75rem 0;
  line-height: 1.7;
  color: var(--ink);
}

.preview-container ul,
.preview-container ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
  line-height: 1.7;
}

.preview-container li {
  margin-bottom: 0.25rem;
  color: var(--ink);
}

.preview-container blockquote {
  margin: 1rem 0;
  padding: 0.6rem 1rem;
  border-left: 4px solid var(--gold);
  background-color: var(--surface-sunken);
  color: var(--ink-soft);
  font-style: italic;
}

.preview-container code {
  background-color: var(--surface-sunken);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--danger);
}

.preview-container pre {
  background-color: var(--surface-sunken);
  padding: 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--border);
}

.preview-container pre code {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 0.85rem;
  color: var(--ink);
}

.preview-container table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  border: 1px solid var(--border);
  font-family: var(--font-serif);
}

.preview-container th,
.preview-container td {
  padding: 0.7rem 0.85rem;
  text-align: left;
  border: 1px solid var(--border);
}

.preview-container th {
  background-color: var(--surface-sunken);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink);
}

.preview-container tr:nth-child(even) {
  background-color: rgba(36, 33, 27, 0.02);
}

.preview-container a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
  transition: border-bottom-color 0.15s var(--ease);
}

.preview-container a:hover {
  border-bottom-color: var(--accent);
}

.preview-container hr {
  border: none;
  border-top: 1px dashed var(--border-strong);
  margin: 2rem 0;
}

.preview-container strong {
  font-weight: 700;
  color: var(--ink);
}

.preview-container em {
  font-style: italic;
  color: var(--ink-soft);
}

.preview-container del {
  text-decoration: line-through;
  color: var(--ink-faint);
}

.preview-container ins {
  text-decoration: underline;
  background-color: var(--success-soft);
  color: var(--success);
}

.preview-container sub,
.preview-container sup {
  font-size: 0.8rem;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

.preview-container sub {
  bottom: -0.25rem;
}

.preview-container sup {
  top: -0.5rem;
}

/* ----------------------------------------------------------------------------
   ACCESIBILIDAD — respeta preferencia de movimiento reducido
---------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ----------------------------------------------------------------------------
   RESPONSIVE
   En pantallas angostas, la grilla de 3 columnas fijas (sidebar/editor/preview)
   se vuelve inusable. En vez de apilarlas y obligar a hacer scroll por todo,
   la app se comporta como una app nativa de una sola pantalla a la vez:
   - Por defecto se ve la lista de notas, a pantalla completa.
   - Al abrir una nota, la lista se oculta y el editor + preview aparecen
     juntos, cada uno con la mitad de la pantalla y su propio scroll interno.
   - Una flecha "←" en el editor vuelve a mostrar la lista.
---------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
    padding: 0.85rem;
    gap: 0.85rem;
    overflow: hidden;
  }

  .sidebar,
  .editor-section,
  .preview-section {
    min-height: 0;
  }

  /* Modo edición: se activa agregando is-note-open a .main-content */
  .main-content.is-note-open {
    display: flex;
    flex-direction: column;
  }

  .main-content.is-note-open .sidebar {
    display: none;
  }

  .main-content.is-note-open .editor-section,
  .main-content.is-note-open .preview-section {
    flex: 1 1 50%;
  }

  .editor-back-button {
    display: inline-flex;
  }

  /* Header compacto en una sola línea: se quita el subtítulo para no
     robarle espacio a la lista de notas y al editor/preview. */
  header {
    padding: 0.55rem 1rem;
    border-bottom-width: 2px;
  }

  header h1 {
    font-size: 0.95rem;
    gap: 0.4rem;
  }

  header h1::before {
    width: 7px;
    height: 7px;
  }

  .app-subtitle {
    display: none;
  }

  /* Encabezado del editor: se reduce y el título "Editor" se oculta
     (queda el botón de volver + la fecha) para dejarle aire a los
     botones de acción y que no tapen el lado izquierdo. */
  .editor-header,
  .preview-header {
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
    gap: 0.4rem;
  }

  .editor-header-left {
    gap: 0.45rem;
  }

  .editor-title-group h2,
  .preview-header h2 {
    display: none;
  }

  .editor-meta {
    font-size: 0.72rem;
  }

  .editor-back-button {
    width: 2rem;
    height: 2rem;
    font-size: 1.05rem;
  }

  /* Botones Guardar / Eliminar: más chicos y compactos en mobile */
  .editor-actions {
    gap: 0.4rem;
    flex-shrink: 0;
  }

  .editor-actions .btn {
    padding: 0.45rem 0.65rem;
    font-size: 0.68rem;
  }

  /* Nota: el posicionamiento (izquierda/derecha/arriba/abajo) de los
     dropdowns de filtros y del menú de opciones ya no se resuelve
     "adivinando" con CSS — se calcula dinámicamente en JS en base al
     espacio real disponible (ver positionDropdown() en app.js), así
     que funciona sin importar dónde termine el botón que los abre. El
     max-width de abajo queda solo como red de seguridad de ancho.
  */
}