/* Image Editor — extends ../shared/editor-core.css */
/* All base tokens inherited from editor-core.css */
:root {
  /* Image editor uses standard tokens — no overrides needed */
  --font-mono: "SF Mono", "Fira Code", monospace;
  --toolbar-w: 52px;
  --right-panel-w: 280px;
  --menubar-h: 36px;
  --toolopts-h: 38px;
  --statusbar-h: 28px;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ── Scrollbar ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Menu Bar ───────────────────────────────── */
.menu-bar {
  height: var(--menubar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  z-index: 200;
  position: relative;
}

.menu-bar .logo {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 12px;
  font-weight: 700;
  font-size: 13px;
  color: var(--brand-light);
}

.menu-bar .logo svg { width: 22px; height: 22px; }

.menu-bar .menu-items { display: flex; gap: 0; flex: 1; }

.menu-item {
  position: relative;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.menu-item:hover, .menu-item.active {
  background: var(--surface-hover);
  color: var(--text);
}

.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 0;
  box-shadow: var(--shadow-lg);
  z-index: 300;
}

.menu-item.active .menu-dropdown { display: block; }

.menu-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  width: 100%;
  text-align: left;
}

.menu-dropdown-item:hover {
  background: var(--brand);
  color: #fff;
}

.menu-dropdown-item .shortcut {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 24px;
}

.menu-dropdown-item:hover .shortcut { color: rgba(255,255,255,0.7); }

.menu-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.menu-bar .brand-link {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-left: auto;
}

/* ── Tool Options Bar ───────────────────────── */
.tool-options-bar {
  height: var(--toolopts-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  font-size: 12px;
  overflow-x: auto;
}

.tool-opt-group {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tool-opt-group label {
  color: var(--text-muted);
  font-size: 11px;
}

.tool-opt-group input[type="range"] {
  width: 80px;
  accent-color: var(--brand);
  height: 4px;
}

.tool-opt-group input[type="number"] {
  width: 52px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 2px 6px;
  font-size: 12px;
  text-align: center;
}

.tool-opt-group input[type="color"] {
  width: 28px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  padding: 1px;
}

.tool-opt-group select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 2px 6px;
  font-size: 12px;
}

.tool-opt-btn {
  padding: 3px 10px;
  background: var(--surface-active);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.tool-opt-btn:hover { background: var(--brand); color: #fff; }
.tool-opt-btn.active { background: var(--brand); color: #fff; }

.tool-opt-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
}

/* ── Editor Layout ──────────────────────────── */
.editor-layout {
  display: flex;
  height: calc(100vh - var(--menubar-h) - var(--toolopts-h) - var(--statusbar-h));
}

/* ── Left Toolbar ───────────────────────────── */
.toolbar {
  width: var(--toolbar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  gap: 2px;
  overflow-y: auto;
  flex-shrink: 0;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.tool-btn:hover { background: var(--surface-hover); color: var(--text); }
.tool-btn.active { background: var(--brand); color: #fff; }

.tool-btn svg { width: 20px; height: 20px; }

.tool-btn .tool-shortcut {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 8px;
  color: var(--text-muted);
  font-weight: 700;
}

.tool-btn.active .tool-shortcut { color: rgba(255,255,255,0.6); }

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

.toolbar .color-swatches {
  margin-top: auto;
  padding: 6px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.color-swatch-pair {
  position: relative;
  width: 34px;
  height: 34px;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: 2px solid var(--border-light);
  cursor: pointer;
  position: absolute;
}

.color-swatch.fg { top: 0; left: 0; z-index: 2; }
.color-swatch.bg { bottom: 0; right: 0; z-index: 1; }

.color-swap-btn {
  font-size: 10px;
  position: absolute;
  top: -2px;
  right: -2px;
  z-index: 3;
  color: var(--text-muted);
}

/* ── Canvas Workspace ───────────────────────── */
.canvas-workspace {
  flex: 1;
  overflow: hidden;
  position: relative;
  background:
    repeating-conic-gradient(#1a1a2e 0% 25%, #151525 0% 50%) 0 0 / 20px 20px;
}

.canvas-container {
  position: absolute;
  transform-origin: 0 0;
}

.canvas-container canvas {
  position: absolute;
  top: 0;
  left: 0;
}

#overlayCanvas {
  pointer-events: none;
  z-index: 10;
}

/* ── Right Panels ───────────────────────────── */
.right-panels {
  width: var(--right-panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.panel {
  border-bottom: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.panel-header:hover { background: var(--surface-hover); }

.panel-header h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

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

.panel-action-btn {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.panel-action-btn:hover { background: var(--surface-active); color: var(--text); }

.panel-body {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Layers Panel ───────────────────────────── */
.layers-panel .panel-body { padding: 0; }

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.layer-item:hover { background: var(--surface-hover); }
.layer-item.active { background: var(--surface-active); border-left: 3px solid var(--brand); }

.layer-thumb {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background:
    repeating-conic-gradient(#333 0% 25%, #444 0% 50%) 0 0 / 6px 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.layer-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

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

.layer-name {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-name-input {
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--brand);
  border-radius: 3px;
  color: var(--text);
  padding: 1px 4px;
  width: 100%;
}

.layer-meta {
  font-size: 10px;
  color: var(--text-muted);
}

.layer-visibility {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: color 0.15s;
  font-size: 14px;
}

.layer-visibility:hover { color: var(--text); }
.layer-visibility.hidden { color: var(--text-muted); opacity: 0.4; }

.layer-blend-row {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.layer-blend-row label { font-size: 11px; color: var(--text-muted); }

.layer-blend-row select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 2px 4px;
  font-size: 11px;
}

.layer-blend-row input[type="range"] {
  width: 60px;
  accent-color: var(--brand);
}

.layer-actions-row {
  display: flex;
  gap: 2px;
  padding: 6px 10px;
  justify-content: center;
}

.layer-action-btn {
  width: 32px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  transition: background 0.15s, color 0.15s;
}

.layer-action-btn:hover { background: var(--surface-active); color: var(--text); }

/* ── Properties Panel (Adjustments) ─────────── */
.properties-panel .panel-body {
  gap: 10px;
}

.adj-section {
  background: var(--bg);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.adj-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.adj-section-header:hover { background: var(--surface-hover); }

.adj-section-header .arrow {
  font-size: 10px;
  transition: transform 0.2s;
}

.adj-section.collapsed .adj-section-body { display: none; }
.adj-section.collapsed .arrow { transform: rotate(-90deg); }

.adj-section-body { padding: 8px 10px; }

.adj-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.adj-slider-row label {
  font-size: 11px;
  color: var(--text-muted);
  width: 64px;
  flex-shrink: 0;
}

.adj-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--brand);
  height: 4px;
}

.adj-slider-row .adj-value {
  font-size: 11px;
  color: var(--text-secondary);
  width: 36px;
  text-align: right;
  font-family: var(--font-mono);
}

.adj-btn {
  width: 100%;
  padding: 6px;
  background: var(--surface-active);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  transition: background 0.15s;
  margin-top: 4px;
}

.adj-btn:hover { background: var(--brand); color: #fff; }

/* Histogram */
.histogram-canvas {
  width: 100%;
  height: 60px;
  border-radius: 4px;
  background: #111;
  margin-bottom: 6px;
}

/* Curves */
.curves-canvas {
  width: 100%;
  height: 120px;
  border-radius: 4px;
  background: #111;
  cursor: crosshair;
  margin-bottom: 6px;
}

/* ── Status Bar ─────────────────────────────── */
.status-bar {
  height: var(--statusbar-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 24px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.status-bar span { white-space: nowrap; }

/* ── Toast ──────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 48px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  max-width: 340px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--brand); }

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

.toast.removing {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-12px); }
}

/* ── Dialogs ────────────────────────────────── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 380px;
  max-width: 520px;
  animation: dialogIn 0.25s ease;
}

@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-bright);
}

.dialog-close {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-muted);
  transition: background 0.15s;
}

.dialog-close:hover { background: var(--surface-active); }

.dialog-body { padding: 18px; }

.dialog-body .form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.dialog-body .form-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.dialog-body .form-group input,
.dialog-body .form-group select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

.dialog-body .form-row {
  display: flex;
  gap: 12px;
}

.dialog-body .form-row .form-group { flex: 1; }

.dialog-body .form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.dialog-body .form-check input[type="checkbox"] { accent-color: var(--brand); }
.dialog-body .form-check label { font-size: 12px; color: var(--text-secondary); }

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}

.btn {
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.btn-secondary {
  background: var(--surface-active);
  color: var(--text-secondary);
}

.btn-secondary:hover { background: var(--border); color: var(--text); }

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover { background: var(--brand-dark); }

/* ── Drop Zone ──────────────────────────────── */
.drop-zone-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,148,136,0.15);
  border: 3px dashed var(--brand);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-zone-content {
  text-align: center;
  color: var(--brand-light);
  font-size: 18px;
  font-weight: 600;
}

.drop-zone-content p { margin-top: 12px; }

/* ── Hidden File Input ──────────────────────── */
#fileInput { display: none; }

/* ── Selection Marching Ants (via overlay) ──── */
/* handled in JS on overlayCanvas */

/* ── Crop Overlay ───────────────────────────── */
.crop-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 20;
}

.crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 1px solid #333;
  pointer-events: all;
  cursor: nwse-resize;
  z-index: 21;
}

/* ── Text Input Overlay ─────────────────────── */
.text-input-overlay {
  position: absolute;
  z-index: 30;
}

.text-input-overlay textarea {
  background: transparent;
  border: 2px dashed var(--brand);
  color: #fff;
  font-size: 24px;
  padding: 4px;
  resize: both;
  min-width: 100px;
  min-height: 32px;
  outline: none;
}

/* ── Rich Tool Tooltips (Pixlr-style) ─────── */
.tool-tooltip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  max-width: 240px;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tool-tooltip.visible {
  opacity: 1;
  transform: translateX(0);
}

.tool-tooltip-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-bright);
  margin-bottom: 4px;
}

.tool-tooltip-desc {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.tool-tooltip-shortcut {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 7px;
  letter-spacing: 0.5px;
}

/* ── Navigator Panel ───────────────────────── */
.navigator-panel .panel-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.navigator-preview-wrap {
  position: relative;
  width: 100%;
  background: #0a0a12;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.navigator-preview-wrap canvas {
  width: 100%;
  display: block;
}

.navigator-viewport-rect {
  position: absolute;
  border: 1.5px solid var(--brand);
  background: rgba(13, 148, 136, 0.08);
  pointer-events: none;
}

.navigator-info {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  padding: 0 2px;
}

.navigator-zoom-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.navigator-zoom-row input[type="range"] {
  flex: 1;
  accent-color: var(--brand);
  height: 3px;
}

.navigator-zoom-row span {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  min-width: 34px;
  text-align: right;
}

/* ── History Panel ─────────────────────────── */
.history-panel .panel-body {
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.history-item:hover {
  background: var(--surface-hover);
}

.history-item.active {
  background: var(--surface-active);
  color: var(--text-bright);
  border-left: 3px solid var(--brand);
}

.history-item.future {
  opacity: 0.35;
}

.history-item-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
}

.history-item.active .history-item-icon {
  color: var(--brand);
}

.history-item-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-index {
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ── Improved Tool Options Bar ─────────────── */
.tool-opt-group .opt-value-label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  min-width: 38px;
  text-align: right;
}

.tool-opt-group label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ── Toolbar section labels ────────────────── */
.toolbar-section-label {
  display: block;
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0 0;
}

.tool-btn .tool-name {
  display: none;
}
