/**
 * Image Viewer Styles — matches the app's light design system
 */

/* ── Main container ─────────────────────────────────────────────────────────── */
.img-viewer-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  background: var(--bg-light, #f8fafc);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* ── Top toolbar ────────────────────────────────────────────────────────────── */
.img-toolbar-simple {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-surface, #fff);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  flex-shrink: 0;
  min-height: 52px;
  z-index: 10;
}

.img-filename {
  color: var(--text-primary, #0f172a);
  font-size: 14px;
  font-weight: 600;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.img-toolbar-spacer { flex: 1; }

/* ── Toolbar separator ───────────────────────────────────────────────────────── */
.img-toolbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border-color, #e2e8f0);
  flex-shrink: 0;
  margin: 0 4px;
}

/* ── Zoom controls ───────────────────────────────────────────────────────────── */
.img-zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.img-zoom-label {
  min-width: 42px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #475569);
  user-select: none;
}

.img-btn-zoom-fit {
  padding: 0 10px;
  font-size: 12px;
}

/* ── Toolbar buttons ────────────────────────────────────────────────────────── */
.img-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  height: 34px;
  min-width: 34px;
  background: var(--bg-light, #f1f5f9);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 6px;
  color: var(--text-primary, #0f172a);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.img-btn:hover  { background: var(--bg-hover, #e8edf2); border-color: #cbd5e1; }
.img-btn:active { background: #dde3ea; }

.img-btn-icon-only { padding: 0; }

.img-btn-save {
  background: var(--color-primary, #2563eb);
  border-color: var(--color-primary, #2563eb);
  color: #fff;
}
.img-btn-save:hover  { background: #1d4ed8; border-color: #1d4ed8; }
.img-btn-save:active { background: #1e40af; }

.img-btn-exit {
  background: var(--bg-light, #f1f5f9);
  border-color: #cbd5e1;
  color: var(--text-secondary, #475569);
}

/* ── Version compare section ────────────────────────────────────────────────── */
.img-version-section {
  display: flex;
  align-items: center;
  gap: 6px;
}

.img-version-select {
  padding: 5px 10px;
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 6px;
  color: var(--text-primary, #0f172a);
  font-size: 13px;
  cursor: pointer;
}
.img-version-select:focus { outline: none; border-color: var(--color-primary, #2563eb); }

/* ── Editor wrapper ─────────────────────────────────────────────────────────── */
.img-editor-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
  background: var(--bg-light, #f1f5f9);

  /* Center the canvas in the available space */
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-editor-wrap #tui-image-editor-container {
  /* Let TUI control its size; we control the wrap */
}

/* ── TUI overrides ───────────────────────────────────────────────────────────── */

/* Hide built-in header — we have our own toolbar */
.tui-image-editor-header {
  display: none !important;
}

/* Canvas area fills remaining height after hiding header */
.tui-image-editor-main {
  top: 0 !important;
  /* Center the canvas element within the main area */
  display: flex !important;
  align-items: center;
  justify-content: center;
  overflow: visible !important;
}

/* The actual canvas container — make it relative so flex centering works */
.tui-image-editor {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  flex-shrink: 0;
  /* zoom transform applied via JS: transform: scale(N) */
  transform-origin: center center;
  transition: transform 0.1s ease;
}

/* Menu bar background matches app surface */
.tui-image-editor-menu {
  background: var(--bg-surface, #fff) !important;
  border-top: 1px solid var(--border-color, #e2e8f0) !important;
}

/* Submenu panel background */
.tui-image-editor-submenu {
  background: var(--bg-surface, #fff) !important;
  border-top: 1px solid var(--border-color, #e2e8f0) !important;
}

/* Ensure the container element itself fills height */
.tui-image-editor-container {
  background: transparent !important;
}

/* ── Loading / error ────────────────────────────────────────────────────────── */
.img-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #ef4444;
  font-size: 14px;
  text-align: center;
  padding: 40px;
}
.img-error-detail {
  color: var(--text-secondary, #64748b);
  font-size: 12px;
  margin: 8px 0;
}

/* ── Version Compare Modal ──────────────────────────────────────────────────── */
.img-compare-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}
.img-compare-modal.show { display: flex; }

.img-compare-content {
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  width: 95%;
  max-width: 1600px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.img-compare-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--bg-light, #f8fafc);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  flex-shrink: 0;
}

.img-compare-header h3 {
  margin: 0;
  color: var(--text-primary, #0f172a);
  font-size: 15px;
  font-weight: 600;
}

.img-compare-close {
  background: none;
  border: none;
  color: var(--text-secondary, #64748b);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: all 0.15s;
}
.img-compare-close:hover { background: var(--bg-hover, #f1f5f9); color: var(--text-primary, #0f172a); }

.img-compare-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

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

.img-compare-pane-header {
  padding: 8px 16px;
  background: var(--bg-light, #f8fafc);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  color: var(--text-secondary, #64748b);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.img-compare-pane-body {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  padding: 20px;
}

.img-compare-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
  background: #fff;
}

.img-compare-divider {
  width: 1px;
  background: var(--border-color, #e2e8f0);
  flex-shrink: 0;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .img-compare-body    { flex-direction: column; }
  .img-compare-divider { width: auto; height: 1px; }
  .img-filename        { max-width: 160px; }
  .img-version-section { gap: 4px; }
}
