:root {
  --bg: #0b0b0d;
  --bg-1: #111114;
  --bg-2: #17171c;
  --bg-3: #1f1f25;
  --border: #2a2a31;
  --text: #ececf1;
  --text-2: #a0a0aa;
  --muted: #6b6b74;
  --accent: #ffb020;
  --accent-2: #ff8a00;
  --danger: #ff4d4f;
  --ok: #22c55e;
  --shadow: 0 10px 40px rgba(0,0,0,.5);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f8;
    --bg-1: #ffffff;
    --bg-2: #f0f0f2;
    --bg-3: #e6e6ea;
    --border: #e0e0e5;
    --text: #15151a;
    --text-2: #4a4a55;
    --muted: #8a8a95;
    --shadow: 0 8px 30px rgba(0,0,0,.08);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------- LOGIN ---------- */
.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(255,176,32,.12), transparent 60%), var(--bg);
  z-index: 10;
}
.login-card {
  width: min(380px, 92vw);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.login-card p { margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.login-card input {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button[type=submit] {
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  transition: filter .15s;
}
.login-card button[type=submit]:hover { filter: brightness(1.08); }
.login-card #btn-reset-sw {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 13px;
  cursor: pointer;
}
.login-card #btn-reset-sw:hover { color: var(--text); border-color: var(--text-2); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- APP LAYOUT ---------- */
.app {
  display: grid;
  grid-template-columns: 260px 340px 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0;
}
.sidebar-header {
  padding: 16px 18px 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.sidebar-header h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.folder-list {
  flex: 1; overflow-y: auto;
  padding: 4px 8px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.folder-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
}
.folder-item:hover { background: var(--bg-2); color: var(--text); }
.folder-item.active {
  background: var(--bg-2);
  color: var(--text);
  border-color: var(--border);
}
.folder-item .count {
  margin-left: auto;
  font-size: 12px; color: var(--muted);
  background: var(--bg-3);
  padding: 2px 8px; border-radius: 999px;
}
.folder-item .icon { width: 16px; height: 16px; flex: 0 0 16px; }
.folder-item[data-id] .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
}
.sync-status {
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.sync-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}
.sync-status.syncing .dot { background: var(--accent); animation: pulse 1s infinite; }
.sync-status.ok .dot { background: var(--ok); }
.sync-status.offline .dot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.ghost-btn {
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px; font-size: 13px;
  transition: all .15s;
}
.ghost-btn:hover { color: var(--text); background: var(--bg-2); }

.primary-btn {
  background: var(--accent); color: #111;
  border: none; border-radius: var(--radius-sm);
  padding: 8px 14px; font-weight: 600; font-size: 14px;
}

.icon-btn {
  background: transparent; border: none;
  color: var(--text-2);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  transition: all .15s;
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn.primary { background: var(--accent); color: #111; }
.icon-btn.primary:hover { filter: brightness(1.08); }
.icon-btn.danger:hover { color: var(--danger); background: rgba(255,77,79,.1); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- NOTES LIST ---------- */
.notes-pane {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0;
}
.notes-header {
  padding: 12px 14px;
  display: flex; gap: 8px; align-items: center;
  border-bottom: 1px solid var(--border);
}
#search-input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
.folder-title {
  padding: 10px 16px 6px;
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.notes-list {
  flex: 1; overflow-y: auto;
  padding: 4px 8px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.note-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s;
  position: relative;
}
.note-item:hover { background: var(--bg-2); }
.note-item.active {
  background: var(--bg-2);
  border-color: var(--border);
}
.note-item .title {
  font-size: 14px; font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note-item .pin {
  color: var(--accent); flex: 0 0 12px;
}
.note-item .preview {
  font-size: 13px; color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.note-item .footer {
  margin-top: 6px;
  font-size: 11px; color: var(--muted);
  display: flex; gap: 8px; align-items: center;
}
.note-item .color-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex: 0 0 8px;
}
.notes-empty {
  padding: 40px 20px;
  text-align: center; color: var(--muted); font-size: 14px;
}

/* ---------- EDITOR ---------- */
.editor-pane {
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--bg-1);
}
.editor-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
}
.editor-meta {
  flex: 1;
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color .2s;
}
.editor-meta.saved { color: var(--ok); }
.editor-meta.saved::before { content: "✓ Guardado · "; }
.editor-actions { display: flex; gap: 2px; }
.editor-title {
  width: 100%;
  background: transparent;
  border: none; outline: none;
  color: var(--text);
  font-size: 28px; font-weight: 700;
  letter-spacing: -0.02em;
  padding: 24px 40px 8px;
}
.editor-toolbar {
  display: flex; gap: 2px; align-items: center;
  padding: 6px 40px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.editor-toolbar button {
  background: transparent; border: none;
  color: var(--text-2);
  min-width: 30px; height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 14px;
}
.editor-toolbar button:hover { background: var(--bg-2); color: var(--text); }
.editor-toolbar .sep {
  width: 1px; height: 18px; background: var(--border); margin: 0 4px;
}
.editor-body {
  flex: 1;
  padding: 16px 40px 60px;
  overflow-y: auto;
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  outline: none;
  caret-color: var(--accent);
}
.editor-body:empty::before {
  content: "Empieza a escribir...";
  color: var(--muted);
  pointer-events: none;
}
.editor-body h1, .editor-body h2, .editor-body h3 {
  letter-spacing: -0.01em; margin: 1em 0 .4em;
}
.editor-body ul, .editor-body ol { padding-left: 24px; }
.editor-body a { color: var(--accent); }
.editor-body input[type=checkbox] {
  margin-right: 8px;
  accent-color: var(--accent);
}
.editor-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: 14px; color: var(--text-2);
  margin: .6em 0;
}
.editor-body code {
  background: var(--bg-2);
  padding: 2px 6px; border-radius: 4px;
  font-family: var(--mono); font-size: .9em;
}
.editor-pane { position: relative; }
.editor-empty {
  position: absolute;
  inset: 0;
  display: grid; place-items: center;
  color: var(--muted);
  pointer-events: none;
  z-index: 1;
}
/* Estado: sin nota seleccionada — ocultar UI de edición y mostrar mensaje */
body:not(.has-note) .editor-title,
body:not(.has-note) .editor-toolbar,
body:not(.has-note) .editor-body,
body:not(.has-note) .editor-footer,
body:not(.has-note) .editor-actions,
body:not(.has-note) .editor-meta,
body:not(.has-note) #btn-back { display: none !important; }
body.has-note .editor-empty { display: none !important; }

/* ---------- MODAL ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center;
  z-index: 50;
}
.modal-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; font-size: 18px; }
.modal-card input {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px;
  outline: none; margin-bottom: 8px;
}
.modal-card input:focus { border-color: var(--accent); }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 16px;
}
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--border); cursor: pointer;
}
.color-swatch.selected { border-color: var(--text); transform: scale(1.1); }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
  animation: toastIn .2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- RESPONSIVE ---------- */
.mobile-only { display: none; }
@media (max-width: 960px) {
  .app { grid-template-columns: 300px 1fr; }
  .sidebar { grid-column: 1; grid-row: 1; }
  .notes-pane { grid-column: 2; }
  .editor-pane {
    position: fixed !important; inset: 0;
    z-index: 20;
    transform: translateX(100%);
    transition: transform .25s ease;
  }
  body.has-note .editor-pane { transform: translateX(0); }
  .mobile-only { display: inline-grid; }
}
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: 80vw; max-width: 300px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .notes-pane { grid-column: 1; }
  .editor-title, .editor-body, .editor-toolbar { padding-left: 20px; padding-right: 20px; }
}

/* Editor footer */
.editor-footer {
  padding: 8px 40px 14px;
  font-size: 12px;
  color: var(--muted);
  display: flex; justify-content: flex-end;
}

/* Sidebar actions */
.sidebar-actions { display: flex; gap: 4px; }
.sidebar-actions .ghost-btn { padding: 6px 10px; }

/* Editor image */
.editor-body img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
  cursor: zoom-in;
}

/* Trash view */
.folder-item.trash { color: var(--text-2); }
.folder-item.trash.active { color: var(--danger); }
.trash-actions {
  display: flex; gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.trash-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.trash-actions button:hover { color: var(--text); }
.trash-actions button.danger:hover { color: var(--danger); border-color: var(--danger); }

/* Print */
@media print {
  body > *:not(#editor-pane) { display: none !important; }
  .editor-header, .editor-toolbar, .editor-footer, .editor-empty { display: none !important; }
  .editor-pane { position: static !important; background: white !important; color: black !important; }
  .editor-title, .editor-body { color: black !important; padding: 0 !important; }
  .reminder-badge { display: none !important; }
}

/* Color variants on cards */
.color-yellow { background: rgba(255,176,32,.08); }
.color-red    { background: rgba(255,77,79,.08); }
.color-green  { background: rgba(34,197,94,.08); }
.color-blue   { background: rgba(59,130,246,.08); }
.color-purple { background: rgba(168,85,247,.08); }
