/* ============================================================
   Thumbnail Agent — light, plain, sidebar layout, Urbanist only
   Accent is graphite/near-black - no hue, reads as "product" not "demo"
   ============================================================ */

:root {
  --bg: #f6f6f5;
  --surface: #ffffff;
  --surface-2: #efeeec;
  --border: #e2e0dc;
  --text: #1e1d1b;
  --text-dim: #6b6965;
  --text-faint: #a19e98;
  --accent: #222220;
  --accent-hover: #35342f;
  --accent-soft: #ececea;
  --green: #3c8a5b;
  --red: #c14a4a;
  --red-soft: #fbeeee;
  --font: 'Urbanist', ui-sans-serif, system-ui, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(30, 29, 27, 0.04);
  --shadow-md: 0 4px 16px rgba(30, 29, 27, 0.06);
  --shadow-lg: 0 16px 44px rgba(30, 29, 27, 0.10);
  --sidebar-w: 268px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
::selection { background: var(--accent-soft); color: var(--accent); }
button { font-family: var(--font); }

/* ---------------- App shell ---------------- */

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding: 0 4px;
}

.sidebar__mark {
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  border-radius: 7px;
  flex: none;
}

.sidebar__word {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar__new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 18px;
}
.sidebar__new:hover { background: var(--accent-hover); }

.sidebar__usage {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 22px;
}

.sidebar__usage-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  padding: 3px 0;
}
.sidebar__usage-row span:last-child { color: var(--text); font-weight: 600; }

.sidebar__section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 0 4px;
  margin-bottom: 10px;
}

.sidebar__history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 -8px;
  padding: 0 8px;
}

.sidebar__footer {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 16px;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

.sidebar__link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  padding: 6px 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.sidebar__link:hover { color: var(--text); background: var(--surface-2); }

/* ---------------- Main ---------------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 44px 48px;
}

.console {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  max-width: 1080px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: var(--shadow-sm);
}

.panel__title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

.panel__subtitle {
  font-size: 13.5px;
  color: var(--text-dim);
  margin: 0 0 26px;
}

.panel--preview {
  display: flex;
  flex-direction: column;
  min-height: 480px;
  position: sticky;
  top: 44px;
}

/* ---------------- Form fields ---------------- */

.field-group { margin-bottom: 22px; }
.field-group--half { margin-bottom: 0; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 22px;
}

.field-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 9px;
}

.field-label__value {
  color: var(--text-dim);
  font-weight: 700;
}

.field-textarea,
.field-input,
.field-select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field-textarea::placeholder,
.field-input::placeholder { color: var(--text-faint); }

.field-textarea:focus,
.field-input:focus,
.field-select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--text-faint);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b6965'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 32px;
  cursor: pointer;
}

.field-hint {
  text-align: right;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-faint);
  margin-top: 6px;
}

/* dropzone */

.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 24px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--surface-2);
}
.dropzone:hover, .dropzone.is-drag {
  border-color: var(--text-faint);
  background: var(--accent-soft);
}

.dropzone__idle {
  text-align: center;
  color: var(--text-dim);
}
.dropzone__idle svg { margin-bottom: 10px; opacity: 0.5; }
.dropzone__idle p { margin: 4px 0; font-size: 13.5px; font-weight: 500; }
.dropzone__note { font-size: 12px !important; color: var(--text-faint); font-weight: 400 !important; }

.dropzone__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 8px;
}

.thumb-chip {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}
.thumb-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-chip__primary-tag {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 8.5px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}
.thumb-chip__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: rgba(30, 29, 27, 0.65);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.thumb-chip__remove:hover { background: var(--red); }

/* tier select */

.tier-select {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tier-option {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 12px;
  text-align: left;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--font);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.tier-option:hover { border-color: var(--text-faint); }
.tier-option--active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.tier-option__name { display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 2px; }
.tier-option__desc { display: block; font-size: 11px; color: var(--text-faint); }
.tier-option--active .tier-option__desc { color: var(--text-dim); }

/* range */

.field-range {
  width: 100%;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.field-range::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}
.field-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--surface);
}

/* submit */

.submit-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 20px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 14.5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.submit-btn:hover { background: var(--accent-hover); }
.submit-btn:active { transform: scale(0.99); }
.submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form-error {
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
  margin-top: 14px;
  padding: 11px 14px;
  background: var(--red-soft);
  border-radius: var(--radius-sm);
}

/* ---------------- Preview panel ---------------- */

.preview-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 420px;
}

.preview-state { text-align: center; width: 100%; padding: 20px; }

.empty-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--text-faint);
}

.preview-state--empty p {
  color: var(--text-faint);
  font-size: 13.5px;
  font-weight: 500;
}

/* loading state */

.spinner {
  width: 38px;
  height: 38px;
  margin: 0 auto 20px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

.loading-status {
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* result state */

.result-image-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: var(--shadow-lg);
  animation: reveal 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.result-image { width: 100%; display: block; }

.result-meta {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.result-meta span strong { color: var(--text); font-weight: 700; }

.result-variations {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.variation-chip {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  background: none;
}
.variation-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.variation-chip--active { border-color: var(--accent); }

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.result-btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.result-btn:hover { border-color: var(--text-faint); background: var(--surface-2); }
.result-btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.result-btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* error state */

.error-title {
  font-weight: 700;
  font-size: 17px;
  color: var(--red);
  margin: 0 0 8px;
}
.error-detail {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 18px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------------- History (sidebar list) ---------------- */

.history__empty {
  color: var(--text-faint);
  font-size: 12.5px;
  font-weight: 500;
  padding: 4px;
}

.history-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  text-align: left;
  padding: 6px;
  color: inherit;
  font-family: var(--font);
  transition: background 0.15s;
}
.history-card:hover { background: var(--surface-2); }

.history-card__thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
  flex: none;
  border: 1px solid var(--border);
}

.history-card__thumb--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
}

.history-card__body { min-width: 0; }

.history-card__prompt {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-card__meta {
  display: flex;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-faint);
}

.history-card__status--failed { color: var(--red); }
.history-card__status--processing { color: var(--text-dim); }

/* ---------------- Responsive ---------------- */

@media (max-width: 920px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar__history { max-height: 220px; }
  .main { padding: 28px 20px; }
  .console { grid-template-columns: 1fr; }
  .panel--preview { position: static; }
  .field-row { grid-template-columns: 1fr; }
}
