:root {
  color-scheme: dark;
  --page: #17191e;
  --panel: #1e2027;
  --panel-raised: #242630;
  --canvas: #13151a;
  --line: #343741;
  --line-soft: #2a2d36;
  --text: #eceef2;
  --muted: #a0a4b0;
  --quiet: #727783;
  --mint: #79dfbd;
  --mint-dark: #1b5947;
  --amber: #f1bf72;
  --red: #ee8b89;
  font-family: "DM Sans", "Noto Sans SC", sans-serif;
  font-size: 13px;
  font-weight: 400;
  background: var(--page);
  color: var(--text);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--page); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible, .drop-zone:focus-within { outline: 2px solid var(--mint); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 58px; flex: 0 0 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line-soft); background: #1a1c22; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); font-size: 14px; font-weight: 600; text-decoration: none; }
.brand-mark { width: 19px; height: 19px; display: grid; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); gap: 2px; transform: rotate(-8deg); }
.brand-mark i { display: block; background: var(--mint); border-radius: 2px; }
.brand-mark i:nth-child(2) { opacity: .68; }
.brand-mark i:nth-child(3) { opacity: .48; }
.brand-mark i:nth-child(4) { opacity: .82; }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.connection-state { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.connection-state i, .status-dot { width: 7px; height: 7px; border-radius: 50%; background: #777c86; }
.connection-state.connected i { background: var(--mint); box-shadow: 0 0 0 3px rgba(121,223,189,.11); }

.workspace { min-height: 0; flex: 1; display: grid; grid-template-columns: 344px minmax(0, 1fr); }
.controls-panel { height: calc(100vh - 58px); min-height: 570px; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line-soft); }
.mode-tabs { flex: 0 0 48px; display: grid; grid-template-columns: 1fr 1fr; padding: 7px 12px 0; gap: 2px; border-bottom: 1px solid var(--line-soft); }
.mode-tab { position: relative; border: 0; border-radius: 5px 5px 0 0; background: transparent; color: var(--muted); cursor: pointer; }
.mode-tab:hover { color: var(--text); background: rgba(255,255,255,.025); }
.mode-tab.active { color: var(--text); background: var(--panel-raised); }
.mode-tab.active::after { position: absolute; right: 23%; bottom: 0; left: 23%; height: 2px; content: ""; background: var(--mint); }
.panel-scroll { min-height: 0; flex: 1; overflow: auto; padding: 17px 14px 20px; scrollbar-color: #484b55 transparent; scrollbar-width: thin; }
.field-section { padding-bottom: 15px; }
.connection-fields { border-bottom: 1px solid var(--line-soft); }
.field-label { display: block; color: #c4c7cf; font-size: 12px; font-weight: 500; line-height: 18px; }
.label-line { display: flex; align-items: center; justify-content: space-between; min-height: 19px; }
.api-url-label { margin-top: 8px; }
.model-label { margin-top: 9px; }
input[type="url"], input[type="password"], input[list], textarea, .file-input, input[type="number"], select {
  width: 100%; min-width: 0; border: 1px solid #3b3e49; border-radius: 5px; background-color: #1b1d24; color: var(--text);
}
input[type="url"], input[type="password"], input[list], input[type="number"], select { height: 36px; padding: 0 10px; }
input::placeholder, textarea::placeholder { color: #737884; }
input[type="password"], input[type="url"], input[list] { font-size: 12px; }
.key-wrap { position: relative; margin-top: 2px; }
.key-wrap input { padding-right: 40px; }
.input-action, .icon-button { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; }
.input-action { position: absolute; top: 1px; right: 1px; width: 34px; height: 34px; }
.input-action:hover, .icon-button:hover { background: #30333d; color: var(--text); }
.input-action svg, .icon-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.text-button { padding: 3px 1px; border: 0; background: transparent; color: var(--mint); font-size: 11px; cursor: pointer; }
.text-button:hover { color: #b6f4dd; }
.connection-note, .char-count { color: var(--quiet); font-size: 10px; white-space: nowrap; }
.connection-note { overflow: hidden; max-width: 140px; text-overflow: ellipsis; }
.connection-fields input[type="url"], .connection-fields input[list] { margin-top: 2px; }
.connection-fields input:focus, textarea:focus, select:focus, input[type="number"]:focus { border-color: #719989; }

.prompt-section { padding-top: 13px; padding-bottom: 15px; }
textarea { display: block; min-height: 100px; margin-top: 4px; padding: 10px; resize: vertical; line-height: 1.55; font-size: 12px; }
.field-error { margin: 8px 0 0; color: var(--red); font-size: 11px; line-height: 1.5; }
.edit-files { padding-bottom: 16px; border-bottom: 1px solid var(--line-soft); }
.drop-zone { min-height: 90px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; margin-top: 7px; border: 1px dashed #515560; border-radius: 5px; color: #d5d8df; cursor: pointer; }
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--mint); background: rgba(121,223,189,.04); }
.drop-zone small { color: var(--quiet); font-size: 10px; }
.upload-icon { color: var(--mint); font-size: 22px; font-weight: 300; line-height: 22px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; clip: rect(0,0,0,0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.file-list { display: grid; gap: 6px; margin-top: 7px; }
.file-item { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 5px; border: 1px solid var(--line); border-radius: 4px; background: #1a1c22; }
.file-item img { width: 31px; height: 31px; flex: 0 0 31px; border-radius: 3px; object-fit: cover; background: var(--canvas); }
.file-name { min-width: 0; flex: 1; overflow: hidden; color: #ced1d9; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.file-remove { width: 26px; height: 26px; flex: 0 0 26px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 17px; }
.file-remove:hover { background: #353943; color: var(--red); }
.mask-label { margin-top: 13px; }
.optional { margin-left: 4px; color: var(--quiet); font-weight: 400; }
.file-input { height: auto; margin-top: 5px; padding: 6px; font-size: 10px; }
.mask-preview img { display: block; width: 48px; height: 48px; margin-top: 6px; border-radius: 3px; object-fit: cover; }

.parameter-details { padding: 11px 0 16px; border-top: 1px solid var(--line-soft); }
.parameter-details summary, .api-details summary { display: flex; align-items: center; gap: 6px; min-height: 20px; color: #989daa; font-size: 11px; cursor: pointer; list-style: none; user-select: none; }
.parameter-details summary::-webkit-details-marker, .api-details summary::-webkit-details-marker { display: none; }
.disclosure-caret { width: 0; height: 0; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 5px solid #777d89; transition: transform .15s ease; }
details[open] > summary .disclosure-caret { transform: rotate(90deg); }
.parameter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 9px; }
.control-field { display: flex; min-width: 0; flex-direction: column; gap: 4px; color: #a6aab5; font-size: 10px; }
.control-field select, .control-field input[type="number"] { height: 34px; color: #e0e2e7; font-size: 11px; }
select { padding-right: 7px; }
select:disabled, input:disabled { color: #686d78; opacity: .65; }
.control-field input[type="range"] { width: 100%; height: 34px; margin: 0; accent-color: var(--mint); }
.control-field output { color: var(--quiet); }
.count-field { max-width: calc(50% - 5px); }
.api-details { padding: 11px 0 4px; border-top: 1px solid var(--line-soft); }
.api-docs { padding: 10px 2px 0; }
.endpoint-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.endpoint-row span { color: var(--mint); font-size: 9px; font-weight: 600; }
.endpoint-row code, .api-docs p code { color: #c1c5ce; font-family: "DM Sans", "Noto Sans SC", sans-serif; font-size: 10px; }
.api-docs p { margin: 9px 0; color: #9da1ac; font-size: 10px; line-height: 1.6; overflow-wrap: anywhere; }
.copy-endpoint { height: 30px; padding: 0 9px; border: 1px solid #454954; border-radius: 4px; background: transparent; color: #cdd0d7; font-size: 10px; cursor: pointer; }
.copy-endpoint:hover { border-color: var(--mint); color: var(--mint); }

.panel-footer { flex: 0 0 auto; padding: 12px 14px 14px; border-top: 1px solid var(--line-soft); background: var(--panel); }
.generate-button { position: relative; width: 100%; height: 40px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 5px; background: var(--mint); color: #11251d; font-size: 12px; font-weight: 600; cursor: pointer; transition: background .15s ease; }
.generate-button:hover { background: #9bebd0; }
.generate-button:disabled { cursor: wait; opacity: .82; }
.button-shortcut { position: absolute; right: 10px; display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid rgba(15,54,40,.25); border-radius: 3px; font-size: 15px; font-weight: 400; }
.button-spinner { width: 13px; height: 13px; display: none; border: 2px solid rgba(17,37,29,.22); border-top-color: #11251d; border-radius: 50%; animation: spin .8s linear infinite; }
.generate-button.loading .button-spinner { display: block; }
.generate-button.loading .button-shortcut { display: none; }

.results-panel { min-width: 0; height: calc(100vh - 58px); min-height: 570px; display: flex; flex-direction: column; padding: 0 22px 13px; }
.results-toolbar { min-height: 63px; display: flex; align-items: center; justify-content: space-between; }
.results-toolbar h1 { margin: 0; color: var(--text); font-size: 14px; font-weight: 500; }
.result-meta { display: block; margin-top: 3px; color: var(--quiet); font-size: 10px; }
.result-actions { display: flex; gap: 4px; }
.canvas { position: relative; min-height: 0; flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; border: 1px solid #2b2e37; border-radius: 5px; background-color: var(--canvas); background-image: linear-gradient(45deg, #1a1c22 25%, transparent 25%), linear-gradient(-45deg, #1a1c22 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #1a1c22 75%), linear-gradient(-45deg, transparent 75%, #1a1c22 75%); background-position: 0 0, 0 8px, 8px -8px, -8px 0; background-size: 16px 16px; }
.empty-state { display: flex; flex-direction: column; align-items: center; padding: 28px; text-align: center; }
.empty-mark { width: 43px; height: 43px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 4px; margin-bottom: 17px; opacity: .78; }
.empty-mark i { border: 1px solid #626772; border-radius: 2px; }
.empty-mark i:nth-child(2), .empty-mark i:nth-child(3) { border-color: #497866; background: rgba(121,223,189,.12); }
.empty-state p, .progress-state p { margin: 0; color: #c8cbd3; font-size: 12px; }
.empty-state span, .progress-state > span:not(.progress-orbit) { margin-top: 6px; color: var(--quiet); font-size: 10px; }
.image-grid { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); align-content: center; justify-items: center; gap: 13px; padding: 16px; }
.result-item { position: relative; width: 100%; max-width: 800px; max-height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; border: 1px solid #363943; border-radius: 4px; background: #13151a; }
.result-item img { display: block; max-width: 100%; max-height: calc(100vh - 165px); object-fit: contain; }
.result-item footer { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; opacity: 0; transition: opacity .15s ease; }
.result-item:hover footer, .result-item:focus-within footer { opacity: 1; }
.result-item footer a, .result-item footer button { display: grid; place-items: center; min-width: 30px; height: 29px; padding: 0 8px; border: 1px solid #555a65; border-radius: 4px; background: rgba(22,24,29,.9); color: #eef0f4; text-decoration: none; font-size: 10px; cursor: pointer; }
.progress-state { display: flex; flex-direction: column; align-items: center; padding: 24px; }
.progress-orbit { width: 31px; height: 31px; margin-bottom: 15px; border: 2px solid #3c4b46; border-top-color: var(--mint); border-radius: 50%; animation: spin .9s linear infinite; }
.progress-state button { margin-top: 15px; padding: 5px 12px; border: 1px solid #4b4e58; border-radius: 4px; background: transparent; color: #c7cbd2; font-size: 10px; cursor: pointer; }
.progress-state button:hover { border-color: var(--red); color: var(--red); }
.status-strip { height: 38px; flex: 0 0 38px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.status-strip .status-dot { width: 6px; height: 6px; flex: 0 0 6px; background: #666b76; }
.status-strip.busy .status-dot { background: var(--amber); }
.status-strip.success .status-dot { background: var(--mint); }
.status-strip.error .status-dot { background: var(--red); }
.status-time { margin-left: auto; color: var(--quiet); }
.toast { position: fixed; z-index: 10; right: 18px; bottom: 18px; max-width: min(360px, calc(100vw - 36px)); padding: 10px 14px; transform: translateY(12px); border: 1px solid #444852; border-radius: 5px; background: #252830; color: var(--text); font-size: 11px; opacity: 0; pointer-events: none; transition: opacity .16s ease, transform .16s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }
.history-overlay { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(7, 8, 11, .72); }
.history-dialog { width: min(980px, 100%); max-height: min(760px, calc(100vh - 40px)); display: flex; flex-direction: column; overflow: hidden; border: 1px solid #444852; border-radius: 7px; background: #202229; box-shadow: 0 22px 70px rgba(0,0,0,.4); }
.history-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px 15px; border-bottom: 1px solid var(--line-soft); }
.history-header h2 { margin: 0; color: var(--text); font-size: 15px; font-weight: 500; }
.history-header p { margin: 5px 0 0; color: var(--quiet); font-size: 10px; }
.history-filters { display: flex; align-items: flex-end; gap: 10px; padding: 14px 20px 8px; }
.history-date-field { display: flex; min-width: 150px; flex-direction: column; gap: 5px; color: #aeb2bd; font-size: 10px; }
.history-date-field input { height: 34px; padding: 0 9px; border: 1px solid #3b3e49; border-radius: 4px; background: #1b1d24; color: var(--text); font-size: 11px; }
.history-query { position: relative; height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 13px; border: 0; border-radius: 4px; background: var(--mint); color: #11251d; font-size: 11px; font-weight: 600; cursor: pointer; }
.history-query:hover { background: #9bebd0; }
.history-query:disabled { cursor: wait; opacity: .78; }
.history-spinner { width: 12px; height: 12px; display: none; border: 2px solid rgba(17,37,29,.22); border-top-color: #11251d; border-radius: 50%; animation: spin .8s linear infinite; }
.history-query.loading .history-spinner { display: block; }
.history-note { min-height: 18px; margin: 0; padding: 0 20px 10px; color: var(--quiet); font-size: 10px; line-height: 1.5; }
.history-note.error { color: var(--red); }
.history-content { min-height: 210px; flex: 1; overflow: auto; border-top: 1px solid var(--line-soft); background: #191b21; }
.history-empty { min-height: 210px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--quiet); text-align: center; }
.history-empty-mark { margin-bottom: 9px; color: #708b80; font-size: 27px; }
.history-empty p { margin: 0; font-size: 11px; }
.history-table-wrap { overflow: auto; }
.history-table { width: 100%; min-width: 720px; border-collapse: collapse; font-size: 10px; }
.history-table th { position: sticky; top: 0; z-index: 1; padding: 10px 13px; border-bottom: 1px solid #3a3d47; background: #23262e; color: #9da2ad; font-size: 10px; font-weight: 500; text-align: left; white-space: nowrap; }
.history-table td { max-width: 220px; padding: 11px 13px; border-bottom: 1px solid #2a2d35; color: #d4d7de; vertical-align: top; }
.history-table tr:hover td { background: rgba(121,223,189,.035); }
.history-table .history-muted { color: var(--quiet); }
.history-table .history-status { color: var(--mint); }
.history-table .history-status.failed { color: var(--red); }
.history-table .history-nowrap { white-space: nowrap; }
body.modal-open { overflow: hidden; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .topbar { height: 52px; flex-basis: 52px; padding: 0 14px; }
  .workspace { display: flex; flex-direction: column; }
  .controls-panel { width: 100%; height: auto; min-height: 0; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .mode-tabs { flex-basis: 45px; padding-right: 12px; padding-left: 12px; }
  .panel-scroll { max-height: none; overflow: visible; padding: 13px 14px 12px; }
  .prompt-section textarea { min-height: 90px; }
  .parameter-details { padding-bottom: 12px; }
  .parameter-grid { gap: 9px 10px; }
  .panel-footer { padding: 10px 14px; }
  .results-panel { height: min(64vh, 560px); min-height: 370px; padding: 0 12px 6px; }
  .results-toolbar { min-height: 51px; }
  .canvas { min-height: 280px; }
  .image-grid { grid-template-columns: 1fr; gap: 8px; padding: 8px; }
  .result-item img { max-height: 52vh; }
  .result-item footer { opacity: 1; }
  .status-strip { height: 34px; flex-basis: 34px; }
  .history-overlay { align-items: end; padding: 0; }
  .history-dialog { max-height: 88vh; border-right: 0; border-bottom: 0; border-left: 0; border-radius: 7px 7px 0 0; }
  .history-header, .history-filters { padding-right: 14px; padding-left: 14px; }
  .history-filters { align-items: stretch; flex-wrap: wrap; }
  .history-date-field { flex: 1 1 130px; min-width: 0; }
  .history-query { flex: 1 1 100%; }
  .history-note { padding-right: 14px; padding-left: 14px; }
}

@media (max-width: 390px) {
  .panel-scroll { padding-right: 13px; padding-left: 13px; }
  .results-panel { padding-right: 9px; padding-left: 9px; }
  .field-label { font-size: 11px; }
  .parameter-grid { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
