/* app.css — Global Tokens, ShiftTools Custom Cursor, Shell Layout & Controls */
:root {
  --bg-main: #f8f9fa;
  --bg-studio: #ffffff;
  --text-main: #111111;
  --text-muted: #767676;
  --border-light: #eaeaea;
  --accent-color: #000000;
  --accent-hover: #222222;
  --accent-light: #f1f1f1;
  --color-green: #00b074;
  --color-red: #ff3b30;
  --shadow-soft: 0 12px 40px rgba(0, 0, 0, 0.03);
  --shadow-popup: 0 20px 50px rgba(0, 0, 0, 0.06);
}

*, ::before, ::after {
  box-sizing: border-box;
  cursor: none !important;
}

input, textarea, select {
  caret-color: var(--accent-color);
}

/* ─── ShiftTools Custom Cursor ─── */
#shift-cursor {
  position: fixed; pointer-events: none; z-index: 999999;
  width: 26px; height: 26px; left: -50px; top: -50px;
  transition: width .13s, height .13s;
}
#shift-cursor svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 5px rgba(0,0,0,.15)); transition: transform .12s; }
#shift-cursor.hover { width: 32px; height: 32px; }
#shift-cursor.click svg { transform: scale(.8); }
#shift-cursor.busy svg { animation: cursorPulse 0.8s infinite alternate; filter: drop-shadow(0 2px 8px rgba(0, 122, 255, 0.4)); }
@keyframes cursorPulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.25); }
}

#shift-trail {
  position: fixed; pointer-events: none; z-index: 999998;
  width: 14px; height: 14px; opacity: .2; left: -50px; top: -50px;
  transition: left .2s ease-out, top .2s ease-out;
}

/* ─── Hardware OS Cursor Fallback During AI Processing ─── */
/* Prevents cursor freeze when Transformers.js / ONNX Runtime blocks JS thread */
body.is-processing,
body.is-processing *,
body.is-processing ::before,
body.is-processing ::after {
  cursor: wait !important;
}
body.is-processing #shift-cursor,
body.is-processing #shift-trail {
  display: none !important;
}

@media (hover: none), (pointer: coarse) {
  html, body, * { cursor: auto !important; }
  #shift-cursor, #shift-trail { display: none !important; }
}

body {
  margin: 0; padding: 0;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: 'Outfit', 'Plus Jakarta Sans', -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── App Shell Layout ─── */
.br-shell {
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.br-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 12px 12px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.br-app-container {
  width: 100%;
  flex: 1;
  background: var(--bg-studio);
  border-radius: 0 0 16px 16px;
  box-shadow: var(--shadow-popup);
  border: 1px solid var(--border-light);
  border-top: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Header ─── */
.br-header {
  min-height: 64px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  box-sizing: border-box;
  background: #ffffff;
  flex-wrap: wrap;
  gap: 12px;
}
.br-header-left { display: flex; align-items: center; gap: 12px; }
.br-backbtn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px;
  color: var(--text-main); text-decoration: none;
  background: #ffffff; border: 1px solid var(--border-light);
  transition: all 0.2s;
}
.br-backbtn:hover { background: var(--accent-light); }

.br-title {
  font-size: 16px; font-weight: 600; letter-spacing: -0.02em;
}
.br-badge {
  font-size: 11px; color: var(--text-muted);
  background: var(--accent-light);
  border-radius: 6px; padding: 2px 8px;
  font-weight: 500;
}

/* Minimal text tabs */
.br-tabs {
  display: flex;
  gap: 20px;
}
.br-tab {
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  background: none; border: none; padding: 8px 0;
  position: relative; transition: color 0.2s;
}
.br-tab:hover { color: var(--text-main); }
.br-tab.active { color: var(--text-main); font-weight: 600; }
.br-tab.active::after {
  content: '';
  position: absolute; bottom: 0; left: 0; width: 100%; height: 2px;
  background: var(--text-main);
}

/* ─── Workspace Grid ─── */
.br-workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  overflow: hidden;
  background: #fcfcfc;
}

/* Responsive Header & Spacing for Mobile */
@media (max-width: 720px) {
  .br-header {
    flex-direction: column;
    align-items: flex-start;
    height: auto;
    padding: 16px;
    gap: 16px;
  }
  .br-tabs {
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    gap: 24px;
    padding-bottom: 4px;
  }
  .br-tabs::-webkit-scrollbar {
    display: none;
  }
}

/* ─── Studio Stage (Left Side) ─── */
.br-stage {
  display: flex;
  flex-direction: column;
  position: relative;
  background: #fbfbfb;
  overflow: hidden;
}

/* Drop / Upload State */
.br-dropzone-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.br-dropcard {
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  max-width: 320px;
}
.br-drop-circle {
  width: 72px; height: 72px; border-radius: 50%;
  background: #ffffff; border: 1px solid var(--border-light);
  box-shadow: 0 8px 24px rgba(0,0,0,0.02);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
  transition: transform 0.2s;
}
.br-dropcard:hover .br-drop-circle {
  transform: scale(1.05);
}
.br-drop-title {
  font-size: 18px; font-weight: 600; margin-bottom: 6px;
  letter-spacing: -0.02em;
}
.br-drop-sub {
  font-size: 13px; color: var(--text-muted); line-height: 1.5;
  margin-bottom: 24px;
}

/* Compare / Image View */
.br-viewer-wrap {
  flex: 1; display: none; align-items: center; justify-content: center;
  position: relative; padding: 32px;
  overflow: hidden;
}
.br-img-frame {
  position: relative; max-width: 90%; max-height: 90%;
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.04);
  background: #ffffff;
  user-select: none;
}
.br-checkerboard {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background-image:
    linear-gradient(45deg, #f0f0f2 25%, transparent 25%),
    linear-gradient(-45deg, #f0f0f2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0f0f2 75%),
    linear-gradient(-45deg, transparent 75%, #f0f0f2 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #ffffff;
}
.br-img-element {
  display: block; max-height: 60vh; max-width: 100%;
  object-fit: contain; position: relative; z-index: 1;
}
.br-processed-overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 2;
  clip-path: inset(0 0 0 50%);
}
.br-processed-img {
  width: 100%; height: 100%; object-fit: contain;
  position: absolute; top: 0; left: 0;
}

/* Elegant compare divider */
.br-compare-slider {
  position: absolute; top: 0; left: 50%;
  width: 1px; height: 100%; background: #ffffff;
  z-index: 10;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.br-slider-button {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: #ffffff; border: 1px solid var(--border-light);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500;
}

/* Labels */
.br-side-tag {
  position: absolute; bottom: 16px;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 4px 10px; border-radius: 6px;
  z-index: 20;
}
.br-tag-orig { left: 16px; background: rgba(255,255,255,0.9); color: var(--text-main); }
.br-tag-result { right: 16px; background: var(--text-main); color: #ffffff; }

/* Bottom Info bar under preview */
.br-info-bar {
  display: none;
  min-height: 54px; height: auto; border-top: 1px solid var(--border-light);
  background: #ffffff;
  align-items: center; justify-content: space-between;
  padding: 12px 24px; box-sizing: border-box;
  font-size: 12px; color: var(--text-muted);
  flex-wrap: wrap; gap: 12px;
}
.br-info-left {
  display: flex; align-items: center; gap: 16px; flex: 1; min-width: 200px;
}
#imgNameLabel {
  word-break: break-all; margin-top: 2px;
}

/* ─── Precision Mode Stage ─── */
.br-precision-stage {
  flex: 1; display: none; align-items: center; justify-content: center;
  position: relative; padding: 32px;
  overflow: hidden;
}
#precisionCanvas {
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.04);
  background-image:
    linear-gradient(45deg, #f0f0f2 25%, transparent 25%),
    linear-gradient(-45deg, #f0f0f2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0f0f2 75%),
    linear-gradient(-45deg, transparent 75%, #f0f0f2 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #ffffff;
  max-width: 90%; max-height: 90%;
  transform-origin: center center;
  transition: transform 0.05s ease-out;
}
#precisionCanvas.brush-hovering {
  cursor: none !important;
}
#brushCursorOutline {
  position: fixed;
  pointer-events: none;
  border: 1px solid #111111;
  box-shadow: 0 0 0 1px #ffffff;
  border-radius: 50%;
  display: none;
  z-index: 1000000;
  box-sizing: border-box;
  transform: translate(-50%, -50%);
}
.br-precision-toolbar {
  height: 48px; border-top: 1px solid var(--border-light);
  background: #ffffff; display: flex; align-items: center;
  padding: 0 20px; box-sizing: border-box; gap: 12px;
}
.br-tool-btn {
  height: 30px; padding: 0 12px; border-radius: 8px;
  font-size: 12px; font-weight: 500; border: 1px solid var(--border-light);
  background: #ffffff; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; transition: all 0.2s;
}
.br-tool-btn.active {
  background: var(--text-main); color: #ffffff; border-color: var(--text-main);
}
.br-tool-btn:hover:not(.active) {
  background: var(--accent-light); color: var(--text-main);
}

/* ─── Batch View Stage ─── */
.br-batch-stage {
  flex: 1; display: none; flex-direction: column;
  overflow-y: auto; padding: 32px; box-sizing: border-box;
}
.br-batch-dropcard {
  border: 1px dashed var(--border-light);
  border-radius: 16px; padding: 24px; text-align: center;
  background: #ffffff; margin-bottom: 24px;
}
.br-batch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 16px;
}
.br-batch-item {
  background: #ffffff; border: 1px solid var(--border-light);
  border-radius: 12px; overflow: hidden; position: relative;
  aspect-ratio: 1; display: flex; flex-direction: column;
}
.br-batch-thumb-wrap {
  flex: 1; background: var(--bg-main); overflow: hidden;
  position: relative;
}
.br-batch-thumb-img {
  width: 100%; height: 100%; object-fit: cover;
}
.br-batch-lbl {
  font-size: 10px; font-weight: 500; color: var(--text-muted);
  padding: 8px; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.br-batch-status-dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border-light);
}
.br-batch-status-dot.pending { background: var(--text-muted); }
.br-batch-status-dot.processing { background: var(--text-muted); }
.br-batch-status-dot.done { background: var(--color-green); }

.br-batch-remove {
  position: absolute; top: 6px; left: 6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(255,255,255,0.9); border: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-main); font-weight: 600;
  opacity: 0; transition: opacity 0.2s;
}
.br-batch-item:hover .br-batch-remove { opacity: 1; }

/* ─── Control Panel (Right Side) ─── */
.br-panel {
  background: #ffffff;
  border-left: 1px solid var(--border-light);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.br-panel-content {
  padding: 24px; display: flex; flex-direction: column; gap: 24px;
}

.br-group-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
  margin-bottom: 12px;
}

/* Minimal Slider Layout */
.br-control-field {
  display: flex; flex-direction: column; gap: 8px;
}
.br-field-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; font-weight: 500;
}
.br-field-val {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-muted);
}
.br-slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--border-light); outline: none; border-radius: 4px;
  transition: background 0.15s;
}
.br-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent-color); border: 2.5px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18); transition: transform 0.15s, background-color 0.15s;
}
.br-slider::-webkit-slider-thumb:hover { transform: scale(1.2); background: var(--accent-hover); }

/* Background Color swatches */
.br-colors {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.br-color-chip {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border-light); box-sizing: border-box;
  transition: transform 0.15s;
}
.br-color-chip.active {
  transform: scale(1.1);
  border: 2px solid var(--text-main);
}
.br-color-chip.trans {
  background-image:
    linear-gradient(45deg, #e4e4e7 25%, transparent 25%),
    linear-gradient(-45deg, #e4e4e7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e4e4e7 75%),
    linear-gradient(-45deg, transparent 75%, #e4e4e7 75%);
  background-size: 8px 8px; background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  background-color: #ffffff;
}

/* Elegant Custom Color Picker block */
.br-custom-picker-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--border-light);
  border-radius: 10px; background: #fafafa;
}
.br-picker-input {
  width: 24px; height: 24px; border: none; border-radius: 50%;
  padding: 0; background: none; overflow: hidden;
}
.br-picker-hex {
  font-size: 12px; font-family: 'JetBrains Mono', monospace; font-weight: 500;
}

/* Mode toggles (Fast / HD quality) */
.br-mode-row {
  display: flex; gap: 6px;
}
.br-mode-chip {
  flex: 1; height: 32px; border-radius: 8px;
  border: 1px solid var(--border-light); background: #ffffff;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  transition: all 0.2s;
}
.br-mode-chip.active {
  background: var(--accent-light); color: var(--text-main);
  border-color: var(--text-main);
}

/* Custom Selection format dropdown */
.br-select {
  height: 38px; border-radius: 10px; border: 1px solid var(--border-light);
  background: #ffffff; font-size: 13px; font-family: inherit;
  padding: 0 32px 0 12px; outline: none; width: 100%; box-sizing: border-box;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23767676' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
}

/* Minimal Buttons */
.br-btn {
  height: 38px; border-radius: 12px; font-size: 13px; font-weight: 600;
  font-family: inherit; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; transition: all 0.2s;
  border: 1px solid var(--border-light); background: #ffffff;
  color: var(--text-main); width: 100%; box-sizing: border-box;
}
.br-btn:hover { background: var(--accent-light); }

.br-btn-black {
  background: var(--text-main); color: #ffffff; border: none;
}
.br-btn-black:hover { background: var(--accent-hover); }

.br-btn-text {
  border: none; background: none; color: var(--text-muted); font-size: 12px;
  height: auto; padding: 4px 0; font-weight: 500; width: auto; align-self: center;
}
.br-btn-text:hover { color: var(--text-main); text-decoration: underline; }

/* ── Modern Custom Dropdown Component ── */
.br-custom-select {
  position: relative;
  width: 100%;
}

.br-custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
}

.br-custom-select-trigger:hover {
  border-color: #d0d0d0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.br-custom-select.open .br-custom-select-trigger {
  border-color: var(--text-main);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.br-select-arrow {
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-muted);
}

.br-custom-select.open .br-select-arrow {
  transform: rotate(180deg);
  color: var(--text-main);
}

.br-custom-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(0.98);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.br-custom-select.open .br-custom-select-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.br-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  transition: background 0.15s ease, color 0.15s ease;
  font-size: 13px;
}

.br-select-option:hover {
  background: #f4f4f7;
}

.br-select-option.active {
  background: #111111;
  color: #ffffff;
}

.br-opt-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.br-opt-title {
  font-weight: 600;
  font-size: 13px;
}

.br-select-option.active .br-opt-title {
  color: #ffffff;
}

.br-opt-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.br-select-option.active .br-opt-desc {
  color: rgba(255, 255, 255, 0.7);
}

.br-opt-check {
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.15s ease;
}

.br-select-option.active .br-opt-check {
  opacity: 1;
  transform: scale(1);
  color: #ffffff;
}

/* Brush indicator preview block */
.br-brush-preview {
  display: flex; align-items: center; gap: 12px;
  padding: 8px; border: 1px solid var(--border-light);
  border-radius: 10px;
}
.br-brush-preview-dot {
  background: var(--text-main); border-radius: 50%;
}

/* Responsive layouts stack control panels cleanly */
@media (max-width: 820px) {
  .br-workspace { grid-template-columns: 1fr !important; height: auto; }
  .br-panel { border-left: none; border-top: 1px solid var(--border-light); max-height: none; overflow: visible; }
  .br-stage { min-height: 400px; }
  .br-precision-stage { min-height: 360px; }
  .br-batch-stage { min-height: 360px; }
  .br-app-container { height: auto !important; }
}
