:root {
  --ink: #13212b;
  --muted: #6f7c84;
  --line: #e3e8ea;
  --soft: #f5f7f7;
  --paper: #ffffff;
  --teal: #087f73;
  --teal-dark: #07584f;
  --amber: #e09a26;
  --red: #c04b4b;
  --shadow: 0 18px 50px rgba(22, 44, 54, .08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #f4f6f5;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #f4f6f5; }
body { font-size: 14px; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.auth-layout { min-height: 100vh; display: grid; place-items: center; padding: 32px; background: #eef4f2; }
.auth-brand { position: fixed; top: 34px; left: 42px; display: flex; align-items: center; gap: 12px; }
.auth-brand strong, .brand-block strong { display: block; font-size: 18px; letter-spacing: 1px; }
.auth-brand span, .brand-block span { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--teal); color: #fff; font-size: 20px; font-weight: 800; border-radius: 9px; box-shadow: 0 7px 14px rgba(8,127,115,.2); }
.auth-card { width: min(420px, 100%); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 30px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 24px; font-size: 22px; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--line); margin: -4px 0 24px; gap: 22px; }
.auth-tab { border: 0; background: none; padding: 0 0 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.auth-tab.active { color: var(--teal); border-bottom-color: var(--teal); font-weight: 700; }
.auth-form { display: grid; gap: 16px; }
label { color: #40515a; font-size: 13px; display: grid; gap: 7px; }
input, textarea, select { border: 1px solid #d8e0e2; border-radius: 6px; background: #fff; color: var(--ink); padding: 11px 12px; outline: none; transition: border-color .16s, box-shadow .16s; }
input:focus, textarea:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(8,127,115,.1); }
textarea { resize: vertical; line-height: 1.65; }
.primary-button, .secondary-button, .ghost-button, .text-button, .icon-button { border: 0; border-radius: 6px; transition: transform .14s, background .14s, color .14s; }
.primary-button { background: var(--teal); color: #fff; padding: 11px 18px; font-weight: 700; }
.primary-button:hover { background: var(--teal-dark); transform: translateY(-1px); }
.primary-button.full { width: 100%; }
.secondary-button { background: #e8f1ef; color: var(--teal-dark); padding: 9px 14px; font-weight: 650; }
.secondary-button:hover { background: #dbe9e6; }
.ghost-button { background: transparent; color: var(--muted); padding: 8px 0; text-align: left; }
.ghost-button:hover, .subtle-link:hover { color: var(--teal); }
.text-button { background: transparent; color: var(--teal); padding: 3px 0; }
.icon-button { width: 32px; height: 32px; background: #f0f4f3; color: #5c6b72; font-size: 20px; line-height: 1; }
.icon-button:hover { background: #dceae6; color: var(--teal-dark); }
.form-message { min-height: 20px; margin: 10px 0 0; color: var(--red); }
.form-message.success { color: var(--teal); }
.auth-footnote { display: block; color: var(--muted); margin-top: 18px; line-height: 1.6; }
.subtle-link { color: var(--muted); text-decoration: none; font-size: 13px; }

.app-shell, .admin-shell { display: flex; min-height: 100vh; }
.sidebar { width: 224px; flex: 0 0 224px; background: #102b30; color: #dcebe8; padding: 24px 17px; display: flex; flex-direction: column; }
.brand-block { display: flex; align-items: center; gap: 11px; padding: 0 9px 30px; }
.brand-block span { color: #8fb7b2; }
.side-nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 12px; border: 0; background: transparent; border-radius: 6px; color: #9fbcb8; text-align: left; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: rgba(77, 187, 168, .2); }
.nav-icon { width: 18px; text-align: center; font-size: 16px; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 12px; padding: 0 12px; }
.sidebar-bottom .subtle-link { color: #9fbcb8; }
.workspace { min-width: 0; flex: 1; padding: 28px 38px 56px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 28px; }
.eyebrow, .section-kicker { color: var(--teal); font-size: 10px; letter-spacing: 1.7px; font-weight: 800; margin: 0 0 6px; }
.topbar h1, .section-heading h2, .preview-header h2 { margin: 0; font-size: 25px; letter-spacing: -.2px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.balance-pill { display: flex; align-items: baseline; gap: 8px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.balance-pill span { color: var(--muted); font-size: 12px; }
.balance-pill strong { color: var(--teal-dark); font-size: 17px; }
.balance-pill small { color: var(--muted); }
.user-menu { display: flex; align-items: center; gap: 10px; color: #43535b; min-width: 0; }
.user-menu > span { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-panel { max-width: 1500px; }
.studio-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr); gap: 24px; align-items: start; }
.composer-column, .preview-column, .admin-note, .editor-panel { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 26px rgba(26, 52, 60, .04); }
.composer-column { padding: 28px; }
.preview-column { min-height: 650px; padding: 25px; position: sticky; top: 24px; }
.section-heading, .preview-header, .control-heading, .submit-row, .modal-header, .editor-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-heading { margin-bottom: 24px; }
.section-heading h2, .preview-header h2 { font-size: 19px; }
.prompt-label { margin-bottom: 8px; font-weight: 700; }
.prompt-input { width: 100%; min-height: 150px; font-size: 15px; }
.mention-row { display: flex; gap: 10px; align-items: flex-start; padding: 13px 0 4px; color: var(--muted); font-size: 12px; }
.mention-list { display: flex; gap: 7px; flex-wrap: wrap; min-width: 0; }
.asset-chip { display: inline-flex; align-items: stretch; min-width: 0; max-width: 100%; border: 1px solid #b8d7d1; background: #f0f8f6; border-radius: 5px; overflow: hidden; }
.mention-chip, .mention-remove { border: 0; background: transparent; color: var(--teal-dark); }
.mention-chip { min-width: 0; max-width: 360px; padding: 4px 8px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-remove { width: 28px; flex: 0 0 28px; border-left: 1px solid #cce1dd; font-size: 16px; line-height: 1; }
.mention-remove:hover { background: #dceeea; color: var(--red); }
.empty-hint { color: #9aa7ab; }
.control-section { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 20px; }
.control-heading { margin-bottom: 12px; }
.control-heading h3 { margin: 0; font-size: 14px; }
.small-muted, .readout, label small { color: var(--muted); font-size: 11px; line-height: 1.5; }
.model-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 9px; }
.model-card { min-height: 82px; border: 1px solid var(--line); border-radius: 7px; padding: 11px; background: #fff; text-align: left; }
.model-card:hover { border-color: #8fc8bf; }
.model-card.selected { border-color: var(--teal); background: #eff8f6; box-shadow: inset 0 0 0 1px var(--teal); }
.model-card strong { display: block; font-size: 13px; color: var(--ink); }
.model-card small { display: block; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.model-card strong, .model-card small { overflow-wrap: anywhere; }
.model-price { color: var(--teal-dark) !important; font-weight: 700; }
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.readout { border: 1px solid #d8e0e2; border-radius: 6px; min-height: 40px; padding: 11px 12px; background: var(--soft); }
.upload-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.upload-slot { border: 1px dashed #bbced0; background: #fbfcfc; color: var(--ink); min-height: 78px; border-radius: 7px; text-align: left; padding: 11px; display: grid; gap: 3px; }
.upload-slot:hover { border-color: var(--teal); background: #f2faf8; }
.upload-symbol { font-size: 22px; color: var(--teal); line-height: 1; }
.upload-slot strong { font-size: 12px; }
.upload-slot small { color: var(--muted); font-size: 11px; }
.submit-row { margin-top: 23px; padding-top: 22px; border-top: 1px solid var(--line); }
.submit-row strong { display: block; font-size: 14px; }
.submit-row small { color: var(--muted); display: block; margin-top: 4px; }
.button-arrow { margin-left: 12px; font-size: 18px; }
.preview-header { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.preview-content { min-height: 560px; display: grid; place-items: center; padding-top: 18px; }
.preview-empty { display: grid; place-items: center; gap: 10px; color: var(--muted); text-align: center; }
.preview-empty strong { color: #55656c; }
.empty-art { width: 68px; height: 68px; display: grid; place-items: center; border: 1px solid #c9dcda; color: var(--teal); border-radius: 50%; font-size: 29px; }
.progress-card { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 17px; }
.progress-card h3 { margin: 0; font-size: 14px; }
.progress-bar { height: 8px; border-radius: 4px; background: #e5eded; overflow: hidden; margin: 18px 0 8px; }
.progress-bar span { display: block; height: 100%; background: var(--teal); transition: width .3s; }
.progress-native { width: 100%; height: 8px; margin: 18px 0 8px; appearance: none; border: 0; border-radius: 4px; overflow: hidden; background: #e5eded; }
.progress-native::-webkit-progress-bar { background: #e5eded; }
.progress-native::-webkit-progress-value { background: var(--teal); }
.progress-native::-moz-progress-bar { background: var(--teal); }
.progress-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.result-media { width: 100%; border-radius: 7px; background: #13252a; overflow: hidden; }
.result-media video, .result-media img { width: 100%; display: block; max-height: 520px; object-fit: contain; }
.result-gallery { display: grid; gap: 10px; width: 100%; }
.result-gallery img { width: 100%; border: 1px solid var(--line); border-radius: 7px; display: block; }
.result-output { width: 100%; }
.result-image-item { display: grid; gap: 8px; justify-items: start; }
.result-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.result-download { display: inline-flex; align-items: center; text-decoration: none; }
.history-list { display: grid; gap: 9px; }
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: center; border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 14px 16px; }
.history-summary { min-width: 0; }
.history-item strong { display: block; font-size: 13px; }
.history-item p { margin: 5px 0 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.history-item small { color: var(--muted); }
.history-meta { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.history-open { white-space: nowrap; }
.status-badge { display: inline-flex; padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.status-badge.muted { color: #68787c; background: #edf1f1; }
.status-badge.green { color: #0d6d5c; background: #e4f4ef; }
.status-badge.amber { color: #8b5c10; background: #fff2d8; }
.status-badge.red { color: #9e3c3c; background: #fce8e8; }

.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(16, 37, 43, .42); z-index: 20; }
.modal-card { width: min(440px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: #fff; border-radius: 8px; padding: 24px; box-shadow: var(--shadow); }
.modal-header { margin-bottom: 13px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-card form { display: flex; gap: 8px; margin-top: 18px; }
.modal-card form input { min-width: 0; flex: 1; }
#user-action-form { display: grid; grid-template-columns: 1fr 1fr; }
#user-action-form .primary-button { grid-column: 1 / -1; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; background: #102b30; color: #fff; padding: 11px 16px; border-radius: 6px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

.admin-note { padding: 25px; max-width: 700px; }
.admin-note h2 { margin: 8px 0; font-size: 19px; }
.admin-note p { color: var(--muted); line-height: 1.7; margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(140px,1fr)); gap: 13px; margin-bottom: 24px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.stat-card span, .stat-card small { color: var(--muted); font-size: 12px; display: block; }
.stat-card strong { font-size: 28px; margin: 14px 0 4px; display: block; color: var(--teal-dark); }
.model-admin-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr); gap: 18px; align-items: start; }
.admin-model-list { display: grid; gap: 8px; }
.admin-model-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 7px; }
.admin-model-row > div { min-width: 0; }
.admin-model-row strong { display: block; overflow-wrap: anywhere; }
.admin-model-row small { color: var(--muted); display: block; margin-top: 5px; overflow-wrap: anywhere; }
.admin-model-row .model-meta { text-align: right; }
.admin-model-row .model-meta strong { color: var(--teal-dark); }
.editor-panel { padding: 22px; position: sticky; top: 20px; }
.editor-header { margin-bottom: 18px; }
.editor-header h3 { margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.editor-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.inline-form { display: flex; align-items: end; gap: 12px; margin-bottom: 14px; }
.inline-form label { min-width: 150px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-size: 12px; }
th { color: var(--muted); font-weight: 700; background: #fbfcfc; }
tbody tr:last-child td { border-bottom: 0; }
.table-action { border: 0; background: #edf4f2; color: var(--teal-dark); border-radius: 4px; padding: 5px 8px; margin-right: 4px; }
.table-action.danger { color: #9e3c3c; background: #fcecec; }
.admin-label { color: var(--muted); }

@media (max-width: 1050px) {
  .sidebar { width: 188px; flex-basis: 188px; }
  .workspace { padding: 24px; }
  .studio-grid, .model-admin-layout { grid-template-columns: 1fr; }
  .preview-column, .editor-panel { position: static; }
  .preview-column { min-height: 420px; }
  .preview-content { min-height: 330px; }
}
@media (max-width: 680px) {
  .auth-layout { padding: 18px; }
  .auth-brand { position: static; margin-bottom: 22px; }
  .auth-layout { display: flex; flex-direction: column; align-items: stretch; justify-content: center; }
  .auth-card { padding: 22px; }
  .app-shell, .admin-shell { display: block; }
  .sidebar { width: 100%; height: auto; padding: 14px 16px; }
  .brand-block { padding: 0 0 13px; }
  .side-nav { display: flex; overflow-x: auto; }
  .nav-item { width: auto; white-space: nowrap; padding: 8px 10px; }
  .sidebar-bottom { display: flex; justify-content: space-between; margin-top: 13px; padding: 0; }
  .workspace { padding: 20px 15px 40px; }
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .topbar h1 { font-size: 21px; }
  .topbar-actions { width: 100%; min-width: 0; gap: 8px; flex-wrap: wrap; justify-content: space-between; }
  .balance-pill { padding: 7px 9px; }
  .balance-pill small { display: none; }
  .composer-column, .preview-column { padding: 18px; }
  .controls-grid, .upload-grid, .stat-grid { grid-template-columns: 1fr; }
  .model-list { grid-template-columns: 1fr 1fr; }
  .history-item { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .history-meta { justify-content: space-between; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .modal-card form { align-items: stretch; flex-direction: column; }
  .modal-card form label, .modal-card form input, .modal-card form button { width: 100%; }
  #user-action-form { grid-template-columns: 1fr; }
  .admin-model-row { grid-template-columns: minmax(0, 1fr); }
  .admin-model-row .model-meta { text-align: left; }
  .mention-row { flex-direction: column; }
  .mention-list { width: 100%; }
  .mention-chip { max-width: calc(100vw - 110px); }
  .submit-row { align-items: stretch; flex-direction: column; }
  .submit-row .primary-button { width: 100%; }
  .toast { left: 15px; right: 15px; bottom: 15px; text-align: center; }
}
