/* Editor layout on top of the reading site's tokens in style.css */

body.editor main { max-width: calc(var(--wide) + 2rem); }

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.badge {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0 0.55rem;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.04em;
}
.editor-nav { display: flex; align-items: center; gap: 1.25rem; font-size: 0.95rem; }
.editor-nav form { margin: 0; }
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.link-button:hover { color: var(--text); }

.editor-title { display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 1.5rem; }
.editor-title .count { color: var(--muted); }

.work-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.work-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
  padding: 0 0.75rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
.work-table td { padding: 0.8rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.work-table tbody tr:hover { background: var(--surface); }
.title-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.work-title { font-weight: 600; }

.state { font-size: 0.85rem; border-radius: 999px; padding: 0.05rem 0.6rem; }
.state.live { color: var(--accent); background: var(--accent-soft); }
.state.draft { color: var(--muted); border: 1px solid var(--line); }

.login {
  max-width: 22rem;
  margin: 4rem auto 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login h1 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.login input {
  padding: 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}
.login input:focus { outline: none; border-color: var(--accent); }
.login button {
  padding: 0.75rem;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #0b1422;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.login .error { margin: 0; color: #f0a0a0; font-size: 0.95rem; }

@media (max-width: 640px) {
  .work-table th:nth-child(3), .work-table td:nth-child(3),
  .work-table th:nth-child(4), .work-table td:nth-child(4) { display: none; }
}

/* ── Shared controls ─────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 100ms, background 100ms;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: 0.4; cursor: default; border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1422; font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn.danger { color: #f0a0a0; }
.btn.danger:hover, .btn.armed { border-color: #e07a7a; }
.btn.armed { background: rgba(224, 122, 122, 0.15); color: #f6c0c0; }
.btn.primary.armed { background: #f0c674; border-color: #f0c674; color: #1d1608; }
[hidden] { display: none !important; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { color: var(--text); border-color: var(--line); }
.icon-btn:disabled { opacity: 0.25; cursor: default; }
.icon-btn.danger:hover { color: #f0a0a0; }
.icon-btn.armed { width: auto; padding: 0 0.6rem; color: #f6c0c0; border-color: #e07a7a; background: rgba(224, 122, 122, 0.15); font: inherit; font-size: 0.85rem; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg circle { fill: currentColor; stroke: none; }

.crumb { display: inline-block; margin-bottom: 0.75rem; font-size: 0.95rem; }
.crumb::before { content: '\2190  '; }

.changes-dot { width: 8px; height: 8px; border-radius: 50%; background: #f0c674; flex: none; }
.new-bar { width: 14px; height: 3px; border-radius: 2px; background: var(--accent); flex: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 1rem);
  padding: 0.6rem 1.1rem;
  background: var(--surface-hover);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms, transform 150ms;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: #e07a7a; }

/* ── Dashboard ───────────────────────────────────────────────── */

.editor-title { flex-wrap: wrap; align-items: center; }
.editor-title h1 { margin-right: 0.25rem; }
.new-work { display: flex; gap: 0.5rem; margin-left: auto; }
.new-work input, .inline-form input, .field input, .field textarea {
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}
.new-work input:focus, .inline-form input:focus, .field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.row-link { cursor: pointer; }
.work-title { color: var(--text); }
.work-title:hover { color: var(--accent); text-decoration: none; }
.work-state { display: contents; }
.view-live { font-size: 0.95rem; margin-left: auto; }

/* ── Work settings ───────────────────────────────────────────── */

.work-editor, .chapter-editor { max-width: 46rem; margin: 0 auto; position: relative; }

.panel {
  margin-bottom: 1.25rem;
  padding: 1.25rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.panel h2 { font-size: 1.05rem; color: var(--text-soft); margin-bottom: 0.9rem; }

.chapter-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.chapter-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.25rem 0.45rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
.chapter-list li:first-child { border-top: 1px solid var(--line); }
.chapter-link { flex: 1; display: flex; align-items: center; gap: 0.6rem; color: var(--text); min-width: 0; }
.chapter-link:hover { color: var(--accent); text-decoration: none; }
.chapter-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-tools { display: flex; gap: 0.1rem; }

.inline-form { display: flex; gap: 0.5rem; }
.inline-form input { flex: 1; min-width: 0; }

.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; flex: 1; }
.field > span { color: var(--muted); font-size: 0.85rem; }
.field textarea { resize: vertical; line-height: 1.5; }
.field-row { display: flex; gap: 1rem; }
.slug-input { display: flex; align-items: center; background: var(--surface); }
.slug-prefix { color: var(--muted); font-size: 0.9rem; padding-right: 0.15rem; }
.slug-input input { flex: 1; min-width: 0; }
.field-status { margin: 0; min-height: 1.2em; color: var(--accent); font-size: 0.9rem; }

.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.4rem 0; }
.settings-row p { margin: 0; color: var(--text-soft); font-size: 0.95rem; }

/* ── Chapter editor ──────────────────────────────────────────── */

.chapter-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
/* Titles are edited by clicking on them, on both the work and chapter pages */
.title-input {
  flex: 1;
  min-width: 0;
  padding: 0.2rem 0;
  background: none;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--text);
  font: inherit;
  font-size: 2rem;
  font-weight: 600;
}
.title-input:hover { border-bottom-color: var(--line); }
.title-input:focus { outline: none; border-bottom-color: var(--accent); }
.editor-title .title-input { flex: 1 1 12rem; }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  padding: 0.45rem;
  margin: 0 -0.45rem 1.5rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tool-group { display: flex; gap: 0.15rem; }
.tool-group + .tool-group { padding-left: 0.75rem; border-left: 1px solid var(--line); }
.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 0.4rem;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-soft);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.tool sub { font-size: 0.6em; }
.tool:hover { background: var(--surface); color: var(--text); }
.tool.on { background: var(--accent-soft); color: var(--accent); border-color: rgba(111, 168, 255, 0.35); }
.tool .swatch-line { stroke: var(--accent); stroke-width: 2.5; }

.palette-wrap { position: relative; }
.palette {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  display: flex;
  gap: 0.35rem;
  padding: 0.45rem;
  background: var(--surface-hover);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.swatch {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: transform 100ms, filter 100ms;
}
.swatch:hover { transform: scale(1.15); filter: brightness(1.35); }
.swatch.text { background: var(--bg); font: inherit; font-weight: 600; font-size: 1rem; }
.swatch.none { display: inline-flex; align-items: center; justify-content: center; background: var(--bg); color: var(--muted); }

.link-pop {
  position: absolute;
  z-index: 20;
  display: flex;
  gap: 0.4rem;
  width: 340px;
  max-width: 100%;
  padding: 0.5rem;
  background: var(--surface-hover);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.link-pop input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
.link-pop input:focus { outline: none; border-color: var(--accent); }
.link-pop .btn { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.editor-surface {
  min-height: 50vh;
  padding-bottom: 6rem;
  outline: none;
  caret-color: var(--accent);
}
.editor-surface hr { cursor: default; }

.publish-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.8rem 0;
  /* Solid, so words scroll cleanly behind it instead of under a line */
  background: var(--bg);
  box-shadow: 0 -12px 16px -4px var(--bg);
}
.save-status { color: var(--muted); font-size: 0.9rem; }
.publish-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-left: auto; }

@media (max-width: 640px) {
  .new-work { margin-left: 0; width: 100%; }
  .new-work input { flex: 1; min-width: 0; }
  .field-row { flex-direction: column; gap: 0; }
  .title-input { font-size: 1.5rem; }
  .publish-actions .btn { flex: 1; }
}

/* ── Connector authorization ─────────────────────────────────── */

.connect-note { margin: 0; color: var(--text-soft); font-size: 0.95rem; line-height: 1.6; }
.login-form { display: flex; flex-direction: column; gap: 0.9rem; }
.login .deny { background: none; border: 1px solid var(--line); color: var(--text-soft); font-weight: 400; }
.login .deny:hover { border-color: var(--accent); color: var(--text); }
