:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #4f8ff7;
  --accent-soft: #eaf2ff;
  --danger: #cf4d4d;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

/* 全体テーマ（ライト / ダーク） */
body.theme-dark {
  --bg: #0b1220;
  --panel: #111b2d;
  --line: #24324b;
  --text: #e5ecf7;
  --muted: #9aa9c0;
  --accent: #6ea8ff;
  --accent-soft: #1b2c49;
  --danger: #ff8f9e;
  --shadow: 0 6px 22px rgba(2, 7, 20, 0.45);
  color-scheme: dark;
}

body.theme-dark .logo-mark,
body.theme-dark .logo-sub {
  border-color: #2a3d5c;
  background: #142137;
  color: #9ec1ff;
}

body.theme-dark .btn-secondary {
  background: #142239;
  border-color: #2a3e60;
  color: var(--text);
}

body.theme-dark .btn-danger {
  background: #2a1820;
  border-color: #6f3441;
  color: #ff9fb0;
}

body.theme-dark .filter-btn:hover,
body.theme-dark .tag-btn:hover,
body.theme-dark .branch-child-row:hover,
body.theme-dark .new-note-template-choice:hover {
  background: #17263d;
}

body.theme-dark .tag-btn {
  border-color: #2a3e5f;
  background: #16243a;
}

body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea {
  background: #0f1a2b;
  border-color: #2a3a57;
  color: var(--text);
}

body.theme-dark .note-card,
body.theme-dark .related-item,
body.theme-dark .branch-child-row,
body.theme-dark .linkmap-node,
body.theme-dark .mobile-sheet,
body.theme-dark .new-note-dialog,
body.theme-dark .new-note-template-modal,
body.theme-dark .help-dialog,
body.theme-dark .linkmap-modal,
body.theme-dark .ai-util-dialog {
  background: var(--panel);
}

body.theme-dark .note-card.is-active,
body.theme-dark .tab-btn.is-active,
body.theme-dark .filter-btn.is-active,
body.theme-dark .tag-btn.is-active {
  background: #1b2d49;
  border-color: #355888;
  color: #cde0ff;
}

body.theme-dark .type-badge {
  background: #1a2b48;
  border-color: #345b8f;
  color: #c6ddff;
}

body.theme-dark .type-badge--knowledge {
  background: #0f2c26;
  border-color: #1d5e51;
  color: #8ce8cb;
}

body.theme-dark .type-badge--template {
  background: #271f3c;
  border-color: #4f3d82;
  color: #cbb8ff;
}

body.theme-dark .type-badge--draft {
  background: #202b3d;
  border-color: #44536f;
  color: #bdc7d8;
}

body.theme-dark .type-badge--faq {
  background: #362a16;
  border-color: #725626;
  color: #ffd89b;
}

body.theme-dark .inline-note-link {
  background: #1a2f4d;
  color: #bcd5ff;
}

body.theme-dark .inline-note-link.is-disabled {
  background: #1c2635;
  color: #8b9ab0;
}

body.theme-dark .btn-linkmap {
  border-color: #3a5b86;
  background: #1c2f4b;
  color: #c6dcff;
}

body.theme-dark .ai-util-dialog-close,
body.theme-dark .help-dialog-close,
body.theme-dark .new-note-template-close,
body.theme-dark .linkmap-close,
body.theme-dark .mobile-sheet-close {
  background: #142239;
  border-color: #30486c;
  color: #afbdd3;
}

body.theme-dark .linkmap-surface {
  border-color: #2a3c58;
  background: linear-gradient(180deg, #0f1a2d 0%, #14233a 100%);
}

body.theme-dark .linkmap-edge {
  stroke: #3f5f87;
}

body.theme-dark .linkmap-node.is-center {
  background: #1b2f4e;
  border-color: #496da1;
}

body.theme-dark .related-section--subtle .related-item {
  background: #152236;
}

body.theme-dark .dialog-content p,
body.theme-dark .dialog-lead,
body.theme-dark .help-section p,
body.theme-dark .ai-util-dialog-body > p,
body.theme-dark .ai-util-dialog-list,
body.theme-dark .branch-child-row__meta,
body.theme-dark .related-item p,
body.theme-dark .linkmap-header h3,
body.theme-dark .new-note-template-choice__hint {
  color: var(--muted);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
  line-height: 1.65;
}

body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 20px 20px;
}

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

.site-header {
  padding: 14px 18px;
}

.site-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
}

.site-header-brand {
  display: grid;
  gap: 6px;
  min-width: 0;
  flex: 1 1 200px;
}

.site-header-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 1 auto;
}

.site-header-toolbar-pc {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.site-header-toolbar-pc .btn {
  white-space: nowrap;
}

.header-action-menu {
  position: relative;
}

.header-action-menu > summary {
  list-style: none;
  cursor: pointer;
}

.header-action-menu > summary::-webkit-details-marker {
  display: none;
}

.header-action-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, 72vw);
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 30;
}

.header-action-menu-panel .btn {
  width: 100%;
  justify-content: flex-start;
}

.header-action-group {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.header-action-group:first-child {
  border-top: none;
  padding-top: 0;
}

.header-action-group-title {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.site-header-menu-btn {
  display: none;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 0.9rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid #e6eefc;
  background: #f7faff;
  color: #3b6fd6;
}

.logo-image {
  height: 40px;
  width: auto;
  max-width: min(360px, 58vw);
  object-fit: contain;
  display: block;
}

.logo-fallback {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.logo-text {
  font-weight: 700;
  letter-spacing: 0.01em;
}

.logo-sub {
  font-size: 0.82rem;
  color: var(--muted);
  border: 1px solid #e6eefc;
  background: #f7faff;
  border-radius: 999px;
  padding: 2px 10px;
}

.site-tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.site-footer {
  flex-shrink: 0;
  padding: 10px 14px;
  text-align: center;
}

.site-footer-copy {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}

.site-footer-link {
  color: var(--accent);
  text-decoration: none;
}

.site-footer-link:hover {
  text-decoration: underline;
}

.backup-section {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.backup-section h4 {
  margin: 0 0 8px;
}

.snapshot-list {
  display: grid;
  gap: 10px;
}

.snapshot-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.snapshot-item-meta {
  display: grid;
  gap: 2px;
}

.snapshot-item-meta span {
  color: var(--muted);
  font-size: 0.9rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 252px 360px minmax(420px, 1fr);
  gap: 14px;
  padding: 0;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-height: 0;
}

.left-column,
.center-column,
.right-column {
  padding: 16px;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  border-color: #3f7ee0;
  color: #fff;
}

.btn-secondary {
  background: #fff;
}

.btn-danger {
  color: var(--danger);
  background: #fff;
  border-color: #f2d6d6;
}

.btn-plain {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 0;
}

.muted-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.left-section h2 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.left-filter-stack {
  display: grid;
  gap: 8px;
}

.left-filter-stack select {
  width: 100%;
}

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

.filter-btn,
.tag-btn {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}

/* 絞り込み：「メモ」と「知識メモ」が並んだときに一目で区別できるよう色点を付ける */
.filter-list .filter-btn {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-list .filter-btn[data-type-filter="memo"]::before,
.filter-list .filter-btn[data-type-filter="knowledge"]::before {
  content: "";
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.filter-list .filter-btn[data-type-filter="memo"]::before {
  background: #3b82f6;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.28);
}

.filter-list .filter-btn[data-type-filter="knowledge"]::before {
  background: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.28);
}

.filter-btn:hover,
.tag-btn:hover {
  background: #f8fafc;
}

.filter-btn.is-active,
.tag-btn.is-active {
  background: var(--accent-soft);
  border-color: #c7ddff;
  color: #1f4f9f;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-btn {
  width: auto;
  border: 1px solid #e7eef9;
  background: #f8fbff;
  font-size: 0.86rem;
}

.storage-hint {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.storage-hint p {
  margin: 2px 0;
}

.center-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.list-toolbar {
  display: grid;
  gap: 8px;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #b8d0f8;
  border-color: #b8d0f8;
}

.note-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.note-card {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(15, 23, 42, 0.04);
}

.note-bulk-cb {
  margin-top: 10px;
  flex-shrink: 0;
  cursor: pointer;
}

.note-card-inner {
  flex: 1;
  min-width: 0;
}

.note-card.is-active {
  border-color: #bdd7ff;
  background: #f9fbff;
}

.note-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: 999px;
  padding: 2px 9px;
  background: #f2f6ff;
  border: 1px solid #dae6ff;
  color: #335ea7;
  font-size: 0.76rem;
}

/* 分類ごとに色分け（メモ＝青は .type-badge 既定、知識メモは緑系で一覧でも判別しやすく） */
.type-badge--knowledge {
  background: #ecfdf5;
  border-color: #bbf7d0;
  color: #166534;
}

.type-badge--template {
  background: #f5f3ff;
  border-color: #ddd6fe;
  color: #5b21b6;
}

.type-badge--draft {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #475569;
}

.type-badge--faq {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.tag-chip {
  background: #f7f7f8;
  border: 1px solid #ececec;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.75rem;
  color: #4b5563;
}

.card-snippet {
  margin: 8px 0 0;
  color: #4b5563;
  font-size: 0.9rem;
}

.empty-state {
  border: 1px dashed #d5dbe5;
  border-radius: 12px;
  padding: 22px 14px;
  background: #fafcff;
  color: #5b6472;
}

.empty-title {
  margin: 0 0 6px;
  font-weight: 600;
  color: #1f2937;
}

.right-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.tab-row {
  display: flex;
  gap: 8px;
}

.tab-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  background: #fff;
  cursor: pointer;
}

.tab-btn.is-active {
  background: var(--accent-soft);
  border-color: #c9ddff;
  color: #1f4f9f;
}

/* 右カラムは縦 flex のため、ツール行は幅を内容に合わせて右端へ（横長の空帯を出さない） */
.right-column-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  align-self: flex-end;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  background: transparent;
  border: none;
}

.btn-ai-util {
  flex: 0 1 auto;
  min-width: 9.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 9px 16px;
  letter-spacing: 0.02em;
  background: var(--accent-soft);
  border: 1px solid #8eb4f5;
  color: #1a4a9e;
  box-shadow: 0 2px 10px rgba(79, 143, 247, 0.16);
}

.btn-ai-util:hover {
  background: #dfe9ff;
  border-color: var(--accent);
  color: #143d82;
  box-shadow: 0 3px 14px rgba(79, 143, 247, 0.22);
}

.editor-view,
.preview-view {
  overflow: auto;
  display: grid;
  gap: 10px;
  padding-right: 2px;
  /* 子の入力欄が列幅いっぱいに広がるよう、1列グリッドの最小幅を 0 にする */
  grid-template-columns: minmax(0, 1fr);
}

.editor-view[hidden],
.preview-view[hidden] {
  display: none !important;
}

.field-label {
  color: var(--muted);
  font-size: 0.88rem;
}

.field-hint {
  margin: -4px 0 6px;
  color: #94a3b8;
  font-size: 0.82rem;
  line-height: 1.5;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 10px;
}

.field-grid > div {
  min-width: 0;
}

/* PC 編集：本文・タイトルは表示タブと同様に右カラム幅いっぱいに */
.editor-view #note-title-input,
.editor-view #note-content-input,
.editor-view .field-grid select,
.editor-view .field-grid input[type="text"] {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--muted);
  font-size: 0.84rem;
}

.meta-row p {
  margin: 0;
}

textarea {
  min-height: 220px;
  resize: vertical;
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

#save-status-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* 派生メモ（別案）: 控えめな案内ブロック */
.branch-panel {
  border: 1px solid #e8edf5;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fafbfd;
  font-size: 0.86rem;
  color: #475569;
}

.branch-panel--parent {
  margin: 0;
}

.branch-panel__label {
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.02em;
}

.branch-panel__title {
  margin: 0 0 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #64748b;
}

.branch-panel__muted {
  margin: 0;
  color: #94a3b8;
  font-size: 0.84rem;
  line-height: 1.5;
}

.branch-parent-link {
  display: inline-block;
  max-width: 100%;
  text-align: left;
  font-weight: 600;
  color: #1e3a5f;
  padding: 4px 0;
}

.branch-derived-wrap {
  display: grid;
  gap: 10px;
}

.preview-view > .branch-derived-wrap {
  margin-top: 6px;
}

.branch-child-list {
  display: grid;
  gap: 6px;
}

.branch-child-row {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.branch-child-row:hover {
  border-color: #c9d6ec;
  background: #f8fafc;
}

.branch-child-row__title {
  display: block;
  font-weight: 600;
  color: #1e293b;
  font-size: 0.9rem;
}

.branch-child-row__meta {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: #64748b;
}

.note-branch-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  color: #5b6c88;
  background: #eef2f9;
  border: 1px solid #dde5f2;
  vertical-align: middle;
}

.preview-header h2 {
  margin: 0 0 4px;
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.markdown-body {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 1.2em 0 0.5em;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body p,
.markdown-body li {
  margin: 0.5em 0;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1em 0;
}

.markdown-body a {
  color: #2f6ac8;
}

.inline-note-link {
  border: none;
  background: #eef4ff;
  color: #2759a9;
  border-radius: 8px;
  padding: 1px 6px;
  cursor: pointer;
}

.inline-note-link.is-disabled {
  cursor: default;
  color: #8791a1;
  background: #f2f4f8;
}

.related-section {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.related-section h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.related-section--subtle {
  border-top-color: #eef2f7;
  padding-top: 12px;
  margin-top: 6px;
}

.related-section--subtle h3 {
  font-size: 0.95rem;
  color: #64748b;
  font-weight: 600;
}

.related-section--subtle .related-item {
  background: #fbfcfe;
  box-shadow: none;
}

.related-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 8px;
}

.related-heading-row h3 {
  margin: 0;
}

.btn-linkmap {
  flex: 0 0 auto;
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: 999px;
  border: 1px solid #cfe0fb;
  background: #f6f9ff;
  color: #3b5bdb;
  font-weight: 600;
}

.btn-linkmap:hover {
  border-color: #b9d4ff;
  background: #eef4ff;
}

.related-list {
  display: grid;
  gap: 8px;
}

.related-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  cursor: pointer;
}

.related-item p {
  margin: 4px 0 0;
  color: #4b5563;
  font-size: 0.86rem;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 20px 45px rgba(17, 24, 39, 0.18);
}

dialog::backdrop {
  background: rgba(20, 24, 35, 0.25);
}

.dialog-content {
  min-width: 320px;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.dialog-content h3 {
  margin: 0;
}

.dialog-content p {
  margin: 0;
  color: var(--muted);
}

.dialog-actions {
  display: grid;
  gap: 8px;
}

.dialog-lead {
  margin: 0;
  color: var(--muted);
}

.ai-util-dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: #fff;
  box-shadow: 0 20px 45px rgba(17, 24, 39, 0.18);
}

.ai-util-dialog::backdrop {
  background: rgba(20, 24, 35, 0.25);
}

.ai-util-dialog-inner {
  min-width: min(92vw, 340px);
  max-width: 400px;
  padding: 16px 18px 14px;
  display: grid;
  gap: 12px;
}

.ai-util-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-util-dialog-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.ai-util-dialog-close {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.ai-util-dialog-close:hover {
  background: var(--accent-soft);
  border-color: #c9ddff;
  color: #1f4f9f;
}

.ai-util-dialog-body {
  margin: 0;
  padding: 0;
}

.ai-util-dialog-body > p {
  margin: 0;
  font-size: 0.88rem;
  color: #475569;
  line-height: 1.65;
}

.ai-util-dialog-body > p + p {
  margin-top: 0.65em;
}

.ai-util-dialog-note {
  margin-top: 12px !important;
  font-size: 0.78rem !important;
  color: var(--muted) !important;
}

.ai-util-dialog-list {
  margin: 6px 0 0;
  padding-left: 1.15rem;
  font-size: 0.78rem;
  color: #64748b;
  line-height: 1.55;
}

.ai-util-dialog-list li {
  margin: 0.25em 0;
}

.ai-util-dialog-footer-btn {
  justify-self: start;
}

.linkmap-dialog {
  width: min(92vw, 860px);
  max-width: 92vw;
  border: none;
  background: transparent;
  box-shadow: none;
}

.linkmap-dialog::backdrop {
  background: rgba(20, 24, 35, 0.28);
}

.linkmap-modal {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(17, 24, 39, 0.14);
  padding: 14px 14px 12px;
  max-height: min(86vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.linkmap-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.linkmap-header h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  color: #1f2937;
}

.linkmap-lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.linkmap-close {
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.linkmap-close:hover {
  border-color: #d1d5db;
  color: #374151;
}

.linkmap-surface {
  position: relative;
  flex: 1;
  min-height: 280px;
  height: min(52vh, 420px);
  border: 1px solid #eef2f7;
  border-radius: 14px;
  background: linear-gradient(180deg, #fbfcfe 0%, #f8fafc 100%);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.linkmap-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.linkmap-edge {
  stroke: #c5d4e8;
  stroke-width: 1.4;
}

.linkmap-nodes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.linkmap-node {
  position: absolute;
  pointer-events: auto;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  padding: 8px 10px;
  text-align: left;
  cursor: grab;
  display: grid;
  gap: 4px;
  color: #1f2937;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
}

.linkmap-node.is-dragging {
  cursor: grabbing;
  z-index: 2;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.12);
}

.linkmap-node:hover {
  border-color: #d6e6ff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.linkmap-node.is-center {
  background: #f1f6ff;
  border-color: #cfe0fb;
  cursor: grab;
  box-shadow: 0 8px 18px rgba(59, 91, 219, 0.12);
}

.linkmap-node-title {
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.linkmap-node-type {
  justify-self: start;
  font-size: 0.72rem;
}

.linkmap-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 16px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 220px 320px 1fr;
  }
}

@media (max-width: 900px) {
  body {
    padding: 12px 14px 16px;
  }

  .logo-image {
    height: 32px;
  }

  .left-column,
  .center-column,
  .right-column {
    padding: 14px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .linkmap-surface {
    min-height: 240px;
    height: min(48vh, 360px);
  }
}

/* --------------------------------------------------------------------------
   モバイル専用（768px 以下）：タブ切替・1カラム・情報量の抑制
   PC の3カラムはこのブレークポイントより上で維持
   -------------------------------------------------------------------------- */

.mobile-top-tabs,
.mobile-list-actions,
.mobile-search-cta {
  display: none;
}

.mobile-sheet-dialog {
  border: none;
  border-radius: 0;
  padding: 0;
  max-width: 100%;
  width: min(100%, 420px);
  background: transparent;
  box-shadow: none;
}

.mobile-sheet-dialog::backdrop {
  background: rgba(20, 24, 35, 0.32);
}

.mobile-sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 16px 14px;
  display: grid;
  gap: 14px;
  max-height: min(86vh, 640px);
  overflow: auto;
  box-shadow: 0 18px 40px rgba(17, 24, 39, 0.16);
}

.mobile-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.mobile-sheet-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.mobile-sheet-close {
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-sheet-lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.mobile-sheet-subheading {
  margin: 0 0 6px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.mobile-sheet-section {
  padding-bottom: 4px;
  border-bottom: 1px solid #f1f5f9;
}

.mobile-sheet-section:last-of-type {
  border-bottom: none;
}

.mobile-sheet-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
}

.mobile-sheet-actions {
  display: grid;
  gap: 10px;
}

.mobile-menu-hint {
  margin: 0;
  padding-top: 8px;
  border-top: 1px solid #eef2f7;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.mobile-menu-hint p {
  margin: 4px 0 0;
}

.btn-mobile-tool {
  min-height: 44px;
  padding: 10px 14px;
  font-size: 0.9rem;
}

.btn-mobile-compact {
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
}

@media (max-width: 768px) {
  body {
    padding: 10px 12px 28px;
    gap: 10px;
  }

  .site-tagline {
    display: none;
  }

  .site-header {
    padding: 10px 12px;
  }

  .site-header-toolbar-pc {
    display: none;
  }

  .site-header-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
  }

  .left-column {
    display: none !important;
  }

  .mobile-top-tabs {
    display: flex;
    gap: 8px;
    padding: 5px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    flex-shrink: 0;
  }

  .mobile-tab-btn {
    flex: 1;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 12px 10px;
    min-height: 48px;
    font-size: 0.95rem;
    font-weight: 600;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
  }

  .mobile-tab-btn.is-active {
    background: var(--accent-soft);
    border-color: #c9ddff;
    color: #1f4f9f;
  }

  body.app-mobile-tab-search .right-column {
    display: none !important;
  }

  body.app-mobile-tab-write .center-column {
    display: none !important;
  }

  .mobile-list-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
  }

  .mobile-list-actions .btn-mobile-tool {
    flex: 1;
    min-width: 0;
  }

  .mobile-list-actions .btn-ai-util {
    min-width: 0;
    font-size: 0.92rem;
  }

  body.app-mobile-tab-write .mobile-list-actions,
  body.app-mobile-tab-write .mobile-search-cta {
    display: none !important;
  }

  .mobile-search-cta {
    display: block;
  }

  .center-column {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .list-toolbar {
    flex-shrink: 0;
  }

  .note-list {
    flex: 1;
    min-height: 140px;
  }

  .right-column {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .tab-row {
    flex-shrink: 0;
  }

  .right-column-tools {
    flex-shrink: 0;
  }

  .tab-btn {
    padding: 9px 14px;
    min-height: 42px;
    font-size: 0.88rem;
  }

  .editor-view,
  .preview-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: auto;
  }

  .editor-block-title {
    order: 1;
  }

  .editor-block-branch-parent {
    order: 2;
  }

  .editor-block-body {
    order: 3;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .editor-block-fields {
    order: 4;
  }

  .editor-block-meta {
    order: 5;
  }

  .editor-block-footer {
    order: 6;
  }

  .editor-block-branch-derived {
    order: 7;
  }

  .editor-block-related {
    order: 8;
  }

  .editor-block-body .field-hint {
    margin: 0 0 4px;
  }

  #note-content-input {
    min-height: min(52vh, 360px);
    flex: 1;
    resize: vertical;
  }

  .editor-block-branch-derived {
    border: 1px solid #eef2f7;
    border-radius: 12px;
    padding: 10px 12px;
    margin-top: 2px;
    background: #fbfcfe;
  }

  .editor-block-related.related-section--subtle {
    border: 1px solid #eef2f7;
    border-radius: 12px;
    padding: 10px 12px;
    margin-top: 4px;
    background: #fbfcfe;
  }

  .editor-block-related .related-heading-row {
    margin-bottom: 6px;
  }

  .editor-block-related .btn-linkmap {
    font-size: 0.72rem;
    padding: 6px 8px;
  }

  .preview-view .related-section--subtle {
    border: 1px solid #eef2f7;
    border-radius: 12px;
    padding: 10px 12px;
    margin-top: 8px;
  }

  .markdown-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
  }

  .card-snippet {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* --------------------------------------------------------------------------
   新規メモ：ひな形選択（モーダル）
   -------------------------------------------------------------------------- */

.new-note-dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: #fff;
  color: var(--text);
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
  max-width: min(96vw, 440px);
  width: 100%;
}

.new-note-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.new-note-template-modal {
  max-height: min(88vh, 640px);
  overflow: auto;
  display: grid;
  gap: 12px;
  background: #fff;
  color: var(--text);
  border-radius: 16px;
}

.new-note-template-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.new-note-template-header h3 {
  margin: 0;
  font-size: 1.08rem;
  color: #1f2937;
}

.new-note-template-close {
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.new-note-template-lead {
  margin: 0;
}

.new-note-template-list {
  display: grid;
  gap: 8px;
}

.new-note-template-choice {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.new-note-template-choice:hover {
  border-color: #c9d6ec;
  background: #f8fafc;
}

.new-note-template-choice.is-primary-choice {
  border-color: #b9d4ff;
  background: linear-gradient(180deg, #f6f9ff 0%, #fff 100%);
  box-shadow: 0 1px 0 rgba(59, 91, 219, 0.08);
}

.new-note-template-choice__label {
  display: block;
  font-weight: 600;
  color: #1e293b;
  font-size: 0.95rem;
}

.new-note-template-choice__hint {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.45;
}

.new-note-template-footer-btn {
  justify-self: start;
}

/* --------------------------------------------------------------------------
   ヘルプ（機能説明）
   -------------------------------------------------------------------------- */

.help-dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: #fff;
  color: var(--text);
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
  max-width: min(96vw, 560px);
  width: 100%;
}

.help-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.help-dialog-inner {
  max-height: min(92vh, 720px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.help-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.help-dialog-header h3 {
  margin: 0;
  font-size: 1.08rem;
  color: #1f2937;
}

.help-dialog-close {
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.help-dialog-body {
  min-height: 0;
  max-height: min(68vh, 560px);
  overflow-y: auto;
  padding-right: 4px;
  display: grid;
  gap: 18px;
}

.help-section h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e3a5f;
}

.help-section p {
  margin: 0;
  font-size: 0.88rem;
  color: #475569;
  line-height: 1.65;
}

.help-section p + p {
  margin-top: 0.65em;
}

.help-external-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.help-external-link:hover {
  color: #3b7de0;
}

.help-section code {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  font-size: 0.86em;
  padding: 1px 6px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #e2e8f0;
}

.help-list {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.88rem;
  color: #475569;
  line-height: 1.65;
}

.help-list li {
  margin: 0.35em 0;
}

.help-dialog-footer-btn {
  justify-self: start;
}

/* スマホ「新しく書く」中：一覧に戻らずにひな形から作れる導線 */
.mobile-write-new-toolbar {
  display: none;
}

@media (max-width: 768px) {
  body.app-mobile-layout.app-mobile-tab-write .mobile-write-new-toolbar {
    display: block;
    margin-bottom: 6px;
  }
}

.list-toolbar--secondary {
  margin-top: 6px;
  flex-wrap: wrap;
  gap: 8px;
}

.content-input-wrap {
  position: relative;
}

.link-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 5;
  margin-top: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  max-height: 200px;
  overflow: auto;
}

.link-suggest button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  margin: 2px 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.link-suggest button:hover {
  background: var(--accent-soft);
}

.editor-inline-actions {
  margin-top: 8px;
}

.preview-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.preview-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.toc-view {
  padding: 8px 0 12px;
  font-size: 0.92rem;
}

.toc-block {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.toc-block h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.toc-nested {
  margin-left: 10px;
  display: grid;
  gap: 4px;
}

.toc-note-link {
  display: block;
  text-align: left;
  padding: 4px 0;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

@media print {
  .site-header,
  .left-column,
  .center-column,
  .mobile-top-tabs,
  .tab-row,
  .preview-header-actions,
  .mobile-write-new-toolbar,
  .site-footer {
    display: none !important;
  }

  body {
    padding: 0;
    background: #fff;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  #right-column {
    display: block !important;
    border: none;
    box-shadow: none;
    padding: 0;
    width: 100%;
    max-width: none;
  }

  #preview-view,
  #preview-view[hidden] {
    display: block !important;
    visibility: visible !important;
  }

  #editor-view {
    display: none !important;
  }
}
