/* ─── Toggle switch (39 features) ─────────────────────────────────────── */
.toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px 0;
  cursor: pointer;
  user-select: none;
}
.toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.toggle__switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--anker-toggle-off);
  border-radius: var(--radius-pill);
  transition: background 160ms ease;
  flex-shrink: 0;
}
.toggle__switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #FFFFFF;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 160ms ease;
}
.toggle input:checked ~ .toggle__switch {
  background: var(--anker-toggle-on);
}
.toggle input:checked ~ .toggle__switch::after {
  transform: translateX(16px);
}
.toggle input:focus-visible ~ .toggle__switch {
  outline: 2px solid var(--anker-gold);
  outline-offset: 2px;
}
.toggle__label {
  font-size: 0.92rem;
  color: var(--anker-text);
}

/* ─── Tags / chips ─────────────────────────────────────────────────────── */
.tags-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: 6px 8px;
  background: var(--anker-bg);
  border: 1px solid var(--anker-border);
  border-radius: var(--radius-sm);
  position: relative;
}
.tags-input:focus-within {
  border-color: var(--anker-gold);
  box-shadow: 0 0 0 3px rgba(212, 160, 23, 0.15);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px 4px 10px;
  background: var(--anker-bg-soft);
  color: var(--anker-charcoal);
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
}
.chip__remove {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  font-size: 14px;
  line-height: 1;
  color: var(--anker-text-muted);
  cursor: pointer;
}
.chip__remove:hover {
  background: rgba(0,0,0,0.08);
  color: var(--anker-charcoal);
}
.tags-input__field {
  flex: 1 0 80px;
  min-width: 80px;
  padding: 4px 6px;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.92rem;
}
.tags-input__suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--anker-bg);
  border: 1px solid var(--anker-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 20;
}
.tags-input__suggestions[hidden] { display: none; }
.tags-input__suggestion {
  padding: 8px 12px;
  font-size: 0.92rem;
  cursor: pointer;
}
.tags-input__suggestion:hover,
.tags-input__suggestion[aria-selected="true"] {
  background: var(--anker-bg-soft);
}

/* ─── Photo card / dropzone ───────────────────────────────────────────── */
.photo-box {
  background: var(--anker-bg-soft);
  border: 1px solid var(--anker-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}
.photo-box__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-sm);
}
.photo-box__count {
  font-size: 0.82rem;
  color: var(--anker-text-muted);
  font-variant-numeric: tabular-nums;
}
.photo-dropzone {
  position: relative;
  border: 2px dashed var(--anker-border);
  border-radius: var(--radius-sm);
  padding: var(--space-lg);
  text-align: center;
  color: var(--anker-text-muted);
  background: var(--anker-bg);
  transition: border-color 120ms ease, background 120ms ease;
}
.photo-dropzone p { font-size: 0.9rem; pointer-events: none; }
.photo-dropzone:hover { border-color: var(--anker-gold); }
.photo-dropzone--dragover {
  border-color: var(--anker-gold);
  background: rgba(212, 160, 23, 0.08);
}
.photo-dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.photo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-sm);
  margin-top: var(--space-md);
  list-style: none;
}
.photo-list:empty { margin-top: 0; }
.photo-card {
  position: relative;
  border-radius: var(--radius-sm);
  background: var(--anker-bg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.photo-card__media {
  position: relative;
  aspect-ratio: 4/3;
  background: var(--anker-bg-soft2);
  overflow: hidden;
}
.photo-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-card__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 0.78rem;
  color: var(--anker-text-muted);
  text-align: center;
  padding: var(--space-sm);
}
.photo-card__drag {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}
.photo-card--no-drag .photo-card__drag { display: none; }
.photo-card__delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-card__delete:hover { background: var(--anker-error); }
.photo-card__progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(0,0,0,0.1);
}
.photo-card__progress > span {
  display: block;
  height: 100%;
  background: var(--anker-gold);
  transition: width 120ms ease;
  width: 0;
}
.photo-card__tag {
  padding: 6px 8px;
  border-top: 1px solid var(--anker-border);
  background: var(--anker-bg);
}
.photo-card__tag select,
.photo-card__tag input[type="text"] {
  padding: 4px 6px;
  font-size: 0.82rem;
  width: 100%;
}
.photo-card__tag-row {
  display: flex;
  gap: 4px;
}
.photo-card--ghost { opacity: 0.4; }

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 12px 24px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
  letter-spacing: 0.02em;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary {
  background: var(--anker-charcoal);
  color: #fff;
  border: 1px solid var(--anker-charcoal);
}
.btn--primary:hover:not(:disabled) {
  background: #2A2A2A;
  border-color: var(--anker-gold);
  color: var(--anker-gold-soft);
}
.btn--ghost {
  background: transparent;
  color: var(--anker-charcoal);
  border: 1px solid var(--anker-charcoal);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--anker-bg-soft);
}

/* ─── Submit summary ─────────────────────────────────────────────────── */
.submit-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--anker-bg-soft);
  border: 1px solid var(--anker-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
}
.summary-stat__num {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--anker-charcoal);
}
.summary-stat__label {
  font-size: 0.78rem;
  color: var(--anker-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.submit-warnings {
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--anker-error-bg);
  color: var(--anker-error);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.submit-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: flex-end;
  flex-wrap: wrap;
}
.submit-status {
  margin-top: var(--space-md);
  font-size: 0.92rem;
  min-height: 1.4em;
}
.submit-status--success { color: var(--anker-success); }
.submit-status--error { color: var(--anker-error); }

/* ─── Field errors ────────────────────────────────────────────────────── */
.field-error {
  display: block;
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--anker-error);
}
label.has-error input,
label.has-error select,
label.has-error textarea {
  border-color: var(--anker-error);
}

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast-host {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--anker-charcoal);
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  max-width: 320px;
  animation: toast-in 180ms ease;
}
.toast--error { background: var(--anker-error); }
.toast--success { background: var(--anker-success); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Error overlay ───────────────────────────────────────────────────── */
.error-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-md);
}
.error-overlay__card {
  background: var(--anker-bg);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.error-overlay__card h2 { margin-bottom: var(--space-md); }
.error-overlay__card p {
  margin-bottom: var(--space-lg);
  color: var(--anker-text-muted);
}
.error-overlay__actions {
  display: flex;
  justify-content: center;
  gap: var(--space-md);
}

/* ─── Phase-5: Topbar tab + autosave-status ─────────────────────────── */
.topbar__nav {
  display: flex;
  gap: var(--space-sm);
}
.topbar__tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: transparent;
  color: var(--anker-text-muted);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.topbar__tab:hover {
  color: var(--anker-charcoal);
  background: var(--anker-bg-soft);
}
.topbar__tab.is-active,
.topbar__tab[aria-current="true"] {
  color: var(--anker-charcoal);
  border-bottom-color: var(--anker-gold);
}
.topbar__status-block {
  display: flex;
  align-items: center;
  min-width: 160px;
  justify-content: flex-end;
}
.autosave-status {
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--anker-bg-soft);
  color: var(--anker-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background 160ms ease, color 160ms ease;
}
.autosave-status--idle    { background: var(--anker-bg-soft); color: var(--anker-text-muted); }
.autosave-status--saving  { background: rgba(212, 160, 23, 0.18); color: #8C6C0E; }
.autosave-status--saved   { background: var(--anker-success-bg); color: var(--anker-success); }
.autosave-status--error   { background: var(--anker-error-bg); color: var(--anker-error); }
.autosave-status--offline { background: #FDF3D9; color: #8C6C0E; }

/* ─── Phase-5: History modal ────────────────────────────────────────── */
.history-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.history-modal[hidden] { display: none; }
.history-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.55);
}
.history-modal__panel {
  position: relative;
  margin: var(--space-lg) auto;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  background: var(--anker-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.history-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--anker-border);
}
.history-modal__close {
  font-size: 24px;
  line-height: 1;
  color: var(--anker-text-muted);
  padding: 4px 10px;
}
.history-modal__close:hover { color: var(--anker-charcoal); }

.history-tabs {
  display: flex;
  gap: var(--space-sm);
  padding: 0 var(--space-lg);
  border-bottom: 1px solid var(--anker-border);
}
.history-tab {
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--anker-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.history-tab:hover { color: var(--anker-charcoal); }
.history-tab.is-active,
.history-tab[aria-selected="true"] {
  color: var(--anker-charcoal);
  border-bottom-color: var(--anker-gold);
}
.history-tab .cnt {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  background: var(--anker-bg-soft);
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  color: var(--anker-text-muted);
  font-variant-numeric: tabular-nums;
}

.history-filter {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--anker-border);
  background: var(--anker-bg-soft);
}
.history-filter label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--anker-text-muted);
}
.history-filter label > span { margin-bottom: 0; text-transform: none; letter-spacing: normal; }
.history-filter select {
  width: auto;
  padding: 4px 28px 4px 10px;
  font-size: 0.85rem;
}
.btn--sm {
  padding: 4px 10px;
  font-size: 0.78rem;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title actions" "meta meta";
  gap: 4px var(--space-md);
  padding: var(--space-md);
  background: var(--anker-bg);
  border: 1px solid var(--anker-border);
  border-radius: var(--radius-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.history-row:hover {
  border-color: var(--anker-gold);
  box-shadow: var(--shadow-sm);
}
.history-row__title {
  grid-area: title;
  font-weight: 600;
  color: var(--anker-charcoal);
}
.history-row__meta {
  grid-area: meta;
  font-size: 0.82rem;
  color: var(--anker-text-muted);
}
.history-row__actions {
  grid-area: actions;
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}
.history-row__nolink {
  font-size: 0.82rem;
  color: var(--anker-text-muted);
  font-style: italic;
}
.history-empty,
.history-loading,
.history-error {
  padding: var(--space-lg);
  text-align: center;
  color: var(--anker-text-muted);
  font-size: 0.9rem;
}
.history-error { color: var(--anker-error); }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--anker-bg-soft);
  color: var(--anker-text-muted);
}
.badge--current {
  background: var(--anker-success-bg);
  color: var(--anker-success);
}

/* ─── Phase-5: Conflict modal (above history-modal) ─────────────────── */
.conflict-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}
.conflict-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.65);
}
.conflict-modal__panel {
  position: relative;
  background: var(--anker-bg);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  max-width: 540px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.conflict-modal__panel h2 {
  margin-bottom: var(--space-md);
}
.conflict-modal__panel p {
  margin-bottom: var(--space-md);
}
.conflict-modal__editor { color: var(--anker-charcoal); }
.conflict-modal__ts { font-variant-numeric: tabular-nums; }
.conflict-modal__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}
.conflict-modal__details {
  margin-top: var(--space-md);
  font-size: 0.85rem;
}
.conflict-modal__details summary {
  cursor: pointer;
  color: var(--anker-text-muted);
}
.conflict-modal__diff {
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  background: var(--anker-bg-soft);
  border-radius: var(--radius-sm);
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
  color: var(--anker-text);
}

/* ─── Phase-5: Active-editor banner (above topbar) ──────────────────── */
.active-editor-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  background: #FFF8E1;
  border-bottom: 1px solid #E6BD52;
  color: #5C4400;
  font-size: 0.88rem;
}
.active-editor-banner__msg {
  flex: 1;
}
.active-editor-banner__name {
  font-weight: 700;
  margin-right: 4px;
}

/* ─── Responsive: history-modal ─────────────────────────────────────── */
@media (max-width: 720px) {
  .history-modal__panel {
    margin: 0;
    max-height: 100vh;
    width: 100vw;
    border-radius: 0;
  }
  .history-row {
    grid-template-columns: 1fr;
    grid-template-areas: "title" "meta" "actions";
  }
  .history-row__actions {
    justify-content: flex-start;
  }
  .topbar { flex-wrap: wrap; }
  .topbar__nav, .topbar__status-block, .topbar__taskmeta { flex-basis: auto; }
  .topbar__title { flex-basis: 100%; order: 0; }
  .topbar__nav { order: 1; }
  .topbar__status-block { order: 2; min-width: 120px; }
  .topbar__taskmeta { order: 3; }
}

/* ─── Phase-3-polish: Render-progress modal ──────────────────────────── */
.render-progress {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}
.render-progress[hidden] { display: none; }
.render-progress__overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.6);
}
.render-progress__panel {
  position: relative;
  background: var(--anker-bg);
  padding: var(--space-xl);
  border-radius: var(--radius-md);
  max-width: 460px;
  width: 92%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.render-progress__logo {
  height: 36px;
  width: auto;
  margin: 0 auto var(--space-md);
  display: block;
}
.render-progress__title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin-bottom: var(--space-sm);
  color: var(--anker-charcoal);
}
.render-progress__stages {
  list-style: none;
  padding: 0;
  margin: var(--space-md) 0;
  text-align: left;
}
.render-progress__stages li {
  padding: 6px 0;
  font-size: 0.92rem;
  color: var(--anker-text-muted);
  display: flex;
  gap: 10px;
  align-items: center;
}
.render-progress__stages li::before {
  content: '○';
  width: 18px;
  text-align: center;
  color: var(--anker-border);
  flex-shrink: 0;
}
.render-progress__stages li.is-active {
  color: var(--anker-charcoal);
  font-weight: 600;
}
.render-progress__stages li.is-active::before {
  content: '⟳';
  color: var(--anker-gold);
  animation: rp-spin 1s linear infinite;
}
.render-progress__stages li.is-done {
  color: var(--anker-text-muted);
}
.render-progress__stages li.is-done::before {
  content: '✓';
  color: var(--anker-success);
}
.render-progress__stages .hint {
  font-size: 0.78rem;
  color: var(--anker-text-muted);
  font-weight: 400;
  margin-left: 4px;
}
.render-progress__bar {
  height: 4px;
  background: var(--anker-border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--space-md);
}
.render-progress__bar > span {
  display: block;
  height: 100%;
  background: var(--anker-gold);
  width: 0;
  transition: width 800ms ease-out;
}
.render-progress__msg {
  margin-top: var(--space-md);
  font-size: 0.85rem;
  color: var(--anker-text-muted);
}
.render-progress__actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--space-lg);
}
.render-progress--error .render-progress__title {
  color: var(--anker-error);
}
.render-progress--error .render-progress__bar > span {
  background: var(--anker-error);
}

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

@media (max-width: 480px) {
  .render-progress__panel { padding: var(--space-lg); }
  .render-progress__actions .btn { flex: 1 1 auto; }
}
