/* GNote */

:root {
  --bg: #ffffff;
  --bg-sink: #f7f7f5;
  --bg-hover: #ecebe9;
  --text: #32302c;
  --text-dim: #8a8781;
  --line: #e6e4e1;
  --accent: #2f7d6e;
  --accent-soft: #e6f2ef;
  --danger: #b4453a;
  --shadow: 0 6px 24px rgba(15, 15, 15, 0.11), 0 1px 2px rgba(15, 15, 15, 0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  --sidebar-w: 264px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1f1e;
    --bg-sink: #191919;
    --bg-hover: #2f2f2d;
    --text: #e8e6e3;
    --text-dim: #8f8d88;
    --line: #333331;
    --accent: #6fbfa9;
    --accent-soft: #23342f;
    --danger: #e08276;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

/* The UA stylesheet's [hidden] rule is a bare attribute selector, so any
   class or id rule that sets `display` silently outranks it — and everything
   marked hidden shows up anyway. Restate it with the authority it needs. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

input {
  font: inherit;
  color: inherit;
}

kbd {
  font: 11px var(--mono);
  color: var(--text-dim);
  background: var(--bg-hover);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ================================================================== auth */
#auth {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  background: var(--bg-sink);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.auth-logo {
  font-size: 34px;
}
.auth-card h1 {
  margin: 12px 0 4px;
  font-size: 22px;
}
.auth-sub {
  margin: 0 0 22px;
  color: var(--text-dim);
  font-size: 14px;
}

.auth-card label {
  display: block;
  margin-bottom: 14px;
}
.auth-card label span {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.auth-card input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-sink);
}
.auth-card input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: var(--bg);
}

.auth-error:empty {
  display: none;
}
.auth-error {
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 13.5px;
}

.btn-primary {
  width: 100%;
  padding: 10px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:disabled {
  opacity: 0.6;
}

.btn-link {
  display: block;
  width: 100%;
  margin-top: 12px;
  color: var(--text-dim);
  font-size: 13.5px;
  text-align: center;
}
.btn-link:hover {
  color: var(--text);
}

/* =================================================================== app */
#app {
  display: flex;
  height: 100dvh;
}

/* ------------------------------------------------------------- sidebar */
#sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-sink);
  border-right: 1px solid var(--line);
  transition: margin-left 0.18s ease;
}
body.is-collapsed #sidebar {
  margin-left: calc(var(--sidebar-w) * -1);
}

.ws {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 10px;
}
.ws-badge {
  width: 26px;
  height: 26px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.ws-meta {
  min-width: 0;
  flex: 1;
  line-height: 1.25;
}
.ws-meta strong {
  display: block;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-meta small {
  color: var(--text-dim);
  font-size: 12px;
}

.icon-btn {
  padding: 4px 7px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-actions {
  padding: 0 6px 6px;
}
.nav-action {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-dim);
  text-align: left;
}
.nav-action:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.nav-action kbd {
  margin-left: auto;
}

.nav-label {
  padding: 12px 14px 5px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 20px;
}

.nav-row {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.nav-row:hover {
  background: var(--bg-hover);
}
.nav-row.is-active {
  background: var(--bg-hover);
  font-weight: 600;
}

.nav-caret {
  width: 16px;
  flex: none;
  color: var(--text-dim);
  font-size: 10px;
  transition: transform 0.12s ease;
}
.nav-caret.is-open {
  transform: rotate(90deg);
}
.nav-caret.is-leaf {
  visibility: hidden;
}

.nav-icon {
  flex: none;
  font-size: 14px;
}
.nav-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-lock {
  font-size: 10px;
  opacity: 0.6;
}

.nav-add {
  flex: none;
  width: 20px;
  border-radius: 4px;
  color: var(--text-dim);
  opacity: 0;
}
.nav-row:hover .nav-add {
  opacity: 1;
}
.nav-add:hover {
  background: var(--bg);
}

.side-foot {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
}
.side-foot .btn-link {
  margin: 0;
  width: auto;
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- main */
#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
}

.crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13.5px;
  overflow: hidden;
}
.crumb {
  color: var(--text-dim);
  text-decoration: none;
  padding: 2px 5px;
  border-radius: 5px;
  white-space: nowrap;
}
.crumb:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.crumb-sep {
  color: var(--text-dim);
  opacity: 0.5;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pill {
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 20px;
  padding: 2px 9px;
}
.save {
  font-size: 12px;
  color: var(--text-dim);
  transition: opacity 0.2s;
}
.save[data-state='saved'] {
  opacity: 0.45;
}
.save[data-state='error'] {
  color: var(--danger);
  opacity: 1;
}

/* ---------------------------------------------------------------- page */
.page {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 56px 45vh; /* tall tail: clicking below the last line still lands in the page */
}

.page-icon {
  font-size: 52px;
  line-height: 1;
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 4px;
}
.page-icon:hover {
  background: var(--bg-hover);
}

.page-title {
  margin: 0 0 10px;
  font-size: 40px;
  font-weight: 700;
  line-height: 1.2;
  outline: none;
}

[contenteditable][data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  pointer-events: none;
}

/* -------------------------------------------------------------- blocks */
.editor {
  min-height: 60px;
}

.bl {
  position: relative;
}

.bl-row {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  border-radius: 4px;
}

.bl-gutter {
  position: absolute;
  left: -46px;
  top: 1px;
  display: flex;
  gap: 1px;
  opacity: 0;
  transition: opacity 0.1s;
}
.bl:hover > .bl-row > .bl-gutter {
  opacity: 1;
}

.bl-btn {
  width: 20px;
  height: 24px;
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
}
.bl-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.bl-drag {
  cursor: grab;
}

.bl-marker {
  flex: none;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-width: 22px;
  padding-top: 3px;
  color: var(--text-dim);
  user-select: none;
}

.bl-content {
  flex: 1;
  min-width: 0;
  padding: 3px 2px;
  outline: none;
  word-break: break-word;
}
.bl-content code {
  font: 0.88em var(--mono);
  background: var(--bg-hover);
  color: #c7254e;
  border-radius: 4px;
  padding: 1px 5px;
}
@media (prefers-color-scheme: dark) {
  .bl-content code {
    color: #f08d9b;
  }
}
.bl-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bl-kids {
  margin-left: 26px;
}

/* type-specific */
.bl-h1 > .bl-row > .bl-content {
  font-size: 29px;
  font-weight: 700;
  margin-top: 22px;
  line-height: 1.3;
}
.bl-h2 > .bl-row > .bl-content {
  font-size: 23px;
  font-weight: 650;
  margin-top: 17px;
  line-height: 1.3;
}
.bl-h3 > .bl-row > .bl-content {
  font-size: 19px;
  font-weight: 600;
  margin-top: 13px;
  line-height: 1.35;
}

.bl-quote > .bl-row {
  border-left: 3px solid var(--text);
  padding-left: 12px;
  margin: 5px 0;
}

.bl-callout > .bl-row {
  background: var(--accent-soft);
  border-radius: 7px;
  padding: 12px 14px 12px 10px;
  margin: 6px 0;
}

.bl-code > .bl-row > .bl-content {
  font: 13.5px/1.6 var(--mono);
  white-space: pre-wrap;
  background: var(--bg-sink);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px 14px;
  margin: 5px 0;
  tab-size: 2;
}

.bl-todo.is-checked > .bl-row > .bl-content {
  color: var(--text-dim);
  text-decoration: line-through;
}
.bl-marker input[type='checkbox'] {
  width: 15px;
  height: 15px;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
}

.bl-toggle {
  color: var(--text-dim);
  font-size: 11px;
  transition: transform 0.12s ease;
}
.bl-toggle.is-open {
  transform: rotate(90deg);
}

/* --------------------------------------------------- the '***' AI line */
/* Question and answer are deliberately unstyled — they read as ordinary lines
   of the note, because that's what they are. Only a failure is coloured. */
.bl-answer.is-error > .bl-row > .bl-content {
  color: var(--danger);
}

/* Sit the spinner exactly where the answer text will start, instead of centred
   in the 22px marker column — otherwise the line visibly jumps left the moment
   the answer replaces it. */
.bl-answer > .bl-row > .bl-marker {
  min-width: 0;
  justify-content: flex-start;
  padding-top: 4px;
}

/* The frames are swapped in JS. Monospace + a fixed box so the glyph spins on
   the spot instead of jittering as - \ | / change width. */
.bl-spin {
  display: inline-block;
  width: 1ch;
  font: 14px/1.5 var(--mono);
  text-align: center;
  color: var(--text-dim);
  user-select: none;
}

.bl-void {
  flex: 1;
  min-width: 0;
}
.bl-void hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.bl-page {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px;
  border-radius: 5px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.bl-page:hover {
  background: var(--bg-hover);
}
.bl-page-title {
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}

/* --------------------------------------------------------- slash menu */
.slash,
.blockmenu {
  position: absolute;
  z-index: 50;
  display: none;
  min-width: 260px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
}
.slash.is-open,
.blockmenu.is-open {
  display: block;
}

.sl-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  text-align: left;
}
.sl-item.is-active,
.sl-item:hover {
  background: var(--bg-hover);
}
.sl-icon {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13px;
  color: var(--text-dim);
}
.sl-text {
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}
.sl-text b {
  font-size: 14px;
  font-weight: 550;
}
.sl-text small {
  font-size: 12px;
  color: var(--text-dim);
}

.blockmenu {
  min-width: 160px;
}
.blockmenu button {
  display: block;
  width: 100%;
  padding: 6px 9px;
  border-radius: 5px;
  font-size: 14px;
  text-align: left;
}
.blockmenu button:hover {
  background: var(--bg-hover);
}
.blockmenu .is-danger {
  color: var(--danger);
}

/* ----------------------------------------------------------- toolbar */
.toolbar {
  position: absolute;
  z-index: 60;
  display: none;
  gap: 1px;
  transform: translateX(-50%);
  padding: 4px;
  background: #2c2c2b;
  border-radius: 7px;
  box-shadow: var(--shadow);
}
.toolbar.is-open {
  display: flex;
}
.toolbar button {
  min-width: 30px;
  padding: 4px 7px;
  border-radius: 4px;
  color: #eee;
  font-size: 13.5px;
}
.toolbar button:hover {
  background: #454543;
}

/* ------------------------------------------------------------- search */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: start center;
  padding-top: 14vh;
  background: rgba(15, 15, 15, 0.42);
}
.modal-card {
  width: 100%;
  max-width: 580px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}
.search-bar input {
  flex: 1;
  border: 0;
  outline: none;
  background: none;
  font-size: 16px;
}

.search-results {
  max-height: 52vh;
  overflow-y: auto;
  padding: 6px;
}
.hit {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  text-align: left;
}
.hit:hover {
  background: var(--bg-hover);
}
.hit-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}
.hit-body b {
  font-size: 14px;
  font-weight: 550;
}
.hit-body small {
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  padding: 22px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* -------------------------------------------------------------- mobile */
@media (max-width: 760px) {
  #sidebar {
    position: fixed;
    z-index: 20;
    height: 100dvh;
    box-shadow: var(--shadow);
  }
  body:not(.is-collapsed) #sidebar {
    margin-left: 0;
  }
  body.is-collapsed #sidebar {
    margin-left: calc(var(--sidebar-w) * -1);
  }
  .page {
    padding: 24px 20px 40vh;
  }
  .page-title {
    font-size: 31px;
  }
  /* No hover on touch — keep the gutter inside the viewport instead of off it. */
  .bl-gutter {
    display: none;
  }
}
