/* ==========================================
   0. DESIGN TOKENS
   Shared palette, spacing, radius, and elevation.
   New code should use these variables instead of
   hard-coded hex values.
   ========================================== */
:root {
  --bg-app: #faf5ec;
  --bg-map: #f4ecdd;
  --surface: #ffffff;
  --surface-muted: #f7f0e2;
  --surface-dark: #2c1f0e;
  --border: #e0d5c5;
  --border-strong: #c8bfad;
  --border-muted: #e8dece;
  --text: #2c1f0e;
  --text-muted: #756652;
  --text-subtle: #9b8c7a;
  --text-faint: #b8aa98;
  --primary: #8b3a2f;
  --primary-dark: #6e2e25;
  --primary-soft: rgba(139, 58, 47, 0.09);
  --success: #6f8753;
  --success-dark: #53663e;
  --danger: #a64a3c;
  --danger-soft: rgba(166, 74, 60, 0.14);
  --warning: #9d7138;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 2px 10px rgba(44, 31, 14, 0.07);
  --shadow-md: 0 8px 24px rgba(44, 31, 14, 0.11);
  --shadow-lg: 0 18px 46px rgba(44, 31, 14, 0.16);
  --focus-ring: 0 0 0 3px rgba(139, 58, 47, 0.25);
  --font-display: "Playfair Display", "Times New Roman", serif;
  --font-sans: "Source Sans 3", "Segoe UI", sans-serif;
}

/* ==========================================
   1. BASE RESET & VIEWPORT FIXES
   ========================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100dvh;
  width: 100vw;
  overflow-x: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text);
}

/* Visibility Utilities */
.hidden-element {
  display: none !important;
}

.hidden-view {
  display: none !important;
}

.active-view {
  display: block !important;
}

.view-section {
  padding-top: 80px; /* Room for top nav on desktop */
  padding-bottom: 40px;
  box-sizing: border-box;
}

/* ==========================================
   2. BRANDING & NAVIGATION
   ========================================== */
.brand-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.brand-lockup-logo {
  height: 42px;
  width: auto;
}

.brand-lockup-word {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 2.25rem;
  color: var(--text);
  line-height: 1;
}

.brand-lockup-hi {
  font-weight: 800;
}

.brand-lockup-library {
  font-weight: 300;
  color: var(--text-subtle);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-brand-logo {
  height: 32px;
  width: auto;
}

.nav-brand-word {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 1.25rem;
  color: var(--text);
  line-height: 1;
}

.nav-user {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.nav-user-email {
  font-size: 0.9rem;
  color: #71717a;
  font-weight: 500;
}

.visually-hidden-input {
  display: none;
}

.dropzone-icon {
  margin-bottom: 12px;
}

.canvas-hidden {
  display: none;
}

.brand-logo {
  height: 32px;
  width: auto;
  display: block;
  object-fit: contain;
}

.app-nav {
  position: fixed;
  top: 0; /* Pin to top for desktop */
  left: 0;
  right: 0;
  z-index: 1000;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.nav-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: #64748b;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  min-height: 44px; /* Ensure safe touch target size */
  transition: color 0.2s, background-color 0.2s;
}

.nav-btn.active {
  color: #3b82f6;
  font-weight: 600;
  background-color: #eff6ff;
}

.nav-btn:focus-visible,
.logout-btn:focus-visible,
.auth-btn:focus-visible,
.map-zoom-btn:focus-visible,
.map-hint-close:focus-visible,
.clickable-dropzone:focus-visible,
.icon-btn:focus-visible,
.modal-btn:focus-visible,
.spine-card-input:focus-visible,
.search-input:focus-visible,
.auth-input:focus-visible,
.shelf-card:focus-visible,
.book-popover button:focus-visible,
.map-zoom-btn:focus-visible,
#infiniteMap:focus-visible,
.shelf-svg-overlay polygon:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.auth-input:focus-visible,
.search-input:focus-visible {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

/* Align center navigation links horizontally */
.nav-links {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Constrain all navigation SVG icons */
.nav-icon {
  width: 24px;
  height: 24px;
  display: block;
}

/* Fix Logout Button Flex Alignment */
.logout-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  padding: 6px 12px;
  background-color: white;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  color: #3f3f46;
}

.plan-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: 1px solid #bfdbfe;
  font-size: 0.78rem;
  font-weight: 700;
}

.usage-meter {
  font-size: 0.78rem;
  color: var(--text-subtle);
}

/* ==========================================
   3. AUTHENTICATION VIEW
   ========================================== */
.auth-background {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center;
  padding: 20px;
}

.auth-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  padding: 32px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
  text-align: center;
}

.auth-form {
  margin-top:1em;
}

.auth-input {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 0px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
}

.auth-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.auth-btn {
  width: 100%;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
  margin-top: 5px;
}

.primary-btn {
  background-color: #3b82f6;
  color: white;
}

.secondary-btn {
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  color: #475569;
}

.auth-footer {
  margin-top: 1em;
}

.text-link {
  background-color: unset;
  border: none;
  text-decoration: underline;
  color: #3b82f6;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: unset;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--text-faint);
  font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.google-auth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: #334155;
  margin: 0;
}

.google-auth-btn:hover {
  background: var(--bg-app);
  border-color: var(--text-faint);
}

.google-auth-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.google-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.auth-error {
  display: block;
  margin-top: 10px;
  color: #dc2626;
  font-size: 0.85rem;
}

/* Scan progress: Upload -> Review spines -> Save shelf */
.scan-progress {
  max-width: 1400px;
  margin: 12px auto 0;
  padding: 0 20px;
}

.scan-progress-heading {
  margin: 0 0 10px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.scan-steps {
  list-style: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0;
  margin: 0;
  padding: 14px 16px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.scan-step {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-faint);
}

.scan-step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 12px;
  left: calc(50% + 16px);
  width: calc(100% - 32px);
  height: 2px;
  border-radius: 999px;
  background: var(--border);
}

.scan-step-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: #e2e8f0;
  color: var(--text-subtle);
  z-index: 1;
}

.scan-step-label {
  line-height: 1.2;
}

.scan-step.is-active {
  color: var(--primary-dark);
}

.scan-step.is-active .scan-step-dot {
  background: var(--primary);
  color: #ffffff;
}

.scan-step.is-done {
  color: var(--success-dark);
}

.scan-step.is-done .scan-step-dot {
  background: var(--success);
  color: #ffffff;
}

.scan-step.is-done:not(:last-child)::after {
  background: var(--success);
}

/* ==========================================
   4. SCAN WORKSPACE & CANVAS TOOLBAR
   ========================================== */
.scan-container {
  display: flex;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: flex-start;
}

.canvas-container {
  position: relative;
  flex: 1;
  min-width: 0;
  width: 100%;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 450px;
  max-height: calc(100dvh - 260px);
}

#shelfCanvas {
  display: block;
  flex: 0 1 auto;
  align-self: center;
  justify-self: center;
  margin: auto;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100dvh - 300px);
  min-height: 0;
  object-fit: contain;
  object-position: center center;
}

#shelfCanvas.canvas-hidden {
  display: none;
}

.save-shelf-btn {
  display: block;
  width: 100%;
}

/* Crop Button Overlay */
.crop-canvas-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 20;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, transform 0.1s;
}

.crop-canvas-btn:hover {
  background: #f8fafc;
}

.crop-canvas-btn:active {
  transform: scale(0.95);
}

.crop-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.dropzone-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-sizing: border-box;
  color: #94a3b8;
  text-align: center;
  width: auto;
  max-width: none;
  margin: 0;
}

.dropzone-empty-state h3,
.dropzone-empty-state p {
  max-width: 22rem;
}

.canvas-container.drag-over {
  outline: 3px dashed #3b82f6;
  outline-offset: -6px;
  background: #16213a;
}

.clickable-dropzone {
  cursor: pointer;
  padding: 32px 20px;
  border-radius: 12px;
}

.clickable-dropzone:hover .dropzone-cta-btn {
  filter: brightness(0.95);
}

.dropzone-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.dropzone-cta-btn {
  width: auto;
  display: inline-flex;
  padding: 10px 20px;
}

.dropzone-hint {
  font-size: 0.8rem;
  color: #94a3b8;
}

/* Sidebar & Detected Spines */
#pendingContainer {
  width: 380px;
  background: #ffffff;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 230px);
  min-height: 240px;
}

.spines-scroll {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding-right: 2px;
}

.spines-sticky-save {
  position: sticky;
  bottom: -16px;
  margin: 12px -16px -16px;
  padding: 12px 16px 16px;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid #e2e8f0;
  border-radius: 0 0 12px 12px;
}

.spines-sticky-save .save-shelf-btn {
  margin: 0;
}

.spines-save-count {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  color: #64748b;
  text-align: center;
}

.maximize-spines-btn {
  display: none;
}

/* ==========================================
   5. MAP ENGINE & OVERLAYS
   ========================================== */
#infiniteMap {
  width: 100vw;
  height: calc(100dvh - 80px);
  position: relative;
  overflow: hidden;
  background-color: #eef2f7;
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.055) 1px, transparent 1px);
  background-size: 32px 32px;
  cursor: grab;
}

.map-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 60;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  pointer-events: none;
}

.map-controls > * {
  pointer-events: auto;
}

.map-zoom-group {
  display: inline-flex;
  background: #ffffff;
  border: 1px solid #d4d4d8;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.map-zoom-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  background: #ffffff;
  color: #0f172a;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.map-zoom-btn + .map-zoom-btn {
  border-left: 1px solid #e2e8f0;
}

.map-zoom-btn:hover {
  background: #f8fafc;
}

.map-fit-btn {
  font-size: 0.82rem;
  font-weight: 700;
  color: #1d4ed8;
}

.map-hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 560px);
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  font-size: 0.82rem;
  padding: 10px 12px 10px 16px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

.map-hint-close {
  border: none;
  border-radius: 999px;
  background: #3b82f6;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.map-empty-state {
  position: absolute;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
}

.map-empty-card {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
  padding: 28px;
  max-width: 380px;
  text-align: center;
}

.map-empty-card h3 {
  margin: 0 0 8px;
  color: #0f172a;
  font-size: 1.15rem;
}

.map-empty-card p {
  margin: 0 0 18px;
  color: #475569;
  font-size: 0.9rem;
  line-height: 1.5;
}

.map-empty-card .auth-btn {
  width: auto;
  display: inline-flex;
  justify-content: center;
  padding: 10px 20px;
}

#mapViewport {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* Sidebar toggle chevron */
.toggle-icon {
  width: 24px;
  height: 24px;
  display: block;
  transition: transform 0.3s ease;
}

.book-popover {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translate(-50%, -100%);
  background: #1e293b;
  color: white;
  padding: 8px;
  border-radius: 8px;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 100;
  pointer-events: auto;
  min-width: 180px;
  max-width: 260px;
}

#libraryView {
  position: relative;
}

/* Floating Desktop Sidebar */
#libraryView .sidebar {
  position: absolute;
  top: 100px; 
  right: 20px;
  width: 320px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  z-index: 50;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 140px);
}

.sidebar-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e2e8f0;
  cursor: default;
  gap: 12px;
}

.sidebar-title {
  color: #3f3f46;
  margin-top: 0;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-muted);
  font-size: 1.2rem;
}

.sidebar-heading {
  margin: 0;
}

.sidebar-search {
  margin-top: 12px;
}

.sheet-handle {
  display: none;
}

.sidebar-content {
  padding: 25px 16px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}

.sidebar-actions-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0px;
}

.sidebar-actions-row .auth-btn,
.sidebar-actions-row .auth-input {
  margin: 0;
}

/* Sidebar Search & List Styles */
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
}

.search-input:focus {
  border-color: #3b82f6;
}

.library-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}

/* Sidebar toggle chevron */
.toggle-icon {
  width: 24px;
  height: 24px;
  display: block;
  transition: transform 0.3s ease;
}

/* ==========================================
   6. MODALS & LOADING OVERLAYS
   ========================================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 16px;
}

.loading-message {
  font-weight: 600;
  font-size: 1.1rem;
  margin: 0;
  color: #f8fafc;
}

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

/* Shelf Manager Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.modal-content {
  background: #ffffff;
  padding: 24px;
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

/* Modal List Item Styling */
.manager-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 400px;
  overflow-y: auto;
}

.manager-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.manager-list-item:last-child {
  border-bottom: none;
}

.manager-shelf-name {
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manager-shelf-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  margin: 0;
  color: #3f3f46;
  font-size: 1.2rem;
}

.modal-message {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

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

.modal-btn {
  width: auto;
  padding: 8px 16px;
}

.modal-btn-danger {
  background-color: var(--danger);
}

.modal-input-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.modal-input {
  margin-bottom: 8px;
}

.modal-dialog {
  gap: 4px;
}

.upgrade-modal-dialog {
  max-width: min(640px, calc(100vw - 32px));
}

.upgrade-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 4px 0 10px;
}

.upgrade-plan-col {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 12px;
}

.upgrade-plan-col-premium {
  border-color: rgba(139, 58, 47, 0.35);
  background: rgba(139, 58, 47, 0.06);
}

.upgrade-plan-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  color: var(--text);
  font-size: 1rem;
}

.upgrade-current-plan {
  display: inline-block;
  margin-left: 6px;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 0;
}

.upgrade-plan-list {
  margin: 0;
  padding-left: 16px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #71717a;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 44px;
  min-height: 44px;
}

/* Crop modal */
.crop-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.crop-modal-card {
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius-lg);
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow-lg);
  width: min(90vw, 720px);
}

.crop-modal-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.crop-modal-title {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 700;
}

.crop-modal-hint {
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.crop-canvas-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  width: 100%;
  margin: 0 auto;
  max-height: 65vh;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-dark);
  overflow: hidden;
}

.crop-canvas {
  cursor: crosshair;
  display: block;
  flex: 0 1 auto;
  align-self: center;
  margin: auto;
  max-width: 100%;
  max-height: 65vh;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center center;
}

.crop-modal-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: flex-end;
}

/* ==========================================
   6b. TOASTS (Step 7: branded non-blocking feedback)
   ========================================== */
.toast-container {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface-dark);
  color: #f8fafc;
  border-radius: 10px;
  padding: 12px 12px 12px 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.35);
  border-left: 4px solid var(--primary);
  font-size: 0.88rem;
  line-height: 1.4;
}

.toast-success {
  border-left-color: var(--success);
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-info {
  border-left-color: var(--primary);
}

.toast-message {
  flex: 1;
}

.toast-close {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  min-width: 32px;
  min-height: 32px;
}

.offline-banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2100;
  background: #1e293b;
  color: #f8fafc;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 8px 12px;
  width: min(92vw, 560px);
  text-align: center;
  font-size: 0.84rem;
}

.pwa-install-btn {
  min-height: 1rem;
  min-width: 96px;
  border: 1px solid var(--border-strong);
}

.pwa-ios-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 2600;
  background: var(--surface-dark);
  color: #f8fafc;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.pwa-ios-hint-close {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  cursor: pointer;
}

/* ==========================================
   6c. REUSABLE COMPONENTS (Step 9: replace inline styles)
   ========================================== */
.page-header {
  padding: 16px 20px 0;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.upload-label-btn {
  width: auto;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
}

.canvas-controls-bar {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  font-size: 0.8rem;
}

.zoom-range {
  width: 80px;
  cursor: pointer;
}

.zoom-reset-btn {
  background: #334155;
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  cursor: pointer;
  min-height: 32px;
}

.spines-step-hint {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--text-subtle);
}

.spines-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

.spines-title {
  color: #3f3f46;
}

.spines-batch-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.spine-icon-btn {
  width: 100%;
  height: 32px;
  min-width: 32px;
  padding: 0;
  font-size: 0.75rem;
  border-radius: 6px;
  line-height: 1;
}

.spine-card.is-highlighted {
  border-color: var(--success);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.spine-card.is-confirmed {
  border-color: var(--success);
  background-color: rgba(16, 185, 129, 0.08);
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.25);
}

.empty-state {
  text-align: center;
  color: var(--text-subtle);
  padding-top: 40px;
}

.scan-error {
  color: var(--danger);
}

.scan-loading-text {
  text-align: center;
}

.spine-card {
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.spine-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.spine-number {
  background: #8b5cf6;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: bold;
  flex-shrink: 0;
}

.spine-card-input {
  padding: 8px;
  flex: 1;
}

.spine-actions {
  display: flex;
  gap: 8px;
  padding-left: 32px;
}

.spine-btn {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.spine-btn-primary {
  flex: 1;
}

.spine-btn-skip {
  width: auto;
  background-color: #e5e7eb;
  border-color: #d1d5db;
}

.spine-batch-btn {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.search-results-col {
  padding-left: 32px;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-status {
  font-size: 0.85rem;
  color: #71717a;
}

.search-status-error {
  font-size: 0.85rem;
  color: var(--danger);
}

.book-result-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  border: 2px solid var(--primary);
  border-radius: var(--radius-md);
  background-color: var(--primary-soft);
}

.book-result-thumb {
  width: 50px;
  height: 70px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.book-result-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: center;
  gap: 4px;
}

.book-result-title {
  font-size: 0.95rem;
  color: #1e3a8a;
}

.book-result-author {
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.book-lookup-dialog {
  max-width: 480px;
  width: min(480px, calc(100vw - 32px));
}

.book-lookup-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-direction: column;
}

.book-lookup-row .modal-input {
  flex: 1;
  margin-bottom: 0;
}

.book-lookup-results {
  padding-left: 0;
  margin-top: 12px;
  max-height: min(50vh, 360px);
  overflow-y: auto;
}

.book-confirm-btn {
  background-color: var(--success);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  align-self: flex-start;
  min-height: 36px;
}

.spine-confirmed-row {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(16, 185, 129, 0.45);
  border-radius: var(--radius-md);
  background-color: rgba(16, 185, 129, 0.12);
}

.spine-confirmed-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #065f46;
  background: rgba(16, 185, 129, 0.2);
}

.library-row {
  padding: 8px;
  border-bottom: 1px solid var(--border-muted);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.library-row-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-row-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.library-lookup-btn,
.library-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 6px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  color: var(--text-subtle);
}

.library-lookup-btn:hover,
.library-delete-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.library-delete-btn {
  margin-left: 0;
}

.shelf-card {
  position: absolute;
  width: 300px;
  min-width: 160px;
  background: var(--surface);
  padding: 10px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-muted);
  cursor: grab;
  user-select: none;
  transition: box-shadow 0.2s;
}

.shelf-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  pointer-events: none;
}

.shelf-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #3f3f46;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.shelf-card-actions {
  pointer-events: auto;
  display: flex;
  gap: 6px;
}

.shelf-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.shelf-icon-btn-rescan {
  color: var(--primary);
}

.shelf-icon-btn-rename {
  color: #71717a;
}

.shelf-icon-btn-delete {
  color: var(--danger);
}

.shelf-img-wrap {
  position: relative;
  width: 100%;
  min-height: 160px;
  background: #f4f4f5;
  border-radius: var(--radius-sm);
}

.shelf-img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  pointer-events: none;
  border: 1px solid #f4f4f5;
}

.shelf-img:not([src]) {
  visibility: hidden;
  min-height: 160px;
}

.shelf-resize-handle {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  border-radius: 2px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, #94a3b8 50%, #94a3b8 60%, transparent 60%),
    linear-gradient(135deg, transparent 70%, #94a3b8 70%, #94a3b8 80%, transparent 80%);
  background-color: rgba(255, 255, 255, 0.7);
  z-index: 5;
  pointer-events: auto;
}

.shelf-resize-handle:hover,
.shelf-resize-handle:focus-visible {
  background-color: #ffffff;
}

.shelf-svg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.book-popover-main {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.book-popover-cover {
  width: 48px;
  height: 68px;
  flex-shrink: 0;
  border-radius: 4px;
  object-fit: cover;
  background: #334155;
}

.book-popover-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

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

.book-popover-title {
  font-weight: 600;
  max-width: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-popover-search {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.75rem;
  min-height: 32px;
}

.book-popover-delete {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.75rem;
  min-height: 32px;
}

.book-popover-close {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 0.9rem;
  min-width: 32px;
  min-height: 32px;
}

.manage-shelves-btn {
  background: var(--surface);
  border: 1px solid #d4d4d8;
  box-shadow: var(--shadow-sm);
}

.modal-edit-btn {
  background: var(--surface-muted);
  border: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-right: 4px;
  min-height: 36px;
}

.modal-del-btn {
  background: var(--danger-soft);
  color: var(--danger);
  border: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 36px;
}

.shelf-card.is-dragging {
  cursor: grabbing;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

#infiniteMap:focus-visible {
  outline-offset: -2px;
}

#infiniteMap.kb-focus {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ==========================================
   7. MOBILE RESPONSIVE RULES
   ========================================== */
@media (max-width: 768px) {
  /* Shift safe area padding from top to bottom for mobile */
  .view-section {
    padding-top: 20px;
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  }

  /* Move Navigation to Bottom */
  .app-nav {
    top: auto; 
    bottom: 0; 
    border-bottom: none;
    border-top: 1px solid #e2e8f0;
    justify-content: space-around;
    padding: 8px 10px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }

  .nav-btn {
    font-size: 0.85rem;
    gap: 6px;
    padding: 8px 16px;
    min-height: 58px;
    min-width: 76px;
    flex: 1;
  }

  .nav-btn .nav-text {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.1;
  }

  .nav-icon {
    width: 26px;
    height: 26px;
  }

  .nav-links {
    gap: 6px;
    flex: 1;
    justify-content: space-around;
  }

  .nav-user {
    flex: 1;
    justify-content: center;
    gap: 6px;
  }

  .plan-badge,
  .usage-meter,
  #upgradeBtn,
  #manageBillingBtn {
    display: none !important;
  }

  .logout-btn {
    font-size: 0.85rem;
    min-height: 58px;
    min-width: 76px;
  }
  
  .brand-logo {
    height: 28px;
  }

  .scan-container,
  .scan-workspace {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .canvas-container {
    width: 100%;
    min-height: 320px;
    max-height: 42vh;
    margin: 0 auto;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  #shelfCanvas {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    align-self: center;
    justify-self: center;
    object-fit: contain;
    object-position: center center;
  }

  #pendingContainer {
    width: 100%;
    max-height: 45vh;
    overflow-y: auto;
    padding-bottom: 20px;
  }

  .spines-sticky-save {
    bottom: -20px;
    margin: 12px -16px -20px;
  }

  .scan-progress {
    padding: 0 12px;
  }

  .scan-steps {
    padding: 12px 10px 10px;
  }

  .scan-step {
    font-size: 0.75rem;
  }

  .map-hint {
    top: 70px;
    bottom: auto;
    border-radius: 16px;
    white-space: normal;
    text-align: left;
    align-items: flex-start;
  }

  /* Full-screen Mobile Overlay when Maximized */
  #pendingContainer.maximized {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh !important;
    z-index: 500;
    background: #ffffff;
    padding: 16px;
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    box-sizing: border-box;
  }

  .maximize-spines-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  .spines-batch-actions {
    align-items: stretch;
  }

  .spines-batch-actions .spine-batch-btn,
  .spines-batch-actions .maximize-spines-btn {
    min-height: 40px;
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }

  .spines-batch-actions .maximize-spines-btn.spine-icon-btn {
    height: auto;
    width: auto;
    min-width: 7em;
  }

  .nav-brand, 
  #userEmailDisplay {
    display: none !important;
  }

  .offline-banner {
    top: 12px;
  }

  /* Mobile Library Sidebar Drawer */
#libraryView .sidebar {
    position: fixed; /* Locks the drawer to the screen, not the page */
    top: auto;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)); 
    right: 12px;
    left: 12px;
    width: auto;
    border-radius: 16px;
    z-index: 900;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.1);
  }
  
  .sidebar-header {
    cursor: pointer;
    position: relative;
    padding-top: 18px;
  }
  
  /* Collapsible State Handled by app.js */
  .sidebar-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    overflow: hidden;
    border: none;
  }
  
  .sidebar-header.collapsed .toggle-icon {
    transform: rotate(180deg);
  }
}

@media (display-mode: standalone) and (max-width: 768px) {
  .app-nav {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .view-section {
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  }
}

/* ==========================================
   8. FOLIO REBRAND OVERRIDES
   ========================================== */
body {
  background: radial-gradient(120% 100% at 100% 0%, #f6efdf 0%, var(--bg-app) 45%, #f8f1e4 100%);
}

.brand-lockup-logo {
  display: none;
}

.nav-brand-logo {
  display: block;
  height: 28px;
  width: auto;
}

.brand-lockup-word,
.nav-brand-word {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

.brand-lockup-hi {
  color: var(--primary);
  font-style: italic;
  font-weight: 500;
}

.brand-lockup-library {
  color: var(--text);
  font-style: normal;
  font-weight: 700;
}

.auth-background {
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0) 40%),
    radial-gradient(120% 100% at 100% 0%, #f4ecda 0%, #f9f3e8 55%, #faf5ec 100%);
}

.auth-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}

.auth-header p {
  color: var(--text-subtle);
}

.auth-input,
.search-input,
.modal-input {
  border-color: var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.auth-input::placeholder,
.search-input::placeholder {
  color: var(--text-faint);
}

.auth-btn {
  font-family: var(--font-sans);
  font-weight: 600;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn {
  border-color: var(--border-strong);
  color: var(--text-muted);
  background: #fff;
}

.app-nav {
  position: sticky;
  top: 0;
  left: auto;
  right: auto;
  z-index: 1000;
  max-width: 1200px;
  margin: 0 auto;
  margin-top: 8px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(250, 245, 236, 0.92);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  min-width: 120px;
}

.nav-brand-word {
  font-size: 1.7rem;
  line-height: 1;
}

.nav-links {
  gap: 6px;
}

.nav-btn {
  min-height: 0;
  padding: 8px 14px 10px;
  border-radius: 6px;
  font-family: var(--font-sans);
  color: var(--text-subtle);
  position: relative;
}

.nav-btn.active {
  color: var(--text);
  background: var(--surface-muted);
}

.nav-btn.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 4px;
  height: 2px;
  background: var(--primary);
  border-radius: 999px;
}

.nav-btn .nav-text {
  font-size: 0.86rem;
  font-weight: 500;
}

.nav-icon {
  display: none;
}

.nav-user {
  position: relative;
  gap: 10px;
  flex-wrap: nowrap;
}

.usage-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 11px 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.usage-ring {
  position: relative;
  width: 24px;
  height: 24px;
}

.usage-ring svg {
  width: 24px;
  height: 24px;
  transform: rotate(-90deg);
}

.usage-ring-track,
.usage-ring-progress {
  fill: none;
  stroke-width: 2.5;
}

.usage-ring-track {
  stroke: #dfd3bf;
}

.usage-ring-progress {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 62.8;
  stroke-dashoffset: 62.8;
  transition: stroke-dashoffset 0.2s ease;
}

.usage-ring-value {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.56rem;
  font-weight: 700;
  color: var(--text);
}

.usage-meter {
  font-size: 0.78rem;
  color: var(--text-subtle);
  white-space: nowrap;
}

.account-avatar-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #e8dcc4;
  color: var(--primary);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  font-style: italic;
  cursor: pointer;
}

.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.account-menu-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 6px;
  min-height: 36px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  text-align: left;
  padding: 8px 10px;
}

.account-menu-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.account-menu-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-subtle);
  padding: 4px 2px 6px;
}

.account-menu-link {
  width: fit-content;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: underline;
  padding: 0 2px 4px;
  cursor: pointer;
}

.account-menu-link.hidden-element {
  display: none !important;
}

.nav-user-email {
  margin: 0;
  color: var(--text-subtle);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.plan-badge {
  align-self: flex-start;
  border-color: rgba(139, 58, 47, 0.28);
  color: var(--primary);
  background: rgba(139, 58, 47, 0.1);
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px 20px 60px;
}

#uploadView {
  padding-top: 0;
}

.scan-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.scan-folio-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scan-folio-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.scan-folio-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.scan-folio-eyebrow {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
  font-weight: 600;
}

.scan-folio-step-title {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 1.06rem;
  color: var(--text);
}

.scan-folio-step-name {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.scan-steps {
  display: block;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

.scan-step {
  align-items: flex-start;
  text-align: left;
  flex-direction: row;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.scan-step:last-child {
  border-bottom: none;
}

.scan-step:not(:last-child)::after {
  display: none;
}

.scan-step-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.scan-step-sub {
  color: var(--text-faint);
  font-size: 0.75rem;
}

.scan-step-dot {
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
  background: var(--surface-muted);
  border: 1px solid var(--border-strong);
  color: var(--text-subtle);
}

.scan-step.is-active .scan-step-dot,
.scan-step.is-done .scan-step-dot {
  border-color: var(--primary);
  background: #fff;
  color: var(--primary);
}

.scan-step.is-done .scan-step-dot {
  background: var(--primary);
  color: #fff;
}

.scan-step.is-active {
  background: rgba(139, 58, 47, 0.05);
  color: var(--text);
}

.scan-step.is-done {
  color: var(--text-subtle);
}

.scan-past-shelves {
  list-style: none;
  margin: 0;
  padding: 0;
}

.scan-past-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.scan-past-item img {
  width: 44px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
}

.scan-past-item span {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.scan-past-item strong {
  font-size: 0.77rem;
  color: var(--text);
}

.scan-past-item small {
  color: var(--text-subtle);
  font-size: 0.7rem;
}

.scan-past-empty {
  justify-content: center;
}

.scan-past-empty small {
  font-size: 0.76rem;
}

.scan-wizard-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow-md);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.scan-wizard-head {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.scan-stage-tag {
  margin: 0;
  width: fit-content;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-subtle);
  padding: 2px 8px;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

.page-title {
  margin-top: 10px;
  font-family: var(--font-display);
  color: var(--text);
  font-size: clamp(1.8rem, 3vw, 2.2rem);
  line-height: 1.15;
}

.scan-stage-description {
  margin: 8px 0 0;
  color: var(--text-subtle);
  max-width: 520px;
  line-height: 1.6;
}

.scan-wizard-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 18px;
}

.scan-main-panel {
  min-width: 0;
}

.scan-side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-label-btn {
  width: fit-content;
  margin: 0 0 10px;
}

.canvas-container {
  background: var(--surface-muted);
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  min-height: 27vh;
  max-height: none;
}

#shelfCanvas {
  max-height: 25vh;
}

.canvas-container.drag-over {
  outline: none;
  border-color: var(--primary);
  background: rgba(139, 58, 47, 0.06);
}

.dropzone-empty-state {
  color: var(--text-faint);
}

.dropzone-empty-state h3 {
  font-family: var(--font-sans);
  color: var(--text);
}

.dropzone-empty-state p {
  color: var(--text-subtle);
}

.dropzone-hint {
  color: var(--text-faint);
}

.canvas-controls-bar {
  background: rgba(44, 31, 14, 0.75);
}

.scan-footer-row {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 12px;
}

.scan-analyse-btn {
  width: auto;
  min-width: 170px;
  margin: 0;
}

.scan-analyse-btn:disabled {
  background: #dfd2bb;
  color: #ab9c86;
}

.scan-tips-panel {
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

.scan-tip-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  margin-top: 8px;
}

.scan-tip-card h4 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text);
}

.scan-tip-card p {
  margin: 4px 0 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-subtle);
}

#pendingContainer {
  width: 100%;
  margin-top: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 35vh;
}

#uploadView[data-scan-stage="upload"] #pendingContainer {
  display: none;
}

#uploadView[data-scan-stage="review"] .upload-label-btn,
#uploadView[data-scan-stage="review"] .scan-tips-panel {
  display: none;
}

.sidebar-title,
.spines-title,
.modal-title {
  font-family: var(--font-display);
  color: var(--text);
}

.spines-step-hint,
.spines-save-count,
.search-status,
.scan-loading-text,
.empty-state {
  color: var(--text-subtle);
}

.spine-number {
  background: var(--primary);
}

.spine-card {
  border-color: var(--border);
  background: #fff;
}

.spine-card.is-highlighted {
  border-color: var(--primary);
  background: rgba(139, 58, 47, 0.08);
  box-shadow: 0 0 0 2px rgba(139, 58, 47, 0.15);
}

.spine-card.is-confirmed,
.spine-confirmed-row {
  border-color: rgba(111, 135, 83, 0.5);
  background-color: rgba(111, 135, 83, 0.14);
}

.spine-confirmed-badge {
  color: #3f5a24;
  background: rgba(111, 135, 83, 0.2);
}

.book-result-card {
  border-color: rgba(139, 58, 47, 0.3);
  background: rgba(139, 58, 47, 0.08);
}

.book-result-title {
  color: var(--text);
}

#infiniteMap {
  background-color: var(--bg-map);
  background-image:
    linear-gradient(rgba(80, 58, 36, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(80, 58, 36, 0.06) 1px, transparent 1px);
}

.map-zoom-group,
.manage-shelves-btn {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.94);
}

.map-zoom-btn {
  color: var(--text);
  background: #fff;
}

.map-fit-btn {
  color: var(--primary);
}

.map-hint {
  background: rgba(44, 31, 14, 0.9);
}

.map-hint-close {
  background: var(--primary);
}

.map-empty-card,
#libraryView .sidebar,
.modal-content {
  border-color: var(--border);
  box-shadow: var(--shadow-md);
}

.book-popover {
  background: rgba(44, 31, 14, 0.92);
}

.toast {
  background: rgba(44, 31, 14, 0.95);
}

.toast-close {
  color: #e2d9ca;
}

.loading-overlay,
.modal-overlay,
.crop-modal-overlay {
  background: rgba(44, 31, 14, 0.72);
}

.loading-spinner {
  border-top-color: var(--primary);
}

@media (max-width: 960px) {
  .scan-shell {
    grid-template-columns: 1fr;
  }

  .scan-folio-sidebar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .scan-wizard-body {
    grid-template-columns: 1fr;
  }

  .scan-side-panel {
    border-top: 1px solid var(--border);
    padding-top: 12px;
  }

  .scan-tips-panel {
    border-left: none;
    padding-left: 0;
  }
}

@media (max-width: 768px) {
  .scan-folio-sidebar {
    display: none;
  }

  .upgrade-summary {
    grid-template-columns: 1fr;
  }

  .main-content {
    padding: 12px 12px calc(92px + env(safe-area-inset-bottom, 0px));
  }

  .app-nav {
    position: fixed;
    bottom: 0;
    top: auto;
    left: 10px;
    right: 10px;
    margin: 0;
    border-radius: 12px 12px 0 0;
    padding: 8px 10px;
  }

  .nav-brand {
    display: none;
  }

  .usage-pill {
    display: none;
  }

  .nav-links {
    flex: 1;
    justify-content: space-between;
  }

  .nav-btn {
    flex: 1;
    padding: 10px 4px;
  }

  .account-menu {
    right: 0;
    bottom: calc(100% + 8px);
    top: auto;
  }

  .scan-wizard-card {
    padding: 16px;
  }
}