/* ──────────────────────────────────────────────────────────────────
   Color by Numbers Admin — styling
   ────────────────────────────────────────────────────────────────── */

:root {
  --bg:           #FAF6F0;
  --surface:      #FFFFFF;
  --surface-alt:  #F4EEE5;
  --border:       #E5DDCF;
  --text:         #2A2520;
  --text-muted:   #8A8175;
  --accent:       #C68B5A;
  --accent-soft:  rgba(198, 139, 90, 0.12);
  --success:      #6B9A6B;
  --danger:       #B6483D;
  --warn:         #C58A2E;
  --shadow:       0 4px 14px rgba(0, 0, 0, 0.06);
  --radius:       12px;
  --radius-sm:    8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 16px; margin: 0 0 12px; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
code {
  background: var(--surface-alt);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.hidden { display: none !important; }

/* ── Top bar ─────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 700;
}

/* ── Status bars ─────────────────────────────────────────────────── */

.status-bar {
  padding: 8px 24px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.status-ok   { background: rgba(107, 154, 107, 0.08); color: var(--success); }
.status-warn { background: rgba(197, 138, 46, 0.08); color: var(--warn); }

.status-line {
  padding: 0 24px;
  font-size: 13px;
  height: 28px;
  display: flex;
  align-items: center;
  color: var(--text-muted);
  transition: color 120ms;
}
.status-err { color: var(--danger); }

/* ── Settings panel ──────────────────────────────────────────────── */

.settings-panel {
  margin: 16px 24px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 560px;
}
.settings-panel .field { margin: 10px 0; }

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

main {
  padding: 8px 24px 40px;
  max-width: 1280px;
  margin: 0 auto;
}

.dropzone-section,
.published-section {
  margin-top: 24px;
}

.counter {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Drop zone ───────────────────────────────────────────────────── */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone p { margin: 4px 0; }

/* ── Card grid ───────────────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.card-header strong {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── Pending card layout ─────────────────────────────────────────── */

.card-body {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 16px;
  align-items: start;
}

.preview-pane {
  display: grid;
  place-items: center;
  min-height: 140px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.preview-img {
  max-width: 124px;
  max-height: 124px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

.preview-meta {
  margin-top: 6px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.spinner {
  font-size: 13px;
  color: var(--text-muted);
}

.controls-pane {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Form fields ─────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field > span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.field input,
.field select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  width: 100%;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

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

.actions-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 80ms;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: #B57B4A;
  border-color: #B57B4A;
}

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

/* ── Published card ──────────────────────────────────────────────── */

.published-body {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  align-items: start;
}
.thumb {
  width: 120px;
  height: 120px;
  object-fit: contain;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.thumb-fallback {
  width: 120px;
  height: 120px;
  display: grid;
  place-items: center;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
}

.published-info > div { margin: 4px 0; }

.thumb-canvas {
  width: 120px;
  height: 120px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ──────────────────────────────────────────────────────────────────
   Editor overlay
   ────────────────────────────────────────────────────────────────── */

.editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 37, 32, 0.55);
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.editor-root {
  width: 100%;
  height: 100%;
  max-width: 1400px;
  max-height: 900px;
  background: var(--bg);
  border-radius: var(--radius);
  display: grid;
  grid-template-rows: auto 1fr;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.editor-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.editor-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-toolbar {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}

.btn-tool {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 18px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  display: grid;
  place-items: center;
}

.btn-tool:hover { background: var(--surface); }
.btn-tool.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.editor-actions {
  display: flex;
  gap: 8px;
}

.editor-main {
  display: grid;
  grid-template-columns: 90px 1fr;
  overflow: hidden;
}

/* ── Palette rail ── */

.palette-rail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  align-items: center;
}

.swatch {
  width: 52px;
  height: 52px;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  background-clip: padding-box;
  transition: transform 80ms, border-color 80ms;
}

.swatch:hover { transform: scale(1.05); }

.swatch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.swatch-add {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 24px;
  font-weight: 300;
  display: grid;
  place-items: center;
}

/* ── Canvas area ── */

.canvas-wrap {
  position: relative;
  background: var(--surface-alt);
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.pixel-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
  /* prevent the browser from intercepting pinch/scroll — we handle it */
}

.editor-info {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  font-family: monospace;
}

/* ── HSV picker popover ── */

.picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1100;
  display: grid;
  place-items: center;
}

.picker-pop {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.picker-sv {
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
}

.picker-hue {
  border-radius: 4px;
  cursor: ns-resize;
  touch-action: none;
}

.picker-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  min-width: 100px;
}

.picker-swatch {
  width: 100px;
  height: 60px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.picker-hex {
  width: 100px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-family: monospace;
  font-size: 13px;
  text-transform: uppercase;
}
