:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17211f;
  background: #eef2f1;
  font-synthesis: none;
  --ink: #17211f;
  --muted: #66716e;
  --line: #d6ddda;
  --line-strong: #b7c2be;
  --paper: #ffffff;
  --surface: #f7f9f8;
  --accent: #16745d;
  --accent-dark: #0f5d4a;
  --accent-soft: #e7f3ef;
  --warning: #9a6214;
  --danger: #a33a32;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: #eef2f1;
  color: var(--ink);
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(22, 116, 93, 0.22);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(460px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 18px 55px rgba(25, 42, 37, 0.08);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-lockup strong, .brand-lockup span { display: block; letter-spacing: 0; }
.brand-lockup strong { font-size: 15px; line-height: 1.3; }
.brand-lockup > div > span { margin-top: 2px; color: var(--muted); font-size: 11px; text-transform: uppercase; }

.brand-mark {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--ink);
  color: white;
  font-size: 12px;
  font-weight: 750;
}

.login-brand { margin-bottom: 38px; }
.oidc-buttons { display: grid; gap: 8px; }
.oidc-button { width: 100%; min-height: 44px; }
.login-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 11px;
}
.login-divider::before, .login-divider::after { content: ""; height: 1px; background: var(--line); }
.login-form label { display: block; margin-bottom: 9px; font-size: 13px; font-weight: 650; }
.password-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }

input[type="password"], textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

input[type="password"] { height: 44px; padding: 0 12px; }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 12px; }

.studio { min-height: 100vh; }
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  position: sticky;
  top: 0;
  z-index: 20;
}

.top-actions { display: flex; align-items: center; gap: 10px; }
.user-label {
  max-width: 240px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #9aa4a0; }
.status-pill.ready .status-dot { background: var(--accent); }
.status-pill.warning .status-dot { background: var(--warning); }

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}
.icon-button:hover { background: var(--surface); border-color: var(--line-strong); }
.icon-button svg, .button svg { width: 17px; height: 17px; stroke-width: 1.8; }

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.composer-panel {
  align-self: start;
  min-height: calc(100vh - 64px);
  padding: 28px 24px 32px;
  border-right: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 64px;
}

.gallery-panel { min-width: 0; padding: 28px clamp(20px, 3vw, 44px) 56px; }
.panel-heading, .gallery-heading, .gallery-heading > div {
  display: flex;
  align-items: baseline;
}
.panel-heading, .gallery-heading { justify-content: space-between; gap: 16px; }
.panel-heading > div, .gallery-heading > div { display: flex; align-items: baseline; gap: 10px; }
.section-index { color: var(--accent); font-size: 11px; font-weight: 750; }
h1, h2 { margin: 0; font-size: 19px; line-height: 1.25; letter-spacing: 0; }
.character-count, .gallery-count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.generation-form { margin-top: 28px; }
.field { margin: 0 0 24px; padding: 0; border: 0; }
.field > label, .field > legend { display: block; margin: 0 0 9px; padding: 0; font-size: 12px; font-weight: 700; }
.prompt-field textarea {
  min-height: 196px;
  max-height: 360px;
  resize: vertical;
  padding: 13px 14px;
  line-height: 1.6;
}
textarea::placeholder { color: #98a19e; }

.ratio-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.ratio-option { min-width: 0; position: relative; }
.ratio-option input, .segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.ratio-option > span:last-child {
  height: 58px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 4px 7px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
}
.ratio-shape {
  position: absolute;
  z-index: 1;
  display: block;
  border: 1.5px solid currentColor;
  color: #8a9490;
  pointer-events: none;
  transform: translate(calc(50% + 3px), 9px);
}
.ratio-shape.square { width: 18px; height: 18px; }
.ratio-shape.landscape { width: 23px; height: 16px; transform: translate(calc(50% - 1px), 10px); }
.ratio-shape.portrait { width: 15px; height: 22px; transform: translate(calc(50% + 5px), 7px); }
.ratio-shape.wide { width: 25px; height: 14px; transform: translate(calc(50% - 2px), 11px); }
.ratio-option input:checked ~ span { color: var(--accent); }
.ratio-option input:checked ~ span:last-child { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.segmented-control span {
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
}
.segmented-control input:checked + span { background: var(--paper); color: var(--ink); font-weight: 700; box-shadow: 0 1px 4px rgba(23, 33, 31, 0.1); }
.inline-field { display: grid; grid-template-columns: 1fr 128px; align-items: center; }
.inline-field > label { margin: 0; }
select { height: 38px; padding: 0 32px 0 11px; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 16px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}
.button.primary { background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { border-color: var(--line-strong); background: var(--paper); color: var(--ink); }
.button.compact { min-height: 44px; }
.generate-button { width: 100%; height: 48px; }
.button:disabled { cursor: not-allowed; opacity: 0.55; }
.button.loading svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.gallery-heading { min-height: 28px; }
.gallery-count { min-width: 24px; height: 20px; display: grid; place-items: center; border-radius: 10px; background: #dfe6e3; color: #4f5c58; }
.text-button { border: 0; padding: 5px 0; background: transparent; color: var(--muted); font-size: 12px; }
.text-button:hover { color: var(--danger); }

.empty-state {
  min-height: calc(100vh - 180px);
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
}
.empty-state p { margin: 14px 0 0; font-size: 12px; }
.empty-frame {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.45);
}
.empty-frame svg { width: 24px; height: 24px; stroke-width: 1.3; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  margin-top: 22px;
}
.image-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}
.image-stage {
  position: relative;
  aspect-ratio: var(--image-ratio, 1 / 1);
  overflow: hidden;
  background: #dfe5e2;
}
.image-stage img { width: 100%; height: 100%; display: block; object-fit: cover; cursor: zoom-in; }
.card-actions {
  position: absolute;
  right: 8px;
  top: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 150ms ease, transform 150ms ease;
}
.image-card:hover .card-actions, .image-card:focus-within .card-actions { opacity: 1; transform: none; }
.card-actions .icon-button { width: 32px; height: 32px; border-color: rgba(255,255,255,.55); background: rgba(255,255,255,.92); }
.card-body { padding: 12px; }
.card-prompt { margin: 0; overflow: hidden; color: #2d3835; font-size: 12px; line-height: 1.5; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.card-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 10px; }

.pending-card { border-color: #d9dfdc; }
.pending-stage {
  overflow: hidden;
  background: #f1f3f2;
  isolation: isolate;
}
.pending-visual,
.pending-visual::before,
.pending-visual::after,
.pending-dot-layer {
  position: absolute;
  pointer-events: none;
}
.pending-visual { inset: 0; overflow: hidden; }
.pending-visual::before,
.pending-visual::after,
.pending-dot-layer {
  content: "";
  inset: -24%;
  background-image: radial-gradient(circle, rgba(67, 79, 75, 0.45) 0 1px, transparent 1.25px);
  will-change: transform, opacity;
}
.pending-visual::before {
  background-size: 14px 14px;
  opacity: 0.58;
  -webkit-mask-image: radial-gradient(ellipse 43% 38% at 72% 22%, #000 0%, rgba(0, 0, 0, 0.72) 48%, transparent 100%);
  mask-image: radial-gradient(ellipse 43% 38% at 72% 22%, #000 0%, rgba(0, 0, 0, 0.72) 48%, transparent 100%);
  animation: dots-drift-a 8.5s ease-in-out infinite alternate;
}
.pending-visual::after {
  background-size: 17px 17px;
  opacity: 0.44;
  -webkit-mask-image: radial-gradient(ellipse 47% 42% at 27% 76%, #000 0%, rgba(0, 0, 0, 0.68) 45%, transparent 100%);
  mask-image: radial-gradient(ellipse 47% 42% at 27% 76%, #000 0%, rgba(0, 0, 0, 0.68) 45%, transparent 100%);
  animation: dots-drift-b 10.5s ease-in-out infinite alternate;
}
.pending-dot-layer {
  display: block;
  background-size: 11px 11px;
  opacity: 0.2;
  -webkit-mask-image: radial-gradient(ellipse 32% 47% at 54% 49%, #000 0%, rgba(0, 0, 0, 0.5) 42%, transparent 100%);
  mask-image: radial-gradient(ellipse 32% 47% at 54% 49%, #000 0%, rgba(0, 0, 0, 0.5) 42%, transparent 100%);
  animation: dots-drift-c 7s ease-in-out infinite alternate;
}
.pending-status {
  position: absolute;
  z-index: 2;
  left: 14px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #53605c;
  font-size: 11px;
}
.pending-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pending-pulse 1.8s ease-in-out infinite;
}
.pending-elapsed {
  color: #818b87;
  font-variant-numeric: tabular-nums;
}
@keyframes dots-drift-a {
  0% { transform: translate3d(-2%, -1%, 0) scale(0.98); opacity: 0.38; }
  55% { opacity: 0.68; }
  100% { transform: translate3d(5%, 4%, 0) scale(1.04); opacity: 0.48; }
}
@keyframes dots-drift-b {
  0% { transform: translate3d(4%, 3%, 0) scale(1.03); opacity: 0.34; }
  50% { opacity: 0.54; }
  100% { transform: translate3d(-5%, -3%, 0) scale(0.97); opacity: 0.42; }
}
@keyframes dots-drift-c {
  0% { transform: translate3d(-1%, 4%, 0); opacity: 0.12; }
  100% { transform: translate3d(3%, -4%, 0); opacity: 0.28; }
}
@keyframes pending-pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.82); }
  50% { opacity: 1; transform: scale(1); }
}

.lightbox {
  width: min(1120px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  background: #101514;
  color: white;
}
.lightbox::backdrop { background: rgba(8, 13, 12, 0.86); }
.lightbox > img { width: 100%; max-height: calc(100vh - 140px); display: block; object-fit: contain; background: #0b0f0e; }
.lightbox-close { position: absolute; z-index: 2; top: 10px; right: 10px; border-color: rgba(255,255,255,.2); background: rgba(16,21,20,.8); color: white; }
.lightbox-caption { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 14px; }
.lightbox-caption p { max-width: 760px; margin: 0; font-size: 12px; line-height: 1.5; color: #d8dfdc; }
.lightbox-caption .button { flex: 0 0 auto; }

.toast-region { position: fixed; z-index: 50; right: 18px; bottom: 18px; display: grid; gap: 8px; }
.toast { max-width: min(380px, calc(100vw - 36px)); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 11px 13px; background: var(--paper); box-shadow: 0 10px 30px rgba(20,35,31,.14); font-size: 12px; }
.toast.error { border-left-color: var(--danger); }

@media (max-width: 820px) {
  .topbar { padding: 0 16px; }
  .status-pill > span:last-child { display: none; }
  .status-pill { width: 30px; justify-content: center; padding: 0; }
  .workspace { display: block; }
  .composer-panel { min-height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); padding: 24px 18px 28px; }
  .gallery-panel { padding: 24px 18px 40px; }
  .prompt-field textarea { min-height: 150px; }
  .empty-state { min-height: 280px; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .card-body { padding: 10px; }
  .card-actions { opacity: 1; transform: none; }
}

@media (max-width: 520px) {
  .login-shell { padding: 26px 20px; }
  .password-row { grid-template-columns: 1fr; }
  .user-label { display: none; }
  .gallery-grid { grid-template-columns: 1fr; }
  .lightbox { width: calc(100vw - 20px); }
  .lightbox-caption { align-items: flex-start; }
  .lightbox-caption p { max-height: 54px; overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .pending-visual::before, .pending-visual::after, .pending-dot-layer, .pending-pulse { animation: none !important; }
}
