@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Space+Mono:wght@400;700&display=swap');

/* ==========================================================================
   Paperplane PDF  -  Enterprise Next-Gen Design System
   ========================================================================== */

:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Space Mono', monospace;

  /* Color Palette */
  --bg-app: #f4f6f3;
  --bg-panel: #ffffff;
  --bg-panel-alt: #fafbfa;
  --border-light: #e4eae4;
  --border-subtle: #d3ded4;
  --text-main: #142023;
  --text-muted: #5e6f72;
  --text-dim: #8fa0a3;

  /* Brand Accents */
  --accent: #ff4b26;
  --accent-hover: #e03816;
  --accent-glow: rgba(255, 75, 38, 0.25);
  --accent-subtle: #fff1ed;

  /* Sidebar Dark Theme */
  --sidebar-bg: #121a1c;
  --sidebar-panel: #1b2629;
  --sidebar-hover: #233134;
  --sidebar-border: #26363a;
  --sidebar-text: #eef3f1;
  --sidebar-muted: #8ca3a0;

  /* Studio / PDF Viewport */
  --studio-bg: #1c2628;
  --studio-panel: #233134;
  --studio-border: #2f4044;
  --studio-page-shadow: 0 16px 45px rgba(0, 0, 0, 0.35);

  /* Status Colors */
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --error: #ef4444;
  --error-bg: #fef2f2;

  /* Elevation */
  --shadow-sm: 0 2px 8px rgba(20, 32, 35, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 32, 35, 0.08);
  --shadow-lg: 0 20px 48px rgba(20, 32, 35, 0.12);
  --shadow-modal: 0 25px 60px -15px rgba(0, 0, 0, 0.4);

  /* Transitions */
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --sidebar-width: 270px;
  --sidebar-collapsed-width: 76px;
}

/* Theme Customizations (Dark Mode, Light Mode, Sharp Contrast) */
:root[data-paperplane-theme="dark"] body.auth-pending, body.dark-mode, body.high-contrast {
  --bg-app: #0d1416;
  --bg-panel: #141e21;
  --bg-panel-alt: #1a2528;
  --border-light: #28393d;
  --border-subtle: #33484c;
  --text-main: #f0f5f4;
  --text-muted: #a3b8b6;
  --text-dim: #708684;
  --accent-subtle: #2b1d19;
  --success-bg: rgba(16, 185, 129, 0.15);
  --warning-bg: rgba(245, 158, 11, 0.15);
  --error-bg: rgba(239, 68, 68, 0.15);
}

body.light-mode:not(.auth-pending), :root:not([data-paperplane-theme="dark"]) body.light-mode {
  --bg-app: #f4f6f3;
  --bg-panel: #ffffff;
  --bg-panel-alt: #f8faf9;
  --border-light: #e2eae4;
  --border-subtle: #cbd7cf;
  --text-main: #142023;
  --text-muted: #5e6f72;
  --text-dim: #8fa0a3;
  --accent-subtle: #fff1ed;
}

body.sharp-contrast {
  --border-light: #475569 !important;
  --border-subtle: #64748b !important;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
}

/* ==========================================================================
   App Shell Layout: Fixed Left Sidebar + Main Dynamic Workspace
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  transition: grid-template-columns 0.3s var(--ease-spring);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) 1fr;
}

/* --------------------------------------------------------------------------
   Sidebar (Fixed & Sticky)
   -------------------------------------------------------------------------- */

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  height: 100vh;
  height: 100dvh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: hidden;
  user-select: none;
}

.sidebar-header {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: #fff;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.03em;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, #ff7a59 100%);
  display: grid;
  place-items: center;
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 4px 14px var(--accent-glow);
  flex-shrink: 0;
}

.brand-dot {
  color: var(--accent);
}

.collapse-btn {
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.collapse-btn:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-search-box {
  padding: 14px 16px 8px;
}

.sidebar-search-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--sidebar-panel);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-muted);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-search-btn:hover {
  background: var(--sidebar-hover);
  border-color: #3b5054;
  color: #fff;
}

.sidebar-search-btn kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
}

.sidebar-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 14px;
}

.sidebar-scroll-area::-webkit-scrollbar {
  width: 4px;
}
.sidebar-scroll-area::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.nav-group-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-muted);
  padding: 14px 10px 6px;
}

.nav-category-tab {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #c9d6d3;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s var(--ease-spring);
  position: relative;
}

.nav-category-tab:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-category-tab.active {
  background: var(--sidebar-panel);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-cat-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  color: #ff856b;
}

.nav-cat-badge {
  margin-left: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.07);
  padding: 2px 7px;
  border-radius: 12px;
  color: var(--sidebar-muted);
}

/* Tool Sub-List in Sidebar */
.sidebar-tool-list {
  margin-top: 4px;
  padding-left: 28px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-tool-item {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #a4b7b4;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-tool-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-tool-item.active {
  color: var(--accent);
  font-weight: 700;
  background: rgba(255, 75, 38, 0.08);
}

/* --------------------------------------------------------------------------
   STICKY BOTTOM-LEFT PROFILE COMPONENT (Permanently Pinned)
   -------------------------------------------------------------------------- */

.sidebar-sticky-footer {
  margin-top: auto;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  padding: 14px;
  background: rgba(10, 15, 17, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

/* Quota Tracker inside Sticky Footer */
.quota-container {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quota-label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #9cb1ae;
}

.quota-label-row > span:first-child {
  white-space: nowrap;
  flex-shrink: 0;
}

#quota-text,
#settings-quota-text {
  min-width: 0;
  flex: 1 1 auto;
  text-align: right;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.quota-progress-track {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
}

.quota-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #10b981, #3b82f6);
  border-radius: 10px;
  transition: width 0.3s ease, background 0.3s ease;
}

.quota-progress-fill.warn {
  background: linear-gradient(90deg, #f59e0b, #ef4444);
}

.quota-progress-fill.full {
  background: #ef4444;
}

.quota-progress-fill.pro {
  background: linear-gradient(90deg, #f59e0b, #10b981);
}

/* Sidebar Upgrade Banner Button */
.sidebar-upgrade-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 75, 38, 0.45);
  background: linear-gradient(135deg, rgba(255, 75, 38, 0.16) 0%, rgba(255, 122, 89, 0.25) 100%);
  color: #ff856b;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-upgrade-btn:hover {
  background: linear-gradient(135deg, rgba(255, 75, 38, 0.3) 0%, rgba(255, 122, 89, 0.4) 100%);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-1px);
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 9px;
  background: var(--sidebar-panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: all 0.18s ease;
}

.profile-card:hover {
  background: var(--sidebar-hover);
  border-color: #3b5054;
}

.profile-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #0284c7;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
}

.profile-avatar.status-online::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid var(--sidebar-panel);
}

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

.profile-name {
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.profile-badge {
  font-size: 10.5px;
  color: var(--sidebar-muted);
  display: block;
}

/* Privacy Mode Toggle inside Sticky Footer */
.footer-privacy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 7px;
}

.footer-privacy-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: #b7c7c4;
}

.footer-privacy-label span {
  font-size: 13px;
}

.privacy-mode-support {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 3px 8px 0;
  color: #91a6a5;
  font-size: 10.5px;
  line-height: 1.35;
}

.toggle-switch-sm {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.toggle-switch-sm input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider-sm {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #3b5054;
  transition: 0.2s;
  border-radius: 18px;
}

.toggle-slider-sm:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.toggle-switch-sm input:disabled + .toggle-slider-sm {
  cursor: not-allowed;
  opacity: 0.55;
}

input:checked + .toggle-slider-sm {
  background-color: var(--accent);
}

input:checked + .toggle-slider-sm:before {
  transform: translateX(14px);
}

.profile-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.profile-card-row .profile-card {
  flex: 1;
  min-width: 0;
}

.sidebar-settings-gear-btn {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--sidebar-panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #b7c7c4;
  font-size: 17px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.sidebar-settings-gear-btn:hover {
  background: var(--sidebar-hover);
  color: #fff;
  border-color: #4b6267;
  transform: rotate(45deg);
}

/* Collapsed Sidebar Styles */
.app-shell.sidebar-collapsed .brand span:not(.brand-mark),
.app-shell.sidebar-collapsed .nav-group-title,
.app-shell.sidebar-collapsed .nav-category-tab span:not(.nav-cat-icon),
.app-shell.sidebar-collapsed .sidebar-tool-list,
.app-shell.sidebar-collapsed .sidebar-search-btn kbd,
.app-shell.sidebar-collapsed .sidebar-search-btn span,
.app-shell.sidebar-collapsed .profile-info,
.app-shell.sidebar-collapsed .quota-container,
.app-shell.sidebar-collapsed .sidebar-upgrade-btn,
.app-shell.sidebar-collapsed .footer-privacy-label {
  display: none !important;
}

.app-shell.sidebar-collapsed .privacy-mode-support {
  display: none !important;
}

.app-shell.sidebar-collapsed .sidebar-header {
  padding: 12px 6px;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.app-shell.sidebar-collapsed .brand {
  margin: 0;
  justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-search-btn {
  justify-content: center;
  padding: 9px;
}

.app-shell.sidebar-collapsed .nav-category-tab {
  justify-content: center;
  padding: 12px;
}

.app-shell.sidebar-collapsed .footer-privacy-row {
  justify-content: center;
  padding: 6px 4px;
}

.app-shell.sidebar-collapsed .toggle-switch-sm {
  margin: 0 auto;
}

.app-shell.sidebar-collapsed .profile-card {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 4px;
}

/* ==========================================================================
   Main Dynamic Workspace & App Shell Body
   ========================================================================== */

.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

.main-area.studio-active {
  overflow: hidden !important;
}

/* --------------------------------------------------------------------------
   Top Action Bar
   -------------------------------------------------------------------------- */

.topbar {
  height: 64px;
  padding: 0 28px;
  background: rgba(18, 26, 28, 0.94);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 260;
}

body.dark-mode .topbar,
body:not(.light-mode) .topbar {
  background: rgba(18, 26, 28, 0.94);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

body.light-mode .topbar {
  background: rgba(255, 255, 255, 0.96);
  border-bottom-color: #dfe7e1;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  min-width: 0;
  white-space: nowrap;
}

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-main);
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--border-subtle);
}

.topbar-upgrade-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 75, 38, 0.4);
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: all 0.18s ease;
}

.topbar-upgrade-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--accent-glow);
  background: linear-gradient(135deg, #ff5c38 0%, #ff8a6b 100%);
}

.breadcrumb-trail {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #9cb1b0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb-trail span,
.breadcrumb-trail b {
  flex: 0 0 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.light-mode .breadcrumb-trail {
  color: #4b5e61;
}

.breadcrumb-trail .crumb-sep {
  color: #586f6d;
  font-size: 11px;
}

body.light-mode .breadcrumb-trail .crumb-sep {
  color: #8fa0a3;
}

.breadcrumb-trail b {
  flex: 0 1 auto;
  min-width: 0;
  color: #ffffff;
  font-weight: 700;
}

body.light-mode .breadcrumb-trail b {
  color: #111a1c;
}

/* Workspace View Mode Switcher Pills */
.workspace-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  gap: 3px;
  flex-shrink: 0;
}

body.light-mode .workspace-tabs {
  background: #eef2ec;
  border: 1px solid #d5dfd7;
}

.tab-pill {
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: #a0b5b3;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

body.light-mode .tab-pill {
  color: #4b6063;
}

.tab-pill:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

body.light-mode .tab-pill:hover {
  color: #111a1c;
  background: rgba(0, 0, 0, 0.04);
}

.tab-pill.active {
  background: #243438;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

body.light-mode .tab-pill.active {
  background: #ffffff;
  color: #111a1c;
  border-color: #cbd7cf;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-auth-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-topbar-signin,
.btn-topbar-register,
.topbar-user-pill {
  min-height: 34px;
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.15s ease;
}

.btn-topbar-signin {
  color: var(--text-main);
  background: transparent;
  border: 1px solid var(--border-light);
}

.btn-topbar-register {
  color: #ffffff;
  background: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-topbar-signin:hover,
.btn-topbar-register:hover,
.topbar-user-pill:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.topbar-user-pill {
  color: var(--text-main);
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  max-width: 170px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

#topbar-username {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar-sm {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), #ff7a59);
  font-size: 10px;
  font-weight: 800;
}

.engine-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  font-family: var(--font-mono);
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

body.light-mode .engine-pill {
  background: #ecfdf5;
  color: #065f46;
  border-color: rgba(16, 185, 129, 0.35);
}

.engine-pill.wasm {
  background: rgba(37, 99, 235, 0.15);
  color: #60a5fa;
  border-color: rgba(37, 99, 235, 0.3);
}

body.light-mode .engine-pill.wasm {
  background: #eff6ff;
  color: #1e40af;
  border-color: rgba(37, 99, 235, 0.35);
}

.engine-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.topbar-action-btn {
  background: #1b2629;
  border: 1px solid #2d3e42;
  color: #e4edf0;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

body.light-mode .topbar-action-btn {
  background: #ffffff;
  border: 1px solid #d1ddd5;
  color: #1a282b;
}

.topbar-action-btn:hover {
  border-color: var(--accent);
  color: #ffffff;
  transform: translateY(-1px);
}

body.light-mode .topbar-action-btn:hover {
  border-color: var(--accent);
  color: #111a1c;
}


.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  background: var(--bg-panel);
  color: var(--text-main);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-panel-alt);
  border-color: var(--border-subtle);
}

/* ==========================================================================
   DYNAMIC WORKSPACE VIEWS
   ========================================================================== */

.dynamic-workspace {
  flex: 1;
  padding: 28px 36px 60px;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   VIEW 1: Tool Action Desk
   -------------------------------------------------------------------------- */

.tool-desk-container {
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: fadeIn 0.25s var(--ease-spring);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tool Header Card */
.tool-hero-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 24px 28px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.tool-hero-title-group h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.tool-hero-title-group {
  min-width: 0;
}

.tool-hero-title-group p {
  color: var(--text-muted);
  font-size: 14px;
  max-width: 650px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.tool-category-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 4px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
  display: inline-block;
}

/* Dropzone */
.dropzone {
  background: var(--bg-panel);
  border: 2px dashed var(--border-subtle);
  border-radius: 16px;
  padding: 44px 28px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s var(--ease-spring);
  position: relative;
}

.dropzone:hover, .dropzone.over {
  border-color: var(--accent);
  background: #fffafa;
  transform: scale(1.003);
}

body.high-contrast .dropzone:hover,
body.high-contrast .dropzone.over {
  background: rgba(255, 75, 38, 0.04);
}

.drop-icon-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent);
  font-size: 24px;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  transition: transform 0.2s ease;
}

.dropzone:hover .drop-icon-circle {
  transform: translateY(-3px);
}

.dropzone h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.dropzone p {
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 8px;
}

.dropzone .browse-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  background: transparent;
  border: none;
}

.dropzone-options { display: inline-flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 12px; }
.dropzone-option { display: inline-flex; align-items: baseline; gap: 3px; }
.dropzone-cloud-option { margin: 10px 0 0; font-size: 12.5px; color: var(--text-dim); }

.ai-restored-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: var(--text-main);
  font-size: 12.5px;
}
.ai-restored-banner[hidden] { display: none; }

.dropzone small {
  display: block;
  width: 100%;
  max-width: 58rem;
  margin: 0 auto;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* File Queue Cards */
.file-queue {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.file-row-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.file-row-card:hover {
  border-color: var(--border-subtle);
}

.file-row-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-row-icon {
  font-size: 20px;
}

.file-row-name {
  font-weight: 700;
  font-size: 13.5px;
}

.file-row-size {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: 6px;
}

.file-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.delete-file-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  font-size: 14px;
  transition: all 0.15s ease;
}

.delete-file-btn:hover {
  color: var(--error);
  background: var(--error-bg);
}

/* Options Box */
.options-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 22px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.option-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.option-field input,
.option-field select,
.option-field textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-panel-alt);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.option-field select {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.option-field textarea {
  min-height: 4.5em;
  line-height: 1.45;
  resize: vertical;
  overflow-wrap: anywhere;
}

.option-field select.exam-preset-select {
  min-height: 48px;
  font-size: 16px;
}

.option-field input:focus,
.option-field select:focus,
.option-field textarea:focus {
  border-color: var(--accent);
  background: var(--bg-panel-alt);
}

/* Explicit native control colors prevent Chromium/Windows dark-mode
   inversion from producing white text on white dropdowns. */
select,
.option-field select,
.form-field-edit-row select,
.editor-select {
  background-color: var(--bg-panel-alt);
  color: var(--text-main) !important;
  border: 1px solid var(--border-light);
  color-scheme: light;
}

select option,
.option-field select option,
.form-field-edit-row select option,
.editor-select option,
option {
  background-color: #ffffff !important;
  color: #142023 !important;
}

body.dark-mode select,
body.dark-mode .option-field select,
body.dark-mode .form-field-edit-row select,
body.dark-mode .editor-select {
  color-scheme: dark;
}

body.dark-mode select option,
body.dark-mode .option-field select option,
body.dark-mode .form-field-edit-row select option,
body.dark-mode .editor-select option,
body.dark-mode .modal-card select option,
body.dark-mode .page-modal-card select option {
  background-color: #1f2937 !important;
  color: #f9fafb !important;
}

.option-field input::placeholder,
.option-field textarea::placeholder,
.editor-input::placeholder,
input::placeholder,
textarea::placeholder {
  color: #8fa0a3 !important;
  opacity: 1;
}

.option-field-wide { grid-column: 1 / -1; }

#install-app-btn[hidden],
#scan-camera-control[hidden] { display: none !important; }

.scan-camera-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  width: 100%;
  justify-content: center;
  margin-block: 8px 4px;
}

.scan-camera-control .btn-secondary-action {
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

.scan-camera-control small {
  flex-basis: 100%;
  max-width: 42ch;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 600px) {
  .pwa-install-btn { min-width: 44px; min-height: 44px; padding-inline: 10px; }
  .scan-camera-control .btn-secondary-action { width: 100%; }
}

.mark-contrast-preview {
  --mark-color: #243b53;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 18px;
  padding: 12px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--card-bg);
}

.mark-preview-page {
  position: relative;
  flex: 0 0 112px;
  width: 112px;
  aspect-ratio: 0.707;
  overflow: hidden;
  border: 1px solid #89939d;
  border-radius: 3px;
  background: #f4f5f6;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  color: #28313a;
}

.mark-preview-page::before {
  content: "";
  position: absolute;
  inset: 14% 12%;
  opacity: .5;
  background: repeating-linear-gradient(to bottom, #8c959f 0 1px, transparent 1px 8px);
  mask-image: linear-gradient(to bottom, transparent, #000 12%, #000 88%, transparent);
}

.mark-preview-mark {
  position: absolute;
  z-index: 1;
  max-width: 88%;
  overflow: hidden;
  padding: 1px 3px;
  color: var(--mark-color);
  font-weight: 700;
  font-size: 8px;
  line-height: 1.15;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  -webkit-text-stroke: 0.35px Canvas;
  paint-order: stroke fill;
  text-shadow: 0 1px 2px #fff, 0 -1px 2px #111;
}

.mark-preview-mark.is-watermark {
  top: 48%;
  left: 50%;
  max-width: 130%;
  transform: translate(-50%, -50%) rotate(-35deg);
  opacity: .76;
}

.mark-preview-mark.is-page-number { bottom: 7%; left: 50%; transform: translateX(-50%); }
.mark-preview-mark.is-page-number.header-center { top: 7%; bottom: auto; }
.mark-preview-mark.is-page-number.footer-left,
.mark-preview-mark.is-page-number.header-left { left: 8%; right: auto; transform: none; }
.mark-preview-mark.is-page-number.footer-right,
.mark-preview-mark.is-page-number.header-right { left: auto; right: 8%; transform: none; }
.mark-preview-mark.is-page-number.header-left,
.mark-preview-mark.is-page-number.header-right { top: 7%; bottom: auto; }

.mark-preview-mark.is-signature {
  right: 7%;
  bottom: 12%;
  max-width: 70%;
  padding: 5px 8px 3px;
  border: 1px dashed #858f99;
  border-radius: 3px;
}

.mark-preview-caption {
  flex: 1 1 230px;
  min-width: min(100%, 180px);
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.mark-contrast-preview[data-page-background="dark"] .mark-preview-page {
  background: #20252b;
  color: #d3d9df;
}

.mark-contrast-preview[data-page-background="dark"] .mark-preview-page::before {
  opacity: .34;
  background: repeating-linear-gradient(to bottom, #c4cbd2 0 1px, transparent 1px 8px);
}

.mark-contrast-preview[data-page-background="unknown"] .mark-preview-page {
  background: #f4f5f6;
  color: #28313a;
}

.mark-contrast-preview[data-page-background="unknown"] .mark-preview-mark {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 3px;
  text-shadow: none;
}

.mark-preview-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  z-index: 0;
}

.mark-preview-page.has-pdf-preview::before {
  display: none;
}

@media (max-width: 480px) {
  .mark-contrast-preview { justify-content: flex-start; }
  .mark-preview-page { flex-basis: 88px; width: 88px; }
  .mark-preview-caption { flex-basis: 150px; }
}

.option-engine-badge {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: var(--accent-subtle);
  color: var(--text-main);
}

.option-engine-badge strong,
.option-engine-badge small { display: block; }
.option-engine-badge strong { font-size: 12px; }
.option-engine-badge small { color: var(--text-muted); font-size: 11px; margin-top: 3px; }
.engine-badge-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px var(--success-bg); }

/* Primary Action Bar */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
}

.btn-primary-action {
  background: linear-gradient(135deg, var(--accent) 0%, #ff6842 100%);
  color: #fff;
  border: none;
  padding: 14px 28px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px var(--accent-glow);
  transition: all 0.2s var(--ease-spring);
}

.btn-primary-action:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(255, 75, 38, 0.35);
}

.btn-primary-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.secure-assurance {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* --------------------------------------------------------------------------
   Multi-Stage Animated Progress Loader
   -------------------------------------------------------------------------- */

.progress-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow-md);
  margin-top: 14px;
  scroll-margin-top: calc(var(--topbar-height, 84px) + 12px);
  scroll-margin-bottom: calc(122px + env(safe-area-inset-bottom, 0px));
}

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

.progress-header strong {
  font-size: 15px;
  font-weight: 700;
}

.progress-header span {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  font-weight: 700;
}

.progress-track {
  height: 8px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
  position: relative;
}

.progress-bar-fill {
  display: block;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  accent-color: var(--accent);
  background: rgba(0, 0, 0, 0.06);
}

.progress-bar-fill::-webkit-progress-bar { background: rgba(0, 0, 0, 0.06); border-radius: 8px; }
.progress-bar-fill::-webkit-progress-value { background: linear-gradient(90deg, var(--accent) 0%, #ff8b6e 100%); border-radius: 8px; transition: width 0.3s ease; }
.progress-bar-fill::-moz-progress-bar { background: linear-gradient(90deg, var(--accent) 0%, #ff8b6e 100%); border-radius: 8px; }

.progress-steps {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
}

.progress-step.done {
  color: var(--success);
  font-weight: 600;
}

.progress-step.active {
  color: var(--accent);
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   Result Output Banner
   -------------------------------------------------------------------------- */

.result-card {
  background: var(--success-bg);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: fadeIn 0.3s var(--ease-spring);
}

.result-card.error {
  background: var(--error-bg);
  border-color: rgba(239, 68, 68, 0.25);
}
.result-card.result-neutral {
  border-color: var(--border-light);
  background: var(--bg-panel-alt);
  color: var(--text-muted);
}
.option-required-hint {
  display: block;
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.4;
}

.result-info strong {
  font-size: 17px;
  color: var(--text-main);
  display: block;
  margin-bottom: 4px;
}

.result-info small {
  color: var(--text-muted);
  font-size: 13px;
}

.result-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.result-actions > a,
.result-actions > button {
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-download {
  background: var(--success);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.25);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-download:hover {
  background: #0ea371;
  transform: translateY(-1px);
}

.ai-result-card {
  display: block;
  background: var(--bg-panel);
  border-color: rgba(236, 72, 153, 0.28);
}

.ai-result-card .result-info { margin-bottom: 16px; }
.result-content { width: 100%; margin-bottom: 16px; }
.metadata-json-result {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  background: var(--bg-panel);
}
.metadata-json-result__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.metadata-json-result__header h3 { margin: 0; font-size: 14px; color: var(--text-main); }
.metadata-json-result__status { margin: 9px 0; color: var(--text-muted); font-size: 12px; }
.metadata-json-result__output {
  width: 100%;
  max-height: 280px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-panel-alt);
  color: var(--text-main);
  font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Metadata results need a full-width JSON area instead of competing with the
   download and Studio actions inside the generic flex result row. */
.result-card:has(> .result-content .metadata-json-result) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 14px;
}
.result-card:has(> .result-content .metadata-json-result) > .result-info,
.result-card:has(> .result-content .metadata-json-result) > .result-content,
.result-card:has(> .result-content .metadata-json-result) > .result-actions {
  min-inline-size: 0;
  inline-size: 100%;
}
.result-card:has(> .result-content .metadata-json-result) > .result-content {
  margin-block-end: 0;
}
.result-card:has(> .result-content .metadata-json-result) > .result-actions {
  flex-wrap: wrap;
}
.ai-result-answer,
.ai-result-markdown,
.ai-markdown-output {
  color: var(--text-main);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.ai-result-answer h2,
.ai-result-answer h3,
.ai-result-answer h4,
.ai-result-markdown h2,
.ai-result-markdown h3,
.ai-result-markdown h4,
.ai-markdown-output h2,
.ai-markdown-output h3,
.ai-markdown-output h4 {
  margin: 10px 0 6px;
  color: var(--text-main);
}

.ai-result-answer p,
.ai-result-markdown p,
.ai-markdown-output p { margin: 0 0 8px; }
.ai-result-answer ul,
.ai-result-markdown ul,
.ai-markdown-output ul { margin: 6px 0 10px 20px; }
.ai-result-answer code,
.ai-result-markdown code,
.ai-markdown-output code { color: var(--accent); font-family: var(--font-mono); }
.ai-result-citations,
.ai-result-actions,
.chat-citation-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.ai-result-citations strong { font-size: 12px; color: var(--text-muted); }
.ai-citation-tag,
.chat-citation-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent-subtle);
  border: 1px solid rgba(236, 72, 153, 0.25);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 700;
}
.ai-citation-tag.muted { color: var(--text-muted); }
.ai-result-card .ai-open-studio-result-btn { margin-top: 16px; padding: 10px 16px; font-size: 12px; }
.ai-result-card .btn-download { margin-top: 6px; }
.chat-markdown { margin-top: 6px; }
.ai-markdown-output {
  font-size: 12.5px;
  min-height: 140px;
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 14px;
  background: var(--bg-panel-alt);
}

/* --------------------------------------------------------------------------
   VIEW 2: Next-Level In-App PDF Studio (Viewer & Editor)
   -------------------------------------------------------------------------- */

.pdf-studio {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  background: var(--studio-bg);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--studio-border);
  height: calc(100vh - 100px);
  height: calc(100dvh - 100px);
  min-height: 520px;
  position: relative;
}

/* Studio Left Thumbnail Sidebar */
.studio-thumbnails-bar {
  background: #172023;
  border-right: 1px solid var(--studio-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.studio-thumbnails-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--studio-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.studio-thumbnails-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.thumb-card {
  background: #233134;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
}

.thumb-card:hover {
  border-color: #435b60;
}

.thumb-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.thumb-card img,
.thumb-card canvas {
  width: 100%;
  height: auto;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.thumb-card-footer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
  color: #a4b7b4;
  font-size: 11px;
  font-weight: 600;
}

.thumb-actions {
  display: flex;
  gap: 4px;
}

.thumb-action-btn {
  background: transparent;
  border: none;
  color: #a4b7b4;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 11px;
}

.thumb-action-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* Studio Center Viewport */
.studio-main-viewport {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--studio-bg);
  position: relative;
  overflow: hidden;
}

/* Studio Toolbar - Accessible, Non-clipping & Responsive 2-Tier Modern Ribbon */
.studio-toolbar {
  display: flex;
  flex-direction: column;
  background: #192426;
  border-bottom: 1px solid var(--studio-border);
  padding: 0;
  user-select: none;
  z-index: 100;
  flex-shrink: 0;
}

.studio-primary-ribbon {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 14px;
  background: #192426;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.studio-primary-ribbon::-webkit-scrollbar {
  height: 4px;
}

.studio-primary-ribbon::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.studio-sub-ribbon {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 3px 14px;
  background: #141c1e;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.studio-sub-ribbon::-webkit-scrollbar {
  height: 4px;
}

.studio-sub-ribbon::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.studio-sub-ribbon[hidden] {
  display: none !important;
}

.studio-mode-switcher {
  display: inline-flex;
  align-items: center;
  background: #0d1416;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.studio-mode-btn {
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.studio-mode-btn:hover {
  color: #ffffff;
}

.studio-mode-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.studio-dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.studio-dropdown-trigger {
  gap: 6px;
}

.studio-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1000;
  min-width: 210px;
  background: #192426;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.studio-dropdown-menu[hidden] {
  display: none !important;
}

.studio-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: #e2e8f0;
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}

.studio-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.studio-dropdown-item svg {
  flex-shrink: 0;
  color: var(--accent);
}

.studio-tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.studio-tool-btn {
  background: #243437;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.studio-tool-btn:hover {
  background: #31464a;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
  transform: translateY(-1px);
}

.studio-tool-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.studio-clear-btn:hover {
  background: #7f1d1d !important;
  border-color: #ef4444 !important;
  color: #fee2e2 !important;
}

.studio-save-btn {
  min-height: 36px;
  padding: 6px 14px !important;
  font-size: 12.5px !important;
  font-weight: 700 !important;
  border-radius: 6px !important;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.studio-page-badge {
  color: #ffffff;
  font-size: 11.5px;
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 5px 8px;
  background: #111a1c;
  border: 1px solid var(--studio-border);
  border-radius: 6px;
}
.studio-page-badge { display: inline-flex; align-items: center; gap: 4px; }
.studio-page-badge input { width: 32px; padding: 0; border: 0; outline: 0; background: transparent; color: inherit; text-align: center; font: inherit; }
.studio-page-badge input::-webkit-inner-spin-button, .studio-page-badge input::-webkit-outer-spin-button { margin: 0; }

.studio-divider {
  width: 1px;
  height: 22px;
  background: var(--studio-border);
  margin: 0 4px;
}

.zoom-select {
  background: #172023 !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  color: #ffffff !important;
  padding: 5px 8px !important;
  border-radius: 6px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  font-weight: 600;
  outline: none;
  min-height: 36px;
  min-width: 80px;
  width: 80px;
  text-align: center;
  cursor: pointer;
}

.zoom-select option {
  background: #192426 !important;
  color: #ffffff !important;
}

/* Responsive button text collapsing: on screens <= 1440px or browser zoom */
@media (max-width: 1440px) {
  .studio-tool-btn .tool-btn-text {
    display: none;
  }
  .studio-tool-btn {
    padding: 6px 8px;
    min-width: 36px;
    justify-content: center;
  }
}

@media (max-width: 1366px) {
  .topbar {
    padding: 0 14px;
    gap: 8px;
  }
  .topbar-left {
    flex: 1 1 auto;
    min-width: 0;
    gap: 8px;
    max-width: none;
    overflow: hidden;
  }
  .breadcrumb-trail {
    font-size: 12px;
  }
  .workspace-tabs {
    padding: 3px;
    gap: 2px;
  }
  .tab-pill {
    padding: 5px 9px;
    font-size: 11.5px;
    gap: 4px;
  }
  .topbar-right {
    gap: 6px;
    flex-shrink: 0;
  }
  .topbar-upgrade-pill {
    padding: 5px 9px;
    font-size: 11px;
  }
  .btn-topbar-signin,
  .btn-topbar-register,
  .topbar-user-pill {
    padding: 5px 8px;
    font-size: 11px;
  }
}

/* At desktop-zoom and compact desktop widths, the main workspace becomes too
   narrow for the breadcrumb, view switcher, and account actions on one row. */
@media (max-width: 1280px) and (min-width: 901px) {
  .topbar {
    display: flex !important;
    flex: 0 0 auto;
    height: auto;
    min-height: 64px;
    flex-wrap: wrap;
    justify-content: flex-start;
    padding-block: 8px;
  }

  .topbar-left {
    flex: 1 1 240px;
    max-width: none;
    overflow: visible;
  }

  .topbar-right {
    flex: 0 1 auto;
    min-width: 0;
    margin-inline-start: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .workspace-tabs {
    order: 3;
    flex: 1 0 100%;
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* Dedicated Contextual Page Selection Panel */
.organizer-selection-panel {
  background: #1b2628;
  border-bottom: 1px solid var(--studio-border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px 12px;
  flex-wrap: wrap;
  overflow: visible;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  min-height: 44px;
  position: relative;
  flex-shrink: 0;
}

.organizer-selection-panel::-webkit-scrollbar {
  height: 4px;
}

.organizer-selection-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.selection-panel-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.selection-count-badge {
  font-size: 11.5px;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.selection-quick-tools {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

.batch-subtle-btn {
  background: #253639;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.batch-subtle-btn:hover {
  background: #33484c;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
}

.selection-action-clusters {
  display: flex;
  align-items: center;
  gap: 6px 8px;
  flex-wrap: wrap;
  flex: 1 1 auto;
  min-width: 0;
}

.action-cluster {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  max-width: 100%;
  gap: 4px;
  background: #141d1f;
  border: 1px solid var(--studio-border);
  border-radius: 6px;
  padding: 3px 6px;
}

.cluster-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-right: 4px;
  padding-right: 6px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.cluster-btn {
  background: transparent;
  border: 1px solid transparent;
  color: #e2e8f0;
  padding: 4px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.12s ease;
}

.cluster-btn:hover {
  background: #28393d;
  border-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.cluster-btn-danger:hover {
  background: rgba(239, 68, 68, 0.2) !important;
  border-color: #ef4444 !important;
  color: #fca5a5 !important;
}

/* Studio Canvas Display Area - High DPI & Smooth Independent Bi-Directional Scrolling */
.studio-canvas-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  padding: 24px 16px;
  background: #141b1d;
  position: relative;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.page-render-wrapper {
  margin: 0 auto;
  width: fit-content;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
  background: #ffffff;
  transition: transform 0.15s ease;
  user-select: none;
}

.studio-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #141b1d;
  backdrop-filter: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 250;
  color: #ffffff;
}

.studio-loading-overlay[hidden] {
  display: none !important;
}

.studio-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent, #ff4b26);
  border-radius: 50%;
  animation: studioSpin 0.75s linear infinite;
}

@keyframes studioSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.studio-loading-text {
  font-size: 13.5px;
  font-weight: 600;
  color: #e2e8f0;
  letter-spacing: 0.02em;
}

.pdf-page-canvas {
  display: block;
  border-radius: 4px;
}

.pdf-annotation-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pdf-draw-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* --------------------------------------------------------------------------
   VIEW 3: AI Document Intelligence Studio
   -------------------------------------------------------------------------- */

.ai-studio-wrapper {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: calc(100vh - 130px);
  min-height: calc(100dvh - 130px);
  position: relative;
}

.ai-studio-topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-upload-strip {
  background: var(--bg-panel);
  border: 1.5px dashed var(--border-light);
  border-radius: 8px;
  padding: 14px 18px;
  transition: border-color 0.15s ease;
  cursor: pointer;
}

.ai-upload-strip:hover {
  border-color: var(--accent);
}

.ai-upload-content {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-main);
}

.ai-upload-content svg {
  color: var(--accent);
  flex-shrink: 0;
}

.ai-active-doc-strip {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-doc-info-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-doc-info-group svg {
  color: var(--accent);
  flex-shrink: 0;
}

.ai-doc-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-doc-details strong {
  font-size: 13.5px;
  color: var(--text-main);
}

.ai-doc-meta-text {
  font-size: 11.5px;
  color: var(--text-muted);
}
.ai-doc-source-note { display: block; flex: 1 0 100%; order: 3; max-width: 100%; color: var(--text-muted); font-size: 10px; line-height: 1.35; white-space: normal; overflow-wrap: anywhere; }

.ai-doc-status-badge {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.ai-doc-actions {
  display: flex;
  gap: 8px;
}

.ai-engine-notice-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 4px;
}

.ai-engine-info {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-engine-pill {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
}

.ai-test-conn-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
}

.ai-test-conn-btn:hover {
  color: var(--text-main);
}

.ai-studio-container {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  flex: 1;
  min-height: 520px;
}

@media (max-width: 900px) {
  .ai-studio-container {
    grid-template-columns: 1fr !important;
  }

  #ai-extract-type-select {
    min-height: 44px;
    padding: 8px 10px !important;
    font-size: 14px !important;
  }
}

/* Extraction Modal Styles */
.extraction-modal-card {
  max-width: 820px;
  width: 95vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  border-radius: 8px !important;
  overflow: hidden;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
}

.extraction-modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  background: var(--bg-panel);
}

.extraction-header-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.extraction-badge-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.extraction-type-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.extraction-status-badge {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.extraction-modal-header h3 {
  font-size: 17.5px;
  font-weight: 700;
  margin: 4px 0 0 0;
  color: var(--text-main);
}

.extraction-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

.extraction-close-btn {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.extraction-close-btn:hover {
  color: var(--text-main);
}

.extraction-tabs {
  display: flex;
  padding: 0 22px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-panel-alt);
  gap: 8px;
}

.extraction-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.extraction-tab-btn:hover {
  color: var(--text-main);
}

.extraction-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.extraction-tab-content {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.extraction-warning-box {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 6px;
  padding: 10px 14px;
  display: flex;
  gap: 10px;
  font-size: 12.5px;
  color: #b45309;
}

.extraction-warning-box svg {
  flex-shrink: 0;
  margin-top: 1px;
}

.extraction-fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.extraction-field-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.extraction-field-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.extraction-field-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  word-break: break-word;
}

.extraction-field-value.null-val {
  color: #9ca3af;
  font-weight: normal;
  font-style: italic;
}

.extraction-field-value.highlight-val {
  color: #059669;
  font-size: 14.5px;
}

.extraction-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.extraction-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.extraction-section-header h4 {
  font-size: 13px;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
}

.extraction-count-badge {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  color: var(--text-muted);
}

.extraction-table-wrap {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  overflow-x: auto;
  max-height: 200px;
}

.extraction-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

.extraction-table th {
  background: var(--bg-panel-alt);
  padding: 8px 12px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
}

.extraction-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
}

.extraction-table tr:last-child td {
  border-bottom: none;
}

.extraction-empty-state {
  text-align: center;
  padding: 14px;
  font-size: 12px;
  color: var(--text-muted);
  border: 1px dashed var(--border-light);
  border-radius: 6px;
  background: var(--bg-panel-alt);
}

.extraction-meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.extraction-meta-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.extraction-meta-col label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.extraction-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
}

.extraction-pill {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 3px 8px;
  color: var(--text-main);
}

.extraction-json-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.extraction-json-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.extraction-json-pre {
  background: #0f172a;
  color: #f1f5f9;
  padding: 14px;
  border-radius: 6px;
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  max-height: 360px;
  margin: 0;
  border: 1px solid #1e293b;
}

.extraction-modal-footer {
  padding: 12px 22px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
}

.extraction-footer-left {
  display: flex;
  gap: 8px;
}

.ai-chat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  flex: 1;
  min-height: 500px;
  position: relative;
}

.ai-chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Desktop browser measurements found the compact Clear Chat control below
   the 24px minimum target; give it a stable, comfortable hit area. */
.ai-chat-header #ai-chat-clear-btn {
  min-height: 36px;
}

.ai-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 250px;
  max-height: 520px;
}

.chat-bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
}

.chat-bubble.user {
  margin-left: auto;
  background: var(--accent) !important;
  color: #ffffff !important;
  border-bottom-right-radius: 3px;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.chat-bubble.ai {
  margin-right: auto;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 3px;
}

.ai-question-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.ai-question-suggestion {
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--text-main);
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}

.ai-question-suggestion:hover,
.ai-question-suggestion:focus-visible {
  border-color: var(--accent);
  outline-color: var(--accent);
}

.chat-citation-tag {
  display: inline-block;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--accent-subtle);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
  margin-top: 6px;
  cursor: pointer;
}

.ai-chat-form {
  padding: 14px 18px;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg-panel);
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin-top: auto;
}

.ai-chat-input {
  flex: 1;
  background: var(--bg-panel-alt) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--border-light) !important;
  border-radius: 9px;
  padding: 12px 16px;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease;
}

.ai-chat-input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent-glow) !important;
}

.ai-chat-input::placeholder {
  color: var(--text-dim) !important;
}

.modal-header-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  color: var(--accent);
}

.modal-header-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.btn-cancel {
  background: var(--bg-panel-alt) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--border-subtle) !important;
  padding: 10px 20px !important;
  border-radius: 8px !important;
  font-size: 13.5px !important;
  font-weight: 600 !important;
  font-family: var(--font-sans) !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.15s ease !important;
}

.btn-cancel:hover {
  background: var(--bg-app) !important;
  border-color: var(--text-dim) !important;
  color: var(--text-main) !important;
  transform: translateY(-1px) !important;
}

body.dark-mode .btn-cancel {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

body.dark-mode .btn-cancel:hover {
  background: #374151 !important;
  border-color: #4b5563 !important;
}

.modal-close {
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  flex: 0 0 40px !important;
  border-radius: 50% !important;
  background: transparent !important;
  border: 1px solid transparent !important;
  color: var(--text-muted) !important;
  cursor: pointer !important;
  display: grid !important;
  place-items: center !important;
  font-size: 16px !important;
  line-height: 1 !important;
  transition: all 0.15s ease !important;
  padding: 0 !important;
}

.modal-close:hover {
  background: rgba(239, 68, 68, 0.12) !important;
  border-color: rgba(239, 68, 68, 0.25) !important;
  color: var(--error) !important;
  transform: rotate(90deg) scale(1.05) !important;
}

.modal-close svg {
  width: 14px;
  height: 14px;
  display: block;
}

/* --------------------------------------------------------------------------
   Command Palette / All-Tools Directory Modal (Ctrl+K)
   -------------------------------------------------------------------------- */

.command-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.85) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  animation: fadeIn 0.15s ease;
}

.command-modal {
  --bg-panel: #111827;
  --bg-panel-alt: #1f2937;
  --border-light: rgba(255, 255, 255, 0.12);
  --border-subtle: rgba(255, 255, 255, 0.18);
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --accent-subtle: rgba(255, 75, 38, 0.12);

  width: 90%;
  max-width: 680px;
  background: #111827 !important;
  color: #f9fafb !important;
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  border-radius: 18px !important;
  box-shadow: 0 30px 70px -15px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.08) !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

.command-search-header {
  padding: 18px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.command-search-header input {
  flex: 1;
  border: none;
  font-size: 17px;
  font-weight: 600;
  outline: none;
  background: transparent;
  color: #f9fafb !important;
}

.command-results-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}

.command-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #9ca3af;
  padding: 8px 12px 4px;
}

.command-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.1s ease;
  color: #f9fafb;
}

.command-item:hover, .command-item.focused {
  background: rgba(255, 75, 38, 0.15);
}

.command-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.command-item-left strong {
  font-size: 13.5px;
  color: #f9fafb;
}

.command-item-left small {
  color: #9ca3af;
  font-size: 12px;
}

.command-item-badge {
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: #6b7280;
}

.command-backdrop[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.85) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  --bg-panel: #111827;
  --bg-panel-alt: #1f2937;
  --border-light: rgba(255, 255, 255, 0.12);
  --border-subtle: rgba(255, 255, 255, 0.18);
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --accent-subtle: rgba(255, 75, 38, 0.12);

  width: 100%;
  max-width: 480px;
  background: #111827 !important;
  color: #f9fafb !important;
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  border-radius: 18px !important;
  padding: 30px;
  box-shadow: 0 30px 70px -15px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.08) !important;
  animation: modalPop 0.22s var(--ease-spring);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h2,
.modal-header h3,
.modal-card h2,
.modal-card h3,
.modal-card h4,
.modal-card strong {
  color: #f9fafb !important;
}

.modal-card p {
  color: #9ca3af;
}

.close-modal-btn {
  background: transparent;
  border: none;
  font-size: 19px;
  color: #9ca3af !important;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 10px;
  border-radius: 8px;
  line-height: 1;
  transition: all 0.15s ease;
}

.close-modal-btn:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.1) !important;
}

.modal-card label,
.modal-card .option-field label {
  color: #d1d5db !important;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  display: block;
}

.modal-card input[type="text"],
.modal-card input[type="email"],
.modal-card input[type="password"],
.modal-card input[type="url"],
.settings-modal-card input {
  background: #1f2937 !important;
  border: 1px solid #374151 !important;
  color: #f9fafb !important;
  border-radius: 8px;
  padding: 10px 14px;
}

.modal-card input::placeholder,
.settings-modal-card input::placeholder {
  color: #6b7280 !important;
}

.modal-card input:focus,
.settings-modal-card input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent-glow) !important;
  outline: none;
}

.modal-card .file-row-card {
  background: #1f2937 !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: #f9fafb !important;
}

.modal-card .file-row-card strong {
  color: #f9fafb !important;
}

.modal-card .file-row-card code {
  background: rgba(255, 255, 255, 0.08) !important;
  color: #93c5fd !important;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12) !important;
  margin-bottom: 18px;
}

.auth-tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  font-weight: 700;
  font-size: 13.5px;
  color: #9ca3af !important;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.auth-tab-btn.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent) !important;
}

.auth-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Toast Notification / Tooltip Feedback */
/* Toast Notification / Tooltip Feedback */
.toast-notice {
  position: fixed;
  top: 76px;
  right: 24px;
  background: var(--text-main);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 3100;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUpToast 0.25s var(--ease-spring);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.toast-notice.toast-success {
  background: #064e3b;
  border-color: #059669;
  color: #ecfdf5;
}

.toast-notice.toast-error {
  background: #7f1d1d;
  border-color: #dc2626;
  color: #fef2f2;
}

.toast-notice.toast-warning {
  background: #78350f;
  border-color: #d97706;
  color: #fffbeb;
}

.toast-notice.toast-info {
  background: #1e293b;
  border-color: #3b82f6;
  color: #f8fafc;
}

@keyframes slideUpToast {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==========================================================================
   Comprehensive Settings Modal (Tabbed Layout)
   ========================================================================== */

.settings-modal-card {
  max-width: 840px !important;
  width: 95%;
  min-height: 560px !important;
  padding: 32px 36px !important;
  display: flex;
  flex-direction: column;
}

.settings-tabs {
  display: flex;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
  margin-bottom: 24px;
  padding-bottom: 8px;
  overflow-x: auto;
}

.settings-tab-btn {
  background: transparent;
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  color: #9ca3af !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.settings-tab-btn:hover {
  color: #f9fafb !important;
  background: rgba(255, 255, 255, 0.06);
}

.settings-tab-btn.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent) !important;
  background: rgba(255, 75, 38, 0.12) !important;
}

.settings-pane {
  animation: fadeIn 0.18s ease;
}

.settings-pane[hidden] {
  display: none !important;
}

.settings-card-item {
  background: #1f2937 !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 14px;
  padding: 22px 26px;
  color: #f3f4f6 !important;
}

.settings-user-info-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-signout {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-signout:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
}

/* Theme picker cards */
.theme-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.theme-choice-card {
  background: var(--bg-panel-alt);
  border: 2px solid var(--border-light);
  border-radius: 12px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.theme-choice-card:hover {
  border-color: #4b6267;
  transform: translateY(-1px);
}

.theme-choice-card.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.theme-choice-card strong {
  font-size: 13.5px;
  color: #f9fafb !important;
}

.theme-choice-card small {
  font-size: 11.5px;
  color: #9ca3af !important;
  line-height: 1.4;
}

.theme-swatch {
  font-size: 22px;
  margin-bottom: 2px;
}

/* Billing summary inside settings */
.billing-status-summary {
  background: #1f2937 !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 14px;
  padding: 22px 26px;
}

.quota-progress-track {
  background: rgba(255, 255, 255, 0.1) !important;
}

/* API info banner callout */
.api-info-callout {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.1) !important;
  border: 1px solid rgba(59, 130, 246, 0.3) !important;
  margin-bottom: 16px;
}

.tool-desk-ai-workspace-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid rgba(236, 72, 153, 0.28);
  border-radius: 12px;
  background: rgba(236, 72, 153, 0.07);
  color: var(--text-main);
  line-height: 1.45;
}

.tool-desk-ai-workspace-note strong {
  flex: 0 0 auto;
}

.tool-desk-ai-workspace-note span {
  flex: 1 1 22rem;
  min-width: 0;
  font-size: 0.9rem;
}

.tool-desk-ai-workspace-note a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  color: #9d174d;
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

body.dark-mode .tool-desk-ai-workspace-note a,
body.high-contrast .tool-desk-ai-workspace-note a {
  color: #fda4af;
}

:is(.workspace-page, .seo-content, .legal-article, .legal-doc-pane, .option-help, .tier-features-list) a:not([class]) {
  color: #c2410c;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

body.dark-mode :is(.workspace-page, .seo-content, .legal-article, .legal-doc-pane, .option-help, .tier-features-list) a:not([class]),
body.high-contrast :is(.workspace-page, .seo-content, .legal-article, .legal-doc-pane, .option-help, .tier-features-list) a:not([class]) {
  color: #ff8a65;
}

.api-info-icon {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}

.api-info-text {
  font-size: 12.5px;
  color: var(--text-main);
  line-height: 1.55;
}

.api-info-text code {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 75, 38, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11.5px;
}

/* Enterprise settings dashboard: pinned rail + independently scrolling
   content viewport. These rules intentionally override the legacy compact
   tab strip above. */
.settings-modal-card {
  width: min(94vw, 1020px) !important;
  flex: 0 0 min(94vw, 1020px);
  max-width: none !important;
  height: 78vh;
  min-height: 580px;
  max-height: 820px;
  min-width: 0;
  padding: 0 !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.settings-modal-card > .modal-header {
  flex: 0 0 auto;
  padding: 24px 30px;
  margin: 0;
  border-bottom: 1px solid var(--border-light);
}

.settings-layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.settings-modal-card .settings-tabs {
  flex: 0 0 264px;
  width: 264px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 22px 14px;
  margin: 0;
  border: 0 !important;
  border-right: 1px solid var(--border-light) !important;
  overflow-y: auto;
}

.settings-modal-card .settings-tabs .settings-tab-btn {
  min-height: 54px;
  height: auto;
  overflow: visible;
}

.settings-modal-card .settings-tabs .settings-tab-btn small {
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: break-word;
}

.settings-modal-card .settings-tab-btn {
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  border-bottom: 0;
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
  color: var(--text-muted) !important;
}

.settings-modal-card .settings-tab-btn > span:first-child {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: currentColor;
  font-size: 13px;
}

.settings-modal-card .settings-tab-btn > span:first-child svg {
  width: 15px;
  height: 15px;
  max-width: 15px;
  max-height: 15px;
  display: block;
  flex: 0 0 15px;
}

.settings-modal-card .settings-tab-btn > span:last-child {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.settings-modal-card .settings-tab-btn strong {
  color: currentColor !important;
  font-size: 12px;
  line-height: 1.25;
}

.settings-modal-card .settings-tab-btn small {
  color: var(--text-dim);
  font-size: 10.5px;
  line-height: 1.25;
}

.settings-modal-card .settings-tab-btn:hover {
  background: var(--bg-panel-alt);
  border-color: var(--border-light);
  color: var(--text-main) !important;
}

.settings-modal-card .settings-tab-btn.active {
  color: var(--accent) !important;
  background: var(--accent-subtle) !important;
  border-color: rgba(255, 75, 38, 0.24) !important;
}

.settings-modal-card .settings-content {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 28px 32px 24px;
  overflow-y: auto;
}

.settings-modal-card .settings-pane {
  max-width: 700px;
  margin: 0 auto;
}

.settings-modal-card .settings-card-item,
.settings-modal-card .billing-status-summary,
.settings-modal-card .api-info-callout {
  background: var(--bg-panel-alt) !important;
  border: 1px solid var(--border-light) !important;
  color: var(--text-main) !important;
  box-shadow: none;
}

.settings-modal-card .settings-card-item { padding: 22px 24px; margin-bottom: 16px; }
.settings-modal-card .settings-card-item h4 { color: var(--text-main) !important; margin: 0 0 8px; font-size: 15px; }
.settings-modal-card .settings-card-item p { color: var(--text-muted) !important; }
.settings-modal-card input,
.settings-modal-card select,
.settings-modal-card textarea {
  background: var(--bg-panel-alt) !important;
  border: 1px solid var(--border-light) !important;
  color: var(--text-main) !important;
}
.settings-modal-card input::placeholder { color: var(--text-dim) !important; }
.settings-modal-card .settings-user-info-row h4 { color: var(--text-main) !important; }
.settings-modal-card .settings-clean-footer { border-color: var(--border-light) !important; }
.billing-return-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; margin: 10px 18px 0; border-radius: 10px;
  border: 1px solid rgba(59, 130, 246, 0.35); background: rgba(59, 130, 246, 0.1);
  color: var(--text-main);
}
.billing-return-banner.is-success { border-color: rgba(16, 185, 129, 0.45); background: rgba(16, 185, 129, 0.12); }
.billing-return-banner.is-warning { border-color: rgba(245, 158, 11, 0.45); background: rgba(245, 158, 11, 0.12); }
.billing-return-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.billing-return-copy strong { font-size: 13.5px; color: var(--text-main); }
.billing-return-copy span { font-size: 12.5px; color: var(--text-muted); }
.billing-return-actions { display: flex; align-items: center; gap: 8px; }
.account-plan-expiry { margin-top: 6px; font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }
.billing-expiry-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; margin-bottom: 10px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border-light); font-size: 12.5px;
}
.billing-expiry-row span { color: var(--text-muted); }
.order-history-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.order-history-item {
  display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border-light); background: rgba(255, 255, 255, 0.02); font-size: 12.5px;
}
.order-history-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.order-history-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; color: var(--text-muted); font-size: 11.5px; }
.support-status-pill {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  background: rgba(59, 130, 246, 0.16); color: #60a5fa;
}
.support-status-pill.is-paid, .support-status-pill.is-resolved { background: rgba(16, 185, 129, 0.18); color: #34d399; }
.support-status-pill.is-open { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.support-founder-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.support-founder-header h4 { margin: 0 !important; }
.support-sla-pill {
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 75, 38, 0.14); color: var(--accent); border: 1px solid rgba(255, 75, 38, 0.25);
}
.support-contact-strip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border-light); font-size: 12.5px;
}
.support-contact-strip a { color: var(--accent); font-weight: 600; text-decoration: none; }
.support-contact-strip a:hover { text-decoration: underline; }
.support-contact-strip small { color: var(--text-muted); }
.support-troubleshooter { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.support-faq-item {
  border: 1px solid var(--border-light); border-radius: 8px; padding: 9px 12px; font-size: 12.5px;
}
.support-faq-toggle {
  width: 100%; background: none; border: none; padding: 0; cursor: pointer; font: inherit;
  font-weight: 600; color: var(--text-main); text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.support-faq-chevron { color: var(--text-muted); font-size: 15px; flex-shrink: 0; }
.support-faq-body p { margin: 8px 0 6px; line-height: 1.45; }
.support-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.support-textarea { min-height: 92px; resize: vertical; font-family: inherit; }
.support-context-check { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; color: var(--text-muted); margin: 8px 0; cursor: pointer; }
.support-context-check input { width: auto !important; margin-top: 2px; }
.support-ticket-result {
  padding: 10px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.45; margin-top: 8px;
  border: 1px solid rgba(16, 185, 129, 0.45); background: rgba(16, 185, 129, 0.12); color: var(--text-main);
}
@media (max-width: 640px) {
  .support-form-grid { grid-template-columns: 1fr; }
  .billing-return-banner { margin: 8px 12px 0; }
}
.settings-eyebrow { display: block; color: var(--accent); font: 700 10px var(--font-mono); letter-spacing: .08em; margin-bottom: 8px; }
.settings-privacy-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-top: 18px; margin-top: 16px; border-top: 1px solid var(--border-light); }
.settings-privacy-toggle-row strong, .settings-privacy-toggle-row small { display: block; }
.settings-privacy-toggle-row strong { font-size: 13px; color: var(--text-main); }
.settings-privacy-toggle-row small { color: var(--text-muted); font-size: 11.5px; line-height: 1.45; margin-top: 4px; }
.settings-privacy-toggle-row > label.toggle-switch-sm {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
}
.settings-privacy-toggle-row > label.toggle-switch-sm .toggle-slider-sm {
  inset: 13px 6px;
}

body.light-mode .settings-modal-card {
  background: #ffffff !important;
  border: 1px solid #e2eae4 !important;
  color: #142023 !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.15) !important;
}
body.light-mode .settings-modal-card .settings-card-item,
body.light-mode .settings-modal-card .billing-status-summary {
  background: #f8faf9 !important;
  border-color: #e4eae4 !important;
  color: #142023 !important;
}
body.light-mode .settings-modal-card input,
body.light-mode .settings-modal-card select,
body.light-mode .settings-modal-card textarea {
  background: #f8faf9 !important;
  border-color: #d1ddd5 !important;
  color: #142023 !important;
}
body.light-mode .settings-modal-card h3,
body.light-mode .settings-modal-card h4,
body.light-mode .settings-modal-card strong { color: #142023 !important; }
body.light-mode .settings-modal-card p { color: #5e6f72 !important; }

body.dark-mode .settings-modal-card {
  background: #111827 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}
body.dark-mode .settings-modal-card .settings-card-item,
body.dark-mode .settings-modal-card .billing-status-summary {
  background: #1f2937 !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  color: #f9fafb !important;
}

/* Google Social Auth & Password Toggle */
.btn-google-auth,
.btn-google-social {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  background: #ffffff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-sizing: border-box;
  transition: all 0.18s ease;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.1);
  margin-bottom: 14px;
}

.btn-google-auth:hover,
.btn-google-social:hover {
  background: #f8fafc;
  border-color: #bdc1c6;
  box-shadow: 0 2px 6px rgba(60, 64, 67, 0.15);
  transform: translateY(-1px);
}

body.dark-mode .btn-google-auth,
body.dark-mode .btn-google-social {
  background: #1e2630;
  color: #e5e7eb;
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

body.dark-mode .btn-google-auth:hover,
body.dark-mode .btn-google-social:hover {
  background: #26313f;
  border-color: rgba(255, 255, 255, 0.28);
}

.btn-google-social .google-icon,
.btn-google-auth .google-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 14px 0 16px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-light);
}

.auth-divider span {
  padding: 0 12px;
}

.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-wrapper input {
  width: 100%;
  padding-right: 42px !important;
}

.password-toggle-btn {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 17px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.password-toggle-btn:hover {
  color: var(--text-main);
}

.auth-otp-input {
  width: 100%;
  text-align: center;
  font-family: var(--font-mono, monospace);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 8px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--bg-panel-alt);
  color: var(--text-main);
  border: 1.5px solid var(--border-light);
  box-sizing: border-box;
  transition: all 0.15s ease;
}

.auth-otp-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}

.otp-resend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ==========================================================================
   Multi-Tier Pricing Modal Grid
   ========================================================================== */

.pricing-modal-card {
  max-width: 840px !important;
  width: 95%;
  padding: 32px 36px !important;
}

.pricing-tiers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.pricing-limits-section {
  margin-top: 24px;
  padding: 18px;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  background: var(--surface-2, rgba(255,255,255,0.025));
}
.pricing-limits-section h3 { margin: 0 0 8px; }
.pricing-limits-section > p { max-width: 900px; color: var(--text-muted); font-size: 13px; line-height: 1.55; }
.pricing-limits-scroll { max-width: 100%; overflow: auto; border: 1px solid var(--border-light); border-radius: 10px; }
.pricing-limits-scroll table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 12px; }
.pricing-limits-scroll th, .pricing-limits-scroll td { padding: 9px 11px; border-bottom: 1px solid var(--border-light); text-align: left; vertical-align: top; word-break: normal; overflow-wrap: break-word; }
.pricing-limits-scroll thead th { position: sticky; top: 0; background: var(--surface-1, var(--bg-panel)); }
.pricing-limits-scroll tbody th { font-weight: 650; white-space: normal; min-width: 130px; }
.seo-limits-link { margin: 16px 0; font-weight: 650; }

@media (max-width: 600px) {
  .pricing-limits-scroll { overflow: visible; border: 0; }
  .pricing-limits-scroll table { display: block; width: 100%; min-width: 0; font-size: 12px; }
  .pricing-limits-scroll thead {
    position: absolute; inset: 0 auto auto 0; width: 1px; height: 1px; padding: 0; margin: -1px;
    max-width: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .pricing-limits-scroll thead tr,
  .pricing-limits-scroll thead th {
    position: static !important;
    display: block !important;
    width: 1px !important;
    min-width: 0 !important;
    max-width: 1px !important;
    padding: 0 !important;
    overflow: hidden !important;
  }
  .pricing-limits-scroll tbody { display: grid; gap: 10px; }
  .pricing-limits-scroll tbody tr {
    display: grid; gap: 0; min-width: 0; padding: 4px 10px;
    border: 1px solid var(--border-light); border-radius: 10px;
    background: var(--bg-panel-alt, #f8faf9);
  }
  .pricing-limits-scroll tbody th,
  .pricing-limits-scroll tbody td {
    display: grid; grid-template-columns: minmax(90px, .72fr) minmax(0, 1.28fr);
    gap: 10px; min-width: 0; padding: 9px 0; border-bottom: 1px solid var(--border-light);
    white-space: normal; word-break: normal; overflow-wrap: break-word;
  }
  .pricing-limits-scroll tbody tr > :last-child { border-bottom: 0; }
  .pricing-limits-scroll tbody :is(th, td)::before {
    content: attr(data-label); color: var(--text-muted); font-size: 10px;
    font-weight: 750; line-height: 1.4; text-transform: uppercase; letter-spacing: .03em;
  }
}

@media (max-width: 760px) {
  .pricing-tiers-grid {
    grid-template-columns: 1fr;
  }
}

.pricing-tier-card {
  background: #1f2937 !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  border-radius: 14px;
  padding: 42px 24px 24px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.2s ease;
}

.pricing-tier-card:hover {
  border-color: rgba(255, 255, 255, 0.3) !important;
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.pricing-tier-card.popular {
  border-color: var(--accent) !important;
  background: linear-gradient(180deg, rgba(255, 75, 38, 0.12) 0%, #1f2937 100%) !important;
  box-shadow: 0 6px 20px rgba(255, 75, 38, 0.15);
}

.pricing-tier-card.developer {
  border-color: #3b82f6 !important;
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.12) 0%, #1f2937 100%) !important;
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.15);
}

.tier-popular-tag {
  position: absolute;
  top: 12px;
  right: 16px;
  background: linear-gradient(135deg, var(--accent) 0%, #ff7a59 100%);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 6px;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.tier-developer-tag {
  position: absolute;
  top: 12px;
  right: 16px;
  background: #2563eb;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}

.tier-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.tier-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: #f9fafb !important;
}

.tier-subtitle {
  font-size: 12px;
  color: #9ca3af !important;
}

.tier-price-box {
  margin: 12px 0 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.tier-price-main {
  display: flex;
  align-items: baseline;
  gap: 0;
}

.tier-price-val {
  font-size: 38px;
  font-weight: 800;
  color: #f9fafb !important;
  line-height: 1;
}

body.light-mode .tier-price-val {
  color: #111827 !important;
}

body.light-mode .tier-price-period,
body.light-mode .tier-price-alt,
body.light-mode .tier-subtitle {
  color: #4b5563 !important;
}

body.light-mode .tier-price-box {
  border-bottom: 1px solid #e5e7eb !important;
}

.tier-price-period {
  font-size: 13.5px;
  font-weight: 600;
  color: #9ca3af !important;
}

.tier-price-alt {
  display: inline-block;
  margin-top: 5px;
  font-size: 12px;
  color: #9ca3af !important;
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08) !important;
  padding: 3px 8px;
  border-radius: 5px;
}

.tier-features-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 20px;
  flex: 1;
}

.tier-features-list li {
  position: relative;
  display: block;
  padding-left: 22px;
  font-size: 12.5px;
  line-height: 1.48;
  color: #e5e7eb !important;
}

.tier-features-list li strong {
  color: #f9fafb !important;
}

.tier-features-list li > span:first-child {
  position: absolute;
  left: 0;
  top: 2px;
  display: inline-flex;
  align-items: center;
  color: var(--success);
  font-weight: 800;
  font-size: 13.5px;
}

.settings-password-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.tier-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.tier-subscribe-btn {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 13.5px;
  font-weight: 800;
}

.tier-subscribe-btn.dev-theme {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

.tier-subscribe-btn.dev-theme:hover {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.tier-active-status {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  line-height: 1.35;
}

body:not(.light-mode) .tier-active-status {
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(110, 231, 183, 0.35);
}

.btn-demo-upgrade {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-subtle) !important;
  color: var(--text-main) !important;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.btn-demo-upgrade:hover,
.btn-secondary-action:hover {
  background: var(--bg-app) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
  transform: translateY(-1px);
}

.btn-secondary-action {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-subtle) !important;
  color: var(--text-main) !important;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

body.dark-mode .btn-demo-upgrade,
body.dark-mode .btn-secondary-action {
  background: #1f2937;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

.checkout-contact-bar {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel-alt);
}

.checkout-contact-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 440px;
  margin: 0 auto;
  text-align: left;
}

.checkout-contact-field label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
}

.checkout-phone-input {
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  font-size: 14px;
  padding: 9px 12px;
}

.checkout-phone-hint {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

.checkout-phone-error {
  font-size: 12px;
  font-weight: 600;
  color: #b91c1c;
}

body.dark-mode .checkout-contact-bar,
body.high-contrast .checkout-contact-bar {
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(148, 163, 184, 0.28);
}

body.dark-mode .checkout-phone-error,
body.high-contrast .checkout-phone-error {
  color: #fca5a5;
}

.razorpay-trust-footer {
  margin-top: 18px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}

body.dark-mode .razorpay-trust-footer,
body.high-contrast .razorpay-trust-footer {
  color: #cbd5e1;
}

.seo-use-cases {
  margin: 18px 0;
  padding: 16px 20px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel-alt);
}
.seo-use-cases h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}
.seo-use-cases ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.payment-method-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--text-main);
  background: var(--bg-panel-alt);
  font-size: 10px;
  font-weight: 700;
}

body.light-mode .payment-method-badge {
  border-color: #cbd5e1;
  color: #0f172a;
  background: #f1f5f9;
}

body.dark-mode .payment-method-badge,
body.high-contrast .payment-method-badge {
  border-color: rgba(255, 255, 255, 0.22);
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.08);
}

.razorpay-trust-note {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 4px;
}

/* Actionable Error Dialog */
.error-dialog-card {
  max-width: 440px;
  text-align: center;
  padding: 32px 28px;
}

.error-dialog-icon {
  font-size: 44px;
  margin-bottom: 12px;
  line-height: 1;
}

.error-dialog-card h3 {
  font-size: 18.5px;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--text-main);
}

.error-dialog-card p {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 22px;
}

.error-dialog-actions {
  display: flex;
  gap: 10px;
}

/* Mobile Backdrop Overlay */
.mobile-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 18, 20, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 45;
}

.mobile-backdrop[hidden] {
  display: none !important;
}

/* Responsive Rules */
@media (max-width: 900px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    display: block !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
  }
  .main-area {
    display: block !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
  }
  .dynamic-workspace {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
  .home-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    padding: 16px 12px 64px !important;
  }
  .full-page-view {
    padding: 20px 14px !important;
    margin-bottom: 16px !important;
  }
  .waitlist-form-row,
  .waitlist-input-group {
    flex-direction: column !important;
    width: 100% !important;
  }
  .waitlist-select {
    flex: 1 1 auto !important;
    width: 100% !important;
  }
  .mobile-menu-btn {
    display: flex;
  }
  .sidebar {
    position: fixed;
    left: -290px;
    top: 0;
    bottom: calc(66px + env(safe-area-inset-bottom, 0px));
    width: 290px;
    height: calc(100vh - 66px - env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - 66px - env(safe-area-inset-bottom, 0px));
    transition: left 0.3s var(--ease-spring);
    z-index: 50;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
  }
  .sidebar-scroll-area { min-height: 0; }
  .sidebar.mobile-open {
    left: 0;
  }
  .topbar {
    padding: 0 16px;
  }
  .topbar-upgrade-pill span:not(:first-child) {
    display: none;
  }
  .topbar-upgrade-pill {
    padding: 6px 10px;
  }
  .pdf-studio {
    grid-template-columns: 1fr;
  }
  .studio-thumbnails-bar {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Legal Center Modal & Documents (Privacy Policy & Terms of Service)
   -------------------------------------------------------------------------- */
.legal-modal-card {
  max-width: 780px;
  width: 95%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.legal-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
  flex-shrink: 0;
}

.legal-tab-btn {
  background: transparent;
  border: none;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
}

.legal-tab-btn:hover {
  color: var(--text-main);
}

.legal-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.legal-scroll-body {
  overflow-y: auto;
  padding-right: 12px;
  flex: 1;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-main);
}

.legal-scroll-body h3 {
  font-size: 16px;
  margin: 16px 0 8px 0;
  color: var(--text-main);
}

.legal-scroll-body p {
  margin-bottom: 12px;
  color: var(--text-muted);
}

.legal-scroll-body ul {
  margin: 0 0 14px 20px;
  color: var(--text-muted);
}

.legal-scroll-body li {
  margin-bottom: 6px;
}

.legal-highlight-box {
  background: var(--bg-panel-alt);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
}

.auth-legal-notice {
  font-size: 11.5px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 14px;
  line-height: 1.45;
}

.auth-legal-notice a,
.settings-legal-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.auth-legal-notice a:hover,
.settings-legal-footer a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Dedicated Full-Screen Workspace Views (Legal & API Documentation)
   ========================================================================== */

.full-page-view {
  background: var(--bg-panel);
  border-radius: 16px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  padding: 32px 40px;
  min-height: calc(100vh - 160px);
  min-height: calc(100dvh - 160px);
  animation: fadeIn 0.22s var(--ease-spring);
  margin-bottom: 24px;
}

.view-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 26px;
}

.btn-back-workspace {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-back-workspace:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateX(-3px);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.view-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.view-header-title h2 {
  font-size: 21px;
  font-weight: 800;
  margin: 0;
  color: var(--text-main);
}

.view-header-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
  letter-spacing: 0.04em;
}

.view-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-spec-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.18s ease;
}

.btn-spec-link.swagger-link {
  background: rgba(255, 75, 38, 0.12);
  color: var(--accent);
  border: 1px solid rgba(255, 75, 38, 0.3);
}

.btn-spec-link.swagger-link:hover {
  background: var(--accent);
  color: #fff;
}

.btn-spec-link.redoc-link {
  background: rgba(59, 130, 246, 0.12);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.btn-spec-link.redoc-link:hover {
  background: #3b82f6;
  color: #fff;
}

/* Legal View Navigation Tabs */
.legal-view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-panel-alt);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  max-width: 100%;
  box-sizing: border-box;
}

.cookie-consent-banner {
  position: fixed;
  right: 20px;
  left: auto;
  bottom: 20px;
  z-index: 1550;
  max-width: min(440px, calc(100vw - 32px));
  background: var(--bg-panel);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
}
.cookie-consent-banner[hidden] { display: none !important; }
.cookie-banner-text { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--text-muted); }
.cookie-banner-link { color: var(--accent); font-weight: 700; text-decoration: underline; white-space: nowrap; }
.cookie-banner-actions { flex: 0 0 auto; }
.cookie-banner-btn { padding: 7px 14px !important; font-size: 12px !important; min-height: 34px !important; white-space: nowrap; }

#upgrade-modal.modal-backdrop {
  z-index: 3600 !important;
}

.legal-view-tab-btn {
  padding: 8px 18px;
  border-radius: 7px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.legal-view-tab-btn.active {
  background: var(--bg-panel);
  color: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Legal Hero Banner */
.legal-hero-banner {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  padding: 22px 26px;
  border-radius: 14px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  margin-bottom: 28px;
}

.legal-hero-icon {
  font-size: 28px;
  line-height: 1;
}

.legal-hero-banner h3 {
  margin: 0 0 6px 0;
  font-size: 16px;
  color: var(--text-main);
  font-weight: 800;
}

.legal-hero-banner p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Legal Article Typography */
.legal-article section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-light);
}

.legal-article section:last-child {
  border-bottom: none;
}

.legal-article h3 {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-main);
  margin: 0 0 12px 0;
}

.legal-article p {
  font-size: 14px;
  color: var(--text-main);
  line-height: 1.7;
  margin: 0 0 12px 0;
}

.legal-article ul {
  margin: 0 0 14px 20px;
  padding: 0;
}

.legal-article li {
  font-size: 14px;
  color: var(--text-main);
  line-height: 1.7;
  margin-bottom: 8px;
}

.legal-article code {
  font-family: var(--font-mono);
  background: rgba(255, 75, 38, 0.1);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12.5px;
}

/* API Docs Dedicated Workspace Styles */
.api-docs-hero-box {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 14px;
  padding: 22px 26px;
  margin-bottom: 24px;
}

.api-docs-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

@media (max-width: 900px) {
  .api-docs-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .api-docs-meta-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Compact desktop ribbon density requested for the 1920px Studio toolbar. */
@media (min-width: 901px) {
  html.studio-active body .studio-toolbar .studio-primary-ribbon,
  html.studio-active body .studio-toolbar .studio-sub-ribbon {
    gap: 4px !important;
    min-height: 0 !important;
    padding: 3px 8px !important;
  }
  html.studio-active body .studio-toolbar .studio-tool-btn {
    min-width: 0 !important;
    min-height: 28px !important;
    padding: 3px 6px !important;
    gap: 3px !important;
    font-size: 10px !important;
    line-height: 1.1 !important;
  }
  html.studio-active body .studio-toolbar .studio-mode-btn {
    min-height: 27px !important;
    padding: 3px 7px !important;
    font-size: 10px !important;
  }
  html.studio-active body .studio-toolbar .studio-divider { margin-inline: 2px !important; }
  html.studio-active body .studio-toolbar .studio-page-badge { min-height: 26px !important; }
  html.studio-active body .studio-toolbar .zoom-select { min-height: 27px !important; padding-block: 2px !important; }
}

@media (max-width: 900px) {
  html.studio-active body .studio-toolbar .studio-tool-btn,
  html.studio-active body .studio-toolbar .studio-mode-btn { min-height: 40px; }
}

.organizer-order-status { min-height: 20px; margin: 4px 0 8px; color: var(--text-muted); font-size: 12px; line-height: 1.4; }
.organizer-order-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; max-height: min(52vh, 520px); overflow: auto; padding: 2px 4px 8px 2px; overscroll-behavior: contain; }
.organizer-order-card { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-items: center; gap: 6px 8px; min-width: 0; padding: 7px; border: 1px solid var(--border-light); border-radius: 10px; background: var(--bg-panel); cursor: grab; touch-action: pan-y; }
.organizer-order-card.dragging { opacity: .45; }
.organizer-order-card.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); }
.organizer-order-thumbnail { display: block; grid-column: 1 / -1; width: 100%; height: 118px; object-fit: contain; border: 1px solid var(--border-light); border-radius: 5px; background: white; }
.organizer-order-card strong { min-width: 0; color: var(--text-main); font-size: 12px; white-space: nowrap; }
.organizer-order-move-controls { display: flex; gap: 4px; }
.organizer-order-move-controls button { width: 36px; min-height: 36px; border: 1px solid var(--border-light); border-radius: 7px; color: var(--text-main); background: var(--bg-panel-alt); font-size: 17px; cursor: pointer; }
.organizer-order-move-controls button:disabled { opacity: .4; cursor: not-allowed; }
.organizer-order-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tier-current-plan { display: inline-flex; width: fit-content; margin: 0 0 8px; padding: 4px 8px; border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 999px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: 10px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.tier-current-plan[hidden] { display: none !important; }
.pricing-tier-card.is-current-plan { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-light)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 12%, transparent); }
@media (max-width: 480px) {
  .organizer-order-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; max-height: 44dvh; }
  .organizer-order-thumbnail { height: 104px; }
  .organizer-order-move-controls button { width: 40px; min-height: 40px; }
  .organizer-order-card strong { white-space: normal; }
}

.api-meta-item {
  min-width: 0;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 14px 18px;
}

.meta-label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.meta-val {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
  font-family: var(--font-mono);
}

.api-docs-meta-grid .meta-val {
  overflow-wrap: break-word;
  word-break: normal;
}

.api-code-workbench-card {
  background: #0b1114;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin-bottom: 28px;
}

.api-code-workbench-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 12px 14px;
  background: #141e21;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 0;
}

.api-docs-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.full-api-tab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 700;
  color: #8fa0a3;
  cursor: pointer;
  transition: all 0.15s ease;
}

.full-api-tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.full-api-tab.active {
  color: #fff;
  background: var(--accent);
}

.btn-copy-code {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #eef3f1;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-copy-code:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.api-code-wrapper {
  position: relative;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  background: #0b1114;
}

.api-code-block {
  margin: 0;
  padding: 20px;
  max-width: 100%;
  max-height: 380px;
  overflow: auto;
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: #d1e2e0;
}

.api-code-block code {
  display: block;
  min-width: 0;
  font-family: inherit;
  white-space: pre;
}

.forms-detected-panel {
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: var(--bg-panel-alt);
}

.forms-detected-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.forms-detected-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.forms-field-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--text-main);
  font-size: 12px;
  cursor: pointer;
}

.forms-field-chip:hover {
  border-color: var(--accent);
}

.forms-field-chip__type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.btn-secondary-inline {
  padding: 5px 10px;
  border: 1px solid var(--border-light);
  border-radius: 7px;
  background: var(--bg-panel);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.endpoints-table-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border-light);
}

.endpoints-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: left;
}

.endpoints-table th {
  background: var(--bg-panel-alt);
  padding: 14px 18px;
  font-weight: 800;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.endpoints-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
}

.endpoints-table tr:last-child td {
  border-bottom: none;
}

.http-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
}

.http-badge.post {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
}

.http-badge.get {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
}

/* ==========================================================================
   Global Application Footer
   ========================================================================== */

.app-global-footer {
  margin-top: auto;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  border-top: 1px solid var(--border-light);
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--bg-panel);
  border-radius: 12px 12px 0 0;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.footer-sep {
  color: var(--text-dim);
  user-select: none;
}

.footer-link-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.footer-link-btn:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.footer-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ==========================================================================
   PHASE 2: PROFESSIONAL PDF EDITOR STYLES
   ========================================================================== */

/* Unsaved Changes Indicator */
.editor-unsaved-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #f59e0b;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  letter-spacing: 0.3px;
}

.unsaved-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  animation: editorPulse 1.6s infinite ease-in-out;
}

@keyframes editorPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.3); }
}

/* Style Controls in Toolbar */
.editor-style-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-color-input {
  width: 30px;
  height: 30px;
  padding: 1px;
  border: 2px solid #ffffff !important;
  border-radius: 6px;
  background: #192426;
  cursor: pointer;
  outline: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.75), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.editor-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.editor-color-input::-webkit-color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}

.editor-stroke-select {
  height: 30px;
  background: #243437 !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  border-radius: 6px;
  color: #ffffff !important;
  padding: 0 8px !important;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  min-width: 68px;
  outline: none;
}

.editor-stroke-select option {
  background: #192426 !important;
  color: #ffffff !important;
}

/* Floating Text Overlay Panel */
.editor-floating-panel {
  position: fixed;
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  width: 380px;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 12px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.7);
  z-index: 1000;
  overflow: hidden;
  animation: editorFadeInDown 0.18s ease-out;
}

@keyframes editorFadeInDown {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.editor-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #1f2937;
}

.editor-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #f3f4f6;
}

.editor-panel-close-btn {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.editor-panel-close-btn:hover {
  color: #f3f4f6;
}

.editor-panel-notice {
  padding: 8px 16px;
  background: rgba(59, 130, 246, 0.1);
  border-bottom: 1px solid rgba(59, 130, 246, 0.2);
  font-size: 11px;
  color: #93c5fd;
  line-height: 1.4;
}

.editor-panel-body {
  padding: 14px 16px;
}

.editor-textarea {
  width: 100%;
  box-sizing: border-box;
  background: #0d1416;
  border: 1px solid #374151;
  border-radius: 8px;
  color: #f3f4f6;
  padding: 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.editor-textarea:focus {
  border-color: var(--accent);
}

.editor-panel-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  align-items: flex-end;
}

.editor-control-col label {
  display: block;
  font-size: 10.5px;
  color: #9ca3af;
  margin-bottom: 4px;
  font-weight: 600;
  text-transform: uppercase;
}

.editor-color-swatch {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.editor-select {
  height: 32px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text-main);
  padding: 0 8px;
  font-size: 12px;
}

body.light-mode .editor-select {
  background: #ffffff !important;
  border-color: #d1d5db !important;
  color: #111827 !important;
}

body.light-mode .editor-select option {
  background-color: #ffffff !important;
  color: #111827 !important;
}

body.dark-mode .editor-select,
body:not(.light-mode) .editor-select {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

body.dark-mode .editor-select option,
body:not(.light-mode) .editor-select option {
  background-color: #1f2937 !important;
  color: #f9fafb !important;
}

.editor-toggle-group {
  display: flex;
  gap: 4px;
}

.editor-toggle-btn {
  width: 32px;
  height: 32px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #e5e7eb;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.editor-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.editor-panel-footer {
  padding: 12px 16px;
  border-top: 1px solid #1f2937;
}

/* Signature Mark Modal */
.editor-sig-modal-card {
  max-width: 600px;
  width: 90%;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 14px;
  padding: 22px;
}

.editor-sig-tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0 12px;
  border-bottom: 1px solid #1f2937;
  padding-bottom: 8px;
}

.editor-sig-tab-btn {
  background: none;
  border: none;
  color: #9ca3af;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.editor-sig-tab-btn.active {
  background: rgba(255, 75, 38, 0.15);
  color: #ff4b26;
}

.editor-sig-canvas {
  width: 100%;
  height: 180px;
  background: #ffffff;
  border: 2px dashed #4b5563;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
}

.sig-canvas-hint {
  font-size: 11px;
  color: #6b7280;
  text-align: center;
  margin-top: 8px;
}

.editor-sig-input {
  width: 100%;
  box-sizing: border-box;
  background: #0d1416;
  border: 1px solid #374151;
  border-radius: 8px;
  color: #f3f4f6;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}

.editor-sig-input:focus {
  border-color: var(--accent);
}

.sig-type-preview {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #111827;
  font-family: 'Brush Script MT', cursive, sans-serif;
  font-size: 40px;
  border-radius: 8px;
  margin-top: 14px;
  border: 1px solid #e5e7eb;
}

.editor-sig-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}

/* Document Stamp Picker */
.editor-stamp-card {
  max-width: 500px;
  width: 90%;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 14px;
  padding: 22px;
}

.editor-stamps-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 18px 0;
}

.stamp-preset-btn {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 14px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.stamp-preset-btn:hover {
  transform: translateY(-2px);
  border-color: #6b7280;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.stamp-badge {
  font-family: Impact, 'Arial Black', sans-serif;
  font-size: 19px;
  letter-spacing: 2.5px;
  padding: 5px 12px;
  border: 2.5px solid currentColor;
  border-radius: 4px;
  transform: rotate(-3deg);
  display: inline-block;
}

.stamp-approved .stamp-badge { color: #10b981; }
.stamp-rejected .stamp-badge { color: #ef4444; }
.stamp-draft .stamp-badge { color: #f59e0b; }
.stamp-confidential .stamp-badge { color: #dc2626; }
.stamp-reviewed .stamp-badge { color: #3b82f6; }

.editor-custom-stamp-box {
  background: #0d1416;
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 14px;
  margin-top: 8px;
}

.editor-custom-stamp-box input {
  flex: 1;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #f3f4f6;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}

/* =============================================================================
   PHASE 3: PROFESSIONAL PAGE MANAGEMENT ENGINE & ORGANIZER STYLES
   ============================================================================= */

/* Organizer Header Controls */
.organizer-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #f1f5f9;
}

.organizer-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.org-head-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #cbd5e1;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.org-head-btn:hover {
  background: rgba(56, 189, 248, 0.15);
  border-color: #38bdf8;
  color: #38bdf8;
}

/* Floating Multi-Page Batch Toolbar */
.organizer-batch-bar {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(56, 189, 248, 0.35);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 50;
  animation: slideDownBatch 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

@keyframes slideDownBatch {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.batch-bar-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.batch-count {
  font-size: 11px;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.25);
  white-space: nowrap;
}

.batch-bar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* Viewport-contained AI chat and PDF Studio layouts. */
.app-shell.ai-active { height: 100dvh; min-height: 0; overflow: hidden; }
.ai-active .main-area { height: 100dvh; min-height: 0; overflow: hidden; }
.ai-active .dynamic-workspace { flex: 1 1 auto; height: calc(100dvh - 64px); min-height: 0; max-width: none; padding: 8px 14px 12px; overflow: hidden; }
.ai-active #view-ai-studio { height: 100%; min-height: 0; overflow: hidden; gap: 10px; }
.ai-active .ai-studio-topbar { flex: 0 0 auto; gap: 6px; }
.ai-active .ai-upload-strip { padding: 8px 12px; }
.ai-active .ai-engine-notice-bar { display: flex; flex: 0 0 auto; padding: 5px 10px; }
.ai-active .ai-engine-info { display: none; }
.ai-active .footer, .ai-active .site-footer, .ai-active .privacy-footer { display: none !important; }
.ai-active .ai-studio-container { min-height: 0; grid-template-columns: minmax(0, 1fr) minmax(260px, 32%); gap: 10px; }
.ai-active .ai-chat-card { min-height: 0; height: 100%; }
.ai-active .ai-chat-messages { min-height: 0; max-height: none; overscroll-behavior: contain; }
.ai-active .ai-chat-form { position: static; }
.pdf-studio { width: 100%; min-width: 0; height: calc(100dvh - 64px); min-height: 0; border-radius: 0; }
.studio-toolbar { position: relative; z-index: 200; overflow: visible; }
.studio-primary-ribbon, .studio-sub-ribbon { overflow-x: auto; overflow-y: visible; }
.studio-dropdown-wrapper { z-index: 1001; }
.studio-dropdown-menu { z-index: 10000; max-height: min(70vh, 480px); overflow-y: auto; }
.studio-main-viewport { overflow: visible; }
.studio-canvas-area { position: relative; overflow: auto; }
.studio-empty-state { min-height: 100%; display: grid; align-content: center; justify-items: center; gap: 12px; color: #e2e8f0; text-align: center; }
.studio-empty-state p { color: #a4b7b4; }
.studio-empty-state button { margin: 4px; padding: 9px 14px; border: 1px solid #52666b; border-radius: 6px; background: #243437; color: white; cursor: pointer; }
.organizer-batch-bar { flex-wrap: wrap; justify-content: flex-start; }
.batch-bar-actions { flex-wrap: wrap; min-width: 0; }
.organizer-selection-panel { flex-wrap: wrap; overflow: visible; }

/* Keep workspace content within the column left by the sidebar. */
.app-shell, .main-area, .main-area > *, .view-main, .tool-content, .tool-workspace,
.home-content, .home-hero, .home-tools-grid, .ai-studio-container, .pdf-studio,
.studio-thumbnails-bar, .studio-thumbnails-scroll, .organizer-grid { min-width: 0; max-width: 100%; box-sizing: border-box; }
.app-shell { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.app-shell.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr); }
.organizer-grid.grid-mode { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding-right: 8px; }
.organizer-grid .thumb-card, .organizer-grid .page-card { min-width: 0; max-width: 100%; }
.auth-pending #topbar-auth-user,
.auth-pending #settings-user-email, .auth-pending #settings-user-avatar,
.auth-pending #settings-user-badge, .auth-pending #settings-user-actions { visibility: hidden; }
.auth-pending #topbar-auth-guest,
.auth-pending #topbar-upgrade-btn,
.auth-pending #sidebar-upgrade-btn,
.auth-pending #settings-guest-actions { visibility: visible; }
.auth-pending #user-name, .auth-pending #user-role-badge,
.auth-restoring #user-name, .auth-restoring #user-role-badge { visibility: hidden; }
.auth-pending #user-avatar, .auth-restoring #user-avatar { visibility: hidden; }
.auth-pending .profile-card, .auth-restoring .profile-card { visibility: visible; }
body.auth-pending #tool-tier-badge { visibility: visible; }
.auth-restoring #topbar-auth-guest,
.auth-restoring #topbar-upgrade-btn,
.auth-restoring #sidebar-upgrade-btn,
.auth-restoring #settings-user-email, .auth-restoring #settings-user-avatar,
.auth-restoring #settings-user-badge, .auth-restoring #settings-guest-actions,
.auth-restoring #settings-user-actions { visibility: hidden; }
.auth-pending .profile-card-row, .auth-restoring .profile-card-row { position: relative; }
.auth-pending .profile-card-row::before, .auth-restoring .profile-card-row::before {
  content: ""; position: absolute; inset: 4px 42px 4px 0; border-radius: 8px;
  background: linear-gradient(90deg, rgba(120, 130, 132, .08), rgba(120, 130, 132, .18), rgba(120, 130, 132, .08));
  background-size: 200% 100%; animation: auth-shell-shimmer 1.4s ease-in-out infinite;
}
@keyframes auth-shell-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .auth-pending .profile-card-row::before, .auth-restoring .profile-card-row::before { animation: none; }
}
.dynamic-workspace, .tool-desk-container, .home-tools-catalog, .home-cat-section { min-width: 0; max-width: 100%; }
.home-cat-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); }
[hidden] { display: none !important; }
@media (max-width: 900px) {
  .app-shell, .app-shell.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
  .organizer-grid.grid-mode { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .ai-active #view-ai-studio { height: calc(100dvh - 58px); }
  .ai-active .ai-studio-container { grid-template-columns: minmax(0, 1fr) !important; }
  .ai-active .ai-chat-card { border-radius: 8px; }
  .pdf-studio { grid-template-columns: 58px minmax(0, 1fr); height: calc(100dvh - 56px); }
  .studio-primary-ribbon, .studio-sub-ribbon { flex-wrap: wrap; }
}

.batch-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  padding: 4px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.batch-btn:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: #38bdf8;
  color: #38bdf8;
}

.batch-btn.batch-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #ef4444;
}

.batch-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s;
}

.batch-close-btn:hover {
  color: #f1f5f9;
}

/* Sub-navigation inside Organizer */
.organizer-subnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  margin-bottom: 10px;
}

.organizer-subnav-left,
.organizer-subnav-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.org-sub-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.org-sub-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.org-layout-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.org-layout-btn.active,
.org-layout-btn:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: #38bdf8;
  color: #38bdf8;
}

/* Grid & Strip Containers */
.organizer-grid {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.organizer-grid.grid-mode {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

/* Organizer Thumb Card */
.organizer-thumb-card {
  background: #1e293b;
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.organizer-thumb-card * {
  -webkit-user-select: none;
  user-select: none;
}

.organizer-thumb-card:hover {
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
}

.organizer-thumb-card.active {
  border-color: var(--accent, #ff4b26);
  box-shadow: 0 0 14px rgba(255, 75, 38, 0.35);
}

.organizer-thumb-card.selected {
  border-color: #38bdf8;
  background: #172554;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.3);
}

.organizer-thumb-card.dragging {
  opacity: 0.4;
  border-style: dashed;
  border-color: #38bdf8;
}

/* Card Header: Grip, Checkbox, Page Number */
.thumb-header {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(20px, 1fr) 18px auto;
  align-items: center;
  gap: 4px;
  padding: 0 2px;
}

.thumb-grip,
.organizer-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 13px;
  cursor: grab;
  padding: 0 2px;
  transition: color 0.15s;
  touch-action: none;
}

.thumb-grip:hover,
.organizer-drag-handle:hover {
  color: #38bdf8;
}

.thumb-checkbox-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.thumb-checkbox {
  cursor: pointer;
  width: 14px;
  height: 14px;
  accent-color: #38bdf8;
}

.thumb-page-num {
  font-size: 11px;
  font-weight: 700;
  color: #cbd5e1;
  justify-self: end;
  white-space: nowrap;
}

/* Preview Canvas / Image Wrap */
.thumb-preview-wrap {
  width: 100%;
  min-height: 110px;
  border-radius: 4px;
  overflow: hidden;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.thumb-rendered-img,
.thumb-rendered-canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
}

.thumb-skeleton {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #64748b;
  font-size: 11px;
}

.thumb-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: thumbSpin 0.7s linear infinite;
}

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

/* Card Footer: Metadata & Quick Hover Actions */
.thumb-footer {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 2px 2px 0 2px;
}

.organizer-grid.grid-mode .thumb-footer {
  flex-wrap: wrap;
  gap: 3px;
}

.organizer-grid.grid-mode .thumb-meta-text {
  flex: 1 1 100%;
}

.organizer-grid.grid-mode .thumb-quick-actions {
  width: 100%;
  justify-content: flex-end;
  opacity: 0.72;
}

.thumb-meta-text {
  font-size: 10px;
  color: #64748b;
  font-family: monospace;
}

.thumb-quick-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  opacity: 0.3;
  transition: opacity 0.15s;
}

.organizer-thumb-card:hover .thumb-quick-actions {
  opacity: 1;
}

.thumb-mini-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #94a3b8;
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.thumb-mini-btn:hover {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
}

.btn-del-quick:hover {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #ef4444 !important;
}

/* Drag Drop Indicators */
.organizer-drop-indicator {
  position: absolute;
  pointer-events: none;
  z-index: 100;
  transition: all 0.1s ease;
}

.organizer-drop-indicator.horizontal-indicator {
  height: 3px;
  background: #38bdf8;
  border-radius: 2px;
  box-shadow: 0 0 10px #38bdf8;
}

.organizer-drop-indicator.vertical-indicator {
  width: 3px;
  background: #38bdf8;
  border-radius: 2px;
  box-shadow: 0 0 10px #38bdf8;
}

/* Context Menu */
.page-context-menu {
  position: fixed;
  z-index: 99999;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.65);
  min-width: 210px;
  backdrop-filter: blur(12px);
  animation: fadeInCtx 0.15s ease-out;
}

@keyframes fadeInCtx {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.ctx-item {
  background: transparent;
  border: none;
  color: #e2e8f0;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctx-item:hover {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

.ctx-item.ctx-danger {
  color: #f87171;
}

.ctx-item.ctx-danger:hover {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

.ctx-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 4px 0;
}

/* Interactive Canvas Crop Overlay */
.studio-crop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  pointer-events: auto;
  user-select: none;
}

.crop-box {
  position: absolute;
  border: 2px dashed #38bdf8;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
  cursor: move;
  z-index: 101;
}

.crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid #0284c7;
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  z-index: 102;
}

.handle-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-n  { top: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.handle-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-e  { top: calc(50% - 5px); right: -5px; cursor: ew-resize; }
.handle-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.handle-s  { bottom: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.handle-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle-w  { top: calc(50% - 5px); left: -5px; cursor: ew-resize; }

.crop-dimension-pill {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.crop-floating-toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 12px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 200;
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.crop-tool-title {
  font-size: 13px;
  font-weight: 700;
  color: #f1f5f9;
}

.crop-scope-select {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #cbd5e1;
}

.crop-scope-select label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Phase 3 Modals (Resize, Split, Import) */
.page-modal-card {
  max-width: 520px;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.import-modal-card {
  max-width: 680px;
}

.form-group-row {
  margin-bottom: 14px;
}

.form-group-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 6px;
}

.toggle-pill-group,
.radio-pill-group {
  display: flex;
  gap: 8px;
}

.toggle-pill-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94a3b8;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-pill-btn.active,
.toggle-pill-btn:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: #38bdf8;
  color: #38bdf8;
}

.radio-pill-group label {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Split Mode Card Choices */
.split-mode-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.split-mode-card {
  background: #1e293b;
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.15s;
}

.split-mode-card:hover {
  border-color: rgba(56, 189, 248, 0.4);
}

.split-mode-card.active {
  border-color: #38bdf8;
  background: #172554;
}

.split-mode-info {
  flex: 1;
}

.split-mode-info strong {
  display: block;
  color: #f1f5f9;
  font-size: 13px;
}

/* Import Dropzone & Preview Grid */
.import-dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s;
  background: rgba(255, 255, 255, 0.02);
}

.import-dropzone:hover {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.05);
}

.import-thumb-item {
  background: #1e293b;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.import-thumb-item.selected {
  border-color: #38bdf8;
  background: #172554;
}

.import-thumb-item input[type="checkbox"] {
  position: absolute;
  top: 6px;
  left: 6px;
  cursor: pointer;
  accent-color: #38bdf8;
}

.import-thumb-item canvas {
  width: 100%;
  height: auto;
  border-radius: 3px;
  background: #fff;
}

.import-thumb-item span {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
}

/* =============================================================================
   Phase 4: Compression, Repair & OCR Engine Styles
   ============================================================================= */

.compress-modal-card,
.ocr-modal-card,
.repair-modal-card {
  max-width: 540px;
  background: #0d1416;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.compress-analysis-box {
  background: rgba(35, 49, 52, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px;
}

.compress-presets-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.progress-bar-wrap {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

#ocr-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #2563eb);
  transition: width 0.3s ease;
}

#repair-report-box {
  background: rgba(35, 49, 52, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
}

/* =============================================================================
   Phase 5: Professional Conversion Center Engine Styles
   ============================================================================= */

.convert-modal-card {
  width: min(640px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  min-width: 0;
  box-sizing: border-box;
  background: #0e1518;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.6);
}

.convert-direction-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 8px;
}

.convert-dir-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.convert-dir-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #f1f5f9;
}

.convert-dir-btn.active {
  background: #2563eb;
  color: #ffffff;
  border-color: #3b82f6;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.convert-format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(110px, 100%), 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 2px 2px 8px 2px;
}

.convert-option-row {
  flex-wrap: wrap;
}
.convert-option-row label {
  min-width: 0;
}
.convert-option-row select,
.convert-option-row input {
  max-width: 100%;
  min-width: 0;
}

@media (max-width: 640px) {
  #convert-modal.modal-backdrop {
    padding: max(8px, env(safe-area-inset-top, 0px)) 8px max(8px, env(safe-area-inset-bottom, 0px));
    place-items: center;
  }
  #convert-modal .convert-modal-card {
    width: min(640px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    min-width: 0;
    padding: 14px;
  }
  #convert-modal .modal-header > div { min-width: 0; overflow-wrap: anywhere; }
  #convert-modal .modal-header span { display: block; }
  #convert-modal .convert-direction-tabs { min-width: 0; }
  #convert-modal .convert-dir-btn { flex: 1 1 0; min-width: 0; padding: 8px 6px; white-space: normal; }
  #convert-modal .convert-source-box,
  #convert-modal .convert-source-box > div:first-child { min-width: 0; }
  #convert-modal #convert-source-filename { max-width: 38vw; overflow-wrap: anywhere; }
  #convert-modal .convert-option-row { gap: 8px !important; }
  #convert-modal .convert-option-row label { margin-left: 0 !important; min-width: 0 !important; flex: 1 1 100%; }
  #convert-modal .convert-option-row select,
  #convert-modal .convert-option-row input { flex: 1 1 140px; width: 100% !important; }
  #convert-modal .format-card { min-width: 0; overflow-wrap: anywhere; }
  #convert-modal .format-desc { overflow-wrap: anywhere; }
}

.format-card {
  background: rgba(23, 33, 36, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.format-card:hover {
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(35, 49, 52, 0.8);
  transform: translateY(-1px);
}

.format-card.selected {
  border-color: #38bdf8;
  background: rgba(37, 99, 235, 0.18);
  box-shadow: 0 0 0 1px #38bdf8, 0 4px 12px rgba(56, 189, 248, 0.2);
}

.format-card.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.8);
}

.format-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.format-icon {
  font-size: 18px;
}

.format-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge-full {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.badge-limited {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-unavail {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.format-name {
  font-size: 11px;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.format-desc {
  font-size: 9.5px;
  color: #94a3b8;
  line-height: 1.2;
}

/* =============================================================================
   Phase 6: PDF Forms, Signing & Security Engine Styles
   ============================================================================= */

.forms-modal-card {
  max-width: 620px;
  background: #0e1518;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
}

.sign-modal-card {
  max-width: 580px;
  background: #0e1518;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
}

.security-modal-card {
  max-width: 600px;
  background: #0e1518;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
}

.form-field-edit-row {
  transition: all 0.15s ease;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--studio-border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
}

.form-field-edit-row:hover {
  background: rgba(35, 49, 52, 0.85);
  border-color: rgba(56, 189, 248, 0.4);
}

.form-field-edit-row input[type="text"],
.form-field-edit-row select {
  width: 100%;
  background: #172023;
  border: 1px solid var(--studio-border);
  color: #f1f5f9;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}

.form-field-edit-row input[type="text"]:focus,
.form-field-edit-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Signature Verification Badges */
.badge-valid {
  background: rgba(16, 185, 129, 0.2) !important;
  color: #34d399 !important;
  border: 1px solid rgba(16, 185, 129, 0.4) !important;
}

.badge-tampered {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #f87171 !important;
  border: 1px solid rgba(239, 68, 68, 0.4) !important;
}

.badge-invalid {
  background: rgba(245, 158, 11, 0.2) !important;
  color: #fbbf24 !important;
  border: 1px solid rgba(245, 158, 11, 0.4) !important;
}

/* Security Audit styling */
.sec-audit-box {
  background: rgba(35, 49, 52, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
}

.sec-audit-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sec-audit-item:last-child {
  border-bottom: none;
}

/* ==========================================================================
   Tool Desk directory styling
   ========================================================================== */

.home-container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 36px 32px 72px 32px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  animation: fadeInHome 0.25s ease-out;
}

@keyframes fadeInHome {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.home-hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px 20px 16px;
  gap: 16px;
}

.home-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 75, 38, 0.1);
  color: var(--accent);
  border: 1px solid rgba(255, 75, 38, 0.25);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.home-hero-badge .badge-dot {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}

.home-hero-title {
  font-size: clamp(28px, 4.2vw, 44px);
  font-weight: 800;
  letter-spacing: -0.035em;
  color: var(--text-main);
  max-width: 840px;
  line-height: 1.15;
}

.home-hero-subtitle {
  font-size: clamp(15px, 2vw, 17px);
  color: var(--text-muted);
  max-width: 660px;
  line-height: 1.55;
}

.home-search-bar {
  width: 100%;
  max-width: 600px;
  margin-top: 10px;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-panel);
  border: 2px solid var(--border-light);
  border-radius: 14px;
  padding: 10px 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.search-icon-svg {
  color: var(--text-dim);
  flex-shrink: 0;
}

.search-input-wrapper input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 15px;
  font-family: var(--font-sans);
  color: var(--text-main);
  width: 100%;
  margin-left: 10px;
}

.search-input-wrapper input::placeholder {
  color: var(--text-dim);
}

.search-clear-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.15s;
}

.search-clear-btn:hover {
  color: var(--text-main);
}

.home-filter-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.filter-pill {
  border: 1px solid var(--border-light);
  background: var(--bg-panel);
  color: var(--text-muted);
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
}

.filter-pill:hover {
  border-color: var(--text-dim);
  color: var(--text-main);
}

.filter-pill.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 3px 12px var(--accent-glow);
}

.home-search-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.home-search-meta .link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
}

.home-tools-catalog {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.home-cat-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.home-cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

.home-cat-title-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.home-cat-title {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.home-cat-count {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}

.home-cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
}

.home-tool-card {
  color: inherit;
  text-decoration: none;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  cursor: pointer;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}

.home-tool-card:hover, .home-tool-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-subtle);
}

.home-tool-card:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.home-tool-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.home-tool-body {
  display: flex;
  flex-direction: column;
  width: 100%;
  flex-grow: 1;
}

.home-tool-title {
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text-main);
  margin-bottom: 6px;
}

.home-tool-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 16px;
  flex-grow: 1;
}

.home-tool-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}

.home-status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.home-status-badge.ready {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.home-status-badge.prereq {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.home-tool-arrow {
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 700;
  transition: transform 0.18s, color 0.18s;
}

.home-tool-card:hover .home-tool-arrow {
  color: var(--accent);
  transform: translateX(3px);
}

.home-no-results {
  text-align: center;
  padding: 48px 24px;
  background: var(--bg-panel);
  border: 1px dashed var(--border-light);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.no-results-icon {
  font-size: 36px;
}

.tool-desk-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 16px 0;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 18px;
}

.btn-back-home {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-back-home:hover {
  background: var(--bg-panel-alt);
  border-color: var(--border-subtle);
  transform: translateX(-2px);
}

.tool-desk-breadcrumb {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   SEO education surface (server-rendered on every public tool URL)
   -------------------------------------------------------------------------- */
.seo-content {
  width: 100%;
  margin: 8px auto 0;
  border-top: 1px solid var(--border-light);
  background: linear-gradient(180deg, transparent 0%, rgba(255, 75, 38, 0.025) 100%);
}

.seo-content-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px clamp(20px, 3vw, 44px) 56px;
}

.seo-eyebrow {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.seo-content h2 {
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.08;
  letter-spacing: -0.035em;
  margin-bottom: 14px;
}

.seo-content h3 {
  font-size: 16px;
  line-height: 1.25;
  margin-bottom: 8px;
}

.seo-lede {
  max-width: 760px;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.65;
  margin-bottom: 28px;
}

.seo-howto-grid,
.seo-proof-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.seo-howto-step,
.seo-proof-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.seo-howto-step > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-subtle);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 14px;
}

.seo-howto-step p,
.seo-proof-card p,
.seo-faq-item p {
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.6;
}

.seo-comparison {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 28px;
  overflow-x: auto;
}

.seo-comparison-table {
  min-width: 620px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  overflow: hidden;
}

.seo-comparison-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 13px;
}

.seo-comparison-row:first-child { border-top: 0; }
.seo-comparison-head { background: var(--bg-panel-alt); color: var(--text-main); font-weight: 700; }
.seo-comparison-row strong { color: var(--success); }

.seo-faq {
  margin-bottom: 26px;
}

.seo-faq-item {
  border-top: 1px solid var(--border-light);
  padding: 14px 0;
}

.seo-faq-item:last-child { border-bottom: 1px solid var(--border-light); }

.seo-faq-item summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  list-style-position: inside;
  padding: 4px 0;
}

.seo-faq-item p { padding: 10px 24px 0; }

.seo-related {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}

.seo-related-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  border: 1px solid rgba(255, 75, 38, 0.25);
  border-radius: 999px;
  padding: 8px 12px;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.seo-related-link:hover,
.seo-related-link:focus-visible {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

@media (max-width: 768px) {
  .home-container {
    padding: 20px 16px 48px 16px;
    gap: 24px;
  }
  .home-hero {
    padding: 16px 8px;
  }
  .home-cat-grid {
    grid-template-columns: 1fr;
  }
  .home-filter-pills {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
}

/* Touch-first layout overrides.  The drawer is the primary navigation on
   narrow screens; tool cards become a horizontally swipeable rail. */
@media (max-width: 900px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    display: block !important;
    grid-template-columns: none !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
  }

  .main-area {
    display: block !important;
    grid-column: auto !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
  }

  .sidebar {
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  .mobile-menu-btn,
  .collapse-btn,
  .sidebar-search-btn,
  .sidebar-settings-gear-btn,
  .topbar .icon-btn,
  .topbar-action-btn,
  .tab-pill,
  .btn-primary-action,
  .btn-back-home,
  .nav-category-tab,
  .sidebar-tool-item,
  .filter-pill,
  .browse-link {
    min-height: 48px;
  }

  .collapse-btn,
  .sidebar-settings-gear-btn { min-width: 48px; }

  .topbar {
    min-height: 64px;
    height: auto;
    gap: 10px;
  }

  .topbar-left,
  .topbar-right {
    min-width: 0;
  }

  .breadcrumb-trail {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .workspace-tabs {
    display: none;
  }

  .dynamic-workspace {
    padding: 20px 16px 42px;
  }

  .tool-hero-card {
    flex-direction: column;
    gap: 16px;
    padding: 20px;
  }

  .tool-hero-actions { width: 100%; }
  .tool-hero-actions .topbar-action-btn { width: 100%; justify-content: center; }

  .action-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .btn-primary-action { justify-content: center; }
  .secure-assurance { justify-content: center; text-align: center; }

  .home-cat-grid {
    display: flex;
    overflow-x: auto;
    gap: 12px;
    padding: 2px 2px 10px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .home-tool-card {
    flex: 0 0 min(82vw, 310px);
    scroll-snap-align: start;
  }

  .seo-content-inner { padding: 36px 0 42px; }
  .seo-howto-grid,
  .seo-proof-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar {
    padding: 8px 12px;
    justify-content: flex-start;
  }
  .topbar-left {
    flex: 1;
    min-width: 0;
  }
  /* Keep a direct sign-in entry point on phones; the menu remains for tools. */
  .topbar-right {
    display: flex !important;
    flex: 0 0 auto;
    gap: 0;
    margin-left: auto;
  }
  .topbar-right > :not(#topbar-auth-guest):not(#topbar-auth-user):not(#install-app-btn) { display: none !important; }
  #topbar-auth-guest:not([hidden]),
  #topbar-auth-user:not([hidden]) { display: inline-flex !important; }
  #topbar-register-btn { display: none !important; }
  #topbar-signin-btn { min-height: 44px; padding: 7px 10px; white-space: nowrap; }
  #install-app-btn { min-height: 44px; padding: 7px 10px; white-space: nowrap; font-size: 11px; }
  #topbar-user-profile-btn { max-width: 96px; min-height: 44px; padding-inline: 8px; }
  #topbar-username { max-width: 36px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .breadcrumb-trail { gap: 5px; font-size: 12px; }
  .dynamic-workspace { padding-inline: 12px; min-width: 0; }
  .tool-desk-nav-bar .tool-desk-breadcrumb { display: none; }
  .tool-hero-card,
  .dropzone,
  .options-panel,
  .action-bar,
  .result-card {
    width: 100%;
    min-width: 0;
  }
  .tool-hero-card { overflow: hidden; }
  .tool-hero-title-group { width: 100%; }
  .home-container { padding-inline: 0; }
  .dropzone { padding: 22px 14px; }
  .drop-icon-circle { width: 48px; height: 48px; margin-bottom: 10px; font-size: 20px; }
  .dropzone p { display: block; line-height: 1.5; }
  .dropzone .browse-link {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .dropzone-options { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
  .dropzone-option { justify-content: center; min-height: 36px; padding-inline: 8px; }
  .dropzone h2 { font-size: 16px; }
  .seo-content-inner { padding-inline: 2px; }
  .seo-comparison { padding: 16px; margin-inline: 0; }
}

@media (max-width: 600px) {
  .tool-desk-nav-bar {
    min-height: 0;
    margin-bottom: 10px;
    padding-block: 6px 8px;
  }
  .tool-hero-card { padding: 14px !important; }
  .tool-hero-actions { display: none !important; }
  .dropzone p { font-size: 12px; }
  .dropzone small { font-size: 11px; line-height: 1.4; }
  #home-filter-pills {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    width: 100%;
    max-width: 100%;
    gap: 8px;
    overflow: visible;
    padding: 2px 2px 10px;
  }
  #home-filter-pills [role="tab"] {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
  }
  .studio-active .studio-primary-ribbon > .studio-mode-switcher { order: 1; }
  .studio-active .studio-primary-ribbon > .studio-dropdown-wrapper { order: 2; }
  .studio-active .studio-primary-ribbon > .studio-tool-group[title="Open Document"] { order: 3; }
  .studio-active #studio-close-doc-btn { display: none; }
  .studio-active .studio-primary-ribbon > .studio-tool-group[title="Page Navigation"] { order: 4; }
  .studio-active .studio-primary-ribbon > .studio-tool-group[title="Zoom Controls"] { order: 5; }
  .studio-active .studio-primary-ribbon > .studio-tool-group[title="History"] { order: 6; }
  .studio-active .studio-primary-ribbon > .studio-export-group { order: 7; }
  .studio-active .studio-primary-ribbon > .studio-divider { display: none; }
  .topbar {
    padding: 6px 12px !important;
    min-height: 56px;
    height: auto !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 6px 8px !important;
  }
  .breadcrumb-trail {
    order: 3;
    flex: 1 0 100%;
    max-width: 100% !important;
    font-size: 11.5px !important;
    gap: 4px !important;
    white-space: nowrap;
    overflow: hidden;
  }
  .breadcrumb-trail > b,
  .breadcrumb-trail > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .workspace-tabs { display: none !important; }
  .topbar-left {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 6px !important;
    min-width: 0 !important;
  }
  .topbar-right {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    flex-shrink: 0 !important;
  }
  .topbar-upgrade-pill,
  #topbar-cloud-btn,
  .btn-topbar-register {
    display: none !important;
  }
  .topbar-auth-group:not([hidden]) {
    display: inline-flex !important;
    gap: 4px !important;
  }
  .btn-topbar-signin,
  .topbar-user-pill {
    min-height: 36px !important;
    padding: 6px 10px !important;
    font-size: 11px !important;
    white-space: nowrap !important;
  }
  .topbar-user-pill #topbar-username { display: none !important; }
  .topbar-right .icon-btn { min-height: 36px !important; min-width: 36px !important; }
  .tool-desk-nav-bar .tool-desk-breadcrumb { display: none !important; }
  .tool-hero-card,
  .dropzone,
  .options-panel,
  .action-bar,
  .result-card { min-width: 0 !important; width: 100% !important; }
  .tool-hero-title-group { width: 100% !important; }
  .seo-comparison-table { min-width: 0 !important; width: 100% !important; }
}

@media (max-width: 760px) {
  .settings-modal-card {
    width: 96vw !important;
    height: 88vh;
    min-height: 0;
  }
  .settings-layout { flex-direction: column; overflow: auto; }
  .settings-modal-card .settings-tabs {
    flex: 0 0 auto;
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 12px;
    border-right: 0 !important;
    border-bottom: 1px solid var(--border-light) !important;
  }
  .settings-modal-card .settings-tab-btn { min-width: 190px; min-height: 54px; }
  .settings-modal-card .settings-content { padding: 20px 16px; overflow: visible; }
  .settings-modal-card > .modal-header { padding: 18px 20px; }
  .settings-privacy-toggle-row { align-items: flex-start; }
}

/* --------------------------------------------------------------------------
   Unified modal theme contract
   All modal families must follow the active workspace theme. These rules are
   intentionally last so legacy engine-specific selectors cannot reintroduce
   pitch-black panels or low-contrast controls in Light Paper mode.
   -------------------------------------------------------------------------- */
body.light-mode .modal-card,
body.light-mode .page-modal-card,
body.light-mode .command-modal {
  --bg-panel: #ffffff;
  --bg-panel-alt: #f8faf9;
  --border-light: #e2eae4;
  --border-subtle: #d1ddd5;
  --text-main: #142023;
  --text-muted: #5e6f72;
  --text-dim: #8fa0a3;
  --accent-subtle: #fff1ed;
  background: #ffffff !important;
  border: 1px solid #e2eae4 !important;
  color: #142023 !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.15) !important;
}

body.light-mode .modal-header h2,
body.light-mode .modal-header h3,
body.light-mode .modal-card h2,
body.light-mode .modal-card h3,
body.light-mode .modal-card h4,
body.light-mode .modal-card h5,
body.light-mode .modal-card strong,
body.light-mode .command-modal strong {
  color: #142023 !important;
}

body.light-mode .modal-card p,
body.light-mode .modal-card small,
body.light-mode .modal-card label,
body.light-mode .command-modal small,
body.light-mode .command-group-title {
  color: #5e6f72 !important;
}

body.light-mode .modal-card input,
body.light-mode .modal-card select,
body.light-mode .modal-card textarea,
body.light-mode .page-modal-card input,
body.light-mode .page-modal-card select,
body.light-mode .page-modal-card textarea,
body.light-mode .command-modal input {
  background: #f8faf9 !important;
  border: 1px solid #d1ddd5 !important;
  color: #142023 !important;
}

body.light-mode .modal-card input::placeholder,
body.light-mode .modal-card textarea::placeholder,
body.light-mode .command-modal input::placeholder {
  color: #8fa0a3 !important;
}

body.light-mode .modal-card .file-row-card,
body.light-mode .pricing-tier-card,
body.light-mode .split-mode-card,
body.light-mode .import-thumb-item,
body.light-mode .format-card,
body.light-mode .form-field-edit-row {
  background: #f8faf9 !important;
  border-color: #e2eae4 !important;
  color: #142023 !important;
}

body.light-mode .pricing-tier-card.popular,
body.light-mode .pricing-tier-card.developer {
  background: #f8faf9 !important;
}

body.light-mode .split-mode-card *,
body.light-mode .format-card *,
body.light-mode .form-field-edit-row * {
  color: #142023;
}

body.light-mode .pricing-tier-card h3,
body.light-mode .pricing-tier-card h4,
body.light-mode .pricing-tier-card p,
body.light-mode .pricing-tier-card li,
body.light-mode .pricing-tier-card li strong,
body.light-mode .pricing-tier-card .tier-features-list li {
  color: #142023 !important;
}

body.light-mode .pricing-tier-card .tier-subscribe-btn,
body.light-mode .pricing-tier-card .tier-subscribe-btn * {
  color: #ffffff !important;
}

body.light-mode .format-desc,
body.light-mode .format-name,
body.light-mode .split-mode-info strong,
body.light-mode .command-item,
body.light-mode .command-item-left strong {
  color: #142023 !important;
}

body.light-mode .command-search-header,
body.light-mode .extraction-modal-header,
body.light-mode .modal-footer,
body.light-mode .modal-body,
body.light-mode .editor-sig-tabs {
  border-color: #e2eae4 !important;
}

body.light-mode .command-item {
  color: #142023 !important;
}

body.light-mode .command-item:hover,
body.light-mode .command-item.focused {
  background: #fff1ed !important;
}

body.light-mode .compress-analysis-box,
body.light-mode .import-preview-area,
body.light-mode .sec-status-hero,
body.light-mode #ocr-progress-box,
body.light-mode #repair-report-box,
body.light-mode .modal-card [style*="background: rgba(35, 49, 52"],
body.light-mode .modal-card [style*="background: rgba(30, 41, 59"] {
  background: #f4f6f3 !important;
  border-color: #e2eae4 !important;
  color: #142023 !important;
}

body.light-mode .modal-card [style*="color: #fff"],
body.light-mode .modal-card [style*="color:#fff"],
body.light-mode .modal-card [style*="color: #f9fafb"],
body.light-mode .modal-card [style*="color:#f9fafb"] {
  color: #142023 !important;
}

body.light-mode #compress-stat-opp,
body.light-mode #ocr-scope-hint,
body.light-mode #ocr-progress-pct {
  color: #0369a1 !important;
}

body.light-mode #repair-report-msg,
body.light-mode #compress-analysis-stats,
body.light-mode #convert-result-stats,
body.light-mode #convert-format-selection-area > label {
  color: #1e293b !important;
}

body.light-mode #convert-options-area,
body.light-mode #convert-source-box {
  background: #f4f6f3 !important;
  border-color: #cbd5e1 !important;
  color: #142023 !important;
}

body.light-mode #convert-options-area label,
body.light-mode #convert-result-time {
  color: #475569 !important;
}

body.light-mode #convert-source-filename,
body.light-mode #convert-result-name {
  color: #0f172a !important;
}

body.light-mode .convert-dir-btn:not(.active) {
  background: #f1f5f9 !important;
  border-color: #cbd5e1 !important;
  color: #334155 !important;
}

body.light-mode .convert-dir-btn:not(.active):hover {
  background: #e2e8f0 !important;
  color: #0f172a !important;
}

body.light-mode #compress-error-box {
  background: #fef2f2 !important;
  color: #991b1b !important;
  border-color: #dc2626 !important;
}

body.light-mode #repair-report-badge {
  color: #065f46 !important;
}

body.light-mode .thumb-mini-btn {
  color: #334155 !important;
}

body.light-mode #settings-user-badge,
body.light-mode .settings-card .profile-badge {
  color: #475569;
}

body.dark-mode .modal-card,
body.dark-mode .page-modal-card,
body.dark-mode .command-modal {
  --bg-panel: #111827;
  --bg-panel-alt: #1f2937;
  --border-light: #374151;
  --border-subtle: #4b5563;
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  background: #111827 !important;
  color: #f9fafb !important;
}

body.dark-mode .command-modal input,
body.dark-mode .modal-card input,
body.dark-mode .modal-card select,
body.dark-mode .modal-card textarea {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

body.dark-mode .pricing-tier-card,
body.dark-mode .split-mode-card,
body.dark-mode .import-thumb-item,
body.dark-mode .format-card,
body.dark-mode .form-field-edit-row {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

body.dark-mode .compress-analysis-box,
body.dark-mode .import-preview-area,
body.dark-mode .sec-status-hero,
body.dark-mode #ocr-progress-box,
body.dark-mode #repair-report-box {
  background: #172023 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

/* =============================================================================
   Phase 6 Fix: Field Dimension Grid
   ============================================================================= */

.field-dimension-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.dimension-cell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dimension-cell small {
  color: var(--text-muted);
  font-size: 11px;
}

.dimension-input {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  padding: 6px 8px !important;
}

/* =============================================================================
   VIEW 6: Dedicated Native Desktop & Mobile Apps Hub
   ============================================================================= */

.download-full-view {
  background: var(--bg-app);
  color: var(--text-main);
  padding-bottom: 60px;
}

.download-badge-fast {
  font-size: 11px;
  font-weight: 700;
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 999px;
  padding: 4px 10px;
}

.download-content-wrapper {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.download-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.download-actions a {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.download-hero-banner {
  background: linear-gradient(135deg, rgba(255, 75, 38, 0.08), rgba(20, 32, 35, 0.6));
  border: 1px solid rgba(255, 75, 38, 0.2);
  border-radius: 12px;
  padding: 24px 28px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.download-hero-icon {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: rgba(255, 75, 38, 0.12);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.download-hero-text h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 6px 0;
}

.download-hero-text p {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.waitlist-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 24px 28px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.waitlist-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.waitlist-card-header h4 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 4px 0;
  color: var(--text-main);
}

.waitlist-card-header p {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 6px 0 0 0;
  display: block;
  overflow: visible;
}

.waitlist-stats-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 75, 38, 0.1);
  border: 1px solid rgba(255, 75, 38, 0.2);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.waitlist-form-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.waitlist-input-group {
  display: flex;
  gap: 10px;
  flex: 1;
  align-items: stretch;
}

.waitlist-select {
  flex: 0 0 250px;
  height: 44px !important;
  min-height: 44px !important;
  box-sizing: border-box !important;
  padding: 0 14px !important;
  font-size: 13.5px !important;
  line-height: 42px !important;
  border-radius: 8px !important;
  background-color: var(--bg-panel-alt, #1f2937) !important;
  color: var(--text-main, #f9fafb) !important;
  border: 1px solid var(--border-light, #374151) !important;
  outline: none;
}

.waitlist-select option {
  padding: 10px 14px !important;
  font-size: 13.5px !important;
  line-height: 1.5 !important;
  min-height: 36px !important;
}

.waitlist-email-input {
  flex: 1;
  height: 44px !important;
  min-height: 44px !important;
  box-sizing: border-box !important;
  padding: 0 16px !important;
  font-size: 13.5px !important;
  line-height: 42px !important;
  border-radius: 8px !important;
  background-color: var(--bg-panel-alt, #1f2937) !important;
  color: var(--text-main, #f9fafb) !important;
  border: 1px solid var(--border-light, #374151) !important;
  outline: none;
  transition: border-color 0.15s ease;
}

.waitlist-email-input:focus,
.waitlist-select:focus {
  border-color: var(--accent) !important;
}

body:not(.dark-mode) .waitlist-select,
body:not(.dark-mode) .waitlist-email-input {
  background-color: #ffffff !important;
  color: #142023 !important;
  border-color: #d1d5db !important;
}

.waitlist-submit-btn {
  height: 44px !important;
  min-height: 44px !important;
  box-sizing: border-box !important;
  padding: 0 22px !important;
  font-size: 13.5px !important;
  font-weight: 700 !important;
  border-radius: 8px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  white-space: nowrap !important;
}

.waitlist-success-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 10px;
  padding: 16px 20px;
}

.waitlist-success-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.waitlist-success-banner strong {
  font-size: 14px;
  color: #059669;
  display: block;
  margin-bottom: 4px;
}

.waitlist-success-banner p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.45;
}

.platform-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 18px;
}

.platform-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: all 0.2s ease;
}

.platform-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 75, 38, 0.35);
  box-shadow: var(--shadow-md);
}

.platform-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.platform-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.win-icon { background: rgba(0, 164, 239, 0.12); color: #00a4ef; }
.mac-icon { background: rgba(160, 160, 160, 0.15); color: var(--text-main); }
.linux-icon { background: rgba(233, 84, 32, 0.12); color: #e95420; }
.android-icon { background: rgba(61, 220, 132, 0.12); color: #3ddc84; }
.ios-icon { background: rgba(10, 132, 255, 0.12); color: #0a84ff; }

.platform-card-header h4 {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 2px 0;
  color: var(--text-main);
}

.platform-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.platform-features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.platform-features li {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.platform-features li::before {
  content: '✓';
  color: #10b981;
  font-weight: 700;
  font-size: 11px;
}

.platform-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}

.platform-status-tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
}

.platform-status-tag.ready {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.platform-status-tag.testing {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.btn-platform-join {
  font-size: 11.5px;
  padding: 4px 10px;
}

/* --------------------------------------------------------------------------
   Mobile Workspace Bottom Navigation Bar
   -------------------------------------------------------------------------- */
.mobile-workspace-bar {
  display: none;
}

@media (max-width: 900px) {
  /* Keep rich AI follow-up actions usable by touch on phones and tablets. */
  .ai-result-actions > * { min-height: 44px; box-sizing: border-box; }

  /* The result auto-scroll aligns action cards above the fixed mobile dock. */
  #result { scroll-margin-bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }

  .mobile-workspace-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 62px;
    background: rgba(18, 26, 28, 0.96);
    backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body.light-mode .mobile-workspace-bar {
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid #dfe7e1;
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    gap: 4px;
    cursor: pointer;
    padding: 6px 12px;
    transition: color 0.15s ease;
  }

  .mobile-nav-btn svg {
    transition: transform 0.15s ease;
  }

  .mobile-nav-btn.active {
    color: var(--accent);
    font-weight: 700;
  }

  .mobile-nav-btn.active svg {
    transform: translateY(-2px);
  }

  .mobile-view-pill { flex: 0 1 auto; max-width: min(34vw, 140px); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  @media (min-width: 601px) and (max-width: 900px) {
    .topbar { height: auto !important; min-height: 60px; flex-wrap: wrap !important; }
    .topbar-left { min-width: 0 !important; }
    .breadcrumb-trail {
      display: flex !important;
      flex: 1 0 100% !important;
      flex-wrap: wrap !important;
      min-width: 0 !important;
      font-size: 12px !important;
      gap: 4px 6px !important;
      white-space: normal !important;
      overflow: visible !important;
      text-overflow: clip !important;
    }
    .mobile-view-pill { display: none !important; }
  }

  /* Keep the submit action in the form flow so it cannot cover tool controls. */
  body:not(.studio-active):not(.ai-active) .action-bar {
    position: static;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  body:not(.studio-active):not(.ai-active) #run-button {
    position: static;
    inset: auto;
    z-index: auto;
    width: 100%;
    max-width: 100%;
  }

  body:not(.studio-active):not(.ai-active) .secure-assurance {
    display: none;
  }

  .dynamic-workspace,
  .main-content {
    padding-bottom: 74px !important;
  }

  /* Leave scroll space for the fixed workspace navigation. */
  body:not(.studio-active):not(.ai-active) .main-area {
    padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

  #app-shell.ai-active .main-area,
  .ai-studio-main,
  .workspace-inline-panel {
    padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

  .toast-notice {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(168px + env(safe-area-inset-bottom, 0px));
    z-index: 3100;
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
    justify-content: center;
  }
}

/* Keep intermediate breadcrumb ancestors legible; only truncate the active leaf label if space tightens. */
.breadcrumb-trail > span:not(:last-child),
.breadcrumb-trail .crumb-sep {
  flex: 0 0 auto !important;
  flex-shrink: 0 !important;
  max-width: none !important;
  overflow: visible !important;
  text-overflow: clip !important;
}
.breadcrumb-trail > b,
.breadcrumb-trail > span:last-child {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Keep the full workspace navigation inside the column left by the desktop sidebar. */
.mobile-brand { display: none; }

@media (min-width: 1461px) and (max-width: 1620px) {
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar-left { flex: 1 1 auto; min-width: 0; }
  .breadcrumb-trail { max-width: none; flex: 1 1 auto; min-width: 0; }
  .workspace-tabs { position: static; transform: none; flex: 0 1 auto; min-width: 0; }
  .tab-pill { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  .topbar-right { gap: 6px; flex-shrink: 0; }
  .topbar-upgrade-pill { padding: 6px 10px; white-space: nowrap; }
  .topbar-user-pill { max-width: 150px; }
}

@media (min-width: 901px) and (max-width: 1460px) {
  .topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-areas: "context actions" "views views" !important;
    grid-template-rows: auto auto !important;
    align-content: start !important;
    align-items: center !important;
    justify-content: initial !important;
    row-gap: 10px !important;
    column-gap: 12px !important;
    height: auto !important;
    min-height: 82px !important;
    padding: 10px 14px !important;
  }

  .topbar-left {
    grid-area: context;
    max-width: 100%;
    min-width: 0;
    overflow: visible;
  }

  .breadcrumb-trail {
    max-width: 100%;
    flex-wrap: wrap;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .breadcrumb-trail > b,
  .breadcrumb-trail > span:last-child {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
  }

  .workspace-tabs {
    position: static !important;
    transform: none !important;
    margin-top: 2px;
    grid-area: views;
    justify-self: center;
    width: max-content;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }

  .tab-pill { flex: 0 0 auto; white-space: nowrap; }

  .topbar-right {
    grid-area: actions;
    min-width: 0;
    max-width: 100%;
    flex-shrink: 1;
    gap: 6px;
  }

  .topbar-upgrade-pill { padding: 6px 10px; white-space: nowrap; }
  .studio-active .topbar,
  .ai-active .topbar {
    display: grid !important;
    height: auto !important;
  }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .topbar-upgrade-pill { display: none; }
}

/* Make the native app waitlist form fit the narrower content column beside the desktop sidebar. */
@media (min-width: 901px) and (max-width: 1200px) {
  .waitlist-form-row {
    align-items: stretch;
    flex-direction: column;
  }

  .waitlist-input-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
  }

  .waitlist-select,
  .waitlist-email-input { width: 100%; min-width: 0; }
  .waitlist-select { flex-basis: auto; }
  .waitlist-submit-btn { width: 100%; }
}

/* Phone header keeps the product identity and cloud action discoverable. */
@media (max-width: 900px) {
  .mobile-brand {
    display: inline-flex;
    align-items: center;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--text-main);
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.04em;
    cursor: pointer;
  }

  .mobile-brand span { color: var(--accent); }
  .topbar-left { gap: 8px; }
  .mobile-menu-btn { width: 44px; min-width: 44px; height: 44px; }

  .mobile-workspace-bar { height: 66px; }

  .mobile-nav-btn {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    padding: 4px 2px;
    font-size: 10px;
  }

  .mobile-nav-btn span {
    max-width: 100%;
    line-height: 1.05;
    text-align: center;
  }

  .dynamic-workspace,
  .main-content,
  .workspace-page,
  .full-page-view,
  #view-desk,
  #view-pricing,
  .pricing-tiers-section { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important; }
  body:not(.studio-active):not(.ai-active) .action-bar { margin-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  .modal-backdrop { z-index: 3600 !important; }
  .modal-close,
  .close-modal-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    flex: 0 0 44px !important;
    position: relative;
    z-index: 5;
  }
  .cookie-consent-banner {
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    inset-inline: 12px;
    max-width: none;
    flex-wrap: wrap;
  }
}

@media (max-width: 600px) {
  #topbar-cloud-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
  }

  #topbar-cloud-btn span { display: none; }
  #topbar-search-btn { width: 44px; min-width: 44px; min-height: 44px; }
  .btn-topbar-signin,
  .topbar-user-pill { min-height: 44px !important; }

  .download-full-view {
    box-sizing: border-box;
    padding: 14px 10px !important;
  }

  .download-full-view .view-header-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    padding: 0 2px 12px;
  }

  .download-full-view .view-header-title {
    order: 2;
    flex: 1 1 100%;
    min-width: 0;
  }

  .download-full-view .view-header-title h2 {
    font-size: 19px;
    line-height: 1.25;
  }

  .download-full-view .view-header-bar > div:last-child { order: 3; }

  .download-content-wrapper {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px 2px;
    gap: 14px;
  }

  .download-hero-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 18px;
  }

  .download-hero-text h3 { font-size: 18px; line-height: 1.3; }

  .waitlist-card { padding: 18px; gap: 12px; }

  .waitlist-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .waitlist-card-header > div:first-child { min-width: 0; }
  .waitlist-stats-pill { max-width: 100%; white-space: normal; line-height: 1.25; }
  .platform-cards-grid { grid-template-columns: minmax(0, 1fr); }
  .platform-footer { flex-wrap: wrap; gap: 10px; }
}





/* Final viewport constraints: keep AI controls reachable on phones and tablets. */
@media (max-width: 900px) {
  .app-shell.ai-active { height: 100dvh !important; min-height: 0 !important; overflow: hidden !important; }
  .ai-active .main-area { display: flex !important; flex-direction: column !important; height: 100dvh !important; min-height: 0 !important; overflow: hidden !important; }
  .ai-active .topbar { flex: 0 0 56px; }
  .ai-active #view-ai-studio { position: fixed; inset: 56px 0 60px; height: auto !important; min-height: 0 !important; padding: 8px 10px; overflow: hidden; display: flex; flex-direction: column; }
  .ai-active .ai-studio-container { flex: 1 1 auto; min-height: 0 !important; height: 0; display: flex; }
  .ai-active .ai-chat-card { flex: 1 1 auto; min-height: 0 !important; }
  .ai-active .ai-chat-messages { flex: 1 1 auto; min-height: 0 !important; max-height: none !important; }
  .ai-active .ai-chat-form { flex: 0 0 auto; }
}

@media (max-width: 900px) {
  .studio-primary-ribbon, .studio-sub-ribbon { flex-wrap: wrap; align-content: flex-start; max-height: 164px; overflow-y: auto; }
  .studio-primary-ribbon > *, .studio-sub-ribbon > *, .studio-tool-group, .studio-mode-switcher, .studio-dropdown-wrapper { flex: 0 0 auto; }
  .studio-divider { display: none; }
  .studio-tool-btn { white-space: nowrap; }
  .studio-empty-state { position: absolute; inset: 0; z-index: 20; min-height: 0; background: var(--studio-bg); }
  .studio-main-viewport { min-width: 0; }
}

/* Keep Studio commands visible instead of relying on ribbon scrollbars. */
.studio-primary-ribbon, .studio-sub-ribbon { flex-wrap: wrap; overflow-x: hidden; overflow-y: visible; align-content: center; }
.studio-primary-ribbon > *, .studio-sub-ribbon > *, .studio-tool-group, .studio-mode-switcher, .studio-dropdown-wrapper { flex: 0 0 auto; }
.studio-dropdown-menu { left: auto; right: 0; }
#studio-canvas-area { position: relative; min-width: 0; }
.studio-empty-state { position: absolute; inset: 0; z-index: 20; min-height: 0; background: var(--studio-bg); }
#studio-canvas-area:has(.studio-empty-state) #page-render-wrapper { display: none !important; }
#studio-canvas-area:has(.studio-empty-state) #pdf-canvas,
#studio-canvas-area:has(.studio-empty-state) #pdf-draw-canvas { display: none !important; }
.studio-primary-ribbon, .studio-sub-ribbon { overflow: visible; }
.studio-toolbar { overflow: visible !important; }
@media (max-width: 900px) { .pdf-studio { height: calc(100dvh - 116px) !important; } }

.tool-availability-notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 12px;
  background: rgba(245, 158, 11, 0.08);
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.5;
}
.tool-availability-notice[hidden] { display: none; }

/* Phone Studio: keep tool names visible and remove empty page-browser chrome. */
@media (max-width: 600px) {
  .studio-active .studio-thumbnails-bar:has(.organizer-empty-msg) {
    max-height: 46px;
    min-height: 46px;
    overflow: hidden;
  }
  .studio-active .studio-thumbnails-bar:has(.organizer-empty-msg) .studio-thumbnails-header {
    min-height: 44px;
    border-bottom: 0;
  }
  .studio-active .studio-thumbnails-bar:has(.organizer-empty-msg) .studio-thumbnails-scroll {
    display: none !important;
  }
  .studio-active .studio-primary-ribbon,
  .studio-active .studio-sub-ribbon {
    min-height: 52px;
    padding: 6px 8px 9px;
    gap: 7px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .studio-active .studio-primary-ribbon > *,
  .studio-active .studio-sub-ribbon > *,
  .studio-active .studio-tool-group,
  .studio-active .studio-mode-switcher,
  .studio-active .studio-dropdown-wrapper {
    scroll-snap-align: start;
  }
  .studio-active .studio-tool-btn .tool-btn-text {
    display: inline !important;
  }
  .studio-active .studio-tool-btn {
    min-height: 42px;
    min-width: 44px;
    gap: 6px;
    padding: 7px 10px;
    font-size: 12px;
  }
  .studio-active .studio-mode-switcher { flex: 0 0 auto; }
  .studio-active .studio-mode-btn { min-height: 42px; padding: 7px 11px; font-size: 12px; }
  .studio-active .studio-dropdown-trigger { min-width: 102px; }
  .studio-active .studio-sub-ribbon .studio-tool-btn {
    min-width: 78px;
  }
  .studio-active .studio-empty-state {
    min-height: 34dvh;
    padding: 24px 16px;
    background: transparent !important;
    border: 0;
    box-shadow: none;
  }
  .studio-active .studio-empty-state h2 { font-size: 21px; }
  .studio-active .studio-empty-state p { font-size: 14px; line-height: 1.45; }
  .studio-active .studio-empty-state button {
    min-height: 44px;
    padding-inline: 16px;
  }
  .studio-active .studio-canvas-area {
    min-height: 38dvh;
    max-height: none;
    padding: 8px;
  }
}

/* Follow-up fixes: compact upload prompt, contained thumbnails/actions and safe dark hover. */
.ai-upload-strip { width: fit-content; max-width: 100%; }
.ai-upload-content { justify-content: flex-start; flex-wrap: wrap; gap: 10px 14px; }
.ai-stage-line { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; min-height: 20px; color: var(--text-muted); font-size: 12px; font-weight: 600; }
.ai-connection-test-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ai-connection-status { font-size: 12px; font-weight: 600; color: var(--success, #10b981); }
.ai-connection-status.error { color: var(--error, #ef4444); }
.ai-connection-status.pending { color: var(--text-muted); }
.ai-stage-dots { display: inline-block; color: var(--accent); letter-spacing: 2px; animation: aiStagePulse 1s ease-in-out infinite; }
@keyframes aiStagePulse { 50% { opacity: .28; transform: translateY(-1px); } }
.ai-chat-error { margin-top: 9px; color: var(--error); font-size: 12px; }
.ai-chat-retry, .ai-chat-stop { border: 1px solid var(--border-light); border-radius: 7px; padding: 7px 10px; background: var(--bg-panel-alt); color: var(--text-main); cursor: pointer; }
.ai-chat-stop:not([hidden]) { display: inline-flex; align-items: center; }
.ai-chat-stop:hover, .ai-chat-retry:hover { background: var(--sidebar-hover); border-color: var(--accent); }
.organizer-selection-panel { flex-wrap: wrap; overflow: visible; height: auto; }
.selection-action-clusters, .action-cluster { flex-wrap: wrap; min-width: 0; max-width: 100%; }
.organizer-grid.grid-mode { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; box-sizing: border-box; padding: 0 2px; }
.organizer-grid.grid-mode .organizer-thumb-card { min-width: 0; width: auto; max-width: 100%; box-sizing: border-box; }
body.dark-mode .dropzone:hover, body.dark-mode .dropzone.over { background: #202b2d; border-color: var(--accent); color: var(--text-main); box-shadow: 0 0 0 2px rgba(255,75,38,.12); }

/* Studio owns the remaining app viewport. Only its canvas and thumbnail panel
   scroll, so controls stay reachable and a long page stack cannot stretch the
   surrounding workspace to tens of thousands of pixels. */
.main-area.studio-active { flex: 1 1 auto; height: 100dvh; min-height: 0; overflow: hidden !important; }
.studio-active .dynamic-workspace { flex: 1 1 auto; width: 100%; max-width: none; height: 0; min-height: 0; margin: 0; padding: 0 !important; overflow: hidden; }
.studio-active #view-pdf-studio { width: 100%; height: 100%; min-height: 0; overflow: hidden; }
.studio-active .pdf-studio { height: 100% !important; min-height: 0; grid-template-rows: minmax(0, 1fr); overflow: hidden; }
.studio-active .studio-thumbnails-bar { height: 100%; min-height: 0; }
.studio-active .studio-thumbnails-scroll { flex: 1 1 0; height: auto; min-height: 0; overflow-x: hidden; overflow-y: auto; }
.studio-active .studio-main-viewport { height: 100%; min-height: 0; overflow: hidden; }
.studio-active .studio-canvas-area { flex: 1 1 auto; height: 0; min-height: 0; max-height: none; overflow: auto !important; overscroll-behavior: contain; }
.studio-active .studio-toolbar { position: relative; top: auto; z-index: 200; flex: 0 0 auto; }
.studio-active .studio-main-viewport > .ephemeral-work-notice { flex: 0 0 auto; margin: 6px 8px 0; padding: 6px 10px; font-size: 11px; }

/* Continuous PDF reading view: page shells preserve scroll geometry while
   nearby canvases render lazily, keeping long documents responsive. */
.studio-active #studio-page-stack {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: max-content;
  min-width: 100%;
  padding: 4px 0 28px;
  box-sizing: border-box;
}
.studio-active .studio-page-sheet {
  flex: 0 0 auto;
  max-width: 100%;
  overflow: hidden;
  contain: layout paint;
  scroll-margin-block: 10px;
}
.studio-active .studio-page-sheet.is-current { outline: 2px solid rgba(255, 75, 38, .42); outline-offset: 2px; }
.studio-active .studio-page-loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 20px;
  color: #34464a;
  background: #fff;
  font: 600 13px/1.45 system-ui, sans-serif;
  text-align: center;
}
.studio-active .studio-page-loading[hidden] { display: none !important; }
.studio-active .studio-page-loading button { justify-self: center; min-height: 40px; padding: 7px 14px; border: 1px solid #ff4b26; border-radius: 7px; color: #9b2d16; background: #fff3ef; cursor: pointer; }
.studio-active .studio-page-sheet .pdf-page-canvas { position: relative; z-index: 0; max-width: 100%; height: auto !important; }
.studio-active .studio-page-sheet .pdf-draw-canvas { z-index: 2; }
.studio-active #studio-canvas-area:has(.studio-empty-state) #studio-page-stack { display: none; }
@media (max-width: 900px) {
  .studio-active .main-area { flex: 1 1 auto; height: calc(100dvh - 62px); min-height: 0; overflow: hidden !important; }
  .studio-active .dynamic-workspace { flex: 1 1 auto; height: 0; min-height: 0; padding: 0 !important; overflow: hidden; }
  .studio-active .pdf-studio { height: 100% !important; min-height: 0; }
  .studio-active .studio-thumbnails-bar { max-height: 180px; }
  .studio-active .studio-thumbnails-scroll { max-height: 128px; }
  .studio-active .studio-main-viewport { flex: 1 1 0; height: 0; min-height: 0; }
  .studio-active .studio-canvas-area { flex: 1 1 auto; height: 0; min-height: 0; max-height: none; overflow: auto !important; scroll-behavior: auto; }
  .studio-active #studio-page-stack { min-width: 100%; width: 100%; gap: 12px; }
  .studio-active .studio-page-sheet { max-width: calc(100vw - 48px); }
  .studio-active .studio-page-sheet .pdf-page-canvas { max-width: 100%; height: auto !important; }
}

/* Mobile Studio: keep navigation and tool ribbons stationary while the page
   canvas scrolls in the remaining phone-sized viewport. */
@media (max-width: 900px) {
  .topbar-auth-group[hidden] { display: none !important; }
  .app-shell.studio-active { height: 100dvh; min-height: 0; overflow: hidden; }
  /* The legacy touch layout sets .main-area to display:block!important. Keep
     the editor's flex sizing authoritative so its canvas receives real height. */
  .studio-active .main-area { display: flex !important; flex: 1 1 auto; flex-direction: column; height: calc(100dvh - 62px) !important; min-width: 0; min-height: 0; overflow: hidden !important; }
  .studio-active .topbar { flex: 0 0 auto; }
  .studio-active .app-global-footer { display: none !important; }
  .studio-active #view-pdf-studio { display: block; min-width: 0; width: 100%; height: 100%; padding: 0; }
  .studio-active .pdf-studio {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: 100% !important;
    overflow: hidden;
    border-radius: 0;
  }
  .studio-active .studio-thumbnails-bar {
    display: flex !important;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: 180px;
    border-right: 0;
    border-bottom: 1px solid var(--studio-border);
  }
  .studio-active .studio-thumbnails-header { flex: 0 0 40px; min-height: 40px; padding: 6px 10px; }
  .studio-active .studio-thumbnails-scroll {
    display: block;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: 138px;
    overflow-x: auto;
    overflow-y: auto;
    padding: 7px 10px;
    gap: 8px;
  }
  .studio-active .studio-thumbnails-scroll > * { flex: initial; max-width: 100%; }
  .studio-active .organizer-subnav { display: flex; width: 100%; min-height: 34px; align-items: center; justify-content: space-between; }
  .studio-active .organizer-grid.strip-mode { display: flex; flex-direction: row; flex-wrap: nowrap; width: 100%; min-width: 0; max-width: 100%; gap: 8px; overflow-x: auto; overflow-y: hidden; }
  .studio-active .organizer-grid.grid-mode { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .studio-active .organizer-thumb-card { min-width: 0; width: 100%; max-width: 100%; box-sizing: border-box; }
  .studio-active .thumb-header { gap: 2px; padding-inline: 0; }
  .studio-active .thumb-grip { flex: 0 0 20px; width: 20px; min-width: 20px; min-height: 20px; padding: 0; }
  .studio-active .thumb-checkbox-label { flex: 0 0 18px; width: 18px; min-width: 18px; justify-content: center; }
  .studio-active .thumb-page-num { flex: 0 0 auto; min-width: 0; white-space: nowrap; }
  .studio-active .organizer-grid.strip-mode .organizer-thumb-card { flex: 0 0 76px; width: 76px; max-width: 76px; padding: 4px; }
  .studio-active .organizer-thumb-card canvas { max-width: 100%; height: auto; }
  .studio-active .organizer-subnav button { min-height: 30px; }
  .studio-active .thumb-card-footer { font-size: 9px; }
  .studio-active .studio-main-viewport { flex: 1 1 0; width: 100%; min-width: 0; min-height: 0; height: 0; overflow: hidden; }
  .studio-active .studio-toolbar { position: relative; top: auto; width: 100%; overflow: hidden !important; }
  .studio-active .studio-main-viewport > .ephemeral-work-notice { margin: 4px 6px 0; padding: 6px 8px; font-size: 10px; }
  .studio-active .studio-primary-ribbon,
  .studio-active .studio-sub-ribbon {
    display: flex;
    flex-wrap: nowrap !important;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    max-height: none;
    padding: 5px 8px;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap;
    scrollbar-width: auto;
    scrollbar-color: rgba(255,255,255,.55) rgba(255,255,255,.08);
  }
  .studio-active .studio-primary-ribbon::-webkit-scrollbar,
  .studio-active .studio-sub-ribbon::-webkit-scrollbar { height: 7px; }
  .studio-active .studio-primary-ribbon::-webkit-scrollbar-track,
  .studio-active .studio-sub-ribbon::-webkit-scrollbar-track { background: rgba(255,255,255,.08); }
  .studio-active .studio-primary-ribbon::-webkit-scrollbar-thumb,
  .studio-active .studio-sub-ribbon::-webkit-scrollbar-thumb { background: rgba(255,255,255,.5); border-radius: 5px; }
  .studio-active .studio-primary-ribbon > *,
  .studio-active .studio-sub-ribbon > *,
  .studio-active .studio-tool-group,
  .studio-active .studio-mode-switcher { flex: 0 0 auto; flex-wrap: nowrap; }
  .studio-active .studio-divider { display: block; flex: 0 0 1px; height: 24px; margin: 0 2px; }
  .studio-active .studio-tool-btn { flex: 0 0 auto; min-height: 38px; }
  .studio-active .studio-dropdown-menu { position: fixed; left: 8px; right: 8px; top: auto; max-width: none; max-height: 60vh; }
  .studio-active .studio-canvas-area {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 0;
    min-height: 0;
    max-height: none;
    box-sizing: border-box;
    padding: 12px;
    overflow: auto !important;
    align-items: center;
  }
  .studio-active .page-render-wrapper { max-width: 100%; }
  .studio-active .pdf-page-canvas { max-width: 100%; height: auto !important; }
  .studio-active .pdf-draw-canvas { max-width: 100%; }
  .studio-active .studio-empty-state {
    position: relative !important;
    inset: auto;
    display: grid;
    width: 100%;
    min-width: 0;
    min-height: 42vh;
    box-sizing: border-box;
    padding: 22px 14px;
    overflow-wrap: anywhere;
    text-align: center;
  }
  .studio-active .studio-empty-state h2,
  .studio-active .studio-empty-state p { max-width: 100%; margin-inline: 0; }
  .studio-active .studio-empty-state > div { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
}

/* Keep AI tools reachable on phones and tablets. The chat stays a compact,
   scrollable panel and extraction/summary cards follow it in the same pane. */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
@media (max-width: 900px) {
  .ai-active .ai-studio-container {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: 16px;
  }
  .ai-active .ai-chat-card {
    flex: 0 0 auto !important;
    width: 100%;
    height: min(520px, 66dvh);
    min-height: 380px !important;
  }
  .ai-active .ai-studio-container > div:last-child {
    display: flex !important;
    flex: 0 0 auto !important;
    width: 100%;
    flex-direction: column;
    gap: 12px !important;
  }
  .ai-active .ai-studio-container > div:last-child .ai-chat-card {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    height: auto;
  }
  .ai-active #summary-display {
    min-height: 96px;
    max-height: min(28dvh, 240px);
  }
}

/* Keep the mobile editor operable by touch. Per-page quick actions are
   replaced by the selected-page batch bar on phones, which has room for
   readable 44px controls instead of tiny buttons inside each thumbnail. */
@media (max-width: 900px) {
  .studio-active .studio-toolbar button,
  .studio-active .studio-mode-btn,
  .studio-active .studio-dropdown-trigger,
  .studio-active .organizer-subnav button,
  .studio-active .batch-subtle-btn,
  .studio-active .cluster-btn,
  .studio-active #organizer-split-trigger-btn,
  .studio-active #organizer-import-trigger-btn,
  .studio-active #org-select-all-btn,
  .studio-active #org-invert-btn,
  .studio-active #org-strip-view-btn,
  .studio-active #org-grid-view-btn,
  .ai-active #ai-upload-btn,
  .ai-active #ai-test-connection-btn,
  .ai-active #ai-chat-clear-btn {
    min-height: 44px;
  }

  .studio-active .studio-toolbar button {
    min-width: 44px;
  }

  .studio-active .studio-primary-ribbon,
  .studio-active .studio-sub-ribbon {
    scroll-behavior: smooth;
    scroll-padding-inline: 8px;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .studio-active .thumb-checkbox-label {
    flex: 0 0 44px;
    width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  .studio-active .thumb-grip {
    display: inline-flex;
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    touch-action: none;
  }

  .studio-active #org-strip-view-btn,
  .studio-active #org-grid-view-btn {
    min-width: 44px;
  }

  .studio-active .thumb-checkbox {
    width: 18px;
    height: 18px;
  }

  .studio-active .thumb-quick-actions {
    display: none !important;
  }
}

.ephemeral-work-notice {
  margin: 8px 14px 12px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 75, 38, 0.22);
  border-radius: 10px;
  background: rgba(255, 75, 38, 0.055);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}
.security-sanitize-report { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--border-light); border-radius: 8px; background: var(--bg-panel-alt); color: var(--text-main); font-size: 12px; line-height: 1.5; }
.security-sanitize-report ul { margin: 8px 0 10px; padding-left: 18px; }
.security-sanitize-report[hidden] { display: none !important; }

/* Accessible local-work controls. */
.ephemeral-work-notice { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ephemeral-work-notice > span { min-width: 0; }
.work-clear-btn { flex: 0 0 auto; min-height: 36px; padding: 6px 10px; border: 1px solid var(--border-light); border-radius: 8px; color: var(--text-main); background: var(--bg-panel); cursor: pointer; }
.work-clear-btn:hover { border-color: var(--accent); color: var(--accent); }
.visually-hidden,
.visually-hidden-file-input { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; clip-path: inset(50%) !important; border: 0 !important; }
.ai-empty-state { display: grid; justify-items: center; gap: 20px; width: 100%; max-width: 760px; margin: auto; padding: 28px 16px; box-sizing: border-box; text-align: center; }
.ai-empty-copy { display: grid; gap: 8px; max-width: 540px; }
.ai-empty-copy strong { color: var(--text-main); font-size: clamp(20px, 4vw, 28px); }
.ai-empty-copy span { color: var(--text-muted); line-height: 1.55; }
.ai-empty-state .ai-upload-strip { width: min(100%, 580px); max-width: 580px; }
.ai-empty-state .ai-upload-content { display: grid; justify-items: center; width: 100%; box-sizing: border-box; text-align: center; }
.ai-empty-state .ai-upload-content > span { display: grid; gap: 4px; }
.ai-upload-inline-btn { flex: 0 0 auto; }
.ai-studio-wrapper > .ephemeral-work-notice { align-self: stretch; margin: 0 0 10px; }

@media (min-width: 901px) and (max-width: 1180px) {
  .workspace-tabs { max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
  .tab-pill { min-height: 40px; flex: 0 0 auto; white-space: nowrap; }
  .topbar-left, .topbar-right { min-width: 0; }
}

.tool-desk-directory { width: min(100%, 1480px); margin: 0 auto; padding: 28px 24px 48px; box-sizing: border-box; }
.tool-desk-directory-hero { max-width: 980px; margin: 8px auto 32px; padding: clamp(20px, 4vw, 36px); border: 1px solid var(--border-subtle); border-radius: 18px; background: var(--bg-panel); box-shadow: 0 10px 28px rgba(14, 26, 28, .08); }
.tool-desk-directory-hero h1 { margin: 6px 0 8px; font-size: clamp(28px, 4vw, 42px); line-height: 1.1; }
.tool-desk-directory-hero > p { max-width: 620px; margin: 0; color: var(--text-muted); line-height: 1.55; }
.tool-desk-search-wrap { display: flex; align-items: center; gap: 12px; max-width: 720px; min-height: 52px; margin: 22px 0 14px; padding: 0 15px; border: 1px solid var(--border-light); border-radius: 12px; color: var(--text-muted); background: var(--bg-main); box-sizing: border-box; }
.tool-desk-search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.tool-desk-search-wrap input { width: 100%; min-width: 0; min-height: 48px; border: 0; outline: 0; background: transparent; color: var(--text-main); font: inherit; }
.tool-desk-directory-filters { display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%; overflow: visible; padding: 3px 2px 8px; }
.tool-desk-directory-filters .filter-pill { min-height: 40px; flex: 0 0 auto; }
.tool-desk-directory .home-tool-card { width: 100%; text-align: left; font: inherit; cursor: pointer; }
.tool-desk-search-meta { margin: 0 0 14px; color: var(--text-muted); font-size: 13px; }
.studio-action-feedback { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin: 8px 0; padding: 10px 12px; border: 1px solid var(--border-light); border-radius: 10px; color: var(--text-main); background: var(--bg-panel); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.studio-action-feedback a { color: var(--accent); font-weight: 700; }
.studio-action-feedback[hidden] { display: none !important; }
.studio-action-feedback .work-clear-btn { min-height: 36px; }
section, h1, h2, h3 { scroll-margin-top: 104px; }

@media (max-width: 900px) {
  .sidebar-tool-item,
  .nav-category-tab {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .tool-desk-directory { padding: 16px 8px 30px; }
  .tool-desk-directory-hero { margin: 0 0 18px; padding: 18px 14px; border-radius: 14px; }
  .tool-desk-directory-hero h1 { font-size: 30px; }
  .tool-desk-directory-filters { flex-wrap: wrap; overflow: visible; margin-right: 0; }
  .tool-desk-directory .home-cat-grid { display: grid; grid-template-columns: minmax(0, 1fr); overflow: visible; gap: 12px; }
  .tool-desk-directory .home-tool-card { width: 100%; min-width: 0; }
  .tool-desk-search-meta { padding: 0 4px; }
  .mobile-workspace-bar { display: flex; }
  .mobile-nav-btn { flex: 1 1 0; min-width: 0; padding: 5px 2px; font-size: 9px; gap: 3px; }
  .mobile-nav-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .studio-action-feedback { align-items: flex-start; margin: 8px 0; font-size: 12px; }
  .studio-active .studio-undo-banner { position: relative; }
  #forms-import-json-text { display: block; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto; }
}

/* The tool cards already repeat these steps on phones. Keep the directory
   focused on search, filters, and tools above the fold. */
@media (max-width: 600px) {
  #view-tool-desk-directory .tool-desk-quick-steps { display: none; }
}

/* Phone workspaces use document scrolling. This gives every toolbar row,
   thumbnail and result its own space instead of stacking fixed panels. */
@media (max-width: 900px) {
  html, body { height: auto !important; min-height: 100% !important; overflow-x: hidden !important; overflow-y: auto !important; }
  #app-shell, #app-shell.studio-active, #app-shell.ai-active {
    display: block !important;
    height: auto !important;
    min-height: 100dvh !important;
    overflow: visible !important;
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
  }
  .topbar {
    position: fixed !important;
    inset: 0 0 auto !important;
    z-index: 120 !important;
    height: calc(64px + env(safe-area-inset-top, 0px)) !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
  }
  .main-area, .main-area.studio-active, .ai-active .main-area {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: calc(100dvh - 56px) !important;
    padding-top: calc(64px + env(safe-area-inset-top, 0px)) !important;
    overflow: visible !important;
  }
  .dynamic-workspace, .studio-active .dynamic-workspace, .ai-active .dynamic-workspace {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 10px 8px calc(92px + env(safe-area-inset-bottom, 0px)) !important;
    overflow: visible !important;
    box-sizing: border-box;
  }
  .sidebar.mobile-open { z-index: 1200 !important; }
  .app-global-footer { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* Editor thumbnail strip and toolbar all participate in normal page flow. */
  .studio-active #view-pdf-studio,
  .studio-active .pdf-studio,
  .studio-active .studio-main-viewport {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    box-sizing: border-box;
  }
  .studio-active .studio-main-viewport { flex: 0 0 auto !important; }
  .studio-active .pdf-studio { border-radius: 10px; }
  .studio-active .studio-thumbnails-bar {
    display: flex !important;
    flex: 0 0 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    border-right: 0;
    border-bottom: 1px solid var(--studio-border);
  }
  .studio-active .studio-thumbnails-scroll {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: 176px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 8px !important;
    box-sizing: border-box;
  }
  .studio-active .organizer-subnav { display: flex; width: 100%; min-height: 42px; justify-content: space-between; }
  .studio-active .organizer-grid.strip-mode {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    gap: 8px;
    overflow: visible !important;
  }
  .studio-active .organizer-grid.strip-mode .organizer-thumb-card {
    flex: initial !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 112px;
  }
  .studio-active .organizer-thumb-card canvas,
  .studio-active .organizer-thumb-card img { display: block; max-width: 100%; height: auto; }
  .studio-active .studio-main-viewport { gap: 0; }
  .studio-active .studio-main-viewport > .ephemeral-work-notice { flex: 0 0 auto; margin: 8px; font-size: 12px; }
  .studio-active .work-clear-btn { min-height: 40px; }
  .studio-active .studio-toolbar { position: relative !important; top: auto !important; z-index: 130 !important; width: 100%; height: auto !important; max-height: none !important; overflow: visible !important; }
  .studio-active .studio-primary-ribbon,
  .studio-active .studio-sub-ribbon {
    display: flex !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    padding: 7px !important;
    overflow: visible !important;
    white-space: normal !important;
    box-sizing: border-box;
  }
  .studio-active .studio-primary-ribbon > *,
  .studio-active .studio-sub-ribbon > *,
  .studio-active .studio-tool-group,
  .studio-active .studio-mode-switcher { flex: 0 1 auto !important; flex-wrap: wrap !important; min-width: 0; }
  .studio-active .studio-divider { display: none !important; }
  .studio-active .studio-tool-btn { min-width: 44px; min-height: 44px; max-width: 100%; }
  .studio-active .studio-sub-ribbon .studio-tool-btn { min-width: 0 !important; }
  .studio-active .studio-tool-btn::after { content: none !important; display: none !important; }
  .studio-active .studio-tool-btn .tool-btn-text { display: inline !important; }
  .studio-active .studio-canvas-area {
    display: block !important;
    flex: 0 0 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 42dvh !important;
    max-height: none !important;
    padding: 10px 4px 20px !important;
    overflow: visible !important;
    box-sizing: border-box;
  }
  .studio-active #studio-page-stack { display: flex; width: 100% !important; min-width: 0 !important; align-items: center; overflow: visible; }
  .studio-active .studio-page-sheet { max-width: calc(100vw - 40px) !important; }
  .studio-active .studio-page-sheet .pdf-page-canvas { display: block; max-width: 100% !important; height: auto !important; }
  .studio-active .studio-empty-state { min-height: 38dvh; }

  /* AI chat is a regular page section with a clear upload entry point. */
  .ai-active #view-ai-studio {
    position: relative !important;
    inset: auto !important;
    display: flex !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 8px 0 20px !important;
    overflow: visible !important;
  }
  .ai-active .ai-studio-topbar { display: flex; flex-direction: column; width: 100%; gap: 10px; }
  .ai-active .ai-engine-notice-bar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .ai-active .ai-engine-info { display: none !important; }
  .ai-active .ai-studio-container {
    display: flex !important;
    flex: 0 0 auto !important;
    flex-direction: column !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    gap: 14px !important;
    padding: 0 0 18px !important;
    overflow: visible !important;
  }
  .ai-active .ai-chat-card { flex: 0 0 auto !important; width: 100% !important; height: auto !important; min-height: 0 !important; }
  .ai-active .ai-chat-header { flex-wrap: wrap; gap: 8px; }
  .ai-active .ai-chat-header > div { flex: 1 1 160px !important; }
  .ai-active .ai-chat-card:has(#ai-empty-state:not([hidden])) .ai-chat-header small { display: none !important; }
  .ai-active .ai-chat-card:has(#ai-empty-state:not([hidden])) #ai-upload-inline-btn,
  .ai-active .ai-chat-card:has(#ai-empty-state:not([hidden])) #ai-chat-clear-btn { display: none !important; }
  .ai-active .ai-chat-messages { display: flex; flex-direction: column; min-height: 250px !important; max-height: min(58dvh, 520px) !important; height: auto !important; overflow-y: auto !important; }
  .ai-active .ai-chat-messages:has(.ai-empty-state) { min-height: 350px !important; max-height: none !important; }
  .ai-active .ai-chat-messages:has(.ai-empty-state:not([hidden])) { flex: 0 0 auto !important; height: auto !important; min-height: 280px !important; overflow: visible !important; }
  .ai-active .ai-chat-form { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 20; background: var(--bg-panel); }
  .ai-active .ai-chat-card:has(.ai-empty-state:not([hidden])) .ai-chat-form { position: relative; bottom: auto; }
  .ai-active .ai-studio-container > div:last-child { display: flex !important; flex: 0 0 auto !important; width: 100% !important; flex-direction: column; gap: 12px !important; }
  .ai-active .ai-studio-container > div:last-child .ai-chat-card { flex: 0 0 auto !important; height: auto !important; min-height: 0 !important; }
  .ai-active #summary-display { min-height: 100px; max-height: 300px; }
  .ai-active .ephemeral-work-notice { align-items: flex-start; }
  .ai-active .work-clear-btn { min-height: 40px; }
  .ai-active .ai-upload-strip { width: 100%; max-width: 100%; }
  .ai-active .ai-empty-state { gap: 12px; padding: 16px 12px; }
  .ai-active .ai-empty-copy { gap: 5px; }
  .ai-active .ai-empty-copy strong { font-size: 22px; }
  .ai-active .ai-empty-copy span { font-size: 13px; line-height: 1.4; }
  .ai-active .ai-empty-state .ai-upload-content { gap: 8px; padding: 12px !important; }
}

.ai-stage-timeline {
  display: flex;
  gap: 6px;
  max-width: 100%;
  margin: 8px 0 10px;
  padding: 0 0 4px;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: thin;
}

.ai-stage-timeline li {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.ai-stage-timeline li.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

.ai-stage-timeline li.is-complete {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border-light));
}

.ai-response-mode {
  width: fit-content;
  max-width: 100%;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--bg-panel-alt);
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
}

.app-confirm-dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: none;
  margin: auto;
  padding: 22px;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  color: var(--text-main);
  background: var(--bg-panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .38);
}
.app-confirm-dialog::backdrop { background: rgba(5, 12, 14, .64); }
.app-confirm-dialog h2 { margin: 0 0 8px; font-size: 19px; }
.app-confirm-dialog p { margin: 0; color: var(--text-muted); line-height: 1.55; overflow-wrap: anywhere; }
.app-confirm-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.app-confirm-actions button { min-height: 44px; padding: 8px 14px; border: 1px solid var(--border-light); border-radius: 8px; color: var(--text-main); background: var(--bg-panel-alt); cursor: pointer; }
.app-confirm-actions .app-confirm-accept { border-color: var(--accent); color: #fff; background: var(--accent); }
.app-confirm-actions .app-confirm-accept.danger { border-color: #dc2626; background: #dc2626; }
.app-confirm-actions button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 46%, white); outline-offset: 2px; }

@media (max-width: 420px) {
  .ai-stage-timeline {
    gap: 4px;
  }

  .ai-stage-timeline li {
    padding: 4px 7px;
    font-size: 10px;
  }
}

/* Keep mobile tool discovery readable without requiring a sideways swipe. */
@media (max-width: 900px) {
  .home-cat-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    overflow: visible !important;
    padding: 2px 0 10px;
    scroll-snap-type: none;
  }

  .home-tool-card {
    width: 100%;
    min-width: 0;
    flex: initial !important;
    scroll-snap-align: none;
  }
}

/* Mobile Studio is a fixed editor workspace: thumbnails stay reachable while
   continuous page scrolling happens inside the canvas viewport. */
@media (max-width: 900px) {
  html.studio-active,
  html.studio-active body {
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden !important;
  }

  html.studio-active body #app-shell {
    display: block !important;
    width: 100% !important;
    height: 100dvh !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  html.studio-active body #app-shell .main-area {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column !important;
    width: 100% !important;
    height: calc(100dvh - 62px) !important;
    min-width: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: calc(64px + env(safe-area-inset-top, 0px)) 0 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  html.studio-active body #app-shell .dynamic-workspace {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  html.studio-active body #view-pdf-studio {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  html.studio-active body .pdf-studio {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    min-width: 0 !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100% !important;
    overflow: hidden !important;
    border-radius: 0 !important;
  }

  html.studio-active body .studio-thumbnails-bar {
    display: flex !important;
    flex: 0 0 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: 180px !important;
    overflow: hidden !important;
  }

  html.studio-active body .studio-thumbnails-header { flex: 0 0 40px !important; min-height: 40px !important; }
  html.studio-active body .studio-thumbnails-scroll {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: 138px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding-bottom: 64px !important;
    box-sizing: border-box !important;
  }

  html.studio-active body .organizer-grid.strip-mode {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    gap: 8px !important;
    overflow: visible !important;
  }
  html.studio-active body .organizer-grid.strip-mode .organizer-thumb-card {
    flex: initial !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 112px !important;
  }

  html.studio-active body .studio-main-viewport {
    display: flex !important;
    flex: 1 1 0 !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 0 !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
  }
  html.studio-active body .studio-toolbar {
    position: relative !important;
    top: auto !important;
    z-index: 130 !important;
    flex: 0 0 auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  html.studio-active body .studio-primary-ribbon,
  html.studio-active body .studio-sub-ribbon {
    display: flex !important;
    flex: 0 0 52px !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 52px !important;
    max-height: 52px !important;
    height: 52px !important;
    padding: 5px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
    scrollbar-width: thin;
  }
  html.studio-active body .studio-primary-ribbon > *,
  html.studio-active body .studio-sub-ribbon > *,
  html.studio-active body .studio-tool-group,
  html.studio-active body .studio-mode-switcher {
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    min-width: max-content;
  }
  html.studio-active body .studio-divider { display: block !important; flex: 0 0 1px !important; height: 24px !important; }
  html.studio-active body .studio-tool-btn { flex: 0 0 auto !important; min-height: 42px !important; white-space: nowrap !important; }
  html.studio-active body .studio-canvas-area {
    display: block !important;
    flex: 1 1 auto !important;
    width: 100% !important;
    height: 0 !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 10px 8px 20px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    box-sizing: border-box !important;
  }
  html.studio-active body #studio-page-stack {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow: visible !important;
    gap: 12px !important;
  }
  html.studio-active body .studio-page-sheet { max-width: calc(100vw - 40px) !important; }
  html.studio-active body .studio-page-sheet .pdf-page-canvas { display: block; max-width: 100% !important; height: auto !important; }
}

/* --------------------------------------------------------------------------
   V6 workspace layout: fixed AI geometry and a mobile-first Studio shell.
   These rules replace the accumulated per-breakpoint layouts above.
   -------------------------------------------------------------------------- */
.mobile-view-pill { display: none; }

/* AI Docs keeps the same proportions while messages, summaries and files change. */
#app-shell.ai-active .ai-studio-wrapper {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  align-content: start;
  padding-bottom: 12px;
}
#app-shell.ai-active .ai-studio-topbar { min-width: 0; gap: 8px; }
.ai-howto-section {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  background: var(--bg-panel);
}
.ai-howto-section h2 {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.35;
  text-wrap: balance;
}
.ai-howto-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ai-howto-steps li {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--bg-panel-alt);
}
.ai-howto-steps li strong { font-size: 12.5px; }
.ai-howto-steps li span { color: var(--text-muted); font-size: 12px; line-height: 1.45; }
@media (max-width: 700px) {
  .ai-howto-steps { grid-template-columns: minmax(0, 1fr); }
}
#app-shell.ai-active .ai-active-doc-strip { min-width: 0; flex-wrap: wrap; }
#app-shell.ai-active .ai-doc-info-group { min-width: 0; flex: 1 1 360px; flex-wrap: wrap; }
#app-shell.ai-active .ai-doc-details { min-width: 0; overflow-wrap: anywhere; }
#app-shell.ai-active .ai-studio-container {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 31%, 410px) !important;
  align-items: stretch;
  gap: 16px;
  width: 100%;
  min-width: 0;
  min-height: clamp(620px, calc(100dvh - 300px), 820px) !important;
  height: clamp(620px, calc(100dvh - 300px), 820px);
}
#app-shell.ai-active .ai-chat-card { width: 100%; min-width: 0; min-height: 0; height: 100%; }
#app-shell.ai-active .ai-chat-header { flex: 0 0 auto; min-width: 0; }
#app-shell.ai-active .ai-chat-messages {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#app-shell.ai-active .ai-chat-form { position: static; flex: 0 0 auto; margin-top: auto; }
#app-shell.ai-active .ai-studio-container > div:last-child {
  display: grid !important;
  grid-template-rows: minmax(260px, .78fr) minmax(344px, 1.22fr);
  gap: 14px !important;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
#app-shell.ai-active .ai-studio-container > div:last-child > .ai-chat-card {
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
#app-shell.ai-active .view-header-badge,
#app-shell.ai-active .ai-doc-status-badge,
#app-shell.ai-active .ai-engine-pill,
#app-shell.ai-active .ai-citation-tag {
  flex: 0 0 auto;
  width: max-content;
  max-width: 100%;
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}
#app-shell.ai-active #summary-display {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
  overflow-wrap: anywhere;
  scrollbar-gutter: stable;
}
#app-shell.ai-active .ai-chat-card:has(#ai-empty-state:not([hidden])) .ai-chat-messages {
  align-items: stretch;
}
#app-shell.ai-active .ai-empty-state {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}
#app-shell.ai-active .ai-upload-strip { width: min(100%, 680px); box-sizing: border-box; }
#app-shell.ai-active .ai-upload-content { justify-content: center; flex-wrap: wrap; text-align: center; }
#app-shell.ai-active .ai-upload-content > span { max-width: 520px; }

/* The editor becomes a normal page on phones: only the app header stays pinned.
   Its command and page controls sit in a compact dock above the app navigation. */
.studio-mobile-dock,
.studio-mobile-properties-panel,
.studio-mobile-pages-close { display: none; }
@media (max-width: 900px) {
  .mobile-view-pill {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    min-height: 30px;
    max-width: min(44vw, 175px);
    padding: 0 10px;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: var(--bg-panel-alt);
    color: var(--text-main);
    font-size: 12px;
    font-weight: 650;
    line-height: 1;
    white-space: nowrap;
  }

  #app-shell.ai-active { padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important; }
  #app-shell.ai-active .main-area {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: calc(100dvh - 56px) !important;
    overflow: visible !important;
    padding-top: calc(64px + env(safe-area-inset-top, 0px)) !important;
  }
  #app-shell.ai-active .dynamic-workspace {
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 10px 12px 22px !important;
    overflow: visible !important;
    box-sizing: border-box;
  }
  #app-shell.ai-active .ai-studio-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    min-width: 0;
    min-height: 0;
    padding-bottom: 8px;
  }
  /* Keep the primary conversation and upload action in the first phone
     viewport; the explanatory/how-to panel remains available after the tools. */
  #app-shell.ai-active .ai-studio-container { order: 0; }
  #app-shell.ai-active .ai-howto-section { order: 1; }
  #app-shell.ai-active .ai-studio-container {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto auto;
    gap: 12px;
    width: 100%;
    min-width: 0;
    min-height: 0 !important;
    height: auto !important;
    overflow: visible;
  }
  #app-shell.ai-active .ai-chat-card {
    display: flex;
    width: 100%;
    min-width: 0;
    height: min(68dvh, 640px) !important;
    min-height: min(520px, calc(100dvh - 190px)) !important;
    max-height: 680px;
  }
  #app-shell.ai-active .ai-chat-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center !important;
    gap: 8px;
    padding: 12px 14px;
  }
  #app-shell.ai-active .ai-chat-header > div { flex: 1 1 165px !important; min-width: 0; }
  #app-shell.ai-active .ai-chat-header small { display: block !important; }
  #app-shell.ai-active #ai-upload-inline-btn:not([hidden]),
  #app-shell.ai-active #ai-chat-clear-btn:not([hidden]) {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 auto !important;
    align-self: center !important;
    height: auto !important;
    min-height: 38px !important;
    padding: 6px 12px !important;
    white-space: nowrap !important;
  }
  #app-shell.ai-active #ai-upload-inline-btn[hidden],
  #app-shell.ai-active #ai-chat-clear-btn[hidden] { display: none !important; }
  #app-shell.ai-active .chat-bubble {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-wrap: anywhere;
  }
  #app-shell.ai-active .ai-question-suggestion {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #app-shell.ai-active .ai-chat-messages {
    flex: 1 1 0 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 14px 12px;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }
  #app-shell.ai-active .ai-chat-form {
    position: static !important;
    bottom: auto !important;
    z-index: auto;
    flex: 0 0 auto !important;
    gap: 8px;
    padding: 10px;
  }
  #app-shell.ai-active .ai-chat-input { min-width: 0; min-height: 44px; padding: 10px 12px; }
  #app-shell.ai-active .ai-chat-form .btn-primary-action { min-height: 44px; padding-inline: 14px !important; }
  #app-shell.ai-active .ai-chat-card:has(#ai-empty-state:not([hidden])) .ai-chat-messages { display: flex; }
  #app-shell.ai-active .ai-empty-state { min-height: 0 !important; gap: 16px; padding: 14px 4px; }
  #app-shell.ai-active .ai-empty-copy strong { font-size: clamp(21px, 6vw, 28px); }
  #app-shell.ai-active .ai-upload-content { flex-direction: column; gap: 8px; padding: 12px; }
  #app-shell.ai-active .ai-upload-content > span { display: grid; gap: 4px; }
  #app-shell.ai-active .ai-upload-content > span > span { max-width: 100%; }
  #app-shell.ai-active .ai-upload-content .btn-primary-action { min-height: 44px; }
  #app-shell.ai-active .ai-studio-container > div:last-child {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    width: 100%;
    height: auto;
    min-width: 0;
    gap: 12px !important;
  }
  #app-shell.ai-active .ai-studio-container > div:last-child > .ai-chat-card {
    height: auto !important;
    min-height: 0 !important;
    max-height: none;
    padding: 16px !important;
  }
  #app-shell.ai-active #summary-display { min-height: 140px; max-height: min(36dvh, 280px); }
  #app-shell.ai-active .ai-active-doc-strip { align-items: flex-start; padding: 10px 12px; }
  #app-shell.ai-active .ai-doc-info-group { flex-basis: 100%; gap: 8px; }
  #app-shell.ai-active .ai-doc-actions { width: 100%; justify-content: flex-end; }
  #app-shell.ai-active .ai-engine-notice-bar { flex-wrap: wrap; gap: 6px; padding: 4px 2px; }
  #app-shell.ai-active .ephemeral-work-notice { max-width: 100%; }

  html.studio-active,
  html.studio-active body {
    width: 100%;
    height: auto !important;
    min-height: 100%;
    overflow-x: clip !important;
    overflow-y: auto !important;
  }
  html.studio-active body #app-shell {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    height: auto !important;
    min-height: 100dvh !important;
    overflow: visible !important;
    padding-bottom: calc(174px + env(safe-area-inset-bottom)) !important;
  }
  html.studio-active body #app-shell .main-area {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: calc(100dvh - 64px) !important;
    margin: 0 !important;
    padding: calc(64px + env(safe-area-inset-top, 0px)) 0 0 !important;
    overflow: visible !important;
  }
  html.studio-active body #app-shell .dynamic-workspace {
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 8px 12px !important;
    overflow: visible !important;
    box-sizing: border-box;
  }
  html.studio-active body #view-pdf-studio {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  html.studio-active body .pdf-studio {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
  }
  html.studio-active body .studio-thumbnails-bar {
    display: none !important;
    position: fixed !important;
    inset: var(--studio-mobile-pages-top, calc(68px + env(safe-area-inset-top, 0px))) 8px auto !important;
    z-index: 900 !important;
    width: auto !important;
    height: auto !important;
    max-height: min(58dvh, 480px) !important;
    min-height: 0 !important;
    overflow: hidden !important;
    border: 1px solid var(--studio-border) !important;
    border-radius: 16px !important;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .38);
  }
  html.studio-active body #app-shell.studio-pages-open .studio-thumbnails-bar { display: flex !important; }
  html.studio-active body .studio-thumbnails-header {
    display: flex !important;
    flex: 0 0 auto !important;
    min-height: 50px !important;
    padding: 8px 10px !important;
    gap: 8px;
  }
  html.studio-active body .organizer-header-actions { gap: 6px; }
  html.studio-active body .studio-mobile-pages-close { display: inline-flex !important; }
  html.studio-active body .studio-mobile-batch-slot:empty { display: none !important; }
  html.studio-active body .studio-mobile-batch-slot:not(:empty) {
    display: block;
    flex: 0 0 auto;
    width: 100%;
    max-height: 30dvh;
    overflow: auto;
    overscroll-behavior: contain;
    border-bottom: 1px solid var(--studio-border);
    background: var(--studio-bg);
  }
  html.studio-active body #studio-mobile-batch-slot .organizer-selection-panel {
    position: static !important;
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    max-height: none;
    padding: 8px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible !important;
    animation: none;
  }
  html.studio-active body #studio-mobile-batch-slot .selection-panel-summary { justify-content: space-between; gap: 6px; }
  html.studio-active body #studio-mobile-batch-slot .selection-action-clusters {
    width: 100%;
    min-width: 0;
    overflow: visible;
    flex-wrap: wrap !important;
    padding-bottom: 4px;
    overscroll-behavior-inline: contain;
  }
  html.studio-active body #studio-mobile-batch-slot .action-cluster { flex: 1 1 100%; min-width: 0; flex-wrap: wrap; }
  html.studio-active body #studio-mobile-batch-slot .cluster-btn { flex: 0 1 auto; min-width: 68px; white-space: nowrap; }
  html.studio-active body .studio-thumbnails-scroll {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: calc(min(58dvh, 480px) - 54px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 10px !important;
    box-sizing: border-box;
  }
  html.studio-active body .organizer-grid.strip-mode,
  html.studio-active body .organizer-grid.grid-mode {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    gap: 8px !important;
    overflow: visible !important;
  }
  html.studio-active body .organizer-grid .organizer-thumb-card {
    width: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 0 !important;
  }
  html.studio-active body .organizer-grid .organizer-thumb-card canvas,
  html.studio-active body .organizer-grid .organizer-thumb-card img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
  }
  html.studio-active body .studio-main-viewport {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    overflow: visible !important;
    background: transparent;
  }
  html.studio-active body .studio-main-viewport > .ephemeral-work-notice {
    display: flex !important;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin: 8px 0 !important;
    padding: 7px 9px !important;
    border-radius: 10px;
    font-size: 11px !important;
    line-height: 1.35;
  }
  html.studio-active body .studio-main-viewport > .ephemeral-work-notice > span {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  html.studio-active body .studio-main-viewport > .ephemeral-work-notice .work-clear-btn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 6px 9px;
    font-size: 11px;
    white-space: nowrap;
  }
  html.studio-active body .studio-toolbar {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    border: 1px solid var(--studio-border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
  }
  html.studio-active body .studio-primary-ribbon {
    display: flex !important;
    flex-flow: row wrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 5px !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    padding: 7px !important;
    overflow: visible !important;
    white-space: normal !important;
    box-sizing: border-box !important;
  }
  html.studio-active body .studio-primary-ribbon > *,
  html.studio-active body .studio-tool-group,
  html.studio-active body .studio-mode-switcher,
  html.studio-active body .studio-dropdown-wrapper {
    flex: 0 0 auto !important;
    min-width: 0 !important;
  }
  html.studio-active body .studio-primary-ribbon .studio-divider,
  html.studio-active body .studio-sub-ribbon .studio-divider { display: none !important; }
  html.studio-active body .studio-sub-ribbon {
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 56px !important;
    max-height: none !important;
    height: auto !important;
    padding: 6px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    box-sizing: border-box !important;
  }
  html.studio-active body .studio-sub-ribbon > *,
  html.studio-active body .studio-sub-ribbon .studio-tool-group { flex: 0 0 auto !important; min-width: 0 !important; }
  html.studio-active body .studio-toolbar button,
  html.studio-active body .studio-mode-btn,
  html.studio-active body .studio-dropdown-trigger,
  html.studio-active body .studio-mobile-dock button {
    min-height: 44px !important;
    box-sizing: border-box;
  }
  html.studio-active body .studio-toolbar .tool-btn-text { white-space: nowrap; }
  html.studio-active body .studio-mode-btn { padding-inline: 9px; }
  html.studio-active body .studio-dropdown-menu { position: fixed; inset: auto 8px calc(178px + env(safe-area-inset-bottom)) 8px; width: auto; max-width: none; max-height: 55dvh; z-index: 1500; overflow: auto; }
  html.studio-active body .organizer-selection-panel { width: 100%; max-width: 100%; box-sizing: border-box; overflow: visible !important; }
  html.studio-active body .selection-action-clusters,
  html.studio-active body .action-cluster { min-width: 0; max-width: 100%; flex-wrap: wrap; }
  html.studio-active body .studio-canvas-area {
    display: block !important;
    width: 100% !important;
    height: min(66dvh, 820px) !important;
    min-height: 430px !important;
    max-height: none !important;
    margin: 10px 0 0;
    padding: 12px 8px 18px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    border: 1px solid var(--studio-border);
    border-radius: 12px;
    box-sizing: border-box !important;
  }
  html.studio-active body #studio-page-stack {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow: visible !important;
    gap: 12px !important;
  }
  html.studio-active body .studio-page-sheet { max-width: calc(100dvw - 72px) !important; }
  html.studio-active body .studio-page-sheet .pdf-page-canvas { display: block; max-width: 100% !important; height: auto !important; }
  html.studio-active body .studio-mobile-dock {
    display: flex !important;
    position: fixed;
    inset: auto 0 calc(66px + env(safe-area-inset-bottom, 0px)) 0;
    z-index: 950;
    flex-direction: column;
    gap: 5px;
    padding: 7px 8px;
    border-top: 1px solid var(--border-light);
    background: color-mix(in srgb, var(--bg-panel) 95%, transparent);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, .16);
    backdrop-filter: blur(16px);
    box-sizing: border-box;
  }
  html.studio-active body .studio-mobile-command-row,
  html.studio-active body .studio-mobile-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    min-width: 0;
  }
  html.studio-active body .studio-mobile-command-row { min-height: 44px; }
  html.studio-active body #studio-mobile-history-slot,
  html.studio-active body #studio-mobile-export-slot,
  html.studio-active body #studio-mobile-page-slot,
  html.studio-active body #studio-mobile-zoom-slot { display: flex; align-items: center; min-width: 0; }
  html.studio-active body #studio-mobile-history-slot .studio-tool-group,
  html.studio-active body #studio-mobile-export-slot .studio-tool-group { display: flex; align-items: center; gap: 5px; }
  html.studio-active body #studio-mobile-export-slot { flex: 1 1 auto; justify-content: flex-end; }
  html.studio-active body #studio-mobile-export-slot .studio-export-group { margin-left: 0 !important; }
  html.studio-active body #studio-mobile-export-slot #clear-canvas-btn { min-width: 44px !important; padding: 0 8px; }
  html.studio-active body #studio-mobile-export-slot #clear-canvas-btn .tool-btn-text,
  html.studio-active body #studio-mobile-history-slot .tool-btn-text { display: none !important; }
  html.studio-active body #studio-mobile-export-slot #save-studio-btn { min-width: 112px; min-height: 44px; padding: 8px 12px; white-space: nowrap; }
  html.studio-active body .studio-mobile-status-row { min-height: 44px; }
  html.studio-active body .studio-mobile-dock-btn {
    display: inline-flex;
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1px;
    width: auto;
    min-width: 58px;
    padding: 3px 6px;
    border: 1px solid var(--border-light);
    border-radius: 9px;
    background: var(--bg-panel-alt);
    color: var(--text-main);
    font-size: 9px;
    line-height: 1.1;
    white-space: nowrap;
  }
  html.studio-active body .studio-mobile-dock-btn > span:first-child { font-size: 15px; }
  html.studio-active body #studio-mobile-page-slot { flex: 0 0 auto; }
  html.studio-active body #studio-mobile-page-slot #page-indicator { display: inline-flex; align-items: center; gap: 3px; padding: 4px; }
  html.studio-active body #studio-mobile-page-slot #page-jump-input { width: 36px; min-width: 36px; height: 34px; padding: 0 2px; font-size: 13px; text-align: center; }
  html.studio-active body #studio-mobile-page-slot #page-total-indicator { min-width: 17px; text-align: center; font-size: 12px; }
  html.studio-active body #studio-mobile-zoom-slot { flex: 0 1 auto; min-width: 0; justify-content: center; overflow: hidden; }
  html.studio-active body #studio-mobile-zoom-slot .studio-tool-group { display: inline-flex; align-items: center; gap: 3px; max-width: 100%; }
  html.studio-active body #studio-mobile-zoom-slot button { width: 32px !important; min-width: 32px !important; height: 38px !important; min-height: 38px !important; padding: 0 !important; }
  html.studio-active body #studio-mobile-zoom-slot .zoom-select { width: 52px !important; min-width: 52px !important; height: 38px !important; min-height: 38px !important; line-height: 38px !important; padding: 0 2px !important; font-size: 11px !important; text-align: center !important; text-align-last: center !important; }
  html.studio-active body .studio-mobile-properties-panel {
    display: block;
    position: fixed;
    inset: auto 8px calc(174px + env(safe-area-inset-bottom, 0px)) auto;
    z-index: 960;
    width: min(320px, calc(100vw - 16px));
    max-height: min(48dvh, 420px);
    overflow: auto;
    padding: 12px;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    background: var(--bg-panel);
    color: var(--text-main);
    box-shadow: 0 18px 48px rgba(0, 0, 0, .34);
    box-sizing: border-box;
  }
  html.studio-active body .studio-mobile-properties-panel[hidden] { display: none !important; }
  html.studio-active body .studio-mobile-properties-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
  html.studio-active body .studio-mobile-properties-header > div { display: grid; gap: 3px; }
  html.studio-active body .studio-mobile-properties-header span { color: var(--text-muted); font-size: 12px; }
  html.studio-active body #studio-mobile-properties-close { width: 40px; min-width: 40px !important; border: 1px solid var(--border-light); border-radius: 8px; background: var(--bg-panel-alt); color: var(--text-main); font-size: 22px; }
  html.studio-active body #studio-mobile-properties-slot .editor-style-group { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0; }
  html.studio-active body #studio-mobile-properties-slot .editor-delete-obj-btn { flex: 1 1 100%; }
  html.studio-active body .studio-mobile-pages-close { min-height: 40px !important; }

  body:not(.studio-active) .main-area,
  body:not(.studio-active) .dynamic-workspace { min-width: 0; }
  body:not(.studio-active) .mobile-workspace-bar { z-index: 1000; }
}

@media (max-width: 420px) {
  #app-shell.ai-active .ai-chat-header { flex-wrap: wrap; align-items: center; }
  #app-shell.ai-active #ai-chat-clear-btn,
  #app-shell.ai-active #ai-upload-inline-btn { flex: 0 0 auto !important; align-self: center !important; }
  html.studio-active body .studio-mobile-dock { padding-inline: 5px; }
  html.studio-active body .studio-mobile-dock-btn { width: auto; min-width: 54px; padding: 3px 5px; }
  html.studio-active body #studio-mobile-page-slot #page-jump-input { width: 32px; min-width: 32px; }
  html.studio-active body #studio-mobile-zoom-slot button { width: 34px; min-width: 34px !important; }
  html.studio-active body #studio-mobile-zoom-slot .zoom-select { width: 50px; min-width: 50px; padding: 0 2px !important; }
  html.studio-active body #studio-mobile-export-slot #save-studio-btn { min-width: 104px; }
}

/* Keep tool actions readable at narrow laptop widths and keep every grid inside its viewport. */
@media (min-width: 901px) and (max-width: 1200px) {
  #app-shell.ai-active .ai-studio-container { grid-template-columns: minmax(0, 1fr) minmax(280px, 32%) !important; gap: 12px; }
  #app-shell.ai-active .ai-chat-header { padding-inline: 14px; }
  #app-shell.ai-active .ai-chat-messages { padding: 16px; }
  .action-bar { flex-wrap: wrap; }
  #run-button { flex: 0 0 auto; max-width: 100%; white-space: nowrap; }
}

html, body { max-width: 100%; }
#app-shell.ai-active,
#app-shell.ai-active .main-area,
#app-shell.ai-active .dynamic-workspace,
#app-shell.ai-active #view-ai-studio,
#app-shell.ai-active .ai-studio-container,
#app-shell.ai-active .ai-chat-card,
html.studio-active body,
html.studio-active body #app-shell,
html.studio-active body .main-area,
html.studio-active body .dynamic-workspace,
html.studio-active body #view-pdf-studio,
html.studio-active body .pdf-studio,
html.studio-active body .studio-main-viewport { min-width: 0; max-width: 100%; box-sizing: border-box; }

/* V6 verification corrections: internal toolbar scrolling, isolated mobile
   controls, and chat input clear of the fixed workspace navigation. */
@media (max-width: 900px) {
  #app-shell.ai-active .ai-chat-card {
    height: min(56dvh, calc(100dvh - 330px), 640px) !important;
    min-height: min(300px, calc(100dvh - 350px)) !important;
  }

  html.studio-active body .studio-primary-ribbon {
    flex: 0 0 50px !important;
    flex-flow: row nowrap !important;
    min-height: 50px !important;
    max-height: 50px !important;
    height: 50px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }
  html.studio-active body .studio-toolbar {
    position: relative !important;
    z-index: 200 !important;
  }
  html.studio-active body .studio-sub-ribbon {
    flex: 0 0 54px !important;
    flex-flow: row nowrap !important;
    min-height: 54px !important;
    max-height: 54px !important;
    height: 54px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
    overscroll-behavior-inline: contain;
  }
  html.studio-active body .studio-primary-ribbon > *,
  html.studio-active body .studio-sub-ribbon > *,
  html.studio-active body .studio-tool-group,
  html.studio-active body .studio-mode-switcher,
  html.studio-active body .studio-dropdown-wrapper {
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    min-width: max-content !important;
  }
  html.studio-active body .studio-mobile-dock {
    bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  }
  html.studio-active body .studio-thumbnails-bar {
    inset: var(--studio-mobile-pages-top, 252px) 8px calc(174px + env(safe-area-inset-bottom, 0px)) 8px !important;
    width: auto !important;
    max-height: none !important;
    min-height: 0 !important;
  }
  html.studio-active body .studio-thumbnails-scroll {
    max-height: none !important;
  }
  html.studio-active body .studio-mobile-properties-panel {
    max-height: min(32dvh, 300px);
  }
  html.studio-active body .toast-notice {
    top: calc(64px + env(safe-area-inset-top, 0px));
    bottom: auto;
    z-index: 3100;
  }
  #app-shell.ai-active .ai-chat-card {
    height: min(56dvh, calc(100dvh - 410px), 640px) !important;
    min-height: min(280px, calc(100dvh - 430px)) !important;
  }
  #app-shell.ai-active .ai-studio-wrapper:has(#ai-active-doc-bar:not([hidden])) .ai-chat-card {
    height: min(56dvh, calc(100dvh - 472px), 640px) !important;
    min-height: min(260px, calc(100dvh - 492px)) !important;
  }
}

@media (max-width: 420px) {
  #app-shell.ai-active .ai-chat-card {
    height: min(56dvh, calc(100dvh - 410px), 640px) !important;
    min-height: min(280px, calc(100dvh - 430px)) !important;
  }
  #app-shell.ai-active .ai-studio-wrapper:has(#ai-active-doc-bar:not([hidden])) .ai-chat-card {
    height: min(56dvh, calc(100dvh - 472px), 640px) !important;
    min-height: min(260px, calc(100dvh - 492px)) !important;
  }
}

/* On wide screens the AI workspace flows vertically inside a scrollable main
   column so the global footer remains below the workspace without clipping or
   overlapping the AI Chat input or Executive Summarizer at 1024px-1280px. */
@media (min-width: 901px) {
  #app-shell.ai-active {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  #app-shell.ai-active .main-area {
    height: 100dvh !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    scroll-padding-top: 76px;
  }
  #app-shell.ai-active .dynamic-workspace {
    flex: 0 0 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: calc(100dvh - 64px) !important;
    overflow: visible !important;
  }
  #app-shell.ai-active .ai-studio-wrapper,
  #app-shell.ai-active #view-ai-studio {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    height: auto !important;
    min-height: calc(100dvh - 88px);
    overflow: visible !important;
    padding-bottom: 12px;
    box-sizing: border-box;
  }
  #app-shell.ai-active .ai-studio-topbar { flex: 0 0 auto; }
  #app-shell.ai-active .ai-studio-container {
    flex: 1 1 auto;
    height: auto !important;
    min-height: min(520px, calc(100dvh - 330px)) !important;
  }
  #app-shell.ai-active .app-global-footer {
    display: flex !important;
    flex-shrink: 0;
    margin-top: 12px;
  }
}

/* V7: reserved AI result areas keep the same panel geometry while a request
   starts, completes, or fails. AI providers do not expose truthful progress,
   so the bar is deliberately indeterminate and labelled as waiting. */
.studio-mobile-page-actions { display: none !important; }
#app-shell.ai-active .ai-card-heading-row { min-height: 36px; flex-wrap: nowrap; gap: 8px; }
#app-shell.ai-active .ai-card-heading-row h4 { flex: 1 1 auto; min-width: 0; }
#app-shell.ai-active .ai-card-heading-row .view-header-badge { flex: 0 0 auto; }
#app-shell.ai-active .chat-markdown .ai-citation-tag { margin-inline: 2px; vertical-align: middle; }
#app-shell.ai-active .ai-chat-messages:has(#ai-empty-state:not([hidden])) { padding-block-start: 20px; }
#app-shell.ai-active .ai-studio-topbar { min-height: 82px; }
#app-shell.ai-active .ai-active-doc-strip { min-height: 54px; box-sizing: border-box; }
#app-shell.ai-active .ai-doc-details { overflow: hidden; }
#app-shell.ai-active .ai-doc-details strong,
#app-shell.ai-active .ai-doc-meta-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#app-shell.ai-active .summary-runtime-slot,
#app-shell.ai-active .extract-runtime-slot {
  display: flex;
  flex: 0 0 44px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
}
#app-shell.ai-active .summary-progress:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 10px;
  width: 100%;
  min-width: 0;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
}
#app-shell.ai-active .summary-progress-track {
  grid-column: 1 / -1;
  height: 4px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--bg-panel-alt);
}
#app-shell.ai-active .summary-progress-track > span {
  display: block;
  width: 34%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: aiIndeterminate 1.25s ease-in-out infinite alternate;
}
@keyframes aiIndeterminate { from { transform: translateX(-35%); } to { transform: translateX(200%); } }
#app-shell.ai-active .summary-actions-slot {
  display: flex;
  flex: 0 0 38px;
  align-items: center;
  min-width: 0;
  min-height: 38px;
}
#app-shell.ai-active #summary-actions-bar:not([hidden]) { display: flex !important; width: 100%; }
#app-shell.ai-active #summary-display {
  flex: 1 1 auto;
  min-height: 112px;
  max-height: none;
  box-sizing: border-box;
  white-space: normal;
  overflow-wrap: anywhere;
  overflow-y: auto;
  line-height: 1.55;
}
#app-shell.ai-active .extract-runtime-slot { color: var(--text-muted); font-size: 11px; line-height: 1.35; }
#app-shell.ai-active .extract-runtime-slot #extract-runtime-status:not([hidden]) { display: block; min-width: 0; }
#app-shell.ai-active .extract-runtime-slot #extract-cancel-btn:not([hidden]) { display: inline-flex; min-height: 36px; align-items: center; flex: 0 0 auto; }
#app-shell.ai-active #trigger-extract-btn,
#app-shell.ai-active #trigger-summary-btn { min-height: 46px; flex: 0 0 46px; }

/* Studio becomes a true full-width workspace. The app footer remains after the
   editor in the normal document flow, so it is reached by scrolling. */
@media (min-width: 901px) {
  #app-shell.ai-active .ai-studio-topbar { min-height: 91px; }
  .main-area.studio-active { height: 100dvh !important; min-height: 0 !important; overflow-x: hidden !important; overflow-y: auto !important; scroll-padding-top: 76px; }
  .studio-active .dynamic-workspace { flex: 0 0 auto !important; width: 100% !important; height: auto !important; min-height: calc(100dvh - 64px) !important; overflow: visible !important; }
  .studio-active #view-pdf-studio { height: calc(100dvh - 80px) !important; min-height: 480px !important; overflow: visible !important; }
  .studio-active .pdf-studio { width: 100% !important; height: 100% !important; min-height: 480px !important; max-height: none !important; overflow: visible !important; grid-template-columns: clamp(190px, 20vw, 280px) minmax(0, 1fr) !important; }
  .studio-active .studio-main-viewport { overflow: visible !important; }
  .studio-active .studio-toolbar { position: sticky !important; top: var(--topbar-height, 76px) !important; z-index: 110 !important; }
  .studio-active .studio-thumbnails-bar { position: sticky; top: var(--topbar-height, 76px); align-self: start; height: calc(100dvh - var(--topbar-height, 76px)) !important; }
  .studio-pages-collapsed #view-pdf-studio { grid-template-columns: minmax(0, 1fr) !important; }
  .studio-pages-collapsed #studio-thumbnails-bar { display: none !important; }
  .studio-pages-toggle-btn { display: inline-flex; }
  .studio-active .app-global-footer { display: flex !important; margin-top: 12px; }
  .studio-active .studio-primary-ribbon,
  .studio-active .studio-sub-ribbon { flex-wrap: wrap !important; align-content: center; max-height: none !important; height: auto !important; overflow: visible !important; gap: 5px; padding: 5px 8px; }
  .studio-active .studio-tool-btn { min-height: 34px !important; padding: 4px 7px !important; font-size: 11px; gap: 4px; }
  .studio-active .studio-mode-btn { min-height: 32px; padding: 4px 8px; }
}

/* Four small touch rows replace the cramped sideways mobile ribbons. Page
   insertion/extraction/deletion moves into the Pages panel; history, export,
   zoom, and page navigation already live in the bottom dock. */
@media (max-width: 900px) {
  .studio-pages-toggle-btn { display: none !important; }
  #app-shell.ai-active .ai-studio-topbar { min-height: 118px; justify-content: flex-start; }
  #app-shell.ai-active .ai-active-doc-strip { min-height: 58px; align-items: center; padding: 8px 10px; }
  #app-shell.ai-active .ai-doc-info-group { flex: 1 1 0; flex-wrap: nowrap; min-width: 0; }
  #app-shell.ai-active .ai-doc-status-badge { display: none; }
  #app-shell.ai-active .ai-doc-actions { flex: 0 0 auto; width: auto; }
  #app-shell.ai-active .ai-doc-actions button { min-height: 38px; padding-inline: 9px !important; }
  #app-shell.ai-active .ai-chat-card { height: min(52dvh, 460px) !important; min-height: min(360px, 52dvh) !important; max-height: 460px !important; }
  #app-shell.ai-active .ai-studio-wrapper:has(#ai-active-doc-bar:not([hidden])) .ai-chat-card { height: min(52dvh, 460px) !important; min-height: min(360px, 52dvh) !important; }
  #app-shell.ai-active .ai-studio-container > div:last-child > .ai-chat-card:first-child { height: 300px !important; min-height: 300px !important; max-height: 300px !important; }
  #app-shell.ai-active .ai-studio-container > div:last-child > .ai-chat-card:last-child { height: 390px !important; min-height: 390px !important; max-height: 390px !important; }
  #app-shell.ai-active .ai-studio-wrapper:has(#ai-active-doc-bar:not([hidden])) .ai-studio-container > div:last-child > .ai-chat-card:first-child { height: 300px !important; min-height: 300px !important; max-height: 300px !important; }
  #app-shell.ai-active .ai-studio-wrapper:has(#ai-active-doc-bar:not([hidden])) .ai-studio-container > div:last-child > .ai-chat-card:last-child { height: 390px !important; min-height: 390px !important; max-height: 390px !important; }
  #app-shell.ai-active #summary-display { min-height: 140px; max-height: 280px; }
  #app-shell.ai-active .summary-runtime-slot,
  #app-shell.ai-active .extract-runtime-slot { flex-basis: 48px; min-height: 48px; }
  #app-shell.ai-active .summary-actions-slot { flex-basis: 40px; min-height: 40px; }

  html.studio-active body { overflow-x: clip !important; overflow-y: auto !important; }
  html.studio-active body #app-shell { min-height: 100dvh !important; height: auto !important; overflow: visible !important; padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important; }
  html.studio-active body .studio-canvas-area { padding-bottom: calc(196px + env(safe-area-inset-bottom, 0px)) !important; }
  html.studio-active body #app-shell .main-area { height: auto !important; min-height: 100dvh !important; overflow: visible !important; padding-bottom: 0 !important; }
  html.studio-active body #app-shell .dynamic-workspace { height: auto !important; min-height: 0 !important; overflow: visible !important; padding-bottom: 12px !important; }
  html.studio-active body #view-pdf-studio { height: auto !important; min-height: 0 !important; overflow: visible !important; }
  html.studio-active body .pdf-studio { height: calc(100dvh - 150px) !important; min-height: 480px !important; max-height: none !important; overflow: hidden !important; }
  html.studio-active body .app-global-footer { display: flex !important; margin: 12px 8px 0; padding: 14px 12px calc(90px + env(safe-area-inset-bottom, 0px)); }
  html.studio-active body .studio-primary-ribbon,
  html.studio-active body .studio-sub-ribbon { flex-flow: row wrap !important; align-content: center !important; justify-content: flex-start !important; flex: 0 0 auto !important; gap: 4px !important; height: auto !important; min-height: 0 !important; max-height: none !important; overflow: visible !important; padding: 4px 6px !important; }
  html.studio-active body .studio-primary-ribbon { flex-flow: row wrap !important; align-content: center !important; justify-content: flex-start !important; flex: 0 0 auto !important; gap: 4px !important; height: auto !important; min-height: 0 !important; max-height: none !important; overflow: visible !important; padding: 4px 6px !important; }
  html.studio-active body .studio-toolbar { height: auto !important; min-height: 0 !important; max-height: none !important; overflow: visible !important; }
  html.studio-active body .studio-primary-ribbon > *,
  html.studio-active body .studio-sub-ribbon > * { min-width: 0 !important; max-width: 100%; }
  html.studio-active body .studio-primary-ribbon > .studio-tool-group,
  html.studio-active body .studio-sub-ribbon > .studio-tool-group { flex: 0 1 auto !important; flex-wrap: wrap !important; min-width: 0 !important; max-width: 100%; }
  html.studio-active body #studio-clear-pdf-btn { width: auto !important; min-width: 56px !important; padding-inline: 5px !important; }
  html.studio-active body .studio-primary-ribbon > .studio-tool-group[title="Open Document"] { flex: 1 1 100% !important; }
  html.studio-active body .studio-sub-ribbon > .studio-tool-group[title="Annotation Tools"],
  html.studio-active body .studio-sub-ribbon > .studio-tool-group[title="Shapes & Media"] { flex: 1 1 100% !important; width: 100%; max-width: 100%; flex-wrap: wrap !important; }
  html.studio-active body .studio-primary-ribbon .studio-divider,
  html.studio-active body .studio-sub-ribbon .studio-divider { display: none !important; }
  html.studio-active body .studio-tool-group { gap: 4px !important; }
  html.studio-active body .studio-tool-btn,
  html.studio-active body .studio-mode-btn { width: 56px !important; min-width: 56px !important; height: 48px !important; min-height: 48px !important; padding: 4px 2px !important; flex-direction: column !important; justify-content: center; gap: 2px !important; border-radius: 8px !important; box-sizing: border-box; }
  html.studio-active body .studio-tool-btn svg,
  html.studio-active body .studio-mode-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
  html.studio-active body .studio-tool-btn .tool-btn-text,
  html.studio-active body .studio-mode-btn span { display: block !important; max-width: 100%; overflow: visible; text-overflow: clip; white-space: normal; text-align: center; font-size: 9px; line-height: 1.08; }
  html.studio-active body .studio-mode-switcher { display: flex; flex: 0 0 auto !important; padding: 0; gap: 3px; }
  html.studio-active body .studio-dropdown-trigger { min-width: 56px !important; }
  html.studio-active body .studio-dropdown-trigger > svg:last-child { display: none; }
  html.studio-active body .studio-export-group { margin-left: 0 !important; }
  html.studio-active body .studio-save-btn { width: 92px !important; min-width: 92px !important; flex-direction: row !important; gap: 4px !important; }
  html.studio-active body .studio-mobile-page-actions { display: none !important; padding: 8px 10px; border-bottom: 1px solid var(--studio-border); background: #172023; }
  html.studio-active body #app-shell.studio-pages-open .studio-mobile-page-actions { display: block !important; }
  html.studio-active body .studio-mobile-page-actions-label { display: block; margin-bottom: 6px; color: #a4b7b4; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
  html.studio-active body #studio-mobile-page-actions-slot .studio-tool-group { display: flex; flex-wrap: wrap; gap: 5px; }
  html.studio-active body #studio-mobile-page-actions-slot .studio-tool-btn { width: auto !important; min-width: 68px !important; height: 40px !important; min-height: 40px !important; flex-direction: row !important; padding-inline: 8px !important; }
  html.studio-active body #studio-mobile-page-actions-slot .studio-tool-btn .tool-btn-text { font-size: 10px; }
}

@media (max-width: 900px) {
  #app-shell.ai-active .ai-studio-topbar { min-height: 118px; }
  html.studio-active body .studio-thumbnails-bar { max-height: min(40dvh, 300px) !important; }
  html.studio-active body .studio-thumbnails-scroll { max-height: none !important; min-height: 0 !important; }
}

@media (max-width: 380px) {
  html.studio-active body .studio-tool-btn,
  html.studio-active body .studio-mode-btn { width: 52px !important; min-width: 52px !important; }
  #app-shell.ai-active .ai-active-doc-strip { align-items: stretch; flex-wrap: wrap; gap: 6px 8px; }
  #app-shell.ai-active .ai-doc-info-group { flex: 1 0 100%; width: 100%; }
  #app-shell.ai-active .ai-doc-details { flex: 1 1 auto; width: 0; }
  #app-shell.ai-active .ai-doc-actions { flex: 1 0 100%; width: 100%; justify-content: flex-end; }
  #app-shell.ai-active .ai-doc-actions { gap: 4px; }
  #app-shell.ai-active .ai-doc-actions button { padding-inline: 7px !important; font-size: 11px !important; }
}

@media (max-width: 480px) {
  #app-shell.ai-active .ai-active-doc-strip { align-items: stretch; flex-wrap: wrap; gap: 6px 8px; }
  #app-shell.ai-active .ai-doc-info-group { flex: 1 0 100%; width: 100%; }
  #app-shell.ai-active .ai-doc-details { flex: 1 1 auto; width: 0; }
  #app-shell.ai-active .ai-doc-actions { flex: 1 0 100%; width: 100%; justify-content: flex-end; gap: 4px; }
  #app-shell.ai-active .ai-doc-actions button { padding-inline: 7px !important; font-size: 11px !important; }
}

/* Keep the workspace footer below the first viewport until the user scrolls. */
.app-global-footer { visibility: visible; opacity: 1; pointer-events: auto; transition: opacity .18s ease; }
html.footer-revealed .app-global-footer { visibility: visible; opacity: 1; pointer-events: auto; }

/* Keep the advanced desktop tool ribbons compact while preserving their
   two clear rows and leaving mobile touch targets at their larger size. */
@media (min-width: 1200px) {
  html.studio-active body .studio-toolbar .studio-primary-ribbon,
  html.studio-active body .studio-toolbar .studio-sub-ribbon {
    gap: 3px !important;
    padding: 2px 6px !important;
  }
  html.studio-active body .studio-toolbar .studio-tool-btn {
    min-height: 25px !important;
    padding: 2px 5px !important;
    gap: 2px !important;
    font-size: 9px !important;
  }
  html.studio-active body .studio-toolbar .studio-tool-btn svg {
    width: 13px;
    height: 13px;
  }
  html.studio-active body .studio-toolbar .studio-mode-btn {
    min-height: 25px !important;
    padding: 2px 6px !important;
    font-size: 9px !important;
  }
  html.studio-active body .studio-toolbar .studio-page-badge,
  html.studio-active body .studio-toolbar .zoom-select {
    min-height: 25px !important;
  }
}

/* Mid-size laptop viewports cannot show the complete Studio ribbon at once.
   Keep each control row compact and scrollable instead of wrapping it into
   five dense, hard-to-scan rows at the 901px desktop breakpoint. */
@media (min-width: 901px) and (max-width: 1023px) {
  html.studio-active body .studio-toolbar .studio-primary-ribbon,
  html.studio-active body .studio-toolbar .studio-sub-ribbon {
    flex-flow: row nowrap !important;
    align-items: center !important;
    gap: 4px !important;
    width: 100% !important;
    min-width: 0 !important;
    padding: 6px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    touch-action: pan-x;
    white-space: nowrap !important;
  }

  html.studio-active body .studio-toolbar .studio-primary-ribbon > *,
  html.studio-active body .studio-toolbar .studio-sub-ribbon > *,
  html.studio-active body .studio-toolbar .studio-primary-ribbon .studio-tool-group,
  html.studio-active body .studio-toolbar .studio-sub-ribbon .studio-tool-group {
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    width: max-content !important;
    max-width: none !important;
  }
}

/* Wrap Studio desktop ribbons cleanly above 1024px so right-side controls
   (Organize, More Tools, Export PDF, Stroke) never clip past the viewport edge. */
@media (min-width: 1024px) {
  html.studio-active body .studio-toolbar .studio-primary-ribbon,
  html.studio-active body .studio-toolbar .studio-sub-ribbon {
    flex-flow: row wrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    row-gap: 4px !important;
    overflow: visible !important;
    white-space: normal !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon > *,
  html.studio-active body .studio-toolbar .studio-sub-ribbon > *,
  html.studio-active body .studio-toolbar .studio-primary-ribbon > .studio-tool-group,
  html.studio-active body .studio-toolbar .studio-sub-ribbon > .studio-tool-group {
    flex: 0 0 auto !important;
    flex-wrap: wrap !important;
  }
}

@media (min-width: 901px) and (max-width: 1450px) {
  html.studio-active body .studio-toolbar .studio-primary-ribbon {
    gap: 0 !important;
    padding-inline: 2px !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon .tool-btn-text {
    display: none !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon .studio-tool-btn,
  html.studio-active body .studio-toolbar .studio-primary-ribbon .studio-mode-btn {
    padding-inline: 2px !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon .studio-export-group {
    margin-left: 0 !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon .zoom-select {
    width: 48px !important;
    min-width: 48px !important;
  }
}

/* Switching between the AI empty and uploaded-document states must not trigger
   browser scroll anchoring that shifts the whole workspace under its header. */
#app-shell.ai-active #view-ai-studio,
#app-shell.ai-active .ai-studio-wrapper { overflow-anchor: none; }

/* Sticky navigation uses a solid surface and a matching scroll offset so page
   headings and tool controls do not appear through the bar or land underneath it. */
.main-area { scroll-padding-top: 76px; }
.main-area > .dynamic-workspace { scroll-margin-top: 76px; }
.topbar { background-color: var(--bg-panel) !important; }
.view-header-bar, .tool-desk-container, .api-endpoints-section { scroll-margin-top: 84px; }

@media (min-width: 901px) and (max-width: 1180px) {
  .sidebar-sticky-footer #quota-container { padding: 8px 8px; }
  .sidebar-sticky-footer #quota-container .quota-label-row { gap: 4px 6px; font-size: 10.5px; white-space: normal; }
  .sidebar-sticky-footer #quota-container .quota-label-row > span:first-child { white-space: nowrap; }
  .sidebar-sticky-footer #quota-container #quota-text { min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: right; }
}

.platform-card.is-selected {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(255, 75, 38, 0.24) !important;
}

@media (max-width: 767px) {
  .mobile-nav-btn { font-size: 11px !important; line-height: 1.15; }
  /* Keep result details and next-step actions in a clear vertical reading order
     on narrow screens. A side-by-side card leaves only a sliver for the file
     details once all four actions are available. */
  #result.result-card {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  #result .result-info {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  #result .result-info small {
    display: block;
    overflow-wrap: anywhere;
  }
  .result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .result-actions > * { flex: 1 1 140px; min-width: 0; max-width: 100%; box-sizing: border-box; justify-content: center; white-space: normal; text-align: center; }
  #result .result-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  #result .result-actions > * {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }
  .result-actions .btn-download { min-height: 44px; box-sizing: border-box; }
  .toast-notice { top: auto !important; bottom: calc(168px + env(safe-area-inset-bottom, 0px)) !important; z-index: 3100 !important; }
  .settings-modal-card {
    width: min(96vw, 620px, calc(100vw - 48px)) !important;
    max-width: min(96vw, calc(100vw - 48px)) !important;
    flex: 0 1 auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    height: min(88dvh, 760px) !important;
    box-sizing: border-box !important;
    padding: 14px !important;
    overflow: hidden;
  }
  .settings-modal-card .settings-layout { min-width: 0; min-height: 0; overflow: hidden; }
  .settings-modal-card .settings-tabs {
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    padding: 8px;
    gap: 6px;
    box-sizing: border-box;
  }
  .settings-modal-card .settings-tab-btn {
    flex: 0 0 128px;
    min-width: 0 !important;
    min-height: 44px !important;
    padding: 7px 9px !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .settings-modal-card .settings-tab-btn small { display: none; }
  .settings-modal-card .settings-tab-btn > span:last-child { min-width: 0; }
  .settings-modal-card .settings-tab-btn strong,
  .settings-modal-card .settings-tab-btn small { overflow-wrap: anywhere; }
  .settings-modal-card .settings-content,
  .settings-modal-card .settings-pane { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
  .settings-modal-card .settings-content { flex: 1 1 auto; min-height: 0; padding: 12px 8px !important; overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; }
  .settings-modal-card .settings-card-item,
  .settings-modal-card .billing-status-summary,
  .settings-modal-card .api-info-callout { min-width: 0; max-width: 100%; box-sizing: border-box; padding: 14px; }
  .settings-modal-card .settings-card-item p,
  .settings-modal-card .settings-card-item h4 { overflow-wrap: anywhere; }

  .endpoints-table-wrapper { position: relative; overflow: hidden; }
  .endpoints-table, .endpoints-table tbody { display: block; width: 100%; min-width: 0; }
  .endpoints-table thead { display: none; }
  .endpoints-table tr { display: block; margin: 8px; border: 1px solid var(--border-light); border-radius: 8px; overflow: hidden; background: var(--bg-panel); }
  .endpoints-table td { display: grid; grid-template-columns: minmax(76px, 30%) minmax(0, 1fr); gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border-light); overflow-wrap: anywhere; }
  .endpoints-table td::before { content: attr(data-label); color: var(--text-muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
  .endpoints-table td code { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
  #view-api-docs, #view-legal, .api-docs-full-view, .api-docs-full-content, .api-docs-hero-box, .api-docs-meta-grid, .api-code-workbench-card, .api-code-wrapper, .legal-view-content-wrapper { min-width: 0; max-width: 100%; box-sizing: border-box; }
  #view-api-docs, #view-legal { overflow-x: hidden; }
  #view-api-docs .view-header-bar, #view-legal .view-header-bar { flex-wrap: wrap; gap: 10px; }
  #view-api-docs .view-header-actions { flex-wrap: wrap; width: 100%; }
  .api-docs-full-content pre, .api-docs-full-content .api-code-block { max-width: 100%; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--border-light); box-sizing: border-box; }
  .api-docs-full-content .api-code-block code { display: block; max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
}

@media (max-width: 480px) {
  html.studio-active body .studio-toolbar { height: auto !important; min-height: 0 !important; overflow: visible !important; }
  html.studio-active body .studio-primary-ribbon,
  html.studio-active body .studio-sub-ribbon {
    display: flex !important;
    flex-flow: row wrap !important;
    align-content: flex-start !important;
    justify-content: flex-start !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    white-space: normal !important;
  }
  html.studio-active body .studio-primary-ribbon > *,
  html.studio-active body .studio-sub-ribbon > *,
  html.studio-active body .studio-tool-group,
  html.studio-active body .studio-mode-switcher { min-width: 0 !important; max-width: 100%; }
  html.studio-active body .studio-sub-ribbon > .studio-tool-group[title="Page Operations"] { flex: 1 1 100% !important; flex-wrap: wrap !important; }
  html.studio-active body .studio-sub-ribbon > .studio-tool-group[title="Page Operations"] .studio-tool-btn { flex: 0 0 auto !important; }
  html.studio-active body .studio-primary-ribbon .zoom-select { width: 76px !important; min-width: 76px !important; }
  html.studio-active body .studio-tool-btn .tool-btn-text,
  html.studio-active body .studio-mode-btn span { font-size: 10px !important; }
  #app-shell.ai-active .ai-chat-messages:has(#ai-empty-state:not([hidden])) { min-height: 220px !important; max-height: none !important; overflow: visible !important; }
  #app-shell.ai-active #view-ai-studio { padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px)) !important; }
  #app-shell.ai-active .ai-empty-state { min-height: 0 !important; justify-content: flex-start !important; padding-block: 12px !important; }
  #app-shell.ai-active .ai-stage-line { flex-wrap: wrap; white-space: normal; }
}

/* ==========================================================================
   Google AdSense & Responsive Sponsorship Placement Containers
   ========================================================================== */
.adsense-banner-container {
  width: 100%;
  max-width: 960px;
  margin: 14px auto;
  padding: 6px 12px;
  background: var(--bg-surface, #ffffff);
  border: 1px dashed var(--border-subtle, rgba(0, 0, 0, 0.12));
  border-radius: 10px;
  box-sizing: border-box;
  text-align: center;
  transition: all 0.2s ease;
}

body.dark-mode .adsense-banner-container {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.1);
}

.adsense-banner-container .ad-disclaimer {
  font-size: 9px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted, #888888);
  margin-bottom: 4px;
}

.adsense-banner-container .ad-placeholder-box {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.adsense-banner-container .ad-clean-preview {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-normal, #333333);
}

.adsense-banner-container.post-download-ad {
  margin-top: 16px;
  background: rgba(59, 130, 246, 0.03);
  border-style: solid;
  border-color: rgba(59, 130, 246, 0.2);
}

/* Dedicated workspace routes share the controls used by their overlays. */
.workspace-page {
  width: min(100% - 32px, 1200px);
  margin: 32px auto;
  min-width: 0;
}
.workspace-page > h1,
.workspace-page > h2.workspace-fallback-heading { margin: 0 0 12px; font-size: clamp(1.5rem, 2.5vw, 2rem); font-weight: 800; line-height: 1.2; }
.workspace-page details {
  padding: 14px 18px;
  margin: 10px 0;
  border: 1px solid var(--border-light);
  border-radius: 10px;
}
.workspace-inline-panel > .modal-card {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0;
  flex-basis: auto;
  box-sizing: border-box;
  max-height: none;
  margin: 20px 0;
  overflow: visible;
}
.workspace-inline-panel .close-modal-btn { display: none; }
.workspace-inline-panel .settings-modal-card > .modal-header { display: none; }
@media (max-width: 767px) {
  .workspace-inline-panel > .settings-modal-card {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible;
  }
}
.app-global-footer .footer-right { flex-wrap: wrap; }

:root[data-paperplane-theme="dark"] { color-scheme: dark; background: #0e1416; }
:root[data-paperplane-theme="dark"] body.light-mode.auth-pending { background: #0e1416; }

/* Keep the Studio palette in sync with the account theme. The dark canvas used
   to ignore the saved Light Paper preference and made /studio look like a
   different theme from every other workspace. */
:root[data-paperplane-theme="light"] {
  --studio-bg: #edf1ef;
  --studio-panel: #ffffff;
  --studio-border: #d3ded8;
  --studio-page-shadow: 0 12px 32px rgba(20, 32, 35, 0.16);
}

:root[data-paperplane-theme="light"] .studio-thumbnails-bar,
:root[data-paperplane-theme="light"] .studio-main-viewport,
:root[data-paperplane-theme="light"] .studio-canvas-area,
:root[data-paperplane-theme="light"] .studio-toolbar,
:root[data-paperplane-theme="light"] .studio-primary-ribbon,
:root[data-paperplane-theme="light"] .studio-sub-ribbon,
:root[data-paperplane-theme="light"] .studio-thumbnails-scroll,
:root[data-paperplane-theme="light"] .studio-mode-switcher,
:root[data-paperplane-theme="light"] .studio-dropdown-menu,
:root[data-paperplane-theme="light"] .studio-context-menu {
  background-color: #f8faf9;
  color: #142023;
}

:root[data-paperplane-theme="light"] .studio-tool-btn {
  background: #ffffff;
  border-color: #cbd7cf;
  box-shadow: 0 1px 3px rgba(20, 32, 35, 0.08);
}

:root[data-paperplane-theme="light"] .studio-mode-btn {
  color: #526367;
}

:root[data-paperplane-theme="light"] .studio-mode-btn.active {
  color: #ffffff;
}

:root[data-paperplane-theme="light"] .studio-dropdown-item {
  color: #26373a;
}

:root[data-paperplane-theme="light"] .studio-dropdown-item:hover {
  color: #142023;
  background: #e9efeb;
}

:root[data-paperplane-theme="light"] .studio-loading-overlay {
  background: #f8faf9;
  color: #142023;
}

:root[data-paperplane-theme="light"] .studio-loading-text {
  color: #26373a;
}

:root[data-paperplane-theme="light"] .studio-empty-state {
  color: #26373a;
}

:root[data-paperplane-theme="light"] .studio-empty-state p {
  color: #5e6f72;
}

:root[data-paperplane-theme="light"] .studio-empty-state button {
  border-color: #cbd7cf;
  background: #ffffff;
  color: #142023;
}

:root[data-paperplane-theme="light"] .studio-thumbnails-header {
  background: #eef3f0;
  color: #142023;
}

:root[data-paperplane-theme="light"] .organizer-header-title,
:root[data-paperplane-theme="light"] .studio-thumbnails-header .organizer-header-title {
  color: #142023 !important;
}

:root[data-paperplane-theme="light"] .org-head-btn {
  background: #ffffff !important;
  border-color: #cbd7cf !important;
  color: #142023 !important;
}

:root[data-paperplane-theme="light"] .org-head-btn:hover {
  background: #e9efeb !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

:root[data-paperplane-theme="light"] .organizer-empty-msg {
  color: #4b5e61 !important;
}

:root[data-paperplane-theme="light"] .studio-tool-btn,
:root[data-paperplane-theme="light"] .studio-mode-btn,
:root[data-paperplane-theme="light"] .thumb-card-footer,
:root[data-paperplane-theme="light"] .thumb-action-btn {
  color: #26373a;
}

:root[data-paperplane-theme="light"] .studio-mode-switcher {
  background: #e9efeb !important;
  border-color: #cbd7cf !important;
}

:root[data-paperplane-theme="light"] .studio-page-badge {
  background: #ffffff !important;
  color: #142023 !important;
  border-color: #cbd7cf !important;
}

:root[data-paperplane-theme="light"] .studio-page-badge input {
  color: #142023 !important;
}

:root[data-paperplane-theme="light"] .zoom-select,
:root[data-paperplane-theme="light"] .editor-stroke-select {
  background: #ffffff !important;
  border-color: #cbd7cf !important;
  color: #142023 !important;
}

:root[data-paperplane-theme="light"] .zoom-select option,
:root[data-paperplane-theme="light"] .editor-stroke-select option {
  background: #ffffff !important;
  color: #142023 !important;
}

:root[data-paperplane-theme="light"] .studio-tool-btn:hover,
:root[data-paperplane-theme="light"] .studio-mode-btn:hover,
:root[data-paperplane-theme="light"] .thumb-action-btn:hover {
  color: #142023;
  background-color: #e9efeb;
}

:root[data-paperplane-theme="light"] .studio-tool-btn.active,
:root[data-paperplane-theme="light"] .studio-mode-btn.active {
  color: #142023;
  background-color: #e5ece8;
}

/* Studio controls can be moved between ribbons and mobile slots. Keep the
   light-theme foreground explicit after those moves, including inline legacy
   toolbar styles that otherwise leave light text on the pale ribbon. */
html[data-paperplane-theme="light"] body.studio-active .studio-toolbar .studio-tool-btn:not(.active),
html[data-paperplane-theme="light"] body.studio-active .studio-toolbar .studio-mode-btn:not(.active) {
  color: #26373a !important;
}
html[data-paperplane-theme="light"] body.studio-active .studio-toolbar .studio-tool-btn.active,
html[data-paperplane-theme="light"] body.studio-active .studio-toolbar .studio-mode-btn.active {
  color: #142023 !important;
}

:root[data-paperplane-theme="light"] .thumb-card {
  background: #ffffff;
  border-color: #d3ded8;
}

:root[data-paperplane-theme="light"] .thumb-card.active {
  border-color: var(--accent);
}

/* Studio feedback must clear its variable-height ribbon before it appears. */
html.studio-active body .toast-notice {
  top: var(--studio-toast-top, 76px) !important;
}
html.studio-active body .toast-notice.toast-visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
@media (max-width: 600px) and (max-height: 900px) {
  html.studio-active body .toast-notice {
    max-width: calc(100vw - 24px);
    padding: 6px 10px;
    gap: 7px;
    font-size: 12px;
  }
}
h1, h2, h3, .tool-hero-title { word-spacing: .08em; }

.quota-label-row { gap: 6px 10px; flex-wrap: wrap; }
#quota-text, #settings-quota-text { white-space: normal; }
body:not(.dark-mode):not(.high-contrast) #run-button:disabled {
  opacity: 1 !important;
  color: #34464a !important;
  background: #f8faf9 !important;
  background-image: none !important;
  border: 1px solid #cbd7cf !important;
}
body.dark-mode #run-button:disabled,
body.high-contrast #run-button:disabled {
  opacity: 1 !important;
  color: #f0f5f4 !important;
  background: #1a2528 !important;
  background-image: none !important;
  border: 1px solid #475569 !important;
}
@media (min-width: 1024px) and (max-width: 1200px) {
  #app-shell .topbar { position: relative !important; top: auto !important; }
  #app-shell .workspace-tabs { position: static !important; transform: none !important; margin-inline: auto; }
}
@media (min-width: 901px) and (max-width: 1023px) {
  #app-shell .mobile-brand, #app-shell .mobile-view-pill { display: none !important; }
}
.pricing-modal-card { max-height: calc(100dvh - 32px); overflow: auto; }
.workspace-inline-panel > .pricing-modal-card { max-height: none; overflow: visible; }
@media (max-width: 480px) {
  .workspace-inline-panel .pricing-tiers-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

/* Browser zoom can make a desktop-sized window behave like a short mobile
   viewport. Keep the submit action in document flow so it cannot cover the
   current tool content above the fixed mobile navigation. */
@media (max-width: 900px) and (max-height: 600px) {
  html.studio-active body #app-shell.studio-pages-open .studio-thumbnails-bar {
    inset: var(--studio-mobile-pages-top, calc(8px + env(safe-area-inset-top, 0px))) 8px calc(8px + env(safe-area-inset-bottom, 0px)) 8px !important;
    top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    max-height: none !important;
    z-index: 970 !important;
  }

  html.studio-active body #app-shell.studio-pages-open .studio-thumbnails-scroll {
    max-height: none !important;
    gap: 4px !important;
    padding: 0 6px 4px !important;
  }

  html.studio-active body #app-shell.studio-pages-open .studio-thumbnails-scroll > .organizer-subnav {
    flex: 0 0 30px !important;
    min-height: 30px !important;
    margin: 0 0 3px !important;
    padding: 0 4px 3px !important;
  }

  html.studio-active body #app-shell.studio-pages-open .studio-thumbnails-scroll > .organizer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  html.studio-active body #app-shell.studio-pages-open .studio-mobile-page-actions {
    flex: 0 0 40px !important;
    max-height: 40px !important;
    min-height: 40px !important;
    overflow: hidden !important;
    padding: 2px 8px !important;
  }

  html.studio-active body #app-shell.studio-pages-open .studio-mobile-page-actions-label {
    display: none !important;
  }

  html.studio-active body #app-shell.studio-pages-open #studio-mobile-page-actions-slot .studio-tool-group {
    flex-wrap: nowrap !important;
    gap: 4px !important;
    overflow-x: auto;
  }

  html.studio-active body #app-shell.studio-pages-open #studio-mobile-page-actions-slot .studio-tool-btn {
    min-width: 44px !important;
    height: 34px !important;
    min-height: 34px !important;
    padding-inline: 5px !important;
  }

  body:not(.studio-active):not(.ai-active) #run-button {
    position: static;
    inset: auto;
    z-index: auto;
    width: 100%;
    max-width: 100%;
  }

  body:not(.studio-active):not(.ai-active) .main-area {
    padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* Layouts follow available space on phones and tablets; dialogs stay usable
   with the software keyboard open and long labels wrap inside their controls. */
@media (max-width: 900px) {
  .settings-modal-card {
    width: min(96vw, 620px, calc(100vw - 48px)) !important;
    max-width: min(96vw, calc(100vw - 48px)) !important;
    flex: 0 1 auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    height: min(88dvh, 760px) !important;
    max-height: calc(100dvh - 24px) !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  .settings-modal-card .settings-layout { flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
  .settings-modal-card .settings-tabs {
    flex: 0 0 auto; width: 100%; box-sizing: border-box;
    display: flex; flex-direction: row; flex-wrap: nowrap;
    overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch; touch-action: pan-x;
    padding: 8px; gap: 6px;
  }
  .settings-modal-card .settings-tab-btn { flex: 0 0 128px; width: auto; min-width: 0 !important; min-height: 44px !important; padding: 7px 9px !important; white-space: normal; overflow-wrap: anywhere; }
  .settings-modal-card .settings-tab-btn small { display: none; }
  .settings-modal-card .settings-content { flex: 1 1 auto; min-height: 0; min-width: 0; width: 100%; box-sizing: border-box; padding: 12px 8px; overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; }
  .workspace-inline-panel > .settings-modal-card { height: auto !important; max-height: none !important; overflow: visible !important; }
}
.modal-backdrop > .editor-sig-modal-card,
.modal-backdrop > .sign-modal-card,
.modal-backdrop > .security-modal-card {
  box-sizing: border-box;
  width: min(600px, calc(100% - 24px));
  min-width: 0;
  max-width: calc(100% - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
}
.editor-sig-tabs, .editor-sig-footer, .editor-sig-footer > div { flex-wrap: wrap; gap: 8px; }
.editor-sig-tab-btn { min-width: 0; white-space: normal; flex: 1 1 120px; }
.editor-sig-canvas { display: block; box-sizing: border-box; }
.editor-sig-modal-card .modal-header > div,
.sign-modal-card .modal-header > div,
.security-modal-card .modal-header > div { min-width: 0; overflow-wrap: anywhere; }
.modal-close { flex-shrink: 0; }

@media (max-width: 480px) {
  .app-global-footer .footer-left {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
  }
}
.sign-draw-field { min-width: 0; }
#sign-draw-canvas {
  display: block;
  width: min(100%, 560px);
  height: 144px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}
.sign-draw-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
#sign-draw-status { color: var(--text-muted); font-size: 12px; }
@media (max-width: 600px) {
  #sign-draw-canvas { height: 128px; }
  .sign-draw-actions button { min-height: 44px; }
}

@media (max-width: 480px) {
  #app-shell.ai-active .ai-stage-timeline {
    flex-wrap: wrap;
    overflow-x: visible;
    overflow-y: visible;
    gap: 5px;
    padding-bottom: 2px;
  }
}

@media (max-width: 600px) {
  /* Leave enough trailing scroll space for the final Settings tab to sit fully
     inside its horizontal rail after switchSettingsTab scrolls it into view. */
  .settings-modal-card .settings-tabs {
    padding-right: 24px !important;
  }
}

/* Keep Studio's phone toolbars compact: make each command ribbon a single
   horizontally scrollable row instead of wrapping every tool onto the page. */
@media (max-width: 900px) {
  html.studio-active body .sidebar.mobile-open {
    z-index: 1200 !important;
  }
  html.studio-active body .studio-toolbar {
    gap: 0 !important;
    overflow: hidden !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon {
    display: flex !important;
    flex: 0 0 auto !important;
    flex-flow: row wrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    padding: 5px 8px 8px !important;
    gap: 5px !important;
    box-sizing: border-box !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon > *,
  html.studio-active body .studio-toolbar .studio-primary-ribbon .studio-tool-group {
    flex: 0 1 auto !important;
    flex-wrap: wrap !important;
    width: auto !important;
    max-width: 100% !important;
  }
  html.studio-active body .studio-toolbar .studio-sub-ribbon {
    display: flex !important;
    flex: 0 0 auto !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 54px !important;
    max-height: none !important;
    height: auto !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 5px 12px 10px !important;
    gap: 6px !important;
    white-space: nowrap !important;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    touch-action: pan-x;
    box-sizing: border-box !important;
  }
  html.studio-active body .studio-toolbar .studio-sub-ribbon > *,
  html.studio-active body .studio-toolbar .studio-sub-ribbon .studio-tool-group {
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    width: max-content;
    max-width: none !important;
  }
  html.studio-active body .studio-toolbar .studio-tool-btn,
  html.studio-active body .studio-toolbar .studio-mode-btn {
    flex: 0 0 auto !important;
    min-width: 56px !important;
    width: auto !important;
    padding: 4px 8px !important;
    min-height: 44px !important;
    height: auto !important;
  }
  html.studio-active body .studio-toolbar .studio-divider { display: none !important; }
  html.studio-active body .studio-toolbar .studio-sub-ribbon > .studio-tool-group[title="Annotation Tools"],
  html.studio-active body .studio-toolbar .studio-sub-ribbon > .studio-tool-group[title="Shapes & Media"] {
    flex: 0 0 auto !important;
    width: max-content !important;
    max-width: none !important;
  }
}

/* An empty document-context bar has no content until a PDF is loaded. Collapse
   its reserved height so the mobile AI chat starts directly beneath the app
   header instead of leaving a blank 118px band. Keep the bar when document or
   connection controls become visible. */
#app-shell.ai-active .ai-studio-topbar:has(#ai-active-doc-bar[hidden]):not(:has(#ai-test-connection-btn:not([hidden]), .ai-connection-status:not([hidden]))) {
  min-height: 0 !important;
  gap: 0 !important;
}
#app-shell.ai-active .ai-studio-topbar:has(#ai-active-doc-bar[hidden]):not(:has(#ai-test-connection-btn:not([hidden]), .ai-connection-status:not([hidden]))) .ai-engine-notice-bar {
  display: none !important;
}

/* Keep focused AI actions visible above the fixed mobile workspace bar. */
@media (max-width: 900px) {
  html {
    scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

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

  .dynamic-workspace,
  .ai-studio-main,
  .ai-chat-thread,
  #pricing-modal.workspace-inline-panel {
    scroll-padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  }
}

/* Success toasts must not sit on top of the result card's next-step actions. */
.toast-notice.toast-result-aware-success {
  top: var(--toast-download-top, 76px) !important;
  bottom: auto !important;
  animation: none;
}

/* Retain the live-region announcement when no visible toast position is safe. */
.toast-notice.toast-visually-hidden {
  position: fixed !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Reduce unused vertical gaps on phone-sized tool pages. The upload form stays
   in document flow, while its primary action gets clear of the fixed bottom
   navigation in compact single-step workflows such as Merge and Rotate. */
@media (max-width: 600px) {
  .dynamic-workspace { padding-block-start: 12px !important; }
  .tool-desk-container { gap: 8px; }
  .tool-desk-nav-bar { margin-block-end: 4px; }
  .tool-desk-nav-bar { min-height: 0; padding-block: 2px 4px; }
  .tool-desk-nav-bar .btn-back-home { min-height: 34px; padding: 4px 10px; font-size: 12px; }
  .tool-hero-card { padding: 6px 12px !important; gap: 4px !important; }
  #tool-title { font-size: clamp(17px, 4.6vw, 20px) !important; line-height: 1.15; }
  #tool-tier-badge { font-size: 10px !important; padding: 2px 7px !important; }
  #tool-description { display: none; }
  .dropzone { padding-block: 12px; }
  .dropzone { padding-inline: 10px !important; }
  .drop-icon-circle { width: 32px; height: 32px; margin-bottom: 4px; font-size: 14px; }
  .dropzone h2 { font-size: 15px; margin-bottom: 2px; }
  .dropzone p { margin-bottom: 4px; font-size: 11px; line-height: 1.3; }
  .dropzone small { font-size: 10px; line-height: 1.25; }
  .dropzone-options { gap: 4px; }
  .dropzone-option { min-height: 30px; font-size: 11.5px; }
  .options-panel { padding: 10px 12px; gap: 8px; }
  .option-field { gap: 3px; font-size: 11.5px; line-height: 1.3; }
  .option-field label { font-size: 10.5px; margin-bottom: 0; }
  .option-field p, .option-field small { margin-block: 0; font-size: 11px; line-height: 1.28; }
  .options-panel select, .options-panel input:not([type="checkbox"]):not([type="radio"]) { min-height: 36px; padding-block: 6px; font-size: 13px; }
  .action-bar { padding-block: 0; gap: 6px; }
  #run-button { min-height: 44px; padding-block: 9px; }
  #options:has(#title) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  #options:has(#title) { grid-template-columns: minmax(0, 1fr); }
}

/* Hide promotional / house ad banners and upgrade nudges for paid accounts. */
body.is-paid-plan .adsense-banner-container,
body.is-paid-plan #sidebar-upgrade-btn,
body.is-paid-plan #topbar-upgrade-btn,
body.is-paid-plan #ad-banner-upgrade-link,
body.is-paid-plan [data-house-ad] {
  display: none !important;
}

/* Ensure the 480px Log In control stays single-row, clear of icons, and >=44px tall. */
@media (max-width: 480px) {
  .topbar-right > :not(#topbar-auth-guest):not(#topbar-auth-user):not(#install-app-btn),
  #topbar-cloud-btn,
  #topbar-register-btn,
  .topbar-upgrade-pill {
    display: none !important;
  }
  #topbar-auth-guest:not([hidden]),
  #topbar-auth-user:not([hidden]) {
    display: inline-flex !important;
    align-items: center !important;
  }
  #topbar-signin-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 44px !important;
    padding: 7px 12px !important;
    font-size: 12px !important;
    white-space: nowrap !important;
  }
}

/* Dark / Light Theme parity for PDF Studio and AI Document Intelligence */
body.light-mode .pdf-studio {
  --studio-bg: #e7ecea;
  --studio-panel: #f4f7f5;
  --studio-border: #cfd9d4;
  background: #e7ecea;
}
body.light-mode .studio-thumbnails-bar {
  background: #f4f7f5;
  border-right-color: #cfd9d4;
}
body.light-mode .studio-thumbnails-header,
body.light-mode .studio-toolbar,
body.light-mode .studio-primary-ribbon,
body.light-mode .studio-sub-ribbon,
body.light-mode .organizer-selection-panel {
  background: #ffffff;
  color: #142023;
  border-color: #d3ded4;
}
body.light-mode .studio-tool-btn,
body.light-mode .studio-mode-btn,
body.light-mode .cluster-btn,
body.light-mode .batch-subtle-btn,
body.light-mode .org-head-btn,
body.light-mode .org-sub-btn {
  color: #142023;
  background: #f4f7f5;
  border-color: #cbd7cf;
}
body.light-mode .studio-mode-btn.active,
body.light-mode .studio-tool-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
body.light-mode .organizer-thumb-card {
  background: #ffffff;
  color: #142023;
  border-color: #cbd7cf;
}
body.light-mode .studio-page-badge,
body.light-mode .studio-toolbar .zoom-select,
body.light-mode .action-cluster {
  background: #f4f7f5;
  color: #142023;
  border-color: #cbd7cf;
}
body.dark-mode .ai-chat-card,
body.dark-mode .ai-howto-section,
body.dark-mode .ai-active-doc-strip,
body.dark-mode .ai-summary-card,
body.dark-mode .ai-extract-card {
  background: var(--bg-panel);
  color: var(--text-main);
  border-color: var(--border-light);
}
body.dark-mode .ai-engine-pill,
body.dark-mode .ai-howto-steps li,
body.dark-mode #summary-display {
  background: var(--bg-panel-alt);
  color: var(--text-main);
  border-color: var(--border-light);
}
.dashboard-redirect-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 14px 18px;
  margin-bottom: 18px;
  border-radius: 12px;
  border: 1px solid rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.1);
  color: var(--text-main);
}
.dashboard-redirect-notice[hidden] { display: none; }
.dashboard-redirect-copy {
  display: grid;
  gap: 3px;
  font-size: 13px;
  line-height: 1.5;
  flex: 1 1 320px;
}
.dashboard-redirect-copy strong {
  font-size: 14px;
  font-weight: 700;
}
.dashboard-redirect-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.seo-content h1#seo-page-heading {
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.03em;
  line-height: 1.08;
  margin: 0 0 14px;
  color: var(--text-main);
}
#app-shell.public-info-active .dynamic-workspace {
  display: none;
}
#app-shell.public-info-active .seo-content {
  margin-top: 0;
  border-top: 0;
}
.seo-content a:not(.seo-related-link):not(.btn-primary-action):not(.btn-demo-upgrade) {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ID 463: Studio Server badge on server-backed dropdown actions */
.studio-server-pill {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
  opacity: 0.78;
}

/* ID 465 / 622 / 632: Keep auth-pending hook without grey pill overlay covering header controls */
.auth-pending .topbar-right {
  position: relative;
}
.auth-pending .topbar-right::before {
  content: "";
  display: none;
  width: 0;
  height: 0;
  pointer-events: none;
}
.auth-pending #quota-container {
  position: relative;
}
.auth-pending #quota-text,
.auth-pending #settings-quota-text {
  user-select: text;
}

.translation-warnings-list {
  margin: 6px 0 0 18px;
  padding: 0;
  font-size: 13px;
  line-height: 1.45;
}

.security-overview-card {
  margin: 18px 0 22px;
  padding: 18px 20px;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  background: var(--bg-panel);
}

.security-overview-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.security-overview-card p,
.security-overview-card li {
  line-height: 1.6;
  color: var(--text-muted);
}

.security-overview-card ul {
  margin: 10px 0 0 18px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.google-popup-fallback-btn {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

/* ID 475: High-contrast /download hero copy in light and dark themes */
.download-hero-banner {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
}
body.light-mode .download-hero-banner {
  background: #f8fafc;
  color: #0f172a;
  border-color: #cbd5e1;
}
body.light-mode .download-hero-text h1,
body.light-mode .download-hero-text h2,
body.light-mode .download-hero-text h3 {
  color: #0f172a;
}
body.light-mode .download-hero-text p {
  color: #334155;
}
body.dark-mode .download-hero-banner,
body:not(.light-mode) .download-hero-banner {
  background: #162326;
  color: #f1f5f9;
  border-color: rgba(148, 163, 184, 0.25);
}
body.dark-mode .download-hero-text h1,
body.dark-mode .download-hero-text h2,
body.dark-mode .download-hero-text h3,
body:not(.light-mode) .download-hero-text h1,
body:not(.light-mode) .download-hero-text h2,
body:not(.light-mode) .download-hero-text h3 {
  color: #f8fafc;
}
body.dark-mode .download-hero-text p,
body:not(.light-mode) .download-hero-text p {
  color: #cbd5e1;
}

/* ID 474: Keep Scan to PDF compact in flow so #run-button fits inside standard desktop viewports without overlapping #options */
.dynamic-workspace:has(#scan-camera-control:not([hidden])) {
  padding-top: 8px !important;
}
#view-tool-desk:has(#scan-camera-control:not([hidden])) {
  gap: 8px;
}
#view-tool-desk:has(#scan-camera-control:not([hidden])) .tool-desk-nav-bar {
  margin-bottom: 0;
  padding-block: 0 2px;
}
#view-tool-desk:has(#scan-camera-control:not([hidden])) .tool-hero-card {
  padding: 10px 16px;
}
#view-tool-desk:has(#scan-camera-control:not([hidden])) .tool-hero-card h1 {
  font-size: 20px;
  margin-bottom: 2px;
}
#view-tool-desk:has(#scan-camera-control:not([hidden])) .tool-hero-card p {
  font-size: 12.5px;
  line-height: 1.35;
}
#view-tool-desk:has(#scan-camera-control:not([hidden])) .tool-hero-meta-row {
  margin-bottom: 2px !important;
}
#job-form:has(#scan-camera-control:not([hidden])) {
  display: grid;
  gap: 8px;
}
#job-form:has(#scan-camera-control:not([hidden])) .dropzone {
  padding-block: 8px;
  gap: 3px;
}
#job-form:has(#scan-camera-control:not([hidden])) .drop-icon-circle {
  width: 30px;
  height: 30px;
  margin-bottom: 2px;
}
#job-form:has(#scan-camera-control:not([hidden])) .dropzone h2 {
  font-size: 15px;
  margin-bottom: 1px;
}
#job-form:has(#scan-camera-control:not([hidden])) .dropzone p {
  margin-bottom: 2px;
}
#job-form:has(#scan-camera-control:not([hidden])) .scan-camera-control {
  margin-block: 2px;
  gap: 4px 10px;
}
#job-form:has(#scan-camera-control:not([hidden])) .scan-camera-control .btn-secondary-action {
  min-height: 36px;
  padding: 6px 12px;
}
#job-form:has(#scan-camera-control:not([hidden])) .options-panel {
  padding: 8px 14px;
  gap: 6px;
}
#job-form:has(#scan-camera-control:not([hidden])) .option-field {
  gap: 3px;
}
#job-form:has(#scan-camera-control:not([hidden])) .action-bar {
  margin-top: 0;
  padding-block: 0;
}
.studio-toolbar .zoom-select {
  min-width: 82px !important;
  width: auto !important;
  padding-inline: 8px 22px !important;
}
.tool-desk-container {
  padding-bottom: 24px;
}

/* ID 470: Wrap Studio top toolbar cleanly at 901px–1240px so buttons never clip */
@media (min-width: 901px) and (max-width: 1240px) {
  html.studio-active body .studio-toolbar .studio-primary-ribbon,
  html.studio-active body .studio-toolbar .studio-sub-ribbon {
    display: flex !important;
    flex-flow: row wrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    gap: 6px !important;
    padding: 6px 10px !important;
  }
  html.studio-active body .studio-toolbar .studio-primary-ribbon > *,
  html.studio-active body .studio-toolbar .studio-sub-ribbon > * {
    flex: 0 0 auto !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
  }
  html.studio-active body .studio-toolbar .studio-divider {
    display: none !important;
  }
}

/* ID 486 + ID 504: Mobile 390px header breathing room without truncating workspace pill */
@media (max-width: 900px) {
  .mobile-view-pill {
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    padding: 5px 8px !important;
    font-size: 11.5px !important;
  }
  .mobile-brand {
    min-height: 40px !important;
    display: inline-flex !important;
    align-items: center !important;
  }
  .tool-desk-search-wrap input {
    font-size: 14px;
  }
  .tool-desk-directory-filters .filter-pill,
  .tool-desk-nav-bar .btn-back-home,
  .seo-related-link,
  .topbar-action-btn,
  .mobile-nav-btn {
    min-height: 40px !important;
  }
  html.studio-active body .studio-main-viewport:has(.studio-empty-state) .studio-toolbar {
    overflow: hidden;
  }
  html.studio-active body .studio-main-viewport:has(.studio-empty-state) .studio-sub-ribbon {
    display: none !important;
  }
  html.studio-active body .studio-main-viewport:has(.studio-empty-state) .studio-primary-ribbon {
    min-height: 44px !important;
    height: 44px !important;
    padding: 3px 6px !important;
  }
}

@media (max-width: 480px) {
  .topbar { padding: 0 8px !important; gap: 4px !important; }
  .topbar-left { gap: 4px !important; }
  .mobile-menu-btn { width: 40px !important; min-width: 40px !important; }
  .mobile-brand { font-size: 14px !important; }
  .mobile-view-pill { font-size: 11px !important; padding: 4px 7px !important; max-width: none !important; overflow: visible !important; text-overflow: clip !important; }
}

/* v32 Deep Audit Fixes: z-index stacking, Settings 820px containment, <=900px dock clearance,
   Convert/Stamp modals at 390px, and ~1360px Studio toolbar rhythm */
.toast-notice,
.toast-notice.toast-result-aware-success {
  z-index: 4000 !important;
}

.topbar {
  z-index: 400 !important;
}

#editor-stamp-picker {
  z-index: 3300;
}

.editor-stamp-card {
  width: min(520px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
}

@media (max-width: 420px) {
  .editor-stamps-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .editor-custom-stamp-box > div {
    flex-wrap: wrap;
  }
}

@media (min-width: 1241px) and (max-width: 1440px) {
  html.studio-active body .studio-primary-ribbon {
    gap: 4px;
    padding: 6px 8px;
  }
  html.studio-active body .studio-primary-ribbon .studio-divider {
    margin-inline: 2px;
  }
  html.studio-active body #save-studio-btn {
    padding-inline: 10px;
    white-space: nowrap;
  }
}

@media (max-width: 900px) {
  .topbar {
    z-index: 400 !important;
  }

  .workspace-inline-panel,
  .workspace-inline-panel > .settings-modal-card,
  .workspace-inline-panel .settings-layout,
  .workspace-inline-panel .settings-content,
  .workspace-inline-panel .settings-pane,
  .workspace-inline-panel .settings-card-item,
  .workspace-inline-panel .settings-user-info-row {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  .workspace-inline-panel > .settings-modal-card {
    height: auto !important;
    max-height: none !important;
    overflow: hidden !important;
  }
  .workspace-inline-panel .settings-user-info-row,
  .workspace-inline-panel #settings-create-key-form {
    flex-wrap: wrap;
  }
  .workspace-inline-panel input,
  .workspace-inline-panel select,
  .workspace-inline-panel textarea,
  .workspace-inline-panel button {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .cookie-consent-banner {
    bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
    left: 12px !important;
    right: 12px !important;
    max-width: none !important;
    z-index: 950 !important;
  }

  body:not(.studio-active):not(.ai-active) .main-area,
  body:not(.studio-active):not(.ai-active) .dynamic-workspace,
  body:not(.studio-active):not(.ai-active) .seo-content,
  body:not(.studio-active):not(.ai-active) .global-footer,
  .workspace-inline-panel {
    padding-bottom: calc(116px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body.ai-active .ai-studio-container,
  body.studio-active .studio-main-viewport {
    padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
  }

  #run-button,
  .action-bar,
  .result-card,
  .pricing-tier-card,
  .settings-card-item,
  .btn-primary-action,
  .btn-download,
  .btn-secondary,
  button,
  input,
  select,
  textarea {
    scroll-margin-bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 640px) {
  #convert-modal .convert-modal-card,
  #convert-modal .modal-header,
  #convert-modal .modal-body,
  #convert-modal .convert-source-box,
  #convert-modal .convert-direction-tabs,
  #convert-modal .convert-format-grid {
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  #convert-modal .convert-source-box {
    flex-wrap: wrap;
    gap: 8px;
  }
  #convert-modal .convert-source-box > div {
    min-width: 0;
    max-width: 100%;
  }
  #convert-modal #convert-source-filename {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 600px) {
  #result .metadata-result-grid,
  .metadata-summary-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* Light-mode legibility for Studio Conversion & Security sub-panels */
body.light-mode #convert-source-box,
body.light-mode #convert-options-area,
body.light-mode #split-summary-box,
body.light-mode #compress-analysis-box,
body.light-mode #ocr-progress-box,
body.light-mode #repair-report-box {
  background: var(--bg-panel-alt) !important;
  border-color: var(--border-light) !important;
  color: var(--text-main) !important;
}

body.light-mode #convert-source-filename,
body.light-mode #convert-result-name,
body.light-mode #convert-modal .convert-option-row label,
body.light-mode #convert-progress-box > div:first-child,
body.light-mode #convert-result-stats,
body.light-mode #compress-analysis-stats,
body.light-mode #repair-report-msg,
body.light-mode #security-modal .form-group-row > div,
body.light-mode #sec-pane-audit > div > div {
  color: var(--text-main) !important;
}

body.light-mode #convert-modal .modal-body > div > label,
body.light-mode #convert-result-time,
body.light-mode #convert-source-meta {
  color: var(--text-muted) !important;
}

/* Tablet settings tabs wrap cleanly onto 2 neat rows without right-edge clipping */
@media (max-width: 900px) and (min-width: 601px) {
  .workspace-inline-panel .settings-modal-card .settings-tabs {
    flex-wrap: wrap !important;
    overflow-x: visible !important;
    gap: 8px !important;
  }
  .workspace-inline-panel .settings-modal-card .settings-tabs .settings-tab-btn {
    flex: 1 1 calc(33.333% - 8px) !important;
    min-width: 0 !important;
    white-space: normal !important;
  }
}

/* ID 522, ID 341, ID 340: Authoritative mobile header, legible non-truncated breadcrumbs,
   uncluttered PWA install bar row at 390px, and bottom workspace-dock clearance across all views */
@media (max-width: 900px) {
  html,
  body {
    scroll-padding-top: calc(var(--topbar-height, 78px) + 12px) !important;
    scroll-padding-bottom: calc(118px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .topbar {
    position: fixed !important;
    inset: 0 0 auto !important;
    z-index: 400 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px 10px !important;
    height: auto !important;
    min-height: calc(56px + env(safe-area-inset-top, 0px)) !important;
    padding: calc(6px + env(safe-area-inset-top, 0px)) 12px 6px !important;
    box-sizing: border-box !important;
  }

  .topbar-left {
    display: contents !important;
  }

  #mobile-menu-btn { order: 1; flex: 0 0 auto; }
  .mobile-brand { order: 2; flex: 0 0 auto; }
  .mobile-view-pill { order: 3; flex: 0 1 auto; margin-right: auto; }

  .topbar-right {
    order: 4;
    flex: 0 0 auto !important;
    margin-left: auto !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    max-width: 100%;
  }

  .breadcrumb-trail {
    order: 5 !important;
    flex: 1 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 3px 6px !important;
    padding-top: 4px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 12px !important;
    line-height: 1.3 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  body.light-mode .breadcrumb-trail {
    border-top-color: rgba(17, 26, 28, 0.08);
  }

  .breadcrumb-trail > span,
  .breadcrumb-trail > b,
  .breadcrumb-trail .crumb-sep,
  .breadcrumb-trail > span:last-child {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    max-width: none !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    overflow-wrap: anywhere;
  }

  .main-area,
  .main-area.studio-active,
  .ai-active .main-area,
  #app-shell.ai-active .main-area,
  html.studio-active body #app-shell .main-area {
    padding-top: calc(var(--topbar-height, 84px) + 6px) !important;
  }

  body:not(.studio-active):not(.ai-active) .main-area,
  body:not(.studio-active):not(.ai-active) .dynamic-workspace,
  #app-shell.ai-active .main-area,
  #app-shell.ai-active .dynamic-workspace,
  .workspace-inline-panel,
  #view-pricing,
  #view-tool-desk-directory,
  #view-tool-desk,
  #view-home,
  #view-legal,
  .seo-content,
  #settings-modal .settings-content {
    padding-bottom: calc(124px + env(safe-area-inset-bottom, 0px)) !important;
  }

  html.studio-active body #app-shell {
    padding-bottom: calc(184px + env(safe-area-inset-bottom, 0px)) !important;
  }

  html.studio-active body .pdf-studio {
    height: calc(100dvh - var(--topbar-height, 84px) - 184px) !important;
    min-height: min(440px, calc(100dvh - var(--topbar-height, 84px) - 184px)) !important;
  }

  #run-button,
  .action-bar,
  .result-card,
  .pricing-tier-card,
  .pricing-upgrade-btn,
  .settings-card-item,
  .ai-chat-form,
  #chat-send-btn,
  #trigger-summary-btn,
  #trigger-extract-btn,
  .btn-primary-action,
  .btn-download,
  .btn-secondary,
  button,
  input,
  select,
  textarea {
    scroll-margin-top: calc(var(--topbar-height, 84px) + 12px) !important;
    scroll-margin-bottom: calc(122px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px !important;
    gap: 6px !important;
  }

  .topbar:has(#install-app-btn:not([hidden])) .topbar-right {
    flex: 1 0 100% !important;
    width: 100% !important;
    margin-left: 0 !important;
    justify-content: space-between !important;
    padding-top: 2px;
  }

  .topbar:has(#install-app-btn:not([hidden])) #install-app-btn:not([hidden]) {
    min-height: 36px !important;
    height: auto !important;
    padding: 6px 11px !important;
    font-size: 11.5px !important;
    white-space: nowrap !important;
  }

  .breadcrumb-trail {
    font-size: 11.5px !important;
  }
}

/* Compact hero/dropzone rhythm at 601px-900px so Upload/Cloud Import and
   primary controls sit cleanly above the fixed mobile workspace dock. */
@media (min-width: 601px) and (max-width: 900px) {
  .tool-desk-container { gap: 12px; }
  .tool-hero-card { padding: 14px 18px; }
  .tool-hero-title-group h1 { font-size: 20px; margin-bottom: 4px; }
  .dropzone { padding: 22px 18px; }
  .drop-icon-circle { width: 42px; height: 42px; margin-bottom: 8px; }
  .dropzone-cloud-option { margin-top: 6px; }
}
