:root {
  color-scheme: dark;
  --bg: #0c1012;
  --sidebar: #090c0e;
  --panel: #121719;
  --panel-raised: #182022;
  --line: #293337;
  --line-strong: #405056;
  --text: #f1f6f4;
  --muted: #9caaa7;
  --faint: #687774;
  --lime: #baf27a;
  --lime-ink: #112006;
  --amber: #f2bd6f;
  --coral: #f47b68;
  --cyan: #66d5cf;
  --danger: #ff8672;
  --z-sidebar: 20;
  --z-dialog: 50;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
label[for],
.upload-zone {
  cursor: pointer;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.upload-zone:focus-within {
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  background-image: linear-gradient(135deg, rgb(102 213 207 / 2.5%), transparent 34%, rgb(244 123 104 / 2%) 70%, transparent);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: var(--z-sidebar);
  display: flex;
  width: 220px;
  flex-direction: column;
  padding: 24px 14px 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.brand {
  display: flex;
  min-height: 52px;
  align-items: center;
  gap: 12px;
  padding: 0 10px 22px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 5px;
  border: 1px solid #40504e;
  background: #131a1b;
}

.brand-mark span {
  background: var(--lime);
}

.brand-mark span:last-child {
  margin-top: 9px;
  background: var(--amber);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.brand-text strong {
  font-size: 17px;
  font-weight: 800;
}

.brand-text small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
}

.primary-nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.nav-item:hover {
  color: var(--text);
  background: #171917;
}

.nav-item.active {
  border-color: #39514d;
  color: var(--lime);
  background: #16201e;
}

.nav-count {
  min-width: 24px;
  margin-left: auto;
  padding: 1px 6px;
  border-radius: 8px;
  color: var(--text);
  background: #31352f;
  font-size: 11px;
  text-align: center;
}

.sidebar-spacer {
  flex: 1;
}

.quota-block {
  margin: 0 10px 16px;
}

.quota-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--faint);
  font-size: 11px;
}

.quota-label strong {
  color: var(--muted);
  font-weight: 600;
}

.quota-track,
.progress-track {
  height: 3px;
  overflow: hidden;
  background: #31352f;
}

.quota-track span,
.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--lime);
  transition: width 300ms ease;
}

.progress-track span.indeterminate {
  width: 22% !important;
  animation: indeterminate 1.4s ease-in-out infinite alternate;
}

.main-area {
  min-height: 100vh;
  margin-left: 220px;
}

.topbar {
  display: flex;
  min-height: 92px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: rgb(12 16 18 / 86%);
  backdrop-filter: blur(16px);
}

.topbar > div,
.topbar-actions {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--faint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 23px;
  font-weight: 680;
  line-height: 1.2;
}

h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.topbar-actions,
.service-state,
.preview-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.service-state {
  min-width: 0;
  min-height: 44px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: #12191b;
  font-size: 12px;
  text-align: left;
  transition: border-color 180ms ease, background-color 180ms ease;
}

.service-state:hover {
  border-color: var(--line-strong);
  background: #192225;
}

.service-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.service-copy strong {
  overflow: hidden;
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-copy small {
  color: var(--faint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgb(244 184 96 / 12%);
  animation: status-pulse 2.4s ease-in-out infinite;
}

.service-state.ready .status-dot {
  background: var(--lime);
  box-shadow: 0 0 0 3px rgb(200 242 124 / 12%);
}

.service-state.error .status-dot {
  background: var(--coral);
  box-shadow: 0 0 0 3px rgb(237 118 95 / 12%);
}

.mobile-settings {
  display: none !important;
}

.studio {
  display: grid;
  grid-template-columns: minmax(390px, 460px) minmax(430px, 1fr);
  min-height: 680px;
  border-bottom: 1px solid var(--line);
  animation: studio-enter 360ms ease-out both;
}

.creation-tabs {
  display: flex;
  gap: 8px;
  padding: 16px 32px 0;
  border-bottom: 1px solid var(--line);
  background: #0d1214;
}

.creation-tab {
  display: inline-flex;
  min-width: 160px;
  min-height: 48px;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  background: transparent;
  text-align: left;
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.creation-tab:hover {
  color: var(--text);
  background: #151d1f;
}

.creation-tab.active {
  border-color: var(--line);
  color: var(--text);
  background: var(--panel);
  box-shadow: inset 0 2px 0 var(--lime);
}

.creation-tab span {
  font-size: 12px;
  font-weight: 650;
}

.creation-tab small {
  margin-left: auto;
  color: var(--faint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
}

.image-studio {
  display: grid;
  grid-template-columns: minmax(390px, 460px) minmax(430px, 1fr);
  min-height: 680px;
  border-bottom: 1px solid var(--line);
  animation: studio-enter 360ms ease-out both;
}

.image-composer,
.image-preview-panel {
  min-width: 0;
  padding: 26px 30px 30px;
}

.image-composer {
  border-right: 1px solid var(--line);
  box-shadow: inset 0 2px 0 var(--lime);
}

.image-preview-panel {
  background: #121719;
  box-shadow: inset 0 2px 0 var(--cyan);
}

.image-model-switch {
  margin-bottom: 20px;
}

.image-model-field {
  margin-bottom: 18px;
}

.model-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-input-row input {
  min-width: 0;
  flex: 1;
}

.model-fetch-button {
  flex: 0 0 34px;
  color: var(--cyan);
}

.model-fetch-button[aria-busy="true"] svg {
  animation: spin 900ms linear infinite;
}

.image-model-field small,
.control-group > small {
  display: block;
  margin-top: 7px;
  color: var(--faint);
  font-size: 11px;
}

.number-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.number-input input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  background: #0d1214;
}

.number-input span {
  color: var(--muted);
  white-space: nowrap;
}

.settings-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.settings-divider::before,
.settings-divider::after {
  flex: 1;
  height: 1px;
  background: var(--line);
  content: "";
}

.image-controls {
  display: grid;
  gap: 18px;
  margin-top: 22px;
}

.image-gallery {
  display: grid;
  min-height: 500px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-content: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #090d0e;
}

.gallery-empty,
.gallery-loading {
  display: flex;
  min-height: 420px;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--faint);
  text-align: center;
}

.gallery-empty svg {
  width: 42px;
  height: 42px;
  color: var(--cyan);
}

.gallery-empty strong,
.gallery-loading strong {
  color: var(--muted);
  font-size: 13px;
}

.gallery-empty small,
.gallery-loading small {
  font-size: 10px;
}

.gallery-item {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #121719;
  transition: border-color 180ms ease, opacity 180ms ease;
}

.gallery-item:hover,
.gallery-item.active {
  border-color: var(--lime);
}

.gallery-item:not(.active) {
  opacity: 0.7;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery-item span {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  color: var(--lime-ink);
  background: var(--lime);
  font-size: 10px;
  font-weight: 700;
}

.composer,
.preview-panel {
  min-width: 0;
  padding: 26px 30px 30px;
}

.composer {
  border-right: 1px solid var(--line);
  box-shadow: inset 0 2px 0 rgb(186 242 122 / 42%);
}

.preview-panel {
  box-shadow: inset 0 2px 0 rgb(102 213 207 / 42%);
}

.section-heading,
.preview-header,
.history-heading,
.history-heading > div,
.section-heading > div,
.preview-header > div:first-child {
  display: flex;
  align-items: center;
}

.section-heading,
.preview-header,
.history-heading {
  justify-content: space-between;
  margin-bottom: 22px;
}

.section-heading > div,
.preview-header > div:first-child,
.history-heading > div {
  gap: 10px;
}

.step-number {
  color: var(--lime);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
}

.model-badge {
  max-width: 190px;
  overflow: hidden;
  padding: 4px 7px;
  border: 1px solid #405039;
  border-radius: 3px;
  color: var(--lime);
  background: #181d15;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0e0f0e;
}

.segment {
  display: inline-flex;
  min-height: 39px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  transition: color 180ms ease, background-color 180ms ease;
}

.segment:hover {
  color: var(--text);
}

.segment.active {
  color: var(--text);
  background: #292d28;
  box-shadow: inset 0 0 0 1px #3b403a;
}

.mode-switch {
  width: 100%;
  min-width: 0;
  margin-bottom: 20px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field label,
.field-label-row label,
fieldset legend {
  color: #c8cdc5;
  font-size: 12px;
  font-weight: 600;
}

.field-label-row span,
.field > small {
  color: var(--faint);
  font-size: 11px;
}

textarea,
input[type="password"],
input[type="text"],
input[type="url"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #0d0e0d;
  transition: border-color 180ms ease, background-color 180ms ease;
}

textarea {
  min-height: 154px;
  padding: 14px 14px 44px;
  resize: vertical;
  line-height: 1.65;
}

textarea::placeholder,
input::placeholder {
  color: #62685f;
}

textarea:hover,
textarea:focus,
input[type="password"]:hover,
input[type="password"]:focus,
input[type="text"]:hover,
input[type="text"]:focus,
input[type="url"]:hover,
input[type="url"]:focus,
select:hover,
select:focus {
  border-color: var(--line-strong);
  background: #101210;
}

.prompt-field {
  position: relative;
}

.prompt-tools {
  position: absolute;
  right: 9px;
  bottom: 9px;
  left: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.text-tool {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  transition: color 180ms ease, background-color 180ms ease;
}

.text-tool:hover {
  color: var(--text);
  background: #252925;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: #181a18;
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  color: var(--text);
  background: #252825;
}

.icon-button.small {
  width: 32px;
  height: 32px;
  min-height: 32px;
  flex-basis: 32px;
  border-color: transparent;
  background: transparent;
}

.image-field {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.upload-zone {
  position: relative;
  display: flex;
  min-height: 88px;
  align-items: center;
  gap: 13px;
  padding: 12px;
  overflow: hidden;
  border: 1px dashed #485044;
  border-radius: 6px;
  background: #111311;
  transition: border-color 180ms ease, background-color 180ms ease;
}

.upload-zone:hover,
.upload-zone.dragging {
  border-color: var(--lime);
  background: #171c13;
}

.upload-icon,
.connection-icon {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border: 1px solid #3b4536;
  border-radius: 5px;
  color: var(--lime);
  background: #1b2117;
}

.upload-zone > span:nth-of-type(2) {
  display: grid;
  gap: 2px;
}

.upload-zone strong {
  font-size: 12px;
}

.upload-zone small {
  color: var(--faint);
  font-size: 10px;
}

.upload-zone img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-zone:has(img:not([hidden]))::after {
  position: absolute;
  inset: 0;
  content: "";
  background: rgb(0 0 0 / 18%);
}

.remove-image {
  position: absolute;
  z-index: 1;
  top: 8px;
  right: 8px;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 4px;
  color: white;
  background: rgb(0 0 0 / 66%);
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 14px;
  margin-top: 21px;
}

.control-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.control-group legend {
  margin-bottom: 8px;
}

.aspect-group {
  grid-column: 1 / -1;
}

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

.visual-option {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: #111211;
  font-size: 11px;
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.visual-option:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.visual-option.active {
  border-color: #738c58;
  color: var(--lime);
  background: #1a2016;
}

.ratio-icon {
  display: block;
  border: 1.5px solid currentColor;
  border-radius: 1px;
}

.ratio-icon.landscape {
  width: 22px;
  height: 14px;
}

.ratio-icon.portrait {
  width: 12px;
  height: 20px;
}

.ratio-icon.square {
  width: 17px;
  height: 17px;
}

.compact .segment {
  min-height: 40px;
  padding: 0 6px;
  font-size: 11px;
}

.duration-options {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.resolution-group .segment small {
  margin-left: 3px;
  padding: 1px 3px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 7px;
  opacity: 0.72;
}

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

.form-error {
  margin-top: 16px;
  padding: 9px 11px;
  border-left: 2px solid var(--danger);
  color: #ffc4ba;
  background: #281715;
  font-size: 12px;
}

.generate-button,
.primary-button {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  border-radius: 6px;
  color: var(--lime-ink);
  background: var(--lime);
  transition: background-color 180ms ease, box-shadow 180ms ease;
}

.generate-button {
  margin-top: 22px;
  padding: 0 13px 0 18px;
}

.generate-button:hover:not(:disabled),
.primary-button:hover:not(:disabled) {
  background: #ddffa1;
  box-shadow: 0 0 0 3px rgb(200 242 124 / 12%);
}

.generate-button > span,
.button-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button-meta {
  padding-left: 14px;
  border-left: 1px solid rgb(21 32 8 / 20%);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
}

.preview-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  background: #121412;
}

.stage {
  position: relative;
  display: grid;
  min-height: 420px;
  flex: 1;
  place-items: center;
  overflow: hidden;
  border: 1px solid #343934;
  border-radius: 6px;
  background: #070807;
}

.stage::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  opacity: 0.08;
  background-image: linear-gradient(#ffffff 1px, transparent 1px), linear-gradient(90deg, #ffffff 1px, transparent 1px);
  background-size: 48px 48px;
}

.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #070807;
}

.stage-topline {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  color: #d2d7cf;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  text-shadow: 0 1px 4px #000;
}

.live-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-label > span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--coral);
}

.generation-overlay,
.empty-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 30px;
  background: rgb(10 12 10 / 94%);
  text-align: center;
}

.generation-overlay p {
  margin: 5px 0 18px;
  color: var(--muted);
  font-size: 12px;
}

.generation-overlay .progress-track {
  width: min(260px, 74%);
  margin-bottom: 8px;
}

.generation-overlay small {
  color: var(--faint);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
}

.render-orbit {
  position: relative;
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  margin-bottom: 17px;
  border: 1px solid #3c4635;
  border-radius: 50%;
  color: var(--lime);
}

.render-orbit > span {
  position: absolute;
  inset: -4px;
  border: 2px solid transparent;
  border-top-color: var(--lime);
  border-right-color: var(--amber);
  border-radius: 50%;
  animation: spin 1.4s linear infinite;
}

.empty-overlay {
  gap: 10px;
  color: var(--faint);
}

.empty-overlay svg {
  width: 36px;
  height: 36px;
}

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

@keyframes indeterminate {
  from { transform: translateX(0); }
  to { transform: translateX(350%); }
}

.history-section {
  padding: 28px 32px 48px;
  box-shadow: inset 0 2px 0 rgb(244 123 104 / 34%);
}

.history-list {
  display: grid;
  gap: 7px;
}

.history-empty {
  display: flex;
  min-height: 100px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font-size: 12px;
}

.history-item {
  display: grid;
  min-width: 0;
  grid-template-columns: 46px minmax(0, 1fr) 92px 110px 38px;
  align-items: center;
  gap: 14px;
  min-height: 62px;
  padding: 7px 10px 7px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: inherit;
  background: #151715;
  text-align: left;
  transition: border-color 180ms ease, background-color 180ms ease;
}

.history-item:hover {
  border-color: var(--line-strong);
  background: #191c19;
}

.history-thumb {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 4px;
  color: var(--lime);
  background: #222820;
}

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

.history-info strong,
.history-info small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-info strong {
  margin-bottom: 3px;
  font-size: 12px;
  font-weight: 550;
}

.history-info small,
.history-time {
  color: var(--faint);
  font-size: 10px;
}

.job-status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 7px;
  border: 1px solid #495144;
  border-radius: 4px;
  color: #bfc6bb;
  font-size: 10px;
}

.job-status.completed,
.job-status.done,
.job-status.succeeded,
.job-status.success {
  border-color: #536b43;
  color: var(--lime);
  background: #192016;
}

.job-status.failed,
.job-status.error,
.job-status.cancelled {
  border-color: #69413a;
  color: #ffad9e;
  background: #271715;
}

.history-play {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 4px;
  color: var(--lime);
  background: #252b22;
}

.mobile-nav {
  display: none;
}

.settings-dialog {
  width: min(620px, calc(100vw - 28px));
  max-height: min(820px, calc(100vh - 28px));
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: #121719;
  box-shadow: 0 24px 80px rgb(0 0 0 / 50%);
}

.settings-dialog::backdrop {
  background: rgb(0 0 0 / 72%);
  backdrop-filter: blur(3px);
}

.dialog-card {
  padding: 24px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.connection-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0e1416;
}

.connection-summary > div,
.connection-summary strong,
.connection-summary small {
  display: block;
}

.connection-summary strong {
  margin-bottom: 2px;
  font-size: 12px;
}

.connection-summary small {
  color: var(--muted);
  font-size: 10px;
}

.password-input {
  position: relative;
}

.password-input input {
  min-height: 46px;
  padding: 0 48px 0 12px;
}

.settings-fields {
  display: grid;
  gap: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(150px, 0.65fr);
  gap: 12px;
}

.settings-dialog input,
.settings-dialog select {
  min-height: 46px;
  padding: 0 12px;
}

.settings-dialog select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 19px, calc(100% - 12px) 19px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

.input-with-icon {
  position: relative;
}

.input-with-icon > svg {
  position: absolute;
  z-index: 1;
  top: 14px;
  left: 12px;
  width: 16px;
  color: var(--faint);
}

.input-with-icon input {
  padding-left: 38px;
}

.api-key-field {
  padding: 13px;
  border: 1px solid #3c4d47;
  border-radius: 6px;
  background: #101816;
}

.password-input .icon-button {
  position: absolute;
  top: 7px;
  right: 7px;
}

.connection-route {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #0d1214;
}

.connection-route span {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10px;
}

.connection-route code {
  overflow: hidden;
  color: var(--cyan);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.security-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 12px 0 18px;
  color: var(--faint);
  font-size: 10px;
}

.security-note svg {
  flex: 0 0 auto;
  color: var(--lime);
}

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

.primary-button,
.secondary-button {
  min-height: 46px;
  justify-content: center;
  font-weight: 700;
}

.primary-button {
  gap: 8px;
}

.secondary-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #171d1f;
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.secondary-button:hover {
  border-color: var(--line-strong);
  color: var(--text);
  background: #1d2629;
}

@keyframes status-pulse {
  50% { box-shadow: 0 0 0 6px rgb(186 242 122 / 4%); }
}

@keyframes studio-enter {
  from { opacity: 0; transform: translateY(8px); }
}

.toast-region {
  position: fixed;
  z-index: 60;
  right: 22px;
  bottom: 22px;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--lime);
  border-radius: 5px;
  color: #e5e9e2;
  background: #20231f;
  box-shadow: 0 12px 34px rgb(0 0 0 / 32%);
  font-size: 12px;
  animation: toast-in 180ms ease-out;
}

.toast.error {
  border-left-color: var(--danger);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@media (max-width: 1120px) {
  .sidebar {
    width: 76px;
    padding-inline: 10px;
  }

  .brand {
    justify-content: center;
    padding-inline: 0;
  }

  .brand-text,
  .nav-item > span:not(.nav-count),
  .quota-block {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 0;
  }

  .nav-count {
    position: absolute;
    margin: -28px 0 0 28px;
    min-width: 16px;
    padding: 0 4px;
  }

  .main-area {
    margin-left: 76px;
  }

  .studio {
    grid-template-columns: minmax(360px, 420px) minmax(360px, 1fr);
  }

  .composer,
  .preview-panel {
    padding-inline: 22px;
  }
}

@media (max-width: 900px) {
  .studio,
  .image-studio {
    display: block;
  }

  .composer {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage {
    min-height: 520px;
  }

  .image-composer {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .image-gallery {
    min-height: 460px;
  }
}

@media (max-width: 640px) {
  body {
    padding-bottom: 68px;
    font-size: 16px;
  }

  .sidebar {
    display: none;
  }

  .main-area {
    margin-left: 0;
  }

  .topbar {
    min-height: 76px;
    padding: 14px 16px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .service-state {
    max-width: 144px;
    padding: 0 8px;
  }

  .service-state span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-settings {
    display: inline-grid !important;
  }

  .composer,
  .preview-panel,
  .image-composer,
  .image-preview-panel,
  .history-section {
    width: 100%;
    max-width: 100vw;
    padding: 22px 16px;
  }

  .section-heading {
    gap: 10px;
  }

  .model-badge {
    max-width: 88px;
  }

  .mode-switch .segment {
    gap: 6px;
    min-width: 0;
    padding-inline: 5px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .composer {
    min-height: 0;
  }

  .creation-tabs {
    gap: 4px;
    padding: 10px 16px 0;
  }

  .creation-tab {
    min-width: 0;
    flex: 1;
    padding-inline: 9px;
  }

  .creation-tab small {
    display: none;
  }

  .image-gallery {
    grid-template-columns: 1fr;
    min-height: 380px;
  }

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

  .aspect-group {
    grid-column: auto;
  }

  .visual-option {
    min-width: 0;
    gap: 6px;
    padding-inline: 3px;
  }

  .visual-option b {
    font-size: 10px;
  }

  .stage {
    min-height: 470px;
  }

  .history-item {
    grid-template-columns: 42px minmax(0, 1fr) 34px;
    gap: 10px;
  }

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

  .dialog-card {
    padding: 18px;
  }

  .history-time,
  .history-item > .job-status {
    display: none;
  }

  .history-thumb {
    width: 42px;
    height: 42px;
  }

  .mobile-nav {
    position: fixed;
    z-index: var(--z-sidebar);
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    min-height: 66px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: rgb(11 12 11 / 96%);
    backdrop-filter: blur(12px);
  }

  .mobile-nav button {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    border: 0;
    color: var(--faint);
    background: transparent;
    font-size: 10px;
  }

  .mobile-nav button.active {
    color: var(--lime);
  }

  .toast-region {
    right: 16px;
    bottom: 82px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
