:root {
  color-scheme: light;
  --bg: #f4f7f7;
  --panel: #ffffff;
  --panel-2: #e8eef1;
  --ink: #24221f;
  --muted: #657077;
  --line: #d3dde2;
  --accent: #166b5f;
  --accent-ink: #ffffff;
  --warn: #9b4d1f;
  --danger: #a03232;
  --blue: #245f93;
  --shadow: 0 18px 50px rgba(25, 39, 45, 0.08);
  --radius: 8px;
  --content-font-ja: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  --content-font-latin: Inter, system-ui, sans-serif;
  --content-font-size: 16px;
  --content-line-height: 1.75;
  --content-paragraph-spacing: 18px;
  --content-width: 820px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
}

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

button,
.button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:hover,
.button:hover {
  border-color: #aaa195;
  background: #f7faf9;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.danger {
  color: var(--danger);
}

button.ghost {
  background: transparent;
}

button.icon {
  width: 34px;
  padding: 0;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

a {
  color: var(--blue);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #e5edf0;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}

.brand strong {
  font-size: 18px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  justify-content: flex-start;
  width: 100%;
}

.nav button.active {
  background: #d4e2e5;
  border-color: #b8cbd1;
}

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

.note-item {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px;
  background: rgba(255, 255, 255, 0.56);
  cursor: pointer;
  text-align: left;
  display: grid;
  gap: 4px;
}

.note-item:hover,
.note-item.active {
  border-color: #b9cbd1;
  background: var(--panel);
}

.note-item strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item span {
  color: var(--muted);
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(310px, 380px);
  gap: 18px;
  align-items: start;
}

.editor-panel,
.side-panel,
.page-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.editor-panel {
  min-width: 0;
  overflow: hidden;
}

.editor-toolbar,
.panel-head,
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.editor-toolbar {
  flex-wrap: wrap;
}

.title-input {
  flex: 1;
  min-width: 220px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 22px;
  font-weight: 700;
  outline: none;
}

.toolbar-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: calc(100vh - 170px);
}

.editor-wrap {
  display: flex;
  flex-direction: column;
}

.markdown-input {
  flex: 1;
  width: 100%;
  min-height: 620px;
  border: 0;
  resize: none;
  outline: none;
  padding: 22px;
  background: #ffffff;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 15px;
  line-height: 1.7;
}

.hidden-markdown-source {
  display: none;
}

.visual-editor-wrap {
  background: #ffffff;
}

.visual-editor {
  width: 100%;
  min-height: 620px;
  margin: 0 auto;
  outline: none;
  caret-color: var(--accent);
  cursor: text;
  white-space: normal;
}

.visual-editor:focus {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.visual-editor:empty::before {
  content: "ここに書く";
  color: var(--muted);
}

.preview {
  padding: 22px;
  max-width: var(--content-width);
  font-family: var(--content-font-ja);
  font-size: var(--content-font-size);
  line-height: var(--content-line-height);
  overflow-wrap: anywhere;
}

.preview p {
  margin: 0 0 var(--content-paragraph-spacing);
}

.preview h1,
.preview h2,
.preview h3,
.preview h4 {
  line-height: 1.35;
  margin: 0 0 14px;
}

.preview blockquote {
  margin: 0 0 14px;
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--muted);
}

.note-list.muted-list {
  opacity: 0.55;
}

.note-list.muted-list .note-item {
  filter: grayscale(0.4);
}

.settings-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
  padding: 10px 14px;
  background: rgba(155, 77, 31, 0.08);
  border: 1px solid rgba(155, 77, 31, 0.4);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.92em;
}

.settings-banner.warn strong {
  color: var(--warn);
}

.settings-banner code {
  background: rgba(36, 95, 147, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
}

.preview .ai-callout {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin: -10px 0 var(--content-paragraph-spacing) 22px;
  padding: 0;
  background: transparent;
  border: 0;
  color: #9099a0;
  font-size: 0.86em;
  font-style: italic;
  line-height: 1.6;
  user-select: none;
}

.preview .ai-callout .ai-callout-icon {
  flex-shrink: 0;
  color: #b9c3c8;
  font-style: normal;
  font-size: 0.95em;
  line-height: 1.6;
  margin-top: 1px;
}

.preview .ai-callout .ai-callout-body {
  flex: 1;
  min-width: 0;
}

.preview .ai-callout[data-importance="high"] {
  margin-left: 22px;
  font-style: normal;
  color: #5a6168;
  font-size: 0.92em;
}

.preview .ai-callout[data-importance="high"] .ai-callout-icon {
  color: var(--accent);
}

.preview .ai-callout[data-confidence="low"] {
  color: #a09893;
}

.preview .ai-callout[data-confidence="low"] .ai-callout-icon {
  color: var(--warn);
}

.preview .after-ai-callout {
  min-height: 1.6em;
  margin: -8px 0 var(--content-paragraph-spacing) 0;
}

.preview .ai-reply-line {
  min-height: 1.6em;
  margin: -6px 0 8px 34px;
  padding-left: 12px;
  border-left: 2px solid #d8e1e5;
  color: var(--ink);
}

.preview .ai-reply-line:empty::before {
  content: "";
}

/* 返信行の後のAIコメントは親コメントよりさらにインデント */
.preview .ai-reply-line + .ai-callout {
  margin-left: 46px;
}

/* 返信チェーン内のさらなる返信行 */
.preview .ai-reply-line + .ai-callout + .ai-reply-line {
  margin-left: 58px;
  padding-left: 12px;
  border-left: 2px solid #c5d4da;
}

.visual-editor .ai-callout {
  cursor: default;
}

.preview pre {
  overflow: auto;
  padding: 14px;
  background: #edf2f4;
  border-radius: var(--radius);
}

.preview code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.preview figure {
  margin: 16px 0;
}

.preview img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.preview figcaption {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.youtube {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.youtube iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--radius);
}

.url-card {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-decoration: none;
  background: #f7faf9;
}

.url-card span {
  color: var(--muted);
  font-size: 12px;
}

.marker {
  display: inline;
  border-radius: 5px;
  padding: 1px 5px;
  background: #e5efe7;
  color: #205940;
}

.marker-weak {
  background: #f3e5d8;
  color: #784214;
}

.marker-ask,
.marker-cf {
  background: #e1ebf3;
  color: #214c70;
}

.status-bar {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.side-panel {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.side-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.side-section:last-child {
  border-bottom: 0;
}

.side-section h3 {
  margin: 0;
  font-size: 14px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ghost-suggestion {
  background: #f7faf9;
}

.ghost-preview {
  border-left: 3px solid #b8cbd1;
  padding-left: 10px;
  color: #7d878c;
  font-style: italic;
  line-height: 1.6;
}

.ghost-preview p {
  margin: 0 0 8px;
}

.second-self-digest .digest-body {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
}


.second-self-digest h2 {
  margin: 8px 0 4px;
  font-size: 0.86rem;
}

.profile-suggestions,
.graph-edge-list {
  display: grid;
  gap: 8px;
}

.profile-suggestion {
  gap: 6px;
}

.thinking-log {
  gap: 8px;
}

.thinking-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.thinking-row strong,
.thinking-row span {
  display: block;
}

.thinking-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #bac8ce;
  margin-top: 7px;
}

.thinking-row.running .thinking-dot {
  background: var(--accent);
}

.thinking-row.error .thinking-dot {
  background: var(--danger);
}

.comment,
.card,
.share-card,
.revision {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #ffffff;
  display: grid;
  gap: 8px;
}

.comment header,
.card header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #edf2f4;
  color: var(--muted);
  font-size: 12px;
}

.badge.high {
  background: #e1efe7;
  color: #1f6544;
}

.badge.low {
  background: #f1e0db;
  color: #8a362b;
}

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

.empty {
  color: var(--muted);
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.page-panel {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.search-input,
.setting-input,
.comment-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: #ffffff;
}

.comment-input {
  min-height: 82px;
  resize: vertical;
}

.settings-grid {
  display: grid;
  gap: 14px;
  max-width: 760px;
}

.settings-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.settings-grid input,
.settings-grid select,
.settings-grid textarea {
  color: var(--ink);
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    position: static;
    min-height: auto;
  }

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

  .side-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 10px;
  }

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

  .editor-wrap {
    border-bottom: 1px solid var(--line);
  }

  .markdown-input,
  .visual-editor {
    min-height: 340px;
  }

  .editor-toolbar,
  .panel-head,
  .status-bar {
    align-items: stretch;
  }
}
