/* Fusion Hub selection AI-menu, correction workflow, and local bookmarks.
   Reuses hub.css design tokens (--accent/--ink/--muted/--surface) and the
   .primary-button / .quiet-button / .danger-button / .form-message classes. */

/* Selection dot-menu — a fixed-position child of #detailDialog so it paints
   in the modal's top-layer subtree and tracks the live selection rect. */
.hub-ai-dot {
  position: fixed;
  z-index: 5;
  display: flex;
  gap: 0.15rem;
  padding: 0.2rem;
  border-radius: 999px;
  background: var(--ink);
  box-shadow: var(--shadow);
}
.hub-ai-dot button {
  border: 0;
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
  background: transparent;
  color: #fff;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.hub-ai-dot button:hover { background: rgba(255, 255, 255, 0.16); }

/* Explain panel docked bottom-right inside the detail dialog. */
.hub-ai-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 6;
  width: min(440px, calc(100vw - 2rem));
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hub-ai-panel[hidden],
.hub-ai-dot[hidden] { display: none !important; }
.hub-ai-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}
.hub-ai-panel-head strong { font-size: 0.85rem; }
.hub-ai-panel-head .hub-ai-quota-tag {
  font-size: 0.68rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.hub-ai-panel-body {
  padding: 0.8rem;
  overflow: auto;
  font-size: 0.86rem;
  line-height: 1.6;
  color: var(--ink);
}
.hub-ai-panel-body .hub-ai-loading { color: var(--muted); }
.hub-ai-panel-body .hub-ai-error { color: var(--accent); }
.hub-ai-result h1, .hub-ai-result h2, .hub-ai-result h3 { margin: 0.6rem 0 0.3rem; line-height: 1.3; }
.hub-ai-result h1 { font-size: 1rem; } .hub-ai-result h2 { font-size: 0.95rem; } .hub-ai-result h3 { font-size: 0.9rem; }
.hub-ai-result p { margin: 0.4rem 0; }
.hub-ai-result ul, .hub-ai-result ol { margin: 0.4rem 0; padding-left: 1.2rem; }
.hub-ai-result pre {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  overflow: auto;
  font-size: 0.8rem;
}
.hub-ai-result code { font-family: "JetBrains Mono", monospace; }
.hub-ai-result :not(pre) > code {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 0.8rem;
}
.hub-ai-panel-foot {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}
.hub-ai-close { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; cursor: pointer; }

/* Bookmark star in the explain panel header. */
.hub-ai-bookmark {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0 0.1rem;
  line-height: 1;
}
.hub-ai-bookmark:hover { opacity: 0.7; }

/* Bookmark cards in the saved-explanations dialog. */
.hub-ai-bookmark-card {
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.8rem;
}
.hub-ai-bookmark-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.hub-ai-bookmark-date { color: var(--muted); font-size: 0.72rem; }
.hub-ai-bookmark-record {
  flex: 1;
  color: var(--muted);
  font-size: 0.74rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hub-ai-bookmark-card .hub-ai-quote {
  font-size: 0.76rem;
  margin-bottom: 0.4rem;
}
.hub-ai-bookmark-card .hub-ai-result {
  font-size: 0.82rem;
  line-height: 1.55;
  max-height: 12rem;
  overflow: auto;
}
.hub-ai-bookmark-card .danger-button {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  flex-shrink: 0;
}
.hub-ai-bookmark-card + .hub-ai-bookmark-card { margin-top: 0.5rem; }

/* Correction + key dialogs share the hub .dialog chrome. */
.hub-ai-correction pre, .hub-ai-correction .hub-ai-quote {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  margin: 0.3rem 0 0.6rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: pre-wrap;
}
.hub-ai-correction label {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.hub-ai-correction input, .hub-ai-correction textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
}
.hub-ai-correction input:focus, .hub-ai-correction textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.hub-ai-correction textarea { min-height: 5rem; resize: vertical; }
.hub-ai-checkbox { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.6rem; font-size: 0.8rem; color: var(--ink); }
.hub-ai-checkbox input { width: auto; margin: 0; }

.hub-ai-bookmarks-empty { color: var(--muted); font-size: 0.8rem; padding: 0.4rem 0; }

/* Registered-account AI explanation and feedback activity. */
.hub-ai-history-dialog { width: min(820px, calc(100vw - 2rem)); }
.hub-ai-history-content { display: grid; gap: 1rem; }
.hub-ai-history-section { display: grid; gap: 0.55rem; }
.hub-ai-history-section-heading,
.hub-ai-history-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.hub-ai-history-section-heading h3 { margin: 0; font-size: 0.95rem; }
.hub-ai-history-count,
.hub-ai-history-status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.16rem 0.48rem;
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--muted);
  background: var(--surface-soft);
}
.hub-ai-history-status.is-processing,
.hub-ai-history-status.is-proofreading,
.hub-ai-history-status.is-publishing { color: #875f13; border-color: #e7cf8a; background: #fff8df; }
.hub-ai-history-status.is-completed { color: #1f6e50; border-color: #a8d8c5; background: #effaf4; }
.hub-ai-history-status.is-failed { color: var(--accent); border-color: #e6bbb5; background: var(--accent-soft); }
.hub-ai-history-card {
  min-width: 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.82rem;
}
.hub-ai-history-card strong { overflow-wrap: anywhere; }
.hub-ai-history-meta,
.hub-ai-history-record { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.74rem; }
.hub-ai-history-summary { margin: 0.65rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.hub-ai-history-card .hub-ai-quote {
  margin: 0.65rem 0;
  padding: 0.5rem 0.6rem;
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.hub-ai-history-card .hub-ai-result { max-height: 16rem; overflow: auto; }
.hub-ai-history-log,
.hub-ai-history-feedback-detail { margin-top: 0.65rem; }
.hub-ai-history-log summary,
.hub-ai-history-feedback-detail summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.hub-ai-history-events { display: grid; gap: 0.45rem; margin: 0.65rem 0 0; padding-left: 1.25rem; }
.hub-ai-history-events li { display: grid; gap: 0.1rem; overflow-wrap: anywhere; }
.hub-ai-history-events time { color: var(--muted); font-size: 0.72rem; }
.hub-ai-history-pr { display: inline-block; margin-top: 0.7rem; color: var(--accent); font-weight: 600; }

@media (max-width: 560px) {
  .hub-ai-history-dialog { width: min(100vw - 1rem, 820px); padding: 1rem; }
  .hub-ai-history-section-heading,
  .hub-ai-history-card-head { flex-direction: column; }
  .hub-ai-history-status { align-self: flex-start; }
}

/* ---------------------------------------------------------------------------
   Standalone code pages (codes/*.html) don't load hub.css, so this block gives
   hub-ai.css + the correction dialog the tokens and .dialog chrome they
   depend on. Scoped under body.hub-standalone so it never affects the Hub page.
   ------------------------------------------------------------------------- */
body.hub-standalone {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-soft: #faf9f6;
  --ink: #17211e;
  --muted: #66716d;
  --accent: #9f3029;
  --accent-soft: #f6e9e5;
  --line: #ddd9d2;
  --danger: #a12e2e;
  --shadow: 0 18px 50px rgba(31, 27, 23, 0.12);
}
body.hub-standalone .hub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  max-width: 900px;
  margin: 0 auto;
  padding: 0.6rem 1.2rem;
  font-size: 0.82rem;
}
body.hub-standalone .hub-header a { color: var(--accent); font-weight: 600; }
body.hub-standalone .feedback-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  padding: 0.65rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
  cursor: pointer;
}
body.hub-standalone .dialog {
  width: min(680px, calc(100vw - 2rem));
  max-height: min(86vh, 900px);
  padding: 1.4rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: auto;
}
body.hub-standalone .dialog::backdrop { background: rgba(20, 24, 22, 0.48); }
body.hub-standalone .dialog-close {
  position: sticky;
  top: 0;
  z-index: 2;
  display: block;
  margin-left: auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #efede8;
  color: var(--ink);
  font-size: 1.25rem;
  cursor: pointer;
}
body.hub-standalone .dialog-heading { margin: -1.6rem 2.5rem 1rem 0; }
body.hub-standalone .dialog-heading h2 { font-family: Georgia, serif; font-size: 1.15rem; }
body.hub-standalone .dialog-heading p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.8rem; }
body.hub-standalone .eyebrow {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
body.hub-standalone .primary-button,
body.hub-standalone .quiet-button,
body.hub-standalone .danger-button {
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
body.hub-standalone .primary-button { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
body.hub-standalone .quiet-button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
body.hub-standalone .danger-button { border: 1px solid #e2b9b9; background: #fff5f5; color: var(--danger); }
body.hub-standalone .primary-button:disabled,
body.hub-standalone .quiet-button:disabled { opacity: 0.45; cursor: not-allowed; }
body.hub-standalone .dialog-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
body.hub-standalone .form-message { min-height: 1.4em; color: var(--muted); font-size: 0.75rem; }
body.hub-standalone .hub-ai-quote { font-size: 0.82rem; }
