/* Notes: toolbar, label filter and the card grid. */
.view-notes {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.notes-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

#notes-search {
  flex: 1;
  min-width: 10rem;
  max-width: 28rem;
}

/* "Take a note..." bar, as at the top of Keep. */
.note-composer {
  align-self: center;
  display: flex;
  align-items: center;
  width: min(36rem, 100%);
  padding: 0.2rem 0.4rem 0.2rem 0;
  border-radius: 14px;
  background-color: var(--surface);
  box-shadow: var(--pressed);
}

.note-composer-text {
  flex: 1;
  padding: 0.55rem 1rem;
  border: none;
  background: none;
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  cursor: text;
}

.note-composer-text:hover {
  background: none;
}

.icon {
  display: inline-flex;
  vertical-align: middle;
}

button.icon-button:has(.icon) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 50%;
  flex: none;
}

/* Note colours (cards, the editor and its swatches). */
[data-color="default"] { --note-bg: var(--note-default); }
[data-color="red"] { --note-bg: var(--note-red); }
[data-color="orange"] { --note-bg: var(--note-orange); }
[data-color="yellow"] { --note-bg: var(--note-yellow); }
[data-color="green"] { --note-bg: var(--note-green); }
[data-color="teal"] { --note-bg: var(--note-teal); }
[data-color="blue"] { --note-bg: var(--note-blue); }
[data-color="purple"] { --note-bg: var(--note-purple); }

#note-panel-colors .swatch {
  --swatch: var(--note-bg);
}

/* Masonry-style columns, like Keep. */
.notes-grid {
  columns: 16rem;
  column-gap: 1.4rem;
}

.notes-grid .empty-state {
  column-span: all;
}

/* Each note is a raised piece of surface in its own tint. */
.note-card {
  position: relative;
  break-inside: avoid;
  margin-bottom: 1.4rem;
  padding: 0.85rem 0.95rem;
  border-radius: 18px;
  background-color: var(--note-bg, var(--surface));
  box-shadow: 7px 7px 16px var(--shadow-dark), -7px -7px 16px var(--shadow-light);
  cursor: pointer;
  overflow: hidden;
}

.note-card:hover {
  box-shadow: 9px 9px 20px var(--shadow-dark), -9px -9px 20px var(--shadow-light);
}

.note-card-title {
  margin: 0 1.8rem 0.4rem 0;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.note-card-text {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Long notes are cut short on the card and fade out; the editor shows them in full. */
.note-card-text.long {
  max-height: 21rem;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent);
  mask-image: linear-gradient(to bottom, #000 75%, transparent);
}

.note-card-title + .note-card-text:empty {
  display: none;
}

/* ---------- Formatted (Markdown) note text, on cards and in the editor's preview ---------- */
.md {
  line-height: 1.45;
}

.md > :first-child,
.note-card-text.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }

.md p,
.md ul,
.md ol,
.md blockquote,
.md pre,
.md table {
  margin: 0 0 0.6em;
}

/* Headings: each level clearly smaller than the one above. H1 and H2 are underlined to start
   sections, H3 and H4 are bold, H5 is small capitals and H6 a quiet label. */
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 1.4em 0 0.5em;
  line-height: 1.25;
  font-weight: 700;
  color: var(--text-main);
}

.md h1 {
  font-size: 1.9em;
  padding-bottom: 0.25em;
  border-bottom: 2px solid var(--border);
}

.md h2 {
  font-size: 1.5em;
  padding-bottom: 0.2em;
  border-bottom: 1px solid var(--border-soft);
}

.md h3 { font-size: 1.25em; }
.md h4 { font-size: 1.08em; }

.md h5 {
  font-size: 0.85em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.md h6 {
  font-size: 0.85em;
  font-weight: 600;
  color: var(--text-muted);
}

/* Smaller on cards, but still in the same steps. */
.note-card-text.md h1 { font-size: 1.45em; }
.note-card-text.md h2 { font-size: 1.25em; }
.note-card-text.md h3 { font-size: 1.1em; }
.note-card-text.md h4 { font-size: 1em; }
.note-card-text.md h1,
.note-card-text.md h2,
.note-card-text.md h3,
.note-card-text.md h4,
.note-card-text.md h5,
.note-card-text.md h6 {
  margin-top: 0.9em;
}

.md ul,
.md ol {
  padding-left: 1.4em;
}

.md li > ul,
.md li > ol {
  margin: 0.15em 0 0;
}

.md li.md-task {
  list-style: none;
  margin-left: -1.3em;
}

.md li.md-task input {
  margin: 0 0.4em 0 0;
  vertical-align: middle;
}

.md li.md-task.done {
  color: var(--text-muted);
  text-decoration: line-through;
}

.md blockquote {
  padding-left: 0.8em;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.md code {
  padding: 0.05em 0.3em;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background-color: var(--code-bg);
}

.md pre {
  padding: 0.6em 0.75em;
  border-radius: 6px;
  overflow-x: auto;
  background-color: var(--code-bg);
}

.md pre code {
  padding: 0;
  background: none;
  white-space: pre;
  font-size: 0.85em;
}

/* The language of a labelled code block, in its corner. */
.md pre[data-language] {
  position: relative;
}

.md pre[data-language]::before {
  content: attr(data-language);
  position: absolute;
  top: 0.25em;
  right: 0.5em;
  font-size: 0.7em;
  color: var(--text-muted);
}

/* Code colouring (highlight.js classes); the colours are in the theme files. */
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-template-tag, .hljs-type { color: var(--code-keyword); }
.hljs-string, .hljs-regexp, .hljs-meta .hljs-string, .hljs-char.escape_ { color: var(--code-string); }
.hljs-number, .hljs-literal, .hljs-built_in, .hljs-symbol, .hljs-variable.constant_, .hljs-operator { color: var(--code-number); }
.hljs-comment, .hljs-quote, .hljs-meta { color: var(--code-comment); }
.hljs-comment, .hljs-quote { font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-title.class_, .hljs-section { color: var(--code-title); }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-variable, .hljs-params, .hljs-selector-class, .hljs-selector-id { color: var(--code-attr); }
.hljs-name, .hljs-tag, .hljs-selector-pseudo, .hljs-bullet { color: var(--code-tag); }
.hljs-addition { color: var(--code-added); background-color: var(--code-added-bg); }
.hljs-deletion { color: var(--code-removed); background-color: var(--code-removed-bg); }
.hljs-strong { font-weight: bold; }
.hljs-emphasis { font-style: italic; }

/* Tables */
.md table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin: 0 0 0.6em;
  border-collapse: collapse;
}

.md th,
.md td {
  padding: 0.3em 0.65em;
  border: 1px solid var(--border);
  text-align: left;
}

.md th {
  background-color: var(--overlay-soft);
}

.md img {
  max-width: 100%;
  height: auto;
}

.md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}

.md a {
  color: var(--btn-primary-strong);
  overflow-wrap: anywhere;
}

.note-card-items {
  list-style: none;
  margin: 0;
  padding: 0;
}

.note-card-items li {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  overflow-wrap: anywhere;
}

.note-card-items li.done span,
.note-item.done input[type="text"] {
  text-decoration: line-through;
  color: var(--text-muted);
}

.note-card-more {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.note-card-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.6rem;
}

.note-due {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.chip.small .icon {
  margin-right: 0.25rem;
}

/* Pin: filled when the note is on the home; on cards it appears on hover/focus when off. */
.note-pin,
.note-pin-toggle {
  color: var(--text-muted);
  opacity: 0.55;
}

.note-pin[aria-pressed="true"],
.note-pin-toggle[aria-pressed="true"] {
  color: var(--text-main);
  opacity: 1;
}

.note-pin {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  display: inline-flex;
  padding: 0.3rem;
  border: none;
  border-radius: 50%;
  background: transparent;
}

.note-pin[aria-pressed="false"] {
  opacity: 0;
}

.note-card:hover .note-pin,
.note-card:focus-within .note-pin,
.note-pin:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .note-pin[aria-pressed="false"] {
    opacity: 0.45;
  }
}

/* ---------- Editor ---------- */
/* An open note takes the whole screen. Without side by side, its contents sit in a readable
   column in the middle (--note-pad); side by side, the two halves use the full width. */
.note-dialog {
  --note-pad: max(1.25rem, calc((100vw - 60rem) / 2));
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 0;
  background-color: var(--note-bg, var(--bg-card));
  overflow: visible;
}

.note-dialog.split {
  --note-pad: 2rem;
}

.note-dialog form {
  box-sizing: border-box;
  height: 100%;
  padding-inline: var(--note-pad);
}

/* The note text (and its preview) fill the editor's free space. */
.note-body {
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
}

.note-body > #note-text,
.note-body > #note-code,
.note-body > #note-preview {
  flex: 1 0 auto;
}

/* The code editor (CodeMirror) for the note text; it fills the space like the text box did. */
#note-code {
  display: flex;
  flex-direction: column;
  min-height: 2rem;
  cursor: text;
}

#note-code[hidden] {
  display: none;
}

#note-code .cm-editor {
  flex: 1 0 auto;
}

/* Side by side: what's typed on the left, formatted on the right. Each half scrolls on its own
   (the preview follows the text). */
.note-body.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 2rem;
}

.note-dialog form > .note-body.split {
  flex: 1 1 0;
  min-height: 12rem;
}

#note-body.split > #note-text,
#note-body.split > #note-preview {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

/* Side by side, the code editor scrolls inside its half. */
#note-body.split > #note-code {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

#note-body.split > #note-code .cm-editor {
  height: 100%;
}

.note-body.split > #note-preview {
  padding-left: 2rem;
  border-left: 1px solid var(--border-soft);
}

/* Formatting toolbar above the note text, with Preview / Edit at its end. */
.note-format {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 -0.3rem;
}

.note-format[hidden],
.note-format-tools[hidden] {
  display: none;
}

.note-format-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}

.note-format-tools button,
.note-preview-toggle {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.45rem;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.note-format-tools button:hover,
.note-preview-toggle:hover {
  background-color: var(--overlay-soft);
  color: var(--text-main);
}

.note-preview-toggle {
  margin-left: auto;
  font-weight: 600;
}

.note-preview {
  min-height: 2rem;
  padding: 0.15rem 0;
  overflow-wrap: anywhere;
  cursor: text;
}

.note-dialog form {
  overflow-y: auto;
  gap: 0.6rem;
  padding-bottom: 0;
}

/* Long notes scroll the whole form rather than being squeezed into it. */
.note-dialog form > * {
  flex-shrink: 0;
}

/* Title, text and entries are typed straight onto the note, without boxes. */
.note-dialog #note-title,
.note-dialog #note-text,
.note-item-main input[type="text"] {
  border: none;
  border-radius: 0;
  padding: 0.15rem 0;
  background: transparent;
  outline: none;
}

.note-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#note-title {
  flex: 1;
  min-width: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

/* The text grows with what's typed; the form scrolls, so long notes have no inner scrollbar. */
.dialog #note-text {
  min-height: 2rem;
  resize: none;
  overflow: hidden;
  line-height: 1.45;
}

.note-items {
  display: flex;
  flex-direction: column;
}

.note-item {
  border-top: 1px solid transparent;
  border-bottom: 1px solid transparent;
}

.note-item:focus-within {
  border-color: var(--border-soft);
}

.note-item-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.note-item-main input[type="text"] {
  flex: 1;
  min-width: 0;
}

.note-item.done input[type="text"] {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Per-entry buttons stay out of the way until the entry is hovered or focused. */
.note-item-main button.icon-button {
  width: 1.7rem;
  height: 1.7rem;
  opacity: 0;
}

.note-item:hover .icon-button,
.note-item:focus-within .icon-button,
.note-item-calendar[aria-pressed="true"] {
  opacity: 1;
}

.note-item-calendar[aria-pressed="true"] {
  color: var(--btn-primary-strong);
  background-color: var(--overlay-soft);
}

@media (hover: none) {
  .note-item-main button.icon-button {
    opacity: 0.6;
  }
}

.note-item-when,
.note-when {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.note-item-when {
  padding: 0 0 0.35rem 1.7rem;
}

.note-item-when input,
.note-item-when select,
.note-when input,
.note-when select {
  padding: 0.1rem 0.35rem;
  font-size: 0.85rem;
  color: var(--text-main);
  background-color: var(--overlay-soft);
}

.note-add-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0;
  border: none;
  background: none;
  color: var(--text-muted);
  text-align: left;
}

.note-add-item:hover {
  background: none;
  color: var(--text-main);
}

.note-done-divider {
  margin-top: 0.4rem;
  padding: 0.4rem 0 0.2rem;
  border-top: 1px solid var(--border-soft);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.note-dialog .note-card-labels:empty {
  display: none;
}

.note-dialog .note-card-labels {
  margin-top: 0;
}

.note-dialog #note-labels {
  background-color: var(--overlay-soft);
}

/* Bottom bar: colour, labels, options menu ... edited time, Close. */
/* Stays at the bottom of the editor while a long note scrolls under it. */
.note-bar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin: 0.2rem calc(-1 * var(--note-pad)) 0;
  padding: 0.3rem calc(var(--note-pad) - 0.5rem) 0.6rem;
  background-color: var(--note-bg, var(--bg-card));
}

.note-edited {
  flex: 1;
  padding: 0 0.5rem;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  bottom: calc(100% + 0.3rem);
  left: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  min-width: 15rem;
  padding: 0.3rem 0;
  border-radius: 8px;
  background-color: var(--bg-card);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  border: none;
  border-radius: 0;
  background: none;
  text-align: left;
  white-space: nowrap;
}

.menu button:hover {
  background-color: var(--bg-hover);
}

#note-split-toggle[aria-pressed="true"] {
  color: var(--text-main);
  background-color: var(--overlay-soft);
}

/* Done: saves and closes the note. */
.note-done {
  margin-left: 0.4rem;
  padding: 0.35rem 1.1rem;
}
