:root {
  --bg: #08111f;
  --bg-2: #0f1e31;
  --panel: rgba(12, 24, 41, 0.86);
  --panel-soft: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.11);
  --text: #f5f9ff;
  --muted: #9fb0c7;
  --line: rgba(166, 197, 255, 0.18);
  --line-strong: rgba(166, 197, 255, 0.32);
  --accent: #3b82f6;
  --accent-2: #18c6a3;
  --accent-3: #f59e0b;
  --danger: #f05252;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 12%, rgba(59, 130, 246, 0.24), transparent 32%),
    radial-gradient(circle at 78% 8%, rgba(24, 198, 163, 0.18), transparent 28%),
    linear-gradient(135deg, #07101d 0%, #0b1728 45%, #101520 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(140, 180, 255, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(140, 180, 255, 0.055) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent 82%);
}

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

button {
  cursor: pointer;
}

.shell {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 74px;
  padding: 0 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 17, 31, 0.76);
  backdrop-filter: blur(22px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: linear-gradient(135deg, #1d4ed8, #15b8a6);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 14px 34px rgba(59, 130, 246, 0.34);
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 15px;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.status {
  min-width: 92px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  font-size: 13px;
  text-align: center;
}

.status.ready {
  color: #86efac;
  border-color: rgba(134, 239, 172, 0.28);
  background: rgba(22, 163, 74, 0.12);
}

.status.missing {
  color: #fcd34d;
  border-color: rgba(252, 211, 77, 0.28);
  background: rgba(245, 158, 11, 0.13);
}

.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.ghost-button,
.admin-link {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.admin-link {
  display: inline-flex;
  align-items: center;
}

.panel-heading p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.workspace {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 28px;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(340px, 470px) minmax(0, 1fr);
  gap: 24px;
}

.studio,
.gallery {
  min-height: calc(100vh - 130px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.studio {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-heading span,
.gallery-head span,
.control-label,
label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.panel-heading span,
.gallery-head span {
  color: #93c5fd;
  text-transform: uppercase;
}

.panel-heading h1 {
  margin: 6px 0 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.prompt-block {
  display: flex;
  min-height: 250px;
  flex-direction: column;
  gap: 10px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(59, 130, 246, 0.75);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.16);
}

textarea {
  min-height: 230px;
  padding: 15px;
  resize: vertical;
  line-height: 1.65;
}

textarea::placeholder,
input::placeholder {
  color: rgba(159, 176, 199, 0.8);
}

input,
select {
  height: 43px;
  margin-top: 8px;
  padding: 0 12px;
}

select option {
  color: #0b1220;
}

.quick-prompts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.quick-prompts button,
.segmented button,
.size-grid button,
.style-grid button,
.result-actions button,
.result-actions a {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-soft);
  text-decoration: none;
}

.quick-prompts button {
  min-height: 38px;
  padding: 0 10px;
  color: #cfe0ff;
  font-size: 13px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.control-wide {
  grid-column: 1 / -1;
}

.segmented,
.style-grid {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented button,
.style-grid button {
  min-height: 42px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.style-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.size-grid button {
  min-height: 58px;
  padding: 8px;
  display: grid;
  align-content: center;
  gap: 4px;
  text-align: left;
}

.size-grid strong {
  font-size: 13px;
}

.size-grid span {
  color: var(--muted);
  font-size: 11px;
}

.quick-prompts button:hover,
.segmented button:hover,
.size-grid button:hover,
.style-grid button:hover {
  border-color: var(--line-strong);
  background: var(--panel-strong);
}

.segmented button.active,
.size-grid button.active,
.style-grid button.active {
  border-color: rgba(59, 130, 246, 0.8);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.34), rgba(24, 198, 163, 0.16));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#generate {
  grid-column: 1 / -1;
  height: 50px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #16a394);
  font-weight: 900;
  box-shadow: 0 18px 38px rgba(37, 99, 235, 0.3);
}

#generate:hover {
  filter: brightness(1.08);
}

#generate:disabled {
  cursor: wait;
  filter: saturate(0.5);
}

.progress-card {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: #dbeafe;
  font-size: 13px;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3b82f6, #18c6a3, #f59e0b);
  transition: width 0.55s ease;
}

.gallery {
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.gallery::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 36px 36px;
}

.gallery-head {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.gallery-head strong {
  font-size: 14px;
  color: #dbeafe;
}

.empty {
  position: relative;
  z-index: 1;
  min-height: 500px;
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(280px, 1fr);
  align-items: start;
  gap: 28px;
  padding-top: 64px;
}

.empty img {
  width: 100%;
  max-height: 500px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.empty h1 {
  margin: 0 0 16px;
  color: #ffffff;
  font-size: 64px;
  line-height: 0.96;
  letter-spacing: 0;
}

.empty p {
  max-width: 600px;
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.75;
}

.grid {
  position: relative;
  z-index: 1;
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.grid.active {
  display: grid;
}

.empty.hidden {
  display: none;
}

.result {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.result img {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.06);
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
}

.result-actions a,
.result-actions button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.result-actions a {
  background: rgba(59, 130, 246, 0.28);
}

.result-actions button {
  background: rgba(255, 255, 255, 0.08);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  width: min(440px, calc(100vw - 44px));
  padding: 14px 16px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 8px;
  color: #fff;
  background: rgba(127, 29, 29, 0.94);
  box-shadow: var(--shadow);
  line-height: 1.5;
}

.settings-dialog {
  width: min(560px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: rgba(12, 24, 41, 0.98);
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(8px);
}

.settings-panel {
  padding: 22px;
}

.settings-panel header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.settings-panel h2 {
  margin: 4px 0 0;
}

.settings-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.settings-panel label,
.admin-form label,
.login-card label {
  display: block;
  margin-bottom: 14px;
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.settings-actions button,
.settings-panel header button,
.admin-form button,
.login-card button,
.user-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-soft);
  font-weight: 800;
}

.settings-actions button:last-child,
.admin-form button,
.login-card button {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #16a394);
}

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

.login-card {
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.login-brand {
  margin-bottom: 28px;
}

.login-card h1 {
  margin: 0 0 10px;
  font-size: 34px;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.7;
}

.admin-layout {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 24px;
}

.admin-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.admin-form {
  margin-top: 20px;
}

.user-table {
  display: grid;
  gap: 12px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.user-row strong,
.user-row span,
.user-row small {
  display: block;
}

.user-row span,
.user-row small {
  margin-top: 4px;
  color: var(--muted);
}

.user-actions {
  display: inline-flex;
  gap: 8px;
}

@media (max-width: 1020px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .studio,
  .gallery {
    min-height: auto;
  }

  .empty {
    min-height: 440px;
    grid-template-columns: 1fr;
    padding-top: 0;
  }

  .empty img {
    max-height: 360px;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: 64px;
    padding: 0 14px;
  }

  .brand small {
    display: none;
  }

  .top-actions {
    gap: 6px;
  }

  .ghost-button,
  .admin-link {
    padding: 0 9px;
    font-size: 12px;
  }

  .workspace {
    padding: 12px;
    gap: 12px;
  }

  .studio,
  .gallery {
    padding: 14px;
  }

  .controls,
  .quick-prompts,
  .segmented,
  .size-grid,
  .style-grid {
    grid-template-columns: 1fr;
  }

  .empty h1 {
    font-size: 38px;
  }

  .settings-actions,
  .user-row {
    grid-template-columns: 1fr;
  }

  .user-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
