/* ── Reset & Base ─────────────────────────────────── */

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

html, body {
  height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: #fff;
  color: #000;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input {
  font: inherit;
  color: inherit;
}

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

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

/* ── Sidebar ─────────────────────────────────────── */

.sidebar {
  width: 340px;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

.sidebar-top {
  padding: 36px 32px 28px;
}

.logo {
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  line-height: 1;
}

.logo-sub {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 6px;
  opacity: 0.3;
}

.sidebar-resize {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  transition: background 150ms ease;
  position: relative;
  z-index: 2;
}

.sidebar-resize:hover,
.sidebar-resize.is-dragging {
  background: rgba(0, 0, 0, 0.08);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-section {
  padding: 8px 32px 28px;
}

.sidebar-section:last-child {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 14px;
  opacity: 0.25;
}

/* ── Mode Toggle ─────────────────────────────────── */

.mode-toggle {
  display: flex;
  background: #f2f2f2;
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 16px;
}

.mode-btn {
  flex: 1;
  padding: 7px 0;
  border: none;
  border-radius: 6px;
  background: none;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 150ms ease;
  opacity: 0.4;
}

.mode-btn.is-active {
  background: #000;
  color: #fff;
  opacity: 1;
}

.mode-panel {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── Room Upload ─────────────────────────────────── */

.upload-drop {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  border: 1.5px dashed #d8d8d8;
  border-radius: 10px;
  padding: 16px;
  background: #fafafa;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.upload-drop:hover,
.upload-drop.is-dragging {
  border-color: #000;
  background: #fff;
}

.upload-drop input {
  display: none;
}

.upload-title {
  font-size: 0.86rem;
  font-weight: 800;
}

.upload-sub {
  font-size: 0.72rem;
  opacity: 0.35;
}

.room-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  min-height: 0;
}

.room-preview:empty {
  display: none;
}

.room-preview img {
  width: 54px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  background: #eee;
}

.room-preview div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.room-preview strong {
  font-size: 0.74rem;
  line-height: 1.2;
}

.room-preview span {
  font-size: 0.68rem;
  opacity: 0.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Style List ─────────────────────────────────── */

.style-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.style-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 10px;
  text-align: left;
  width: 100%;
  transition: all 150ms ease;
}

.style-item:hover {
  background: #f4f4f4;
}

.style-item.is-active {
  background: #000;
  color: #fff;
}

.style-item.is-active .style-swatch {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

.style-swatch {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  flex-shrink: 0;
  background:
    linear-gradient(135deg, var(--swatch-a) 0 34%, var(--swatch-b) 34% 68%, var(--swatch-c) 68% 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.style-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.style-name {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.2;
}

.style-era {
  font-size: 0.74rem;
  opacity: 0.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Prompt Area (Manual) ────────────────────────── */

textarea {
  width: 100%;
  resize: none;
  border: 1.5px solid #e0e0e0;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  background: #fafafa;
  outline: none;
  min-height: 96px;
  transition: border-color 150ms ease;
}

textarea::placeholder {
  color: #aaa;
}

textarea:focus {
  border-color: #000;
  background: #fff;
}

.quick-prompts {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 10px;
}

.quick-chip {
  width: 100%;
  font-size: 0.72rem;
  padding: 8px 12px;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  line-height: 1.3;
  text-align: left;
  transition: all 120ms ease;
}

.quick-chip:hover {
  border-color: #bbb;
  background: #f6f6f6;
}

.btn-generate {
  display: block;
  width: 100%;
  padding: 13px;
  margin-top: 14px;
  border: none;
  border-radius: 10px;
  background: #000;
  color: #fff;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 120ms ease;
}

.btn-generate:hover {
  opacity: 0.8;
}

.btn-generate:disabled {
  opacity: 0.3;
  cursor: wait;
}

.btn-generate.is-loading {
  opacity: 1;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-generate.is-loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.status-line {
  font-size: 0.68rem;
  margin-top: 10px;
  opacity: 0.35;
  line-height: 1.4;
  min-height: 18px;
}

/* ── Chat (Agentic) ─────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  min-height: 0;
}

.chat-msg {
  font-size: 0.84rem;
  line-height: 1.55;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 92%;
  word-wrap: break-word;
}

.chat-msg.user {
  background: #000;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  background: #f2f2f2;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg.system {
  font-size: 0.72rem;
  opacity: 0.4;
  text-align: center;
  align-self: center;
  padding: 4px 10px;
}

.chat-msg.generating {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.7;
  font-size: 0.78rem;
}

.chat-msg.typing {
  padding: 12px 16px;
  min-height: 38px;
}

/* ── Wave Dots ───────────────────────────────────── */

.wave-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 1em;
}

.wave-dots span {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
  animation: wave 1.2s ease-in-out infinite;
}

.wave-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.wave-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes wave {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

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

.action-buttons {
  display: flex;
  gap: 6px;
  align-self: flex-start;
  transition: opacity 200ms ease;
}

.action-buttons.is-used {
  opacity: 0.25;
  pointer-events: none;
}

.proposal-btn {
  padding: 8px 16px;
  border: 1.5px solid #d0d0d0;
  border-radius: 8px;
  background: #fff;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms ease;
}

.proposal-btn:hover {
  border-color: #000;
  background: #f5f5f5;
}

.proposal-btn.primary {
  background: #000;
  color: #fff;
  border-color: #000;
}

.proposal-btn.primary:hover {
  opacity: 0.8;
}

/* ── Chat Input ──────────────────────────────────── */

.chat-input-wrap {
  display: flex;
  gap: 6px;
  padding-top: 10px;
  margin-top: auto;
}

.chat-input-wrap input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.84rem;
  background: #fafafa;
  outline: none;
  transition: border-color 150ms ease;
}

.chat-input-wrap input:focus {
  border-color: #000;
  background: #fff;
}

.chat-send-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: #000;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 120ms ease;
}

.chat-send-btn:hover {
  opacity: 0.8;
}

.chat-send-btn:disabled {
  opacity: 0.3;
  cursor: wait;
}

/* ── Main Canvas ─────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: #f7f7f7;
}

.canvas {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.canvas-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.canvas-img {
  max-width: none;
  max-height: none;
  display: block;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

/* HUD — bottom left */

.canvas-hud {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.canvas-hud > * {
  pointer-events: auto;
}


.canvas-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.hud-btn {
  width: 30px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 100ms ease;
}

.hud-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.hud-fit,
.hud-reset,
.hud-upscale {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  width: auto;
  padding: 0 10px;
}

.hud-reset {
  min-width: 64px;
}

.hud-upscale:disabled {
  opacity: 0.4;
  cursor: default;
}

.hud-zoom {
  font-size: 0.65rem;
  font-weight: 600;
  min-width: 38px;
  text-align: center;
  opacity: 0.5;
  user-select: none;
}

/* ── Upscale Overlay ──────────────────────────────── */

.upscale-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 5;
  backdrop-filter: blur(2px);
}

.upscale-overlay span {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.5;
}

.upscale-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Meta — top right */

.canvas .canvas-meta {
  position: absolute;
  top: 16px;
  right: 20px;
  text-align: right;
  pointer-events: none;
}

.canvas-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.25;
  display: block;
}


/* ── Empty State ─────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px;
}

.empty-title {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.empty-sub {
  font-size: 0.78rem;
  margin-top: 8px;
  opacity: 0.25;
}

/* ── Thumbnail Strip ─────────────────────────────── */

.history-bar {
  background: #fff;
  display: none;
  border-top: 1px solid #eee;
}

.history-bar.has-items {
  display: block;
}

.history-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: none;
  background: #fafafa;
  cursor: pointer;
  padding: 6px 0;
  transition: background 100ms ease;
}

.history-toggle:hover {
  background: #f0f0f0;
}

.history-toggle-icon {
  font-size: 0.5rem;
  opacity: 0.35;
  transition: transform 200ms ease;
}

.history-toggle-label {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.3;
}

.history-bar.is-collapsed .history-toggle-icon {
  transform: rotate(180deg);
}

.thumbstrip-wrap {
  display: flex;
  align-items: center;
  height: 88px;
  overflow: hidden;
  transition: height 200ms ease;
}

.history-bar.is-collapsed .thumbstrip-wrap {
  height: 0;
}

.thumbstrip {
  flex: 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 3px;
  padding: 3px;
  scrollbar-width: none;
}

.thumbstrip::-webkit-scrollbar {
  display: none;
}

.thumb-item {
  flex: 0 0 82px;
  height: 82px;
  cursor: pointer;
  overflow: hidden;
  border: none;
  padding: 0;
  background: #eee;
  border-radius: 6px;
  position: relative;
  transition: opacity 150ms ease;
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-item:hover {
  opacity: 0.85;
}

.thumb-download {
  position: absolute;
  bottom: 4px;
  right: 5px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: background 100ms ease;
}

.thumb-download:hover {
  background: #000;
}

.thumb-item:hover .thumb-download {
  display: flex;
}

.thumb-download:disabled {
  opacity: 0.5;
  cursor: wait;
}

.thumb-item.is-active {
  outline: 2.5px solid #000;
  outline-offset: -2.5px;
}

.thumb-label {
  position: absolute;
  bottom: 4px;
  left: 5px;
  font-size: 0.55rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.9);
  padding: 1px 4px;
  border-radius: 3px;
  letter-spacing: 0.04em;
}

.thumb-badge {
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 0.5rem;
  font-weight: 800;
  background: #000;
  color: #fff;
  width: 15px;
  height: 15px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0;
}

.thumb-clear {
  flex: 0 0 36px;
  height: 82px;
  align-self: center;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.7rem;
  opacity: 0.25;
  transition: opacity 120ms ease;
  display: none;
}

.thumb-clear:hover {
  opacity: 0.6;
}

.history-bar.has-items .thumb-clear {
  display: block;
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 900px) {
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: none;
    overflow-x: hidden;
    display: block;
  }

  .sidebar-top {
    padding: 32px 24px 28px;
  }

  .sidebar-section {
    padding-left: 24px;
    padding-right: 24px;
  }

  .style-item {
    width: calc(100% - 48px);
  }

  .upload-drop,
  .mode-toggle,
  .chat-input-wrap,
  .chat-messages {
    width: calc(100% - 48px);
    max-width: calc(100% - 48px);
  }

  .sidebar-scroll {
    flex: none;
    overflow: visible;
    display: block;
  }

  .sidebar-section:last-child,
  .mode-panel {
    display: block;
  }

  .chat-messages {
    flex: none;
    max-height: 112px;
    min-height: 0;
    overflow-y: auto;
  }

  .canvas {
    min-height: 60vh;
  }

  .thumbstrip-wrap {
    height: 72px;
  }

  .history-bar.is-collapsed .thumbstrip-wrap {
    height: 0;
  }

  .thumb-item {
    flex: 0 0 66px;
    height: 66px;
  }
}
