:root {
  color-scheme: light;

  /* === Design tokens === */
  --bg: #fbfbfa;
  --panel: #ffffff;
  --surface: #f7f7f6;
  --elevated: #ffffff;

  --ink: #1c1c1e;
  --soft-ink: #3a3a3c;
  --muted: #8e8e93;
  --subtle: #aeaeb2;
  --line: #ececec;
  --line-strong: #dedede;

  --green: #34c759;
  --green-dark: #248a3d;
  --green-bg: rgba(52, 199, 89, 0.07);
  --blue: #007aff;
  --blue-bg: rgba(0, 122, 255, 0.07);
  --danger: #ff3b30;
  --danger-bg: rgba(255, 59, 48, 0.06);
  --warn: #ff9500;
  --purple: #af52de;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.025);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.045), 0 1px 2px rgba(0, 0, 0, 0.025);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --window-bar-height: 32px;
  --top-content-height: 52px;

  --apple-font: "PingFang SC", -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--apple-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* === Shell layout === */
.appShell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.appShell.sidebarHidden {
  grid-template-columns: minmax(0, 1fr);
}

.appShell.sidebarHidden .sidebar {
  display: none;
}

/* === Sidebar === */
.sidebar {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 24px 12px 28px;
  overflow-y: hidden;
  overflow-x: hidden;
  background: var(--bg);
  border-right: 1px solid rgba(0, 0, 0, 0.055);
}

.sidebarWindowBar {
  flex: 0 0 var(--window-bar-height);
  -webkit-app-region: drag;
}

.profileRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  flex-shrink: 0;
  min-height: var(--top-content-height);
  gap: 6px;
  margin-bottom: 8px;
}

.profile {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  min-width: 0;
  margin-bottom: 0;
  padding: 0;
  text-align: left;
}

.profileGearBtn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #8e8e93;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transition: background 0.14s ease, color 0.14s ease, opacity 0.16s ease;
}

.profileRow:hover .profileGearBtn,
.profileRow:focus-within .profileGearBtn {
  opacity: 1;
  pointer-events: auto;
}

.profileGearBtn:hover {
  background: #f2f2f7;
  color: #6e6e73;
}

.profileGearBtn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.brandMark {
  display: none;
}

.account {
  font-weight: 560;
  font-size: 14px;
  letter-spacing: 0;
  color: var(--ink);
}

.account span {
  margin-left: 6px;
  padding: 1px 6px 2px;
  border-radius: 999px;
  background: rgba(52, 199, 89, 0.1);
  color: var(--green-dark);
  font-size: 10px;
  font-weight: 540;
  vertical-align: middle;
  letter-spacing: 0;
}

.profile p,
.sectionTitle,
.monthRow,
.numberGrid span,
#draftMeta,
.memoHead time {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 500;
}

.profile p {
  display: none;
}

.profile:hover .account {
  color: var(--green-dark);
}

/* Stats */
.statsCard {
  flex-shrink: 0;
  margin-bottom: 12px;
  padding: 14px 0 12px;
  box-shadow: none;
}

.statsCardInner {
  --heat-cell: 14px;
  --heat-gap: 4px;
  --heat-width: 230px;
  width: var(--heat-width);
  margin: 0 auto;
}

.numberGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: start;
  gap: 0;
  margin-bottom: 18px;
}

.numberGrid > div:nth-child(1) {
  justify-self: start;
  text-align: left;
}

.numberGrid > div:nth-child(2) {
  justify-self: center;
  text-align: center;
}

.numberGrid > div:nth-child(3) {
  justify-self: end;
  text-align: right;
}

.numberGrid strong {
  display: block;
  color: #6f7177;
  font-size: 28px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: 0;
  text-align: inherit;
}

.numberGrid span {
  display: block;
  margin-top: 6px;
  color: #a6a7ab;
  font-weight: 400;
  font-size: 12px;
  text-align: inherit;
}

.heatmapBlock {
  padding: 0;
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(13, var(--heat-cell));
  grid-template-rows: repeat(7, var(--heat-cell));
  grid-auto-flow: column;
  column-gap: var(--heat-gap);
  row-gap: var(--heat-gap);
  width: max-content;
  margin: 0;
}

.dayCell {
  width: var(--heat-cell);
  height: var(--heat-cell);
  border: 0;
  border-radius: 4px;
  box-sizing: border-box;
  background: #f0f1f2;
}

.dayCell.level1 { background: #c9efd8; }
.dayCell.level2 { background: #84dfa2; }
.dayCell.level3 { background: #35c865; }
.dayCell.level4 { background: #20b653; }

.monthRow {
  display: grid;
  grid-template-columns: repeat(13, var(--heat-cell));
  column-gap: var(--heat-gap);
  width: max-content;
  margin: 14px 0 0;
  text-align: left;
  color: #a0a3a8;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
}

.monthRow span {
  white-space: nowrap;
}

/* Nav */
.navList {
  display: grid;
}

.navList {
  gap: 5px;
  margin-bottom: 0;
  min-height: 0;
  overflow-y: visible;
  flex: 0 0 auto;
}

.navItem {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  color: #5d5d61;
  font-weight: 430;
  font-size: 12.5px;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.navItem {
  min-height: 42px;
}

.staticItem {
  color: var(--soft-ink);
}

.navItem:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--ink);
}

.navItem.active {
  background: rgba(52, 199, 89, 0.08);
  color: var(--green-dark);
  font-weight: 460;
}

.filterItem {
  min-height: 32px;
  margin-left: 20px;
  width: calc(100% - 20px);
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
}

.filterItem .navIcon {
  width: 15px;
  height: 15px;
}

.filterItem.active {
  background: var(--green-bg);
  color: var(--green-dark);
  font-weight: 500;
}

.filterItem.active:hover {
  background: rgba(52, 199, 89, 0.12);
}

.navIcon {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  line-height: 1;
}

.navIcon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.navItem:first-child .navIcon svg {
  fill: currentColor;
  stroke: none;
}

.searchBox svg,
.homeIcon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sectionTitle {
  margin-bottom: 6px;
  font-weight: 440;
  font-size: 11.5px;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0;
}

.quietBtn {
  display: grid;
  place-items: center;
  min-height: 31px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.58);
  color: #99999e;
  font-size: 11.5px;
  font-weight: 440;
  box-shadow: none;
  border: 1px solid rgba(0, 0, 0, 0.055);
  transition: all 0.15s ease;
}

.quietBtn:hover {
  background: var(--surface);
  color: var(--soft-ink);
  border-color: var(--line-strong);
  box-shadow: none;
}

/* === Main pane === */
.mainPane {
  max-width: 1100px;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 0 28px 20px;
  display: grid;
  grid-template-rows: calc(var(--window-bar-height) + var(--top-content-height)) auto auto minmax(0, 1fr);
  overflow: hidden;
}

/* Top bar */
.topbar {
  grid-row: 1;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: center;
  gap: 16px;
  height: calc(var(--window-bar-height) + var(--top-content-height));
  padding-top: var(--window-bar-height);
  background: rgba(251, 251, 250, 0.9);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  -webkit-app-region: drag;
}

.topbarLeft {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  -webkit-app-region: no-drag;
}

.topbarControls {
  position: absolute;
  left: -136px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.topbar:hover .topbarControls,
.topbar:focus-within .topbarControls {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.topIconBtn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  transition: all 0.15s ease;
  -webkit-app-region: no-drag;
}

.topIconBtn.active,
.topIconBtn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--soft-ink);
}

.topIconBtn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.breadcrumb {
  display: flex;
  align-items: center;
  min-width: 0;
  color: #4c4c50;
  font-weight: 520;
  font-size: 15px;
  letter-spacing: 0;
}

.titleMenuWrap {
  position: relative;
  min-width: 0;
  -webkit-app-region: no-drag;
}

.viewTitleBtn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 360px;
  min-height: 32px;
  padding: 0 8px 0 0;
  border-radius: 8px;
  color: #3d3d42;
  font-weight: 520;
  -webkit-app-region: no-drag;
}

.viewTitleBtn:hover {
  color: var(--ink);
}

.viewTitleBtn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.titleChevron {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  fill: none;
  stroke: #a0a0a5;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.viewTitleBtn[aria-expanded="true"] .titleChevron {
  transform: rotate(180deg);
}

.viewTitleMenu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 12;
  min-width: 210px;
  padding: 7px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.055);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.085), 0 2px 8px rgba(0, 0, 0, 0.04);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.viewTitleMenu button {
  width: 100%;
  min-height: 30px;
  padding: 0 9px;
  border-radius: 7px;
  text-align: left;
  color: #4f4f54;
  font-size: 12.5px;
  font-weight: 450;
}

.viewTitleMenu button:hover,
.viewTitleMenu button.active {
  background: rgba(0, 0, 0, 0.045);
  color: var(--ink);
}

.viewTitleMenu button.active::after {
  content: "✓";
  float: right;
  color: var(--green-dark);
  font-weight: 600;
}

.menuSectionLabel {
  padding: 4px 9px 5px;
  color: #a2a2a7;
  font-size: 11px;
  font-weight: 500;
}

.menuDivider {
  height: 1px;
  margin: 6px 4px;
  background: rgba(0, 0, 0, 0.055);
}

.homeIcon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--subtle);
  margin-right: 6px;
}

/* Search */
.searchBox {
  display: grid;
  grid-template-columns: 15px 1fr;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 13px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.032);
  color: #b8b8bd;
  border: 1px solid transparent;
  transition: all 0.18s ease;
  -webkit-app-region: no-drag;
}

.searchBox:focus-within {
  background: rgba(255, 255, 255, 0.86);
  border-color: rgba(0, 0, 0, 0.06);
  box-shadow: none;
}

.searchBox svg {
  stroke-width: 1.8;
}

.importBtn input {
  display: none;
}

.hiddenFile {
  display: none;
}

.searchBox input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.searchBox input::placeholder {
  color: var(--subtle);
}

/* === Composer (编辑器核心区域) === */
.composer {
  grid-row: 2;
  margin: 10px 0 14px;
  border: 1px solid rgba(0, 0, 0, 0.055);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: none;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.composer:focus-within {
  border-color: rgba(0, 0, 0, 0.095);
  box-shadow: none;
}

.composer textarea {
  width: 100%;
  height: 76px;
  min-height: 60px;
  max-height: 200px;
  resize: vertical;
  padding: 18px 20px 4px 20px;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-family: var(--apple-font);
  font-size: 15.5px;
  line-height: 1.6;
  transition: height 0.2s ease, min-height 0.2s ease, padding 0.2s ease;
}

.composer.compact textarea {
  height: 36px;
  min-height: 36px;
  max-height: 36px;
  resize: none;
  padding: 10px 20px 0;
  line-height: 1.35;
  overflow: hidden;
}

.composer:focus-within textarea {
  height: 100px;
  min-height: 76px;
  max-height: 200px;
  resize: vertical;
  padding: 18px 20px 4px;
  line-height: 1.6;
}

.composer textarea::placeholder {
  color: var(--subtle);
  font-weight: 400;
}

.composer.draggingImage {
  border-color: var(--green);
  background: rgba(52, 199, 89, 0.03);
  box-shadow: var(--shadow-lg), 0 0 0 3px rgba(52, 199, 89, 0.12);
}

.draftImages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 20px 0;
}

.draftImages[hidden] {
  display: none;
}

.draftImageItem {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.draftImageItem img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.draftImageItem button {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.draftImageItem button::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.09);
  backdrop-filter: blur(4px);
  transition: background 0.14s ease, box-shadow 0.14s ease;
}

.draftImageItem button:hover::before {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.11);
}

.draftImageItem .draftZoomBtn {
  left: -8px;
  right: auto;
}

.draftImageItem button svg {
  position: relative;
  z-index: 1;
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* Selection toolbar */
.selectionToolbar {
  position: absolute;
  top: 18px;
  z-index: 14;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-xl);
}

.selectionToolbar[hidden] {
  display: none;
}

.selectionToolbar button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: #9a9aa0;
  transition: all 0.12s ease;
}

.selectionToolbar button:hover {
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
}

.selectionToolbar span {
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: var(--line);
}

#selectionBoldBtn svg,
#selectionUnderlineBtn svg,
#selectionMarkBtn svg,
.selectionBoldBtn svg,
.selectionUnderlineBtn svg,
.selectionMarkBtn svg,
.selectionListBtn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.selectionListBtn svg circle {
  fill: currentColor;
  stroke: none;
}

.selectionListBtn svg text {
  fill: currentColor;
  stroke: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  font-size: 4.7px;
  font-weight: 500;
}

/* === Editor Tools Bar (工具栏 - 重点改进) === */
.editorTools {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 42px;
  padding: 0 14px 10px 18px;
  color: #a1a1a6;
}

.editorTools button {
  display: grid;
  place-items: center;
  width: 29px;
  min-width: 29px;
  height: 29px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: #9a9aa0;
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  transition: all 0.15s ease;
}

.editorTools button:hover {
  background: rgba(0, 0, 0, 0.032);
  color: var(--soft-ink);
}

#tagBtn,
#imageBtn,
#formatBtn,
#mentionBtn,
.editorTagBtn,
.editorImageBtn,
.editorFormatBtn,
.editorMentionBtn {
  font-size: 16px;
  font-weight: 500;
}

#tagBtn svg,
#imageBtn svg,
#formatBtn svg,
#mentionBtn svg,
#saveBtn svg,
.editorTagBtn svg,
.editorImageBtn svg,
.editorFormatBtn svg,
.editorMentionBtn svg,
.listTool svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.listTool svg circle {
  fill: currentColor;
  stroke: none;
}

.listTool svg text {
  fill: currentColor;
  stroke: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  font-size: 4.7px;
  font-weight: 500;
}

#saveBtn svg {
  width: 19px;
  height: 19px;
  stroke-width: 1.55;
}

#reviewSettingsBtn svg,
#reviewCloseBtn svg,
#reviewPrevBtn svg,
#reviewNextBtn svg,
#relatedCloseBtn svg,
.moreBtn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#boldBtn svg,
#underlineBtn svg,
#markBtn svg,
.editorBoldBtn svg,
.editorUnderlineBtn svg,
.editorMarkBtn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

#formatBtn.active,
.editorFormatBtn.active {
  background: rgba(0, 0, 0, 0.04);
  color: var(--soft-ink);
}

.formatTool {
  position: relative;
  display: flex;
  align-items: center;
  width: 32px;
  height: 32px;
}

.formatMenu {
  position: absolute;
  left: 50%;
  bottom: 34px;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(3, 38px);
  gap: 0;
  padding: 6px 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-xl);
  transform: translateX(-50%);
}

.formatMenu[hidden] {
  display: none;
}

.formatMenu button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  transition: all 0.12s ease;
}

.formatMenu button:hover {
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
}

.editorTools span {
  width: 1px;
  height: 18px;
  flex: 0 0 1px;
  margin: 0 7px;
  background: var(--line);
}

.toolSpacer {
  flex: 1;
}

#saveBtn {
  display: grid;
  place-items: center;
  width: 34px;
  min-width: 34px;
  height: 32px;
  border: 1px solid rgba(52, 199, 89, 0.24);
  border-radius: 9px;
  background: rgba(52, 199, 89, 0.075);
  color: var(--green-dark);
  box-shadow: none;
  transition: all 0.15s ease;
}

#saveBtn:hover {
  background: rgba(52, 199, 89, 0.12);
  border-color: rgba(52, 199, 89, 0.34);
}

#saveBtn:active {
  background: rgba(52, 199, 89, 0.16);
}

#saveBtn:disabled {
  cursor: default;
  border-color: transparent;
  background: rgba(0, 0, 0, 0.04);
  color: var(--subtle);
  box-shadow: none;
}

/* === Special panel === */
.specialPanel {
  grid-row: 3;
  margin-bottom: 12px;
  max-height: min(620px, calc(100vh - 190px));
  overflow: auto;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  color: var(--soft-ink);
  line-height: 1.75;
}

.specialPanel h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
}

.specialPanel ul {
  margin: 10px 0 0;
  padding-left: 20px;
}

.specialPanel p {
  margin: 0;
}

.summaryHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.summaryHeader p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.tagOverviewPanel,
.tagDetailPanel {
  padding: 20px;
}

.tagDetailPanel {
  margin-bottom: 8px;
  max-height: none;
  overflow: visible;
}

.tagPageHeader,
.tagDetailControls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.tagPageHeader {
  margin-bottom: 18px;
}

.tagPageHeader h2 {
  margin-bottom: 3px;
}

.tagPageHeader p {
  color: var(--muted);
  font-size: 12.5px;
}

.tagManageBtn,
.tagBackBtn,
.tagSortControl button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.62);
  color: var(--soft-ink);
  font-size: 12px;
  font-weight: 500;
}

.tagManageBtn {
  padding: 0 11px;
}

.tagManageBtn:hover,
.tagBackBtn:hover {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}

.tagPageSearch {
  display: flex;
  align-items: center;
  width: min(360px, 100%);
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.64);
  color: var(--subtle);
}

.tagPageSearch:focus-within {
  border-color: rgba(52, 199, 89, 0.4);
}

.tagPageSearch svg {
  width: 15px;
  height: 15px;
  margin-right: 7px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.tagPageSearch input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
}

.tagOverviewGroup {
  margin-top: 22px;
}

.tagOverviewGroup h3 {
  margin: 0 0 9px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 520;
}

.tagOverviewGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 7px;
}

.tagOverviewItem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  gap: 10px;
  padding: 0 11px;
  border: 1px solid rgba(0, 0, 0, 0.055);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.5);
  color: var(--soft-ink);
  text-align: left;
}

.tagOverviewItem:hover {
  border-color: rgba(52, 199, 89, 0.24);
  background: rgba(52, 199, 89, 0.055);
  color: var(--green-dark);
}

.tagOverviewName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

.tagOverviewCount {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 11px;
}

.tagOverviewEmpty {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.tagDetailTitle {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.tagBackBtn {
  padding: 0 9px;
  white-space: nowrap;
}

.tagDetailControls {
  align-items: stretch;
}

.tagSortControl {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.025);
}

.tagSortControl button {
  min-height: 28px;
  padding: 0 9px;
  border-color: transparent;
  background: transparent;
}

.tagSortControl button.active {
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (max-width: 640px) {
  .tagPageHeader,
  .tagDetailControls {
    align-items: stretch;
    flex-direction: column;
  }

  .tagManageBtn,
  .tagSortControl {
    align-self: flex-start;
  }

  .tagPageSearch {
    width: 100%;
  }
}

.summaryMetrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.summaryPreview,
.summaryResult,
.settingsPanel {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
}

.summaryPreview {
  padding: 11px 13px;
  margin-bottom: 10px;
}

.summaryPreview strong,
.summaryHistory h3,
.settingsGrid label > span {
  display: block;
  margin-bottom: 5px;
  color: var(--soft-ink);
  font-size: 13px;
  font-weight: 540;
}

.summaryPreview p,
.summaryHistory .mutedLine,
.settingsGrid small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.summaryResult {
  min-height: 112px;
  padding: 13px 14px;
  white-space: pre-wrap;
  color: var(--soft-ink);
  font-size: 13.5px;
  line-height: 1.7;
}

.summaryResult time {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.emptySummary {
  display: grid;
  place-items: center;
  color: var(--subtle);
}

.summaryHistory {
  margin-top: 13px;
}

.summaryHistoryItem {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--soft-ink);
  font-size: 12.5px;
  text-align: left;
}

.summaryHistoryItem:hover {
  background: rgba(0, 0, 0, 0.035);
}

.summaryHistoryItem time {
  color: var(--muted);
  font-size: 12px;
}

.reviewDateActions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 12px;
}

.reviewDateBtn {
  display: grid;
  gap: 2px;
  min-height: 48px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.025);
  color: var(--soft-ink);
  text-align: left;
  font-size: 13px;
}

.reviewDateBtn small {
  color: var(--muted);
  font-size: 11px;
}

.reviewDateBtn:hover,
.reviewDateBtn.active {
  background: rgba(52, 199, 89, 0.09);
  color: var(--green-dark);
}

.pastReviewOverview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin: 0 0 10px;
}

.pastReviewOverview > div,
.randomExplain {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.62);
  padding: 10px 12px;
}

.pastReviewOverview strong,
.pastReviewNotes h3,
.randomExplain strong {
  display: block;
  margin-bottom: 5px;
  color: var(--soft-ink);
  font-size: 13px;
  font-weight: 520;
}

.pastReviewOverview p,
.randomExplain p {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.pastReviewNotes {
  margin-top: 14px;
}

.panelMemo {
  padding: 14px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.055);
}

.panelMemo time {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.panelMemoText {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.75;
}

.panelMemoTags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.panelMemoTags span {
  color: var(--green-dark);
  font-size: 12px;
}

.pastReviewEmpty {
  min-height: 120px;
}

.randomMemoCard {
  margin-top: 12px;
}

.randomMemoCard .panelMemo {
  border-top: 0;
  padding-top: 0;
}

.quietInlineBtn {
  min-height: 30px;
  margin-top: 10px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
  font-size: 12.5px;
}

.quietInlineBtn:hover {
  background: rgba(0, 0, 0, 0.055);
}

.primarySummaryBtn,
.settingsActions button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: rgba(52, 199, 89, 0.1);
  color: var(--green-dark);
  border: 1px solid rgba(52, 199, 89, 0.16);
  font-size: 13px;
  font-weight: 520;
}

.primarySummaryBtn:hover,
.settingsActions button:hover {
  background: rgba(52, 199, 89, 0.14);
}

.settingsPanel {
  padding: 0;
  border: 0;
  background: transparent;
}

.settingsSectionHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding-bottom: 2px;
}

.settingsSectionHeader h3 {
  margin: 0 0 4px;
  color: var(--soft-ink);
  font-size: 15px;
  font-weight: 600;
}

.settingsSectionHeader p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.settingsKeyStatus {
  flex: 0 0 auto;
  min-height: 26px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 149, 0, 0.16);
  border-radius: 999px;
  background: rgba(255, 149, 0, 0.08);
  color: #9a6500;
  font-size: 11.5px;
  font-weight: 560;
}

.settingsKeyStatus.isConfigured {
  border-color: rgba(52, 199, 89, 0.18);
  background: rgba(52, 199, 89, 0.09);
  color: var(--green-dark);
}

.settingsKeyStatus.isError {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger);
}

.settingsGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.settingsGrid label {
  display: grid;
  gap: 5px;
}

.settingsFull {
  grid-column: 1 / -1;
}

.settingsGrid input {
  width: 100%;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: 0;
  background: var(--panel);
  color: var(--soft-ink);
  font-size: 13px;
}

.settingsGrid input:focus {
  border-color: rgba(52, 199, 89, 0.55);
}

.settingsActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.settingsActions button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.settingsAdvanced {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.38);
  overflow: hidden;
}

.settingsAdvanced > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 0 14px;
  color: var(--soft-ink);
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 560;
}

.settingsAdvanced > summary::-webkit-details-marker {
  display: none;
}

.settingsAdvanced > summary::after {
  content: "＋";
  margin-left: auto;
  color: var(--muted);
  font-size: 16px;
  font-weight: 400;
}

.settingsAdvanced[open] > summary::after {
  content: "−";
}

.settingsAdvanced > summary:hover {
  background: rgba(0, 0, 0, 0.018);
}

.settingsAdvanced > summary small {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 400;
}

.settingsAiGuide,
.settingsBackup {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.6);
}

.settingsAiGuide {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  margin: 0 10px 10px;
  background: rgba(255, 255, 255, 0.68);
}

.settingsAiGuide h3,
.settingsBackup h3 {
  margin: 0 0 4px;
  color: var(--soft-ink);
  font-size: 14px;
  font-weight: 560;
}

.settingsAiGuide p,
.settingsBackup p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.settingsAiGuide button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: rgba(52, 199, 89, 0.1);
  color: var(--green-dark);
  border: 1px solid rgba(52, 199, 89, 0.16);
  font-size: 12.5px;
  font-weight: 520;
}

.settingsBackupActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settingsBackupActions button,
.settingsImportBtn {
  display: grid;
  place-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
  font-size: 12.5px;
  cursor: pointer;
}

.settingsImportBtn input {
  display: none;
}

.settingsBackupActions button:hover,
.settingsImportBtn:hover {
  background: rgba(0, 0, 0, 0.055);
}

.settingsBackupActions .dangerSettingsBtn {
  color: var(--danger);
  background: rgba(255, 59, 48, 0.08);
}

#settingsResult {
  min-height: 42px;
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  white-space: pre-wrap;
  font-family: var(--apple-font);
  font-size: 12.5px;
  line-height: 1.6;
}

.mutedLine {
  color: var(--muted);
  font-size: 13px;
}

.mapGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.mapTag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--soft-ink);
  font-weight: 500;
  transition: background 0.12s ease;
}

.mapTag:hover {
  background: var(--line);
}

.referencePanel {
  position: absolute;
  left: 120px;
  bottom: 46px;
  z-index: 10;
  width: min(420px, calc(100% - 170px));
  max-height: 400px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-xl);
}

.composer {
  position: relative;
}

.referencePanel input {
  width: 100%;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: 0;
  color: var(--soft-ink);
  font-family: var(--apple-font);
  font-size: 14px;
  font-weight: 500;
}

.referenceResults {
  max-height: 340px;
  overflow: auto;
  padding: 6px;
}

.referenceItem {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background 0.12s ease;
}

.referenceItem:hover,
.referenceItem:focus {
  background: var(--surface);
  outline: 0;
}

.referenceItem time {
  color: var(--muted);
  font-size: 12px;
}

.referenceItem span {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.referenceEmpty {
  padding: 22px;
  color: var(--subtle);
  text-align: center;
  font-size: 13px;
}

.agentBox {
  display: grid;
  gap: 10px;
}

.agentBox input,
.agentBox textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: 0;
  font-family: var(--apple-font);
  font-size: 14px;
  background: var(--panel);
  transition: border-color 0.15s ease;
}

.agentBox input:focus,
.agentBox textarea:focus {
  border-color: var(--green);
}

.agentActions {
  display: flex;
  gap: 8px;
}

.agentActions button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--soft-ink);
  font-weight: 600;
  font-size: 13px;
  border: 1px solid var(--line);
  transition: all 0.12s ease;
}

.agentActions button:last-child {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.agentActions button:last-child:hover {
  background: var(--green-dark);
}

#agentResult {
  min-height: 120px;
  margin: 0;
  white-space: pre-wrap;
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
  color: var(--soft-ink);
  font: 13px/1.65 var(--apple-font);
  border: 1px solid var(--line);
}

/* === Review Modal === */
.reviewModal[hidden] {
  display: none;
}

.relatedModal[hidden] {
  display: none;
}

.aiGuideModal[hidden] {
  display: none;
}

.tagManagerModal[hidden] {
  display: none;
}

.reviewModal,
.relatedModal,
.aiGuideModal,
.tagManagerModal {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.tagManagerBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(245, 245, 244, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.tagManagerDialog {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(720px, calc(100vw - 48px));
  max-height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--bg);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.12);
}

.tagManagerHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 18px;
  align-items: start;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.tagManagerHeader h2,
.tagManagerGroup h3 {
  margin: 0;
  color: var(--ink);
  letter-spacing: 0;
}

.tagManagerHeader h2 {
  margin-bottom: 5px;
  font-size: 18px;
  font-weight: 580;
}

.tagManagerHeader p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

#tagManagerCloseBtn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--muted);
}

#tagManagerCloseBtn:hover {
  background: rgba(0, 0, 0, 0.045);
  color: var(--ink);
}

#tagManagerCloseBtn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.tagCreateForm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px auto;
  gap: 8px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
}

.tagCreateForm input,
.tagCreateForm select,
.tagManagerInlineAction select {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
  color: var(--soft-ink);
  font: 12.5px var(--apple-font);
}

.tagCreateForm button,
.tagManagerActions button,
.tagManagerInlineAction button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
  font-size: 12px;
}

.tagCreateForm button:hover,
.tagManagerActions button:hover,
.tagManagerInlineAction button:hover {
  background: rgba(0, 0, 0, 0.06);
}

.tagManagerResult {
  min-height: 24px;
  padding: 5px 22px 0;
  color: var(--muted);
  font-size: 12px;
}

.tagManagerList {
  min-height: 0;
  overflow-y: auto;
  padding: 4px 22px 22px;
}

.tagManagerGroup {
  margin-top: 16px;
}

.tagManagerGroup h3 {
  margin-bottom: 7px;
  color: var(--subtle);
  font-size: 11.5px;
  font-weight: 540;
}

.tagManagerRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.045);
}

.tagManagerMeta {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.tagManagerMeta strong {
  overflow: hidden;
  color: var(--soft-ink);
  font-size: 12.5px;
  font-weight: 520;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tagManagerMeta span,
.tagManagerInlineAction span {
  color: var(--subtle);
  font-size: 11px;
}

.tagManagerActions,
.tagManagerInlineAction {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.tagManagerActions button:disabled {
  cursor: default;
  opacity: 0.35;
}

.tagManagerInlineAction {
  grid-column: 1 / -1;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.025);
}

.tagManagerInlineAction select {
  min-width: 150px;
}

.dangerTextBtn {
  color: var(--danger) !important;
}

@media (max-width: 640px) {
  .tagCreateForm {
    grid-template-columns: 1fr;
  }

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

  .tagManagerActions {
    justify-content: flex-start;
  }
}

.reviewBackdrop,
.relatedBackdrop,
.aiGuideBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.reviewDialog {
  position: absolute;
  inset: 20px 30px;
  display: grid;
  grid-template-rows: 76px minmax(0, 1fr) 104px;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: var(--bg);
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.08);
}

.aiGuideDialog {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  width: min(720px, calc(100vw - 48px));
  max-height: min(720px, calc(100vh - 56px));
  transform: translate(-50%, -50%);
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--bg);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.12);
}

.aiGuideHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 18px;
  align-items: start;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.aiGuideHeader h2 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 580;
  letter-spacing: 0;
}

.aiGuideHeader p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

#aiGuideCloseBtn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--subtle);
}

#aiGuideCloseBtn:hover {
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
}

#aiGuideCloseBtn svg {
  width: 18px;
  height: 18px;
}

.aiGuideTextarea {
  width: 100%;
  height: 100%;
  min-height: 260px;
  resize: none;
  padding: 16px 18px;
  border: 0;
  outline: 0;
  background: rgba(255, 255, 255, 0.68);
  color: var(--soft-ink);
  font: 13.5px/1.75 var(--apple-font);
}

.aiGuideActions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
}

.aiGuideActions div {
  display: flex;
  gap: 8px;
}

.aiGuideActions button {
  min-height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
  font-size: 12.5px;
  font-weight: 520;
}

.aiGuideActions button:hover {
  background: rgba(0, 0, 0, 0.055);
}

.aiGuideActions .primaryAiGuideBtn {
  background: rgba(52, 199, 89, 0.12);
  color: var(--green-dark);
  border: 1px solid rgba(52, 199, 89, 0.18);
}

.reviewHeader {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0 32px;
}

.reviewHeader h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 560;
  letter-spacing: 0;
}

.reviewHeader button {
  color: var(--subtle);
  transition: all 0.12s ease;
}

.reviewHeader button:hover {
  background: rgba(0, 0, 0, 0.035);
  color: var(--soft-ink);
}

#reviewSettingsBtn {
  position: absolute;
  top: 50%;
  right: 90px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
}

#reviewCloseBtn {
  position: absolute;
  top: 50%;
  right: 32px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
}

.reviewStage {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(520px, 680px) minmax(220px, 1fr);
  gap: 16px;
  min-width: 0;
  overflow: hidden;
  padding: 0 0 4px;
}

.reviewCard {
  overflow: auto;
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 26px 30px 44px;
  box-shadow: none;
}

.reviewCard.side {
  opacity: 0.32;
}

.reviewAge {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.reviewBody {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.78;
  white-space: pre-wrap;
  font-weight: 400;
}

.reviewFooter {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 96px 12px;
  color: var(--muted);
}

.reviewFooter > button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.035);
  color: var(--subtle);
  transition: all 0.15s ease;
}

.reviewFooter > button:hover {
  background: rgba(0, 0, 0, 0.055);
  color: var(--soft-ink);
}

#reviewPrevBtn {
  justify-self: start;
}

#reviewNextBtn {
  justify-self: end;
}

/* Related modal */
.relatedDialog {
  position: absolute;
  top: 9vh;
  left: 50%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(620px, calc(100vw - 36px));
  max-height: 78vh;
  transform: translateX(-50%);
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-xl);
}

.relatedHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 18px 0 20px;
  border-bottom: 1px solid var(--line);
}

.relatedHeader h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.relatedHeader button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--subtle);
  transition: all 0.12s ease;
}

.relatedHeader button:hover {
  background: var(--surface);
  color: var(--soft-ink);
}

.relatedContent {
  display: grid;
  gap: 6px;
  overflow: auto;
  padding: 12px;
}

.relatedSource {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.relatedSource time,
.relatedItem time {
  color: var(--muted);
  font-size: 12px;
}

.relatedSource p {
  margin: 6px 0 0;
  color: var(--soft-ink);
  line-height: 1.55;
}

.relatedItem {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background 0.12s ease;
}

.relatedItem:hover {
  background: var(--surface);
}

.relatedItem span {
  color: var(--ink);
  line-height: 1.55;
}

.relatedItem small {
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
}

.relatedEmpty {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.imageViewer[hidden] {
  display: none;
}

.imageViewer {
  position: fixed;
  inset: 0;
  z-index: 130;
}

.imageViewerBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.imageViewerDialog {
  position: absolute;
  inset: 48px;
  display: grid;
  place-items: center;
}

.imageViewerDialog img {
  max-width: min(920px, calc(100vw - 96px));
  max-height: calc(100vh - 112px);
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.12);
}

#imageViewerCloseBtn {
  position: absolute;
  top: -6px;
  right: -6px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.09);
  transition: all 0.14s ease;
}

#imageViewerCloseBtn:hover {
  color: var(--soft-ink);
  background: white;
}

#imageViewerCloseBtn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.imageViewerArrow {
  position: absolute;
  top: 50%;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateY(-50%);
  transition: background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.imageViewerArrow[hidden] {
  display: none;
}

.imageViewerArrow:hover {
  background: rgba(255, 255, 255, 0.92);
  color: var(--soft-ink);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.14);
}

.imageViewerArrow svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.imageViewerPrev {
  left: 32px;
}

.imageViewerNext {
  right: 32px;
}

.imageViewerCounter {
  position: absolute;
  bottom: 28px;
  left: 50%;
  z-index: 4;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: white;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  transform: translateX(-50%);
}

.imageViewerCounter[hidden] {
  display: none;
}

/* === Timeline (时间线) === */
.timeline {
  grid-row: 4;
  display: grid;
  align-content: start;
  gap: 0;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 36px;
  overscroll-behavior: contain;
}

/* Memo cards */
.memoCard {
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.055);
  border-radius: 0;
  background: var(--panel);
  padding: 18px 20px 20px;
  box-shadow: none;
  transition: background 0.18s ease;
}

.memoCard.multiSelectable {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  column-gap: 8px;
}

.memoCard.multiSelectable .memoSelectWrap {
  display: grid;
}

.memoCard.selected {
  background: rgba(52, 199, 89, 0.025);
}

.memoSelectWrap {
  display: none;
  grid-row: 1 / span 3;
  align-self: start;
  justify-self: center;
  padding-top: 1px;
}

.memoSelect {
  width: 15px;
  height: 15px;
  accent-color: var(--green);
}

.bulkActionBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.055);
  background: rgba(255, 255, 255, 0.72);
  color: #7a7a80;
  font-size: 12.5px;
  font-weight: 450;
}

.bulkActions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bulkActions button {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  color: #6f6f75;
  background: rgba(0, 0, 0, 0.035);
  font-size: 12px;
  font-weight: 500;
}

.bulkActions button:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.06);
}

.bulkActions .dangerBulkBtn:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.memoCard:first-child {
  border-top: 0;
}

.memoCard:hover {
  background: #fdfdfc;
}

.memoCard.pinned {
  background: rgba(52, 199, 89, 0.018);
  border-top-color: rgba(52, 199, 89, 0.14);
}

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

.timeBtn {
  max-width: calc(100% - 48px);
  text-align: left;
}

.timeBtn:hover time {
  color: var(--soft-ink);
}

.memoActions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.favoriteMark {
  display: grid;
  place-items: center;
  margin-left: auto;
  color: #8e8e93;
  opacity: 0.55;
}

.favoriteMark svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.memoCard:hover .memoActions,
.memoCard:focus-within .memoActions,
.memoActions.menuOpen {
  opacity: 1;
}

.moreBtn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 22px;
  border-radius: var(--radius-sm);
  color: var(--subtle);
  transition: all 0.12s ease;
}

.insightBtn {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, background 0.15s ease;
}

.insightBtn::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.insightBtn:hover {
  background: var(--blue-bg);
}

.memoCard:hover .insightBtn,
.memoCard:focus-within .insightBtn {
  opacity: 1;
  pointer-events: auto;
}

.moreBtn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--soft-ink);
}

.memoMenuPanel {
  position: absolute;
  top: 26px;
  right: 0;
  z-index: 5;
  display: none;
  min-width: 120px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}

.memoActions.menuOpen .memoMenuPanel {
  display: grid;
  gap: 2px;
}

.memoMenuPanel button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.1s ease;
}

.memoMenuPanel button:hover {
  background: var(--surface);
  color: var(--ink);
}

.memoMenuPanel .deleteBtn:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.parentNoteSlot {
  margin: 2px 0 10px;
}

.parentNoteLink {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 30px;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(95, 134, 173, 0.08);
  color: #5e738a;
  text-align: left;
}

.parentNoteLink span {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 620;
}

.parentNoteLink strong {
  overflow: hidden;
  color: var(--soft-ink);
  font-size: 12.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.parentNoteLink:hover {
  background: rgba(95, 134, 173, 0.13);
}

.noteAnnotationSlot {
  margin-top: 10px;
}

.noteAnnotationList {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.025);
}

.noteAnnotationListTitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
}

.noteAnnotationItem {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--soft-ink);
  text-align: left;
}

.noteAnnotationItem:hover {
  background: rgba(255, 255, 255, 0.72);
}

.noteAnnotationItem time {
  color: var(--muted);
  font-size: 11.5px;
}

.noteAnnotationItem span {
  overflow: hidden;
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Memo text */
.memoText {
  white-space: pre-wrap;
  color: var(--soft-ink);
  font-family: var(--apple-font);
  font-size: 14.5px;
  line-height: 1.68;
  font-weight: 400;
  max-width: none;
}

.insightSummary {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.insightSummary time {
  color: var(--muted);
  font-size: 12px;
}

.insightSummary p {
  margin: 6px 0 0;
  color: var(--soft-ink);
  line-height: 1.55;
}

.insightGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.insightGrid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
}

.insightGrid strong {
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  font-weight: 620;
}

.insightGrid span,
.insightSection p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.insightSection {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--line);
}

.insightSection h3 {
  margin: 0 0 6px;
  color: var(--soft-ink);
  font-size: 14px;
  font-weight: 560;
}

.insightSection p {
  margin: 0;
}

.memoText strong {
  font-weight: 600;
}

.memoText u {
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.memoText mark,
.reviewBody mark {
  padding: 1px 4px 2px;
  border-radius: 4px;
  background: #ffe066;
  color: inherit;
}

.memoText .hash {
  display: inline-block;
  padding: 1px 5px 2px;
  border-radius: 5px;
  background: rgba(0, 122, 255, 0.06);
  color: #2b7ecb;
  font-family: var(--apple-font);
  font-size: 0.88em;
  font-weight: 450;
  line-height: 1.4;
}

.memoRef {
  display: inline-block;
  padding: 2px 7px 3px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--apple-font);
  font-size: 0.88em;
  font-weight: 500;
  line-height: 1.4;
  transition: all 0.12s ease;
}

.memoRef:hover {
  background: var(--line);
  color: var(--soft-ink);
}

.imageThumb {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 7px 0;
  vertical-align: top;
}

.memoImage {
  display: block;
  max-width: 72px;
  max-height: 72px;
  border: 0;
  border-radius: 0;
  object-fit: contain;
  background: transparent;
  cursor: zoom-in;
}

.imageZoomBtn {
  position: absolute;
  right: -9px;
  bottom: -9px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  opacity: 0.72;
  transition: opacity 0.14s ease, color 0.14s ease;
}

.imageZoomBtn::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(4px);
  transition: background 0.14s ease, box-shadow 0.14s ease;
}

.imageThumb:hover .imageZoomBtn,
.imageThumb:focus-within .imageZoomBtn {
  opacity: 1;
}

.imageZoomBtn:hover {
  color: var(--soft-ink);
}

.imageZoomBtn:hover::before {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.imageZoomBtn svg {
  position: relative;
  z-index: 1;
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* Edit panel */
.editPanel {
  position: relative;
  display: grid;
  gap: 10px;
}

.editTextarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: 0;
  color: var(--ink);
  background: var(--panel);
  font-family: var(--apple-font);
  font-size: 15px;
  line-height: 1.65;
  transition: border-color 0.15s ease;
}

.editTextarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.1);
}

.editActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.editActions button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--soft-ink);
  font-weight: 600;
  font-size: 13px;
  border: 1px solid var(--line);
}

.editActions .saveEditBtn {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.editPanel .editorTools {
  padding: 0;
}

.editPanel .draftImages {
  padding: 0;
}

.editPanel .selectionToolbar {
  top: 8px;
}

.memoTags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  min-height: 20px;
  margin-top: 10px;
}

.memoTags button {
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: #4e8fb9;
  font-weight: 430;
  font-size: 12px;
  line-height: 1.45;
}

.memoTags button:hover {
  color: #1f74aa;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.memoTags.isStatusOnly {
  gap: 0;
}

.tagStatus {
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.45;
}

.tagStatus.analyzing {
  color: #7c9885;
}

.tagStatus.failed {
  color: #b7826f;
}

.memoTags.isEditing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 7px;
  margin-top: 12px;
}

.tagEditInput {
  width: 100%;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: 0;
  background: rgba(255, 255, 255, 0.72);
  color: var(--soft-ink);
  font-family: var(--apple-font);
  font-size: 12.5px;
}

.tagEditInput:focus {
  border-color: rgba(52, 199, 89, 0.42);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.08);
}

.memoTags .saveTagsBtn,
.memoTags .cancelTagsBtn {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.035);
  color: var(--muted);
  font-size: 12px;
}

.memoTags .saveTagsBtn {
  background: rgba(52, 199, 89, 0.11);
  color: var(--green-dark);
}

.memoTags .saveTagsBtn:hover,
.memoTags .cancelTagsBtn:hover {
  background: rgba(0, 0, 0, 0.055);
  text-decoration: none;
}

/* Empty state */
.empty {
  margin-top: 12px;
  padding: 48px 20px;
  border-radius: var(--radius-lg);
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  text-align: center;
  box-shadow: var(--shadow-sm);
  font-size: 15px;
  font-weight: 500;
}

.emptyIcon svg {
  width: 44px;
  height: 44px;
  margin-bottom: 14px;
  fill: none;
  stroke: var(--subtle);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty p {
  margin: 6px 0;
}

.emptyHint {
  font-size: 13px;
  color: var(--subtle);
  margin-top: 4px;
}

/* Loading state */
.loadingState {
  display: grid;
  place-items: center;
  gap: 16px;
  padding: 60px 0;
}

.loadingSpinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: pm-spin 0.75s linear infinite;
}

@keyframes pm-spin {
  to { transform: rotate(360deg); }
}

.errorState .emptyIcon svg {
  stroke: var(--danger);
}

/* AI preview */
.agentPreview {
  margin: 8px 0;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
}

.agentPreviewHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
}

.agentPreviewHeader span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.agentPreviewCorpus {
  max-height: 240px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  font: 12.5px/1.65 var(--apple-font);
  white-space: pre-wrap;
  color: var(--soft-ink);
  border: 1px solid var(--line);
}

/* Review star button */
.reviewAge {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}

.reviewStarBtn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--line-strong);
  transition: color 0.15s ease, background 0.15s ease;
}

.reviewStarBtn:hover {
  background: rgba(255, 149, 0, 0.08);
}

.reviewStarBtn.starred {
  color: var(--warn);
}

.reviewStarBtn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reviewStarBtn.starred svg {
  fill: currentColor;
}

.metricStrip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}

.metricStrip div {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.metricStrip strong {
  color: var(--ink);
  font-size: 21px;
  line-height: 1;
}

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

.agentKeyRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.agentPreview {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--blue-bg);
  color: var(--soft-ink);
  font-size: 13px;
  line-height: 1.6;
}

.attachmentGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 72px);
  gap: 8px;
  margin-top: 8px;
}

.attachmentGrid .memoImage {
  max-width: 72px;
  max-height: 72px;
  object-fit: contain;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 200;
  max-width: 420px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  color: var(--soft-ink);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
}

.toast[hidden] {
  display: none;
}

.reviewFooterCenter {
  display: grid;
  gap: 10px;
  place-items: center;
}

#reviewCounter {
  color: #929297;
  font-size: 15px;
  line-height: 1;
  white-space: nowrap;
}

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

#reviewSkipBtn,
#reviewDoneBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: auto;
  min-width: 68px;
  height: 34px;
  padding: 0 13px;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  word-break: keep-all;
  border: 1px solid rgba(0, 0, 0, 0.055);
  transition: all 0.12s ease;
}

#reviewDoneBtn {
  background: var(--green-bg);
  color: var(--green-dark);
  border-color: rgba(52, 199, 89, 0.16);
}

#reviewSkipBtn:hover,
#reviewDoneBtn:hover {
  background: rgba(0, 0, 0, 0.045);
  color: var(--soft-ink);
}

#reviewSkipBtn svg,
#reviewDoneBtn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reviewEmpty {
  color: var(--muted);
  text-align: center;
  padding: 44px 0;
  font-size: 14px;
  font-weight: 500;
}

.sidebar,
.specialPanel,
.timeline,
.reviewCard,
.agentPreviewCorpus {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.sidebar::-webkit-scrollbar,
.specialPanel::-webkit-scrollbar,
.timeline::-webkit-scrollbar,
.reviewCard::-webkit-scrollbar,
.agentPreviewCorpus::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}

.sidebar::-webkit-scrollbar-track,
.specialPanel::-webkit-scrollbar-track,
.timeline::-webkit-scrollbar-track,
.reviewCard::-webkit-scrollbar-track,
.agentPreviewCorpus::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.specialPanel::-webkit-scrollbar-thumb,
.timeline::-webkit-scrollbar-thumb,
.reviewCard::-webkit-scrollbar-thumb,
.agentPreviewCorpus::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: transparent;
}

.sidebar.isScrolling,
.specialPanel.isScrolling,
.timeline.isScrolling,
.reviewCard.isScrolling,
.agentPreviewCorpus.isScrolling {
  scrollbar-color: rgba(0, 0, 0, 0.11) transparent;
}

.sidebar.isScrolling::-webkit-scrollbar-thumb,
.specialPanel.isScrolling::-webkit-scrollbar-thumb,
.timeline.isScrolling::-webkit-scrollbar-thumb,
.reviewCard.isScrolling::-webkit-scrollbar-thumb,
.agentPreviewCorpus.isScrolling::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.11);
}

/* === Responsive: phone layout ===
 *
 * Below 760px the sidebar stops being a grid column and becomes an off-canvas
 * drawer opened from the top bar. Same DOM, same nav buttons, same handlers —
 * only the presentation changes. The app frame keeps managing its own scroll so
 * the composer can never be pushed off-screen by a long timeline.
 */
@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .appShell {
    grid-template-columns: minmax(0, 1fr);
    /* `100vh` on iOS describes the keyboard-less viewport, which is how a
       bottom-anchored control ends up under the keyboard. Prefer the height the
       runtime measured from `visualViewport`. */
    height: 100vh;
    height: 100dvh;
    height: var(--app-viewport-height, 100dvh);
  }

  /* --- sidebar becomes a drawer --- */

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 120;
    width: min(320px, 88vw);
    height: auto;
    padding: calc(env(safe-area-inset-top) + 14px) 20px max(16px, env(safe-area-inset-bottom)) 22px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--panel);
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: var(--shadow-xl);
    transition: transform 0.22s ease;
    will-change: transform;
  }

  /* The desktop rule removes the column from the grid entirely; the drawer
     needs it to stay laid out so it can slide. */
  .appShell.sidebarHidden .sidebar {
    display: flex;
    transform: translateX(-102%);
    box-shadow: none;
  }

  .appShell:not(.sidebarHidden) .sidebar {
    transform: translateX(0);
  }

  .sidebarWindowBar {
    display: none;
  }

  .sidebarBackdrop {
    display: none;
  }

  .appShell:not(.sidebarHidden) .sidebarBackdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(0, 0, 0, 0.32);
  }

  /* The drawer is the only navigation on a phone, so its rows have to be
     comfortable thumb targets. */
  .navItem {
    min-height: 46px;
  }

  /* --- main pane --- */

  .mainPane {
    grid-template-rows: auto auto auto minmax(0, 1fr);
    padding: 0 16px max(12px, env(safe-area-inset-bottom));
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    height: auto;
    padding: calc(env(safe-area-inset-top) + 10px) 0 10px;
    background: var(--bg);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    -webkit-app-region: no-drag;
  }

  .topbarLeft {
    gap: 8px;
  }

  /* On the desktop these controls appear on hover; a touch screen can never
     hover, so they have to be pinned open. */
  .topbarControls {
    position: static;
    order: -1;
    opacity: 1;
    pointer-events: auto;
    transform: none;
    margin-right: 0;
  }

  /* Redundant with the drawer button, and there is no room for both. */
  #sidebarToggleBtn {
    display: none;
  }

  .searchBox {
    width: 100%;
    min-height: 40px;
  }

  .searchBox input {
    text-align: left;
  }

  .composer {
    margin: 8px 0 12px;
  }

  /* A drag-to-resize grip cannot be used by touch and only adds a stray mark. */
  .composer textarea,
  .composer:focus-within textarea {
    resize: none;
    padding: 14px 16px 4px;
  }

  .editorTools {
    padding: 0 12px;
  }

  .timeline {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* iOS zooms the whole page whenever a control smaller than 16px takes focus,
     and it never zooms back out — the user is then stuck in a horizontally
     scrolled layout. Several components legitimately use 13-15px on the
     desktop, so this is the one place where `!important` is the right tool: the
     platform constraint has to outrank any component's cosmetic size. */
  input,
  textarea,
  select {
    font-size: 16px !important;
  }

  /* --- dialogs --- */

  .reviewDialog {
    inset: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    grid-template-rows: 62px minmax(0, 1fr) 96px;
  }

  .relatedDialog {
    top: max(10px, env(safe-area-inset-top));
    width: calc(100vw - 20px);
    max-height: min(82vh, calc(var(--app-viewport-height, 100vh) - 20px));
  }

  .tagManagerDialog,
  .aiGuideDialog {
    width: calc(100vw - 20px);
    max-height: calc(var(--app-viewport-height, 100vh) - 20px);
  }

  .imageViewerDialog {
    inset: max(12px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom));
  }

  .imageViewerDialog img {
    max-width: calc(100vw - 16px);
    max-height: calc(var(--app-viewport-height, 100vh) - 24px);
  }

  /* Buttons that sit under the thumb need a real target, not a 34px sliver. */
  .editActions button,
  .tagCreateForm button,
  .aiGuideActions button {
    min-height: 42px;
  }
}

/* === Web runtime surfaces ===
 * Only the browser adapter renders these; the desktop app never shows them.
 */
.sidebarBackdrop {
  display: none;
}

.memoFlowGate {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background: var(--bg);
}

.memoFlowGateCard {
  width: min(360px, 100%);
  padding: 26px 24px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.memoFlowGateCard h2 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 620;
  color: var(--ink);
}

.memoFlowGateCard p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.65;
}

.memoFlowGateForm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 18px;
}

.memoFlowGateForm input {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
}

.memoFlowGateForm button,
.memoFlowGateRetry {
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--green);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
}

.memoFlowGateRetry {
  display: block;
  width: 100%;
  margin-top: 18px;
}

.memoFlowGateHint {
  margin-top: 14px !important;
  font-size: 12px !important;
  color: var(--subtle) !important;
}

