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

:root {
  /* Brand */
  --primary: #cc785c;
  --primary-active: #a9583e;
  --primary-disabled: #e6dfd8;
  --on-primary: #ffffff;

  /* Surfaces */
  --canvas: #faf9f5;
  --canvas-soft: #f5f0e8;
  --surface-card: #efe9de;
  --surface-strong: #e8e0d2;
  --surface-dark: #181715;
  --surface-dark-elevated: #252320;
  --surface-dark-soft: #1f1e1b;

  /* Hairlines */
  --hairline: #e6dfd8;
  --hairline-soft: #ebe6df;
  --hairline-strong: #a09d96;

  /* Text */
  --ink: #141413;
  --body: #3d3d3a;
  --body-strong: #252523;
  --muted: #6c6a64;
  --muted-soft: #8e8b82;
  --on-dark: #faf9f5;
  --on-dark-soft: #a09d96;

  /* Semantics */
  --success: #5db872;
  --error: #c64545;
  --warn: #d4a017;

  /* Timeline */
  --timeline-thinking: #e8a55a;
  --timeline-grep: #5db8a6;
  --timeline-read: #5db8a6;
  --timeline-edit: #e8a55a;
  --timeline-done: #cc785c;

  /* Legacy fallbacks */
  --text3: var(--muted);
  --surface: var(--surface-card);
  --err: var(--error);
  --ok: var(--success);

  /* Rounded */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 9999px;

  --font-display:
    'Copernicus', 'Tiempos Headline', 'Cormorant Garamond', 'EB Garamond', serif;
  --font:
    'StyreneB', 'Inter', system-ui, 'Helvetica Neue', Helvetica, Arial,
    sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: all 0.18s ease;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font: 14px/1.55 var(--font);
  color: var(--body);
  background: var(--canvas);
  scrollbar-color: var(--hairline-strong) transparent;
  scrollbar-width: thin;
}

h1,
h2,
h3,
h4,
h5,
h6,
.logo span {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.5px;
  color: var(--ink);
}

a {
  color: var(--primary);
  text-decoration: none;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

input,
textarea,
select {
  font: inherit;
  outline: none;
  font-family: var(--font);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--hairline-strong);
  border-radius: var(--r-pill);
}

/*═══════════════════════════════════════════
  LAYOUT
═══════════════════════════════════════════*/
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 64px;
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
  z-index: 50;
}

.topbar .logo {
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-family: var(--font-display);
}

.topbar .logo span {
  color: var(--ink);
  font-weight: 400;
  font-size: 24px;
}

.topbar .logo em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  margin-left: 8px;
  background: var(--surface-strong);
  padding: 2px 6px;
  border-radius: var(--r-pill);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/*═══════════════════════════════════════════
  BUTTONS
═══════════════════════════════════════════*/
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  transition: var(--transition);
  white-space: nowrap;
  height: 40px;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}

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

.btn-sec {
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--hairline);
}

.btn-sec:hover {
  background: var(--surface-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  height: auto;
  padding: 6px 12px;
}

.btn-ghost:hover {
  background: var(--surface-strong);
}

.btn-danger {
  background: transparent;
  color: var(--error);
}

.btn-danger:hover {
  background: rgba(207, 45, 86, 0.1);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  height: 32px;
}

.btn-lg {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  height: 44px;
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--r-md);
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

/*═══════════════════════════════════════════
  LEFT PANEL
═══════════════════════════════════════════*/
.panel-l {
  width: 340px;
  min-width: 340px;
  background: var(--canvas-soft);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
  background: var(--surface-card);
}

.panel-tab {
  flex: 1;
  padding: 12px 0;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.panel-tab:hover {
  color: var(--ink);
}

.panel-tab.on {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.hidden {
  display: none !important;
}

.panel-body.hidden {
  display: none;
}

.field {
  margin-bottom: 20px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--ink);
  margin-bottom: 4px;
  font-weight: 500;
}

.field input[type='text'],
.field input[type='password'],
.field input[type='number'],
.field textarea,
.field select {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 10px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  color: var(--ink);
  font-size: 14px;
  transition: var(--transition);
  height: 40px;
}

.field textarea {
  height: auto;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--primary);
}

.field textarea {
  resize: vertical;
  line-height: 1.5;
}

.field select option {
  background: var(--surface-card);
  color: var(--ink);
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.row > .field {
  flex: 1;
  margin-bottom: 0;
}

.row-wrap {
  flex-wrap: wrap;
}

.chip-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--hairline-strong);
  color: var(--muted);
  transition: var(--transition);
  background: var(--surface-card);
}

.chip:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.chip.on {
  background: var(--timeline-done);
  border-color: var(--timeline-done);
  color: var(--on-primary);
}

.divider {
  height: 1px;
  background: var(--hairline);
  margin: 24px 0;
}

/*═══════════════════════════════════════════
  CENTER AREA
═══════════════════════════════════════════*/
.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.center-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  background: var(--canvas-soft);
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}

.center-toolbar .sep {
  width: 1px;
  height: 24px;
  background: var(--hairline);
  margin: 0 8px;
}

.center-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: var(--canvas);
  position: relative;
}

.image-stage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  padding: 48px;
}

.image-stage img {
  max-width: 100%;
  max-height: calc(100vh - 160px);
  object-fit: contain;
  border-radius: var(--r-lg);
  display: block;
  border: 1px solid var(--hairline);
  background: var(--surface-dark);
  transition: all 0.4s ease;
}

/* Claude-like generating animation */
.image-stage.generating::before {
  content: '';
  position: absolute;
  inset: 48px;
  border-radius: var(--r-lg);
  background: var(--surface-dark-soft);
  opacity: 0.5;
  z-index: 1;
  animation: pulse-bg 2s ease-in-out infinite;
}

.image-stage.generating::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 2;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse-bg {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.7; }
}

.image-stage.generating img {
  opacity: 0.2;
  filter: blur(8px);
}

.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
  padding: 48px;
  text-align: center;
}

.image-placeholder svg {
  width: 64px;
  height: 64px;
  opacity: 0.5;
}

.image-placeholder p {
  font-size: 16px;
}

/* Canvas overlay for drawing */
.draw-canvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  display: none;
}

.draw-canvas.on {
  display: block;
}

/*═══════════════════════════════════════════
  RIGHT PANEL
═══════════════════════════════════════════*/
.panel-r {
  width: 320px;
  min-width: 320px;
  background: var(--canvas-soft);
  border-left: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-r-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
  background: var(--surface-card);
}

.panel-r-header h3 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.3px;
  color: var(--ink);
}

.panel-r-header .count {
  font-size: 13px;
  color: var(--muted);
}

.gallery {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-content: start;
}

.gallery-item {
  position: relative;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-card);
  cursor: pointer;
  aspect-ratio: 1;
  border: 1px solid var(--hairline);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}

.gallery-item:hover img {
  transform: scale(1.03);
}

.gallery-item .gi-overlay {
  position: absolute;
  inset: 0;
  background: rgba(38, 37, 30, 0.6);
  /* ink with opacity */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

.gallery-item:hover .gi-overlay {
  opacity: 1;
}

.gallery-item .gi-prompt {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 8px;
  background: linear-gradient(transparent, rgba(38, 37, 30, 0.9));
  font-size: 11px;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
}

/*═══════════════════════════════════════════
  TASK QUEUE
═══════════════════════════════════════════*/
.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-card);
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
}

.task-item .ti-status {
  width: 10px;
  height: 10px;
  border-radius: var(--r-pill);
  flex-shrink: 0;
}

.task-item .ti-status.pending {
  background: var(--timeline-read);
  /* pastel blue */
}

.task-item .ti-status.running {
  background: var(--timeline-thinking);
  /* peach */
  animation: pulse 1s infinite;
}

.task-item .ti-status.done {
  background: var(--timeline-done);
  /* gold */
}

.task-item .ti-status.error {
  background: var(--error);
}

.task-item .ti-text {
  flex: 1;
  font-size: 13px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
}

.task-item .ti-actions {
  display: flex;
  gap: 4px;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

/*═══════════════════════════════════════════
  MODALS
═══════════════════════════════════════════*/
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(247, 247, 244, 0.85);
  /* canvas color with opacity */
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}

.modal-mask.on {
  display: flex;
}

.modal {
  background: var(--surface-card);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-lg);
  padding: 32px;
  max-width: 560px;
  width: 95%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h2 {
  font-family: var(--font-display);
  font-size: 28px;
  /* display-sm */
  font-weight: 400;
  letter-spacing: -0.3px;
  margin-bottom: 24px;
  color: var(--ink);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/*═══════════════════════════════════════════
  PREVIEW
═══════════════════════════════════════════*/
.preview-mask {
  position: fixed;
  inset: 0;
  background: rgba(38, 37, 30, 0.9);
  /* ink */
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 400;
  cursor: zoom-out;
}

.preview-mask.on {
  display: flex;
}

.preview-mask img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: var(--r-lg);
  border: 1px solid var(--hairline-strong);
}

/*═══════════════════════════════════════════
  TOAST
═══════════════════════════════════════════*/
.toast-box {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 14px;
  max-width: 360px;
  animation: toastIn 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--hairline-strong);
}

.toast.success {
  background: var(--surface-card);
  color: var(--success);
  border-left: 4px solid var(--success);
}

.toast.error {
  background: var(--surface-card);
  color: var(--error);
  border-left: 4px solid var(--error);
}

.toast.info {
  background: var(--surface-card);
  color: var(--ink);
  border-left: 4px solid var(--timeline-read);
}

.toast.warn {
  background: var(--surface-card);
  color: var(--warn);
  border-left: 4px solid var(--warn);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/*═══════════════════════════════════════════
  STATUS BAR
═══════════════════════════════════════════*/
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  background: var(--canvas);
  border-top: 1px solid var(--hairline);
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

.statusbar .status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-pill);
  margin-right: 8px;
  display: inline-block;
}

.statusbar .status-dot.ok {
  background: var(--success);
}

.statusbar .status-dot.err {
  background: var(--error);
}

.statusbar .status-dot.idle {
  background: var(--muted-soft);
}

/*═══════════════════════════════════════════
  PROGRESS
═══════════════════════════════════════════*/
.progress {
  height: 4px;
  background: var(--surface-strong);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}

.progress.on {
  display: block;
}

.progress .bar {
  height: 100%;
  background: var(--primary);
  width: 30%;
  border-radius: 2px;
  animation: progInd 1.5s ease-in-out infinite;
}

@keyframes progInd {
  0% {
    width: 10%;
    margin-left: 0;
  }

  50% {
    width: 50%;
    margin-left: 25%;
  }

  100% {
    width: 10%;
    margin-left: 80%;
  }
}

/*═══════════════════════════════════════════
  PROMPT LAB DIALOG
═══════════════════════════════════════════*/
.lab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.lab-card {
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  background: var(--surface-card);
}

.lab-card:hover {
  border-color: var(--primary);
}

.lab-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.lab-card .lab-prompt {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--body);
  background: var(--surface-card);
  font-family: var(--mono);
}

/* Responsive */
@media (max-width: 1200px) {
  .panel-l {
    width: 300px;
    min-width: 300px;
  }

  .panel-r {
    width: 280px;
    min-width: 280px;
  }
}

@media (max-width: 900px) {
  .panel-r {
    display: none;
  }
}

/* Drop Zone */
.drop-zone {
  position: relative;
  border: 1px dashed var(--hairline-strong);
  border-radius: var(--r-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
  background: var(--surface-card);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(245, 78, 0, 0.03);
}

.drop-zone.has-image {
  padding: 8px;
  border-style: solid;
  min-height: auto;
}

.drop-zone-sm {
  padding: 16px;
  min-height: 80px;
}

.drop-zone-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.drop-zone-hint svg {
  opacity: 0.6;
}

.drop-zone-preview {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: var(--r-md);
  display: block;
}

.drop-zone-clear {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface-card);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 1;
}

.drop-zone-clear:hover {
  background: var(--surface-strong);
}
