/* Notes: 自分専用のメモ帳(一覧・エディタ・表示) */

/* 一覧 */

.notes {
  max-width: 860px;
  margin: 32px auto;
  padding: 0 20px;
}

.notes__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.notes__header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.notes__search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.notes__search-field {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--color-surface);
  color: var(--color-text);
}

.notes__search-field:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
}

.notes__search-clear {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--color-muted);
  font-size: 0.85rem;
  white-space: nowrap;
  text-decoration: underline;
}

.notes__search-clear:hover {
  color: var(--color-text);
}

/* 消すものが無いときは出さない。 */
.notes__search:has(.notes__search-field:placeholder-shown) .notes__search-clear {
  display: none;
}

.notes__empty {
  color: var(--color-muted);
  padding: 32px 0;
  text-align: center;
}

.notes__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.notes__item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.notes__item--pinned {
  border-color: var(--color-accent);
}

.notes__item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.notes__item-title {
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.notes__item-title:hover {
  color: var(--color-primary);
}

/* button_to が生成する form が行を崩さないようにする */
.notes__item-head form {
  margin: 0;
  flex: 0 0 auto;
}

.notes__pin {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 4px;
  color: var(--color-accent);
}

.notes__item-excerpt {
  margin: 6px 0 0;
  color: var(--color-muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.notes__item-meta {
  display: block;
  margin-top: 8px;
  color: var(--color-muted);
  font-size: 0.78rem;
}

/* エディタ */

.note-editor {
  max-width: 1280px;
  margin: 24px auto;
  padding: 0 20px;
}

.note-editor__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.note-editor__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.note-editor__actions form {
  margin: 0;
}

.note-editor__link {
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.note-editor__status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-muted);
  white-space: nowrap;
}

.note-editor__status[data-state="dirty"] {
  color: var(--color-accent);
}

.note-editor__status[data-state="saving"] {
  color: var(--color-muted);
}

.note-editor__status[data-state="failed"] {
  color: var(--color-danger);
  font-weight: 600;
}

.note-editor__panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.note-editor__pane {
  min-width: 0;
}

.note-editor__pane--preview {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

@media (max-width: 900px) {
  .note-editor__panes {
    grid-template-columns: minmax(0, 1fr);
  }

  .note-editor__pane--preview {
    position: static;
    max-height: none;
  }
}

/* エディタは画面の高さに合わせて伸ばす(既定の 300px だと書きにくい) */
.note-editor .CodeMirror {
  height: calc(100vh - 200px);
  min-height: 320px;
}

/* プレビューと表示 */

.note-preview,
.note__body {
  overflow-wrap: anywhere;
}

.note-preview__placeholder {
  color: var(--color-muted);
}

.note-preview img,
.note__body img {
  max-width: 100%;
  height: auto;
}

/* 別行立ての数式は横に長くなりやすいので、はみ出す代わりに横スクロールさせる */
.note-preview .katex-display,
.note__body .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
}

.note {
  max-width: 760px;
  margin: 32px auto;
  padding: 0 20px;
}

.note__meta {
  margin: 0 0 8px;
  color: var(--color-muted);
  font-size: 0.85rem;
}

.note__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.note__actions form {
  margin: 0;
}

.note__link {
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.9rem;
}

/* CodeMirror dialog アドオン
   emacs キーマップの M-x と C-s がエディタ内にミニバッファを出すのに使う。
   codemirror@5.65.15 の addon/dialog/dialog.css をそのまま写したもの。
   取り込み方は script/vendor_frontend_libs.mjs を参照。 */

.CodeMirror-dialog {
  position: absolute;
  left: 0; right: 0;
  background: inherit;
  z-index: 15;
  padding: .1em .8em;
  overflow: hidden;
  color: inherit;
}

.CodeMirror-dialog-top {
  border-bottom: 1px solid #eee;
  top: 0;
}

.CodeMirror-dialog-bottom {
  border-top: 1px solid #eee;
  bottom: 0;
}

.CodeMirror-dialog input {
  border: none;
  outline: none;
  background: transparent;
  width: 20em;
  color: inherit;
  font-family: monospace;
}

.CodeMirror-dialog button {
  font-size: 70%;
}
