*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1612;
  --bg-surface: #2a2420;
  --bg-card: #352f28;
  --text: #e8ddd0;
  --text-muted: #a89884;
  --accent: #c4956a;
  --accent-hover: #d4a57a;
  --border: #4a4036;
  --spine: #1a1410;
  --danger: #c45a5a;
  --success: #5ac47a;
}

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body.simple-page-browser-open,
body.simple-mode-overlay-open {
  overflow: hidden;
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* Login Screen */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1612 0%, #2a2018 100%);
}

.login-card {
  background: var(--bg-card);
  padding: 3rem;
  border-radius: 12px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  max-width: 400px;
  width: 90%;
}

.login-card h1 {
  font-size: 1.8rem;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 2rem;
}

.login-btn {
  width: 100%;
  padding: 0.85rem 1.5rem;
  font-size: 1.1rem;
  cursor: pointer;
}

.login-privacy-note {
  margin: 1rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.login-privacy-note a {
  color: var(--accent);
}

#login-form button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

#login-form button:hover { background: var(--accent-hover); }

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Book Selector */
#book-selector {
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1612 0%, #2a2018 100%);
}

.selector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.selector-header h1 {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: normal;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
  max-width: 1000px;
  margin: 0 auto;
}

/* Onboarding banner */
.onboarding-banner {
  max-width: 1000px;
  margin: 1.5rem auto 0;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
}

.onboarding-banner-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.onboarding-banner-header h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--accent);
  font-weight: normal;
}

.onboarding-banner-progress {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Family AI usage meter (admin panel) + soft-warn banner (app screen) --- */
.usage-meter {
  max-width: 1000px;
  margin: 1.5rem auto 0;
  padding: 0.85rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
}
#admin-panel .usage-meter {
  margin: 1rem 1.5rem 0;
}
.usage-meter--warn { border-left-color: #d9a341; }
.usage-meter--danger { border-left-color: #e57373; }

.usage-meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.usage-meter-title { font-size: 0.9rem; color: var(--text); }
.usage-meter-amounts { font-size: 0.85rem; color: var(--text-muted); }

.usage-meter-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}
.usage-meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.usage-meter--warn .usage-meter-fill { background: #d9a341; }
.usage-meter--danger .usage-meter-fill { background: #e57373; }

.usage-meter-foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.usage-meter-reset { white-space: nowrap; }

.usage-warning-banner {
  padding: 0.6rem 1.1rem;
  font-size: 0.88rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.usage-warning-banner--warn { background: rgba(217, 163, 65, 0.15); color: #d9a341; }
.usage-warning-banner--danger { background: rgba(229, 115, 115, 0.15); color: #e57373; }

.onboarding-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.onboarding-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  background: var(--bg-surface);
}

.onboarding-step--done {
  opacity: 0.65;
}

.onboarding-step-marker {
  width: 1.25rem;
  text-align: center;
  color: var(--accent);
  font-weight: bold;
}

.onboarding-step--done .onboarding-step-marker {
  color: var(--success, #7abf7a);
}

.onboarding-step-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.onboarding-step-label {
  font-size: 0.9rem;
}

.onboarding-step-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.onboarding-step-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.onboarding-step-status--pending {
  font-style: italic;
}

.onboarding-tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 1300;
  pointer-events: none;
}

.onboarding-tour-overlay.hidden {
  display: none;
}

.onboarding-tour-scrim {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 7, 0.42);
}

.onboarding-tour-card {
  position: fixed;
  width: min(360px, calc(100vw - 2rem));
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid rgba(196, 149, 106, 0.38);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0,0,0,0.45);
  pointer-events: auto;
}

.onboarding-tour-card[data-centered="true"] {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.onboarding-tour-eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.45rem;
}

.onboarding-tour-title {
  color: var(--text);
  font-size: 1.15rem;
  font-weight: normal;
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.onboarding-tour-body {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.55;
  margin-bottom: 0.9rem;
}

.onboarding-tour-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.onboarding-tour-progress {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.onboarding-tour-buttons {
  display: flex;
  gap: 0.5rem;
}

.onboarding-tour-buttons .btn-subtle {
  min-height: 44px;
  color: var(--text);
  font-size: 1rem;
}

.onboarding-tour-buttons [data-tour-action="next"] {
  border-color: var(--accent);
  color: var(--accent);
}

.onboarding-tour-highlight {
  outline: 3px solid rgba(196, 149, 106, 0.75);
  outline-offset: 4px;
}

.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}

.book-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.book-card-cover {
  aspect-ratio: 3/4;
  overflow: hidden;
  background: var(--bg);
}

.book-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card-info {
  padding: 1rem;
}

.book-card-info h3 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.book-card-author {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.book-card-pages {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.book-card-desc {
  color: var(--text);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  line-height: 1.4;
}

.no-books {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 3rem;
}

/* Activity Feed */
#activity-screen {
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1612 0%, #2a2018 100%);
}

.activity-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.activity-header h1 {
  color: var(--accent);
  font-size: 1.35rem;
  font-weight: normal;
  margin-bottom: 0.2rem;
}

.activity-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.activity-body {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem;
}

.activity-note {
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  background: rgba(53, 47, 40, 0.92);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  color: var(--text-muted);
  line-height: 1.5;
}

.activity-status {
  margin-bottom: 0.9rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.activity-item,
.activity-empty {
  padding: 1rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.18);
}

.activity-item-summary {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
}

.activity-item-meta {
  margin-top: 0.45rem;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.activity-item-actions {
  margin-top: 0.8rem;
}

.activity-empty {
  color: var(--text-muted);
  text-align: center;
}

.activity-actions {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

/* Analytics Dashboard */
#analytics-screen {
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1612 0%, #241d17 100%);
}

.analytics-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.analytics-header h1 {
  color: var(--accent);
  font-size: 1.35rem;
  font-weight: normal;
  margin-bottom: 0.2rem;
}

.analytics-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 60ch;
}

.analytics-body {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem;
}

.analytics-loading,
.analytics-empty {
  padding: 1rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-muted);
}

.analytics-note {
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  background: rgba(53, 47, 40, 0.92);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  color: var(--text-muted);
  line-height: 1.5;
}

.analytics-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.analytics-cards-secondary {
  margin-bottom: 1.25rem;
}

.analytics-card,
.analytics-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.18);
}

.analytics-card {
  padding: 1rem 1.1rem;
}

.analytics-card-value {
  color: var(--text);
  font-size: 1.7rem;
  line-height: 1.1;
}

.analytics-card-label {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.analytics-section {
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.analytics-section h2 {
  color: var(--accent);
  font-size: 1rem;
  font-weight: normal;
  margin-bottom: 0.8rem;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.analytics-table-wrap {
  overflow-x: auto;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
}

.analytics-table th,
.analytics-table td {
  padding: 0.6rem 0.4rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
}

.analytics-table th {
  color: var(--text-muted);
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.76rem;
}

/* Header */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

.header-book-title {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-switcher {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 250px;
}

.book-switcher:hover {
  border-color: var(--accent);
}

.header-actions {
  display: flex;
  gap: 0.75rem;
}

.btn-subtle.fr-return-btn {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.btn-subtle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  transition: all 0.2s;
  position: relative;
}

.btn-subtle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.simple-mode #ui-mode-toggle {
  border-color: var(--accent);
  color: var(--accent);
}

.simple-mode #chat-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.simple-mode #chat-btn:hover {
  color: var(--bg);
  opacity: 0.9;
}

.simple-mode #app-header .btn-subtle,
.simple-mode .hamburger-btn {
  min-height: 44px;
  color: var(--text);
  font-size: 1rem;
}

.simple-mode #app-header .btn-subtle {
  padding: 0.55rem 0.95rem;
}

/* Hamburger lives in both the book-selector header and #app-header — keep
   the 44x44 tap target everywhere in Simple Mode (was scoped to #app-header
   only, leaving the home-page hamburger at ~39x18). */
.simple-mode .hamburger-btn {
  min-width: 44px;
  padding: 0.55rem 0.7rem;
}

/* Items inside the dropdown menu are .btn-subtle but live outside #app-header,
   so they missed the size bump above. Match in-header treatment. */
.simple-mode .header-menu-panel .btn-subtle {
  min-height: 44px;
  font-size: 1rem;
  color: var(--text);
  padding: 0.6rem 0.9rem;
}

.simple-mode #app-header #ui-mode-toggle {
  border-color: var(--accent);
  color: var(--accent);
}

.simple-mode #app-header #chat-btn,
.simple-mode #app-header #chat-btn:hover {
  color: var(--bg);
}

/* Note: the top-right header menu keeps ALL its options in simple mode
   (#manage-users-btn-app, #face-review-toggle, #people-toggle, #admin-toggle
   are intentionally NOT hidden here — they remain role-gated via their own
   `hidden` class). Only non-menu chrome is hidden in simple view below. */
.simple-mode #book-switcher,
.simple-mode #fr-return-btn,
.simple-mode #resize-handle,
.simple-mode #thumbnail-strip-container,
.simple-mode #face-strip-panel,
.simple-mode #book-audio-panel,
.simple-mode #page-jump,
.simple-mode #caption-right,
.simple-mode #comments-right {
  display: none !important;
}

.simple-mode-toolbar {
  display: none;
}

.simple-mode-toolbar.hidden {
  display: none;
}

.simple-mode .simple-mode-toolbar {
  display: grid;
  gap: 1rem;
  max-width: 1120px;
  margin: 1rem auto 0;
  padding: 1.25rem 1.5rem;
  border: 1px solid rgba(196, 149, 106, 0.24);
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(196, 149, 106, 0.14), rgba(53, 47, 40, 0.92)),
    rgba(42, 36, 32, 0.92);
  box-shadow: 0 22px 50px rgba(0,0,0,0.22);
}

.simple-mode-copy {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.simple-mode-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(196, 149, 106, 0.18);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.simple-mode-heading {
  color: var(--text);
  font-size: 1.8rem;
  font-weight: normal;
  line-height: 1.15;
}

.simple-mode-subtitle {
  max-width: 65ch;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.6;
}

.simple-mode-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.simple-mode-page-actions .btn-subtle {
  min-height: 48px;
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  font-size: 0.95rem;
}

.simple-page-browser {
  position: fixed;
  inset: 0;
  z-index: 1250;
  background: rgba(13, 10, 8, 0.82);
  backdrop-filter: blur(12px);
}

.simple-page-browser-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 1rem;
}

.simple-page-browser-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  border: 1px solid rgba(196, 149, 106, 0.18);
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(196, 149, 106, 0.14), rgba(53, 47, 40, 0.92)),
    rgba(42, 36, 32, 0.95);
  box-shadow: 0 18px 40px rgba(0,0,0,0.22);
}

.simple-page-browser-copy {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.simple-page-browser-title {
  color: var(--text);
  font-size: 1.6rem;
  font-weight: normal;
  line-height: 1.2;
}

.simple-page-browser-status {
  color: var(--text-muted);
  font-size: 0.96rem;
  line-height: 1.5;
}

.simple-page-browser-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
  align-items: center;
}

.simple-page-browser-jump-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.simple-page-browser-jump-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.simple-page-browser-jump-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.simple-page-browser-jump-controls input {
  width: 7rem;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.simple-page-browser-jump-controls input:focus {
  outline: none;
  border-color: var(--accent);
}

.simple-page-browser-jump-controls .btn-accent {
  min-height: 44px;
  border-radius: 999px;
}

.simple-page-browser-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0 0;
}

.simple-page-browser-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  align-items: start;
}

.simple-page-browser-group-section {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid rgba(196, 149, 106, 0.16);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(50, 43, 36, 0.95), rgba(35, 30, 26, 0.95));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}

.simple-page-browser-group {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0 0 0.85rem;
  border-bottom: 1px solid rgba(196, 149, 106, 0.12);
}

.simple-page-browser-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  align-items: start;
}

.simple-page-browser-group-label {
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}

.simple-page-browser-group-range {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.simple-page-browser-item {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
  padding: 0.75rem;
  border: 1px solid rgba(196, 149, 106, 0.12);
  border-radius: 22px;
  background: rgba(42, 36, 32, 0.96);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.simple-page-browser-item:hover {
  transform: translateY(-2px);
  border-color: rgba(196, 149, 106, 0.45);
  box-shadow: 0 16px 28px rgba(0,0,0,0.22);
}

.simple-page-browser-item.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(196, 149, 106, 0.2);
}

.simple-page-browser-thumb,
.simple-page-browser-cover-thumb,
.simple-page-browser-fallback-thumb {
  width: 100%;
  aspect-ratio: 10 / 13;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid rgba(196, 149, 106, 0.08);
  overflow: hidden;
}

.simple-page-browser-thumb {
  background-repeat: no-repeat;
}

.simple-page-browser-cover-thumb,
.simple-page-browser-fallback-thumb {
  display: block;
  object-fit: cover;
}

.simple-page-browser-page-label {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 600;
}

.simple-page-number-trigger {
  cursor: pointer;
}

.simple-page-number-trigger:hover,
.simple-page-number-trigger:focus {
  color: var(--accent);
  border-color: rgba(196, 149, 106, 0.28);
}

.simple-transcript-view {
  position: fixed;
  inset: 0;
  z-index: 1260;
  background: rgba(13, 10, 8, 0.82);
  backdrop-filter: blur(12px);
}

.simple-transcript-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

.simple-transcript-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  border: 1px solid rgba(196, 149, 106, 0.18);
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(196, 149, 106, 0.14), rgba(53, 47, 40, 0.92)),
    rgba(42, 36, 32, 0.95);
  box-shadow: 0 18px 40px rgba(0,0,0,0.22);
}

.simple-transcript-copy {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.simple-transcript-title {
  color: var(--text);
  font-size: 1.6rem;
  font-weight: normal;
  line-height: 1.2;
}

.simple-transcript-status {
  max-width: 60ch;
  color: var(--text-muted);
  font-size: 0.96rem;
  line-height: 1.5;
}

.simple-transcript-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.simple-transcript-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0 0;
}

.simple-transcript-content {
  margin: 0;
  min-height: 100%;
  padding: 1.4rem 1.5rem;
  border: 1px solid rgba(196, 149, 106, 0.16);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(50, 43, 36, 0.95), rgba(35, 30, 26, 0.95));
  box-shadow: 0 18px 40px rgba(0,0,0,0.2);
  color: var(--text);
  font-family: inherit;
  font-size: 1.125rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.simple-transcript-content[data-state="loading"],
.simple-transcript-content[data-state="empty"],
.simple-transcript-content[data-state="error"] {
  color: var(--text-muted);
}

/* Page Jump */
#page-jump {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-surface);
  font-size: 0.9rem;
}

#page-jump label { color: var(--text-muted); }

#jump-input {
  width: 4rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  text-align: center;
}

#jump-btn {
  padding: 0.3rem 0.75rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

#page-indicator {
  color: var(--text-muted);
  margin-left: 1rem;
}

/* Resize Handle */
#resize-handle {
  height: 6px;
  background: var(--border);
  cursor: ns-resize;
  transition: background 0.2s;
  flex-shrink: 0;
}

#resize-handle:hover,
#resize-handle.dragging {
  background: var(--accent);
}

/* Caption Panel */
#caption-panel {
  display: flex;
  gap: 1px;
  background: var(--border);
  margin-top: 1px;
}

.caption-col {
  flex: 1;
  background: var(--bg-surface);
  padding: 1.25rem 1.5rem;
  min-height: 120px;
}

#page-items-summary-panel {
  display: block;
  margin-top: 1px;
}

.page-items-summary-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.5rem;
  background: var(--bg-surface);
}

.page-items-summary-columns {
  display: flex;
  gap: 1px;
  background: var(--border);
}

.page-items-summary-col {
  flex: 1;
  background: var(--bg-surface);
  padding: 1rem 1.5rem;
  min-height: 48px;
}

.page-items-summary-block h4,
.page-items-summary-empty strong {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: normal;
  margin: 0 0 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.page-items-summary-list {
  margin: 0;
  padding-left: 1.2rem;
}

.page-items-summary-list li + li {
  margin-top: 0.45rem;
}

.page-items-summary-entry {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.6rem;
  margin-left: -0.6rem;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

.page-items-summary-entry:hover,
.page-items-summary-entry:focus {
  background: rgba(196, 149, 106, 0.12);
}

.page-items-summary-entry-label {
  flex: 1;
}

.page-items-summary-entry-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.page-items-summary-chip {
  padding: 0.16rem 0.45rem;
  border-radius: 999px;
  background: rgba(196, 149, 106, 0.14);
  color: var(--accent);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.page-items-summary-status {
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: capitalize;
}

.page-items-summary-empty p {
  margin: 0 0 0.8rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.modal-content.page-item-modal-content {
  max-width: min(1400px, 96vw);
  width: 96vw;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.page-item-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 15, 13, 0.4);
}

.page-item-modal-titleline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.page-item-modal-titleline h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-item-status-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(196, 149, 106, 0.14);
  border: 1px solid rgba(196, 149, 106, 0.3);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.page-item-status-chip.status-draft {
  background: rgba(150, 150, 150, 0.12);
  border-color: rgba(180, 180, 180, 0.3);
  color: var(--text-muted);
}

.page-item-status-chip.status-archived {
  background: rgba(214, 117, 82, 0.12);
  border-color: rgba(214, 117, 82, 0.35);
  color: #f0c4b6;
}

.page-item-modal-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-item-modal-header-actions .modal-close {
  position: static;
}

.page-item-modal-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 28vw, 360px);
  gap: 0;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.page-item-stage {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: rgba(12, 10, 9, 0.35);
}

.page-item-modal-preview {
  position: relative;
  flex: 1;
  min-height: 220px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(18, 15, 13, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.page-item-modal-preview img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.page-item-modal-preview img.hidden {
  display: none;
}

.page-item-modal-preview img.page-item-preview-draft {
  position: absolute;
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
}

.page-item-preview-empty {
  padding: 1rem;
  color: var(--text-muted);
  text-align: center;
}

.page-item-preview-empty.loading,
.page-item-preview-empty.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  min-height: 100%;
}

.page-item-preview-empty.loading::before {
  content: '';
  width: 26px;
  height: 26px;
  border: 2px solid rgba(231, 198, 158, 0.2);
  border-top-color: rgba(231, 198, 158, 0.92);
  border-radius: 50%;
  animation: page-item-preview-spin 0.85s linear infinite;
}

.page-item-preview-empty.error {
  color: #f0c4b6;
}

@keyframes page-item-preview-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.page-item-enhance-chip {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(18, 15, 13, 0.78);
  border: 1px solid rgba(196, 149, 106, 0.4);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.page-item-enhance-chip.pending {
  border-color: rgba(231, 198, 158, 0.5);
  color: rgba(231, 198, 158, 0.95);
}

.page-item-enhance-chip.failed {
  border-color: rgba(214, 117, 82, 0.55);
  background: rgba(214, 117, 82, 0.2);
  color: #f0c4b6;
  pointer-events: auto;
}

.page-item-stage-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 0;
}

.page-item-filmstrip {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 0.15rem 0.05rem;
}

.page-item-filmstrip::-webkit-scrollbar { height: 6px; }
.page-item-filmstrip::-webkit-scrollbar-thumb { background: rgba(196, 149, 106, 0.3); border-radius: 3px; }

.page-item-filmstrip-tile,
.page-item-filmstrip-add {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(18, 15, 13, 0.68);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 120ms ease, transform 120ms ease;
}

.page-item-filmstrip-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.85;
  transition: opacity 120ms ease;
}

.page-item-filmstrip-tile:hover img,
.page-item-filmstrip-tile.active img {
  opacity: 1;
}

.page-item-filmstrip-tile:hover,
.page-item-filmstrip-add:hover {
  border-color: var(--accent);
}

.page-item-filmstrip-tile.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.page-item-filmstrip-star {
  position: absolute;
  top: 2px;
  left: 4px;
  color: #f5d089;
  font-size: 0.85rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.page-item-filmstrip-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  border-style: dashed;
  color: var(--text-muted);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.page-item-filmstrip-add-icon {
  font-size: 1.2rem;
  line-height: 1;
  color: var(--accent);
}

.page-item-stage-tools {
  display: flex;
  gap: 0.4rem;
  flex: 0 0 auto;
}

.page-item-icon-btn {
  min-width: 38px;
  padding: 0.4rem 0.55rem;
  font-size: 1rem;
}

.page-item-menu {
  position: relative;
  display: inline-block;
}

.page-item-menu-toggle {
  white-space: nowrap;
}

.page-item-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 220px;
  z-index: 320;
  background: var(--bg-surface, #221c17);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.page-item-stage-tools .page-item-popover {
  right: 0;
  top: auto;
  bottom: calc(100% + 4px);
}

.page-item-popover-item {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  border-radius: 6px;
  cursor: pointer;
}

.page-item-popover-item:hover:not(:disabled),
.page-item-popover-item:focus-visible {
  background: rgba(196, 149, 106, 0.16);
  outline: none;
}

.page-item-popover-item:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

.page-item-popover-item.danger {
  color: #f0c4b6;
}

.page-item-popover-item.danger:hover {
  background: rgba(214, 117, 82, 0.18);
}

.page-item-popover-sep {
  height: 1px;
  margin: 0.25rem 0;
  background: var(--border);
}

.page-item-filmstrip-context {
  position: fixed;
  z-index: 340;
  min-width: 200px;
  background: var(--bg-surface, #221c17);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
}

.page-item-filmstrip-context-item {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  border-radius: 6px;
  cursor: pointer;
}

.page-item-filmstrip-context-item:hover {
  background: rgba(196, 149, 106, 0.16);
}

.page-item-filmstrip-context-item.danger {
  color: #f0c4b6;
}

.page-item-filmstrip-context-item.danger:hover {
  background: rgba(214, 117, 82, 0.18);
}

.page-item-filmstrip-context-note {
  padding: 0.45rem 0.65rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.page-item-rail {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1rem 1.1rem;
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: rgba(18, 15, 13, 0.55);
}

.page-item-readonly-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.page-item-readonly-type {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-transform: capitalize;
}

.page-item-rail-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.page-item-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--text);
  font-size: 0.88rem;
}

.page-item-field input,
.page-item-field select,
.page-item-field textarea {
  min-height: 42px;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
}

.page-item-field textarea {
  min-height: 7rem;
  resize: vertical;
  line-height: 1.45;
}

.page-item-caption-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.page-item-caption-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-item-caption-status {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.page-item-caption-status.error {
  color: #f0c4b6;
}

.page-item-faces-block {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.page-item-faces-heading {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.page-item-faces {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.page-item-face-chip {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 0.55rem;
  align-items: center;
  min-width: 12rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
}

.page-item-face-chip img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg);
}

.page-item-face-name {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-item-face-source {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.page-item-readonly {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--text);
}

.caption-title {
  color: var(--accent);
  font-size: 1rem;
  margin-bottom: 0.75rem;
  font-weight: normal;
  font-style: italic;
}

.caption-body {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
  max-height: 300px;
  overflow-y: auto;
}

.caption-body p { margin-bottom: 0.5rem; }
.caption-body ul, .caption-body ol { margin: 0.5rem 0 0.5rem 1.5rem; }
.caption-body strong { color: var(--accent); }

.caption-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.caption-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.caption-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.caption-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Comments Panel */
#comments-panel {
  display: flex;
  gap: 1px;
  background: var(--border);
  margin-top: 1px;
}

.comments-col {
  flex: 1;
  background: var(--bg-surface);
  padding: 1rem 1.5rem;
}

.comments-col h4 {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: normal;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.comments-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.comment-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.comment-item:last-child { border-bottom: none; }

.comment-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.comment-meta .author {
  color: var(--accent);
  font-weight: bold;
}

.comment-text {
  font-size: 0.85rem;
  line-height: 1.5;
}

.comment-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.75rem;
  float: right;
  opacity: 0.6;
}

.comment-delete:hover { opacity: 1; }

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.comment-form input,
.comment-form textarea {
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
}

.comment-form input:focus,
.comment-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.comment-form button {
  align-self: flex-end;
  min-height: 44px;
  padding: 0.35rem 0.75rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h3 {
  color: var(--accent);
  font-weight: normal;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.analytics-notice-content {
  max-width: 640px;
}

.analytics-notice-copy {
  color: var(--text);
  line-height: 1.6;
}

.analytics-notice-list {
  margin: 1rem 0;
  padding-left: 1.2rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.analytics-notice-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  align-items: center;
  margin-top: 1.25rem;
}

.suggest-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  margin-bottom: 1rem;
}

/* Suggest & Edit Caption Forms */
#suggest-form label,
#edit-caption-form label,
#edit-transcript-form label,
#edit-translation-form label,
#edit-group-form label,
#group-manage-form label,
#sequence-manage-form label {
  display: block;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

#suggest-form input,
#suggest-form textarea,
#edit-caption-form input,
#edit-caption-form textarea,
#edit-transcript-form input,
#edit-transcript-form textarea,
#edit-translation-form input,
#edit-translation-form textarea,
#edit-group-form input,
#edit-group-form textarea,
#group-manage-form input,
#group-manage-form textarea,
#sequence-manage-form input,
#sequence-manage-form textarea,
#sequence-manage-form select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

#suggest-form input:focus,
#suggest-form textarea:focus,
#edit-caption-form input:focus,
#edit-caption-form textarea:focus,
#edit-transcript-form input:focus,
#edit-transcript-form textarea:focus,
#edit-translation-form input:focus,
#edit-translation-form textarea:focus,
#edit-group-form input:focus,
#edit-group-form textarea:focus,
#group-manage-form input:focus,
#group-manage-form textarea:focus,
#sequence-manage-form input:focus,
#sequence-manage-form textarea:focus,
#sequence-manage-form select:focus {
  outline: none;
  border-color: var(--accent);
}

#suggest-form button,
#edit-caption-form button,
#edit-transcript-form button,
#edit-translation-form button,
#group-manage-form button[type="submit"],
#sequence-manage-form button[type="submit"] {
  margin-top: 0.5rem;
  padding: 0.6rem 1.5rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: bold;
}

/* History Modal */
.history-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.history-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.history-body {
  font-size: 0.85rem;
  line-height: 1.5;
  max-height: 100px;
  overflow: hidden;
}

/* Admin Panel */
#admin-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 450px;
  max-width: 90vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 90;
  box-shadow: -10px 0 40px rgba(0,0,0,0.5);
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 2;
}

.admin-header h3 {
  color: var(--accent);
  font-weight: normal;
}

.admin-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.badge {
  background: var(--accent);
  color: var(--bg);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

.badge-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 0.35rem;
  vertical-align: super;
}

.admin-item {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.admin-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.admin-item-page {
  color: var(--accent);
  font-weight: bold;
  text-decoration: none;
  cursor: pointer;
}

.admin-item-page:hover {
  text-decoration: underline;
}

.admin-item-author {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.admin-item-body {
  font-size: 0.85rem;
  line-height: 1.5;
  max-height: 120px;
  overflow: hidden;
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  background: var(--bg);
  border-radius: 4px;
}

.admin-item-reason {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 0.5rem;
}

.admin-actions {
  display: flex;
  gap: 0.5rem;
}

.admin-actions button {
  padding: 0.35rem 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

.btn-approve { background: var(--success); color: var(--bg); }
.btn-reject { background: var(--danger); color: #fff; }

/* Admin Cover Section */
.admin-cover-section {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.admin-cover-section .admin-section-title {
  margin: 0 0 0.5rem;
}

.admin-cover-current {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.admin-cover-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.admin-cover-picker label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text);
}

.admin-cover-picker input[type="number"] {
  width: 4.5rem;
  padding: 0.3rem 0.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}

/* Admin Groups Section */
.admin-groups-section {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.admin-groups-section .admin-section-title {
  margin: 0 0 0.5rem;
}

/* Danger Zone — destructive book-level actions (superadmin only) */
.admin-danger-section {
  padding: 1rem 1.25rem;
  margin-top: 1rem;
  border-top: 1px solid var(--danger, #c44);
  background: rgba(200, 50, 50, 0.04);
}

.admin-danger-section .admin-section-title {
  margin: 0 0 0.5rem;
  color: var(--danger, #c44);
}

.admin-danger-note {
  font-size: 0.85em;
  color: var(--muted, #888);
  margin: 0 0 0.75rem;
  line-height: 1.4;
}

.admin-danger-section .btn-danger {
  background: transparent;
  color: var(--danger, #c44);
  border: 1px solid var(--danger, #c44);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.15s, color 0.15s;
}

.admin-danger-section .btn-danger:hover {
  background: var(--danger, #c44);
  color: #fff;
}

.admin-group-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.admin-group-item:last-of-type {
  border-bottom: none;
}

.admin-group-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.admin-group-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.admin-group-label {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-group-range {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.admin-group-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.admin-group-actions button {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}

.admin-group-delete {
  color: var(--danger) !important;
  font-size: 1.1rem !important;
  line-height: 1;
}

#admin-group-add-btn,
#admin-sequence-add-btn {
  margin-top: 0.5rem;
  width: 100%;
  text-align: center;
}

/* Group Manage Modal */
.group-manage-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: -0.25rem 0 0.5rem;
}

.group-manage-hint code {
  background: var(--bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.8rem;
}

.group-manage-range {
  display: flex;
  gap: 1rem;
}

.group-manage-range label {
  flex: 1;
}

.group-manage-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* Person links in captions */
.person-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: bold;
  border-bottom: 1px dotted var(--accent);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.person-link:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
  border-bottom-style: solid;
}

/* Unresolved person reference — clickable pill (admin resolves via review modal) */
.person-link-unresolved {
  color: #e8a96b;
  font-weight: bold;
  border-bottom: 1px dashed #e8a96b;
  cursor: help;
  padding: 0 2px;
  transition: background-color 0.15s, color 0.15s;
}

.person-link-unresolved:hover,
.person-link-unresolved:focus {
  background-color: rgba(232, 169, 107, 0.12);
  color: #ffc389;
  outline: none;
}

.person-link-unresolved[data-status="ambiguous"]::after {
  content: " ?";
  font-size: 0.85em;
  opacity: 0.7;
}

/* Resolver modal — candidate list */
#caption-review-modal .review-ref-header {
  margin-bottom: 1rem;
}

#caption-review-modal .review-ref-header code {
  background: rgba(232, 169, 107, 0.15);
  color: #ffc389;
  padding: 2px 6px;
  border-radius: 3px;
}

#caption-review-modal .review-candidates {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1rem;
  max-height: 300px;
  overflow-y: auto;
}

#caption-review-modal .review-candidate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.4rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

#caption-review-modal .review-candidate:hover,
#caption-review-modal .review-candidate:focus {
  background: rgba(196, 149, 106, 0.1);
  border-color: var(--accent);
  outline: none;
}

#caption-review-modal .review-candidate-meta {
  color: var(--muted, #888);
  font-size: 0.85em;
  white-space: nowrap;
}

#caption-review-modal .review-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#caption-review-modal .review-actions button {
  flex: 1 1 auto;
}

/* People Directory Panel */
#people-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 450px;
  max-width: 90vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 90;
  box-shadow: -10px 0 40px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
}

.people-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
  flex-shrink: 0;
}

.people-header h3 {
  color: var(--accent);
  font-weight: normal;
}

.people-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

#people-search {
  width: calc(100% - 2.5rem);
  margin: 0.75rem 1.25rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

#people-search:focus {
  outline: none;
  border-color: var(--accent);
}

.people-list {
  flex: 1;
  overflow-y: auto;
}

.people-letter-group {
  margin-bottom: 0.25rem;
}

.people-letter {
  padding: 0.4rem 1.25rem;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--bg-surface);
  position: sticky;
  top: 0;
}

.people-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1.25rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.people-list-item:hover {
  background: var(--bg-surface);
}

.people-name {
  color: var(--text);
  font-size: 0.9rem;
}

.people-page-count {
  color: var(--text-muted);
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* People profile view */
.people-back-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.75rem 1.25rem;
  text-align: left;
}

.people-back-btn:hover {
  color: var(--accent-hover);
}

#people-profile-view {
  padding-bottom: 1rem;
}

#person-name {
  color: var(--accent);
  font-size: 1.3rem;
  font-weight: normal;
  padding: 0 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

#person-bio {
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}

.person-pages-heading {
  padding: 0.5rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.person-life-facts {
  padding: 0.25rem 1.25rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.person-life-facts.hidden {
  display: none;
}

.person-life-sep {
  margin: 0 0.4rem;
  opacity: 0.6;
}

#person-pages {
  display: flex;
  flex-direction: column;
}

.person-page-link {
  display: block;
  padding: 0.5rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.person-page-link:hover {
  background: var(--bg-surface);
  color: var(--accent);
}

/* Face Strip */
#face-strip-panel {
  display: flex;
  gap: 1px;
  background: var(--border);
  margin-top: 1px;
}

.face-strip-col {
  flex: 1;
  background: var(--bg-surface);
  padding: 0.5rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  min-height: 44px;
}

.face-strip-empty {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-style: italic;
}

.face-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
  transition: transform 0.15s;
}

.face-chip:hover {
  transform: scale(1.1);
}

.face-chip img,
.face-chip .face-sprite {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  transition: border-color 0.2s;
  background-repeat: no-repeat;
}

.face-chip.identified img,
.face-chip.identified .face-sprite {
  border-color: var(--accent);
}

.face-chip.verified img,
.face-chip.verified .face-sprite {
  border-color: var(--success);
}

.face-chip:hover img,
.face-chip:hover .face-sprite {
  border-color: var(--accent-hover);
}

.face-chip-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  max-width: 56px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.face-chip.identified .face-chip-label {
  color: var(--accent);
}

/* Face Modal — Compact Card */
.face-modal-content {
  max-width: 400px;
  width: calc(100% - 2rem);
  box-sizing: border-box;
}

.face-modal-subject {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.face-modal-subject img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
  flex-shrink: 0;
}

.face-modal-subject h4 {
  color: var(--text);
  font-size: 1rem;
  font-weight: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-width: 0;
}

/* Primary action buttons */
.face-modal-primary-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.face-modal-primary-actions button {
  min-height: 48px;
  padding: 0.75rem 0.5rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary-action {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

.btn-primary-action:hover {
  background: var(--accent-hover);
}

.btn-secondary-action {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border) !important;
}

.btn-secondary-action:hover {
  background: var(--border);
}

.btn-secondary-action .match-count {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Secondary actions (admin/organizer moderation) */
.face-modal-secondary-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.face-modal-secondary-actions button {
  min-height: 40px;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

/* Collapsible appearances accordion */
.face-appearances-section {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.face-appearances-section.expanded {
  max-height: 500px;
}

.face-matches-scroll {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding: 0.5rem 0;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.face-match-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 6px;
  transition: background 0.15s;
  scroll-snap-align: start;
  flex-shrink: 0;
}

.face-match-item:hover {
  background: var(--bg-surface);
}

.face-match-item img,
.face-match-item .face-sprite {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background-repeat: no-repeat;
}

.face-match-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  max-width: 80px;
}

.face-match-page {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: bold;
}

.face-match-caption {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80px;
}

.face-match-person {
  font-size: 0.7rem;
  color: var(--success);
}

.face-match-book {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-style: italic;
}

.face-match-item.cross-book .face-match-page::before {
  content: "\1F4D6 ";
  font-size: 0.65rem;
}

.face-no-matches {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
  padding: 0.5rem 0;
}

/* Bottom Sheet */
.bottom-sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 350;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.bottom-sheet-scrim.visible {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 351;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  max-height: 70vh;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

.bottom-sheet.open {
  transform: translateY(0);
}

.bottom-sheet-handle {
  display: flex;
  justify-content: center;
  padding: 0.75rem 0 0.25rem;
  cursor: grab;
}

.bottom-sheet-handle span {
  width: 40px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 3px;
  opacity: 0.5;
}

.bottom-sheet-body {
  padding: 0.75rem 1.25rem 1.5rem;
}

.bottom-sheet-title {
  color: var(--accent);
  font-size: 1rem;
  font-weight: normal;
  margin-bottom: 0.75rem;
}

.bottom-sheet-suggestions {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.bottom-sheet-suggestions:empty {
  display: none;
}

.bottom-sheet .face-name-search-wrapper {
  margin-bottom: 0.75rem;
}

.bottom-sheet .face-name-search {
  min-height: 44px;
  font-size: 1rem;
  padding: 0.6rem 0.8rem;
}

.bottom-sheet .face-name-list {
  max-height: 180px;
}

.bottom-sheet .face-name-item {
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.bottom-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.bottom-sheet-actions button {
  min-height: 48px;
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}

/* Person Face Gallery (People Directory) */
.person-face-gallery-heading {
  padding: 0.5rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.person-face-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.25rem 1.25rem 0.75rem;
}

.person-face-thumb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.person-face-thumb:hover {
  border-color: var(--accent);
  transform: scale(1.1);
}

/* Person admin controls */
.person-admin-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.person-admin-btn {
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.person-admin-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.person-admin-btn-danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Add Face button chip */
.face-chip-add {
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.15s;
}

.face-chip-add:hover {
  opacity: 1;
}

.face-chip-add-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px dashed var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--text-muted);
  transition: border-color 0.2s, color 0.2s;
}

.face-chip-add:hover .face-chip-add-icon {
  border-color: var(--accent);
  color: var(--accent);
}

/* Add Face overlay */
#add-face-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  cursor: crosshair;
  z-index: 20;
}

.add-face-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
}

#add-face-selection {
  display: none;
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(139, 115, 85, 0.2);
  pointer-events: none;
}

.add-face-cancel {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.3rem 1rem;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
}

.add-face-cancel:hover {
  background: var(--bg);
}

/* === Face Boxes Overlay === */
.face-boxes-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
}

.face-box {
  position: absolute;
  border: 2px solid #d9534f;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}

.face-box:hover {
  box-shadow: 0 0 12px rgba(217, 83, 79, 0.6), 0 0 0 1px rgba(0,0,0,0.4);
}

.face-box.identified {
  border-color: #5ac47a;
}

.face-box.identified:hover {
  box-shadow: 0 0 12px rgba(90, 196, 122, 0.6), 0 0 0 1px rgba(0,0,0,0.4);
}

.face-box.ignored {
  border-color: #888;
  opacity: 0.5;
  border-style: dashed;
}

.face-box.ignored:hover {
  box-shadow: 0 0 12px rgba(136, 136, 136, 0.4), 0 0 0 1px rgba(0,0,0,0.4);
}

.face-box-label {
  position: absolute;
  bottom: -1.4em;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 22, 18, 0.85);
  color: var(--text);
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.face-box.identified .face-box-label {
  color: #5ac47a;
}

.face-box.ignored .face-box-label {
  color: #888;
}

/* Remove Face (danger button) */
.face-modal-assign .btn-danger {
  background: var(--danger);
  color: #fff;
}

.face-modal-assign .btn-danger:hover {
  opacity: 0.85;
}

/* --- Face modal: suggestion chips --- */
.face-suggestions {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.face-suggestion-chip {
  padding: 0.3rem 0.7rem;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.face-suggestion-chip:hover {
  background: var(--accent);
  color: var(--bg);
}

.suggestion-dist {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-left: 0.3rem;
}

/* --- Face modal: searchable name typeahead --- */
.face-name-search-wrapper {
  position: relative;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.face-name-search {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}

.face-name-search:focus {
  outline: none;
  border-color: var(--accent);
}

.face-name-selected {
  flex: 1;
  padding: 0.4rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
}

.face-name-selected:empty {
  display: none;
}

.face-name-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  line-height: 1;
}

.face-name-clear:hover {
  color: var(--danger);
}

.face-name-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0 0 4px 4px;
  z-index: 10;
}

.face-name-list.visible {
  display: block;
}

.face-name-item {
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
}

.face-name-item:hover,
.face-name-item.highlighted {
  background: var(--accent);
  color: var(--bg);
}

.face-name-empty {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* --- Shared button variants (used in face modal + bottom sheet) --- */
.btn-danger {
  background: var(--danger) !important;
  color: #fff !important;
}

.btn-danger:hover {
  opacity: 0.85;
}

.btn-warning {
  background: #8b6914 !important;
  color: #fff !important;
}

.btn-warning:hover {
  background: #a07a18 !important;
}

.btn-secondary {
  background: var(--bg-surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
}

.btn-secondary:hover {
  background: var(--border) !important;
}

/* User-added face indicator */
.face-chip.user-added img,
.face-chip.user-added .face-sprite {
  border-color: var(--text-muted);
  border-style: dashed;
}

.face-chip.user-added .face-chip-label {
  font-style: italic;
}

/* Flagged face indicator */
.face-chip.flagged {
  opacity: 0.4;
}

.face-chip.flagged img,
.face-chip.flagged .face-sprite {
  border-color: var(--danger);
  border-style: dashed;
}

.face-flagged-note {
  color: var(--danger);
  font-size: 0.8rem;
  font-style: italic;
}

/* Removed faces (admin view) */
.face-strip-removed-label {
  color: var(--text-muted);
  font-size: 0.65rem;
  font-style: italic;
  align-self: center;
  margin-left: 0.5rem;
  border-left: 1px solid var(--border);
  padding-left: 0.75rem;
}

.face-chip-removed {
  opacity: 0.35;
}

.face-chip-removed img,
.face-chip-removed .face-sprite {
  border-color: var(--danger) !important;
  filter: grayscale(0.8);
}

.face-chip-removed:hover {
  opacity: 0.8;
}

.face-chip-restore {
  color: var(--accent) !important;
  cursor: pointer;
}

/* AI Badge */
.ai-badge {
  display: inline-block;
  background: var(--border);
  color: var(--text-muted);
  font-size: 0.6rem;
  font-style: normal;
  font-weight: bold;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  margin-left: 0.5rem;
  vertical-align: middle;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Page Group Indicator — Banner Style */
.page-group-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--group-banner-color, var(--accent));
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.page-group-label {
  font-weight: bold;
  color: var(--group-banner-color, var(--accent));
}

.page-group-position {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.page-group-nav {
  display: flex;
  gap: 0.5rem;
}

.page-group-indicator .group-nav {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  transition: all 0.2s;
}

.page-group-indicator .group-nav:hover {
  color: var(--accent-hover);
  border-color: var(--accent);
  background: var(--bg-surface);
}

/* Reading sequence indicator */
.page-sequence-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--sequence-color, var(--accent));
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.page-sequence-label {
  font-weight: bold;
  color: var(--sequence-color, var(--accent));
}

.page-sequence-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.page-sequence-nav {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
}

.page-sequence-nav:hover {
  color: var(--accent-hover);
  border-color: var(--accent);
  background: var(--bg-surface);
}

/* Reading sequence view */
.sequence-active #book-container,
.sequence-active #resize-handle,
.sequence-active #book-audio-panel,
.sequence-active #page-jump,
.sequence-active #thumbnail-strip-container,
.sequence-active #face-strip-panel,
.sequence-active #caption-panel,
.sequence-active #page-items-summary-panel,
.sequence-active #comments-panel {
  display: none !important;
}

#app-screen.sequence-active {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sequence-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

.sequence-view.hidden {
  display: none;
}

.sequence-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.sequence-heading {
  flex: 1;
  min-width: 0;
}

.sequence-heading h2 {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1.25;
}

.sequence-meta,
.sequence-summary {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.sequence-summary {
  margin-top: 0.35rem;
  color: var(--text);
}

.sequence-layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  min-height: 0;
  overflow: hidden;
}

.sequence-rail {
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 0.75rem;
  overflow-y: auto;
}

.sequence-entries,
.sequence-pages {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sequence-entries {
  margin-bottom: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.sequence-entry-btn,
.sequence-page-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.sequence-entry-btn {
  padding: 0.5rem 0.6rem;
}

.sequence-page-btn {
  min-height: 36px;
  padding: 0.35rem 0.55rem;
}

.sequence-entry-btn:hover,
.sequence-entry-btn.active,
.sequence-page-btn:hover,
.sequence-page-btn.active {
  border-color: var(--accent);
  background: rgba(196, 149, 106, 0.12);
}

.sequence-entry-title,
.sequence-entry-meta {
  display: block;
}

.sequence-entry-title {
  font-size: 0.85rem;
}

.sequence-entry-meta {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-top: 0.1rem;
}

.sequence-main {
  display: grid;
  grid-template-columns: minmax(320px, 48%) minmax(320px, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.sequence-scan-panel,
.sequence-text-panel {
  min-width: 0;
  min-height: 0;
}

.sequence-scan-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
}

.sequence-scan-status {
  padding: 0.6rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
}

.sequence-scan-panel img {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: var(--bg-card);
}

.sequence-text-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sequence-text-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 0.35rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  z-index: 2;
  flex-wrap: wrap;
}

.sequence-text-tabs button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  min-height: 34px;
  padding: 0.35rem 0.7rem;
  font-family: inherit;
  cursor: pointer;
}

.sequence-text-tabs button.active,
.sequence-text-tabs button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sequence-text-content {
  flex: 1 1 auto;
  min-height: 0;
  padding: 1rem 1.25rem 3rem;
  overflow-y: auto;
  line-height: 1.7;
}

.sequence-text-content > * {
  max-width: 780px;
}

.sequence-text-block {
  margin: 0 0 0.9rem;
}

.sequence-text-entry_heading {
  color: var(--accent);
  font-size: 1.05rem;
  margin-top: 1.35rem;
}

.sequence-source-link {
  margin-left: 0.5rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  font-size: 0.72rem;
  cursor: pointer;
  font-family: inherit;
}

.sequence-page-break {
  margin: 1.2rem 0;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.sequence-transcript {
  white-space: pre-wrap;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  margin: 0;
}

.sequence-transcript-page {
  margin: 0 0 1.3rem;
  padding-top: 0.2rem;
}

.sequence-transcript-page + .sequence-transcript-page {
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.sequence-transcript-page-label {
  margin-bottom: 0.45rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.sequence-empty {
  color: var(--text-muted);
  margin: 0;
}

@media (max-width: 900px) {
  #app-screen.sequence-active #app-header {
    display: none;
  }

  .sequence-header {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
  }

  #sequence-back-btn {
    flex: 0 0 auto;
    padding: 0.3rem 0.55rem;
    font-size: 0.95rem;
  }

  .sequence-back-label {
    display: none;
  }

  .sequence-heading {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.15rem 0.5rem;
  }

  .sequence-heading h2 {
    font-size: 1rem;
    margin: 0;
    line-height: 1.25;
  }

  .sequence-meta {
    font-size: 0.8rem;
  }

  .sequence-summary {
    display: none;
  }

  .sequence-layout,
  .sequence-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .sequence-rail {
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.4rem;
  }

  .sequence-entries,
  .sequence-pages {
    flex-direction: row;
    min-width: max-content;
    gap: 0.25rem;
  }

  .sequence-entries {
    margin-bottom: 0;
    padding-bottom: 0;
    padding-right: 0.5rem;
    margin-right: 0.5rem;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }

  .sequence-entry-btn {
    width: 170px;
  }

  .sequence-page-btn {
    width: 36px;
    min-height: 26px;
    padding: 0.2rem 0.35rem;
    text-align: center;
  }

  .sequence-scan-status {
    display: none;
  }

  .sequence-scan-panel {
    flex: 0 0 min(42vh, 320px);
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sequence-text-panel {
    flex: 1 1 auto;
    min-height: 0;
  }

  .sequence-text-content > * {
    max-width: none;
  }
}

/* Transcript Block */
.transcript-block {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-height: 250px;
  overflow-y: auto;
}

.transcript-text {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
}

.transcript-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.transcript-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.4;
  max-width: 40ch;
}

.transcript-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.transcript-toolbar-actions button {
  white-space: nowrap;
}

.transcript-toggle {
  font-style: italic;
}

/* Page Metadata Block (admin) */
.metadata-block {
  margin-top: 0.75rem;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.8rem;
}
.metadata-toggle {
  font-style: italic;
}
.meta-section {
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}
.meta-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}
.meta-section summary {
  cursor: pointer;
  font-weight: bold;
  color: var(--accent);
  padding: 0.2rem 0;
  user-select: none;
}
.meta-section summary:hover {
  text-decoration: underline;
}
.meta-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.25rem 0;
}
.meta-table td {
  padding: 0.15rem 0.4rem;
  vertical-align: top;
}
.meta-table td:first-child {
  color: var(--text-muted);
  white-space: nowrap;
  width: 1%;
}
.meta-detail-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.25rem 0;
  font-size: 0.75rem;
}
.meta-detail-table th,
.meta-detail-table td {
  padding: 0.15rem 0.35rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.meta-detail-table th {
  color: var(--text-muted);
  font-weight: normal;
  white-space: nowrap;
}
.meta-detail-table tbody tr:hover {
  background: rgba(196, 149, 106, 0.08);
}
.meta-body-preview,
.meta-body-full {
  margin: 0.25rem 0;
  padding: 0.3rem;
  background: rgba(0,0,0,0.15);
  border-radius: 3px;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}
/* Full (untruncated) description/transcript in the page-info panel — cap height
   and scroll so a long transcript doesn't dominate the metadata sidebar. */
.meta-body-full {
  max-height: 24rem;
  overflow-y: auto;
}
.meta-voice-memory {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.meta-voice-memory:last-child {
  border-bottom: none;
}
.meta-status-ok {
  color: #4a4;
}
.meta-status-err {
  color: #e44;
}
.meta-list {
  padding: 0.25rem 0;
  line-height: 1.6;
}
.meta-comment {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}
.meta-comment:last-child {
  border-bottom: none;
}
.meta-muted {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.person-page-book {
  color: var(--text-muted);
  font-size: 0.8em;
}

.admin-item-book {
  color: var(--text-muted);
  font-size: 0.85em;
  font-style: italic;
}

/* ====== Face Review Screen ====== */
#face-review-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

.fr-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.fr-header h2 {
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: normal;
  white-space: nowrap;
}

.fr-scope-select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}
.fr-scope-select:hover { border-color: var(--accent); }

.fr-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 1;
  justify-content: center;
}

.fr-stat-good { color: var(--success); }
.fr-stat-ai { color: #7eb8da; }
.fr-stat-pending { color: var(--text-muted); }

.fr-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.fr-complete-btn {
  background: var(--success) !important;
  color: var(--bg) !important;
  border-color: var(--success) !important;
  font-weight: bold;
}

.fr-complete-btn:hover {
  opacity: 0.9;
}

.fr-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Names sidebar — resizable */
.fr-names-panel {
  width: var(--fr-names-width, 220px);
  min-width: 140px;
  max-width: 50vw;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.5rem 0;
}

/* Resize handle between names and clusters */
.fr-resize-handle {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  position: relative;
}
.fr-resize-handle:hover,
.fr-resize-handle.fr-resizing {
  background: var(--accent);
}
.fr-resize-handle::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -3px; right: -3px;
}

.fr-name-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  cursor: grab;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  user-select: none;
}

.fr-name-item:hover {
  background: var(--bg-card);
}

.fr-name-item.dragging {
  opacity: 0.5;
  background: var(--bg-card);
}

.fr-name {
  color: var(--text);
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 3px;
  padding: 0 0.15rem;
  transition: color 0.15s;
}
.fr-name:hover {
  color: var(--accent);
}

.fr-name-main {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  gap: 0.12rem;
}

.fr-name-alias-preview {
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fr-name-count {
  color: var(--text-muted);
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-left: 0.5rem;
  padding: 0 0.25rem;
}

/* Person detail expandable panel */
.fr-person-detail {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  animation: fr-detail-open 0.15s ease-out;
}
@keyframes fr-detail-open {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 300px; }
}

/* Collapsible section toggles */
.fr-detail-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.35rem 0;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
}
.fr-detail-toggle:hover { color: var(--accent-hover); }
.fr-detail-arrow {
  font-size: 0.6rem;
  transition: transform 0.15s;
  display: inline-block;
}
.fr-detail-toggle.fr-detail-open .fr-detail-arrow {
  transform: rotate(90deg);
}
.fr-detail-section {
  overflow: hidden;
  padding: 0.4rem 0;
}
.fr-detail-section.fr-detail-collapsed {
  display: none;
}

.fr-detail-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.45rem;
}

.fr-detail-action-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.7rem;
  transition: all 0.15s;
}

.fr-detail-action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.fr-detail-action-btn-danger {
  color: var(--danger);
  border-color: rgba(196, 90, 90, 0.35);
}

.fr-detail-action-btn-danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.fr-detail-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}
.fr-detail-faces {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 0;
  scrollbar-width: thin;
}
.fr-detail-face {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.fr-detail-face:hover {
  border-color: var(--accent);
}
.fr-detail-pages {
  max-height: 120px;
  overflow-y: auto;
  margin-top: 0.4rem;
  scrollbar-width: thin;
}
.fr-detail-page {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 1px 0;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}
.fr-detail-page:hover {
  color: var(--accent);
}
.fr-detail-page-num {
  color: var(--accent);
  font-weight: 600;
  margin-right: 0.3rem;
}
.fr-detail-page-book {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-right: 0.3rem;
}
.fr-detail-bio {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 0.3rem;
}
.fr-detail-loading {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.25rem 0;
}

.fr-detail-aliases {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.fr-detail-alias-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.fr-detail-alias-row:last-child {
  border-bottom: none;
}

.fr-detail-alias-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.fr-detail-alias-name {
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.35;
  word-break: break-word;
}

.fr-detail-alias-type {
  color: var(--text-muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Clusters grid */
.fr-clusters-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  grid-auto-rows: min-content;
  gap: 1rem;
  align-content: start;
}

.fr-cluster-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.fr-cluster-card.fr-confirmed {
  border-color: var(--success);
}

.fr-cluster-card.fr-drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(196, 149, 106, 0.3);
}

.fr-cluster-card.fr-ignored {
  border-color: var(--text-muted);
  opacity: 0.6;
}
.fr-cluster-card.fr-ignored:hover {
  opacity: 0.85;
}
.fr-ignored-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  margin-top: 0.25rem;
}

.fr-cluster-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 0.5rem;
  max-height: 120px;
  overflow-y: auto;
}

.fr-cluster-grid.fr-cluster-placeholder {
  min-height: 56px;
  background: var(--bg);
  border-radius: 6px;
}

.fr-show-all-btn {
  display: block;
  width: 100%;
  padding: 0.25rem;
  margin-top: 0.25rem;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: background 0.15s, border-color 0.15s;
}
.fr-show-all-btn:hover {
  background: var(--bg);
  border-color: var(--accent);
}
.fr-show-all-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.fr-face-menu {
  position: fixed;
  z-index: 10000;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  padding: 4px 0;
  min-width: 140px;
}
.fr-face-menu-item {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}
.fr-face-menu-item:hover {
  background: var(--accent);
  color: var(--bg);
}
.fr-face-menu-eject {
  color: var(--danger, #e57373);
}
.fr-face-menu-ignore {
  color: var(--text-muted);
}

.fr-cluster-face {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.fr-sprite-face {
  display: inline-block;
  background-repeat: no-repeat;
  object-fit: unset;
}

.fr-cluster-face:hover {
  border-color: var(--danger);
  transform: scale(1.1);
}

/* Pagination bar for face clusters */
.fr-pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.fr-page-btn {
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  transition: background 0.15s, border-color 0.15s;
}
.fr-page-btn:hover {
  background: var(--bg);
  border-color: var(--accent);
}
.fr-page-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}
.fr-page-status {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.fr-cluster-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.fr-cluster-count { font-weight: bold; }
.fr-cluster-pages { font-style: italic; }

/* Assignment display */
.fr-cluster-assignment {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.35rem 0.5rem;
  background: var(--bg);
  border-radius: 4px;
}

.fr-assigned-name {
  color: var(--success);
  font-weight: bold;
  font-size: 0.85rem;
}

.fr-assigned-badge {
  font-size: 0.65rem;
  color: var(--bg);
  background: var(--success);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fr-suggested-name {
  color: #7eb8da;
  font-size: 0.85rem;
  font-style: italic;
}

.fr-accept-btn {
  padding: 0.2rem 0.6rem;
  background: #7eb8da;
  color: var(--bg);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: bold;
  transition: opacity 0.2s;
}

.fr-accept-btn:hover {
  opacity: 0.85;
}

/* Assign row */
.fr-cluster-assign {
  display: flex;
  gap: 0.35rem;
}

.fr-name-picker {
  flex: 1;
  min-width: 0;
  position: relative;
}
.fr-name-picker-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.3rem 0.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
}
.fr-name-picker-input:focus {
  outline: none;
  border-color: var(--accent);
}
.fr-name-picker-list {
  display: none;
  position: fixed;
  z-index: 1000;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
}
.fr-name-picker-list.visible {
  display: block;
}
.fr-name-picker-item {
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fr-name-picker-item:hover,
.fr-name-picker-item.highlighted {
  background: var(--accent);
  color: var(--bg);
}
.fr-name-picker-create {
  color: var(--accent);
  font-style: italic;
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 0.4rem;
}

.fr-empty {
  color: var(--text-muted);
  font-style: italic;
  padding: 2rem;
  text-align: center;
  grid-column: 1 / -1;
}

/* Face preview overlay */
.fr-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.fr-preview-container {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  cursor: default;
}

.fr-preview-image {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  display: block;
  border-radius: 4px;
}

.fr-preview-bbox {
  position: absolute;
  border: 3px solid #d9534f;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 20px rgba(217, 83, 79, 0.4);
  pointer-events: none;
}

.fr-preview-bbox.identified {
  border-color: #5ac47a;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 20px rgba(90, 196, 122, 0.4);
}

.fr-preview-bbox.ignored {
  border-color: #888;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 12px rgba(136, 136, 136, 0.3);
  border-style: dashed;
  opacity: 0.6;
}

.fr-preview-label {
  position: absolute;
  bottom: -2rem;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* --- Rename inline edit --- */
.fr-name-edit {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 0.25rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
  margin-left: auto;
}

.fr-name-item:hover .fr-name-edit {
  opacity: 1;
}

.fr-name-edit:hover {
  color: var(--accent);
}

.fr-name-input {
  flex: 1;
  min-width: 0;
  padding: 0.2rem 0.4rem;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}

/* --- Merge multi-select --- */
.fr-name-select {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.fr-name-item.fr-name-selected {
  background: rgba(196, 149, 106, 0.15);
  border-left: 3px solid var(--accent);
  padding-left: calc(0.75rem - 3px);
}

.fr-merge-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  font-size: 0.8rem;
}

.fr-merge-bar span {
  color: var(--text-muted);
}

.fr-merge-btn {
  padding: 0.25rem 0.6rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: bold;
}

.fr-merge-btn:hover {
  background: var(--accent-hover);
}

.fr-merge-clear {
  padding: 0.25rem 0.5rem;
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
}

.fr-merge-clear:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.fr-merge-dialog {
  padding: 0.75rem;
  background: var(--bg-card);
  border-top: 2px solid var(--accent);
  position: sticky;
  bottom: 0;
}

.fr-merge-dialog-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.fr-merge-dialog-or {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0.3rem 0 0.2rem;
}

.fr-merge-dialog select,
.fr-merge-dialog input {
  width: 100%;
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
}

.fr-merge-dialog-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.fr-merge-confirm {
  padding: 0.25rem 0.6rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: bold;
}

.fr-merge-confirm:hover { background: var(--accent-hover); }

.fr-merge-cancel {
  padding: 0.25rem 0.5rem;
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
}

.fr-merge-cancel:hover { color: var(--text); border-color: var(--text-muted); }

/* --- Face drag-and-drop --- */
.fr-face-dragging {
  opacity: 0.4 !important;
  border-color: var(--accent) !important;
}

.fr-name-item.fr-drag-over {
  background: rgba(196, 149, 106, 0.2);
  outline: 2px solid var(--accent);
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- FR Tab bar (hidden on desktop, shown in portrait) --- */
.fr-tab-bar {
  display: none;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0;
  flex-shrink: 0;
}
.fr-tab {
  flex: 1;
  padding: 0.6rem 0.5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  text-align: center;
}
.fr-tab:hover { color: var(--text); }
.fr-tab.fr-tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* --- FR Filter chip --- */
.fr-filter-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  background: rgba(196, 149, 106, 0.12);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--accent);
  flex-shrink: 0;
}
.fr-filter-chip.hidden { display: none; }
.fr-filter-chip-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.25rem;
  line-height: 1;
}
.fr-filter-chip-close:hover { color: var(--text); }

/* --- FR Search bar --- */
.fr-search-bar {
  display: flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 0.4rem;
}
.fr-search-input {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
}
.fr-search-input:focus {
  outline: none;
  border-color: var(--accent);
}
.fr-search-input::placeholder {
  color: var(--text-muted);
}
.fr-search-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.25rem;
  line-height: 1;
  flex-shrink: 0;
}
.fr-search-clear:hover { color: var(--text); }
.fr-search-clear.hidden { display: none; }

/* --- FR Toast --- */
.fr-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.85rem;
  color: var(--text);
  z-index: 9000;
  animation: fr-toast-in 0.2s ease-out;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}
.fr-toast-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  font-family: inherit;
  font-size: inherit;
}
@keyframes fr-toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(1rem); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* --- FR Cluster highlight (desktop scroll-to) --- */
.fr-cluster-card.fr-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(196, 149, 106, 0.4);
}

/* --- FR "Show in Faces" button (hidden on desktop) --- */
.fr-detail-show-faces {
  display: none;
}

/* ===== Portrait / Mobile: Face Review ===== */

#face-review-screen.portrait-mode .fr-tab-bar {
  display: flex;
}

#face-review-screen.portrait-mode .fr-resize-handle {
  display: none;
}

#face-review-screen.portrait-mode .fr-names-panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-right: none;
  border-bottom: 1px solid var(--border);
  display: none;
  flex: 1;
  overflow-y: auto;
}
#face-review-screen.portrait-mode .fr-names-panel.fr-tab-visible {
  display: block;
}

#face-review-screen.portrait-mode .fr-clusters-panel {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
#face-review-screen.portrait-mode .fr-clusters-panel.fr-tab-hidden {
  display: none;
}

#face-review-screen.portrait-mode .fr-name-edit {
  opacity: 1;
}

#face-review-screen.portrait-mode .fr-name-item {
  padding: 0.65rem 0.75rem;
}
#face-review-screen.portrait-mode .fr-name {
  font-size: 0.95rem;
  white-space: normal;
}

#face-review-screen.portrait-mode .fr-name-alias-preview {
  white-space: normal;
}

#face-review-screen.portrait-mode .fr-header {
  padding: 0.5rem 0.75rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}
#face-review-screen.portrait-mode .fr-header h2 {
  font-size: 0.95rem;
}
#face-review-screen.portrait-mode .fr-stats {
  font-size: 0.7rem;
  gap: 0.5rem;
}
#face-review-screen.portrait-mode .fr-header-actions .btn-subtle {
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
}

#face-review-screen.portrait-mode .fr-merge-dialog {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5000;
  border-radius: 12px 12px 0 0;
  border-top: 2px solid var(--accent);
  padding: 1rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}

#face-review-screen.portrait-mode .fr-detail-show-faces {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.3rem 0.6rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
}
#face-review-screen.portrait-mode .fr-detail-show-faces:hover {
  opacity: 0.85;
}

#face-review-screen.portrait-mode .fr-detail-faces {
  flex-wrap: wrap;
  overflow-x: visible;
}
#face-review-screen.portrait-mode .fr-detail-face {
  width: 48px;
  height: 48px;
}
#face-review-screen.portrait-mode .fr-detail-pages {
  max-height: 200px;
}

/* ===== Portrait / Mobile Mode ===== */

/* Header: compact */
.portrait-mode #app-header {
  padding: 0.5rem 0.75rem;
  gap: 0.5rem;
}

.portrait-mode .header-book-title {
  font-size: 0.9rem;
}

.portrait-mode .header-actions {
  gap: 0.4rem;
}

.portrait-mode .btn-subtle {
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
}

/* Page jump: compact */
.portrait-mode #page-jump {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.portrait-mode #page-indicator {
  margin-left: 0;
}

/* Hide resize handle on mobile — height is auto */
.portrait-mode #resize-handle {
  display: none;
}

/* Panels: single column — hide right columns */
.portrait-mode #caption-panel,
.portrait-mode #page-items-summary-panel,
.portrait-mode #comments-panel,
.portrait-mode #face-strip-panel {
  display: block;
}

.portrait-mode #caption-right,
.portrait-mode #page-items-summary-right,
.portrait-mode #comments-right,
.portrait-mode #face-strip-right {
  display: none;
}

.portrait-mode .page-items-summary-controls,
.portrait-mode .page-items-summary-columns {
  display: block;
}

.portrait-mode .caption-col,
.portrait-mode .page-items-summary-col,
.portrait-mode .comments-col,
.portrait-mode .face-strip-col {
  padding: 0.75rem;
}

.portrait-mode .page-item-modal-body {
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
}

.portrait-mode .page-item-rail {
  border-left: none;
  border-top: 1px solid var(--border);
  max-height: 50vh;
}

.portrait-mode .page-item-modal-content {
  width: 100vw;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
}

/* People panel: full width on mobile */
.portrait-mode #people-panel {
  width: 100vw;
  max-width: 100vw;
}

/* Admin panel: full width on mobile */
.portrait-mode #admin-panel {
  width: 100vw;
  max-width: 100vw;
}

/* Modals: tighter on mobile */
.portrait-mode .modal-content {
  width: 95vw;
  max-width: 95vw;
  padding: 1rem;
}

/* ===== User Management Screen ===== */
.um-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.um-header h1 {
  font-size: 1.4rem;
  color: var(--accent);
}

.um-body {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.um-loading, .um-error {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.um-error { color: var(--danger); }

.um-families {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.um-family-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.um-family-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: background 0.15s;
}

.um-family-header:hover {
  background: var(--bg-surface);
}

.um-family-info h3 {
  font-size: 1.1rem;
  margin-bottom: 0.2rem;
}

.um-family-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.um-chevron {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.um-family-body {
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
}

.um-member-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.um-member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--bg-surface);
  border-radius: 6px;
  gap: 1rem;
  flex-wrap: wrap;
}

.um-member-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.um-member-email {
  font-weight: bold;
  word-break: break-all;
}

.um-member-name {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.um-status {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  font-family: system-ui, sans-serif;
  letter-spacing: 0.05em;
}

.um-status-active {
  background: rgba(90, 196, 122, 0.2);
  color: var(--success);
}

.um-status-invited {
  background: rgba(196, 149, 106, 0.2);
  color: var(--accent);
}

.um-badge-super {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: rgba(196, 90, 90, 0.2);
  color: var(--danger);
  text-transform: uppercase;
  font-family: system-ui, sans-serif;
}

.um-member-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.um-role-select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  font-family: inherit;
}

.um-role-label {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

.um-remove-btn {
  color: var(--danger) !important;
}

.um-resend-btn {
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  color: var(--accent) !important;
}

.um-resend-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.um-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  width: 100%;
  max-width: 300px;
}

.um-input:focus {
  outline: none;
  border-color: var(--accent);
}

.um-invite-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.um-processor-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.um-section-header h4 {
  margin-bottom: 0.25rem;
}

.um-section-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.85rem;
}

.um-processor-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.um-processor-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-surface);
  border-radius: 6px;
  cursor: pointer;
}

.um-processor-row input[type="checkbox"] {
  margin-top: 0.2rem;
}

.um-processor-copy {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.um-processor-label {
  font-weight: 600;
}

.um-processor-description {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.um-processor-actions {
  margin-top: 0.85rem;
}

.um-invite-form, .um-add-family-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.um-add-family {
  margin-top: 0.5rem;
}

.um-add-family-form {
  margin-top: 0.5rem;
}

.um-save-role {
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
}

/* ---------- Crop & Rotate Modal ---------- */
.crop-rotate-modal-content {
  max-width: 90vw;
  width: 900px;
  max-height: 90vh;
}

/* Opens from within #page-item-modal, so it needs to stack above the base .modal layer (z:300). */
#view-crop-rotate-modal { z-index: 310; }

.crop-rotate-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.crop-rotate-canvas-wrap {
  position: relative;
  width: 100%;
  max-height: 55vh;
  overflow: hidden;
  background: #111;
  border-radius: 4px;
}

.crop-rotate-canvas-wrap img {
  display: block;
  max-width: 100%;
  max-height: 55vh;
}

/* Cropper.js container overrides for dark theme */
.crop-rotate-canvas-wrap .cropper-modal {
  background: rgba(0, 0, 0, 0.6);
}

.crop-rotate-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.cover-crop-source-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.cover-crop-source-label {
  color: var(--text-muted);
}

.cover-crop-source-option {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}

.crop-rotate-rotation label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.rotation-slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.rotation-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 6px;
}

#crop-rotate-degrees {
  min-width: 4rem;
  text-align: right;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.crop-rotate-quick-btns {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.crop-rotate-quick-btns .btn-subtle {
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
}

.crop-rotate-aspect label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.crop-rotate-aspect-btns {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.crop-aspect-btn {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
}

.crop-aspect-btn.active {
  background: var(--accent);
  color: var(--bg);
}

.crop-rotate-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.crop-rotate-actions .btn-accent {
  min-width: 100px;
}

.crop-rotate-actions .btn-accent:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Create Book Screen ===== */
.create-book-body {
  max-width: 600px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.create-book-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.create-book-header h2 {
  font-size: 1.4rem;
  color: var(--accent);
}

.create-book-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.create-book-advanced {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
}

.create-book-advanced > summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  user-select: none;
}

.create-book-advanced > summary:hover {
  color: var(--text);
}

.create-book-advanced[open] {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.create-book-advanced-note {
  margin: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-group .required {
  color: var(--danger);
}

.form-group input,
.form-group textarea,
.form-group select {
  padding: 0.6rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-actions {
  margin-top: 0.5rem;
}

.error-text {
  color: var(--danger);
  font-size: 0.9rem;
}

.btn-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

.btn-back:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* --- Book Card: Create New --- */
.book-card-create {
  border: 2px dashed var(--border);
  background: transparent;
}

.book-card-create:hover {
  border-color: var(--accent);
}

.book-card-create-cover {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
}

.create-book-icon {
  font-size: 3rem;
  color: var(--text-muted);
  line-height: 1;
}

.book-card-create:hover .create-book-icon {
  color: var(--accent);
}

/* ===== Pipeline Management Screen ===== */
.pipeline-body {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.pipeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.pipeline-header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pipeline-header-left h2 {
  font-size: 1.4rem;
  color: var(--accent);
}

.pipeline-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Upload section */
.pipeline-upload-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.pipeline-upload-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.pipeline-upload-header h3 {
  font-size: 1.1rem;
}

.pipeline-page-count {
  font-size: 0.9rem;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
}

.pipeline-dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.pipeline-dropzone:hover,
.pipeline-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(196, 149, 106, 0.05);
}

.pipeline-dropzone p {
  margin: 0.3rem 0;
  color: var(--text-muted);
}

.dropzone-hint {
  font-size: 0.8rem;
}

.pipeline-dropzone input[type="file"] {
  display: none;
}

.pipeline-upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.upload-thumb {
  position: relative;
  width: 80px;
}

.upload-thumb img {
  width: 80px;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.upload-thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-thumb-name {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-upload-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.pipeline-upload-progress {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--accent);
}

/* Incorporate section — mode cards */
.pipeline-incorporate-section {
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
}
.pipeline-incorporate-section h3 {
  font-size: 1.1rem;
  margin: 0 0 0.25rem;
}
.pipeline-incorporate-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}
.pipeline-mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}
.pipeline-mode-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg);
}
.pipeline-mode-card--recommended {
  border-color: var(--accent);
  border-width: 2px;
}
.pipeline-mode-card--destructive {
  border-color: #e57373;
}
.pipeline-mode-card-header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.pipeline-mode-card-header h4 {
  margin: 0;
  font-size: 1rem;
}
.pipeline-mode-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 600;
}
.pipeline-mode-details {
  margin: 0;
  padding: 0 0 0 1.2rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  flex: 1;
}
.pipeline-mode-details li {
  margin-bottom: 0.3rem;
}
.pipeline-mode-run-btn {
  align-self: flex-start;
  margin-top: auto;
}
.pipeline-mode-run-btn--destructive {
  color: #e57373;
  border-color: #e57373;
}
.pipeline-mode-run-btn--destructive:hover {
  background: rgba(229, 115, 115, 0.1);
}

/* Cost estimates */
.pipeline-cost-estimate {
  font-size: 0.82rem;
}
.pipeline-cost-loading, .pipeline-cost-na, .pipeline-cost-error {
  color: var(--text-muted);
  font-style: italic;
}
.pipeline-cost-error { color: #e57373; }
.pipeline-cost-partial { color: var(--text-muted); font-size: 0.75rem; }
.pipeline-cost-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.pipeline-cost-total {
  font-weight: 600;
  color: var(--accent);
}
.pipeline-cost-toggle {
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
}
.pipeline-cost-detail {
  margin-top: 0.5rem;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}
.pipeline-cost-detail th,
.pipeline-cost-detail td {
  text-align: left;
  padding: 0.2rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.pipeline-cost-detail th {
  color: var(--text-muted);
  font-weight: 500;
}
.pipeline-cost-info {
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* Pipeline stages */
.pipeline-stages-section h3 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

#pipeline-stages-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pipeline-stage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 1rem;
}

.pipeline-stage-info {
  flex: 1;
  min-width: 0;
}

.pipeline-stage-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.pipeline-stage-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.pipeline-stage-tag {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  background: rgba(100, 149, 237, 0.2);
  color: #6495ed;
  border-radius: 3px;
  text-transform: uppercase;
  font-weight: 600;
}

.pipeline-stage-tag--aws {
  background: rgba(255, 153, 0, 0.2);
  color: #ff9900;
}

.pipeline-stage-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pipeline-stage-deps {
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 0.15rem;
}

.pipeline-consent-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.pipeline-consent-block .pipeline-consent-btn {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
}

.pipeline-consent-note {
  color: var(--text-muted);
  font-weight: normal;
}

.pipeline-consent-row--focus {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.pipeline-stage-model {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.8;
  margin-top: 0.1rem;
  font-family: monospace;
}

/* Pipeline config section (superadmin) */
.pipeline-config-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.pipeline-config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.pipeline-config-header h3 {
  margin: 0;
  font-size: 1rem;
}

.pipeline-config-chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.pipeline-config-chevron--open {
  transform: rotate(180deg);
}

.pipeline-config-body {
  padding: 0 1rem 1rem;
}

.pipeline-config-refresh {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.pipeline-config-model-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pipeline-config-rows {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.pipeline-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.pipeline-config-label {
  font-size: 0.85rem;
  font-weight: 500;
  min-width: 180px;
  flex-shrink: 0;
}

.pipeline-config-model-kind {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.08rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.2;
}

.pipeline-config-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  justify-content: flex-end;
}

.pipeline-config-model-select,
.pipeline-config-model-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  color: var(--text);
  font-family: monospace;
  font-size: 0.8rem;
  min-width: 240px;
}

.pipeline-config-model-select:focus,
.pipeline-config-model-input:focus {
  outline: none;
  border-color: var(--accent);
}

.pipeline-config-saved {
  font-size: 0.75rem;
  color: var(--success);
  font-weight: 600;
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

/* Status dots */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-not-run {
  background: var(--text-muted);
  opacity: 0.4;
}

.status-partial {
  background: #e8a838;
}

.status-done {
  background: var(--success);
}

.status-running {
  background: #6495ed;
  animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Stage action buttons */
.pipeline-stage-action {
  flex-shrink: 0;
}

.pipeline-run-btn {
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  font-weight: 600;
}

.pipeline-run-btn.btn-accent {
  background: var(--accent);
  color: var(--bg);
}

.pipeline-run-btn.btn-accent:hover {
  background: var(--accent-hover);
}

.pipeline-run-btn.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.pipeline-run-btn.btn-secondary:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}

.pipeline-run-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pipeline-force-btn {
  font-size: 0.75rem;
  border-color: #b56a3a;
  color: #b56a3a;
}

.pipeline-force-btn:hover:not(:disabled) {
  background: rgba(181, 106, 58, 0.15);
  border-color: #d4874e;
  color: #d4874e;
}

.pipeline-run-btn.pipeline-override-btn {
  border-color: #e57373 !important;
  color: #e57373 !important;
}

.pipeline-run-btn.pipeline-override-btn:hover:not(:disabled) {
  background: rgba(229, 115, 115, 0.12) !important;
  border-color: #ef9a9a !important;
  color: #ef9a9a !important;
}

.pipeline-done-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.6;
}

.pipeline-running-indicator {
  font-size: 0.85rem;
  color: #6495ed;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.pipeline-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(100, 149, 237, 0.25);
  border-top-color: #6495ed;
  border-radius: 50%;
  animation: pipeline-spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes pipeline-spin {
  to { transform: rotate(360deg); }
}

.pipeline-running-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: rgba(100, 149, 237, 0.12);
  border: 1px solid rgba(100, 149, 237, 0.3);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  color: #6495ed;
  font-size: 0.9rem;
}

.pipeline-running-text {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pipeline-cancel-btn {
  background: rgba(220, 80, 80, 0.15);
  color: #e06060;
  border: 1px solid rgba(220, 80, 80, 0.4);
  border-radius: 6px;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}

.pipeline-cancel-btn:hover:not(:disabled) {
  background: rgba(220, 80, 80, 0.25);
}

.pipeline-cancel-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.pipeline-failed-banner {
  background: rgba(220, 80, 80, 0.12);
  border: 1px solid rgba(220, 80, 80, 0.3);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  color: #dc5050;
  font-size: 0.9rem;
}

.pipeline-warning-banner {
  background: rgba(220, 180, 60, 0.12);
  border: 1px solid rgba(220, 180, 60, 0.3);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  color: #d4a930;
  font-size: 0.9rem;
  white-space: pre-line;
}

/* Loading text */
.loading-text {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

/* --- btn-secondary (general) --- */
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* --- Family Picker --- */

#family-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

#family-picker.hidden { display: none; }

.family-picker-container {
  text-align: center;
  max-width: 600px;
}

.family-picker-container h1 {
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.family-picker-subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.family-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.family-picker-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
  color: var(--text);
  font-family: inherit;
}

.family-picker-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.family-picker-card h3 {
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
}

.family-picker-role {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: capitalize;
}

/* ============================================================
   Vendor Cost Dashboard
   ============================================================ */

.costs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.costs-header h1 {
  font-size: 1.4rem;
  color: var(--text);
}
.costs-month-select {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
}
.costs-body {
  padding: 1rem 1.5rem;
  max-width: 900px;
  margin: 0 auto;
}
.costs-loading, .costs-error {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}
.costs-error { color: var(--danger); }

.costs-period {
  margin-bottom: 1rem;
}
.costs-period-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Cards */
.costs-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.costs-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}
.costs-card-unavailable {
  opacity: 0.7;
}
.costs-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.costs-card-header h2 {
  font-size: 1.1rem;
  color: var(--text);
  margin: 0;
}
.costs-scope-badge {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.costs-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}
.costs-badge-mtd {
  background: #4a3a20;
  color: #e8c870;
  border: 1px solid #6a5a30;
}
.costs-badge-final {
  background: #203a20;
  color: #70c870;
  border: 1px solid #306a30;
}
.costs-badge-live {
  background: #1a2a3a;
  color: #70a8d0;
  border: 1px solid #305a7a;
}
.costs-as-of {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.costs-card-total {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.75rem;
}
.costs-card-message {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 0.5rem 0;
}
.costs-card-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* Section titles */
.costs-section-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0.75rem 0 0.4rem;
}

/* Service list & expandable */
.costs-service-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.costs-service-row {
  border-bottom: 1px solid var(--border);
}
.costs-service-row:last-child { border-bottom: none; }

.costs-expandable {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.5rem 0.25rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  text-align: left;
}
.costs-expandable:hover {
  background: var(--bg-surface);
  border-radius: 4px;
}
.costs-expandable::before {
  content: '\25B6';
  font-size: 0.6rem;
  margin-right: 0.5rem;
  transition: transform 0.15s;
  color: var(--text-muted);
}
.costs-expandable.expanded::before {
  transform: rotate(90deg);
}
.costs-svc-name { flex: 1; }
.costs-svc-total {
  color: var(--accent);
  font-family: monospace;
  font-size: 0.85rem;
}

/* Daily breakdown */
.costs-daily-detail {
  padding: 0.25rem 0 0.5rem 1.25rem;
}
.costs-daily-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0;
  font-size: 0.8rem;
}
.costs-daily-date {
  color: var(--text-muted);
  width: 3.5rem;
  flex-shrink: 0;
}
.costs-daily-bar {
  height: 6px;
  background: var(--accent);
  border-radius: 3px;
  min-width: 2px;
  transition: width 0.2s;
}
.costs-daily-amt {
  color: var(--text);
  font-family: monospace;
  font-size: 0.75rem;
  width: 5rem;
  text-align: right;
  flex-shrink: 0;
}

/* Tables */
.costs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0.25rem 0;
}
.costs-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: normal;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.costs-table td {
  padding: 0.4rem 0.5rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.costs-table td.num, .costs-table th.num {
  text-align: right;
  font-family: monospace;
}

/* Neon gauge */
.costs-gauge {
  position: relative;
  height: 20px;
  background: var(--bg-surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin: 0.5rem 0;
}
.costs-gauge-fill {
  height: 100%;
  background: var(--success);
  border-radius: 10px;
  transition: width 0.3s;
}
.costs-gauge-caution .costs-gauge-fill,
.costs-gauge-caution { background: #c4a55a; }
.costs-gauge-warn .costs-gauge-fill,
.costs-gauge-warn { background: var(--danger); }
.costs-gauge-fill.costs-gauge-caution { background: #c4a55a; }
.costs-gauge-fill.costs-gauge-warn { background: var(--danger); }
.costs-gauge-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  color: var(--text);
  text-shadow: 0 0 3px var(--bg);
}
.costs-neon-limits ul {
  list-style: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.costs-neon-limits li {
  padding: 0.2rem 0;
}
.costs-neon-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
}
.costs-neon-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.costs-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.5rem 0;
  font-style: italic;
}

/* Cloudflare card */
.costs-cf-domains {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.costs-cf-domain {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.costs-cf-domain-name {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}
.costs-cf-expiry {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}
.costs-cf-expiry.costs-expiry-warn {
  color: var(--danger);
  font-weight: 600;
}
.costs-cf-sublabel {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}
.costs-gauge-sm {
  height: 16px;
  margin-top: 0.3rem;
}
.costs-gauge-sm .costs-gauge-label {
  font-size: 0.7rem;
}

/* --- Family AI budget dashboard --- */

.fb-bar-wrap {
  position: relative;
  width: 120px;
  height: 14px;
  background: var(--bg-surface);
  border-radius: 7px;
  overflow: hidden;
}
.fb-bar {
  height: 100%;
  background: var(--success, #4a9);
  transition: width 0.2s;
}
.fb-bar-fb-warn  { background: #c4a55a; }
.fb-bar-fb-over  { background: var(--danger, #c44); }
.fb-bar-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  color: var(--text);
  text-shadow: 0 0 3px var(--bg);
}

.fb-row.fb-over td { background: rgba(196, 68, 68, 0.08); }
.fb-row.fb-warn td { background: rgba(196, 165, 90, 0.06); }

.fb-tier-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bg);
  background: var(--text-muted);
}
.fb-tier-paid { background: var(--accent); }
.fb-tier-free { background: var(--text-muted); }

.fb-override-badge,
.fb-grant-badge {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.05rem 0.35rem;
  font-size: 0.7rem;
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.fb-grant-badge { color: var(--success, #4a9); border-color: var(--success, #4a9); }

.fb-over { color: var(--danger, #c44); }
.fb-warn { color: #c4a55a; }

.fb-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem 1rem;
  margin: 0.5rem 0 1rem;
}
.fb-summary-grid > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg-surface);
  border-radius: 4px;
}
.fb-summary-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fb-summary-val {
  font-family: monospace;
  font-size: 0.95rem;
  color: var(--text);
}

.fb-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem 0.75rem;
  margin: 0.5rem 0 1rem;
}
.fb-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.fb-controls input[type="number"],
.fb-controls input[type="text"],
.fb-controls select {
  padding: 0.3rem 0.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.9rem;
}

.fb-tier-input {
  padding: 0.2rem 0.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: monospace;
}

.fb-help {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.4rem 0 0;
}

.fb-lag-count {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  background: rgba(196, 165, 90, 0.2);
  color: #c4a55a;
  font-family: monospace;
  font-size: 0.85rem;
  margin-right: 0.4rem;
}
.fb-lag-zero {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.85rem;
}
.fb-lag-loading {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.85rem;
  opacity: 0.6;
}
.fb-catchup-btn {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
}

.fb-save-status {
  flex-basis: 100%;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.1rem;
}
.fb-save-status-pending { color: var(--text-muted); }
.fb-save-status-ok { color: #6abf69; }
.fb-save-status-error { color: #d97b6b; }

.fb-tier-toggle-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.fb-tier-toggle-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.fb-tier-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-surface);
}
.fb-tier-pill {
  padding: 0.3rem 0.7rem;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.fb-tier-pill:last-child { border-right: 0; }
.fb-tier-pill:hover { background: rgba(196, 149, 106, 0.1); }
.fb-tier-pill-active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
.fb-tier-pill-active:hover { background: var(--accent); }

/* --- Clarifications review card --- */

.clarifications-review-card {
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  margin: 0.75rem 0;
}

.clarifications-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.clarifications-header h4 {
  margin: 0;
  font-size: 1rem;
}

.clarifications-tag {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.clarifications-chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  margin-left: auto;
}

.clarifications-body {
  padding: 0 1rem 1rem;
}

.clarifications-disabled {
  padding: 0.5rem 1rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.clarifications-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.clarifications-count {
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.clarifications-count--open {
  border-color: #5b9bd5;
  color: #5b9bd5;
}

.clarifications-count--answered {
  border-color: #70ad47;
  color: #70ad47;
}

.clarifications-count--stale {
  border-color: #e5a84b;
  color: #e5a84b;
}

.clarifications-count--applied {
  border-color: var(--text-muted);
  color: var(--text-muted);
}

.clarifications-count--dismissed {
  border-color: var(--text-muted);
  color: var(--text-muted);
  opacity: 0.7;
}

.clarifications-actions {
  margin-bottom: 1rem;
}

.clarifications-generate {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.clarifications-questions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.clarification-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}

.clarification-item--stale {
  border-color: #e5a84b;
}

.clarification-item--applied {
  opacity: 0.7;
}

.clarification-item--dismissed {
  opacity: 0.6;
}

.clarification-item-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.clarification-category {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  text-transform: uppercase;
}

.clarification-stale-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: #e5a84b;
  color: #1a1612;
  font-weight: 600;
}

.clarification-status-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
}

.clarification-status--applied {
  background: #70ad47;
  color: #1a1612;
}

.clarification-status--dismissed {
  background: var(--text-muted);
  color: var(--bg);
}

.clarification-question {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.clarification-evidence {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.clarification-evidence-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
}

.clarification-page-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.clarification-page-link:hover {
  text-decoration: underline;
}

.clarification-entity {
  color: var(--text-muted);
  font-style: italic;
}

.clarification-actions {
  margin-top: 0.5rem;
}

.clarification-answer-input {
  width: 100%;
  padding: 0.4rem;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  resize: vertical;
  margin-bottom: 0.4rem;
}

.clarification-action-btns {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.clarification-answer-display {
  font-size: 0.9rem;
  color: var(--text);
  background: var(--card-bg);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  margin-top: 0.4rem;
}

.clarification-resolution-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.clarifications-apply {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}

.clarifications-apply h5 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.clarifications-apply-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.clarifications-apply-item {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.clarifications-apply-item input[type="checkbox"] {
  margin-top: 0.2rem;
}

.clarifications-past {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}

.clarifications-past summary {
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 0.5rem;
}

/* Book context form in pipeline page */
.book-context-form .form-group {
  margin-bottom: 1rem;
}

.book-context-form label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.book-context-form input[type="text"],
.book-context-form textarea {
  width: 100%;
  padding: 0.5rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
}

.book-context-form textarea {
  resize: vertical;
  font-family: inherit;
}

/* ------------------------------------------------------------------ */
/* Chat Panel                                                         */
/* ------------------------------------------------------------------ */
#chat-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 450px;
  max-width: 90vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 1100;
  box-shadow: -10px 0 40px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
}

.chat-header h3 {
  color: var(--accent);
  font-weight: normal;
  margin: 0;
}

.chat-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.chat-header-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  position: relative;
}
.chat-header-actions button:hover { color: var(--text); }

.chat-btn-status {
  position: absolute;
  top: 0.18rem;
  right: 0.18rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg-card);
}
.chat-btn-status.working {
  width: 0.7rem;
  height: 0.7rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  background: transparent;
  animation: chat-spin 0.8s linear infinite;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-msg {
  max-width: 85%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--bg);
  border-bottom-right-radius: 4px;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg-surface);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-msg-content p { margin: 0.4em 0; }
.chat-msg-content p:first-child { margin-top: 0; }
.chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-content ul { margin: 0.4em 0; padding-left: 1.2em; }

.chat-msg-content a.person-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.chat-msg-content a.page-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.chat-system-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.5rem;
}

.chat-tool-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.25rem 0;
}

.chat-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-spin 0.8s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

.chat-working-status {
  flex-shrink: 0;
  padding: 0.5rem 1rem 0.6rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.chat-working-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}
.chat-working-text {
  font-style: italic;
}
.chat-working-hint {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 1rem 0.5rem;
}

.chat-suggestion-chip {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s;
}
.chat-suggestion-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--bg-card);
}

.chat-input-area textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
}
.chat-input-area textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-input-area button {
  flex-shrink: 0;
  padding: 0.5rem 1rem;
}

.chat-proposal {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}
.chat-proposal-desc {
  margin-bottom: 0.4rem;
}
.chat-proposal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.chat-proposal-btn {
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
}
.chat-proposal-approved {
  border-color: #4a8;
}
.chat-proposal-rejected {
  border-color: var(--border);
  opacity: 0.7;
}
.chat-proposal-status {
  font-size: 0.85rem;
  font-weight: 500;
}
.chat-proposal-status.approved {
  color: #4a8;
}
.chat-proposal-status.rejected {
  color: var(--text-muted);
}
.chat-proposal-status.error {
  color: #c44;
}
.chat-proposal-pending {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.chat-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  width: 100%;
}
.chat-history-item:hover { border-color: var(--accent); }
.chat-history-item.unread {
  border-color: var(--accent);
}

.chat-history-title {
  font-size: 0.95rem;
}
.chat-history-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}
.chat-history-unread {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
}
.chat-history-working {
  width: 0.8rem;
  height: 0.8rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-spin 0.8s linear infinite;
}
.chat-history-date {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Mobile: full-width chat panel */
.portrait-mode #chat-panel {
  width: 100vw;
  max-width: 100vw;
}

/* ---- Voice Memories / Audio ---- */

.audio-memories-section {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.audio-memories-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.audio-memories-toggle {
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.audio-memories-chevron {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.audio-memories-section.collapsed .audio-recordings-list,
.audio-memories-section.collapsed .audio-recording-ui {
  display: none;
}

.audio-memories-controls {
  display: flex;
  gap: 0.5rem;
}

.audio-record-btn,
.audio-upload-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.audio-record-btn:hover,
.audio-upload-btn:hover {
  background: var(--surface-hover, #3a3229);
}

.mic-icon {
  font-size: 1rem;
}

/* Recording UI */
.audio-recording-ui {
  margin-bottom: 0.75rem;
}

.audio-upload-status {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.audio-upload-status.success {
  color: var(--accent);
}

.audio-upload-status.error {
  color: #dc3232;
}

.audio-recording-active {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(220, 50, 50, 0.1);
  border: 1px solid rgba(220, 50, 50, 0.3);
  border-radius: 6px;
}

.recording-dot {
  width: 12px;
  height: 12px;
  background: #dc3232;
  border-radius: 50%;
  animation: recording-pulse 1.2s ease-in-out infinite;
}

@keyframes recording-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.recording-timer {
  font-family: monospace;
  font-size: 1.1rem;
  color: var(--text);
  min-width: 3.5rem;
}

.audio-level-meter {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
  max-width: 160px;
}

.audio-level-bar {
  height: 100%;
  width: 0%;
  background: #4a4;
  border-radius: 4px;
  transition: width 0.08s ease-out;
}

.audio-stop-btn {
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  border: 1px solid #dc3232;
  background: #dc3232;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

.audio-cancel-btn {
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

/* Recordings list */
.audio-recordings-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.audio-recording-item {
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.audio-recording-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}

.audio-recording-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent);
}

.audio-recording-duration {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: monospace;
}

.audio-transcription-spinner {
  font-size: 0.85rem;
  animation: recording-pulse 1.5s ease-in-out infinite;
}

.audio-transcription-failed {
  font-size: 0.85rem;
  color: #e5a032;
  cursor: help;
}

/* Audio player */
.audio-player-wrap {
  margin: 0.25rem 0;
}

.audio-player {
  width: 100%;
  height: 36px;
  border-radius: 4px;
}

/* Style the native audio controls for dark theme where supported */
.audio-player::-webkit-media-controls-panel {
  background: var(--surface);
}

.simple-mode #caption-panel,
.simple-mode #page-items-summary-panel,
.simple-mode #comments-panel {
  display: block;
  background: transparent;
  margin: 1rem auto 0;
  max-width: 1120px;
}

.simple-mode .caption-col,
.simple-mode .page-items-summary-col,
.simple-mode .comments-col {
  background:
    linear-gradient(180deg, rgba(53, 47, 40, 0.95), rgba(42, 36, 32, 0.95));
  border: 1px solid rgba(196, 149, 106, 0.18);
  border-radius: 24px;
  padding: 1.35rem 1.5rem 1.5rem;
  box-shadow: 0 18px 40px rgba(0,0,0,0.18);
}

.simple-mode .page-items-summary-controls,
.simple-mode .page-items-summary-columns {
  background: transparent;
}

.simple-mode .caption-title {
  font-size: 1.45rem;
  font-style: normal;
  line-height: 1.25;
  margin-bottom: 1rem;
}

.simple-mode .caption-body {
  max-height: none;
  font-size: 1.125rem;
  line-height: 1.7;
}

.simple-mode .caption-actions {
  margin-top: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.simple-mode .caption-actions button {
  min-height: 46px;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
}

.simple-mode .comments-col h4 {
  color: var(--accent);
  font-size: 1.1rem;
  letter-spacing: 0;
  text-transform: none;
  margin-bottom: 1rem;
}

.simple-mode .page-items-summary-block h4,
.simple-mode .page-items-summary-empty strong {
  color: var(--accent);
  font-size: 1.02rem;
  letter-spacing: 0;
  text-transform: none;
}

.simple-mode .page-items-summary-entry {
  padding: 0.7rem 0.85rem;
  margin-left: -0.85rem;
  border-radius: 14px;
}

.simple-mode .page-items-summary-entry:hover,
.simple-mode .page-items-summary-entry:focus {
  background: rgba(26, 22, 18, 0.28);
}

.simple-mode .comments-list {
  max-height: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.simple-mode .comment-item {
  padding: 0.9rem 1rem;
  border: 1px solid rgba(196, 149, 106, 0.12);
  border-radius: 16px;
  background: rgba(26, 22, 18, 0.26);
}

.simple-mode .comment-meta {
  margin-bottom: 0.4rem;
}

.simple-mode .comment-text {
  font-size: 1.0625rem;
  line-height: 1.65;
}

.simple-mode .comment-form {
  gap: 0.75rem;
}

.simple-mode .comment-form input,
.simple-mode .comment-form textarea {
  padding: 0.8rem 0.95rem;
  border-radius: 16px;
  font-size: 1rem;
}

.simple-mode .comment-form button {
  align-self: stretch;
  min-height: 50px;
  border-radius: 999px;
  font-size: 1rem;
}

.simple-mode .audio-memories-section {
  margin-top: 1.2rem;
  padding-top: 1rem;
}

.simple-mode .audio-memories-header {
  flex-direction: column;
  align-items: stretch;
}

.simple-mode .audio-memories-controls {
  width: 100%;
}

.simple-mode .audio-record-btn,
.simple-mode .audio-upload-btn {
  flex: 1;
  min-height: 48px;
  border-radius: 999px;
  font-size: 0.92rem;
}

.simple-mode .audio-recording-item {
  padding: 0.8rem 0.95rem;
  border-radius: 16px;
}

.simple-mode .audio-transcript-block {
  border-radius: 12px;
}

@media (max-width: 760px) {
  .activity-header {
    flex-direction: column;
    align-items: stretch;
  }

  .analytics-header {
    flex-direction: column;
    align-items: stretch;
  }

  .activity-body {
    padding: 1rem 0.75rem;
  }

  .analytics-body {
    padding: 1rem 0.75rem;
  }

  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .simple-mode .simple-mode-toolbar {
    margin: 0.75rem 0.75rem 0;
    padding: 1rem;
    border-radius: 20px;
  }

  .simple-mode-heading {
    font-size: 1.4rem;
  }

  .simple-mode-subtitle {
    font-size: 0.92rem;
  }

  .simple-mode #caption-panel,
  .simple-mode #page-items-summary-panel,
  .simple-mode #comments-panel {
    margin-left: 0.75rem;
    margin-right: 0.75rem;
  }

  .simple-mode .caption-col,
  .simple-mode .page-items-summary-col,
  .simple-mode .comments-col {
    padding: 1rem;
    border-radius: 20px;
  }

  .simple-page-browser-shell {
    padding: 0.75rem;
  }

  .simple-page-browser-header {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
    border-radius: 20px;
  }

  .simple-page-browser-actions {
    justify-content: stretch;
  }

  .simple-transcript-shell {
    padding: 0.75rem;
  }

  .simple-transcript-header {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
    border-radius: 20px;
  }

  .simple-transcript-title {
    font-size: 1.4rem;
  }

  .simple-transcript-content {
    padding: 1rem;
    border-radius: 20px;
    font-size: 1.0625rem;
    line-height: 1.7;
  }

  .simple-page-browser-actions > .btn-subtle,
  .simple-page-browser-jump-form,
  .simple-page-browser-jump-controls input,
  .simple-page-browser-jump-controls .btn-accent {
    width: 100%;
  }

  .simple-page-browser-jump-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .simple-page-browser-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .simple-page-browser-group-section {
    gap: 0.75rem;
    padding: 0.85rem;
    border-radius: 22px;
  }

  .simple-page-browser-group-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .simple-page-browser-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    padding-bottom: 0.65rem;
  }
}

/* Transcript */
.audio-transcript-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.15rem 0;
  text-decoration: underline;
}

.audio-transcript-block {
  margin-top: 0.35rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Admin controls */
.audio-admin-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
}

.audio-admin-btn {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.audio-admin-btn:hover {
  background: var(--surface-hover, #3a3229);
}

.audio-delete-btn {
  color: #dc3232;
  border-color: rgba(220, 50, 50, 0.3);
}

.audio-delete-btn:hover {
  background: rgba(220, 50, 50, 0.15);
}

.audio-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 0.25rem 0;
}

/* Audio Trim Modal */
.audio-trim-modal-content {
  max-width: 500px;
}

.audio-trim-body {
  padding: 1rem 0 0;
}

.audio-trim-player audio {
  width: 100%;
  height: 40px;
}

.audio-trim-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
}

.audio-trim-range {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin: 1rem 0;
}

.audio-trim-field {
  flex: 1;
}

.audio-trim-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.audio-trim-field input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: monospace;
}

.audio-trim-field input:focus {
  border-color: var(--accent);
  outline: none;
}

#audio-trim-new-duration {
  font-family: monospace;
  font-size: 0.9rem;
  padding: 0.4rem 0;
  display: inline-block;
}

.audio-trim-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.audio-trim-status {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  text-align: center;
}

.audio-trim-status.error {
  color: #dc3232;
}

.audio-trim-status.success {
  color: #4caf50;
}

.audio-trim-btn {
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: none;
  color: var(--accent);
  cursor: pointer;
}

.audio-trim-btn:hover {
  background: rgba(196, 149, 106, 0.12);
}

.audio-versions-btn {
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}

.audio-versions-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Book-Level Audio Panel */
.book-audio-panel {
  max-width: 900px;
  margin: 0.5rem auto;
  padding: 0 1rem;
}

.book-audio-panel .audio-memories-section {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
}

/* ===== Header hamburger menu ===== */

.header-menu {
  position: relative;
  display: flex;
  align-items: center;
}

.header-actions-primary {
  margin-left: auto;
}

.hamburger-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  /* Match .btn-subtle padding so the hamburger lines up with adjacent
     header buttons (Home/Chat) in Expert Mode. Simple Mode overrides
     below bump this to a 44px tap target. */
  padding: 0.4rem 0.8rem;
  /* The icon span is 2px tall in normal flow (the ::before/::after bars are
     absolutely positioned, so they don't contribute to height). Without an
     explicit min-height the button collapses to ~17px tall, visibly shorter
     than the adjacent .btn-subtle buttons (~30px). Match their natural height. */
  min-height: 1.85rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.hamburger-btn:hover,
.hamburger-btn[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.hamburger-icon,
.hamburger-icon::before,
.hamburger-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  position: relative;
}

.hamburger-icon::before,
.hamburger-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.hamburger-icon::before { top: -6px; }
.hamburger-icon::after  { top:  6px; }

.header-menu-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 200px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.header-menu-panel[hidden] {
  display: none;
}

.header-menu-panel .btn-subtle {
  border-color: transparent;
  background: transparent;
  text-align: left;
  padding: 0.5rem 0.75rem;
  width: 100%;
  justify-content: flex-start;
}

.header-menu-panel .btn-subtle:hover {
  background: var(--bg-surface);
  border-color: transparent;
}

/* Portrait/mobile tweaks: keep the hamburger compact */
.portrait-mode .hamburger-btn {
  padding: 0.35rem 0.5rem;
}
