:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --soft: #f1f5f9;
  --soft-blue: #eff6ff;
  --text: #152033;
  --muted: #66758d;
  --line: #d8e1ed;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --indigo: #4f46e5;
  --purple: #8b5cf6;
  --green: #059669;
  --red: #dc2626;
  --slate: #1f2937;
  --shadow: 0 18px 44px rgba(28, 42, 72, 0.08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button,
.button-link {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
}

button:hover,
.button-link:hover {
  background: var(--blue-dark);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

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

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

button.ghost:hover {
  background: var(--soft);
}

button.text-button {
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0 8px;
}

button.text-button:hover {
  background: rgba(37, 99, 235, 0.08);
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 360px;
  resize: vertical;
  padding: 12px;
  line-height: 1.6;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  letter-spacing: 0;
}

.shell {
  width: min(1560px, calc(100vw - 32px));
  margin: 0 auto;
}

.key-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.key-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 18px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.key-help {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.key-help a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.key-help a:hover {
  color: var(--blue-dark);
  text-decoration: underline;
}

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

.brand-lockup img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.brand-lockup span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.app-view {
  padding: 24px 0 32px;
}

.app-header {
  display: grid;
  grid-template-columns: auto minmax(420px, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 16px 18px;
  border: 1px solid #e5ebf4;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 28px rgba(30, 41, 59, 0.04);
}

.account-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.mode-tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2f8;
  overflow-x: auto;
}

.tab-button {
  min-height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: #547092;
  white-space: nowrap;
}

.tab-button:hover {
  background: rgba(255, 255, 255, 0.75);
}

.tab-button.active {
  border-color: #c7d2fe;
  background: #fff;
  color: var(--indigo);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.12);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.top-actions button,
.top-actions .button-link {
  min-height: 40px;
  height: 40px;
  border-radius: 6px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.recharge-link {
  border: 1px solid #d7e2ef;
  background: #fff;
  color: var(--text);
}

.recharge-link:hover {
  background: var(--soft);
}

.balance-pill {
  min-width: 170px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid #d7e2ef;
  border-radius: 6px;
  background: #fff;
  white-space: nowrap;
}

.balance-pill span {
  color: #5a6c86;
  font-size: 12px;
  line-height: 1;
}

.balance-pill strong {
  min-width: 0;
  overflow: hidden;
  color: #174ea6;
  font-size: 15px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-pill.error strong {
  color: var(--red);
}

.create-view {
  display: grid;
  grid-template-columns: minmax(260px, 0.95fr) minmax(330px, 1.15fr) minmax(330px, 1.15fr);
  gap: 16px;
  align-items: stretch;
}

.create-view.has-upload {
  grid-template-columns: minmax(240px, 0.9fr) minmax(260px, 0.9fr) minmax(320px, 1fr) minmax(320px, 1fr);
}

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

.settings-panel,
.prompt-panel,
.result-panel,
.upload-panel {
  min-height: 600px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header span {
  color: var(--muted);
  font-size: 12px;
}

.panel-header.blue {
  background: #eef6ff;
  color: #174ea6;
}

.panel-header.indigo {
  color: #3730a3;
}

.panel-header.purple {
  color: #6d28d9;
}

.panel-header.green {
  color: var(--green);
}

.panel-header.slate {
  color: #334155;
}

.field-group {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.field-title {
  color: #53627a;
  font-size: 13px;
  font-weight: 600;
}

.size-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.size-grid button {
  display: grid;
  gap: 2px;
  min-height: 52px;
  border: 1px solid transparent;
  background: #eef2f7;
  color: #4473b8;
}

.size-grid button span {
  color: #6d8fbd;
  font-size: 11px;
}

.size-grid button.active,
.quality-grid button.active {
  background: var(--slate);
  color: #fff;
}

.size-grid button.active span {
  color: rgba(255, 255, 255, 0.78);
}

.size-grid .wide {
  grid-column: 1 / -1;
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #eef2f7;
}

.quality-grid button {
  min-height: 34px;
  background: transparent;
  color: #4d76b0;
  font-weight: 600;
}

.custom-size-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.custom-size-fields .wide {
  grid-column: 1 / -1;
}

.custom-size-fields span {
  grid-column: 1 / -1;
  min-height: 30px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  padding: 0 10px;
  background: #f8fafc;
  color: #53627a;
  font-size: 12px;
}

.custom-size-fields span.active {
  background: #eef6ff;
  color: #174ea6;
  font-weight: 600;
}

.custom-size-fields span.error {
  background: #fff1f2;
  color: var(--red);
}

.compact-fields {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 10px;
  padding: 0 16px 16px;
}

.prompt-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.prompt-panel textarea {
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: #f8fafc;
}

.submit-bar {
  display: grid;
  grid-template-columns: minmax(140px, 1fr);
  gap: 9px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.message {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.message.error {
  color: var(--red);
}

.message.ok {
  color: var(--green);
}

.upload-panel {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.upload-drop {
  margin: 16px;
  min-height: 76px;
  display: grid;
  align-content: center;
  gap: 6px;
  border: 1px dashed #93b8e6;
  border-radius: 8px;
  background: #eff6ff;
  color: #2563eb;
  cursor: pointer;
}

.upload-drop.dragging {
  border-color: #2563eb;
  background: #dbeafe;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.upload-drop input {
  display: none;
}

.upload-drop strong,
.upload-drop span {
  padding-left: 12px;
}

.upload-drop span {
  color: #5b7faa;
  font-size: 12px;
}

.upload-preview {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 0 16px 16px;
  overflow: auto;
}

.upload-thumb {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.upload-thumb img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}

.upload-thumb strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-thumb span {
  color: var(--muted);
  font-size: 12px;
}

.file-line {
  display: grid;
  gap: 5px;
  margin: 0 16px 16px;
  padding: 11px 12px;
  border: 1px dashed #b7c7dc;
  border-radius: 8px;
  background: #f8fbff;
  color: #48627f;
  cursor: pointer;
}

.file-line:hover {
  border-color: #7da7dc;
  background: #eff6ff;
}

.file-line strong {
  overflow: hidden;
  color: #1f3f73;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-line small {
  color: var(--muted);
  font-size: 11px;
}

.file-line input {
  display: none;
}

.result-preview {
  height: calc(100% - 52px);
  padding: 16px;
  overflow: auto;
}

.result-card {
  display: grid;
  gap: 10px;
}

.result-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.result-image-item {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.result-image-item img {
  width: 100%;
  max-height: 470px;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.result-image-item button {
  min-height: 34px;
  font-size: 12px;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.queue-dock {
  grid-column: 1 / -1;
  overflow: hidden;
}

.page-panel {
  overflow: hidden;
}

.jobs-list {
  display: grid;
}

.jobs-list.compact {
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 10px;
  padding: 12px;
}

.job-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.jobs-list.compact .job-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.job-main {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.job-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.job-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 13px;
  color: var(--muted);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.status.queued {
  color: #31415f;
  background: #e9eef7;
}

.status.running {
  color: #064a78;
  background: #e0f2fe;
}

.status.succeeded {
  color: var(--green);
  background: #e6f7ef;
}

.status.failed {
  color: var(--red);
  background: #fee2e2;
}

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

.history-card .job-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.history-card .job-actions button {
  min-height: 30px;
  padding: 0 2px;
  font-size: 11px;
  white-space: nowrap;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.image-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.error-text {
  color: var(--red);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.empty-state,
.empty {
  display: grid;
  min-height: 160px;
  place-items: center;
  color: #96a3b7;
  text-align: center;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 18px;
}

.manager-view {
  display: grid;
  gap: 12px;
}

.manager-banner,
.manager-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(30, 41, 59, 0.04);
}

.manager-banner {
  padding: 14px 16px;
  color: #174ea6;
}

.manager-banner div {
  display: grid;
  gap: 5px;
}

.manager-banner p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

.manager-toolbar {
  padding: 12px;
}

.search-field {
  width: min(360px, 100%);
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #eef2f7;
}

.segmented button {
  min-height: 32px;
  background: transparent;
  color: #5b6f8c;
}

.segmented button.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

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

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  padding: 14px;
  border-radius: 8px;
  background: #fff;
}

.history-card {
  position: relative;
  display: grid;
  gap: 8px;
  min-width: 0;
}

.history-select {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(216, 225, 237, 0.95);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
  cursor: pointer;
}

.history-select input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.history-select span {
  width: 16px;
  height: 16px;
  border: 1px solid #aab8cc;
  border-radius: 4px;
  background: #fff;
}

.history-select input:checked + span {
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: inset 0 0 0 3px #fff;
}

.history-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.history-card strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-card span {
  color: var(--muted);
  font-size: 11px;
}

.api-view {
  display: grid;
  gap: 14px;
}

.api-doc-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(30, 41, 59, 0.04);
}

.api-doc-hero div {
  display: grid;
  gap: 6px;
}

.api-doc-hero h2,
.api-doc-section h2 {
  color: #174ea6;
}

.api-doc-hero p,
.api-doc-section p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.api-doc-hero code {
  max-width: 100%;
  overflow: hidden;
  border: 1px solid #d7e2ef;
  border-radius: 6px;
  padding: 9px 11px;
  background: #f8fbff;
  color: #174ea6;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.api-doc-section {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(30, 41, 59, 0.04);
}

.api-doc-section.wide {
  grid-column: 1 / -1;
}

.api-kv {
  display: grid;
  gap: 8px;
  margin: 0;
}

.api-kv div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 34px;
  border: 1px solid #e6edf6;
  border-radius: 6px;
  padding: 8px 10px;
  background: #f8fafc;
}

.api-kv.compact div {
  grid-template-columns: 92px minmax(0, 1fr);
}

.api-kv dt {
  color: #53627a;
  font-size: 12px;
  font-weight: 700;
}

.api-kv dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

.api-kv code,
.endpoint-list code,
.api-note code,
.api-response code {
  overflow-wrap: anywhere;
}

.endpoint-list {
  display: grid;
  gap: 8px;
}

.endpoint-list div {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 5px 10px;
  align-items: center;
  border: 1px solid #e6edf6;
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
}

.endpoint-list span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 4px;
  background: #eef6ff;
  color: #174ea6;
  font-size: 11px;
  font-weight: 800;
}

.endpoint-list p {
  grid-column: 2;
  font-size: 12px;
}

.api-doc-section pre {
  margin: 0;
  overflow-x: auto;
  border: 1px solid #dbe6f3;
  border-radius: 8px;
  padding: 14px;
  background: #0f172a;
  color: #dbeafe;
  font-size: 12px;
  line-height: 1.6;
}

.api-doc-section pre code {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}

.api-note,
.api-response {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  border: 1px solid #d8e7ff;
  border-radius: 6px;
  padding: 10px 12px;
  background: #f8fbff;
  color: #33527c;
  font-size: 13px;
  line-height: 1.5;
}

.api-response strong {
  color: #174ea6;
}

.api-response code {
  border-radius: 4px;
  background: #eef6ff;
  color: #174ea6;
  padding: 2px 6px;
}

dialog {
  width: min(430px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.38);
}

.wide-dialog {
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

.dialog-body {
  display: grid;
  gap: 16px;
  padding: 20px;
  background: #fff;
}

.dialog-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.notice {
  padding: 10px 12px;
  border: 1px solid #d8e7ff;
  border-radius: 6px;
  background: #f1f7ff;
  color: #33527c;
  font-size: 13px;
  line-height: 1.5;
}

.notice-message {
  padding: 12px;
  border: 1px solid #d8e7ff;
  border-radius: 6px;
  background: #f8fbff;
  color: #1f3f73;
  font-size: 14px;
  line-height: 1.6;
}

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

.template-shell {
  height: min(820px, calc(100vh - 32px));
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.template-layout {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}

.template-categories {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  padding-right: 10px;
  border-right: 1px solid var(--line);
  overflow: auto;
}

.template-categories button {
  justify-content: flex-start;
  background: transparent;
  color: #52647e;
  min-height: 34px;
  padding: 7px 9px;
  text-align: left;
  line-height: 1.25;
}

.template-categories button.active {
  background: #eef2ff;
  color: var(--indigo);
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  align-content: start;
  min-height: 0;
  overflow: auto;
  padding-right: 6px;
}

.template-card {
  display: grid;
  gap: 0;
  min-height: 238px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
  overflow: hidden;
}

.template-card:hover {
  border-color: #b8c7ff;
  background: #fbfdff;
}

.template-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-top: 4px;
  border: 0;
  border-radius: 6px;
  background: #eef2f7;
  overflow: hidden;
}

.template-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.template-content {
  display: grid;
  align-content: start;
  gap: 8px;
  width: 100%;
  height: 100%;
  padding: 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.template-content:hover {
  background: var(--blue-dark);
  color: #f8fbff;
}

.template-card p {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.template-content:hover p {
  color: #dbeafe;
}

.template-image-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  overflow: hidden;
}

.template-image-preview[hidden] {
  display: none;
}

.template-image-preview button {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.template-image-preview img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  background: #edf2f7;
}

.template-image-preview span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  border-radius: 6px;
  padding: 5px 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 12px;
}

.template-prompt-editor {
  display: grid;
  gap: 6px;
  color: #52647e;
  font-size: 13px;
}

.template-prompt-editor[hidden] {
  display: none;
}

.template-prompt-editor textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid #d5dfef;
  border-radius: 7px;
  padding: 10px;
  color: var(--text);
  font: inherit;
  line-height: 1.55;
}

.template-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.template-tags span {
  border-radius: 4px;
  background: #eef2ff;
  color: var(--indigo);
  padding: 2px 6px;
  font-size: 11px;
}

.template-content:hover .template-tags span {
  background: rgba(255, 255, 255, 0.18);
  color: #eff6ff;
}

.template-vars {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.template-preview-box {
  max-height: 180px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #475569;
  font-size: 13px;
  line-height: 1.6;
}

.image-dialog {
  width: 96vw;
  max-width: none;
  height: 96vh;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.image-dialog-body {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.92);
}

.image-dialog-body img {
  max-width: 94%;
  max-height: 92%;
  object-fit: contain;
}

.image-dialog-loading {
  display: grid;
  justify-items: center;
  gap: 14px;
  color: #e2e8f0;
  font-size: 14px;
}

.image-dialog-loading[hidden] {
  display: none;
}

.image-dialog-loading.error {
  color: #fecaca;
}

.image-dialog-loading.error .image-spinner {
  display: none;
}

.image-spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(226, 232, 240, 0.22);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: image-spin 0.8s linear infinite;
}

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

.image-dialog-body button {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 2;
  background: rgba(255, 255, 255, 0.16);
}

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

  .mode-tabs {
    justify-content: flex-start;
    width: 100%;
  }

  .account-actions {
    justify-content: flex-start;
    width: fit-content;
    max-width: 100%;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .balance-pill {
    flex: 0 0 auto;
  }

  .create-view,
  .create-view.has-upload {
    grid-template-columns: 1fr 1fr;
  }

  .api-doc-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 20px, 680px);
  }

  .create-view,
  .create-view.has-upload {
    grid-template-columns: 1fr;
  }

  .mode-tabs {
    flex-wrap: wrap;
    overflow: visible;
  }

  .tab-button {
    flex: 1 1 calc(33.333% - 6px);
    padding: 0 8px;
    text-align: center;
  }

  .top-actions button,
  .top-actions .button-link {
    flex: 1;
  }

  .account-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .balance-pill {
    width: 100%;
    justify-content: space-between;
  }

  .settings-panel,
  .prompt-panel,
  .result-panel,
  .upload-panel {
    min-height: auto;
  }

  .custom-size-fields {
    grid-template-columns: 1fr;
  }

  .manager-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .api-doc-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .api-kv div,
  .api-kv.compact div,
  .endpoint-list div {
    grid-template-columns: 1fr;
  }

  .endpoint-list p {
    grid-column: auto;
  }

  .template-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .template-categories {
    display: flex;
    min-height: auto;
    max-height: 52px;
    padding-right: 0;
    padding-bottom: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
  }
}


/* ======================================================== */
/* MODERN UI OVERRIDES (Added to beautify the UI)           */
/* ======================================================== */

:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --soft: #f1f5f9;
  --soft-blue: #eff6ff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --indigo: #6366f1;
  --purple: #8b5cf6;
  --green: #10b981;
  --red: #ef4444;
  --slate: #1e293b;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  transition: all 0.2s ease-in-out;
}

.panel, .key-panel, .app-header, dialog, .manager-banner, .manager-toolbar, .history-grid, .api-doc-hero, .api-doc-section, .upload-thumb {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 12px;
}

.app-header {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  padding: 16px 24px;
}

.mode-tabs {
  background: var(--soft);
  border-radius: 12px;
  padding: 6px;
  border: none;
}

.tab-button {
  border-radius: 8px;
  font-weight: 500;
  color: var(--muted);
}
.tab-button:hover {
  background: rgba(255,255,255,0.6);
}
.tab-button.active {
  background: #ffffff;
  color: var(--blue-dark);
  box-shadow: var(--shadow-sm);
  border-color: transparent;
}

button, .button-link {
  border-radius: 8px;
  font-weight: 500;
}
button:hover:not(:disabled), .button-link:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

button.ghost { border-color: var(--line); box-shadow: none; }

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
  outline: none;
}

.size-grid button, .quality-grid button {
  border-radius: 8px;
}
.size-grid button:hover:not(.active), .quality-grid button:hover:not(.active) {
  border-color: var(--blue);
  background: var(--soft-blue);
}

.upload-drop {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  transition: all 0.25s;
}
.upload-drop:hover {
  border-color: var(--blue);
  background: var(--soft-blue);
}

.result-image-item img, .history-card img, .template-card {
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s;
}
.result-image-item img:hover {
  transform: scale(1.02);
}

.history-card:hover img {
  border-color: var(--blue);
}

.panel-header {
  background: #fafafa;
  border-bottom: 1px solid var(--line);
}
.panel-header.blue { border-top: 3px solid var(--blue); background: #fff;}
.panel-header.indigo { border-top: 3px solid var(--indigo); background: #fff;}
.panel-header.purple { border-top: 3px solid var(--purple); background: #fff;}
.panel-header.green { border-top: 3px solid var(--green); background: #fff;}
.panel-header.slate { border-top: 3px solid var(--slate); background: #fff;}

.status {
  border-radius: 6px;
  font-weight: 600;
}

/* Improve grid layout slightly for wide screens */
@media (min-width: 1400px) {
  .create-view {
    grid-template-columns: minmax(320px, 1fr) minmax(400px, 1.2fr) minmax(400px, 1.2fr);
  }
}

/* Extra spacing tweaks */
.shell { padding: 32px 0; }
.panel { gap: 8px; }
.prompt-panel textarea { padding: 16px; font-size: 14px; }
.field-group { padding: 24px; gap: 16px; }
.size-grid button { gap: 8px; font-size: 14px; }
