:root {
  color-scheme: dark;
  --bg-dark: #0f0f23;
  --bg-mid: #1a1a2e;
  --bg-light: #16213e;
  --panel: rgba(255, 255, 255, 0.05);
  --panel-hover: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.2);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.62);
  --faint: rgba(255, 255, 255, 0.4);
  --purple: #8b5cf6;
  --indigo: #6366f1;
  --cyan: #06b6d4;
  --pink: #ec4899;
  --danger: #fb7185;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-dark);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

.gradient-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(at 40% 20%, rgba(139, 92, 246, 0.16) 0, transparent 48%),
    radial-gradient(at 80% 0%, rgba(6, 182, 212, 0.12) 0, transparent 45%),
    radial-gradient(at 0% 50%, rgba(236, 72, 153, 0.1) 0, transparent 48%),
    radial-gradient(at 80% 50%, rgba(139, 92, 246, 0.1) 0, transparent 50%),
    radial-gradient(at 0% 100%, rgba(6, 182, 212, 0.11) 0, transparent 46%),
    linear-gradient(135deg, var(--bg-dark), var(--bg-mid) 58%, var(--bg-light));
}

#particleCanvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.75;
}

.hidden {
  display: none !important;
}

.glass {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.auth-screen {
  position: relative;
  z-index: 2;
  display: grid;
  align-content: center;
  min-height: 100vh;
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  padding: 36px 0;
}

.auth-brand {
  margin-bottom: 26px;
}

.auth-brand h1,
.page-title h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.02;
  background: linear-gradient(90deg, #c4b5fd, #f0abfc, #67e8f9);
  -webkit-background-clip: text;
  color: transparent;
}

.auth-brand p:last-child {
  max-width: 620px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--purple), var(--indigo));
  box-shadow: 0 16px 40px rgba(139, 92, 246, 0.34);
  font-weight: 800;
}

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

.app-layout {
  position: relative;
  z-index: 2;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  width: 240px;
  height: 100vh;
  border-top: 0;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--line);
}

.sidebar-logo strong,
.sidebar-logo span {
  display: block;
}

.sidebar-logo strong {
  font-size: 20px;
  line-height: 1.2;
  background: linear-gradient(90deg, #c4b5fd, #67e8f9);
  -webkit-background-clip: text;
  color: transparent;
}

.sidebar-logo span,
.sidebar-user small {
  color: var(--faint);
  font-size: 12px;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 6px;
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.tab {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  transition: background 220ms ease, color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
}

.tab span {
  width: 20px;
  color: inherit;
  text-align: center;
}

.tab:hover {
  transform: translateX(2px);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.tab.active {
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.2);
  box-shadow: 0 14px 32px rgba(139, 92, 246, 0.11);
}

.sidebar-user {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  border-top: 1px solid var(--line);
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--purple), var(--indigo));
}

.sidebar-user span {
  display: block;
  max-width: 118px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content-shell {
  min-height: 100vh;
  margin-left: 240px;
  padding: 24px;
}

.page-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #67e8f9;
  font-size: 12px;
  line-height: 1.2;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.2;
}

h3 {
  margin: 0 0 16px;
  font-size: 17px;
}

.panel {
  display: none;
  animation: rise 260ms ease both;
}

.panel.active {
  display: block;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.grid {
  display: grid;
  gap: 20px;
}

.two-col {
  grid-template-columns: minmax(0, 1.02fr) minmax(360px, 0.98fr);
}

.card {
  border-radius: 18px;
  padding: 24px;
  transition: background 220ms ease, border-color 220ms ease, transform 220ms ease, box-shadow 220ms ease;
}

.card:hover {
  transform: translateY(-3px);
  background: var(--panel-hover);
  border-color: var(--line-strong);
  box-shadow: 0 24px 70px rgba(139, 92, 246, 0.12);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.form-stack,
.settings-block {
  display: grid;
  gap: 14px;
}

label,
.compact-field {
  display: grid;
  gap: 8px;
}

label span,
.compact-field span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 500;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 12px 14px;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

textarea {
  resize: vertical;
  min-height: 100px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

select option {
  color: var(--text);
  background: var(--bg-mid);
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(139, 92, 246, 0.88);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

.primary-btn,
.secondary-btn,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--text);
  font-weight: 650;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}

.primary-btn {
  min-height: 44px;
  padding: 0 20px;
  background: linear-gradient(90deg, var(--purple), var(--indigo));
  box-shadow: 0 16px 38px rgba(139, 92, 246, 0.26);
}

.secondary-btn {
  min-height: 42px;
  padding: 0 16px;
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.1);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
  font-size: 22px;
  line-height: 1;
}

.primary-btn:hover,
.secondary-btn:hover,
.icon-btn:hover {
  transform: translateY(-2px) scale(1.02);
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 18px 44px rgba(139, 92, 246, 0.22);
}

.primary-btn:active,
.secondary-btn:active,
.icon-btn:active {
  transform: scale(0.98);
}

.primary-btn:disabled,
.secondary-btn:disabled,
.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.upload-zone {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 96px;
  padding: 16px;
  border: 1px dashed rgba(139, 92, 246, 0.52);
  border-radius: 16px;
  background: rgba(139, 92, 246, 0.09);
  overflow: hidden;
  transition: background 170ms ease, border-color 170ms ease;
}

.upload-zone:hover {
  border-color: rgba(6, 182, 212, 0.72);
  background: rgba(6, 182, 212, 0.08);
}

.upload-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-zone strong,
.upload-zone span {
  display: block;
}

.upload-zone span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.upload-zone img {
  width: 76px;
  height: 76px;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid var(--line-strong);
}

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

.result-card {
  display: flex;
  flex-direction: column;
  min-height: 720px;
}

.result-stage {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 520px;
  max-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    rgba(0, 0, 0, 0.18);
  background-size: 24px 24px;
  overflow: auto;
  overscroll-behavior: contain;
}

.result-stage.has-image {
  place-items: start center;
}

.result-stage img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
  animation: fadeIn 220ms ease both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

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

.result-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.result-actions {
  justify-content: center;
  margin-top: 14px;
}

.thumb-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.thumb-strip button {
  height: 70px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.thumb-strip button.active {
  border-color: #67e8f9;
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.16);
}

.thumb-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-card,
.chat-draft-card {
  min-height: 820px;
}

.chat-draft-card {
  display: flex;
  flex-direction: column;
}

.chat-messages {
  display: grid;
  align-content: start;
  gap: 12px;
  height: 560px;
  margin-top: 14px;
  overflow: auto;
  padding-right: 4px;
}

.chat-draft-card textarea {
  flex: 1;
  min-height: 600px;
}

.message {
  width: min(86%, 780px);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.55;
}

.message.user {
  justify-self: end;
  background: rgba(139, 92, 246, 0.18);
}

.message.assistant {
  justify-self: start;
  background: rgba(255, 255, 255, 0.08);
}

.chat-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-top: 16px;
  align-items: end;
}

.chat-input textarea {
  min-height: 72px;
}

.list {
  display: grid;
  gap: 12px;
  max-height: 620px;
  overflow: auto;
}

.list-item,
.history-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.list-item:hover,
.history-item:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.09);
}

.list-item h3,
.history-item h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.list-item p,
.history-item p {
  margin-bottom: 12px;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.history-image-card {
  display: grid;
  align-content: start;
  gap: 10px;
}

.history-topline,
.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.history-topline h3 {
  margin-bottom: 0;
}

.history-meta {
  margin-top: -2px;
}

.history-open-btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.history-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.history-image-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.history-image-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(103, 232, 249, 0.76);
  box-shadow: 0 12px 26px rgba(6, 182, 212, 0.12);
}

.history-images img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(3, 7, 18, 0.76);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

body.viewer-open {
  overflow: hidden;
}

.viewer-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  width: min(1180px, 100%);
  height: min(92vh, 920px);
  padding: 18px;
  border-radius: 20px;
}

.viewer-head,
.viewer-tools,
.viewer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.viewer-head {
  justify-content: space-between;
}

.viewer-tools {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.viewer-stage {
  position: relative;
  display: grid;
  place-items: start center;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.28);
  overflow: auto;
}

.viewer-stage img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(15, 15, 35, 0.82);
  color: var(--text);
  font-size: 30px;
  line-height: 1;
  transform: translateY(-50%);
}

.viewer-nav:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.viewer-prev {
  left: 16px;
}

.viewer-next {
  right: 16px;
}

.viewer-actions {
  justify-content: center;
}

.settings-block {
  align-content: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100% - 44px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(15, 15, 35, 0.86);
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

@media (max-width: 1080px) {
  .two-col,
  .auth-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .result-card {
    min-height: auto;
  }

  .result-stage {
    min-height: min(560px, 72vh);
  }
}

@media (max-width: 780px) {
  .sidebar {
    position: relative;
    width: auto;
    height: auto;
    margin: 10px;
    border: 1px solid var(--line);
    border-radius: 18px;
  }

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

  .sidebar-user {
    border-top: 1px solid var(--line);
  }

  .content-shell {
    margin-left: 0;
    padding: 10px;
  }

  .page-title,
  .section-head,
  .chat-input {
    display: grid;
  }

  .viewer-shell {
    height: calc(100vh - 20px);
    padding: 12px;
  }

  .viewer-head {
    align-items: flex-start;
  }

  .viewer-nav {
    width: 42px;
    height: 42px;
  }
}

@media (max-width: 560px) {
  .auth-screen {
    width: min(100% - 20px, 1120px);
  }

  .side-nav,
  .params-grid {
    grid-template-columns: 1fr;
  }

  .upload-zone {
    grid-template-columns: 1fr;
  }

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

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

  .image-viewer {
    padding: 10px;
  }

  .viewer-head,
  .viewer-actions {
    display: grid;
    justify-items: stretch;
  }

  .viewer-tools {
    justify-content: space-between;
  }

  .viewer-actions .secondary-btn {
    width: 100%;
  }
}
