/* 历史管理：浅金主题的列表、操作菜单与编辑对话框。 */
#historyList .history-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 1px;
  min-width: 0;
  margin: 0 0 5px;
  padding: 2px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  transition: background-color 150ms ease, border-color 150ms ease;
}
#historyList .history-entry:hover,
#historyList .history-entry:focus-within {
  background: #fbf4e5;
  border-color: var(--gold-edge-soft, #e9dfca);
}
#historyList .history-entry.active {
  background: #f3e7cb;
  border-color: #d7bf8e;
}
html.white-controls body.master-edition #historyList .history-item,
html.white-controls body.master-edition #historyList .history-item:hover,
html.white-controls body.master-edition #historyList .history-item.active {
  display: block;
  min-width: 0;
  min-height: 48px;
  width: 100%;
  margin: 0;
  padding: 9px 7px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  color: var(--gold-text, #624f38);
  text-align: left;
}
#historyList .history-item strong {
  display: block;
  overflow: hidden;
  color: var(--gold-ink, #4d3c2b);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.7;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#historyList .history-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 7px;
  margin-top: 4px;
  color: var(--gold-muted, #78654e);
  font-size: 12px;
  line-height: 1.6;
}
#historyList .history-meta small {
  display: inline;
  margin: 0;
  color: inherit;
  font: inherit;
}
#historyList .history-item .history-note {
  display: -webkit-box;
  overflow: hidden;
  margin: 5px 0 0;
  color: var(--gold-muted, #78654e);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
#historyList :is(.history-pin, .history-pin-mark) {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  margin: 0;
  padding: 0 5px;
  border: 1px solid #d6bc86;
  border-radius: 4px;
  background: #f7edda;
  color: #77592d;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.65;
  white-space: nowrap;
}
html.white-controls body.master-edition #historyList .history-options {
  display: grid;
  place-items: center;
  align-self: start;
  min-width: 36px;
  width: 36px;
  min-height: 40px;
  margin: 3px 0 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  color: #826a47;
  cursor: pointer;
}
html.white-controls body.master-edition #historyList .history-options:hover,
html.white-controls body.master-edition #historyList .history-options[aria-expanded="true"] {
  border-color: #d8c49a;
  background: #f1e3c4;
  box-shadow: none;
  color: #604625;
}
#historyList .history-options svg { width: 18px; height: 18px; pointer-events: none; }
#historyList :is(.history-item, .history-options):focus-visible {
  outline: 2px solid var(--gold-focus, #946e35);
  outline-offset: 1px;
}

/* 位置由交互代码计算，保持菜单可贴近三点按钮或右键位置。 */
#historyActionMenu.history-action-menu {
  position: fixed;
  z-index: 180;
  box-sizing: border-box;
  width: 180px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 16px);
  overflow: auto;
  padding: 5px;
  border: 1px solid #d9c69f;
  border-radius: 10px;
  background: var(--gold-paper, #fffdf7);
  color: var(--gold-ink, #4d3c2b);
  box-shadow: 0 8px 28px #63452124, 0 2px 6px #6345210c;
}
#historyActionMenu[hidden] { display: none !important; }
html.white-controls body.master-edition #historyActionMenu button {
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  width: 100%;
  min-height: 40px;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  box-shadow: none;
  color: var(--gold-text, #624f38);
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
}
html.white-controls body.master-edition #historyActionMenu button:hover,
html.white-controls body.master-edition #historyActionMenu button:focus-visible {
  border-color: #e1cea5;
  background: #f5ead2;
  box-shadow: none;
  color: #5b4226;
}
#historyActionMenu button:focus-visible {
  outline: 2px solid var(--gold-focus, #946e35);
  outline-offset: -2px;
}
html.white-controls body.master-edition #historyActionMenu button[data-history-action="delete"] { color: #96523b; }
html.white-controls body.master-edition #historyActionMenu button[data-history-action="delete"]:is(:hover, :focus-visible) {
  border-color: #e6c9b9;
  background: #fbede5;
  color: #85402d;
}
#historyActionMenu button svg { flex: 0 0 auto; width: 16px; height: 16px; pointer-events: none; }

#historyEditDialog.history-edit-dialog {
  box-sizing: border-box;
  width: min(430px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  margin: auto;
  padding: 25px;
  border: 1px solid #d7c196;
  border-radius: 15px;
  background: var(--gold-paper, #fffdf7);
  color: var(--gold-ink, #4d3c2b);
  box-shadow: 0 18px 60px #50391c30, 0 3px 12px #50391c0e;
}
#historyEditDialog::backdrop { background: #3f30244d; backdrop-filter: blur(3px); }
#historyEditDialog form { min-width: 0; margin: 0; }
#historyEditDialog [hidden] { display: none !important; }
#historyEditDialog #historyEditTitle {
  margin: 0 0 19px;
  color: var(--gold-ink, #4d3c2b);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.5;
}
#historyEditDialog label {
  display: block;
  margin: 15px 0 7px;
  color: var(--gold-text, #624f38);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
}
#historyEditDialog :is(input, textarea) {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 11px;
  border: 1px solid #d9c6a0;
  border-radius: 8px;
  background: #fffefb;
  box-shadow: inset 0 1px 2px #6f522508;
  color: var(--gold-ink, #4d3c2b);
  font: inherit;
  font-size: 16px;
  line-height: 1.7;
}
#historyEditDialog textarea { min-height: 150px; max-height: 36vh; resize: vertical; }
#historyEditDialog :is(input, textarea)::placeholder { color: #847057; opacity: 1; }
#historyEditDialog :is(input, textarea):focus-visible {
  outline: 2px solid var(--gold-focus, #946e35);
  outline-offset: 2px;
}
#historyEditDialog p {
  margin: 10px 0 0;
  color: var(--gold-muted, #78654e);
  font-size: 12px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}
#historyEditDialog .history-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 23px;
}
html.white-controls body.master-edition #historyEditDialog .history-edit-actions button {
  min-width: 76px;
  min-height: 42px;
  margin: 0;
  padding: 9px 17px;
  border: 1px solid #d8c6a0;
  border-radius: 8px;
  background: #fffdf7;
  box-shadow: 0 2px 4px #72512707;
  color: var(--gold-text, #624f38);
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
}
html.white-controls body.master-edition #historyEditDialog .history-edit-actions button:last-child {
  border-color: #c6a76a;
  background: #ecd9ae;
  color: #503a21;
  font-weight: 600;
}
html.white-controls body.master-edition #historyEditDialog .history-edit-actions button:hover {
  border-color: #bca16b;
  background: #f3e6ca;
  box-shadow: 0 2px 5px #7251270b;
}
html.white-controls body.master-edition #historyEditDialog .history-edit-actions button:last-child:hover { background: #e4ca94; }
#historyEditDialog .history-edit-actions button:focus-visible {
  outline: 2px solid var(--gold-focus, #946e35);
  outline-offset: 3px;
}
#historyEditDialog.is-delete #historyEditTitle { color: #854a35; }
#historyEditDialog .history-delete-warning { color: #854a35; font-size: 14px; }
html.white-controls body.master-edition #historyEditDialog.is-delete .history-edit-actions button:last-child {
  border-color: #d5a78f;
  background: #f5dfd2;
  color: #85402d;
}
html.white-controls body.master-edition #historyEditDialog.is-delete .history-edit-actions button:last-child:hover {
  border-color: #c58e71;
  background: #edc9b7;
  color: #743522;
}
#historyEditDialog .history-edit-actions button:disabled { opacity: .55; cursor: wait; }

@media (max-width: 600px) {
  #historyList .history-entry { grid-template-columns: minmax(0, 1fr) 40px; }
  html.white-controls body.master-edition #historyList .history-options { width: 40px; min-height: 42px; }
  html.white-controls body.master-edition #historyActionMenu button { min-height: 44px; font-size: 14px; }
  #historyEditDialog.history-edit-dialog { width: calc(100vw - 24px); padding: 21px 19px; border-radius: 13px; }
  #historyEditDialog #historyEditTitle { font-size: 19px; }
  #historyEditDialog .history-edit-actions { gap: 10px; margin-top: 21px; }
  html.white-controls body.master-edition #historyEditDialog .history-edit-actions button { flex: 1; min-height: 44px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  #historyList .history-entry,
  #historyList button,
  #historyActionMenu button,
  #historyEditDialog button { transition: none; }
}
