/* bret — Brand Asset Studio. Hand-rolled dark design system, no build step. */

:root {
  /* Surfaces */
  --bg: #0a0e16;
  --surface: #111824;
  --surface-2: #151e2c;
  --elev: #1b2536;
  --line: #233044;
  --line-2: #2e3c53;

  /* Text */
  --text: #e8edf5;
  --muted: #9aa8be;
  --faint: #6b7a93;

  /* Accents */
  --primary: #6366f1;
  --primary-2: #7c83f7;
  --primary-weak: rgba(99, 102, 241, 0.15);
  --primary-ring: rgba(99, 102, 241, 0.5);
  --success: #22c55e;
  --success-weak: rgba(34, 197, 94, 0.14);
  --warn: #f59e0b;
  --warn-weak: rgba(245, 158, 11, 0.14);
  --danger: #f0586a;
  --danger-weak: rgba(240, 88, 106, 0.13);
  --info: #38bdf8;
  --info-weak: rgba(56, 189, 248, 0.13);

  /* Geometry */
  --r-sm: 7px;
  --r: 11px;
  --r-lg: 16px;
  --r-pill: 999px;

  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --sh-2: 0 12px 32px -14px rgba(0, 0, 0, 0.6);
  --sh-pop: 0 28px 64px -18px rgba(0, 0, 0, 0.75);

  --t: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --maxw: 1180px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* ---- Layout ------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(10, 14, 22, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand-mark { display: inline-flex; align-items: center; gap: 9px; color: var(--text); font-weight: 700; }
.brand-mark:hover { text-decoration: none; }
.brand-dot {
  width: 13px; height: 13px; border-radius: 4px;
  background: linear-gradient(135deg, var(--primary-2), var(--info));
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.6);
}
.brand-dot-lg { width: 22px; height: 22px; border-radius: 7px; }
.brand-name { letter-spacing: -0.01em; }
.topnav { display: flex; align-items: center; gap: 6px; }
.navlink {
  padding: 7px 12px; border-radius: var(--r-sm); color: var(--muted); font-weight: 500;
  transition: color var(--t), background var(--t);
}
.navlink:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.navlink.active { color: var(--text); background: var(--primary-weak); }
.inline { display: inline; }

main { max-width: var(--maxw); margin: 0 auto; padding: 28px 24px 80px; }
.main-narrow { display: grid; place-items: center; min-height: 88vh; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.subtitle { color: var(--muted); margin: 6px 0 0; max-width: 60ch; }
.back-link { display: inline-block; color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.head-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Cards -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--sh-1);
}
.subcard {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin: 16px 0;
}
.subcard-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.subcard-head .muted { font-size: 0.82rem; }
.form-narrow { max-width: 560px; }

/* ---- Forms -------------------------------------------------------------- */
.field { margin: 0 0 14px; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-size: 0.82rem; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  font: inherit;
  transition: border-color var(--t), box-shadow var(--t);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
select { cursor: pointer; }
input[type="file"] { padding: 8px; cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 7px; color: var(--text); font-weight: 500; margin: 0; }
.check input { width: auto; }
.hint { color: var(--faint); font-size: 0.8rem; margin: 12px 0 0; }
kbd {
  font-family: var(--mono); font-size: 0.72rem;
  background: var(--elev); border: 1px solid var(--line-2);
  border-radius: 5px; padding: 1px 5px;
}

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--elev);
  color: var(--text);
  font: inherit; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t), border-color var(--t), filter var(--t), opacity var(--t);
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: 6px 11px; min-height: 32px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-secondary { background: var(--elev); border-color: var(--line-2); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--primary); }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--danger-weak); color: var(--danger); }
.btn-danger:hover { background: var(--danger-weak); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }

/* In-flight htmx buttons show a spinner and hide their label. */
.btn.htmx-request { color: transparent !important; pointer-events: none; }
.btn.htmx-request .icon { opacity: 0; }
.btn.htmx-request::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: #fff; animation: spin 0.7s linear infinite;
}
.btn-ghost.htmx-request::after, .btn-secondary.htmx-request::after { color: var(--text); }

/* ---- Banners ------------------------------------------------------------ */
.banner {
  padding: 10px 13px; border-radius: var(--r-sm); font-size: 0.88rem; margin: 10px 0;
  border: 1px solid var(--line-2);
}
.banner-error { background: var(--danger-weak); border-color: rgba(240, 88, 106, 0.4); color: #ffc4cb; }
.banner-success { background: var(--success-weak); border-color: rgba(34, 197, 94, 0.4); color: #bff0cf; }

/* ---- Empty states ------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 6px; padding: 48px 24px; color: var(--muted);
}
.empty .icon-lg { width: 40px; height: 40px; color: var(--faint); margin-bottom: 6px; }
.empty-title { font-weight: 600; color: var(--text); margin: 0; }
.empty-sub { margin: 0; max-width: 42ch; }
.empty .btn { margin-top: 12px; }
.gallery .empty { grid-column: 1 / -1; }

/* ---- Brand grid --------------------------------------------------------- */
.brand-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.brand-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px; color: var(--text); transition: border-color var(--t), transform var(--t), background var(--t);
}
.brand-card:hover { border-color: var(--primary); background: var(--surface-2); text-decoration: none; transform: translateY(-2px); }
.brand-card-name { font-weight: 600; font-size: 1.05rem; }
.brand-card-desc { color: var(--muted); font-size: 0.85rem; }
.brand-card-go { color: var(--primary-2); font-size: 0.82rem; margin-top: 4px; }

/* ---- Generate layout ---------------------------------------------------- */
.gen-layout { display: grid; grid-template-columns: 380px 1fr; gap: 22px; align-items: start; }
.gen-form { position: sticky; top: 84px; margin-bottom: 0; }
.gen-actions { display: flex; gap: 10px; margin-top: 16px; }
.gen-actions .btn { flex: 1; }
.results-head { margin: 2px 0 14px; }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 12px; background: var(--bg); border: 1px dashed var(--line-2); border-radius: var(--r-sm); }

/* ---- Gallery + tiles ---------------------------------------------------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.tile {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--sh-1);
  transition: border-color var(--t);
}
.tile-ready:hover { border-color: var(--line-2); }
.tile-failed { border-color: rgba(240, 88, 106, 0.35); }
.tile-media { position: relative; width: 100%; background: var(--bg); overflow: hidden; }
.tile-zoom { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.tile-img { display: block; width: 100%; height: 100%; object-fit: cover; }

.tile-skeleton { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.shimmer { position: absolute; inset: 0; background: linear-gradient(100deg, var(--surface-2) 30%, var(--elev) 50%, var(--surface-2) 70%); background-size: 200% 100%; animation: shimmer 1.5s ease-in-out infinite; }
.tile-progress { position: relative; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 0.85rem; font-weight: 500; }

.tile-error { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 18px; color: var(--danger); }
.tile-error .icon-lg { width: 30px; height: 30px; }
.tile-error-msg { color: var(--muted); font-size: 0.8rem; margin: 0; line-height: 1.4; }

.tile-foot { padding: 11px 12px; display: flex; flex-direction: column; gap: 9px; }
.tile-badges { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 0.74rem; }
.tile-source { color: var(--muted); }
.tile-quality { color: var(--faint); text-transform: capitalize; }
.tile-quality::before { content: "· "; }
.tile-size { color: var(--faint); margin-left: auto; }
.tile-prompt { margin: 0; font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.01em;
  border: 1px solid transparent;
}
.badge-pending { background: var(--info-weak); color: var(--info); }
.badge-processing { background: var(--primary-weak); color: var(--primary-2); }
.badge-processing::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
.badge-ready { background: var(--success-weak); color: var(--success); }
.badge-failed { background: var(--danger-weak); color: var(--danger); }

.tile-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tile-actions .btn { flex: 0 0 auto; }
.upscale-menu { position: relative; }
.upscale-menu > summary { list-style: none; display: inline-flex; }
.upscale-menu > summary::-webkit-details-marker { display: none; }
.upscale-form {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 10;
  display: flex; flex-direction: column; gap: 8px; width: 200px;
  background: var(--elev); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 10px; box-shadow: var(--sh-2);
}

/* ---- Files -------------------------------------------------------------- */
.upload-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.upload-row input[type="file"] { flex: 1 1 200px; width: auto; }
.upload-row select { width: auto; }
.file-list { list-style: none; margin: 0; padding: 0; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.file-name { display: inline-flex; align-items: center; gap: 8px; }
.file-actions { display: flex; gap: 6px; }

/* ---- Login -------------------------------------------------------------- */
.login-card { width: min(380px, 92vw); margin: 0; text-align: center; }
.login-brand { display: inline-flex; align-items: center; gap: 11px; margin-bottom: 2px; }
.login-title { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.login-sub { color: var(--muted); margin: 0 0 18px; }
.login-card form { text-align: left; }

/* ---- Toasts ------------------------------------------------------------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.toast {
  padding: 12px 15px; border-radius: var(--r-sm);
  background: var(--elev); border: 1px solid var(--line-2); color: var(--text);
  box-shadow: var(--sh-2); font-size: 0.88rem;
  opacity: 0; transform: translateY(8px); transition: opacity var(--t), transform var(--t);
  border-left: 3px solid var(--line-2);
}
.toast-in { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--info); }

/* ---- Modal -------------------------------------------------------------- */
body.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 40px;
  background: rgba(5, 8, 13, 0.86); backdrop-filter: blur(6px);
}
.modal-img { max-width: 92vw; max-height: 88vh; border-radius: var(--r); box-shadow: var(--sh-pop); }
.modal-close {
  position: absolute; top: 18px; right: 22px; width: 40px; height: 40px;
  background: var(--elev); border: 1px solid var(--line-2); border-radius: 50%;
  color: var(--text); font-size: 22px; line-height: 1; cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); }

/* ---- Icons + spinner ---------------------------------------------------- */
.icon { width: 18px; height: 18px; flex: 0 0 auto; }
.icon-lg { width: 28px; height: 28px; }
.spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid var(--primary-2); border-top-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite; flex: 0 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 860px) {
  .gen-layout { grid-template-columns: 1fr; }
  .gen-form { position: static; }
}
@media (max-width: 520px) {
  main { padding: 20px 16px 64px; }
  .page-head { align-items: flex-start; }
  .toasts { left: 16px; right: 16px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .shimmer { animation: none; background: var(--surface-2); }
  .spinner { border-top-color: var(--primary-2); }
}
