:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --text: #16181d;
  --muted: #646b76;
  --accent: #2563eb;
  --accent-soft: #e6eefd;
  --accent-text: #ffffff;
  --danger: #c4314b;
  --ok: #188a4a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 12px;
  --nav-w: 216px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #e8eaee;
    --muted: #9aa2ae;
    --accent: #5b8cff;
    --accent-soft: #1d2a47;
    --accent-text: #0b1020;
    --danger: #ff6b81;
    --ok: #4cc38a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }

/* --- Estructura ------------------------------------------------------- */
.shell { min-height: 100%; }
.nav {
  position: fixed; z-index: 20; background: var(--surface); border-color: var(--border);
  display: flex;
}
.nav a {
  display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--muted);
  border-radius: 10px; font-weight: 550;
}
.nav a.active { color: var(--accent); }
.brand { display: none; }

@media (min-width: 820px) {
  .nav { inset: 0 auto 0 0; width: var(--nav-w); flex-direction: column; padding: 18px 12px; gap: 2px; border-right: 1px solid var(--border); }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
  .brand img { width: 30px; height: 30px; border-radius: 8px; }
  .nav a { padding: 10px 12px; }
  .nav a:hover { background: var(--surface-2); color: var(--text); }
  .nav a.active { background: var(--accent-soft); }
  .nav a[data-route="ajustes"] { margin-top: auto; }
  main { margin-left: var(--nav-w); padding: 32px 40px 48px; max-width: calc(1100px + var(--nav-w)); }
}
@media (max-width: 819px) {
  .nav {
    inset: auto 0 0 0; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    border-top: 1px solid var(--border); justify-content: space-around;
  }
  .nav a { flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 2px; font-size: 11px; }
  .nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
  .nav a svg { width: 24px; height: 24px; }
  main { padding: calc(18px + var(--safe-t)) 16px calc(var(--tab-h) + var(--safe-b) + 24px); }
}
main:focus { outline: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-head h2 { min-width: 0; }
.section-head a { font-size: 14px; text-decoration: none; white-space: nowrap; flex: none; }
.head-actions { display: flex; gap: 8px; flex: none; }
.grid-2 { display: grid; gap: 24px; }
@media (min-width: 1000px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { color: var(--muted); padding: 22px 16px; text-align: center; }
.error { color: var(--danger); margin: 0; }
.banner { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); margin-bottom: 18px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* --- Controles -------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 550; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px;
  border: 0; background: transparent; cursor: pointer; color: inherit; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }

input[type=text], input[type=password], input[type=date], input[type=time], input[type=search], input:not([type]), select, textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 550; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 15px; font-weight: 400; color: var(--text); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; font-weight: 400; }
.form { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.tabs { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 11px; gap: 2px; }
.tabs button { border: 0; background: transparent; height: 32px; padding: 0 14px; border-radius: 8px; cursor: pointer; font-weight: 550; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* --- Listas ----------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; width: 100%; text-align: left; background: none;
  border: 0; cursor: pointer; color: inherit; text-decoration: none; min-height: 54px;
}
button.item:hover, a.item:hover { background: var(--surface-2); }
.item .grow { flex: 1; min-width: 0; }
.item .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.item .meta { color: var(--muted); font-size: 13px; }
.file-icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-size: 10px; font-weight: 700; flex: none; color: #fff; letter-spacing: .02em; }
.ft-pdf { background: #d9363e; } .ft-doc { background: #2b6cd9; } .ft-xls { background: #1e8a4c; }
.ft-ppt { background: #d46a1f; } .ft-img { background: #8a4fd6; } .ft-dir { background: #e8b13a; } .ft-other { background: #7a8290; }
.item-actions { display: flex; gap: 2px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 180px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.crumbs button { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.crumbs button:last-child { color: var(--text); font-weight: 600; cursor: default; }
.crumbs span { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; height: 32px; padding: 0 12px; cursor: pointer; font-weight: 550; font-size: 13px; color: var(--muted); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dropzone.drag { outline: 2px dashed var(--accent); outline-offset: 4px; }

/* --- Tareas y notas --------------------------------------------------- */
.task { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; min-height: 50px; }
.task input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; cursor: pointer; }
.task .grow { flex: 1; min-width: 0; cursor: pointer; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.due { font-size: 12px; color: var(--muted); }
.due.late { color: var(--danger); font-weight: 600; }
.due.today { color: var(--accent); font-weight: 600; }
.quick-add { display: flex; gap: 8px; margin-bottom: 14px; }
.quick-add input:first-child { flex: 1; }
.quick-add input[type=date] { width: 150px; flex: none; }
.notes-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.note { padding: 14px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 110px; max-height: 240px; overflow: hidden; }
.note:hover { border-color: var(--accent); }
.note h3 { font-size: 15px; }
.note p { margin: 0; color: var(--muted); white-space: pre-wrap; overflow: hidden; font-size: 14px; }
.note .pin { color: var(--accent); font-size: 12px; font-weight: 600; }
details summary { cursor: pointer; color: var(--muted); padding: 10px 2px; font-weight: 550; }

/* --- Calendario ------------------------------------------------------- */
.cal-layout { display: grid; gap: 20px; }
@media (min-width: 1100px) { .cal-layout { grid-template-columns: minmax(0, 1fr) 320px; } }
.cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-head .label { font-size: 18px; font-weight: 650; margin: 0 8px; min-width: 150px; }
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); overflow: hidden; }
.month .dow { font-size: 12px; color: var(--muted); padding: 8px 6px; text-align: center; font-weight: 600; border-bottom: 1px solid var(--border); }
.day {
  min-height: 96px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px; cursor: pointer;
  background: none; border-top: 0; border-left: 0; text-align: left; display: flex; flex-direction: column; gap: 2px; color: inherit; min-width: 0;
}
.day:nth-child(7n+7) { border-right: 0; }
.day:hover { background: var(--surface-2); }
.day.other { color: var(--muted); background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.day .n { font-size: 13px; font-weight: 600; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.day.today .n { background: var(--accent); color: var(--accent-text); }
.day.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.ev-chip { font-size: 12px; border-radius: 5px; padding: 1px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.ev-chip.timed { background: none !important; color: var(--text); padding-left: 2px; }
.ev-chip.timed::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); margin-right: 4px; }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.dots { display: none; gap: 3px; flex-wrap: wrap; padding: 0 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }
@media (max-width: 700px) {
  .day { min-height: 54px; align-items: center; }
  .ev-chip, .more { display: none; }
  .dots { display: flex; justify-content: center; }
}
.agenda-day { margin-bottom: 16px; }
.agenda-day h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; font-weight: 600; }
.agenda-day h3.today { color: var(--accent); }
.event { display: flex; gap: 12px; padding: 10px 14px; align-items: flex-start; cursor: pointer; width: 100%; background: none; border: 0; text-align: left; color: inherit; }
.event:hover { background: var(--surface-2); }
.event .bar { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.event .time { font-size: 13px; color: var(--muted); width: 88px; flex: none; padding-top: 1px; }
.event .grow { flex: 1; min-width: 0; }
.event .title { font-weight: 550; }
.event .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-list { display: grid; gap: 8px; padding: 12px 14px; }

/* --- Login ------------------------------------------------------------ */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; background: var(--surface); padding: 28px 24px; border-radius: 16px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.login-logo { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto; }
.login-card h1 { text-align: center; margin-bottom: 6px; }

/* --- Visor ------------------------------------------------------------ */
.viewer { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; }
.viewer-bar {
  display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-t)) 8px 6px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.viewer-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-tools { display: flex; align-items: center; gap: 2px; }
.zoom-label { font-size: 12px; color: var(--muted); width: 42px; text-align: center; }
.viewer-body { flex: 1; overflow: auto; padding: 16px 8px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.viewer-body .pdf-page { margin: 0 auto 12px; background: #fff; box-shadow: var(--shadow); position: relative; }
.viewer-body .pdf-page canvas { display: block; width: 100%; height: 100%; }
.viewer-body .pdf-page .pnum { position: absolute; bottom: -18px; right: 0; font-size: 11px; color: var(--muted); }
.viewer-body img.doc-img { display: block; max-width: 100%; margin: 0 auto; transform-origin: top center; }
.viewer-body pre.doc-text { white-space: pre-wrap; background: var(--surface); padding: 16px; border-radius: 10px; max-width: 900px; margin: 0 auto; font-size: 14px; }
.viewer-body .docx-wrap { transform-origin: top center; }
.viewer-body .docx-wrapper { background: transparent !important; padding: 0 !important; }
.viewer-body .docx-wrapper > section.docx { box-shadow: var(--shadow) !important; margin-bottom: 16px !important; }
.viewer-msg { text-align: center; color: var(--muted); padding: 60px 20px; display: grid; gap: 14px; justify-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Modal y toast ---------------------------------------------------- */
.modal { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); max-height: calc(100vh - 40px); }
.modal::backdrop { background: rgba(10, 12, 16, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.modal-body { padding: 8px 18px 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 18px 18px; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
@media (max-width: 600px) {
  .modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: var(--safe-b); }
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 550; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
@media (min-width: 820px) { .toast { bottom: 24px; } }
.note-editor textarea { min-height: 280px; }
.note-editor input.title-input { font-size: 18px; font-weight: 600; border: 0; padding: 0; height: 36px; }
.note-editor input.title-input:focus { outline: none; }

/* --- Accesos rápidos -------------------------------------------------- */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (max-width: 500px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.tile { position: relative; display: flex; flex-direction: column; min-height: 132px; }
.tile-open {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; border: 0; background: none;
  cursor: pointer; text-align: left; color: inherit; border-radius: var(--radius); min-width: 0;
}
.tile-open:hover { background: var(--surface-2); }
.tile .file-icon { width: 42px; height: 42px; border-radius: 10px; font-size: 11px; }
.tile-name { font-weight: 550; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.tile-src { font-size: 12px; color: var(--muted); margin-top: auto; }
.tiles.editing .tile { border-style: dashed; border-color: var(--accent); }
.tiles.editing .tile-open { cursor: default; pointer-events: none; }
.tiles.editing .tile-open:hover { background: none; }
.tile-tools { display: flex; justify-content: space-between; border-top: 1px solid var(--border); padding: 2px 4px; }
.tile-tools .icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.danger { color: var(--danger); }
.tile-add {
  border: 1.5px dashed var(--border); background: transparent; border-radius: var(--radius); color: var(--muted); cursor: pointer;
  align-items: center; justify-content: center; gap: 6px; font-weight: 550;
}
.tile-add:hover { border-color: var(--accent); color: var(--accent); }
.row-item { display: flex; align-items: center; padding-right: 6px; min-width: 0; }
.row-item > .item { flex: 1; min-width: 0; width: auto; }
.row-item .item-actions { flex: none; }
.pin-btn { color: var(--muted); }
.pin-btn.on { color: #e8a317; }
.pin-btn.on svg { fill: currentColor; }
.pk-scroll { max-height: min(46vh, 420px); overflow: auto; }
.pk-item .pk-state { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; }
.pk-item.on .pk-state { background: var(--accent); color: var(--accent-text); }
.pk-item .pk-state svg { width: 18px; height: 18px; }
.modal .tabs { justify-self: start; flex-wrap: wrap; }

@media (max-width: 600px) {
  .head-actions .btn { height: 34px; padding: 0 12px; }
  .head-actions .btn .lbl { display: none; }
  .head-actions .btn.primary { width: 34px; padding: 0; }
  .item { padding: 10px 10px 10px 12px; gap: 10px; }
  .item-actions .icon-btn { width: 34px; height: 34px; }
  .item-actions { gap: 0; }
  .toolbar .muted.small { flex-basis: 100% !important; }
}

/* Dentro de los modales nada puede ser más ancho que el modal. */
.modal { overflow-x: hidden; }
.modal-body > *, #pk-body > * { min-width: 0; }
.modal .tabs { display: flex; justify-self: stretch; flex-wrap: nowrap; }
.modal .tabs button { flex: 1 1 0; min-width: 0; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Publicaciones .jwpub --------------------------------------------- */
.ft-jw { background: #4a6da7; }
.jw-index, .jw-doc { max-width: 760px; margin: 0 auto; }
.jw-head { display: flex; gap: 16px; align-items: center; margin: 4px 4px 16px; }
.jw-head h2 { font-size: 18px; }
.jw-cover { width: 76px; border-radius: 8px; box-shadow: var(--shadow); flex: none; }
.jw-nav { display: flex; gap: 8px; margin: 0 0 10px; }
.jw-pager { justify-content: space-between; margin: 12px 0 0; }
.jw-frame { display: block; width: 100%; border: 0; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); min-height: 200px; }
