@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg:           #FAFAF9;
  --panel-bg:     #FFFFFF;
  --border:       #F0EDE8;
  --border-med:   #E8E3DC;
  --ink:          #111827;
  --ink-2:        #374151;
  --muted:        #6B7280;
  --muted-light:  #9CA3AF;
  --orange-50:    #FFF7F0;
  --orange-100:   #FFEAD8;
  --orange-200:   #FFD4B0;
  --orange-400:   #FF9F5A;
  --orange-500:   #FF8C42;
  --orange-600:   #FF7A29;
  --orange-700:   #E86A18;
  --blue:         #0064FF;
  --red:          #DC2626;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
  /* Bumped from 13px → 14px so all rem-based sizes in the left panel are slightly larger */
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ══════════ LOADING OVERLAY ══════════ */
.init-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.init-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--orange-100);
  border-top-color: var(--orange-500);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

/* ══════════ APP SHELL ══════════ */
.app-shell {
  display: none;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ══════════ LEFT PANEL ══════════ */
/* Widened from 272px → 308px so text is more readable inside the iframe */
.left-panel {
  width: 308px;
  min-width: 308px;
  height: 100vh;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 1px 0 8px rgba(0,0,0,0.04);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

/* ── Generator Section ── */
.generator-section {
  display: flex;
  flex-direction: column;
  gap: 11px;
  flex-shrink: 0;
}

.gen-header {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 11px;
  background: linear-gradient(135deg, var(--orange-50), #FFF3E8);
  border: 1px solid var(--orange-100);
  border-radius: 11px;
}

.gen-icon {
  width: 20px;
  height: 20px;
  color: var(--orange-500);
  flex-shrink: 0;
  margin-top: 1px;
}

.gen-title {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--orange-700);
  line-height: 1.3;
}

.gen-sub {
  font-size: 0.58rem;
  color: var(--orange-600);
  opacity: 0.8;
  line-height: 1.5;
  margin-top: 2px;
}

/* ── Generations Counter ── */
.gen-counter {
  font-size: 0.58rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
  flex-shrink: 0;
}
.gen-counter.depleted {
  color: var(--red);
  font-weight: 500;
}
.gen-counter.hidden { display: none; }

/* ── Text Inputs ── */
.text-input {
  width: 100%;
  padding: 7px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--ink);
  background: var(--panel-bg);
  border: 1.5px solid var(--border-med);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.text-input::placeholder {
  color: var(--muted-light);
  font-weight: 400;
}
.text-input:focus {
  border-color: var(--orange-400);
  box-shadow: 0 0 0 2.5px rgba(255,140,66,0.12);
}
.text-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg);
}

/* ── Select Input ── */
.select-wrapper {
  position: relative;
}
.select-input {
  width: 100%;
  padding: 7px 28px 7px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--ink);
  background: var(--panel-bg);
  border: 1.5px solid var(--border-med);
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.select-input:focus {
  border-color: var(--orange-400);
  box-shadow: 0 0 0 2.5px rgba(255,140,66,0.12);
}
.select-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg);
}
.select-chevron {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

/* ── Divider ── */
.lp-divider { height: 1px; background: var(--border); flex-shrink: 0; }

/* ── Buttons ── */
.btn {
  width: 100%;
  padding: 9px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.2s;
  outline: none;
  text-align: center;
  border: none;
  flex-shrink: 0;
}

.btn-dark {
  background: linear-gradient(to right, var(--orange-400), var(--orange-600));
  color: #fff;
  box-shadow: 0 2px 8px rgba(255,140,66,0.30);
}
.btn-dark:hover {
  background: linear-gradient(to right, var(--orange-500), var(--orange-700));
  box-shadow: 0 3px 12px rgba(255,140,66,0.40);
  transform: translateY(-1px);
}
.btn-dark:active { transform: translateY(0); }
.btn-dark:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
  transform: none;
}

.btn-ghost {
  background: var(--orange-50);
  color: var(--orange-600);
  border: 1px solid var(--orange-100);
  font-weight: 500;
}
.btn-ghost:hover {
  background: var(--orange-100);
  border-color: #F5C9A0;
  color: var(--orange-700);
}

/* ── Status ── */
.status-section {
  display: flex; flex-direction: column;
  align-items: center; gap: 9px; padding: 4px 0;
  flex-shrink: 0;
}
.status-section.hidden { display: none; }

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--orange-100);
  border-top-color: var(--orange-500);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  flex-shrink: 0;
}
.spinner-sm { width: 12px; height: 12px; border-width: 1.5px; }

.status-text {
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.65;
}
.status-text strong { color: var(--orange-600); font-weight: 600; }

/* ── Tools ── */
.tools-section { display: flex; flex-direction: column; gap: 11px; }
.tools-section.hidden { display: none; }

.section-label {
  font-size: 0.59rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.mask-ready-msg {
  font-size: 0.65rem;
  line-height: 1.65;
  color: var(--ink-2);
  background: linear-gradient(135deg, var(--orange-50), #FFF8F0);
  border: 1px solid var(--orange-100);
  border-radius: 10px;
  padding: 9px 11px;
}

.pan-hint {
  display: flex; align-items: flex-start; gap: 5px;
  font-size: 0.62rem; color: var(--muted-light); line-height: 1.55;
}
.pan-hint svg { flex-shrink: 0; opacity: 0.4; margin-top: 1px; }
kbd {
  display: inline-block;
  padding: 0 5px;
  font-family: inherit;
  font-size: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border-med);
  border-radius: 4px;
  color: var(--ink-2);
  line-height: 1.7;
}

.field-group { display: flex; flex-direction: column; gap: 5px; }

.field-label {
  font-size: 0.59rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.field-row { display: flex; justify-content: space-between; align-items: center; }
.field-val {
  font-size: 0.65rem;
  color: var(--orange-600);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Tool Buttons ── */
.tool-btn-row { display: flex; gap: 6px; }

.tool-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 8px;
  background: var(--panel-bg);
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.tool-btn svg { flex-shrink: 0; width: 13px; height: 13px; }

.tool-add { border: 1.5px solid var(--blue); color: var(--blue); }
.tool-add:hover  { background: rgba(0,100,255,0.06); }
.tool-add.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.tool-remove { border: 1.5px solid var(--red); color: var(--red); }
.tool-remove:hover  { background: rgba(220,38,38,0.06); }
.tool-remove.active { background: var(--red); color: #fff; border-color: var(--red); }

.tool-neutral { border: 1.5px solid var(--border-med); color: var(--muted); }
.tool-neutral:hover { border-color: var(--orange-400); color: var(--orange-600); background: var(--orange-50); }
.tool-neutral:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }

/* ── Sliders ── */
.slider { width: 100%; height: 3px; accent-color: var(--orange-500); cursor: pointer; display: block; }

/* ── PSD Status ── */
.psd-status { display: flex; align-items: center; gap: 7px; padding: 3px 0; flex-shrink: 0; }
.psd-status.hidden { display: none; }
#psdStatusText { font-size: 0.6rem; color: var(--muted); }

/* PSD status colour states */
.psd-status-success #psdStatusText { color: #16a34a; font-weight: 600; }
.psd-status-error   #psdStatusText { color: var(--red); }

/* ── Error ── */
.error-box {
  padding: 9px 11px;
  border: 1px solid rgba(220,38,38,0.2);
  background: rgba(220,38,38,0.04);
  border-radius: 10px;
  flex-shrink: 0;
}
.error-box.hidden { display: none; }
.error-box p { font-size: 0.65rem; line-height: 1.65; color: var(--red); }

/* ══════════ RIGHT PANEL ══════════ */
.right-panel {
  flex: 1; height: 100vh;
  background: var(--bg);
  display: flex; align-items: stretch;
  overflow: hidden; position: relative;
}

.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; pointer-events: none;
  background: linear-gradient(135deg, #FFF7F0, #FFFBF0, #FFF8F0);
}
.placeholder.hidden { display: none; }
.placeholder-icon { width: 48px; height: 48px; color: #E8C4A0; }
.placeholder p {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #C8A882;
}
.placeholder-sub {
  font-size: 0.58rem !important;
  font-weight: 400 !important;
  letter-spacing: 0.04em !important;
  color: #D4B898 !important;
  text-transform: none !important;
}

.canvas-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.canvas-area.hidden { display: none; }

.canvas-wrapper {
  flex: 1; position: relative; overflow: hidden; background: #F0EBE3;
}
.canvas-wrapper.editing { cursor: none; }
.canvas-wrapper.panning { cursor: grabbing !important; }

.canvas-inner {
  position: absolute; transform-origin: 0 0; line-height: 0;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  border-radius: 2px;
}
#bgCanvas   { display: block; }
#maskCanvas { position: absolute; top: 0; left: 0; display: block; }

/* ── Generated Actions Bar ── */
.generated-actions {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  gap: 10px;
  padding: 20px 24px;
  background: linear-gradient(to top, rgba(240,235,227,0.98) 55%, rgba(240,235,227,0));
  z-index: 10;
  pointer-events: none;
}
.generated-actions.hidden { display: none; }
.generated-actions > * { pointer-events: auto; }

.gen-action-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s;
  outline: none;
  border: none;
  letter-spacing: 0.01em;
}

.gen-btn-regen {
  background: var(--panel-bg);
  color: var(--ink-2);
  border: 1.5px solid var(--border-med);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.gen-btn-regen:hover {
  border-color: var(--orange-400);
  color: var(--orange-600);
  background: var(--orange-50);
  box-shadow: 0 3px 10px rgba(0,0,0,0.08);
}

.gen-btn-create {
  background: linear-gradient(to right, var(--orange-400), var(--orange-600));
  color: #fff;
  box-shadow: 0 3px 12px rgba(255,140,66,0.35);
  margin-left: auto;
}
.gen-btn-create:hover {
  background: linear-gradient(to right, var(--orange-500), var(--orange-700));
  box-shadow: 0 4px 16px rgba(255,140,66,0.45);
  transform: translateY(-1px);
}
.gen-btn-create:active { transform: translateY(0); }
.gen-btn-create:disabled,
.gen-btn-regen:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Brush Cursor ── */
.brush-cursor {
  position: fixed; border-radius: 50%;
  pointer-events: none; transform: translate(-50%, -50%);
  display: none; z-index: 9999;
  border: 1.5px solid rgba(0,100,255,0.85);
}
.brush-cursor.mode-remove { border-color: rgba(220,38,38,0.85); }
.brush-cursor::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 3px; height: 3px; background: rgba(0,100,255,0.85);
  border-radius: 50%; transform: translate(-50%, -50%);
}
.brush-cursor.mode-remove::after { background: rgba(220,38,38,0.85); }

/* ── Scrollbar ── */
.panel-body::-webkit-scrollbar { width: 3px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border-med); border-radius: 2px; }

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }