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

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Layout */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

header {
  text-align: center;
  margin-bottom: 3rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header p {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

/* Sections */
section {
  margin-bottom: 3rem;
}

section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

section h2 .count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.4rem;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Garment Grid */
.garment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.garment-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.garment-card {
  cursor: pointer;
}

.garment-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.garment-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #f3f4f6;
}

.garment-card .info {
  padding: 0.6rem 0.75rem;
}

.garment-card .type {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: capitalize;
}

.garment-card .color {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: var(--radius);
  border: 2px dashed var(--border);
}

.empty-state p {
  margin-bottom: 1rem;
}

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--accent);
  background: #eff6ff;
}

.upload-area input[type="file"] {
  display: none;
}

.upload-area .icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.upload-area p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Outfit Cards */
.outfit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.outfit-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.outfit-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.outfit-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #f3f4f6;
}

.outfit-info {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.outfit-info .label {
  font-size: 0.85rem;
}

.outfit-actions {
  display: flex;
  gap: 0.5rem;
}

.outfit-actions button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.outfit-actions button:hover {
  transform: scale(1.1);
}

.outfit-actions .like:hover {
  background: #dcfce7;
  border-color: #22c55e;
}

.outfit-actions .dislike:hover {
  background: #fee2e2;
  border-color: #ef4444;
}

/* Context input */
.context-input {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.context-input input {
  flex: 1;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color var(--transition);
}

.context-input input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Chat */
.chat-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-messages {
  max-height: 400px;
  overflow-y: auto;
  padding: 1.5rem;
}

.chat-message {
  margin-bottom: 1rem;
  line-height: 1.5;
}

.chat-message.user {
  text-align: right;
}

.chat-message .bubble {
  display: inline-block;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  max-width: 80%;
  text-align: left;
  font-size: 0.9rem;
}

.chat-message.user .bubble {
  background: var(--accent);
  color: white;
}

.chat-message.assistant .bubble {
  background: #f3f4f6;
  color: var(--text);
}

.bubble p,
.bubble ul,
.bubble ol {
  margin-bottom: 0.5rem;
}

.bubble p:last-child,
.bubble ul:last-child,
.bubble ol:last-child {
  margin-bottom: 0;
}

.bubble ul,
.bubble ol {
  padding-left: 1.2rem;
}

.bubble strong {
  font-weight: 600;
}

.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
}

.garment-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px 3px 3px;
  font-size: 0.8rem;
  font-weight: 500;
  vertical-align: middle;
  max-width: 100%;
  margin: 0.15rem 0;
}

.garment-inline img {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

.garment-inline span {
  line-height: 1.35;
}

.garment-ref {
  font-family: monospace;
  font-size: 0.8rem;
  background: #e5e7eb;
  padding: 1px 4px;
  border-radius: 3px;
}

.chat-input {
  display: flex;
  border-top: 1px solid var(--border);
}

.chat-input input {
  flex: 1;
  padding: 1rem;
  border: none;
  font-size: 0.9rem;
  font-family: var(--font);
}

.chat-input input:focus {
  outline: none;
}

.chat-input button {
  padding: 1rem 1.5rem;
  background: var(--accent);
  color: white;
  border: none;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition);
}

.chat-input button:hover {
  background: var(--accent-hover);
}

/* Loading / Status */
.status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.status.loading {
  background: #eff6ff;
  color: var(--accent);
}

.status.success {
  background: #f0fdf4;
  color: #166534;
}

.status.error {
  background: #fef2f2;
  color: #991b1b;
}

/* Dataset selector */
.dataset-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.dataset-row select {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font);
  background: var(--surface);
}

/* Nav */
nav {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

nav button {
  padding: 0.75rem 1.25rem;
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  font-family: var(--font);
  white-space: nowrap;
}

nav button:hover {
  color: var(--text);
}

nav button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Garment detail side drawer */
.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
}

.detail-panel {
  background: var(--surface);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
  width: min(380px, 100vw);
  height: 100vh;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  animation: detail-slide-in var(--transition);
}

@keyframes detail-slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.detail-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  z-index: 1;
}

.detail-close:hover {
  background: #f3f4f6;
  color: var(--text);
}

.detail-image {
  width: 100%;
  background: #f3f4f6;
  overflow: hidden;
  flex-shrink: 0;
}

.detail-image img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
}

.detail-info {
  padding: 1.25rem 1.5rem 1.5rem;
}

.detail-title {
  font-size: 1.05rem;
  font-weight: 600;
  text-transform: capitalize;
  margin-bottom: 0.5rem;
}

.detail-description {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 1.1rem;
  font-style: italic;
}

.attr-list {
  display: flex;
  flex-direction: column;
}

.attr-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.85rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}

.attr-row:last-child {
  border-bottom: none;
}

.attr-key {
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
  margin-right: 1rem;
}

.attr-val {
  text-transform: capitalize;
  text-align: right;
  font-weight: 500;
}

/* Bounding box editor */
.editor-area {
  margin-top: 1.5rem;
}

.editor-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  line-height: 1.5;
}

.editor-hint strong {
  color: var(--text);
}

.editor-canvas-wrap {
  position: relative;
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f3f4f6;
}

.editor-canvas-wrap #annoImage {
  display: block;
  max-width: 100%;
  height: auto;
}

.editor-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

/* Log dock — fixed bottom panel */
.log-dock {
  position: fixed;
  bottom: 0;
  right: 1.5rem;
  width: min(440px, calc(100vw - 3rem));
  z-index: 200;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  background: #1e1e2e;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.log-dock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.85rem;
  background: #2a2a3e;
  cursor: pointer;
  user-select: none;
  gap: 0.5rem;
}

.log-dock-title {
  font-size: 0.78rem;
  color: #89b4fa;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-dock-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.log-dock-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition);
}

.log-dock-btn:hover {
  color: #e5e7eb;
}

.log-dock-body {
  padding: 0.6rem 0.85rem 0.75rem;
}

.log-console {
  max-height: 160px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.log-line {
  font-size: 0.78rem;
  line-height: 1.65;
  color: #a6e3a1;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line:first-child {
  color: #89b4fa;
}

/* Dataset previews */
.dataset-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.dataset-previews img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: #f3f4f6;
}

@media (max-width: 640px) {
  .app {
    padding: 1.5rem 1rem 3rem;
  }

  .garment-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }

  .outfit-grid {
    grid-template-columns: 1fr;
  }

  .context-input {
    flex-direction: column;
  }

  .detail-panel {
    width: 100vw;
  }

  .detail-image img {
    max-height: 260px;
  }

  .detail-info {
    padding: 1rem;
  }
}
