:root {
  color-scheme: light;
  --bg: #eef3f7;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --line: #d9e2ec;
  --line-strong: #c7d4e1;
  --ink: #13202f;
  --muted: #657486;
  --primary: #1769d6;
  --primary-dark: #0f54af;
  --accent: #17a398;
  --soft: #f6f9fc;
  --shadow: 0 14px 34px rgba(26, 42, 62, 0.1);
  --shadow-soft: 0 7px 20px rgba(26, 42, 62, 0.07);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(23, 105, 214, 0.17), transparent 28%),
    radial-gradient(circle at 90% 0%, rgba(23, 163, 152, 0.14), transparent 26%),
    linear-gradient(180deg, #f7fafc 0%, var(--bg) 42%, #e7edf3 100%);
  font-family: "HarmonyOS Sans SC", "MiSans", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(19, 32, 47, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19, 32, 47, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 70%);
}

.app-shell {
  position: relative;
  width: min(1040px, calc(100% - 24px));
  margin: 0 auto;
  padding: 28px 0 20px;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 0;
  margin-bottom: 10px;
  color: #38506a;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.topbar p {
  margin: 0;
  max-width: 780px;
  color: #53667a;
  font-size: 12px;
  font-weight: 600;
}

.topbar-actions .btn {
  color: #31516f;
  background: rgba(255, 255, 255, 0.76);
  border-color: rgba(195, 209, 223, 0.95);
  backdrop-filter: blur(10px);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: start;
}

.tool-panel,
.status-panel,
.history-panel {
  background: var(--panel);
  border: 1px solid rgba(199, 212, 225, 0.78);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.tool-panel {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.side-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.status-panel,
.history-panel {
  padding: 12px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-weight: 800;
  letter-spacing: -0.2px;
}

.section-title span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.section-title span:first-child::before {
  content: "";
  width: 8px;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}

.section-title small,
.muted {
  color: var(--muted);
  font-weight: 400;
}

.form-label {
  margin-bottom: 5px;
  color: #2c3a4a;
  font-size: 13px;
  font-weight: 700;
}

.form-control,
.form-select {
  min-height: 38px;
  color: var(--ink);
  background-color: rgba(255, 255, 255, 0.9);
  border-color: var(--line);
  border-radius: 11px;
  font-size: 14px;
  box-shadow: none !important;
}

.form-control:focus,
.form-select:focus {
  border-color: rgba(23, 105, 214, 0.65);
  box-shadow: 0 0 0 3px rgba(23, 105, 214, 0.12) !important;
}

.prompt-composer {
  overflow: hidden;
  min-height: 182px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid rgba(226, 233, 240, 0.86);
  border-radius: 22px;
  box-shadow: 0 14px 36px rgba(26, 42, 62, 0.085);
}

.prompt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 18px 0;
}

.prompt-header .form-label {
  margin-bottom: 0;
  color: #aebaca;
  font-size: 16px;
  font-weight: 800;
}

#optimizePrompt {
  white-space: nowrap;
  border-radius: 999px;
  font-weight: 700;
}

.prompt-box {
  flex: 1;
  min-height: 42px;
  padding: 2px 18px 3px;
  resize: vertical;
  color: #26384e;
  line-height: 1.38;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 15px;
}

.prompt-box::placeholder {
  color: #c2cedb;
  font-weight: 700;
}

.prompt-box:focus {
  box-shadow: none !important;
}

.settings-summary-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  margin: 0;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(199, 212, 225, 0.9);
  border-radius: 14px;
  box-shadow: 0 9px 24px rgba(24, 40, 58, 0.065);
}

.settings-summary-text {
  color: #41536a;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
}

.settings-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 26, 39, 0.48);
  backdrop-filter: blur(10px);
}

.settings-modal-panel {
  position: relative;
  width: min(920px, 100%);
  max-height: min(86vh, 780px);
  overflow: auto;
  padding: 16px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(217, 226, 236, 0.9);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(10, 24, 42, 0.26);
}

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

.settings-modal-head h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 800;
}

.settings-modal-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.settings-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #405064;
  background: #f2f6fa;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
}

.settings-modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

body.modal-open {
  overflow: hidden;
}

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

.custom-size {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  background: rgba(246, 249, 252, 0.86);
  border: 1px solid var(--line);
  border-radius: 13px;
}

.hide {
  display: none !important;
}

.hint,
.mask-help {
  padding: 9px 10px;
  color: #506174;
  background: rgba(246, 249, 252, 0.9);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.58;
}

.primary-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
}

.action-tip {
  grid-column: 1 / -1;
  min-height: 0;
  font-size: 12px;
}

.action-tip:empty {
  display: none;
}

.action-btn {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
}

.action-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #12847e);
  border: 0;
  box-shadow: 0 10px 18px rgba(23, 105, 214, 0.2);
}

.action-primary:hover {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-dark), #0f706b);
  transform: translateY(-1px);
}

.action-secondary,
.action-ghost,
.btn-soft {
  color: #21415f;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.action-secondary:hover,
.action-ghost:hover,
.btn-soft:hover {
  color: #102b46;
  border-color: rgba(23, 105, 214, 0.35);
  background: #fff;
}

.btn {
  border-radius: 10px;
  font-weight: 700;
}

.btn-sm {
  padding: 0.28rem 0.58rem;
  font-size: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #12847e);
  border: 0;
  box-shadow: 0 10px 18px rgba(23, 105, 214, 0.2);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-dark), #0f706b);
  transform: translateY(-1px);
}

.btn-outline-secondary,
.btn-outline-primary {
  background: rgba(255, 255, 255, 0.62);
}

.job-meta {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 7px 8px;
  margin: 0 0 11px;
  font-size: 13px;
}

.job-meta dt {
  color: var(--muted);
  font-weight: 700;
}

.job-meta dd {
  margin: 0;
  word-break: break-all;
}

.badge {
  border-radius: 999px;
  font-weight: 700;
}

.result-frame {
  overflow: hidden;
  background:
    linear-gradient(45deg, #eef3f8 25%, transparent 25%),
    linear-gradient(-45deg, #eef3f8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef3f8 75%),
    linear-gradient(-45deg, transparent 75%, #eef3f8 75%),
    #f8fbfd;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.result-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.error-box {
  margin: 10px 0 0;
  padding: 10px;
  white-space: pre-wrap;
  color: #9d2020;
  background: #fff4f4;
  border: 1px solid #ffcfcf;
  border-radius: 12px;
  font-size: 12px;
}

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

.history-item {
  position: relative;
  padding: 10px;
  border: 1px solid rgba(217, 226, 236, 0.9);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.76);
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.history-item:hover {
  transform: translateY(-1px);
  border-color: rgba(23, 105, 214, 0.3);
  box-shadow: 0 10px 22px rgba(26, 42, 62, 0.08);
}

.history-head,
.history-foot {
  display: flex;
  justify-content: space-between;
  gap: 9px;
  align-items: center;
}

.history-id {
  min-width: 0;
  color: #223146;
  font-size: 12px;
  font-weight: 800;
  word-break: break-all;
}

.history-prompt {
  margin: 7px 0;
  color: #4b5a6b;
  font-size: 12px;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.history-foot .btn {
  white-space: nowrap;
}

.reference-field {
  position: relative;
  margin-bottom: 10px !important;
}

.inline-reference.reference-field {
  margin-bottom: 14px !important;
}

.inline-reference {
  margin: auto 18px 11px;
}

.inline-reference-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 7px;
  color: #9aa9ba;
  font-size: 13px;
  font-weight: 600;
}

.reference-clear-btn {
  display: none;
  padding: 0;
  color: #9aa9ba;
  background: transparent;
  border: 0;
  font-size: 12px;
}

.reference-preview.has-items + .inline-reference-foot .reference-clear-btn {
  display: inline-flex;
}

.reference-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.reference-preview {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0;
  min-height: 68px;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.compact-reference {
  min-height: 68px;
}

.settings-mask-field {
  grid-column: 1 / -1;
  margin: 4px 0 0 !important;
}

.reference-preview.has-items {
  background: transparent;
}

.mask-help {
  margin-top: 8px;
}

.mask-help strong {
  color: var(--ink);
}

.reference-add-card,
.reference-thumb {
  position: relative;
  overflow: hidden;
  width: 68px;
  height: 68px;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
}

.reference-add-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 68px;
  color: #90a0b3;
  background: #fff;
  border: 2px dashed #d0dbe7;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.reference-add-card:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
  box-shadow: 0 10px 20px rgba(23, 105, 214, 0.14);
}

.reference-add-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 23px;
  color: #8fa0b2;
  font-size: 21px;
  line-height: 1;
}

.reference-add-icon b {
  position: absolute;
  right: -6px;
  top: -6px;
  color: #7f8fa3;
  font-size: 15px;
}

.reference-add-text {
  font-size: 11px;
  font-weight: 800;
}

.reference-add-hint {
  color: var(--muted);
  font-size: 10px;
}

.reference-thumb {
  border: 1px solid #e3e9ef;
  background: #fff;
  box-shadow: 0 9px 18px rgba(20, 34, 48, 0.11);
}

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

.reference-thumb-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 15px 6px 5px;
  color: #fff;
  background: linear-gradient(180deg, transparent, rgba(10, 18, 30, 0.78));
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-remove-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  color: #fff;
  background: rgba(10, 20, 32, 0.78);
  border: 0;
  border-radius: 999px;
  line-height: 1;
}

.reference-remove-btn:hover {
  background: rgba(10, 20, 32, 0.95);
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 1180px) {
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 18px, 1440px);
    padding-top: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 0;
    border-radius: 0;
  }

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

  .prompt-composer {
    min-height: 176px;
    border-radius: 20px;
  }

  .prompt-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 11px 14px 0;
  }

  .prompt-header .form-label {
    font-size: 15px;
  }

  .prompt-box {
    min-height: 42px;
    padding: 6px 14px 4px;
    line-height: 1.36;
  }

  .tool-panel,
  .status-panel,
  .history-panel {
    border-radius: 14px;
  }

  .tool-panel {
    padding: 0;
  }

  .status-panel,
  .history-panel {
    padding: 12px;
  }

  .history-head,
  .history-foot {
    align-items: flex-start;
    flex-direction: column;
  }

  #optimizePrompt {
    flex: 0 0 auto;
    width: auto;
    min-height: 30px;
    padding: 0 10px;
    font-size: 12px;
    line-height: 1;
  }

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

  .reference-preview {
    grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
    gap: 8px;
  }

  .settings-summary-card {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
    padding: 9px;
  }

  .inline-reference {
    margin: auto 14px 12px;
  }

  .reference-add-card,
  .reference-thumb {
    width: 64px;
    height: 64px;
    border-radius: 16px;
  }

  .compact-reference,
  .reference-preview {
    min-height: 64px;
  }

  .primary-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }

  .settings-summary-card .btn {
    width: 100%;
  }

  #submitBtn {
    grid-column: 1 / -1;
    order: -1;
  }

  .settings-modal {
    padding: 10px;
  }

  .settings-modal-panel {
    max-height: 92vh;
    padding: 13px;
  }

  .submit-row .btn {
    flex: 1 1 auto;
  }
}
