:root {
  --bg: #f5f7fb;
  --ink: #162033;
  --muted: #6b7484;
  --line: #dce3ee;
  --panel: #ffffff;
  --soft: #eef3f9;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --warning: #b45309;
  --shadow: 0 18px 48px rgba(26, 36, 58, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-self: start;
  width: 100%;
  height: 100vh;
  padding: 22px 16px;
  background: #111827;
  color: #e5eaf3;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #14b8a6;
  color: #031a18;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: #9ca8ba;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 12px;
  background: transparent;
  color: #aeb8ca;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav .parent {
  margin-top: 8px;
}

.nav .sub {
  padding-left: 28px;
  font-size: 14px;
}

.nav .sub.active {
  background: #0f766e;
}

.sidebar-note {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-note span {
  color: #99f6e4;
  font-size: 12px;
  font-weight: 800;
}

.sidebar-note p {
  margin: 8px 0 0;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.6;
}

.main {
  min-width: 0;
  grid-column: 2;
  padding: 26px;
  overflow-x: hidden;
}

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

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

h1 {
  margin-bottom: 8px;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 6px;
  font-size: 20px;
}

h3 {
  margin-bottom: 4px;
  font-size: 16px;
}

.topbar p,
.panel-header p,
.section-title p,
.api-box p,
.estimate p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.65;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  max-width: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(26, 36, 58, 0.06);
  color: var(--muted);
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(420px, 0.92fr);
  gap: 18px;
  align-items: start;
}

.composer,
.result-panel,
.library {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.composer,
.library {
  min-width: 0;
  padding: 20px;
}

.result-panel {
  min-width: 0;
  overflow: hidden;
  position: sticky;
  top: 24px;
}

.panel-header,
.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-header {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.mode-tabs {
  display: inline-flex;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: var(--soft);
}

.mode-tabs button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.mode-tabs button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(26, 36, 58, 0.12);
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  min-width: 0;
}

.field span,
.control-grid span,
.provider-grid span,
.model-grid span,
.readonly-field span {
  color: #3b4657;
  font-size: 13px;
  font-weight: 800;
}

textarea,
input,
select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.65;
  max-width: 100%;
}

input,
select {
  min-height: 40px;
  padding: 0 10px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(15, 118, 110, 0.72);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.14);
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(180px, 0.9fr);
  gap: 12px;
  margin-bottom: 14px;
}

.upload-card,
.preview-card {
  min-height: 118px;
  border: 1px dashed #c7d2e2;
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.upload-card {
  display: grid;
  align-content: center;
  gap: 6px;
}

.upload-card input {
  display: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #dff7f3;
  color: var(--accent);
  font-weight: 900;
}

.upload-card small {
  color: var(--muted);
  line-height: 1.5;
}

.preview-card {
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  text-align: center;
}

.preview-card img {
  width: 100%;
  height: auto;
  max-height: 156px;
  object-fit: contain;
  border-radius: 6px;
}

.control-grid,
.provider-grid,
.model-grid {
  display: grid;
  gap: 12px;
}

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

.provider-grid {
  grid-template-columns: minmax(260px, 1fr) minmax(240px, 0.8fr);
}

.model-grid {
  grid-template-columns: minmax(220px, 1.4fr) repeat(3, minmax(118px, 0.7fr)) minmax(150px, 0.8fr);
  align-items: end;
}

.model-field-wide {
  min-width: 0;
}

.api-grid {
  grid-template-columns: 150px minmax(220px, 1fr) minmax(220px, 1fr);
}

.control-grid label,
.provider-grid label,
.model-grid label {
  display: grid;
  gap: 8px;
}

.settings-section {
  display: grid;
  gap: 12px;
  border: 1px solid #e1e7f0;
  border-radius: 8px;
  padding: 16px;
  background: #fbfdff;
}

.settings-section + .settings-section {
  margin-top: 12px;
}

.access-section,
.model-section {
  background: #ffffff;
}

.workspace-section {
  margin-top: 16px;
  background: #f9fbff;
}

.settings-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.settings-title > span {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: auto;
  min-width: 38px;
  height: 26px;
  border-radius: 8px;
  padding: 0 9px;
  background: #e7f8f5;
  color: #0f766e;
  font-size: 12px;
  font-weight: 900;
}

.settings-title strong {
  display: block;
  margin-bottom: 4px;
}

.settings-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.api-box {
  border: 1px solid #b7d8d4;
  border-radius: 8px;
  padding: 12px;
  background: #f3fffc;
}

.api-box[hidden] {
  display: none;
}

#authModeField[hidden] {
  display: none;
}

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

.readonly-field strong {
  display: flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid #cfe6e3;
  border-radius: 8px;
  padding: 0 10px;
  background: #ecfdf9;
  color: #0f766e;
  font-size: 13px;
  line-height: 1.3;
}

.model-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px dashed #d2dde8;
  padding-top: 10px;
}

.model-price-row span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.actions.compact {
  margin-top: 12px;
}

.actions.compact button {
  min-height: 34px;
}

.actions button,
.section-title button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.actions .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.advanced-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.tool-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.tool-card.active {
  border-color: rgba(15, 118, 110, 0.55);
  background: #ecfdf9;
}

.tool-card strong,
.tool-card span {
  display: block;
}

.tool-card span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.stylist-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
  padding: 12px;
  background: #ffffff;
}

.stylist-box summary {
  color: #3b4657;
  font-size: 13px;
  font-weight: 900;
}

.stylist-box p {
  margin: 10px 0 12px;
  color: var(--muted);
  line-height: 1.6;
}

.stylist-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stylist-grid label {
  display: grid;
  gap: 7px;
}

.stylist-grid span {
  color: #3b4657;
  font-size: 12px;
  font-weight: 800;
}

.result-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  max-height: min(78vh, 980px);
  width: 100%;
  border: 0;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(232, 237, 245, 0.94)),
    repeating-linear-gradient(
      45deg,
      rgba(148, 163, 184, 0.08) 0,
      rgba(148, 163, 184, 0.08) 14px,
      rgba(255, 255, 255, 0.2) 14px,
      rgba(255, 255, 255, 0.2) 28px
    );
  text-align: center;
}

.result-stage img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 720px);
  max-height: min(70vh, 860px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(26, 36, 58, 0.14);
}

.result-stage:hover img {
  box-shadow: 0 14px 34px rgba(26, 36, 58, 0.2);
}

.result-stage:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: -3px;
}

.result-stage.loading::after {
  content: "生成中...";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.48);
  color: #ffffff;
  font-weight: 900;
}

.result-badge {
  position: absolute;
  left: 14px;
  top: 14px;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(17, 24, 39, 0.78);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.result-hint {
  position: absolute;
  right: 14px;
  bottom: 14px;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.86);
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.estimate {
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.estimate > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.estimate span {
  color: var(--muted);
  font-size: 13px;
}

.estimate strong {
  font-size: 18px;
}

.history {
  padding: 16px;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  min-height: 320px;
  overflow: auto;
  padding-right: 4px;
}

.history-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfdff;
}

.history-item img {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
}

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

.history-item span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.history-item span:last-child {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.lightbox[hidden] {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.78);
}

.lightbox-dialog {
  position: relative;
  z-index: 1;
  width: min(92vw, 1280px);
  max-height: 90vh;
  padding: 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.lightbox-dialog img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(90vh - 36px);
  margin: 0 auto;
  border-radius: 12px;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  min-height: 36px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.92);
  color: #1e293b;
  font-weight: 800;
}

.library {
  margin-top: 18px;
}

.library-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px 170px;
  gap: 10px;
  width: min(620px, 100%);
}

.library-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.library-summary span:first-child {
  color: var(--accent);
  font-weight: 900;
}

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

.prompt-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.prompt-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

.prompt-card-body {
  padding: 12px;
}

.prompt-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.prompt-card-meta span {
  border-radius: 999px;
  padding: 4px 7px;
  background: #eef3f9;
  color: #586579;
  font-size: 11px;
  font-weight: 800;
}

.prompt-card h3 {
  margin-bottom: 8px;
}

.prompt-card p {
  min-height: 66px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.prompt-card button {
  width: 100%;
  min-height: 36px;
  border: 1px solid #b7d8d4;
  border-radius: 7px;
  background: #ecfdf9;
  color: #0f766e;
  font-weight: 800;
}

.library-more {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.library-more button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 18px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  transform: translateY(24px);
  opacity: 0;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  background: #111827;
  color: #ffffff;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .sidebar {
    width: 100%;
  }

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

  .result-panel {
    position: static;
  }

  .result-stage {
    min-height: 360px;
  }

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: auto;
    height: auto;
  }

  .main {
    padding: 16px;
  }

  .topbar,
  .panel-header,
  .section-title {
    display: grid;
  }

  .mode-tabs,
  .status-strip,
  .library-tools {
    width: 100%;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .control-grid,
  .provider-grid,
  .model-grid,
  .upload-grid,
  .prompt-grid,
  .library-tools,
  .advanced-tools,
  .stylist-grid {
    grid-template-columns: 1fr;
  }

  .model-price-row {
    display: grid;
  }

  .result-stage {
    min-height: 260px;
    padding: 16px;
  }

  .result-stage img {
    max-width: 100%;
    max-height: 56vh;
  }

  .history-list {
    min-height: 0;
    max-height: 340px;
  }

  .lightbox-dialog {
    width: min(96vw, 1280px);
    padding: 14px;
  }
}
