:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --panel: #ffffff;
  --fg: #1d1f24;
  --muted: #6b7180;
  --border: #e3e3de;
  --hover: #f0f0eb;
  --accent: #3b6df0;
  --accent-fg: #ffffff;
  --accent-soft: #e7eefe;
  --danger: #d64545;
  --warn: #c97a10;
  --ok: #2f9e6b;
  --code-bg: #f2f2ee;
  --sidebar: #1f2430;
  --sidebar-fg: #cdd3df;
  --sidebar-muted: #8790a3;
  --sidebar-hover: #282e3c;
  --sidebar-active: #333b4e;
  --column: #ededea;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.07);
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --tabbar-h: 0px;

  /* Paleta de texto y resaltado del editor */
  --c-rojo: #d42c2c; --c-naranja: #d9670b; --c-amarillo: #b38600; --c-verde: #23884f;
  --c-azul: #2563eb; --c-morado: #7c3aed; --c-rosa: #db2777; --c-gris: #6b7280;
  --bg-rojo: #fde2e2; --bg-naranja: #ffe8d1; --bg-amarillo: #fff3a8; --bg-verde: #d7f5e2;
  --bg-azul: #dbe7ff; --bg-morado: #ece2ff; --bg-rosa: #ffe0ef; --bg-gris: #e9eaee;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #15171c;
    --panel: #1c1f26;
    --fg: #e4e6eb;
    --muted: #9198a8;
    --border: #2d313b;
    --hover: #252933;
    --accent: #6a90ff;
    --accent-fg: #0d1220;
    --accent-soft: #232e4a;
    --danger: #ff6b6b;
    --warn: #f0a640;
    --ok: #4cc38a;
    --code-bg: #242832;
    --sidebar: #101216;
    --sidebar-fg: #c4cad6;
    --sidebar-muted: #7a8295;
    --sidebar-hover: #1b1e25;
    --sidebar-active: #262b36;
    --column: #191c22;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 14px rgb(0 0 0 / 0.3);

    --c-rojo: #ff7b7b; --c-naranja: #ffa45c; --c-amarillo: #f5d04c; --c-verde: #5fd49a;
    --c-azul: #7aa5ff; --c-morado: #b794ff; --c-rosa: #ff7eb6; --c-gris: #a0a6b3;
    --bg-rojo: #5a2020; --bg-naranja: #5a3615; --bg-amarillo: #564a10; --bg-verde: #18452e;
    --bg-azul: #1d3263; --bg-morado: #3a2763; --bg-rosa: #5a1f3c; --bg-gris: #3a3e48;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  padding: 5px 10px;
  white-space: nowrap;
  touch-action: manipulation;
}
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger, .icon-btn.danger { color: var(--danger); }
input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.icon-btn {
  border: none;
  background: transparent;
  padding: 4px 7px;
  border-radius: 6px;
  line-height: 1;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 30px;
}
.icon-btn.active { background: var(--accent-soft); }

.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 8px; background: var(--hover); }
.segmented button { border: none; background: transparent; padding: 5px 10px; border-radius: 6px; }
.segmented button.active { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }
.segmented.small button { padding: 2px 8px; }

.spacer { flex: 1; }
.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.app[data-view="notes"] .view-notes { display: grid; grid-template-columns: 320px minmax(0, 1fr); }
.app[data-view="board"] .view-board,
.app[data-view="calendar"] .view-calendar,
.app[data-view="reminders"] .view-reminders { display: flex; }
.app:not([data-view="notes"]) .tags-section { display: none; }

.topbar { display: none; }
.tabbar { display: none; }
.drawer-backdrop { display: none; }

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.view-head h2 { margin: 0; font-size: 20px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------ sidebar */

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-fg);
  padding: 14px 10px;
  padding-top: max(14px, env(safe-area-inset-top));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
}
.brand { font-size: 18px; font-weight: 700; padding: 0 8px 10px; color: #fff; }
.sidebar .icon-btn { color: var(--sidebar-muted); }
.sidebar .icon-btn:hover { color: #fff; background: var(--sidebar-active); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: transparent;
  color: var(--sidebar-fg);
  padding: 8px 10px;
  text-align: left;
  border-radius: 6px;
}
.nav button span { flex: 1; }
.nav button:hover { background: var(--sidebar-hover); }
.nav button.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  padding: 14px 8px 4px;
}
.section-head.plain { color: var(--muted); padding: 14px 0 6px; }
.section-head.plain button { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; }

.tree { list-style: none; margin: 0; padding: 0; }
.side-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--sidebar-fg);
  cursor: pointer;
  text-align: left;
  min-height: 34px;
}
button.side-item:hover, .side-item:hover { background: var(--sidebar-hover); }
.side-item.active { background: var(--sidebar-active); color: #fff; }
.side-item.drop-target { outline: 2px dashed var(--accent); background: var(--sidebar-active); }
.side-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .count { font-size: 12px; color: var(--sidebar-muted); }
.side-item .actions { display: none; }
.side-item:hover .actions, .side-item.active .actions { display: flex; }
.side-item:hover .count, .side-item.active .count { display: none; }
.side-empty { padding: 4px 10px; color: var(--sidebar-muted); font-size: 13px; }

.user-box {
  margin-top: auto;
  padding: 12px 6px 0;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--sidebar-active);
  display: flex;
  align-items: center;
  gap: 2px;
}
.user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

/* ------------------------------------------------------------ page list */

.list-pane {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.list-head input { flex: 1; }
.list-title { padding: 10px 14px 6px; font-weight: 700; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.note-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.note-item {
  position: relative;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.note-item:hover { background: var(--hover); }
.note-item.active { background: var(--accent-soft); border-color: var(--accent); }
.note-item.drop-before::before, .note-item.drop-after::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.note-item.drop-before::before { top: -3px; }
.note-item.drop-after::after { bottom: -3px; }
.note-row { display: flex; align-items: center; gap: 4px; }
.note-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item.child .note-title { font-weight: 500; }
.note-flags { font-size: 12px; display: inline-flex; gap: 2px; }
.twisty {
  border: none;
  background: transparent;
  width: 20px;
  height: 20px;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  flex: none;
}
.twisty:hover { color: var(--fg); background: var(--hover); }
.twisty-space { width: 20px; flex: none; }
.add-sub {
  display: none;
  border: none;
  background: transparent;
  padding: 0 4px;
  color: var(--muted);
}
.note-item:hover .add-sub { display: inline-block; }
.note-snippet {
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 2px 0 4px;
}
.note-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 12px; color: var(--muted); align-items: center; }
.chip {
  background: var(--hover);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
  color: var(--muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-group { padding: 12px 10px 4px; font-size: 12px; font-weight: 700; color: var(--muted); list-style: none; }
.list-empty { color: var(--muted); padding: 24px 10px; text-align: center; list-style: none; }

/* ------------------------------------------------------------ editor */

.editor-pane { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.empty { margin: auto; color: var(--muted); padding: 24px; text-align: center; }
.editor { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.editor-head { display: flex; gap: 8px; align-items: center; padding: 10px 16px 4px; }
.back-btn { display: none; font-size: 20px; }
.title-input {
  flex: 1;
  min-width: 0;
  font-size: 22px;
  font-weight: 700;
  border: none;
  padding: 4px 0;
  background: transparent;
}
.title-input:focus { box-shadow: none; }
.status { font-size: 12px; color: var(--muted); white-space: nowrap; }
#note-menu-btn { font-size: 20px; }

.note-meta-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 8px; border-bottom: 1px solid var(--border); }
.note-meta-row select { max-width: 200px; font-size: 13px; padding: 4px 6px; }
.tags-input { flex: 1; min-width: 160px; font-size: 13px; padding: 4px 8px; }

.note-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 7px 16px;
  background: var(--accent-soft);
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.lock-panel { margin: auto; text-align: center; padding: 30px 20px; max-width: 360px; }
.lock-icon { font-size: 48px; }
.lock-panel form { display: flex; gap: 8px; margin-top: 10px; }
.lock-panel input { flex: 1; }

.note-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.editor.readonly .toolbar button[data-fmt],
.editor.readonly .toolbar button[data-pop],
.editor.readonly .toolbar select,
.editor.readonly #attach-btn { display: none; }
.editor.readonly .toolbar .sep { display: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.toolbar > button { border: none; background: transparent; min-width: 32px; height: 32px; padding: 0 6px; flex: none; }
.toolbar > button:hover:not(:disabled) { background: var(--hover); }
.toolbar select { font-size: 13px; padding: 3px 4px; height: 30px; flex: none; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex: none; }
.toolbar .segmented { margin-left: auto; flex: none; }
.color-a { font-weight: 700; border-bottom: 3px solid var(--c-rojo); padding: 0 2px; }

.editor-body { flex: 1; display: grid; min-height: 0; }
.editor-body.mode-split { grid-template-columns: 1fr 1fr; }
.editor-body.mode-edit .preview, .editor-body.mode-view textarea { display: none; }
.editor-body textarea {
  resize: none;
  border: none;
  border-radius: 0;
  padding: 16px 18px;
  font: 14px/1.6 var(--mono);
  min-height: 0;
  height: 100%;
}
.editor-body textarea:focus { box-shadow: none; }
.editor-body.mode-split textarea { border-right: 1px solid var(--border); }
.preview { overflow-y: auto; padding: 16px 22px; min-height: 0; -webkit-overflow-scrolling: touch; }

.editor-pane.dropping::after, dialog.dropping::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 3px dashed var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  pointer-events: none;
}
.drop-hint {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--accent);
  color: var(--accent-fg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  pointer-events: none;
  z-index: 2;
}
.editor-pane.dropping .drop-hint { display: block; }

/* ------------------------------------------------------------ popover (menús y paletas) */

.popover {
  position: fixed;
  z-index: 50;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
  padding: 6px;
  min-width: 200px;
  max-width: calc(100vw - 16px);
}
.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  padding: 8px 10px;
  text-align: left;
  border-radius: 6px;
}
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.swatches { display: grid; grid-template-columns: repeat(5, 36px); gap: 6px; padding: 4px; }
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0;
  font-weight: 700;
}
.swatch.none { font-size: 16px; }
.swatch-custom { display: flex; align-items: center; gap: 8px; padding: 6px 4px 2px; font-size: 13px; color: var(--muted); }
.swatch-custom input { width: 44px; height: 30px; padding: 2px; }

/* ------------------------------------------------------------ attachments & viewer */

.attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  max-height: 180px;
  overflow-y: auto;
  flex: none;
}
.attachments.is-empty { display: none; }
dialog .attachments { padding: 0; border: none; max-height: 220px; }
.attachments-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 0;
}
.attachment .thumb {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hover);
  font-size: 22px;
  border: none;
  padding: 0;
}
.attachment img { width: 100%; height: 100%; object-fit: cover; }
.attachment .info { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.attachment .name {
  color: var(--fg);
  border: none;
  background: none;
  padding: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  text-align: left;
}
.attachment .name:hover { text-decoration: underline; background: none; }
.attachment .size { font-size: 11px; color: var(--muted); }
.attachment .actions { display: flex; }

dialog.viewer {
  width: min(1100px, calc(100vw - 32px));
  height: min(88vh, 900px);
  padding: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
dialog.viewer[open] { display: flex; }
.viewer-head { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.viewer-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-tabs { display: flex; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
.viewer-tabs button { border-radius: 6px 6px 0 0; font-size: 13px; }
.viewer-tabs button.active { background: var(--accent-soft); border-color: var(--accent); }
.viewer-body { flex: 1; overflow: auto; min-height: 0; background: var(--bg); -webkit-overflow-scrolling: touch; }
.viewer-body > iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.viewer-body > img, .viewer-body > video { display: block; max-width: 100%; max-height: 100%; margin: auto; }
.viewer-body > audio { display: block; margin: 40px auto; width: min(500px, 90%); }
.viewer-body > pre { margin: 0; padding: 16px; font: 13px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.viewer-msg { padding: 40px 20px; text-align: center; color: var(--muted); }
.doc-page {
  background: #fff;
  color: #1d1f24;
  max-width: 820px;
  margin: 20px auto;
  padding: 48px 56px;
  box-shadow: var(--shadow);
  line-height: 1.6;
}
.doc-page img { max-width: 100%; }
.doc-page table { border-collapse: collapse; }
.doc-page td, .doc-page th { border: 1px solid #ccc; padding: 4px 8px; }
.sheet-wrap { padding: 12px; }
.sheet-wrap table { border-collapse: collapse; background: var(--panel); font-size: 13px; }
.sheet-wrap td, .sheet-wrap th { border: 1px solid var(--border); padding: 4px 8px; white-space: nowrap; }
.sheet-wrap tr:first-child td { background: var(--hover); font-weight: 600; position: sticky; top: 0; }
.sheet-note { color: var(--muted); font-size: 12px; padding: 0 12px 12px; }

/* ------------------------------------------------------------ markdown */

.md { line-height: 1.65; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.2em 0 0.5em; }
.md h1 { font-size: 1.7em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
.md h2 { font-size: 1.35em; }
.md h3 { font-size: 1.15em; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .table-wrap { margin: 0 0 0.9em; }
.md ul, .md ol { padding-left: 1.6em; }
.md li.task { list-style: none; margin-left: -1.3em; }
.md li.task input { margin: 0 6px 0 0; vertical-align: middle; cursor: pointer; accent-color: var(--accent); width: 16px; height: 16px; }
.md li.task.done { color: var(--muted); text-decoration: line-through; }
.md a { color: var(--accent); }
.md img { max-width: 100%; border-radius: 6px; cursor: zoom-in; }
.md code { font-family: var(--mono); font-size: 0.9em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--code-bg); padding: 12px 14px; border-radius: var(--radius); overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 4px solid var(--accent); margin-left: 0; padding: 2px 14px; color: var(--muted); background: var(--hover); border-radius: 0 6px 6px 0; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md mark { background: var(--bg-amarillo); color: inherit; padding: 0 2px; border-radius: 2px; }
.md .table-wrap { overflow-x: auto; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; }
.md th { background: var(--hover); }
.md [class*="bg-"] { padding: 0 3px; border-radius: 3px; }

.c-rojo { color: var(--c-rojo); } .c-naranja { color: var(--c-naranja); } .c-amarillo { color: var(--c-amarillo); }
.c-verde { color: var(--c-verde); } .c-azul { color: var(--c-azul); } .c-morado { color: var(--c-morado); }
.c-rosa { color: var(--c-rosa); } .c-gris { color: var(--c-gris); }
.bg-rojo { background: var(--bg-rojo); } .bg-naranja { background: var(--bg-naranja); } .bg-amarillo { background: var(--bg-amarillo); }
.bg-verde { background: var(--bg-verde); } .bg-azul { background: var(--bg-azul); } .bg-morado { background: var(--bg-morado); }
.bg-rosa { background: var(--bg-rosa); } .bg-gris { background: var(--bg-gris); }
.fs-xs { font-size: 0.75em; } .fs-sm { font-size: 0.875em; } .fs-lg { font-size: 1.25em; }
.fs-xl { font-size: 1.6em; } .fs-xxl { font-size: 2.2em; line-height: 1.2; }

/* ------------------------------------------------------------ board */

.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(250px, 1fr));
  gap: 14px;
  padding: 16px 20px;
  overflow: auto;
  align-items: start;
  -webkit-overflow-scrolling: touch;
}
.column {
  background: var(--column);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  min-height: 0;
}
.column > header { display: flex; justify-content: space-between; align-items: center; font-weight: 700; padding: 2px 4px 10px; }
.column > header::before { content: ""; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; background: var(--muted); }
.col-doing > header::before { background: var(--accent); }
.col-done > header::before { background: var(--ok); }
.column > header span:first-child { flex: 1; }
.column .count { font-size: 12px; color: var(--muted); background: var(--panel); border-radius: 999px; padding: 0 8px; }
.column-list { display: flex; flex-direction: column; gap: 8px; min-height: 40px; overflow-y: auto; padding: 2px; }
.task-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  cursor: grab;
  border-left: 3px solid var(--muted);
}
.task-card.prio-alta { border-left-color: var(--danger); }
.task-card.prio-media { border-left-color: var(--warn); }
.task-card.prio-baja { border-left-color: var(--ok); }
.task-card:hover { outline: 1px solid var(--accent); }
.task-card.dragging { opacity: 0.4; }
.task-card.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.pill { border-radius: 999px; padding: 0 8px; background: var(--hover); }
.pill.prio-alta { color: var(--danger); }
.pill.prio-media { color: var(--warn); }
.pill.prio-baja { color: var(--ok); }
.pill.overdue { background: var(--danger); color: #fff; }
.task-meta .spacer { flex: 1; }
.move-btns { display: none; gap: 2px; }
.move-btns .icon-btn { min-width: 34px; min-height: 30px; background: var(--hover); }
.card-placeholder { height: 46px; border: 2px dashed var(--accent); border-radius: var(--radius); background: var(--accent-soft); }
.quick-add { margin-top: 8px; background: transparent; border-style: dashed; }
.quick-add:focus { background: var(--panel); border-style: solid; }

/* ------------------------------------------------------------ calendar */

.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-nav h2 { min-width: 170px; text-align: center; }
.cal-nav .icon-btn { font-size: 22px; }
.cal-layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 300px; min-height: 0; }
.cal-month { display: flex; flex-direction: column; min-height: 0; padding: 12px 16px 16px; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); font-size: 12px; font-weight: 700; color: var(--muted); padding-bottom: 6px; text-align: center; }
.cal-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(84px, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.cal-day {
  background: var(--panel);
  padding: 4px 5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
  border: none;
  border-radius: 0;
  text-align: left;
  font: inherit;
}
.cal-day:hover { background: var(--hover); }
.cal-day.other { background: var(--bg); color: var(--muted); }
.cal-day.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-num { font-size: 12px; font-weight: 600; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 50%; flex: none; }
.cal-day.today .cal-num { background: var(--accent); color: var(--accent-fg); }
.cal-chip {
  font-size: 11px;
  border-radius: 4px;
  padding: 1px 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--hover);
  border-left: 3px solid var(--muted);
}
.cal-chip.task.prio-alta { border-left-color: var(--danger); }
.cal-chip.task.prio-media { border-left-color: var(--warn); }
.cal-chip.task.prio-baja { border-left-color: var(--ok); }
.cal-chip.reminder { border-left-color: var(--accent); background: var(--accent-soft); }
.cal-chip.done { text-decoration: line-through; opacity: 0.6; }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; padding: 0 2px; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.cal-dot.reminder { background: var(--accent); }
.cal-dot.done { opacity: 0.4; }

.agenda { border-left: 1px solid var(--border); background: var(--panel); padding: 16px; overflow-y: auto; min-height: 0; }
.agenda h3 { margin: 0 0 12px; font-size: 16px; }
.agenda-actions { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.agenda-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  cursor: pointer;
  background: var(--panel);
  width: 100%;
  text-align: left;
  white-space: normal;
}
.agenda-item:hover { border-color: var(--accent); }
.agenda-item .when { font-size: 12px; color: var(--muted); }
.agenda-item.done .ag-title { text-decoration: line-through; color: var(--muted); }
.agenda-empty { color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------ reminders */

.quick-reminder { display: flex; gap: 8px; padding: 14px 20px 0; flex-wrap: wrap; }
.quick-reminder input[name="title"] { flex: 1; min-width: 180px; }
.reminder-list { flex: 1; overflow-y: auto; padding: 8px 20px 24px; -webkit-overflow-scrolling: touch; }
.rem-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 18px 0 8px; display: flex; gap: 8px; align-items: center; }
.rem-group.overdue h3 { color: var(--danger); }
.rem-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
}
.rem-item.overdue { border-left: 3px solid var(--danger); }
.rem-check { width: 22px; height: 22px; accent-color: var(--accent); flex: none; cursor: pointer; }
.rem-main { flex: 1; min-width: 0; cursor: pointer; }
.rem-title { font-weight: 600; overflow-wrap: anywhere; }
.rem-item.done .rem-title { text-decoration: line-through; color: var(--muted); }
.rem-sub { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.rem-sub .late { color: var(--danger); font-weight: 600; }
.rem-note { border: none; background: none; padding: 0; color: var(--accent); font-size: 12px; }
.rem-empty { color: var(--muted); padding: 30px 0; text-align: center; }
.linked-note { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 8px 10px; background: var(--hover); border-radius: 6px; margin-top: 10px; }
.linked-note span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ login & account */

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at 30% 20%, var(--accent-soft), transparent 60%), var(--bg);
}
.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-brand { font-size: 24px; font-weight: 700; }
.login-sub { margin: -6px 0 6px; color: var(--muted); }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card label input { color: var(--fg); font-weight: 400; font-size: 16px; padding: 9px 11px; }
.login-card button { padding: 10px; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 1em; }

dialog.wide { width: min(860px, calc(100vw - 32px)); }
.table-scroll { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.users-table td { padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.users-table .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.users-table .row-actions button { padding: 3px 8px; font-size: 12px; }
.user-form { margin-top: 18px; }
.user-form h4 { margin: 0 0 10px; }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
#password-form label { margin-bottom: 10px; }

/* ------------------------------------------------------------ dialogs & toast */

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  background: var(--panel);
  color: var(--fg);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
#ask-dialog { width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h3 { margin: 0 0 12px; }
dialog form > input:not(.title-input) { width: 100%; }
dialog .title-input { width: 100%; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
dialog .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
dialog label > * { color: var(--fg); font-weight: 400; font-size: 14px; }
dialog label.block textarea { resize: vertical; width: 100%; }
dialog menu { display: flex; gap: 8px; margin: 18px 0 0; padding: 0; }

.toast {
  position: fixed;
  bottom: calc(20px + var(--tabbar-h) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--fg);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------ pantallas táctiles */

@media (hover: none) {
  .side-item .actions { display: flex; }
  .side-item .count { display: none; }
  .add-sub { display: inline-block; }
  .task-card { cursor: pointer; }
  .move-btns { display: inline-flex; }
}

/* ------------------------------------------------------------ tablet (iPad, iPad mini) */

@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(290px, 85vw);
    z-index: 40;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s;
  }
  .app.drawer-open .sidebar { transform: none; visibility: visible; box-shadow: 4px 0 24px rgb(0 0 0 / 0.3); }
  .app.drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / 0.4); z-index: 39; }

  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex: none;
  }
  .topbar h1 { flex: 1; margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #menu-btn { font-size: 20px; }
  .round { width: 36px; height: 36px; border-radius: 50%; padding: 0; font-size: 18px; }

  .view-board .view-head, .view-reminders .view-head h2 { display: none; }
  .view-reminders .view-head { justify-content: flex-end; border-bottom: none; padding-bottom: 0; }
  .view-reminders .view-head .primary { display: none; }
  .app[data-view="notes"] .view-notes { grid-template-columns: 280px minmax(0, 1fr); }
  .list-head .primary { display: none; }
  .cal-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; overflow-y: auto; }
  .cal-grid { flex: none; grid-auto-rows: minmax(70px, auto); }
  .agenda { border-left: none; border-top: 1px solid var(--border); }
  .cal-head .head-actions { display: none; }
  .editor-body.mode-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .editor-body.mode-split textarea { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ------------------------------------------------------------ móvil */

@media (max-width: 700px) {
  :root { --tabbar-h: 58px; }
  input, select, textarea { font-size: 16px; } /* evita el zoom automático de iOS */
  .toolbar select, .note-meta-row select, .tags-input { font-size: 16px; }

  .main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar button {
    flex: 1;
    border: none;
    background: transparent;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 6px 0 7px;
    font-size: 11px;
    color: var(--muted);
    position: relative;
    height: var(--tabbar-h);
  }
  .tabbar button span { font-size: 20px; line-height: 1.2; filter: grayscale(1); opacity: 0.7; }
  .tabbar button.active { color: var(--accent); font-weight: 600; }
  .tabbar button.active span { filter: none; opacity: 1; }
  .tabbar .badge { position: absolute; top: 4px; left: calc(50% + 6px); }

  .app[data-view="notes"] .view-notes { grid-template-columns: minmax(0, 1fr); }
  .app[data-view="notes"].note-open .list-pane { display: none; }
  .app[data-view="notes"]:not(.note-open) .editor-pane { display: none; }
  .app[data-view="notes"].note-open .topbar,
  .app[data-view="notes"].note-open .tabbar { display: none; }
  .app[data-view="notes"].note-open .main { padding-bottom: env(safe-area-inset-bottom); }
  .back-btn { display: inline-flex; }
  .editor-head { padding: 8px 10px 2px; padding-top: max(8px, env(safe-area-inset-top)); }
  .title-input { font-size: 19px; }
  .note-meta-row { padding: 4px 10px 8px; }
  .note-meta-row select { flex: 1; max-width: none; }
  .tags-input { flex-basis: 100%; }
  .toolbar { padding: 4px 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar .segmented { margin-left: 4px; }
  .editor-body textarea, .preview { padding: 12px 14px; }
  .editor-body.mode-split { grid-template-rows: 1fr 1fr; }
  .attachments { grid-template-columns: 1fr; padding: 8px 10px; max-height: 140px; }

  .board {
    grid-template-columns: repeat(3, 86vw);
    scroll-snap-type: x mandatory;
    padding: 12px;
    gap: 10px;
  }
  .column { scroll-snap-align: center; }

  .cal-month { padding: 8px; }
  .cal-nav h2 { min-width: 0; font-size: 17px; }
  .cal-grid { grid-auto-rows: 52px; }
  .cal-day { align-items: center; padding: 3px 2px; }
  .cal-chip, .cal-more { display: none; }
  .cal-dots { display: flex; justify-content: center; }
  .view-head { padding: 10px 12px; }
  .agenda { padding: 12px; }

  .quick-reminder { padding: 10px 12px 0; }
  .quick-reminder input[name="title"] { flex-basis: 100%; }
  .quick-reminder input[name="when"] { flex: 1; }
  .reminder-list { padding: 4px 12px 20px; }

  dialog {
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  }
  dialog.viewer { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; padding: 0; }
  .viewer-head { padding-top: max(10px, env(safe-area-inset-top)); }
  .doc-page { margin: 0; padding: 20px 16px; box-shadow: none; }
  dialog menu { flex-wrap: wrap; }
  .users-table .row-actions { flex-wrap: wrap; }
}
