/* ==========================================================================
   CAM SCANNER PRO - 2-COLUMN STUDIO WORKSPACE (WHATSAPP AADHAAR STYLE)
   ========================================================================== */

body {
  background: #f3f4f5;
  background-image: none;
  font-family: var(--font-main, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  margin: 0;
  padding: 0;
  color: #0f172a;
}

/* 2-Column Main Studio Workspace Grid */
.studio-workspace-grid {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 12px 16px 20px 16px;
  box-sizing: border-box;
  align-items: stretch;
}

@media (min-width: 761px) {
  .studio-workspace-grid {
    height: calc(100dvh - 82px);
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
    padding-bottom: 12px;
  }
  .floating-tools-sidebar {
    position: static;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow-y: auto;
  }
  .stage-main-wrapper {
    position: static;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }
  .stage-top-bar {
    flex: 0 0 auto;
  }
  .stage-viewport-box {
    height: auto;
    min-height: 0;
    flex: 1 1 0;
    overflow: hidden;
    padding: 16px;
  }
}

@media (max-width: 1250px) {
  .studio-workspace-grid {
    grid-template-columns: 340px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .studio-workspace-grid {
    grid-template-columns: minmax(0, 1fr);
    padding: 8px;
    gap: 10px;
  }
  .stage-main-wrapper {
    position: static;
    grid-row: 1;
  }
  .floating-tools-sidebar {
    position: static;
    max-height: none;
    grid-row: 2;
  }
  .stage-viewport-box {
    height: 60vh;
    min-height: 340px;
    padding: 10px;
  }
}

/* Floating Left Sidebar */
.floating-tools-sidebar {
  background: #ffffff;
  border: 1px solid #d9dde2;
  border-radius: 4px;
  gap: 0;
  padding: 0;
  scrollbar-color: #cbd5e1 #f5f5f5;
  scrollbar-width: thin;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.floating-tools-sidebar::-webkit-scrollbar {
  width: 5px;
}
.floating-tools-sidebar::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* Sidebar Cards */
.floating-tools-sidebar > .sidebar-card-box {
  border: 0 !important;
  border-bottom: 1px solid #e2e5e9 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  padding: 14px 16px;
  background: #ffffff !important;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-card-title {
  font-weight: 700;
  font-size: 13px !important;
  color: #1f2d48 !important;
  border-bottom: 1px solid #e7e9ed !important;
  padding-bottom: 8px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  line-height: 1.5;
}

/* Right Main Stage Container */
.stage-main-wrapper {
  background: #ffffff;
  border: 1px solid #d9dde2;
  border-radius: 4px;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* Stage Header & Step Switcher */
.stage-top-bar {
  background: #fafafa;
  border-bottom: 1px solid #d9dde2;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.stage-step-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #eaedf2;
  border-radius: 8px;
  padding: 4px;
}

.stage-step-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  border: none;
  background: transparent;
  color: #626973;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.stage-step-pill:hover {
  color: #1f2d48;
}

.stage-step-pill.active {
  background: #ffffff;
  color: #c2410c;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  font-weight: 800;
}

/* Stage Live Badge */
.stage-live-badge {
  font-weight: 700;
  font-size: 0.74rem;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.badge-front { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.badge-warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

/* Stage Viewport Area */
.stage-viewport-box {
  background: #e2e5e9;
  height: 100%;
  min-height: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: auto;
  padding: 16px;
  user-select: none;
  box-sizing: border-box;
}

/* Clean Stage Dropzone */
.wa-dropzone {
  background: #ffffff;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
  width: 100%;
  max-width: 520px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.wa-dropzone:hover {
  border-color: #ea580c;
  background-color: #fff7ed;
}

/* Corner Stage Box */
#cornerStage {
  position: relative;
  display: inline-block;
  line-height: 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  max-width: 100%;
  overflow: visible;
  touch-action: none;
}

#sourceCanvas {
  max-width: 100%;
  max-height: calc(100dvh - 220px);
  object-fit: contain;
  display: block;
  border-radius: 4px;
  touch-action: none;
}

@media (max-width: 760px) {
  #sourceCanvas {
    max-height: 52vh;
  }
}

/* SVG Quad Polygon Connecting Lines */
.quad-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
}

/* Corner Handles with 48px Touch Target */
.corner-handle {
  position: absolute;
  width: 26px;
  height: 26px;
  margin-left: -13px;
  margin-top: -13px;
  border-radius: 50%;
  background-color: #ea580c;
  border: 3px solid #ffffff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(37, 99, 235, 0.4);
  cursor: crosshair;
  touch-action: none;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #ffffff;
  transition: transform 0.12s ease, background-color 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
}

.corner-handle::before {
  content: "";
  position: absolute;
  top: -14px;
  left: -14px;
  right: -14px;
  bottom: -14px;
  border-radius: 50%;
}

.corner-handle:hover,
.corner-handle.dragging {
  transform: scale(1.25);
  background-color: #ea580c;
  border-color: #ffffff;
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.6), 0 0 0 2px #ea580c;
}

/* Floating Magnifying Loupe */
.corner-loupe {
  position: absolute;
  width: 110px;
  height: 110px;
  margin-left: -55px;
  margin-top: -55px;
  border-radius: 50%;
  border: 3px solid #38bdf8;
  background-color: #ffffff;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
  transform: translate(-50%, -125%);
}

.corner-loupe.flip-down {
  transform: translate(-50%, 45%);
}

#loupeCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.loupe-crosshair-x {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1.5px;
  background: rgba(220, 38, 38, 0.85);
  transform: translateY(-50%);
}

.loupe-crosshair-y {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: rgba(220, 38, 38, 0.85);
  transform: translateX(-50%);
}

.loupe-center-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px;
  border-radius: 50%;
  background: #dc2626;
  border: 1px solid #ffffff;
}

.loupe-tag {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 9999px;
}

/* Floating Bottom Stage Toolbar (WhatsApp Aadhaar Style) */
.wa-stage-toolbar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  background: rgba(15, 23, 42, 0.92);
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
  z-index: 80;
  backdrop-filter: blur(8px);
}

.wa-toolbar-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.wa-toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
}

.wa-toolbar-btn.primary {
  background: linear-gradient(135deg, #10b981, #c2410c);
  border-color: transparent;
  color: #ffffff;
  font-weight: 800;
}

/* Straightened Output Canvas */
#scanOutput {
  max-width: 100%;
  max-height: calc(100dvh - 220px);
  object-fit: contain;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  display: block;
}

@media (max-width: 760px) {
  #scanOutput {
    max-height: 52vh;
  }
}

/* Preset Pill Grid & Buttons */
.preset-pill-grid {
  display: grid;
  gap: 6px;
}

.preset-pill-btn {
  padding: 8px 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  border: 1px solid #d9dde2;
  border-radius: 6px;
  background-color: #f8fafc;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.preset-pill-btn:hover {
  border-color: #ea580c;
  color: #ea580c;
  background-color: #fff7ed;
}

.preset-pill-btn.active {
  background-color: #ea580c;
  border-color: #ea580c;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

/* Dark Theme Adjustments */
[data-theme="dark"] body {
  background: #090d16;
  color: #f1f5f9;
}

[data-theme="dark"] .floating-tools-sidebar,
[data-theme="dark"] .stage-main-wrapper {
  background: #111827 !important;
  border-color: #1f293d !important;
}

[data-theme="dark"] .floating-tools-sidebar > .sidebar-card-box {
  background: #111827 !important;
  border-bottom-color: #1f293d !important;
}

[data-theme="dark"] .sidebar-card-title {
  color: #f1f5f9 !important;
  border-bottom-color: #1f293d !important;
}

[data-theme="dark"] .stage-top-bar {
  background: #0d1522 !important;
  border-bottom-color: #1f293d !important;
}

[data-theme="dark"] .stage-step-pills {
  background: #1a2436 !important;
}

[data-theme="dark"] .stage-step-pill {
  color: #94a3b8 !important;
}

[data-theme="dark"] .stage-step-pill.active {
  background: #111827 !important;
  color: #38bdf8 !important;
}

[data-theme="dark"] .stage-viewport-box {
  background: #070c14 !important;
}

[data-theme="dark"] .wa-dropzone {
  background: #111827 !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .preset-pill-btn {
  background: #1e293b !important;
  border-color: #334155 !important;
  color: #cbd5e1 !important;
}

[data-theme="dark"] .preset-pill-btn.active {
  background: #ea580c !important;
  border-color: #ea580c !important;
  color: #ffffff !important;
}
