/* ── Interactive Source & Catalog Studio (Amber Material 3) ──────────────── */

.builder-wrap {
  max-width: 1240px;
}

/* ── Studio Header ───────────────────────────────────────────────────────── */

.studio-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  padding: 28px 0 20px;
}

.studio-hero-main {
  max-width: 640px;
}

.studio-hero .eyebrow {
  margin-bottom: 10px;
}

.studio-hero h1 {
  font-size: clamp(28px, 3.6vw, 38px);
  margin: 0 0 8px;
}

.studio-hero .intro {
  max-width: 600px;
  font-size: 15px;
  line-height: 1.55;
}

.studio-hero-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.studio-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.draft-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
}

.draft-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--secondary);
  display: inline-block;
}

/* ── Unified Studio Button System (Overrides base button styles cleanly) ─── */

.studio-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.studio-btn.sm {
  padding: 7px 13px;
  font-size: 12.5px;
  border-radius: 10px;
}

.studio-btn.primary {
  background: var(--primary);
  color: var(--on-primary);
}

.studio-btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 5px 14px rgba(138, 75, 8, 0.2);
}

.studio-btn.tonal {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: #dec197;
}

.studio-btn.tonal:hover:not(:disabled) {
  background: #efd0a3;
  box-shadow: none;
}

.studio-btn.ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.studio-btn.ghost:hover:not(:disabled) {
  background: var(--primary-container);
  border-color: #cca876;
  color: var(--on-primary-container);
  box-shadow: none;
}

.studio-btn.danger-ghost {
  background: var(--surface);
  color: var(--error);
  border-color: #e4c3c3;
}

.studio-btn.danger-ghost:hover:not(:disabled) {
  background: var(--error-bg);
  border-color: #d9a0a0;
  color: var(--error);
  box-shadow: none;
}

/* ── 3-Step Guided Studio Navigation ─────────────────────────────────────── */

.step-nav {
  display: flex;
  gap: 10px;
  padding: 6px;
  background: var(--surface-container);
  border: 1px solid var(--line);
  border-radius: 18px;
  margin-bottom: 24px;
  overflow-x: auto;
}

.step-tab {
  flex: 1;
  min-width: 175px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  box-shadow: none;
}

.step-tab:hover:not(:disabled) {
  background: rgba(255, 253, 249, 0.65);
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

.step-tab.active,
.step-tab.active:hover {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
  transform: none;
}

.step-num-pill {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-high);
  color: var(--muted);
  flex-shrink: 0;
}

.step-tab.active .step-num-pill {
  background: var(--primary);
  color: var(--on-primary);
}

.step-status-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.35;
}

.step-status-pill.ok {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.step-status-pill.err {
  background: var(--error-bg);
  color: var(--error);
}

.step-status-pill.neutral {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

/* ── Main Studio Grid ────────────────────────────────────────────────────── */

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) 365px;
  gap: 26px;
  align-items: start;
  padding-bottom: 56px;
}

.studio-main {
  min-width: 0;
}

.studio-grid.publish-mode {
  grid-template-columns: minmax(0, 1fr);
}

.studio-grid.publish-mode .output-sidebar {
  display: none;
}

/* ── Shared Form Inputs inside Studio ────────────────────────────────────── */

.studio-grid input:not([type="checkbox"]):not([type="radio"]),
.studio-grid textarea,
.studio-grid select,
.studio-dialog input:not([type="checkbox"]):not([type="radio"]),
.studio-dialog textarea,
.studio-dialog select {
  width: 100%;
  flex: initial;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid #c9c0b2;
  border-radius: 12px;
  padding: 10px 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.studio-grid textarea,
.studio-dialog textarea {
  resize: vertical;
  min-height: 76px;
}

.studio-grid input:not([type="checkbox"]):not([type="radio"]):focus,
.studio-grid textarea:focus,
.studio-grid select:focus,
.studio-dialog input:not([type="checkbox"]):not([type="radio"]):focus,
.studio-dialog textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(138, 75, 8, 0.15);
}

.studio-grid input.invalid,
.studio-grid textarea.invalid,
.studio-grid select.invalid {
  border-color: var(--error);
  background: #fffafa;
}

/* ── Panel Cards & Fields ────────────────────────────────────────────────── */

.panel-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.panel-header h2 {
  font-size: 21px;
  margin: 0;
}

.panel-sub {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 18px;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.field-hint {
  font-size: 11.5px;
  color: var(--muted);
  margin: 5px 0 0;
  line-height: 1.45;
}

.req-star {
  color: var(--error);
  font-weight: 700;
}

.char-counter {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
}

/* Auto-ID & Inline Toggles */
.chip-toggle {
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--surface-container);
  color: var(--muted);
  border: 1px solid var(--line);
  line-height: 1.4;
}

.chip-toggle:hover:not(:disabled) {
  background: var(--primary-container);
  color: var(--on-primary-container);
  transform: none;
  box-shadow: none;
}

.chip-toggle.active,
.chip-toggle.active:hover {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: #d6b689;
}

/* Quick Preset Pills */
.quick-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.quick-pill {
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface-low);
  color: var(--muted);
  border: 1px solid var(--line);
  line-height: 1.3;
}

.quick-pill:hover:not(:disabled) {
  background: var(--primary-container);
  border-color: #d6b689;
  color: var(--on-primary-container);
  transform: none;
  box-shadow: none;
}

.quick-pill.active {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

/* Version Stepper */
.stepper-control {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.stepper-control input {
  text-align: center;
  max-width: 84px;
  font-weight: 700;
}

.stepper-btn {
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-container);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.stepper-btn.accent {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: #d8ba8f;
}

.stepper-btn:hover:not(:disabled) {
  background: #ebd3b0;
  transform: none;
  box-shadow: none;
}

/* Cover Input & Live Thumbnail */
.cover-input-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.cover-input-stack {
  flex: 1;
  min-width: 0;
}

.input-with-clear {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-clear input {
  padding-right: 34px;
}

.inline-clear-btn {
  position: absolute;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-container);
  color: var(--muted);
  border: 0;
  font-size: 11px;
}

.inline-clear-btn:hover:not(:disabled) {
  background: var(--surface-high);
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

.cover-thumb {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--primary-container);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}

.cover-thumb.lg {
  width: 52px;
  height: 52px;
  border-radius: 13px;
}

.cover-thumb.sm {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 12px;
}

.cover-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.url-status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-container);
  color: var(--muted);
}

.url-status-pill.ok {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.url-status-pill.err {
  background: var(--error-bg);
  color: var(--error);
}

.url-fix-banner {
  margin-top: 7px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #fbf2e1;
  border: 1px solid #e1c496;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--on-primary-container);
}

/* Optional Details & Footer Nav */
.extra-details {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-low);
  padding: 13px 16px;
}

.extra-details summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--primary);
  user-select: none;
}

.extra-details[open] summary {
  margin-bottom: 14px;
}

.panel-footer-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.panel-footer-nav.standalone {
  border-top: 0;
  padding-top: 8px;
  margin-top: 18px;
}

.footer-tip {
  font-size: 12.5px;
  color: var(--muted);
}

/* ── Interactive Chip Input (Authors, Narrators, Subjects) ───────────────── */

.chip-input-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 10px;
  background: #ffffff;
  border: 1px solid #c9c0b2;
  border-radius: 12px;
  cursor: text;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chip-input-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(138, 75, 8, 0.15);
}

.chip-input-box.invalid {
  border-color: var(--error);
  background: #fffafa;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.25;
  max-width: 100%;
}

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

.tag-remove {
  width: 17px;
  height: 17px;
  padding: 0;
  border-radius: 50%;
  background: rgba(56, 33, 8, 0.12);
  color: var(--on-primary-container);
  border: 0;
  font-size: 10px;
  line-height: 1;
}

.tag-remove:hover:not(:disabled) {
  background: var(--primary);
  color: var(--on-primary);
  transform: none;
  box-shadow: none;
}

.chip-input-box input.chip-text-input {
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 4px !important;
  min-width: 130px;
  flex: 1;
  font-size: 13.5px;
}

/* ── Step 2: Books Shelf & Focused Active Book Editor ────────────────────── */

.books-shelf-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.books-shelf-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.books-shelf-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.books-shelf-heading h2 {
  font-size: 18px;
  margin: 0;
}

.count-chip {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-container);
  color: var(--muted);
}

.books-shelf-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.book-filter-input {
  width: 185px !important;
  padding: 6px 11px !important;
  font-size: 13px !important;
  border-radius: 10px !important;
}

.books-shelf-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.book-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 12px;
  border-radius: 13px;
  background: var(--surface-low);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  max-width: 270px;
  text-align: left;
  box-shadow: none;
}

.book-pill:hover:not(:disabled) {
  background: var(--surface-container);
  border-color: #c8b89f;
  transform: none;
  box-shadow: none;
}

.book-pill.active,
.book-pill.active:hover {
  background: var(--primary-container);
  border-color: #cda66f;
  color: var(--on-primary-container);
  box-shadow: none;
}

.book-pill-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.book-pill-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  line-height: 1.25;
}

.book-pill-meta {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.book-pill.active .book-pill-meta {
  color: #5a3c19;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.ok {
  background: var(--secondary);
}

.status-dot.err {
  background: var(--error);
}

/* Active Book Editor Card */
.active-book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.active-book-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px 24px;
  background: var(--surface-container);
  border-bottom: 1px solid var(--line);
}

.active-book-identity {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
  flex: 1;
}

.active-book-titles {
  min-width: 0;
}

.active-book-titles h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.active-book-titles p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.book-actions-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  padding: 6px 10px;
  font-size: 12.5px;
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  line-height: 1.2;
}

.icon-btn:hover:not(:disabled) {
  background: var(--primary-container);
  color: var(--on-primary-container);
  transform: none;
  box-shadow: none;
}

.icon-btn.danger {
  color: var(--error);
  border-color: #e4c3c3;
}

.icon-btn.danger:hover:not(:disabled) {
  background: var(--error-bg);
  color: var(--error);
}

/* Book Sub-Tabs */
.book-subtabs {
  display: flex;
  gap: 6px;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.subtab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 0;
  border-bottom: 2.5px solid transparent;
  border-radius: 10px 10px 0 0;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
}

.subtab-btn:hover:not(:disabled) {
  background: var(--surface-low);
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

.subtab-btn.active,
.subtab-btn.active:hover {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: transparent;
}

.active-book-body {
  padding: 24px;
}

/* Switch Toggle for Explicit */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

.switch-row span {
  font-size: 13.5px;
  font-weight: 500;
}

.switch-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── Chapters Editor (Spacious & Interactive) ────────────────────────────── */

.chapters-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-container);
}

.mode-btn {
  border: 0;
  border-radius: 0;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
}

.mode-btn:hover:not(:disabled) {
  background: rgba(138, 75, 8, 0.08);
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

.mode-btn.active,
.mode-btn.active:hover {
  background: var(--primary);
  color: var(--on-primary);
}

.mode-note {
  font-size: 12.5px;
  color: var(--muted);
}

/* Shared Audio & Interactive Timeline */
.shared-file-box {
  background: #fbf4e8;
  border: 1px solid #e3c89e;
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.shared-url-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 165px auto;
  gap: 10px;
  align-items: end;
}

.audio-player-bar {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.audio-player-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
}

.audio-player-bar audio {
  width: 100%;
  height: 36px;
}

.audio-status-note {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.audio-status-note.err {
  color: var(--error);
}

.timeline-card {
  background: var(--surface-low);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  margin-bottom: 16px;
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 12.5px;
}

.timeline-track {
  position: relative;
  height: 28px;
  border-radius: 10px;
  background: var(--surface-high);
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
}

.timeline-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  border: 0;
  border-radius: 0;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: #fff8ef;
  background: var(--primary);
  border-right: 1px solid rgba(255, 255, 255, 0.35);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-seg:nth-child(even) {
  background: #b06718;
}

.timeline-seg:nth-child(3n) {
  background: var(--secondary);
}

.timeline-seg.overlap {
  background: rgba(174, 41, 41, 0.85);
}

.timeline-seg:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: none;
  box-shadow: none;
}

/* Spacious Chapter Rows (2-Tier Layout) */
.chapters-list {
  display: grid;
  gap: 11px;
}

.chapter-row {
  background: var(--surface-low);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chapter-row.highlight {
  border-color: var(--primary);
  background: #fdf6ea;
}

.chapter-row-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.chapter-num-badge {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  flex-shrink: 0;
}

.chapter-title-wrap {
  flex: 1;
  min-width: 140px;
}

.chapter-title-wrap input {
  padding: 8px 11px !important;
  font-weight: 600;
}

.chapter-id-pill {
  padding: 4px 10px;
  font-size: 11.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-id-pill:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface);
  transform: none;
  box-shadow: none;
}

.chapter-id-pill.invalid {
  border-color: var(--error);
  color: var(--error);
  background: var(--error-bg);
}

.chapter-id-inline {
  width: 120px !important;
  padding: 4px 8px !important;
  font-size: 11.5px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border-radius: 8px !important;
}

.chapter-multi-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 155px 112px;
  gap: 10px;
  align-items: start;
}

.chapter-single-row {
  display: grid;
  grid-template-columns: 150px 150px minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}

.chapter-row label {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.time-input-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

.playhead-mark-btn {
  padding: 8px 9px;
  border-radius: 10px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  border: 1px solid #d6b689;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.playhead-mark-btn:hover:not(:disabled) {
  background: #edd0a3;
  transform: none;
  box-shadow: none;
}

.duration-badge {
  display: inline-flex;
  align-items: center;
  height: 41px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.duration-badge.ok {
  color: var(--on-secondary-container);
  background: var(--secondary-container);
  border-color: #c4d5b9;
}

.duration-badge.err {
  color: var(--error);
  background: var(--error-bg);
  border-color: #e4b4b4;
}

.chapters-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.tool-drawer {
  margin-top: 14px;
  background: var(--surface-low);
  border: 1px dashed #bfa582;
  border-radius: 14px;
  padding: 16px;
}

.tool-drawer h4 {
  margin: 0 0 6px;
  font-size: 14.5px;
}

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

.seq-preview-box {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
}

.mini-audio-bar {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fbf4e8;
  border: 1px solid #dfbe8f;
}

/* ── Right Sticky Inspector ──────────────────────────────────────────────── */

.output-sidebar {
  position: sticky;
  top: 86px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 102px);
}

.validation-box {
  border-radius: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.validation-box.valid {
  background: var(--secondary-container);
  border-color: #bdcfb2;
}

.validation-box.invalid {
  background: var(--error-bg);
  border-color: #e4b4b4;
}

.validation-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.validation-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
}

.validation-box.valid .validation-title {
  color: var(--on-secondary-container);
}

.validation-box.invalid .validation-title {
  color: var(--error);
}

.validation-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

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

.issue-list {
  margin: 9px 0 0;
  padding-left: 16px;
  font-size: 12px;
  color: #822424;
  max-height: 125px;
  overflow-y: auto;
}

.issue-list li {
  margin-bottom: 5px;
  line-height: 1.4;
}

.issue-jump-btn {
  background: none;
  border: 0;
  padding: 0;
  border-radius: 3px;
  color: #822424;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}

.issue-jump-btn:hover:not(:disabled) {
  background: none;
  color: #4f1111;
  transform: none;
  box-shadow: none;
}

.inspector-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.inspector-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.insp-tab {
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 10px;
  background: var(--surface-low);
  color: var(--muted);
  border: 1px solid transparent;
}

.insp-tab:hover:not(:disabled) {
  background: var(--surface-container);
  color: var(--ink);
  transform: none;
  box-shadow: none;
}

.insp-tab.active,
.insp-tab.active:hover {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: #d8ba8f;
}

.insp-size-pill {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.insp-pane {
  overflow-y: auto;
  max-height: 350px;
  min-height: 180px;
}

/* Mero Live App Preview */
.app-preview-mount {
  display: grid;
  gap: 12px;
}

.preview-source-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-container);
  border: 1px solid var(--line);
}

.preview-source-meta {
  min-width: 0;
  flex: 1;
}

.preview-source-meta strong {
  display: block;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-source-meta span {
  font-size: 11.5px;
  color: var(--muted);
}

.preview-book-card {
  background: var(--surface-low);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.preview-book-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.preview-cover-box {
  width: 68px;
  height: 86px;
  border-radius: 12px;
  background: linear-gradient(155deg, #f6dfbd 0%, #e5b777 100%);
  color: var(--on-primary-container);
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid #d7be98;
}

.preview-cover-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-book-info {
  min-width: 0;
  flex: 1;
}

.preview-book-info h4 {
  margin: 0 0 3px;
  font-size: 15px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.preview-book-by {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.preview-tag {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.preview-chapters {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 5px;
}

.preview-ch-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
}

.preview-ch-btn:hover:not(:disabled) {
  background: var(--primary-container);
  color: var(--on-primary-container);
  transform: none;
  box-shadow: none;
}

.preview-ch-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-ch-dur {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

/* Syntax-Highlighted JSON */
.json-preview-pre {
  margin: 0;
  background: #1d1a17;
  color: #f3ede4;
  border-radius: 12px;
  padding: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  overflow: auto;
  max-height: 340px;
}

.json-key {
  color: #f4be7e;
}

.json-str {
  color: #b5d6a7;
}

.json-num {
  color: #f29d79;
}

.json-bool {
  color: #9dc8e8;
}

.inspector-footer {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.inspector-footer .studio-btn {
  flex: 1;
  padding: 10px 12px;
}

/* ── Step 3: Review, Link Tester & Hosting ───────────────────────────────── */

.publish-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 24px;
  align-items: start;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
}

.stat-tile strong {
  display: block;
  font-size: 20px;
  color: var(--ink);
}

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

.audit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.audit-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-low);
  font-size: 13px;
}

.audit-item.ok {
  background: var(--secondary-container);
  border-color: #c1d4b5;
  color: var(--on-secondary-container);
}

.audit-item.warn {
  background: #fbf3e3;
  border-color: #e3c89e;
  color: var(--on-primary-container);
}

.audit-item.err {
  background: var(--error-bg);
  border-color: #e4b4b4;
  color: var(--error);
}

.link-check-results {
  margin-top: 14px;
  display: grid;
  gap: 7px;
  max-height: 260px;
  overflow-y: auto;
}

.link-check-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-low);
  font-size: 12px;
}

.hosting-steps {
  margin: 12px 0 0;
  padding-left: 18px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.65;
}

.hosting-steps li {
  margin-bottom: 7px;
}

.hosting-steps strong {
  color: var(--ink);
}

/* ── Import Modal Dialog ─────────────────────────────────────────────────── */

.studio-dialog {
  width: min(580px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.studio-dialog::backdrop {
  background: rgba(37, 35, 31, 0.45);
  backdrop-filter: blur(3px);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-head h2 {
  font-size: 20px;
  margin: 0 0 4px;
}

.dialog-head p {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
}

.dialog-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 20px 16px;
  border: 2px dashed #cbb89a;
  border-radius: 14px;
  background: var(--surface-low);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.drop-zone:hover,
.drop-zone.dragover {
  background: var(--primary-container);
  border-color: var(--primary);
}

.drop-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.drop-sub {
  font-size: 12px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ── Non-Blocking Undo Toast ─────────────────────────────────────────────── */

.studio-toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: 14px;
  background: #25231f;
  color: #fff8ef;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px);
}

.toast-undo-btn {
  padding: 5px 11px;
  border-radius: 8px;
  background: var(--primary-vivid);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 700;
  border: 0;
}

.toast-undo-btn:hover:not(:disabled) {
  background: #f57a23;
  transform: none;
  box-shadow: none;
}

.toast-close-btn {
  padding: 4px 7px;
  border-radius: 6px;
  background: transparent;
  color: #cfc6ba;
  border: 0;
  font-size: 12px;
}

.toast-close-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  transform: none;
  box-shadow: none;
}

/* ── Responsive Breakpoints ──────────────────────────────────────────────── */

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

  .output-sidebar {
    position: static;
    max-height: none;
  }

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

@media (max-width: 720px) {
  .studio-hero {
    padding: 20px 0 16px;
  }

  .studio-hero-side {
    align-items: flex-start;
  }

  .panel-card,
  .active-book-body {
    padding: 18px;
  }

  .active-book-header,
  .book-subtabs {
    padding-left: 18px;
    padding-right: 18px;
  }

  .field-grid,
  .shared-url-grid,
  .chapter-multi-row,
  .chapter-single-row {
    grid-template-columns: 1fr;
  }

  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
