:root {
  --ink: #17221d;
  --muted: #69736e;
  --paper: #f4f1e9;
  --card: rgba(255, 255, 252, 0.88);
  --line: rgba(23, 34, 29, 0.12);
  --green: #176b4b;
  --green-dark: #0f4f37;
  --green-soft: #e4f1e9;
  --amber: #d4993c;
  --danger: #b33f3f;
  --shadow: 0 20px 60px rgba(39, 51, 44, 0.1);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--paper); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
[hidden] { display: none !important; }

.ambient {
  position: fixed;
  width: 34rem;
  height: 34rem;
  border-radius: 50%;
  filter: blur(2px);
  pointer-events: none;
  opacity: 0.38;
  z-index: -1;
}
.ambient-one { top: -18rem; right: -8rem; background: radial-gradient(circle, #a8d8bd, transparent 70%); }
.ambient-two { bottom: -20rem; left: -10rem; background: radial-gradient(circle, #ecd6a6, transparent 70%); }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  width: min(100%, 28rem);
  padding: 3rem;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 1.75rem;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  margin-bottom: 1.5rem;
  border-radius: 1rem;
  color: white;
  background: var(--green);
  font-family: Georgia, serif;
  font-size: 1.75rem;
  box-shadow: 0 8px 24px rgba(23, 107, 75, 0.25);
}
.brand-mark.small { width: 2.5rem; height: 2.5rem; margin: 0; border-radius: 0.75rem; font-size: 1.25rem; }
.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--green);
  font-size: 0.69rem;
  font-weight: 750;
  letter-spacing: 0.15em;
}
h1, h2, p { margin-top: 0; }
.login-card h1 { margin-bottom: 0.75rem; font-family: Georgia, "Noto Serif SC", serif; font-size: 2rem; }
.login-copy { color: var(--muted); line-height: 1.65; }
label { display: grid; gap: 0.55rem; color: #39453f; font-size: 0.84rem; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  outline: none;
  transition: border-color 160ms, box-shadow 160ms;
}
input, select { height: 2.85rem; padding: 0 0.85rem; }
textarea { padding: 0.85rem; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 107, 75, 0.1); }
label small { color: var(--muted); font-size: 0.72rem; font-weight: 450; }
.secret-field { position: relative; margin-bottom: 0.8rem; }
.secret-field input { padding-right: 4rem; }
.secret-field .text-button { position: absolute; right: 0.7rem; top: 50%; transform: translateY(-50%); }
.remember-row { display: flex; align-items: center; gap: 0.55rem; margin: 0.9rem 0 1.2rem; font-weight: 500; }
.remember-row input { width: 1rem; height: 1rem; accent-color: var(--green); }
.security-note { margin: 1rem 0 0; color: var(--muted); font-size: 0.72rem; line-height: 1.5; }
.form-error { min-height: 1.1rem; margin: 0.7rem 0 0; color: var(--danger); font-size: 0.78rem; }

.primary-button, .secondary-button, .ghost-button, .generate-button {
  border: 0;
  border-radius: 0.8rem;
  transition: transform 150ms, background 150ms, opacity 150ms;
}
.primary-button, .generate-button { color: white; background: var(--green); }
.primary-button { display: inline-flex; align-items: center; justify-content: center; width: 100%; min-height: 2.9rem; text-decoration: none; font-weight: 700; }
.primary-button:hover, .generate-button:hover { background: var(--green-dark); }
.primary-button:active, .secondary-button:active, .generate-button:active { transform: translateY(1px); }
.secondary-button { padding: 0.72rem 1rem; border: 1px solid var(--line); color: var(--ink); background: #fff; font-weight: 650; }
.ghost-button { padding: 0.65rem 1rem; border: 1px solid var(--line); color: var(--ink); background: rgba(255,255,255,.5); }
.text-button { padding: 0; border: 0; color: var(--green); background: transparent; font-size: 0.78rem; font-weight: 700; }
.icon-button { border: 0; color: var(--muted); background: transparent; font-size: 1.5rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.6rem;
  padding: 0 4vw;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 233, 0.84);
  backdrop-filter: blur(16px);
}
.brand, .top-actions { display: flex; align-items: center; gap: 0.8rem; }
.brand div:last-child { display: grid; }
.brand strong { font-family: Georgia, serif; letter-spacing: 0.02em; }
.brand span { color: var(--muted); font-size: 0.67rem; }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.status-badge i { width: 0.42rem; height: 0.42rem; border-radius: 50%; background: currentColor; }
.status-badge.online, .status-badge.succeeded { color: var(--green); background: var(--green-soft); }
.status-badge.neutral { color: var(--muted); background: #ebeae5; }
.status-badge.working { color: #946820; background: #fbefd9; }
.status-badge.failed { color: var(--danger); background: #fae7e7; }

main { width: min(92vw, 90rem); margin: 0 auto; padding: 1.75rem 0 5rem; }
.section-heading, .panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.section-heading { margin-bottom: 1.1rem; }
.section-heading h2, .panel-heading h2 { margin: 0; font-family: Georgia, "Noto Serif SC", serif; font-weight: 500; }
.section-heading > span { color: var(--muted); font-size: 0.75rem; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(22rem, .95fr); gap: 1.25rem; align-items: start; }
.panel { border: 1px solid rgba(255,255,255,.8); border-radius: 1.35rem; background: var(--card); box-shadow: 0 14px 44px rgba(43,54,47,.07); backdrop-filter: blur(12px); }
.controls-panel, .result-panel, .history-panel { padding: 1.45rem; }
.panel-heading { margin-bottom: 1.25rem; }
.save-state { color: var(--muted); font-size: 0.72rem; }
.input-source-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.25rem;
  margin-bottom: 0.85rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: rgba(235, 234, 229, 0.7);
}
.input-source-tab {
  min-height: 2.55rem;
  border: 0;
  border-radius: 0.68rem;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
}
.input-source-tab.active {
  color: var(--green);
  background: #fff;
  box-shadow: 0 3px 12px rgba(23, 34, 29, 0.08);
}
.drop-zone {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 7.5rem;
  margin-bottom: 1rem;
  padding: 1rem 1.2rem;
  border: 1px dashed rgba(23,107,75,.35);
  border-radius: 1rem;
  background: rgba(228,241,233,.35);
  transition: border-color 150ms, background 150ms;
}
.drop-zone.dragging { border-color: var(--green); background: var(--green-soft); }
.drop-zone > div:nth-child(3) { flex: 1; display: grid; gap: 0.3rem; }
.drop-zone span { color: var(--muted); font-size: 0.72rem; }
.upload-icon { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 0.75rem; color: var(--green); background: #fff; font-size: 1.3rem; }
.file-summary { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1rem; padding: 0.65rem; border: 1px solid var(--line); border-radius: 0.9rem; background: #fff; }
.file-summary img { width: 3.5rem; height: 3.5rem; border-radius: 0.65rem; object-fit: cover; }
.file-summary div { flex: 1; display: grid; gap: 0.2rem; min-width: 0; }
.file-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.82rem; }
.file-summary span { color: var(--muted); font-size: 0.7rem; }
.url-source-panel { min-height: 8.5rem; margin-bottom: 1rem; padding: 0.85rem; border: 1px dashed rgba(23,107,75,.35); border-radius: 1rem; background: rgba(228,241,233,.25); }
.url-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.55rem; }
.url-source-panel .file-summary { margin: 0.8rem 0 0; }
.url-preview-shell { position: relative; flex: 0 0 3.5rem !important; width: 3.5rem; height: 3.5rem; display: grid !important; place-items: center; border-radius: 0.65rem; color: var(--green); background: var(--green-soft); overflow: hidden; }
.url-preview-shell span { color: var(--green); font-size: 0.65rem; font-weight: 800; letter-spacing: 0.08em; }
.field-grid { display: grid; gap: 0.85rem; margin: 1rem 0; }
.field-grid.two { grid-template-columns: repeat(2, 1fr); }
.field-grid.three { grid-template-columns: repeat(3, 1fr); }
.preset-actions { display: flex; align-items: center; gap: 1rem; margin-top: 0.8rem; }
.divider { height: 1px; margin: 1.35rem 0; background: var(--line); }
.print-settings { padding: 0.2rem 0.9rem; border-radius: 0.9rem; background: rgba(228,241,233,.48); }
input[type="range"] { height: 1.4rem; padding: 0; accent-color: var(--green); background: transparent; box-shadow: none; }
.generate-button { display: grid; width: 100%; min-height: 4rem; margin-top: 1.25rem; padding: 0.75rem; }
.generate-button span { font-weight: 750; }
.generate-button small { color: rgba(255,255,255,.7); font-size: 0.67rem; }
.generate-button:disabled { cursor: not-allowed; opacity: 0.45; }

.right-column { display: grid; gap: 1.25rem; }
.result-panel { min-height: 33rem; }
.result-empty, .result-loading { display: grid; place-items: center; align-content: center; min-height: 24rem; text-align: center; }
.result-empty span, .result-loading span { margin-top: 0.35rem; color: var(--muted); font-size: 0.75rem; }
.result-placeholder { margin-bottom: 1rem; color: #9eb2a7; font-size: 3rem; }
.loader { width: 2.5rem; height: 2.5rem; margin-bottom: 1rem; border: 3px solid #d8e7de; border-top-color: var(--green); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.image-stage { display: grid; place-items: center; min-height: 20rem; padding: 0.75rem; border-radius: 0.9rem; background: #ecebe6; overflow: hidden; }
.image-stage img { display: block; max-width: 100%; max-height: 30rem; object-fit: contain; }
.result-meta { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 0.6rem; margin: 0.85rem 0; }
.result-meta div { display: grid; gap: 0.2rem; padding: 0.65rem; border: 1px solid var(--line); border-radius: 0.75rem; }
.result-meta span { color: var(--muted); font-size: 0.62rem; }
.result-meta strong { overflow: hidden; text-overflow: ellipsis; font-size: 0.72rem; white-space: nowrap; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
.primary-button.compact { min-height: 2.65rem; font-size: 0.82rem; }
.compact-heading { margin-bottom: 0.85rem; }
.history-list { display: grid; gap: 0.55rem; max-height: 19rem; overflow: auto; }
.history-empty { padding: 2rem; color: var(--muted); text-align: center; font-size: 0.76rem; }
.history-item { display: grid; grid-template-columns: 4rem minmax(0, 1fr); align-items: center; gap: 0.8rem; width: 100%; padding: 0.65rem; border: 1px solid var(--line); border-radius: 0.8rem; text-align: left; color: var(--ink); background: #fff; transition: border-color 150ms, box-shadow 150ms, transform 150ms; }
.history-item:hover { border-color: rgba(23, 107, 75, 0.35); box-shadow: 0 6px 18px rgba(23, 34, 29, 0.07); transform: translateY(-1px); }
.history-thumbnail { display: grid; place-items: center; width: 4rem; height: 4rem; overflow: hidden; border-radius: 0.65rem; color: var(--muted); background: #ecebe6; font-size: 0.65rem; font-weight: 750; }
.history-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.history-thumbnail.is-queued, .history-thumbnail.is-running { color: #946820; background: #fbefd9; }
.history-thumbnail.is-failed, .history-thumbnail.is-canceled { color: var(--danger); background: #fae7e7; }
.history-content { display: grid; gap: 0.45rem; min-width: 0; color: var(--ink) !important; }
.history-prompt { display: -webkit-box; overflow: hidden; color: var(--ink); font-size: 0.76rem; font-weight: 650; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.history-task-id { overflow: hidden; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.62rem; text-overflow: ellipsis; white-space: nowrap; }

footer { display: flex; justify-content: space-between; gap: 1rem; padding: 1.5rem 4vw; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.7rem; }
.toast { position: fixed; left: 50%; bottom: 2rem; z-index: 20; padding: 0.75rem 1rem; border-radius: 0.75rem; color: #fff; background: var(--ink); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 1rem); transition: 180ms; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .service-grid, .field-grid.three { grid-template-columns: 1fr; }
  .workspace-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .login-card { padding: 2rem 1.4rem; }
  .topbar { padding: 0 1rem; }
  .status-badge.online { display: none; }
  main { width: calc(100% - 1.2rem); padding-top: 2rem; }
  .section-heading > span { display: none; }
  .field-grid.two, .result-meta, .result-actions { grid-template-columns: 1fr; }
  .drop-zone { align-items: flex-start; flex-wrap: wrap; }
  .drop-zone .secondary-button { margin-left: 3.6rem; }
  footer { flex-direction: column; }
}
