/* Lumy Notes web client.
 *
 * Same rule as the marketing pages: no web fonts, no third-party anything.
 * The CSP forbids it, and a client whose claim is "nothing about you leaves
 * this device" should not open by fetching a font from someone else's server.
 */

:root {
  color-scheme: light dark;

  --paper: #fbfaf7;
  --raised: #ffffff;
  --chrome: #f4f2ee;
  --ink: #16171b;
  --ink-soft: #565a63;
  --ink-faint: #8a8e96;
  --rule: #e2e0da;
  --accent: #1f4fa3;
  --accent-ink: #ffffff;
  --ok: #1f6b45;
  --warn: #9a6b1f;
  --bad: #9a3630;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --bar-h: 3.25rem;
  --tools-h: 3.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14161a;
    --raised: #1a1d23;
    --chrome: #191c22;
    --ink: #e9eaee;
    --ink-soft: #a3a9b5;
    --ink-faint: #7b8290;
    --rule: #282c35;
    --accent: #6d9bf0;
    --accent-ink: #0e1117;
    --ok: #6cc39a;
    --warn: #d9ad63;
    --bad: #e08b85;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

/* --- buttons --- */

.primary, .ghost {
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.primary:hover { filter: brightness(1.08); }

.ghost { background: transparent; border-color: var(--rule); color: var(--ink-soft); }
.ghost:hover { border-color: var(--ink-faint); color: var(--ink); }
.ghost:disabled { opacity: 0.4; cursor: default; }

.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.block { width: 100%; }

.icon {
  background: none; border: 0; cursor: pointer;
  font-size: 1.1rem; color: var(--ink-soft); padding: 0.3rem 0.5rem;
}
.icon:hover { color: var(--ink); }

/* --- sign in --- */

.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 1.5rem;
  background: var(--paper);
}

.gate-card {
  width: min(26rem, 100%);
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 2rem 1.8rem 1.6rem;
}

.gate-card h1 {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.sub { margin: 0 0 1.6rem; color: var(--ink-soft); font-size: 0.95rem; }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
}

input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.gate-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; }
.gate-actions button { flex: 1; }

.msg { min-height: 1.4rem; margin: 0.9rem 0 0; font-size: 0.9rem; }
.msg.error { color: var(--bad); }
.msg.ok { color: var(--ok); }

.fineprint {
  margin: 1.4rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.82rem;
  color: var(--ink-faint);
  line-height: 1.5;
}

/* --- app shell --- */

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

.bar {
  height: var(--bar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 0.75rem;
  background: var(--chrome);
  border-bottom: 1px solid var(--rule);
}

.bar-left { display: flex; align-items: center; gap: 0.4rem; min-width: 0; flex: 1; }
.bar-right { display: flex; align-items: center; gap: 0.5rem; }

.title {
  border: 0;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  min-width: 0;
  flex: 1;
  max-width: 30rem;
}
.title:hover { background: var(--raised); }
.title:focus { outline: 2px solid var(--accent); background: var(--raised); }

/* Sync state. Unlike the marketing page's old fake badge, this one is driven
   by the actual socket. */
.sync {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.82rem; color: var(--ink-faint);
  white-space: nowrap;
}
.sync .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--ink-faint); }
.sync.live .dot { background: var(--ok); }
.sync.live { color: var(--ok); }
.sync.off .dot { background: var(--bad); }
.sync.off { color: var(--bad); }
.sync.pending .dot { background: var(--warn); }
.sync.pending { color: var(--warn); }

.body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 15rem;
  flex: 0 0 auto;
  border-right: 1px solid var(--rule);
  background: var(--chrome);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
}

.sidebar.hidden { display: none; }

.note-list { list-style: none; margin: 0; padding: 0; flex: 1; }

.note-list li {
  padding: 0.5rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-list li:hover { background: var(--raised); color: var(--ink); }
.note-list li.active { background: var(--raised); color: var(--ink); font-weight: 600; }
.note-list li .when { display: block; font-size: 0.75rem; color: var(--ink-faint); font-weight: 400; }

.device { border-top: 1px solid var(--rule); padding-top: 0.7rem; }
.device-label { font-size: 0.75rem; color: var(--ink-faint); margin-bottom: 0.25rem; }
.fp {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
  word-break: break-all;
  line-height: 1.35;
}

/* The page is paper, and paper does not follow the system dark theme.
 *
 * This used to be `var(--paper)`, which goes near-black in dark mode — and
 * with near-black default ink on top, the canvas rendered as an empty black
 * rectangle. Dark mode applies to the chrome around the page, not the page. */
.canvas-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  background: #fbfaf7;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* The pen must never scroll or zoom the page while drawing. */
  touch-action: none;
  cursor: crosshair;
}

.empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
  color: var(--ink-faint);
  font-size: 0.95rem;
}

kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05em 0.35em;
}

/* --- tools --- */

.tools {
  height: var(--tools-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  padding: 0 0.9rem;
  background: var(--chrome);
  border-top: 1px solid var(--rule);
  overflow-x: auto;
}

.group { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.group.grow { flex: 1; }

.tiny { font-size: 0.75rem; color: var(--ink-faint); margin: 0; }

.tool {
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 7px;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.tool[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.swatch {
  width: 1.6rem; height: 1.6rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); }

select {
  border: 1px solid var(--rule);
  background: var(--raised);
  border-radius: 7px;
  padding: 0.28rem 0.5rem;
  font-size: 0.85rem;
}

@media (max-width: 46rem) {
  .sidebar { position: absolute; z-index: 5; height: calc(100% - var(--bar-h) - var(--tools-h)); }
  .bar-right .ghost { display: none; }
}

/* --- folder tree ---------------------------------------------------------
 *
 * Folder and note names come out of the encrypted library note, so everything
 * here is inserted with textContent rather than innerHTML. */

.side-actions { display: grid; gap: 0.4rem; }

.tree { flex: 1; overflow-y: auto; margin: 0.2rem -0.2rem; }

.folder { margin-bottom: 0.15rem; }

.folder-row, .note-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.36rem 0.5rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink-soft);
  user-select: none;
}

.folder-row:hover, .note-row:hover { background: var(--raised); color: var(--ink); }
.note-row.active { background: var(--raised); color: var(--ink); font-weight: 600; }

.folder-row { font-weight: 600; color: var(--ink); }

.twisty {
  width: 0.9rem;
  flex: 0 0 auto;
  font-size: 0.7rem;
  color: var(--ink-faint);
  transition: transform 0.12s;
}
.folder.collapsed .twisty { transform: rotate(-90deg); }
.folder.collapsed .folder-notes { display: none; }

.folder-notes { padding-left: 0.9rem; }

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

.row-menu {
  opacity: 0;
  border: 0;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0 0.2rem;
  font-size: 0.95rem;
  line-height: 1;
}
.folder-row:hover .row-menu, .note-row:hover .row-menu { opacity: 1; }
.row-menu:hover { color: var(--ink); }

.note-row .when { font-size: 0.72rem; color: var(--ink-faint); font-weight: 400; }

.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* --- extra tool controls --- */

input[type="color"] {
  width: 2rem;
  height: 1.8rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

input[type="range"] {
  width: 6.5rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.num { min-width: 2.6rem; text-align: right; font-variant-numeric: tabular-nums; }

.hint { color: var(--ink-faint); font-style: italic; }

/* A white swatch needs a visible edge on a white page. */
.swatch { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16); }

/* --- busy overlay, for PDF rendering --- */

.busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(251, 250, 247, 0.72);
  pointer-events: none;
}

.busy span {
  width: 2rem; height: 2rem;
  border: 3px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .busy span { animation: none; }
}
