/* Journal, part 2 of 4 — the record reader and the editor dialog:
   photos, metadata, toolbar and the writing surface. */
.field,
.form-footer button {
  font-size: 14px;
}
.optional {
  font-size: 13px;
}
.form-footer {
  justify-content: space-between;
  align-items: flex-end;
}
.save-hint {
  margin: 0;
  flex: 1;
  min-width: 0;
  padding-right: 16px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--label-3);
}
.form-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
/* The editor is a sheet over the page's column (see records.css): a bar
   with back and the title, the writing area, and the save row at the
   bottom. Only the writing area scrolls. */
#editor.journal-editor { overflow: hidden; }
#editor.journal-editor > form {
  display: flex;
  flex-direction: column;
  width: 100%;
  block-size: 100%;
  min-block-size: 0;
  margin: 0;
}
/* Like the reader's bar (records.css): the header's place, edge to edge. */
#editor.journal-editor .dialog-heading {
  flex: none;
  justify-content: flex-start;
  gap: 8px;
  height: var(--header-h);
  margin: 0;
  padding: 0 var(--sheet-gutter);
  border-bottom: 1px solid var(--separator);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
}
#editor.journal-editor > form > :not(.dialog-heading) { margin-inline: var(--sheet-gutter); }
#editor.journal-editor .editor-heading-copy { display: flex; flex: 1; align-items: baseline; gap: 12px; min-width: 0; }
#editor.journal-editor #editor-title { margin: 0; color: var(--label); font: 600 15px/1.4 var(--font); letter-spacing: 0; }
#editor.journal-editor .editor-thread { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#editor.journal-editor #content-panel {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#editor.journal-editor .form-footer {
  flex: 0 0 auto;
  position: static;
  align-items: center;
  margin: 0;
  padding: 12px 0 16px;
}
.body-input { margin-top: 6px; border: 1px solid var(--separator); border-radius: 8px; background: var(--surface); overflow: hidden; }
.body-input:focus-within { outline: 2px solid #a0b595; outline-offset: 1px; }
#body-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--separator); background: #fafaf5; }
#body-toolbar button, .body-link-actions button { border: 0; border-radius: 4px; padding: 5px 8px; min-height: 34px; background: transparent; color: var(--label-3); font-size: 12px; }
#body-toolbar button:hover, #body-toolbar button[aria-pressed="true"], .body-link-actions button:hover { background: #e9eee5; color: var(--accent); }
#body-toolbar button:disabled { cursor: default; }
#body-editor .tiptap { padding: 12px 14px; min-height: 210px; outline: none; font-size: 15px; font-weight: 400; line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; }
#body-editor .tiptap > p:only-child:has(> br.ProseMirror-trailingBreak:only-child)::before { content: '今天发生了什么？或者，只留下一句话。'; color: #959d93; pointer-events: none; float: left; height: 0; }
.body-input #content { border: 0; border-radius: 0; margin: 0; outline: none; line-height: 1.6; }
.body-link-panel { padding: 10px 14px; border-bottom: 1px solid var(--separator); background: #fafaf5; }
.body-link-actions { display: flex; gap: 4px; margin-top: 6px; }
.body-link-panel .error { margin: 6px 0 0; }
#body-editor p, #story-content.formatted-body p { margin: 0 0 .45em; }
#body-editor h2, #body-editor h3, #story-content.formatted-body h2, #story-content.formatted-body h3 { margin: 1em 0 .5em; font-size: 20px; line-height: 1.5; font-weight: 600; }
#body-editor h3, #story-content.formatted-body h3 { font-size: 18px; }
#body-editor h1, #story-content.formatted-body h1 { margin: 1em 0 .5em; font-size: 24px; line-height: 1.5; font-weight: 600; }
#body-editor blockquote, #story-content.formatted-body blockquote { margin: .8em 0; padding-left: 16px; border-left: 3px solid #becdbb; color: var(--label-3); }
#body-editor ul, #body-editor ol, #story-content.formatted-body ul, #story-content.formatted-body ol { margin: .8em 0; padding-left: 1.7em; }
#body-editor li > p, #story-content.formatted-body li > p { margin-bottom: .25em; }
#body-editor table, #story-content.formatted-body table { width: 100%; margin: 1em 0; border-collapse: collapse; table-layout: fixed; font-size: .95em; }
#body-editor th, #body-editor td, #story-content.formatted-body th, #story-content.formatted-body td { padding: 8px 10px; border: 1px solid var(--separator); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
#body-editor th, #story-content.formatted-body th { background: #f3f5ef; font-weight: 600; }
#body-editor th > p, #body-editor td > p, #story-content.formatted-body th > p, #story-content.formatted-body td > p { margin: 0; }
#body-editor a, #story-content.formatted-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.story-paper #story-content.formatted-body { white-space: normal; }
#story-content.formatted-body p, #story-content.formatted-body h1, #story-content.formatted-body h2, #story-content.formatted-body h3 { white-space: pre-wrap; }
#body-editor .tiptap > :first-child, #story-content.formatted-body > :first-child { margin-top: 0; }
#body-editor .tiptap > :last-child, #story-content.formatted-body > :last-child { margin-bottom: 0; }
.body-math-display { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--label-3); }
.body-math-display input { width: auto; margin: 0; }
#body-math-source { font-family: ui-monospace, monospace; font-size: 13px; }
.tiptap-mathematics-render, .body-math { white-space: normal; }
.tiptap-mathematics-render--editable { cursor: pointer; border-radius: 4px; }
.tiptap-mathematics-render--editable:hover, .tiptap-mathematics-render.ProseMirror-selectednode { background: #edf2e8; outline: 1px solid #bacab2; }
[data-type="block-math"] { margin: .8em 0; max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 4px 0; scrollbar-width: none; }
[data-type="block-math"]::-webkit-scrollbar { display: none; }
[data-type="block-math"] .katex-display { margin: .4em 0; }
.body-math[data-type="inline-math"] { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; scrollbar-width: none; }
.body-math[data-type="inline-math"]::-webkit-scrollbar { display: none; }
@keyframes journal-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@media (max-width: 700px) {
  .site-header {
    gap: 12px;
    flex-wrap: wrap;
  }
  .header-controls {
    gap: 12px;
  }
  main {
    padding: 0 20px 40px;
  }
  .journal {
    padding-top: 0;
  }
}

html { scrollbar-gutter: stable; }
@media (max-width: 520px) {
  .site-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .header-controls {
    width: 100%;
    gap: 12px;
  }
  .site-header .primary {
    padding: 8px 12px;
  }
  .search-panel {
    position: fixed;
    top: 72px;
    right: 20px;
    left: 20px;
    width: auto;
  }
}
@media (max-width: 390px) {
  .header-controls {
    gap: 6px;
  }
  .header-search,
  .search-toggle {
    width: 36px;
    height: 36px;
  }
  .header-search {
    flex-basis: 36px;
  }
  .site-header .primary {
    min-height: 36px;
    padding: 5px 8px;
    font-size: 13px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .search-panel,
  .header-search.is-open .search-panel {
    transition: none;
  }
}

#lightbox[open] { display: block; }
#lightbox #photo-stage { position: absolute; inset: calc(60px + env(safe-area-inset-top)) 80px calc(52px + env(safe-area-inset-bottom)); overflow: hidden; touch-action: none; cursor: zoom-in; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; line-height: 0; }
#lightbox:has(#previous-photo[hidden]) #photo-stage { inset-inline: 24px; }
#lightbox #photo-stage.is-zoomed { cursor: grab; }
#lightbox #photo-stage.is-zoomed:active { cursor: grabbing; }
#lightbox #full-image { transform-origin: 0 0; will-change: transform; }
#lightbox #photo-position { position: absolute; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); translate: -50% 0; color: rgb(255 255 255 / 72%); font-size: 13px; font-variant-numeric: tabular-nums; }
#lightbox button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.photo-nav { position: absolute; z-index: 2; top: 50%; translate: 0 -50%; display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 0; border-radius: 50%; background: rgb(255 255 255 / 12%); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; transition: background-color .15s ease; }
.photo-nav:hover { background: rgb(255 255 255 / 24%); }
.photo-nav[hidden] { display: none; }
#previous-photo { left: 16px; }
#next-photo { right: 16px; }
/* Phones: the photo uses the full width; the arrows sit below it, beside
   the count (a sideways swipe turns the photo too). */
@media (max-width: 640px) {
  #lightbox #photo-stage, #lightbox:has(#previous-photo[hidden]) #photo-stage { inset: calc(60px + env(safe-area-inset-top)) 0 calc(68px + env(safe-area-inset-bottom)); }
  .photo-nav { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); translate: none; width: 44px; height: 44px; }
  #previous-photo { left: 14px; }
  #next-photo { right: 14px; }
  #lightbox #photo-position { bottom: calc(24px + env(safe-area-inset-bottom)); }
}

.record-loading[hidden] { display: none; }
.record-loading .story-panel-heading { gap: 12px; }
#record-status { flex: 1; font-size: 14px; color: var(--label-3); }
.record-loading .story-panel-heading #retry-record { border: 1px solid var(--separator); font-size: 14px; }
.record-placeholder > span { display: block; background: var(--separator); border-radius: 4px; height: 12px; margin-bottom: 16px; opacity: 0.45; }
.record-placeholder .placeholder-date { width: 110px; margin-bottom: 28px; }
.record-placeholder .placeholder-title { width: 52%; height: 25px; margin-bottom: 32px; }
.record-placeholder .placeholder-line { width: 100%; }
.record-placeholder .placeholder-short { width: 70%; }
.record-placeholder .placeholder-gap { margin-top: 32px; }

/* Journal metadata stays optional and compact, alongside the record. */
.record-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.record-tags[hidden] { display: none; }
.record-tag { border: 1px solid var(--separator); border-radius: 14px; background: transparent; color: var(--accent); padding: 3px 9px; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.record-tag:hover { background: var(--bg); }
.entry-author { display: inline-flex; align-items: center; gap: 5px; margin-right: 10px; color: var(--label); }
.entry-author-avatar { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; background: #e9eee8; }
.editor-tag-panel { padding: 10px 12px; border-top: 1px solid var(--separator); background: #fffefa; }
.editor-tag-panel[hidden] { display: none; }
.editor-tag-panel .record-tags { margin-bottom: 8px; }
.tag-input-row { display: flex; align-items: stretch; gap: 8px; }
.tag-input-row input { flex: 1; min-width: 0; width: 100%; }
#add-tag { flex: 0 0 40px; padding: 0; }
#tag-suggestions { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
#tag-suggestions[hidden] { display: none; }
#tag-error { margin-top: 6px; }
#filter-chip-tag { flex-wrap: wrap; max-width: 100%; }
.filter-tag-operator { border-left: 1px solid var(--separator); padding: 3px 5px; color: var(--label-3); }
.filter-tag-value { background: transparent; color: var(--accent); border: 0; border-left: 1px solid var(--separator); font-size: 12px; padding: 4px 6px; }
#filter-tag { max-width: 145px; }
#tag-manager { width: min(540px, calc(100vw - 32px)); padding: 24px; }
#tag-manager-search { width: 100%; }
#tag-manager-status { color: var(--label-3); font-size: 13px; }
#tag-manager-status:empty { display: none; }
.managed-tag { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.managed-tag input { flex: 1; min-width: 0; width: 100%; }
.managed-tag button { flex-shrink: 0; }
.tag-usage { flex-shrink: 0; color: var(--label-3); font-size: 12px; }
@media (max-width: 520px) {
  #tag-manager { padding: 18px; }
  .managed-tag { flex-wrap: wrap; gap: 8px; }
  .managed-tag input { flex-basis: calc(100% - 60px); }
}

/* Focus the journal flow on one writing surface. The date and title stay in
   the form as data fields; the title is projected from the first body line. */
#editor.journal-editor .body-field { margin-top: 0; }
#editor.journal-editor .body-input { margin-top: 0; border-radius: 10px; }
#editor.journal-editor #body-editor .tiptap { min-height: max(310px, calc(100dvh - var(--header-h) - 186px)); padding: 20px 18px; font-size: 16px; line-height: 1.75; }
#editor.journal-editor #content { min-height: max(310px, calc(100dvh - var(--header-h) - 186px)); padding: 20px 18px; font-size: 16px; line-height: 1.75; }
/* Toolbar: icon buttons in small groups, with tags and photos on the right.
   It stays visible while a long record scrolls inside the dialog. */
#editor.journal-editor .body-input { overflow: clip; }
#editor.journal-editor #body-toolbar { position: sticky; top: 0; z-index: 2; align-items: center; gap: 4px 0; padding: 6px 8px; }
.toolbar-group { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.toolbar-group + .toolbar-group { margin-left: 6px; padding-left: 6px; border-left: 1px solid var(--separator); }
#body-toolbar .toolbar-attachments { gap: 6px; margin-left: auto; padding-left: 10px; border-left: 0; }
#editor.journal-editor #body-toolbar [data-body-command] { display: inline-flex; align-items: center; justify-content: center; width: 34px; min-height: 34px; padding: 0; border-radius: 6px; color: #4f5a51; }
#body-toolbar svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#body-toolbar svg .dot { fill: currentColor; stroke: none; }
#body-toolbar [data-body-command="bold"] svg { stroke-width: 2.4; }
#editor.journal-editor #body-toolbar button:disabled { opacity: 0.3; }
#body-toolbar .toolbar-tags-button, #body-toolbar .toolbar-photo-button { display: inline-flex; align-items: center; gap: 5px; margin-left: 0; padding: 5px 10px; border: 1px solid var(--separator); border-radius: 6px; color: var(--accent); font-size: 12px; }
#body-toolbar .toolbar-tags-button svg, #body-toolbar .toolbar-photo-button svg { width: 15px; height: 15px; }
#editor.journal-editor .save-hint { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.save-shortcut { font: inherit; color: #959d93; white-space: nowrap; }
@media (hover: none), (max-width: 520px) { .save-shortcut { display: none; } }
/* The content panel owns the long-record scroll, so the footer never covers
   the last line or the bottom of an inline image. */
#editor.journal-editor .form-footer { z-index: 2; background: var(--bg); }
.toolbar-photo-button {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-left: auto;
  padding: 5px 9px;
  border: 1px solid var(--separator);
  border-radius: 5px;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.toolbar-photo-button:hover { background: #e9eee5; }
.toolbar-photo-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar-photo-button input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.toolbar-tags-button { min-height: 34px; padding: 5px 9px; border: 1px solid var(--separator); border-radius: 5px; background: transparent; color: var(--accent); font-size: 12px; cursor: pointer; white-space: nowrap; }
.toolbar-tags-button:hover, .toolbar-tags-button[aria-expanded='true'] { background: #e9eee5; }
.body-image { display: block; max-width: min(100%, 620px); max-height: 520px; margin: 14px auto; border-radius: 8px; object-fit: contain; box-shadow: 0 4px 16px #29262214; cursor: zoom-in; user-select: none; }
.body-image:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.body-image-link { display: block; max-width: 100%; }
.body-image-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }
.body-image-link.is-missing { display: inline; overflow-wrap: anywhere; }
#editor.journal-editor [data-journal-image] {
  display: block;
  inline-size: auto;
  max-inline-size: 100%;
  block-size: auto;
  max-block-size: min(520px, 50dvh);
  margin: 14px auto;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 4px 16px #29262214;
}
@media (max-width: 520px) {
  #editor.journal-editor #body-editor .tiptap,
  #editor.journal-editor #content { min-height: max(250px, calc(100dvh - 250px)); padding: 16px 14px; }
  .toolbar-group + .toolbar-group { margin-left: 8px; padding-left: 0; border-left: 0; }
  #editor.journal-editor #body-toolbar [data-body-command] { width: 32px; }
}

@media (max-width: 760px) {
  #editor.journal-editor > form { padding: 0 12px env(safe-area-inset-bottom); }
  #editor.journal-editor .dialog-heading { height: 52px; margin: 0 -12px; padding: 0 12px 0 4px; }
}
