/* =========================================================
   Watermark Remover — Dark UI
   ========================================================= */

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

:root {
  --bg:         #0e0f11;
  --surface:    #16181d;
  --surface2:   #1e2128;
  --border:     #2a2d36;
  --text:       #e8eaf0;
  --muted:      #6b7280;
  --accent:     #6366f1;
  --accent-h:   #818cf8;
  --danger:     #ef4444;
  --success:    #22c55e;
  --warn:       #f59e0b;
  --radius:     10px;
  --font:       'Inter', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#caps-bar {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.cap-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.cap-badge.active { border-color: var(--success); color: var(--success); }

.workspace {
  display: grid;
  grid-template-columns: 1fr 300px;
  overflow: hidden;
}

/* ── Canvas area ─────────────────────────────────────────── */

.canvas-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.canvas-scroll {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.canvas-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--border);
}

#img-canvas, #overlay-canvas {
  display: block;
}

#overlay-canvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}

/* upload drop zone */
.drop-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  margin: 24px;
  color: var(--muted);
  transition: border-color 0.2s, color 0.2s;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  color: var(--accent);
}
.drop-zone svg { opacity: 0.5; }
.drop-zone p { font-size: 13px; }
.drop-zone .btn { margin-top: 4px; }

/* toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 80px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
  gap: 24px;
}

.sidebar h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* Segmented control */
.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.segmented button {
  flex: 1;
  padding: 6px 4px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active {
  background: var(--accent);
  color: #fff;
}
.segmented button:hover:not(.active) {
  background: var(--surface2);
  color: var(--text);
}
.segmented button:disabled { opacity: 0.4; cursor: not-allowed; }

.hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); }

/* Sidebar actions */
.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Result preview in sidebar */
.result-preview {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.result-preview img {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}

/* Status */
.status-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 12px;
}
.status-block.hidden { display: none; }
.status-block.error { border-color: var(--danger); color: var(--danger); }
.status-block.success { border-color: var(--success); color: var(--success); }

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.tool-btn {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tool-btn:hover { background: var(--surface2); color: var(--text); }
.tool-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Source video bar (mask panel) ──────────────────────── */

.source-video-bar {
  padding: 12px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.source-video-bar video {
  width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #000;
  display: block;
}

/* ── Mask panel layout ───────────────────────────────────── */

.mask-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.file-name-label {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

/* ── Compare panel ───────────────────────────────────────── */

.compare-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.compare-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  margin: 20px 20px 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #000;
  cursor: ew-resize;
  user-select: none;
  /* min-height keeps it visible even before media loads */
  min-height: 200px;
}

/* Both layers fill the container */
.compare-layer {
  position: absolute;
  inset: 0;
}

.compare-after { z-index: 1; }

.compare-before {
  z-index: 2;
  /* clip-path updated by JS — left side visible */
  clip-path: inset(0 50% 0 0);
}

.compare-layer img,
.compare-layer video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Divider handle */
.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.compare-line {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 6px rgba(0,0,0,0.6);
  transform: translateX(-50%);
}

.compare-knob {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0;
  background: #fff;
  border-radius: 99px;
  padding: 6px 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  color: #111;
}

/* Labels */
.cmp-label {
  position: absolute;
  bottom: 12px;
  z-index: 4;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
}
.cmp-label-before { left: 12px; }
.cmp-label-after  { right: 12px; }

/* Video controls bar */
.compare-video-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Back toolbar */
.compare-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ── Progress bar ────────────────────────────────────────── */

.status-block {
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 8px !important;
}

.status-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.progress-track {
  flex: 1;
  height: 5px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  min-width: 36px;
  text-align: right;
}

/* SAM tool button pulse while waiting */
#sam-btn:disabled {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent);
  animation: sam-pulse 1s ease-in-out infinite;
}
@keyframes sam-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* hidden utility */
.hidden { display: none !important; }
