:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --line: #dfe6e1;
  --text: #17201c;
  --muted: #68736e;
  --soft: #eef3ef;
  --green: #24775c;
  --green-dark: #176246;
  --red: #a93527;
  --shadow: 0 14px 42px rgba(23, 32, 28, 0.06);
  --shadow-soft: 0 8px 26px rgba(23, 32, 28, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.side-nav {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

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

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

.brand span,
.token-card span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.nav-item span {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 7px;
  background: var(--soft);
  color: var(--green);
  font-size: 13px;
}

.nav-item.active {
  border-color: #cfe2d7;
  background: #e7f4ed;
  color: var(--green-dark);
}

.token-card {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf9;
}

.token-card strong {
  margin-top: 6px;
  font-size: 16px;
}

.plain-link {
  margin-top: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 900;
}

.workspace {
  min-width: 0;
  max-width: 1480px;
  width: 100%;
  padding: 24px 28px 36px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.eyebrow {
  display: block;
  margin-bottom: 7px;
  color: #7a837f;
  font-size: 13px;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 19px;
}

.view-head p {
  max-width: 620px;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.55;
}

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

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.chat-workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
}

.image-workspace {
  display: grid;
  gap: 16px;
}

.chat-panel,
.chat-session-panel,
.image-panel,
.image-delivery-panel,
.side-panel,
.account-grid .panel,
#view-account > .panel {
  padding: 20px;
}

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

.panel-head.tight {
  margin-bottom: 8px;
}

.compact-select,
.search-input,
.input,
.textarea,
.chat-input,
.option-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf9;
  color: var(--text);
  outline: none;
}

.compact-select {
  min-width: 220px;
  height: 40px;
  padding: 0 12px;
  font-weight: 800;
}

.search-input {
  width: 320px;
  height: 42px;
  padding: 0 14px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: min(54vh, 560px);
  min-height: 300px;
  overflow: auto;
  padding: 4px 2px 14px;
}

.session-list {
  display: grid;
  gap: 8px;
  max-height: min(56vh, 560px);
  overflow: auto;
  margin: 12px 0;
}

.session-item {
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf9;
  color: var(--text);
  text-align: left;
}

.session-item.active {
  border-color: var(--green);
  background: #e7f4ed;
}

.session-title,
.session-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-title {
  font-weight: 900;
}

.session-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.full-btn {
  width: 100%;
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(760px, 78%);
  padding: 12px 14px;
  border-radius: 8px;
  background: #f3f5f2;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: #d9e9df;
}

.chat-input,
.textarea {
  width: 100%;
  min-height: 104px;
  margin-top: 12px;
  padding: 14px;
  resize: vertical;
  line-height: 1.55;
}

.chat-input {
  min-height: 86px;
  max-height: 260px;
}

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-btn,
.small-btn,
.ghost-btn,
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border-radius: 8px;
  font-weight: 900;
}

.icon-btn {
  width: 40px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--green);
}

.small-btn {
  min-width: 72px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.ghost-btn {
  padding: 0 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.primary-btn {
  min-width: 104px;
  padding: 0 18px;
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
}

.primary-btn:disabled {
  border-color: #9aa8a1;
  background: #9aa8a1;
}

.attachment-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.attachment-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf9;
  color: var(--muted);
  font-size: 13px;
}

.notice {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #f2d5a8;
  border-radius: 8px;
  background: #fff8eb;
  color: #7b5016;
  line-height: 1.5;
}

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

.mode-tab {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 900;
}

.mode-tab.active {
  border-color: var(--green);
  background: #e7f4ed;
  color: var(--green-dark);
}

.mode-desc {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

.upload-zone {
  display: grid;
  min-height: 150px;
  margin-top: 0;
  place-items: center;
  border: 1px dashed #aebbb4;
  border-radius: 8px;
  background: #fafbf9;
  text-align: center;
}

.upload-zone span {
  color: var(--green);
  font-size: 42px;
  line-height: 1;
}

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

.upload-zone em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.preview-card {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--soft);
}

.preview-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-card button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: rgba(23, 32, 28, 0.72);
  color: #fff;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.option-grid select {
  height: 42px;
  padding: 0 12px;
}

.image-history,
.usage-list,
.quota-rows {
  display: grid;
  gap: 10px;
}

.image-history {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
}

.history-card,
.usage-item,
.quota-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf9;
}

.history-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  max-height: none;
  object-fit: cover;
  margin: 10px 0;
  border-radius: 8px;
  background: var(--soft);
}

.image-preview-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
}

.history-title,
.usage-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.status {
  flex: none;
  padding: 5px 9px;
  border-radius: 999px;
  background: #dff0e7;
  color: var(--green-dark);
  font-size: 12px;
}

.status.error {
  background: #fde3de;
  color: var(--red);
}

.history-desc,
.usage-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.history-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  gap: 6px;
  margin-top: 10px;
}

.history-actions .compact-action {
  flex: 1 1 0;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  font-size: 13px;
  white-space: nowrap;
}

.category-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.category-chip {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-weight: 900;
}

.category-chip.active {
  border-color: var(--green);
  background: #e7f4ed;
  color: var(--green-dark);
}

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

.flow-card {
  min-height: 220px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.flow-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #dff0e7;
  color: var(--green-dark);
  font-weight: 900;
}

.flow-card h3 {
  margin: 14px 0 8px;
  font-size: 18px;
}

.flow-card p {
  min-height: 56px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.flow-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

.flow-footer span {
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

.account-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.field {
  display: grid;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.input {
  height: 44px;
  padding: 0 12px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.pill.green {
  background: #dff0e7;
  color: var(--green-dark);
}

.quota-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.quota-grid div {
  padding: 14px 10px;
  border-radius: 8px;
  background: var(--soft);
  text-align: center;
}

.quota-grid span,
.quota-grid strong {
  display: block;
}

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

.quota-grid strong {
  margin-top: 8px;
  font-size: 20px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 20;
  transform: translateX(-50%);
  padding: 11px 16px;
  border-radius: 999px;
  background: rgba(23, 32, 28, 0.92);
  color: #fff;
  font-size: 14px;
}

.site-footer {
  margin-top: 16px;
  padding: 8px 12px 0;
  color: #8a938e;
  font-size: 12px;
  text-align: center;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 28px;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 13, 11, 0.72);
}

.image-modal-body {
  position: relative;
  z-index: 1;
  display: grid;
  max-width: min(92vw, 1100px);
  max-height: 90vh;
  gap: 12px;
}

.image-modal-body img {
  display: block;
  max-width: 100%;
  max-height: 84vh;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
}

.image-modal-close {
  justify-self: end;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 900;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: sticky;
    z-index: 10;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand,
  .token-card {
    display: none;
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 0;
  }

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

  .workspace {
    padding: 18px;
  }

  .split-layout,
  .chat-workspace,
  .image-panel,
  .account-grid,
  .flow-grid,
  .image-history {
    grid-template-columns: 1fr;
  }

  .view-head {
    display: grid;
  }

  .search-input,
  .compact-select {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 14px;
  }

  .nav-item {
    gap: 6px;
    padding: 0 6px;
    font-size: 13px;
  }

  .nav-item span {
    display: none;
  }

  h1 {
    font-size: 26px;
  }

  .mode-tabs,
  .option-grid,
  .quota-grid {
    grid-template-columns: 1fr;
  }

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

  .composer-row {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-btn,
  .ghost-btn {
    width: 100%;
  }
}
