/* KDP Pro Book Engine — Design System
 * Workspace theme (Light). The dark theme lives on socialfreedom.pro.
 * All tokens are sourced from ./tokens.css; this file maps legacy
 * names (--bg0, --gold3, --edge, --shadow-card, …) onto them so
 * existing call-sites do not need to change.
 */
@import url('./tokens.css');
@import url('./fonts.css');

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Backwards-compat aliases → tokens.css ─────────────────────────── */
  --bg0:     var(--bg-page);
  --bg1:     var(--bg-surface);
  --surface: var(--bg-surface);
  --surface2:var(--bg-surface-soft);

  --edge:  var(--border);
  --edge2: var(--border-soft);

  --text:  var(--text-primary);
  --muted: var(--text-secondary);
  --muted2:#7A828C;  /* App-only tertiary muted (unused in tokens.css) */

  --gold:  var(--accent);
  --gold2: var(--accent-light);
  --gold3: var(--accent-dark);

  --shadow-card:     var(--shadow-md);
  --shadow-elevated: var(--shadow-lg);

  /* App-specific aliases that tokens.css does not own */
  --radius: var(--radius-md);
  /* --radius-sm is already 6px in tokens.css — no alias needed */
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg0);
  min-height: 100dvh;
}

a { color: var(--link-on-light); text-decoration: none; }  /* WCAG AA ≥ 4.5:1 on light bg */
a:hover { text-decoration: underline; }

/* ── App Shell ─────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--edge);
  z-index: 80;
  overflow-y: auto;
  transition: transform .22s ease;
}

.app-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left .22s ease;
}

/* Desktop sidebar collapse */
body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
body.sidebar-collapsed .app-content { margin-left: 0; }

/* Expand tab: arrow that appears on left edge when sidebar is collapsed */
#kdp-expand-tab {
  display: none;
  position: fixed;
  left: 0; top: 50%;
  transform: translateY(-50%);
  z-index: 85;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  width: 22px; height: 48px;
  align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--muted);
  box-shadow: 2px 0 8px rgba(0,0,0,.08);
}
#kdp-expand-tab:hover { color: var(--text); background: var(--bg0); }
body.sidebar-collapsed #kdp-expand-tab { display: flex; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,14,20,.38);
  z-index: 79;
}

/* ── Sidebar Brand ─────────────────────────────────────────────────────────── */
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--edge2);
}

.brand__logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.brand__name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -.01em;
}

.brand__tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--gold3);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Sidebar Nav ───────────────────────────────────────────────────────────── */
.side-nav {
  flex: 1;
  padding: 10px 12px;
}

.sidebar__section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted2);
  padding: 12px 8px 4px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  transition: background .14s, color .14s;
  margin-bottom: 2px;
  border: 1px solid transparent;
}

.side-link:hover {
  background: rgba(0,0,0,.035);
  text-decoration: none;
}

.side-link.is-active {
  background: rgba(201,162,77,.12);
  border-color: rgba(201,162,77,.22);
  color: var(--text);
}

.side-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .75;
}

.side-link.is-active .side-icon { opacity: 1; }

.side-title {
  display: block;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}

.side-sub {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.3;
}

/* ── Sidebar Footer ────────────────────────────────────────────────────────── */
.sidebar__footer {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--edge2);
}

.sidebar__user-email {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: 0 28px;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--edge2);
  position: sticky;
  top: 0;
  z-index: 60;
}

.topbar__title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.topbar__credits {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 3px 12px;
}

.topbar__credits strong { color: var(--gold3); }

/* Admin-Mode indicator — only shown on admin.php via dedicated badge */
.topbar__admin-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #991B1B;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.28);
  border-radius: 999px;
  padding: 4px 12px;
}
body.is-admin .topbar { border-bottom-color: rgba(220, 38, 38, 0.35); }

/* Menu (hamburger) button — hidden on desktop, shown via media query on mobile */
#kdp-menu-btn { display: none; }

/* Direct manuscript editor: visible on desktop */
.kdp-direct-edit__hint-mobile { display: none; }
.kdp-direct-edit__editor { display: block; }

/* ── Page Layout ───────────────────────────────────────────────────────────── */
.page { flex: 1; padding: 32px 28px 48px; }

.container {
  max-width: 980px;
  margin: 0 auto;
}

.container--narrow {
  max-width: 600px;
  margin: 0 auto;
}

/* ── Typography ────────────────────────────────────────────────────────────── */
.h1 { font-size: 28px; font-weight: 700; line-height: 1.25; letter-spacing: -.02em; }
.h2 { font-size: 20px; font-weight: 600; line-height: 1.3; }
.h3 { font-size: 16px; font-weight: 600; line-height: 1.4; }
.p  { font-size: 15px; line-height: 1.65; color: var(--muted); }
.small { font-size: 13px; color: var(--muted); }
.kicker {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gold3);
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}

.card + .card { margin-top: 16px; }

.card--soft {
  background: var(--surface2);
  box-shadow: none;
}

.card--accent {
  border-color: rgba(201,162,77,.28);
  background: linear-gradient(180deg, rgba(201,162,77,.04), transparent);
}

/* Compact info/stat card — used in Wizard for niche-report boxes, outline specs, format-info, etc. */
.card--stat {
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--edge2);
  border-radius: var(--radius);
  box-shadow: none;
}
.card--stat__label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.card--stat__value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* Highlighted recommendation box — gold-tinted */
.card--recommend {
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(201,162,77,.06), rgba(201,162,77,.02));
  border: 1px solid rgba(201,162,77,.28);
  border-radius: var(--radius);
  box-shadow: none;
}

/* Stacked vertical card — no flex, explicit gap */
.card--stack { display: flex; flex-direction: column; gap: 12px; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--edge);
  background: var(--surface);
  color: var(--text);
  transition: background .14s, transform .1s, border-color .14s;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:hover { background: rgba(0,0,0,.03); border-color: rgba(32,26,18,.18); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn--primary {
  background: linear-gradient(180deg, var(--gold) 0%, #b88b3a 100%);
  border-color: rgba(201,162,77,.40);
  color: #fff;
  box-shadow: 0 8px 24px rgba(201,162,77,.22);
}

.btn--primary:hover { background: linear-gradient(180deg, #d4aa55 0%, #a37834 100%); color: #fff; }

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn--ghost:hover { background: rgba(0,0,0,.04); color: var(--text); }

.btn--danger {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err-text);
}

.btn--sm { padding: 6px 13px; font-size: 13px; min-height: 0; }
.btn--lg { padding: 13px 28px; font-size: 16px; }

/* Full-width button (replaces inline style="width:100%;justify-content:center;") */
.btn--full { width: 100%; justify-content: center; }

.btn[disabled], .btn.is-loading {
  opacity: .55;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }

.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.label--hint {
  font-weight: 400;
  color: var(--muted);
}

/* Below-field hint text — used under inputs, radio groups, checkbox rows */
.field-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 6px;
}
.field-hint--required { color: var(--warn-text); font-weight: 600; }

/* Checkbox row — label + checkbox + text, used for waiver/terms confirmations */
.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 10px;
}
.checkbox-row input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Radio-card group — custom-styled labels wrapping radio inputs */
.input-radio-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.input-radio-group label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .18s, background .18s;
  font-size: 14px;
  line-height: 1.5;
}
.input-radio-group label:hover {
  border-color: rgba(201,162,77,.4);
}
.input-radio-group label:has(input[type="radio"]:checked) {
  border-color: var(--accent);
  background: rgba(201,162,77,.06);
}
.input-radio-group input[type="radio"] {
  margin-top: 3px;
  flex-shrink: 0;
}

.input, .textarea, .select {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 11px 14px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid rgba(32,26,18,.18);
  border-radius: var(--radius-sm);
  transition: border-color .14s, box-shadow .14s;
  font-family: inherit;
}

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: rgba(201,162,77,.55);
  box-shadow: 0 0 0 3px rgba(201,162,77,.12);
}

.textarea { resize: vertical; min-height: 100px; }

.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'%3E%3Cpath fill='%235C636B' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }

.field-error {
  font-size: 12px;
  color: var(--err-text);
  margin-top: 4px;
}

/* ── Notices / Alerts ──────────────────────────────────────────────────────── */
.notice {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid var(--edge);
  background: var(--surface2);
  margin-bottom: 16px;
}

.notice--ok   { background: var(--ok-bg);   border-color: var(--ok-border);   color: var(--ok-text); }
.notice--warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.notice--err  { background: var(--err-bg);  border-color: var(--err-border);  color: var(--err-text); }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid var(--edge);
  background: var(--surface2);
  color: var(--muted);
}

.badge--ok   { background: var(--ok-bg);   border-color: var(--ok-border);   color: var(--ok-text); }
.badge--warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.badge--gold { background: rgba(201,162,77,.10); border-color: rgba(201,162,77,.28); color: var(--gold3); }

/* ── Grid ──────────────────────────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* ── Progress Bar ──────────────────────────────────────────────────────────── */
.progress {
  height: 10px;
  border-radius: 999px;
  background: #D8D4CC;
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--gold2), var(--gold3));
  transition: width .4s ease;
  border-radius: 999px;
}

/* Animated variant for running states */
.progress__bar--anim {
  background: linear-gradient(90deg, var(--gold3) 0%, var(--gold2) 50%, var(--gold3) 100%);
  background-size: 200% 100%;
  animation: kdp-bar-shift 1.8s ease-in-out infinite;
}

@keyframes kdp-bar-shift {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Spinner for running status labels */
.kdp-spin {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--gold3);
  border-top-color: transparent;
  border-radius: 50%;
  animation: kdp-spinner .7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes kdp-spinner { to { transform: rotate(360deg); } }

/* Animated dots for running labels */
.kdp-dots::after {
  content: '';
  animation: kdp-dot-anim 1.4s steps(4, end) infinite;
}
@keyframes kdp-dot-anim {
  0%  { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ── Divider ───────────────────────────────────────────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0;
  color: var(--muted2);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--edge);
}

/* ── Empty State ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 24px;
}

.empty-state__icon {
  width: 48px;
  height: 48px;
  opacity: .25;
  margin: 0 auto 16px;
}

.empty-state__title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state__sub {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 20px;
}

/* ── Project Cards (Dashboard) ─────────────────────────────────────────────── */
.project-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  color: var(--text);
  transition: border-color .14s, box-shadow .14s, transform .1s;
}

.project-card:hover {
  border-color: rgba(201,162,77,.28);
  box-shadow: 0 16px 40px rgba(0,0,0,.10);
  transform: translateY(-1px);
  text-decoration: none;
  color: var(--text);
}

.project-card__title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 4px;
}

.project-card__meta {
  font-size: 12.5px;
  color: var(--muted);
}

/* ── Wizard Steps ──────────────────────────────────────────────────────────── */
.wizard-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 28px;
  overflow-x: auto;
}

.wizard-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}

.wizard-step__num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  background: rgba(0,0,0,.06);
  color: var(--muted);
  border: 2px solid transparent;
  flex-shrink: 0;
}

.wizard-step.is-done .wizard-step__num {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.wizard-step.is-active .wizard-step__num {
  background: rgba(201,162,77,.14);
  border-color: var(--gold);
  color: var(--gold3);
}

.wizard-step__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.wizard-step.is-active .wizard-step__label { color: var(--text); font-weight: 600; }
.wizard-step.is-done .wizard-step__label   { color: var(--ok-text); }

.wizard-step__connector {
  width: 32px;
  height: 1px;
  background: var(--edge);
  flex-shrink: 0;
}

.wizard-step.is-done + .wizard-step .wizard-step__connector,
.wizard-step.is-done .wizard-step__connector {
  background: var(--ok-border);
}

/* Inactive/unreachable steps — visually distinct from active/done */
.wizard-step[aria-disabled="true"] .wizard-step__num,
.wizard-step[aria-disabled="true"] .wizard-step__label {
  opacity: .45;
}

/* ── Step 5 Tabs ─────────────────────────────────────────────────────────── */
.kdp-tabs__nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.kdp-tabs__nav::-webkit-scrollbar { display: none; }
.kdp-tabs__btn {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.kdp-tabs__btn:hover { color: var(--text); }
.kdp-tabs__btn.active {
  color: var(--gold3);
  border-bottom-color: var(--gold3);
}
.kdp-tabs__panel { display: none; }
.kdp-tabs__panel.active { display: block; }

/* ── Login Page ────────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg0);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow-elevated);
}

.auth-card__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted2);
  padding: 8px 14px;
  border-bottom: 1px solid var(--edge);
  background: rgba(32,26,18,.025);
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--edge2);
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(201,162,77,.04); }

/* ── Focus-visible — WCAG AA (all interactive elements) ───────────────────── */
:focus-visible {
  outline: 2.5px solid var(--gold);
  outline-offset: 2px;
}

.btn:focus-visible,
.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
  outline: none; /* handled by element-level box-shadow below */
  box-shadow: 0 0 0 3px rgba(201,162,77,.32);
  border-color: var(--gold);
}

a:focus-visible {
  outline: 2.5px solid var(--gold);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Smooth transitions (all interactive elements at 160ms) ────────────────── */
.btn, .side-link, .project-card, .input, .textarea, .select, .notice {
  transition-duration: 160ms;
  transition-timing-function: ease;
}

/* ── iPhone notch / Dynamic Island — safe-area insets ─────────────────────── */
/* Applied globally so topbar, sidebar and toast never overlap the notch or home bar. */
.topbar {
  padding-top: env(safe-area-inset-top, 0px);
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
}

.sidebar {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#kdp-toast {
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  right: calc(24px + env(safe-area-inset-right, 0px));
}

/* ── Sidebar close / menu buttons — WCAG 44×44px touch target ─────────────── */
#kdp-sidebar-close {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Chapter Editor ──────────────────────────────────────────────────────── */
.kdp-editor-toggle { display: inline-flex; border: 1px solid var(--edge); border-radius: 6px; overflow: hidden; }
.kdp-editor-toggle__btn { border-radius: 0 !important; border: none !important; font-size: 13px; padding: 6px 14px; min-height: 32px; }
.kdp-editor-toggle__btn.active { background: var(--gold3); color: #fff; }

#chapter-preview h1 { font-size: 22px; font-weight: 700; margin: 24px 0 12px; }
#chapter-preview h2 { font-size: 18px; font-weight: 700; margin: 20px 0 10px; }
#chapter-preview h3 { font-size: 16px; font-weight: 600; margin: 16px 0 8px; }
#chapter-preview blockquote { border-left: 3px solid var(--gold3); padding-left: 14px; color: var(--muted); margin: 12px 0; }
#chapter-preview hr { border: none; border-top: 1px solid var(--edge); margin: 20px 0; }
#chapter-preview p { margin-bottom: 8px; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    width: min(88vw, 300px);
    z-index: 90;
    box-shadow: 22px 0 56px rgba(0,0,0,.24);
    /* Honour left safe-area inset when sidebar is open (landscape notch) */
    padding-left: env(safe-area-inset-left, 0px);
  }

  .app-content { margin-left: 0; }

  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }

  /* Menu button always visible on mobile — via CSS, not inline JS */
  #kdp-menu-btn { display: block !important; min-width: 44px; min-height: 44px; }

  .page {
    padding: 20px 16px 40px;
    /* Reserve space for home indicator at bottom */
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* ── Mobile touch targets (WCAG: min 44×44px) ─────────────────────────────── */
  .btn { min-height: 44px; padding: 10px 18px; }
  .btn--sm { min-height: 38px; }
  .input, .textarea, .select { min-height: 44px; font-size: 16px; } /* 16px prevents iOS auto-zoom */

  /* ── Wizard steps: compact labels on mobile (nicht mehr komplett weg) ──── */
  .wizard-step__label {
    display: block;
    font-size: 10px;
    line-height: 1.15;
    max-width: 56px;
    text-align: center;
    white-space: normal;
    overflow-wrap: break-word;
  }
  .wizard-step__connector { width: 16px; margin-top: 14px; }
  .wizard-steps { gap: 4px; }

  /* ── Wizard step circles: adequate touch target + stacked label ──────────── */
  .wizard-step {
    flex-direction: column;
    gap: 4px;
    padding: 8px 4px;
    min-height: 44px;
    align-items: center;
    text-align: center;
  }

  /* ── Project card: stack on mobile ─────────────────────────────────────────── */
  .project-card {
    flex-direction: column;
    gap: 10px;
  }

  /* ── Full-width primary button on narrow screens ───────────────────────────── */
  .btn--primary-mobile { width: 100%; justify-content: center; }

  /* ── Topbar credits: hide label on very small screens ──────────────────────── */
  .topbar__credits { display: none; }

  /* ── Card padding reduced on mobile ────────────────────────────────────────── */
  .card { padding: 16px; }

  /* ── Auth card padding ─────────────────────────────────────────────────────── */
  .auth-card { padding: 24px 18px; }

  /* ── Book print bar: adjust for safe area ──────────────────────────────────── */
  .print-bar {
    padding-top: max(10px, env(safe-area-inset-top, 0px));
  }

  /* ── Direct manuscript editor: hide textarea on mobile, show hint ───────────── */
  .kdp-direct-edit__editor { display: none; }
  .kdp-direct-edit__hint-mobile { display: block !important; }
  .kdp-direct-edit__hint-desktop { display: none !important; }
}

/* ── Loader/busy state for buttons ────────────────────────────────────────── */
.btn.is-loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: kdp-spinner .7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
  opacity: .7;
}

/* ── Skeleton loader ──────────────────────────────────────────────────────── */
.kdp-skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, rgba(201,162,77,.06) 50%, var(--surface2) 75%);
  background-size: 400% 100%;
  animation: kdp-skeleton-anim 1.6s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes kdp-skeleton-anim {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ── Toast notification ───────────────────────────────────────────────────── */
#kdp-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,.22);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  max-width: calc(100vw - 48px);
}
#kdp-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
#kdp-toast.is-ok   { background: var(--ok-text); }
#kdp-toast.is-err  { background: var(--err-text); }
#kdp-toast.is-gold { background: var(--gold3); }

/* ── Busy overlay (KI-Verarbeitung) ──────────────────────────────────────── */
#kdp-busy-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(10, 9, 8, 0.82);
  backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
}
#kdp-busy-overlay.is-active {
  display: flex;
}
#kdp-busy-card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 36px 40px;
  max-width: 420px;
  width: calc(100vw - 48px);
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}
#kdp-busy-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--edge);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: kdp-spinner .8s linear infinite;
  margin: 0 auto 20px;
}
#kdp-busy-msg {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.4;
}
#kdp-busy-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Launch-Badge ──────────────────────────────────────────────────────── */
.launch-badge {
  display: inline-block;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #2A1A00;
  background: linear-gradient(135deg, #E8B820, #D4A017);
  border-radius: 999px;
  transform: rotate(-2deg);
  box-shadow: 0 1px 4px rgba(180, 130, 0, .25);
  white-space: nowrap;
  line-height: 1.6;
}
.launch-hint {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold3, #D4A017);
}

/* ── Accessibility: reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
