:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe3ee;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --blue: #2563eb;
  --amber: #b45309;
  --danger: #c2410c;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

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

button {
  border: 0;
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1,
.brand p,
.dialog-head h2,
.dialog-head p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.15;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs {
  display: grid;
  grid-auto-flow: column;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.tab-button,
.icon-button,
.primary-button,
.secondary-button {
  min-height: 40px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.tab-button {
  min-width: 92px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
}

.tab-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.icon-button {
  width: 42px;
  min-width: 42px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary-button {
  padding: 0 16px;
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary-button:hover,
.icon-button:hover,
.tab-button:hover {
  border-color: #aebbd0;
}

.danger {
  color: var(--danger);
}

.workspace {
  display: grid;
  min-height: 0;
}

.view {
  display: none;
  min-height: 0;
}

.view.active {
  display: grid;
}

#chatView {
  grid-template-rows: 1fr auto;
  height: calc(100vh - 73px);
}

.thread {
  overflow: auto;
  padding: 28px clamp(14px, 5vw, 48px) 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  display: grid;
  gap: 6px;
  max-width: min(820px, 100%);
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-meta {
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
}

.bubble {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user .bubble {
  color: #ffffff;
  background: #1f4f7a;
  border-color: #1f4f7a;
}

.assistant.pending .bubble::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 4px;
  display: inline-block;
  border-radius: 50%;
  background: var(--amber);
  vertical-align: middle;
  animation: pulse 1s ease-in-out infinite;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px clamp(14px, 5vw, 48px) 22px;
  border-top: 1px solid var(--line);
  background: rgba(247, 248, 251, 0.94);
}

.composer textarea,
.image-controls textarea,
.field input,
.control-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.composer textarea {
  min-height: 48px;
  max-height: 180px;
  resize: none;
  padding: 12px 14px;
  line-height: 1.6;
}

.composer textarea:focus,
.image-controls textarea:focus,
.field input:focus,
.control-row select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.send-button {
  min-width: 96px;
  align-self: end;
}

.image-layout {
  min-height: calc(100vh - 73px);
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
  padding: 22px clamp(14px, 5vw, 48px);
}

.image-controls,
.image-result {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
}

.image-controls {
  align-self: start;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.image-controls label,
.field label,
.control-row label {
  font-weight: 700;
  font-size: 13px;
}

.image-controls textarea {
  resize: vertical;
  min-height: 180px;
  padding: 12px;
  line-height: 1.65;
}

.control-row {
  display: grid;
  gap: 8px;
}

.control-row select {
  height: 42px;
  padding: 0 10px;
}

.image-result {
  min-height: 420px;
  display: grid;
  place-items: center;
  padding: 16px;
}

.empty-state {
  color: var(--muted);
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
}

.empty-state svg {
  width: 44px;
  height: 44px;
  color: #8796ac;
}

.generated {
  width: min(100%, 860px);
  display: grid;
  gap: 12px;
}

.generated img {
  width: 100%;
  max-height: calc(100vh - 190px);
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.generated-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.settings-dialog {
  width: min(620px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.settings-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
  background: var(--surface);
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-head h2 {
  font-size: 20px;
}

.dialog-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.field input {
  height: 42px;
  padding: 0 12px;
}

.secret-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

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

.advanced {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.advanced summary {
  cursor: pointer;
  font-weight: 700;
}

.advanced .field-grid {
  margin-top: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  max-width: min(520px, calc(100vw - 28px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  z-index: 50;
  line-height: 1.5;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.1;
  flex: 0 0 auto;
}

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

@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .tabs {
    grid-column: 1 / -1;
    width: 100%;
  }

  .tab-button {
    width: 100%;
  }

  #chatView,
  .image-layout {
    min-height: calc(100vh - 126px);
  }

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

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

  .send-button {
    width: 100%;
  }

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