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

html, 
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overscroll-behavior-y: contain;
  background: #222222;
  color: #f5f5f5;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 
    sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  user-select: none;
}

input, 
textarea {
  user-select: text;
}

/* Layout */

#app-root {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.app-header {
  flex: 0 0 auto;
  height: 52px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d0d10;
  border-bottom: 1px solid #262630;
}

.app-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c3ff7b;
}

.app-main {
  flex: 1 1 auto;
  display: flex;
  padding: 10px;
  padding-bottom: 4px;
}

.app-footer {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 10px 6px 10px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 11px;
  color: #888;
  background: #050509;
  border-top: 1px solid #181821;
}

.app-footer a {
  color: #c3ff7b;
  text-decoration: none;
}

/* Buttons */

.icon-button {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  outline: none;
  background: #181821;
  color: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

/* Specific styling for the hamburger menu button */
.menu-button {
  background: transparent;
  border-radius: 0;
  padding: 4px 6px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  display: flex;
  gap: 3px;
}

.menu-button:active {
  background: rgba(255, 255, 255, 0.06);
}

.icon-button:active {
  background: #26263a;
}

.small-button {
  min-width: 32px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: none;
  background: #181821;
  color: #f5f5f5;
  font-size: 12px;
  cursor: pointer;
}

.small-button:active {
  background: #26263a;
}

.small-button.danger {
  background: #3b1010;
  color: #ffb0b0;
}

.small-button.danger:active {
  background: #541818;
}

/* Hamburger icon */

.hamburger-line {
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: #f5f5f5;
  display: block;
  margin: 0;
}

/* Note panel */

.note-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 12px;
  padding: 10px 10px 8px 10px;
  /* neutral grey background instead of bluish/purple */
  background: radial-gradient(circle at top left, #1a1a1a, #0a0a0a);
  box-shadow: 
    0 18px 40px rgba(0, 0, 0, 0.75), 
    0 0 0 1px rgba(120, 120, 120, 0.04);
  display: flex;
  flex-direction: column;
}

/* Overlay element inside note panel to show selected note color */
.note-panel .panel-color-overlay {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  z-index: 0;
  opacity: 0.32;
  pointer-events: none;
}

/* Ensure note panel children sit above the overlay */
.note-panel > * {
  position: relative;
  z-index: 1;
}

/* Scroll indicator inside note (small chevron) */
.scroll-indicator {
  position: absolute;
  right: 12px;
  bottom: 56px; /* sit above the footer area inside panel */
  width: 28px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.85);
  background: rgba(0,0,0,0.35);
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 6px 12px rgba(0,0,0,0.6);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 180ms ease, transform 180ms ease;
}

/* Visible state */
.scroll-indicator.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Slightly different in high contrast */
.high-contrast .scroll-indicator {
  background: rgba(255,255,255,0.06);
  color: #c3ff7b;
}

/* Note meta */

.note-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.note-title {
  flex: 1 1 auto;
  border: none;
  outline: none;
  background: transparent;
  color: #f8f8f0;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  /* Prevent extremely long title words from expanding layout */
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.note-title::placeholder {
  color: #666676;
}

.pin-button {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: #181821;
  cursor: pointer;
  font-size: 17px;
}

.pin-button.pinned {
  background: #c3ff7b;
  color: #050509;
}

/* Color selector button next to pin */
.color-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: #202020;
  color: #f5f5f5;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  padding: 0;
  outline: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

/* Palette popover (now a compact horizontal ribbon anchored next to the color button) */
.color-palette {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: #0b0b0d;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.6);
  z-index: 120;
  max-width: calc(100% - 24px);
  align-items: center;
  /* horizontal layout with subtle border */
  border: 1px solid rgba(255,255,255,0.03);
}

/* Smaller swatches for compact ribbon */
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.06);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

/* Hover/tap affordance */
.color-swatch:hover,
.color-swatch:focus {
  transform: translateY(-4px);
  box-shadow: 0 8px 18px rgba(0,0,0,0.55);
  outline: none;
}

/* Selected swatch stronger outline for clarity */
.color-swatch.selected {
  outline: 3px solid rgba(195,255,123,0.28);
  transform: translateY(-4px);
}

/* Ensure palette doesn't inherit note-panel stacking context when appended to body */
.note-panel .color-palette {}

/* Note content */

.note-content {
  flex: 1 1 auto;
  min-height: 120px;
  border: none;
  outline: none;
  resize: none;
  background: rgba(6, 6, 12, 0.7);
  color: #f8f8f0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: inset 0 0 0 1px rgba(120, 255, 120, 0.12);
  /* Ensure long unbroken content wraps and doesn't overflow panel */
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  min-width: 0;
}

/* Note footer */

.note-footer {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 6px;
}

/* Back-to-list button left of timestamps */
.back-button {
  min-width: 40px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #14141f;
  color: #cfe9a9;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
}

.back-button:active {
  background: #26263a;
}

.note-timestamps {
  font-size: 10px;
  color: #88889a;
}

.note-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.note-position-label {
  min-width: 52px;
  text-align: center;
  font-size: 11px;
  color: #b0b0c0;
}

/* Side menu */

.side-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease-out;
  z-index: 30;
}

.side-menu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 68%;
  max-width: 240px;
  background: #0c0c13;
  box-shadow: 6px 0 18px rgba(0, 0, 0, 0.7);
  transform: translateX(-100%);
  transition: transform 200ms ease-out;
  z-index: 40;
  display: flex;
  flex-direction: column;
}

.side-menu.open {
  transform: translateX(0);
}

.side-menu-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.side-menu-header {
  height: 52px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #181821;
  font-size: 14px;
  font-weight: 600;
}

.side-menu-content {
  padding: 8px 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.menu-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: #f5f5f5;
  padding: 10px 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.menu-item:active {
  background: #181821;
}

/* Side menu separators */
.menu-separator {
  height: 1px;
  background: rgba(255,255,255,0.04);
  margin: 8px 6px;
  border-radius: 2px;
  pointer-events: none;
}

/* Modal */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
}

/* Force password settings modal above everything else when active */
.modal-root.password-modal {
  z-index: 9999;
  /* ensure backdrop/dialog keep expected stacking order */
}

.modal-root.visible {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: calc(100% - 40px);
  max-width: 360px;
  border-radius: 14px;
  /* neutral grey dialog background (avoid bluish tint) */
  background: linear-gradient(180deg, #0f0f12, #0b0b0d);
  padding: 12px 12px 10px 12px;
  box-shadow: 
    0 18px 40px rgba(0, 0, 0, 0.8), 
    0 0 0 1px rgba(255, 255, 255, 0.04);
  /* limit height so very long modals don't overflow the viewport */
  max-height: calc(100% - 80px);
  overflow: hidden;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.modal-body {
  font-size: 13px;
  color: #d0d0e0;
  margin-bottom: 10px;
  /* allow vertical scrolling for long modal content while keeping dialog constrained */
  max-height: calc(70vh - 60px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 8px; /* ensure scrollbar doesn't overlap text */
  line-height: 1.45;
}

.modal-body p {
  margin: 6px 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 6px;
}

/* Center a single modal action button (e.g. "Cerrar") */
.modal-actions > button:first-child:last-child {
  margin-left: auto;
  margin-right: auto;
}

.modal-input {
  width: 100%;
  margin-top: 6px;
  border-radius: 8px;
  border: none;
  background: #18181b;
  color: #f5f5f5;
  padding: 8px 10px;
  font-size: 13px;
}

/* Lists and spacing within modal help content */

.notes-list {
  max-height: 520px;
  overflow-y: auto;
  margin-top: 4px;
}
.modal-body ul {
  margin: 6px 0 8px 18px;
  padding-left: 14px;
}
.modal-body li {
  margin: 6px 0;
}

.notes-list-item {
  padding: 8px 8px;
  margin-bottom: 4px;
  border-radius: 8px;
  background: #14141f;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* Drag-and-drop feedback for list rows (visual grip added) */
.list-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #cfe9a9;
  font-size: 16px;
  width: 28px;
  height: 36px;
  border-radius: 6px;
  background: rgba(255,255,255,0.02);
  transition: background 140ms ease, transform 120ms ease;
  user-select: none;
}

/* subtle hover / active affordance on the small handle */
.list-drag-handle:hover {
  background: rgba(195,255,123,0.04);
  transform: translateY(-2px);
}

/* show a clearer pressed state while dragging */
.list-drag-handle:active,
.list-drag-handle.dragging {
  transform: scale(0.995);
  background: rgba(195,255,123,0.06);
}

/* Row being dragged */
#listEditorWrapper .dragging {
  opacity: 0.5;
  transform: scale(0.995);
}

/* Row showing potential drop target */
#listEditorWrapper .drag-over {
  outline: 2px dashed rgba(195,255,123,0.18);
  background: rgba(255,255,255,0.01);
}

.notes-list-item-title {
  flex: 1 1 auto;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notes-list-item-meta {
  font-size: 10px;
  color: #9c9cb0;
  margin-top: 2px;
}

.notes-list-item-pin {
  font-size: 14px;
}

/* High contrast theme toggle */

.high-contrast .note-panel {
  background: #050507;
}

.high-contrast .note-content {
  background: #020203;
}

/* Gallery / thumbnails */

.gallery-view {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  display: grid;
  /* Default gallery is a two-column grid (sticky-style thumbnails) */
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 6px;
  align-content: start;
}

.gallery-card {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0.18));
  border-radius: 12px;
  padding: 10px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.02);
  /* Ensure flex children can shrink and long words wrap instead of breaking layout */
  min-width: 0;
  overflow: hidden;
  word-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

.gallery-card.new-note {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #c3ff7b;
  background: linear-gradient(180deg, rgba(30,30,30,0.9), rgba(10,10,10,0.9));
}

.gallery-card .g-title {
  font-size: 13px;
  font-weight: 600;
  color: #f6f6f0;
  /* Allow wrapping / truncation safely; avoid forcing single-line which can break layout */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.gallery-card .g-excerpt {
  font-size: 12px;
  color: #b8b8c8;
  overflow: hidden;
  max-height: 3.2em;
  line-height: 1.4;
  margin-top: 6px;
  /* Break long words and ensure safe wrapping inside cards */
  word-break: break-word;
  overflow-wrap: anywhere;
  min-width: 0;
}

.gallery-card .g-meta {
  font-size: 10px;
  color: #8f8f9f;
  margin-top: 8px;
  display:flex;
  justify-content:space-between;
  align-items:center;
}

.gallery-card.pinned {
  border-color: rgba(195,255,123,0.18);
  box-shadow: 0 12px 28px rgba(0,0,0,0.6), 0 0 0 1px rgba(195,255,123,0.03) inset;
}

/* Apply note color overlay to gallery cards */
.gallery-card {
  position: relative;
  overflow: hidden;
}

.gallery-card .color-overlay {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.32;
  pointer-events: none;
}

/* Ensure card content sits above overlay */
.gallery-card > .g-title,
.gallery-card > .g-excerpt,
.gallery-card > .g-meta,
.gallery-card .select-checkbox {
  position: relative;
  z-index: 1;
}

/* NEW: attachment indicator moved to bottom-right of gallery card/list item */
.attachment-indicator {
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 2;
  font-size: 14px;
  background: rgba(0,0,0,0.36);
  padding: 4px 6px;
  border-radius: 8px;
  color: #cfe9a9;
  box-shadow: 0 6px 12px rgba(0,0,0,0.45);
  pointer-events: none;
}

/* Slightly different contrast for high-contrast mode */
.high-contrast .attachment-indicator {
  background: rgba(255,255,255,0.06);
  color: #c3ff7b;
}

/* Small paperclip in meta for list view */
.meta-clip {
  font-size: 12px;
  margin-left: 8px;
  color: #cfe9a9;
}

/* ensure meta layout keeps space when clip present */
.gallery-list .g-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* List view styling (single column stacked list) */

.gallery-list {
  /* Single column stacked list */
  grid-template-columns: 1fr;
  gap: 10px;
}

/* Reduce height of the "Crear nueva..." card only in list view (half of default ~96px -> ~48px) */
.gallery-list .gallery-card.new-note {
  min-height: 48px;
  padding: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.view-status {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 8px);
  font-size: 12px;
  /* Changed bluish tint to neutral grey for non-high-contrast mode */
  color: #9a9a9a;
  background: rgba(0,0,0,0.35);
  padding: 4px 8px;
  border-radius: 999px;
}

/* Responsive: keep note-panel visible as before; gallery fits in same main area */
@media (min-width: 600px) {
  .gallery-view {
    max-width: 720px;
  }
}

/* Search box for gallery/list */
.gallery-search {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
  /* ensure the search bar spans the entire grid (above both columns) */
  grid-column: 1 / -1;
}
.gallery-search input {
  flex: 1 1 auto;
  border-radius: 10px;
  padding: 8px 10px;
  border: none;
  background: #14141f;
  color: #f5f5f5;
  font-size: 14px;
  outline: none;
}
.gallery-search .clear-button {
  min-width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: #181821;
  color: #f5f5f5;
  font-size: 16px;
  cursor: pointer;
}

/* Selection mode visuals for gallery cards */

.gallery-card .select-checkbox {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  z-index: 2;
  border: 1px solid rgba(255,255,255,0.04);
}

.gallery-card.selectable .select-checkbox {
  display: flex;
}

.gallery-card.selected {
  outline: 2px solid rgba(195,255,123,0.18);
  transform: translateY(-2px);
}

/* When gallery in select-mode, dim non-selected slightly */
.body-select-mode .gallery-card {
  opacity: 0.95;
}

.body-select-mode .gallery-card:not(.selected) {
  opacity: 0.86;
  filter: saturate(0.95);
}

/* Show delete button prominently when select active */
#deleteSelectedButton {
  background: #3b1010;
  color: #ffb0b0;
}
#deleteSelectedButton:active {
  background: #541818;
}

/* Full-screen editor mode: expand the note panel to fill the main area */
/* This class is toggled on <body> when settings.viewMode === 'editor' */
.editor-full .app-main {
  padding: 0; /* let note panel use full width */
}
.editor-full .gallery-view {
  display: none;
}
.editor-full .note-panel {
  width: 100%;
  max-width: none;
  margin: 0;
  border-radius: 0;
  padding: 12px;
  /* occupy remaining vertical space between header and footer */
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* slightly darker full-bleed background to match app */
  background: linear-gradient(180deg, #0f0f11, #070708);
  box-shadow: none;
}

/* Ensure the inner content (textarea or list editor) can grow and scroll */
.editor-full .note-content,
.editor-full #listEditorWrapper {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* Keep scroll indicator positioned correctly in fullscreen */
.editor-full .scroll-indicator {
  bottom: 72px;
}

/* Attachment thumbnails inside note panel */
.note-attachments {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.attachment-thumb {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  background: #0b0b0d;
  border: 1px solid rgba(255,255,255,0.04);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

/* Delete button on thumbnail (small round icon top-right) */
.attachment-thumb .delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: rgba(59,16,16,0.9);
  color: #ffdede;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  z-index: 3;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.6);
}
.attachment-thumb .delete-btn:active {
  transform: translateY(1px);
}

/* Slightly smaller hit target on very small screens but still tappable */
@media (max-width: 360px) {
  .attachment-thumb .delete-btn {
    width: 16px;
    height: 16px;
    top: 5px;
    right: 5px;
    font-size: 10px;
  }
}

.attachment-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  display: block;
}

/* small filename label under thumb when space allows */
.attachment-thumb .file-label {
  position: absolute;
  bottom: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: #b8b8c8;
}

/* full-screen attachment viewer */
.attachment-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 20px;
}

.attachment-content img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.8);
}

/* non-image file placeholder inside thumb */
.attachment-icon {
  font-size: 20px;
  color: #cfe9a9;
}

/* Download button in attachment viewer (left of close) */
.attachment-viewer .icon-button[title="Descargar"] {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(20,20,20,0.6);
  color: #cfe9a9;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1201;
}

/* Slight spacing and active state */
.attachment-viewer .icon-button[title="Descargar"]:active {
  transform: translateY(1px);
}