/* =====================================================
   StegoScope — Photoshop/Photopea dark theme
   ===================================================== */

:root {
  --bg-darkest:  #141414;
  --bg-dark:     #1e1e1e;
  --bg-mid:      #2a2a2a;
  --bg-panel:    #252525;
  --bg-panel2:   #2d2d2d;
  --bg-tile:     #1a1a1a;
  --border:      #3a3a3a;
  --border-light:#4a4a4a;
  --accent:      #0078d4;
  --accent-hover:#1a8fe3;
  --accent-dim:  #004a8c;
  --text-primary:#d4d4d4;
  --text-muted:  #888;
  --text-bright: #f0f0f0;
  --focus-ring:  #0078d4;
  --tile-gap:    8px;
  --panel-w:     220px;
  --param-w:     260px;
  --header-h:    32px;
  --keybind-h:   26px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-darkest);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}

/* ===================== MENU BAR ===================== */
#menubar {
  height: var(--header-h);
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 12px;
  flex-shrink: 0;
  user-select: none;
  z-index: 100;
  position: relative;
}

.menubar-left { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.menubar-center { flex: 1; display: flex; align-items: center; justify-content: flex-start; overflow: hidden; }
.menubar-right { flex-shrink: 0; color: var(--text-muted); font-size: 11px; }

.app-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.menubar-menus { display: flex; gap: 2px; }
.menu-btn {
  background: none; border: none; color: var(--text-primary);
  padding: 2px 8px; cursor: pointer; border-radius: 3px;
  font-size: 12px;
}
.menu-btn:hover { background: var(--bg-mid); }

/* ===================== TAB BAR ===================== */
#tab-bar { display: flex; align-items: center; gap: 2px; padding: 0 4px; }

.tab-btn {
  background: none; border: none; color: var(--text-muted);
  padding: 4px 12px; cursor: pointer; border-radius: 3px 3px 0 0;
  font-size: 11px; white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.1s;
}
.tab-btn:hover { color: var(--text-primary); background: var(--bg-mid); }
.tab-btn.active {
  color: var(--text-bright);
  border-bottom-color: var(--accent);
}

/* ===================== MAIN LAYOUT ===================== */
#main-layout {
  display: flex;
  height: calc(100vh - var(--header-h) - var(--keybind-h));
  overflow: hidden;
}

/* ===================== HISTORY PANEL ===================== */
#history-panel {
  width: var(--panel-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.panel-header {
  height: 28px;
  background: var(--bg-panel2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}

#history-list::-webkit-scrollbar { width: 6px; }
#history-list::-webkit-scrollbar-track { background: var(--bg-panel); }
#history-list::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.history-empty {
  color: var(--text-muted);
  text-align: center;
  margin-top: 24px;
  font-size: 11px;
  font-style: italic;
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s;
  margin-bottom: 2px;
}
.history-entry:hover { background: var(--bg-mid); }
.history-entry.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.history-thumb {
  width: 36px;
  height: 36px;
  object-fit: contain;
  background: var(--bg-darkest);
  border: 1px solid var(--border);
  border-radius: 2px;
  flex-shrink: 0;
  image-rendering: pixelated;
}

.history-entry-info {
  flex: 1;
  min-width: 0;
}
.history-entry-label {
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-entry-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ===================== GRID AREA ===================== */
#grid-area {
  flex: 1;
  background: var(--bg-darkest);
  overflow: auto;
  position: relative;
}

#grid-area::-webkit-scrollbar { width: 8px; height: 8px; }
#grid-area::-webkit-scrollbar-track { background: var(--bg-darkest); }
#grid-area::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }

/* ===================== DROP ZONE (panel-embedded) ===================== */
.drop-zone-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-mid);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  text-align: center;
  font-size: 11px;
  user-select: none;
}
.drop-zone-panel:hover {
  background: var(--bg-panel2);
  color: var(--text-primary);
}
.drop-zone-panel.drag-over {
  background: rgba(0, 120, 212, 0.12);
  color: var(--accent);
  border-color: var(--accent);
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}
.file-label { color: var(--accent); cursor: pointer; text-decoration: underline; }
.file-label:hover { color: var(--accent-hover); }

/* ===================== TILE GRID ===================== */
#tile-grid {
  padding: var(--tile-gap);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--tile-gap);
  align-content: start;
  width: 100%;
}

.tile {
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  outline: none;
  position: relative;
  transition: border-color 0.1s;
  aspect-ratio: auto;
}
.tile:hover { border-color: var(--border-light); }
.tile.focused {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.tile-canvas-wrap {
  background: repeating-conic-gradient(#333 0% 25%, #222 0% 50%) 0 0 / 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  max-height: 200px;
  overflow: hidden;
  position: relative;
}
.tile-canvas-wrap canvas {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;
}

.tile-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20,20,20,0.7);
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tile-footer {
  padding: 5px 8px;
  background: var(--bg-panel2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tile-name { font-size: 11px; color: var(--text-primary); font-weight: 500; }
.tile-preset { font-size: 10px; color: var(--text-muted); }

/* non-visual (metadata) tile */
.tile.tile-meta .tile-canvas-wrap {
  background: var(--bg-mid);
  padding: 10px;
  align-items: flex-start;
  overflow-y: auto;
  max-height: 200px;
}
.tile-meta-content {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 10px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
  width: 100%;
}
.tile-meta-content .meta-key { color: var(--accent); }
.tile-meta-content .meta-val { color: var(--text-primary); }

.tile-meta-content .meta-line { padding: 1px 0; }
.tile-meta-content .meta-line.sev-info  { color: var(--text-primary); }
.tile-meta-content .meta-line.sev-warn  { color: #d4a24a; }
.tile-meta-content .meta-line.sev-warn  .meta-key { color: #d4a24a; }
.tile-meta-content .meta-line.sev-alert { color: #e06060; background: rgba(224, 96, 96, 0.08); border-left: 2px solid #e06060; padding-left: 4px; }
.tile-meta-content .meta-line.sev-alert .meta-key { color: #f08080; }

/* ===================== PARAMETER PANEL ===================== */
#param-panel {
  width: var(--param-w);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.15s ease;
}
#param-panel.panel-hidden { width: 0; border-left-width: 0; overflow: hidden; }

#param-panel .panel-header {
  padding-right: 4px;
}
#param-panel-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 2px 4px;
  border-radius: 3px;
}
#param-panel-close:hover { color: var(--text-primary); background: var(--bg-mid); }

#param-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Preset bar */
#preset-bar {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
}
.preset-pill {
  background: var(--bg-mid);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.preset-pill:hover { color: var(--text-primary); border-color: var(--border-light); }
.preset-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Param controls */
#param-controls {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
}
#param-controls::-webkit-scrollbar { width: 6px; }
#param-controls::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.param-group {
  margin-bottom: 14px;
}
.param-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--text-muted);
}
.param-value {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.param-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.param-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.1s;
}
.param-slider::-webkit-slider-thumb:hover { background: var(--accent-hover); }
.param-slider:focus::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--accent); }

.param-select {
  width: 100%;
  background: var(--bg-mid);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 11px;
  outline: none;
  cursor: pointer;
}
.param-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.param-select option { background: var(--bg-mid); }

.preset-bar-title {
  width: 100%;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

/* Promote / Apply row — sits at top of panel body */
#param-panel-top {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 7px 12px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.1s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:focus {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--bg-mid);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover { background: var(--border-light); }

/* slow-filter indicator */
.slow-badge {
  display: inline-block;
  font-size: 9px;
  background: var(--bg-mid);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===================== DROP ZONE (grid-area fullscreen) ===================== */
.drop-zone-grid {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg-darkest);
  color: var(--text-muted);
  cursor: pointer;
  z-index: 10;
  font-size: 14px;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}
.drop-zone-grid:hover { background: rgba(255,255,255,0.025); color: var(--text-primary); }
.drop-zone-grid.drag-over {
  background: rgba(0,120,212,0.08);
  color: var(--accent);
  outline: 2px dashed var(--accent);
  outline-offset: -10px;
}
[hidden] { display: none !important; }

/* ===================== MENU DROPDOWN ===================== */
.menu-dropdown {
  position: absolute;
  top: var(--header-h);
  left: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  min-width: 210px;
  z-index: 600;
  padding: 4px 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.menu-dropdown.hidden { display: none; }
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 14px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
.menu-item:hover, .menu-item:focus { background: var(--accent); color: #fff; }
.menu-item-hint { color: var(--text-muted); font-size: 11px; }
.menu-item:hover .menu-item-hint, .menu-item:focus .menu-item-hint { color: rgba(255,255,255,0.7); }
.menu-item-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ===================== TILE ZOOM BUTTON ===================== */
.tile-zoom-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  background: rgba(0,0,0,0.65);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
}
.tile-canvas-wrap:hover .tile-zoom-btn { display: flex; }
.tile-zoom-btn:hover { color: var(--text-bright); background: rgba(0,0,0,0.88); }

/* ===================== ZOOM CONTROLS ===================== */
#zoom-controls {
  position: fixed;
  bottom: calc(var(--keybind-h) + 8px);
  right: 8px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 4px;
  z-index: 50;
  user-select: none;
}
#zoom-controls button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  width: 22px;
  height: 22px;
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#zoom-controls button:hover { color: var(--text-primary); background: var(--bg-mid); }
#zoom-label { font-size: 11px; color: var(--text-muted); min-width: 34px; text-align: center; }

/* ===================== HISTORY PANEL HEADER ACTIONS ===================== */
.panel-header-actions { display: flex; gap: 1px; margin-right: -4px; }
.panel-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  width: 22px;
  height: 22px;
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.panel-icon-btn:hover:not(:disabled) { color: var(--text-primary); background: var(--bg-mid); }
.panel-icon-btn:disabled { opacity: 0.3; cursor: default; }

/* ===================== KEYBIND BAR — key separators ===================== */
.kb-sep {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 1px;
  line-height: 1;
}
.kb-item kbd.kb-key {
  font-family: 'Menlo', 'Consolas', monospace;
}

/* ===================== SCROLLBAR GLOBAL ===================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-darkest); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ===================== KEYBIND BAR ===================== */
#keybind-bar {
  height: var(--keybind-h);
  background: var(--bg-dark);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 0;
  overflow: hidden;
  flex-shrink: 0;
  user-select: none;
}

.kb-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  border-right: 1px solid var(--border);
  height: 100%;
  white-space: nowrap;
}
.kb-item:first-child { padding-left: 0; }
.kb-item:last-child { border-right: none; }

.kb-key {
  background: var(--bg-mid);
  border: 1px solid var(--border-light);
  border-bottom-width: 2px;
  color: var(--text-bright);
  border-radius: 3px;
  padding: 0px 5px;
  font-size: 10px;
  font-family: 'Menlo', 'Consolas', monospace;
  line-height: 16px;
  display: inline-block;
  min-width: 16px;
  text-align: center;
}
.kb-action {
  font-size: 11px;
  color: var(--text-muted);
}

/* ===================== PREVIEW OVERLAY ===================== */
.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
}
.preview-overlay.hidden { display: none; }

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#preview-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-bright);
}
#preview-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; line-height: 1; cursor: pointer;
  padding: 2px 6px; border-radius: 3px;
}
#preview-close:hover { color: var(--text-primary); background: var(--bg-mid); }

.preview-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
  /* checkerboard for transparency */
  background-image: repeating-conic-gradient(#222 0% 25%, #191919 0% 50%);
  background-size: 24px 24px;
}
#preview-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  box-shadow: 0 4px 32px rgba(0,0,0,0.7);
}

.preview-footer {
  padding: 5px 14px;
  background: var(--bg-dark);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
}
.preview-footer kbd {
  background: var(--bg-mid);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  padding: 0 4px;
  font-size: 10px;
  font-family: inherit;
}
