@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --sidebar-bg: #1c1a17;
  --sidebar-text: #d4cfc7;
  --sidebar-muted: #6b6560;
  --sidebar-hover: #2a2724;
  --sidebar-active: #3a3530;
  --accent: #c9a96e;
  --accent-dim: #7a6140;
  --text: #2c2a26;
  --text-muted: #8a8580;
  --border: #e8e2d9;
  --danger: #c0392b;
  --editor-bg: #fdfcfa;
  --shadow: 0 2px 20px rgba(0,0,0,0.08);
  --sidebar-width: 260px;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: 'Lora', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ─── Layout ─────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  position: relative;
}

/* ─── Sidebar ─────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
  position: relative;
  z-index: 10;
}

#sidebar.collapsed {
  width: 0;
}

#sidebar-inner {
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20px 0;
  overflow: hidden;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 12px;
}

#sidebar-header h1 {
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ─── Tree ─────────────────────────────── */
#tree {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-muted) transparent;
}

#tree::-webkit-scrollbar { width: 4px; }
#tree::-webkit-scrollbar-thumb { background: var(--sidebar-muted); border-radius: 2px; }

.tree-folder {
  margin-bottom: 4px;
  border-radius: 6px;
  overflow: hidden;
}

.folder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: background var(--transition);
  color: var(--sidebar-text);
  font-size: 13.5px;
  user-select: none;
}

.folder-row:hover { background: var(--sidebar-hover); }
.folder-row.active { background: var(--sidebar-active); }

.folder-row .chevron {
  font-size: 10px;
  color: var(--sidebar-muted);
  transition: transform var(--transition);
  flex-shrink: 0;
  width: 12px;
  display: inline-block;
  text-align: center;
}

.folder-row.open .chevron { transform: rotate(90deg); }

.folder-row .folder-icon { font-size: 14px; flex-shrink: 0; }

.folder-row .folder-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-row .folder-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.folder-row:hover .folder-actions { opacity: 1; }

.folder-row .folder-actions button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sidebar-muted);
  font-size: 15px;
  padding: 0 2px;
  line-height: 1;
  transition: color var(--transition);
}

.folder-row .folder-actions button:hover { color: var(--danger); }

.notes-list {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}

.notes-list.open { max-height: 600px; }

.note-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 32px;
  cursor: pointer;
  font-size: 13px;
  color: var(--sidebar-muted);
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
  user-select: none;
}

.note-row:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.note-row.active { background: var(--sidebar-active); color: var(--accent); }

.note-row .note-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row .note-del {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sidebar-muted);
  font-size: 15px;
  padding: 0;
  transition: opacity var(--transition), color var(--transition);
}

.note-row:hover .note-del { opacity: 1; }
.note-row .note-del:hover { color: var(--danger); }

/* ─── New folder form ─────────────────────────────── */
#new-folder-area {
  padding: 12px 16px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 8px;
}

#new-folder-area .input-row {
  display: flex;
  gap: 6px;
}

#new-folder-area input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--sidebar-text);
  outline: none;
  font-family: 'JetBrains Mono', monospace;
  transition: border-color var(--transition);
}

#new-folder-area input::placeholder { color: var(--sidebar-muted); }
#new-folder-area input:focus { border-color: var(--accent-dim); }

#new-folder-area button {
  background: var(--accent-dim);
  border: none;
  color: var(--bg);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 16px;
  transition: background var(--transition);
}

#new-folder-area button:hover { background: var(--accent); }

/* ─── Topbar ─────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

#toggle-sidebar {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

#toggle-sidebar:hover {
  background: var(--bg);
  color: var(--text);
}

#topbar-title {
  flex: 1;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#nueva-nota-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

#nueva-nota-btn:hover {
  border-color: var(--accent);
  color: var(--accent-dim);
}

/* ─── Main area ─────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left var(--transition);
  position: relative;
}

/* ─── Editor ─────────────────────────────── */
#editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 40px 48px 40px;
  background: var(--editor-bg);
  overflow-y: auto;
}

#editor-placeholder {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
}

#editor-placeholder .big-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 12px;
  opacity: 0.4;
}

#editor-placeholder p {
  font-size: 15px;
  font-style: italic;
}

#note-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

#titulo-nota {
  font-size: 28px;
  font-weight: 600;
  font-family: 'Lora', serif;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  margin-bottom: 6px;
  width: 100%;
  padding: 0;
}

#titulo-nota::placeholder { color: var(--border); }

.note-meta {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  margin-bottom: 24px;
  letter-spacing: 0.04em;
}

.divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 24px;
}

/* ── Editor body: preview + textarea superpuestos ── */
/* Editor contenteditable */
#contenido-nota {
  flex: 1;
  min-height: 300px;
  border: none;
  outline: none;
  background: transparent;
  font-size: 15.5px;
  color: var(--text);
  line-height: 1.85;
  font-family: 'Lora', serif;
  padding: 0;
  word-break: break-word;
}

#contenido-nota p,
#contenido-nota div {
  margin: 0;
  min-height: 1.85em;
  font-size: 15.5px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.85;
}

#contenido-nota h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  margin: 20px 0 4px;
  line-height: 1.3;
}

#contenido-nota h2 {
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  margin: 16px 0 4px;
  line-height: 1.3;
}

#contenido-nota h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 12px 0 4px;
  line-height: 1.3;
}

/* Botones H1/H2/H3 en topbar */
.hbtn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
}
.hbtn:hover {
  border-color: var(--accent);
  color: var(--accent-dim);
}

.shortcut-hint {
  color: var(--text-muted);
  opacity: 0.6;
  font-size: 10px;
}

/* ─── Responsive: mobile overlay ─────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 9;
  backdrop-filter: blur(2px);
}

/* ─── Tablet: iPad Air ~820px ─────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-width: 230px; }

  #editor { padding: 32px 32px; }
  #nueva-nota-btn { padding: 10px 32px; }

  #titulo-nota { font-size: 24px; }
}

/* ─── Mobile: iPhone 14 ≤480px ─────────────────────────────── */
@media (max-width: 520px) {
  :root { --sidebar-width: 80vw; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
    z-index: 20;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }

  #sidebar.mobile-open {
    transform: translateX(0);
  }

  #sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  #sidebar-overlay.visible { display: block; }

  #main-area { width: 100%; }

  #editor {
    padding: 24px 20px 32px;
  }

  #nueva-nota-btn { padding: 6px 12px; }

  #titulo-nota { font-size: 21px; }

  #note-form { max-width: 100%; }

  #guardar-btn { width: 100%; text-align: center; }

  .editor-footer { justify-content: stretch; }
  .editor-footer #guardar-btn { flex: 1; }
}

/* ── Topbar actions ─────────────────────────────────────── */
#topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

#btn-descargar, #btn-subir {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap;
}
#btn-descargar:hover { border-color: var(--accent); color: var(--accent-dim); }
#btn-subir:hover { border-color: var(--accent); color: var(--accent-dim); }

/* ── Modales ─────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
}
.modal-overlay.visible { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 480px;
  max-width: 92vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  font-family: 'JetBrains Mono', monospace;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-btn-primary {
  background: var(--accent-dim);
  border: none;
  color: white;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  transition: background var(--transition);
}
.modal-btn-primary:hover { background: var(--accent); }
.modal-btn-secondary {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  transition: all var(--transition);
}
.modal-btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }

/* Lista descarga */
.dl-carpeta { margin-bottom: 12px; }
.dl-carpeta-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  background: var(--bg);
}
.dl-carpeta-label:hover { background: var(--border); }
.dl-folder-icon { font-size: 15px; }
.dl-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}
.dl-notas { padding-left: 28px; }
.dl-nota-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
}
.dl-nota-label:hover { background: var(--bg); color: var(--text); }

/* Form importar */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-group input[type="file"],
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: 'Lora', serif;
  outline: none;
}
.form-group select { cursor: pointer; }

/* ── Menú flotante de formato ────────────────────────────── */
#menu-formato {
  position: fixed;
  display: flex;
  gap: 2px;
  background: #1c1a17;
  border: 1px solid #3a3530;
  border-radius: 8px;
  padding: 5px 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  z-index: 500;
  align-items: center;
}

#menu-formato button {
  background: none;
  border: none;
  color: #d4cfc7;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  transition: background 0.15s ease;
  line-height: 1;
}

#menu-formato button:hover {
  background: #3a3530;
  color: #c9a96e;
}
