/* ==========================================================================
   Quick Fill (QF) - Design System
   Warm Aesthetic:
   - Dark Mode: #121212 Base, Clean Neutral Words (#F4F4F5), Warm Orange Accent (#FF9644)
   - Light Mode: #F5EBE1 Grounded Warm Canvas, #FFFDF1 Ivory Surfaces, #FF9644 Accent
   - Typography: Geist & Geist Mono by Vercel
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Theme Variables
   -------------------------------------------------------------------------- */
:root {
  /* Layout & Shared Tokens (Strictly Theme-Independent) */
  --container-max-w: min(1680px, 95vw);
  --page-px: clamp(16px, 2.5vw, 36px);
  --panel-padding: clamp(20px, 2.2vw, 32px);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Geist Mono', monospace;
  --transition-fast: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-theme: background-color 0.18s cubic-bezier(0.4, 0, 0.2, 1),
                      border-color 0.18s cubic-bezier(0.4, 0, 0.2, 1),
                      color 0.18s cubic-bezier(0.4, 0, 0.2, 1),
                      box-shadow 0.18s cubic-bezier(0.4, 0, 0.2, 1);

  /* UX Component Dynamic Scaling Tokens */
  --panel-padding: clamp(16px, 1.8vw, 24px);
  --input-py: clamp(8px, 1.1vh, 11px);
  --input-px: clamp(12px, 1vw, 15px);
  --input-font: clamp(13px, 0.9vw, 14.5px);
  --btn-py: clamp(8px, 1.1vh, 11px);
  --btn-px: clamp(14px, 1.4vw, 20px);
  --btn-font: clamp(12.5px, 0.85vw, 13.5px);
  --btn-min-h: clamp(38px, 4.2vh, 42px);
  --label-font: 13px;
  --origin-font: 11px;
  --heading-font: clamp(16px, 1.15vw, 18px);
  --upload-icon-size: clamp(32px, 2.5vw, 38px);
  --drop-primary-font: clamp(14px, 0.95vw, 15.5px);
  --drop-secondary-font: clamp(11px, 0.75vw, 12px);
  --sample-padding: 7px 11px;
  --sample-font: 11.5px;
  --seg-min-h: clamp(36px, 4vh, 40px);
  --seg-font: clamp(12px, 0.8vw, 13px);

  /* Dark Theme (Default) */
  --bg-base: #121212;
  --bg-surface: #18181b;
  --bg-subtle: #222226;
  --bg-input: #121212;
  --bg-dropzone: #1a1a1e;
  --bg-pill: #222226;
  --border: #2e2e34;
  --border-hover: #FF9644;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #FF9644;
  --accent-hover: #ffa866;
  --accent-subtle: rgba(255, 150, 68, 0.12);
  --accent-contrast: #121212;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.6);
}

body.dark-theme {
  --bg-base: #121212;
  --bg-surface: #18181b;
  --bg-subtle: #222226;
  --bg-input: #121212;
  --bg-dropzone: #1a1a1e;
  --bg-pill: #222226;
  --border: #2e2e34;
  --border-hover: #FF9644;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #FF9644;
  --accent-hover: #ffa866;
  --accent-subtle: rgba(255, 150, 68, 0.12);
  --accent-contrast: #121212;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.6);
}

body.light-theme {
  /* Light Theme: High-Contrast Linen Canvas & Defined Pure White Cards */
  --bg-base: #ebe4da;
  --bg-surface: #ffffff;
  --bg-subtle: #ded5c8;
  --bg-input: #ffffff;
  --bg-dropzone: #f7f3ec;
  --bg-pill: #f7f3ec;
  --border: #c4b39f;
  --border-hover: #e07a22;

  /* Typography: Razor-Sharp Dark Charcoal Text */
  --text-primary: #111113;
  --text-secondary: #4a4035;
  --text-muted: #766a5c;

  /* Accent / Interactive (#FF9644) */
  --accent: #FF9644;
  --accent-hover: #e57e28;
  --accent-subtle: rgba(255, 150, 68, 0.12);
  --accent-contrast: #121212;

  --shadow-sm: 0 3px 12px rgba(45, 35, 25, 0.08), 0 1px 3px rgba(45, 35, 25, 0.05);
  --shadow-md: 0 12px 28px -4px rgba(45, 35, 25, 0.14), 0 4px 12px -2px rgba(45, 35, 25, 0.06);
}

/* --------------------------------------------------------------------------
   2. Reset & Global Setup
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition-property: background-color, border-color, color, box-shadow;
  transition-duration: 0.18s;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: var(--transition-theme);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Synchronized Theme Surface Transitions */
body,
.navbar,
.brand-logo-container,
.brand-logo,
.brand-title,
.engine-badge,
.btn-icon,
.panel,
.panel-header,
.panel-heading,
.subtle-tag,
.status-pill,
.segmented-control,
.seg-btn,
.dropzone,
.dropzone-inner,
.dropzone-primary,
.dropzone-secondary,
.upload-icon,
.demo-samples,
.demo-label,
.sample-pill,
input[type="text"],
textarea,
label,
.field-origin,
.tag-meta,
.form-actions,
.btn,
.btn-primary,
.btn-secondary,
.btn-ghost,
.preview-box,
.preview-media,
.raw-text-view,
.modal-window,
.feature-item,
.password-hint-box,
.merge-info-banner,
.merge-preview-container,
.merge-diff-row,
.toast {
  transition: var(--transition-theme);
}

/* --------------------------------------------------------------------------
   3. Navbar (Fluid & Responsive)
   -------------------------------------------------------------------------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: clamp(8px, 1.1vh, 12px) var(--page-px);
  width: 100%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.navbar-container {
  max-width: var(--container-max-w);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo-container {
  position: relative;
  width: clamp(34px, 2.5vw, 40px);
  height: clamp(34px, 2.5vw, 40px);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-logo-container .brand-logo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  object-fit: contain;
  transition: opacity 0.18s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity;
}

body.dark-theme .logo-dark {
  opacity: 1;
  visibility: visible;
}
body.dark-theme .logo-light {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
body.light-theme .logo-dark {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
body.light-theme .logo-light {
  opacity: 1;
  visibility: visible;
}

.brand-title {
  font-weight: 700;
  font-size: clamp(16px, 1.25vw, 22px);
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.engine-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}



.navbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-theme);
}

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

/* Theme Icon Toggle */
body.dark-theme .icon-sun { display: block; }
body.dark-theme .icon-moon { display: none; }
body.light-theme .icon-sun { display: none; }
body.light-theme .icon-moon { display: block; }

/* --------------------------------------------------------------------------
   4. Page Layout (Fluid Grid across Desktop, Tablet, & Mobile)
   -------------------------------------------------------------------------- */
.page-container {
  max-width: var(--container-max-w);
  margin: clamp(14px, 2vh, 32px) auto;
  padding: 0 var(--page-px);
  display: grid;
  grid-template-columns: minmax(400px, 1.08fr) minmax(500px, 1.38fr);
  gap: clamp(18px, 2.2vw, 36px);
  align-items: start;
  width: 100%;
  flex: 1;
}

/* Desktop Viewport-Fit & Studio Layout (min-width: 1001px) */
@media (min-width: 1001px) {
  .page-container {
    align-items: stretch;
    height: calc(100dvh - 56px - clamp(16px, 2.4vh, 28px));
    max-height: 820px;
    margin: clamp(8px, 1.2vh, 14px) auto;
  }

  .studio-panel,
  .form-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }

  .studio-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  #uploadView {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .dropzone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    padding: clamp(14px, 2vh, 24px) clamp(16px, 1.8vw, 24px);
  }

  .demo-samples {
    margin-top: auto;
    padding-top: 10px;
  }

  .clean-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 0.9vh, 10px);
    min-height: 0;
  }

  .field-group {
    gap: 3px;
  }

  #groupAddress {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #fullAddress {
    flex: 1;
    min-height: 55px;
    max-height: 95px;
    resize: none;
  }

  .form-actions {
    margin-top: auto;
    padding-top: 10px;
  }

  /* When document preview is active, compact the dropzone so the preview shines */
  .studio-panel:has(#previewContainer:not([style*="display: none"])) #uploadView {
    flex: 0 0 auto;
  }

  .studio-panel:has(#previewContainer:not([style*="display: none"])) .dropzone {
    flex: 0 0 auto;
    min-height: 80px;
    padding: 8px 14px;
  }

  .studio-panel:has(#previewContainer:not([style*="display: none"])) .dropzone .upload-icon {
    width: 24px;
    height: 24px;
    margin-bottom: 0;
  }

  .studio-panel:has(#previewContainer:not([style*="display: none"])) .dropzone-primary {
    font-size: 13px;
  }

  .studio-panel:has(#previewContainer:not([style*="display: none"])) .dropzone-secondary {
    display: none;
  }

  .studio-panel:has(#previewContainer:not([style*="display: none"])) #previewContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-top: 10px;
    min-height: 0;
  }

  .studio-panel:has(#previewContainer:not([style*="display: none"])) .preview-media {
    flex: 1;
    min-height: 130px;
    max-height: 260px;
  }
}

/* Fallback for short browser viewports: allow natural scrolling */
@media (max-height: 660px) and (min-width: 1001px) {
  .page-container {
    height: auto;
    min-height: 0;
  }
  .studio-panel,
  .form-panel {
    height: auto;
    overflow: visible;
  }
}

/* Widescreen Scaling (min-width: 1440px) */
@media (min-width: 1440px) {
  :root {
    --container-max-w: min(1860px, 95vw);
    --page-px: clamp(24px, 2.4vw, 44px);
    --panel-padding: clamp(18px, 1.8vw, 26px);
    --heading-font: 19px;
    --label-font: 13.5px;
    --origin-font: 11.5px;
    --input-py: 9px;
    --input-px: 15px;
    --input-font: 14px;
    --btn-py: 9px;
    --btn-px: 20px;
    --btn-font: 13.5px;
    --btn-min-h: 40px;
    --upload-icon-size: 38px;
    --drop-primary-font: 16px;
    --drop-secondary-font: 12px;
    --sample-padding: 8px 12px;
    --sample-font: 12px;
    --seg-min-h: 40px;
    --seg-font: 13px;
  }

  .page-container {
    grid-template-columns: minmax(460px, 1.12fr) minmax(560px, 1.4fr);
    gap: clamp(24px, 2.2vw, 36px);
  }

  .preview-media {
    max-height: 320px;
  }
}

/* Ultrawide & 2K/4K Scaling (min-width: 1800px) */
@media (min-width: 1800px) {
  :root {
    --container-max-w: min(2200px, 95vw);
    --page-px: clamp(32px, 2.8vw, 56px);
    --panel-padding: 26px;
    --heading-font: 20px;
    --label-font: 14px;
    --origin-font: 12px;
    --input-py: 10px;
    --input-px: 16px;
    --input-font: 14.5px;
    --btn-py: 10px;
    --btn-px: 22px;
    --btn-font: 14px;
    --btn-min-h: 42px;
    --upload-icon-size: 42px;
    --drop-primary-font: 17px;
    --drop-secondary-font: 12.5px;
    --sample-padding: 9px 14px;
    --sample-font: 12.5px;
    --seg-min-h: 42px;
    --seg-font: 13.5px;
  }

  .page-container {
    grid-template-columns: minmax(540px, 1.15fr) minmax(680px, 1.45fr);
    gap: 40px;
  }

  .panel {
    border-radius: 18px;
  }

  .preview-media {
    max-height: 380px;
  }

  .brand-title {
    font-size: 20px;
  }

  .brand-logo-container,
  .brand-logo {
    width: 38px;
    height: 38px;
  }

  .btn-icon {
    width: 38px;
    height: 38px;
  }
}

/* 4K Super-Widescreen Scaling (min-width: 2400px) */
@media (min-width: 2400px) {
  :root {
    --container-max-w: min(2560px, 94vw);
    --page-px: clamp(40px, 3vw, 64px);
    --panel-padding: 32px;
    --heading-font: 22px;
    --label-font: 15px;
    --origin-font: 12.5px;
    --input-py: 12px;
    --input-px: 18px;
    --input-font: 15.5px;
    --btn-py: 11px;
    --btn-px: 24px;
    --btn-font: 14.5px;
    --btn-min-h: 46px;
    --upload-icon-size: 48px;
    --drop-primary-font: 18.5px;
    --drop-secondary-font: 13.5px;
    --sample-padding: 10px 16px;
    --sample-font: 13px;
    --seg-min-h: 46px;
    --seg-font: 14px;
  }

  .page-container {
    grid-template-columns: minmax(640px, 1.15fr) minmax(800px, 1.45fr);
    gap: 48px;
  }
}

/* Tablet Layout (<= 1000px) */
@media (max-width: 1000px) {
  :root, body, body.dark-theme, body.light-theme {
    --page-px: clamp(12px, 3vw, 20px);
  }
  .page-container {
    grid-template-columns: 1fr;
    margin: 16px auto;
  }
}

/* Mobile Layout (<= 640px) */
@media (max-width: 640px) {
  :root, body, body.dark-theme, body.light-theme {
    --page-px: 12px;
  }
  .page-container {
    margin: 12px auto;
    gap: 14px;
  }
  .engine-badge {
    display: none; /* Hide long badge on small screens */
  }
  .brand-subtitle {
    display: none;
  }
}

.panel {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--panel-padding, clamp(20px, 2.2vw, 32px));
  box-shadow: var(--shadow-sm);
  min-width: 0;
  width: 100%;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: clamp(16px, 2vh, 22px);
}

.panel-heading {
  font-size: var(--heading-font, clamp(16px, 1.15vw, 19px));
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.subtle-tag {
  font-size: 11px;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.status-pill {
  font-size: 11px;
  color: var(--accent);
  background-color: var(--accent-subtle);
  border: 1px solid transparent;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   5. Segmented Tab Switcher (Touch-Friendly)
   -------------------------------------------------------------------------- */
.segmented-control {
  display: flex;
  background-color: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: clamp(14px, 2vh, 20px);
  gap: 4px;
}

.seg-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: var(--seg-font, clamp(12.5px, 0.85vw, 14px));
  font-weight: 500;
  padding: clamp(8px, 1.1vh, 11px) 12px;
  min-height: var(--seg-min-h, clamp(38px, 4.4vh, 44px));
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-theme);
  display: flex;
  align-items: center;
  justify-content: center;
}

.seg-btn.active {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* --------------------------------------------------------------------------
   6. Dropzone & File Upload
   -------------------------------------------------------------------------- */
.dropzone {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: clamp(32px, 4.8vh, 54px) clamp(16px, 2vw, 32px);
  text-align: center;
  background-color: var(--bg-dropzone);
  cursor: pointer;
  transition: var(--transition-theme);
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background-color: var(--accent-subtle);
  box-shadow: 0 0 0 1px var(--accent);
}

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.2vh, 12px);
  width: 100%;
}

.upload-icon {
  color: var(--accent);
  width: var(--upload-icon-size, clamp(32px, 2.8vw, 42px));
  height: var(--upload-icon-size, clamp(32px, 2.8vw, 42px));
  margin-bottom: 2px;
  transition: transform var(--transition-fast);
}

.dropzone:hover .upload-icon {
  transform: translateY(-2px);
}

.dropzone-primary {
  font-size: var(--drop-primary-font, clamp(14px, 1vw, 16.5px));
  font-weight: 600;
  color: var(--text-primary);
}

.dropzone-secondary {
  font-size: var(--drop-secondary-font, clamp(11.5px, 0.8vw, 13px));
  color: var(--text-muted);
  margin-bottom: 6px;
}

.dropzone-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

/* --------------------------------------------------------------------------
   7. Camera Stream (Dynamic Aspect Ratio)
   -------------------------------------------------------------------------- */
.camera-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.camera-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-frame-guide {
  position: absolute;
  inset: clamp(10px, 3vw, 18px);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  pointer-events: none;
}

.camera-frame-guide span {
  font-size: 11px;
  background-color: rgba(23, 21, 19, 0.8);
  color: #fff;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
}

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

/* --------------------------------------------------------------------------
   8. Document Preview Box
   -------------------------------------------------------------------------- */
.preview-box {
  margin-top: 18px;
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.preview-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}

.preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.preview-media {
  width: 100%;
  max-height: 220px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
}

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

.preview-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 6px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-link:hover {
  color: var(--accent-hover);
}

.raw-text-view {
  margin-top: 10px;
  padding: 10px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 11px;
  color: var(--text-secondary);
  max-height: 140px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* --------------------------------------------------------------------------
   9. Demo Samples Container (Balanced Grid Layout)
   -------------------------------------------------------------------------- */
.demo-samples {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.demo-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.demo-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

.sample-pill {
  background-color: var(--bg-pill);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: var(--sample-font, 12px);
  font-weight: 500;
  padding: var(--sample-padding, 8px 12px);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition-theme), transform 0.15s ease;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
}

.sample-pill:hover {
  background-color: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   10. Form & Input Fields
   -------------------------------------------------------------------------- */
.clean-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.field-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

label {
  font-size: var(--label-font, 13px);
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
}

.field-origin {
  font-size: var(--origin-font, 11px);
  color: var(--text-muted);
  white-space: nowrap;
}

.field-origin.auto-filled {
  color: var(--accent);
  font-weight: 500;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Collapse two-column form inputs to single column on mobile */
@media (max-width: 640px) {
  .field-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

input[type="text"], textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: var(--input-font, clamp(13.5px, 0.95vw, 15px));
  color: var(--text-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--input-py, clamp(10px, 1.3vh, 13px)) var(--input-px, clamp(12px, 1vw, 16px));
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  transition: var(--transition-theme);
}

input[type="text"]:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

.input-readonly {
  background-color: var(--bg-subtle) !important;
  color: var(--text-secondary) !important;
  cursor: default;
}

textarea {
  resize: vertical;
  min-height: clamp(80px, 10vh, 110px);
  max-width: 100%;
  box-sizing: border-box;
}

.address-tags {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.tag-meta {
  font-size: 11px;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   11. Buttons & Form Actions (Mobile-Optimized)
   -------------------------------------------------------------------------- */
.btn {
  font-family: inherit;
  font-size: var(--btn-font, clamp(12.5px, 0.9vw, 14px));
  font-weight: 500;
  padding: var(--btn-py, clamp(9px, 1.3vh, 13px)) var(--btn-px, clamp(16px, 1.6vw, 24px));
  min-height: var(--btn-min-h, clamp(40px, 4.5vh, 46px));
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-theme), transform 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-sm {
  padding: clamp(6px, 1vh, 8px) clamp(10px, 1.2vw, 14px);
  min-height: clamp(32px, 3.8vh, 36px);
  font-size: clamp(11.5px, 0.8vw, 13px);
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

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

.btn-secondary {
  background-color: var(--bg-pill);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: var(--bg-surface);
  border-color: var(--border-hover);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .form-actions .btn-primary {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: center;
  }
  .form-actions .btn-secondary,
  .form-actions .btn-ghost {
    width: 100%;
    justify-content: center;
  }
}

/* Field population animation */
.field-populated {
  border-color: var(--accent) !important;
  background-color: var(--accent-subtle) !important;
  transition: var(--transition-theme);
}

.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background-color: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid transparent;
}

/* --------------------------------------------------------------------------
   12. Toast Notification (Matches UI Component System)
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(14px);
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, var(--transition-theme);
  z-index: 100;
  max-width: min(480px, calc(100vw - 32px));
}

@media (max-width: 580px) {
  .toast {
    bottom: 16px;
    padding: 8px 18px;
    max-width: calc(100vw - 32px);
  }
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast-desc {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* --------------------------------------------------------------------------
   13. Modal Dialog
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(23, 21, 19, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 16px;
  backdrop-filter: blur(3px);
}

.modal-window {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  padding: clamp(18px, 3vw, 26px);
  box-shadow: var(--shadow-md);
}

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

.modal-title-with-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.modal-feature-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feature-item {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 9px 13px;
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.feature-item strong {
  color: var(--text-primary);
}

/* Password Modal Specifics */
.modal-password {
  max-width: 480px;
}

.modal-title-with-icon {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-lock-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.password-warning-banner {
  background-color: var(--accent-subtle);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
}

.password-warning-banner p {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
  margin: 0;
}

.password-hint-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
}

.password-hint-box .hint-icon {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.password-hint-box .hint-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.password-hint-box .hint-text strong {
  color: var(--text-primary);
}

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

.password-input-wrapper input {
  padding-right: 44px !important;
  font-family: monospace;
  font-size: 15px;
  letter-spacing: 1.5px;
}

.btn-toggle-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.btn-toggle-eye:hover {
  color: var(--text-primary);
}

.error-msg {
  color: #e5534b;
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}

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

/* Merge Confirmation Modal */
.modal-merge {
  max-width: 520px;
}

.modal-merge-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.merge-info-banner {
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 12px;
}

.merge-info-banner p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.merge-info-banner strong {
  color: var(--text-primary);
}

.merge-prompt-question {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
  margin-bottom: 14px;
  line-height: 1.4;
}

.merge-preview-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 18px;
}

.merge-diff-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 8px;
  background-color: var(--bg-surface);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border);
}

.merge-diff-row.is-new {
  border-left-color: var(--accent);
}

.merge-diff-row.is-diff {
  border-left-color: var(--accent);
}

.merge-diff-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.merge-diff-values {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  flex-wrap: wrap;
}

.merge-val-old {
  color: var(--text-secondary);
  text-decoration: line-through;
  opacity: 0.8;
}

.merge-arrow {
  color: var(--accent);
  font-size: 11px;
}

.merge-val-new {
  color: var(--text-primary);
  font-weight: 500;
}

.modal-merge-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   14. Small-Screen & Mobile Optimizations (<= 640px, <= 480px, <= 380px)
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .panel {
    padding: 16px 14px;
    border-radius: var(--radius-md);
  }

  .panel-header {
    margin-bottom: 14px;
  }

  .panel-heading {
    font-size: 15px;
  }

  .clean-form {
    gap: 13px;
  }

  input[type="text"], textarea {
    padding: 10px 12px;
    font-size: 16px;
  }

  .demo-samples {
    margin-top: 14px;
    padding-top: 12px;
  }
}

@media (max-width: 480px) {
  :root, body, body.dark-theme, body.light-theme {
    --page-px: 10px;
  }

  .page-container {
    margin: 10px auto;
    gap: 12px;
  }

  .panel {
    padding: 14px 12px;
    border-radius: var(--radius-md);
  }

  .segmented-control {
    margin-bottom: 12px;
  }

  .seg-btn {
    font-size: 12.5px;
    padding: 7px 8px;
    min-height: 38px;
  }

  .dropzone {
    padding: 24px 12px;
  }

  .dropzone-primary {
    font-size: 13.5px;
  }

  .dropzone-secondary {
    font-size: 11.5px;
  }

  .dropzone-actions {
    gap: 6px;
  }

  .dropzone-actions .btn {
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  :root, body, body.dark-theme, body.light-theme {
    --page-px: 8px;
  }

  .navbar {
    padding: 8px var(--page-px);
  }

  .navbar-container {
    gap: 8px;
  }

  .brand {
    gap: 8px;
  }

  .brand-logo-container,
  .brand-logo {
    width: 30px;
    height: 30px;
  }

  .brand-title {
    font-size: 14px;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
  }

  .page-container {
    margin: 8px auto;
    gap: 10px;
  }

  .panel {
    padding: 12px 10px;
    border-radius: var(--radius-sm);
  }

  .field-group {
    gap: 4px;
  }

  .field-meta {
    gap: 4px;
  }

  .field-meta label {
    font-size: 12.5px;
  }

  .field-origin {
    font-size: 10px;
  }

  input[type="text"], textarea {
    padding: 8px 10px;
    font-size: 16px;
  }

  .dropzone {
    padding: 18px 8px;
  }

  .dropzone-actions {
    flex-direction: column;
    width: 100%;
  }

  .dropzone-actions .btn {
    width: 100%;
  }

  .sample-pill {
    padding: 5px 9px;
    font-size: 11px;
  }

  .toast {
    left: 50%;
    right: auto;
    bottom: 14px;
    transform: translateX(-50%) translateY(10px);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    max-width: calc(100vw - 24px);
  }

  .toast.show {
    transform: translateX(-50%) translateY(0);
  }
}
