:root {
  --page: #f3f5f6;
  --surface: #ffffff;
  --surface-soft: #f7f8f9;
  --surface-strong: #eef1f2;
  --line: #dce1e4;
  --line-strong: #c7ced3;
  --text: #171b1f;
  --muted: #66717a;
  --primary: #12634b;
  --primary-hover: #0d503d;
  --primary-soft: #e5f2ed;
  --blue: #265f9e;
  --blue-soft: #e8f1fb;
  --amber: #8b5905;
  --amber-soft: #fff2d6;
  --danger: #a43a3a;
  --danger-soft: #fbecec;
  --shadow: 0 12px 34px rgba(25, 33, 39, 0.1);
  --sidebar-width: 236px;
  --topbar-height: 66px;
  --radius: 7px;
  --control-height: 40px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--page); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: var(--sidebar-width);
  padding: 16px 12px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; padding: 2px 8px 18px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border-radius: 6px; color: #fff; background: var(--primary); }
.brand-copy { display: grid; min-width: 0; }
.brand-copy strong { font-size: 15px; white-space: nowrap; }
.brand-copy span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-nav { display: grid; align-content: start; gap: 4px; }
.sidebar-nav a {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 10px;
  border-radius: 6px;
  color: #434c54;
  font-weight: 650;
}
.sidebar-nav a:hover { background: var(--surface-soft); }
.sidebar-nav a.active { color: var(--primary); background: var(--primary-soft); }
.sidebar-nav svg { width: 18px; height: 18px; }
.nav-count { min-width: 22px; padding: 1px 6px; border-radius: 10px; color: var(--muted); background: var(--surface-strong); font-size: 10px; text-align: center; }
.sidebar-nav a.active .nav-count { color: var(--primary); background: #d5e9e1; }

.workspace-switch {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 9px;
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-soft);
  text-align: left;
}
.workspace-switch span { display: grid; min-width: 0; }
.workspace-switch small { color: var(--muted); font-size: 10px; }
.workspace-switch strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-backdrop { position: fixed; inset: 0; z-index: 25; border: 0; background: rgba(20, 26, 30, 0.48); }

.main-shell { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: var(--topbar-height);
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-left > div { display: grid; min-width: 0; }
.topbar h1 { margin: 0; font-size: 17px; line-height: 1.25; letter-spacing: 0; }
.topbar-left span { color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.mobile-menu { display: none !important; }

.connection-state { display: inline-flex; align-items: center; gap: 7px; min-height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 15px; color: var(--muted); background: var(--surface-soft); font-size: 11px; white-space: nowrap; }
.connection-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #99a2a9; }
.connection-state.ready { color: var(--primary); border-color: #bad7cb; background: var(--primary-soft); }
.connection-state.ready::before { background: var(--primary); }

.main-content { width: min(1560px, 100%); margin: 0 auto; padding: 20px 24px 32px; }
.route-page { min-width: 0; }
.generation-layout { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(390px, 0.92fr); gap: 18px; align-items: start; }
.preview-column { position: sticky; top: calc(var(--topbar-height) + 18px); display: grid; gap: 18px; min-width: 0; }

.tool-panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 2px 8px rgba(27, 35, 40, 0.025); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 60px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.panel-header > div { display: grid; min-width: 0; }
.panel-header h2, .page-toolbar h2 { margin: 0; font-size: 14px; letter-spacing: 0; }
.panel-header span, .page-toolbar > div > span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-header.compact-header { min-height: 54px; }
.panel-body { padding: 18px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--control-height); padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 6px; color: #2d353c; background: var(--surface); font-weight: 650; white-space: nowrap; }
.button:hover:not(:disabled) { background: var(--surface-soft); }
.button.primary { color: #fff; border-color: var(--primary); background: var(--primary); }
.button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.button.secondary { background: var(--surface); }
.button.ghost { border-color: transparent; background: transparent; }
.button.danger { color: var(--danger); border-color: #e1baba; background: var(--surface); }
.button.compact { min-height: 34px; padding: 0 11px; font-size: 12px; }
.icon-button { width: var(--control-height); padding: 0; }
.compact-icon { width: 30px; min-height: 30px; }

input, select, textarea { width: 100%; color: var(--text); border: 1px solid var(--line-strong); border-radius: 6px; outline: none; background: #fff; transition: border-color 140ms ease, box-shadow 140ms ease; }
input, select { height: var(--control-height); padding: 0 11px; }
textarea { min-height: 210px; padding: 11px 12px; line-height: 1.6; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(18, 99, 75, 0.11); }

.form-field { display: grid; gap: 7px; min-width: 0; }
.form-field.full { grid-column: 1 / -1; }
.field-label, .field-label-row { color: #353d44; font-size: 12px; font-weight: 700; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 5px; min-width: 0; }
.field-title code { color: var(--muted); font-family: "Cascadia Mono", Consolas, monospace; font-size: 9px; font-weight: 400; }
.required-mark { color: var(--danger); }
.field-counter, .field-note { color: var(--muted); font-size: 10px; font-weight: 400; }
.field-note { overflow-wrap: anywhere; }

.workflow-picker { display: grid; grid-template-columns: minmax(210px, 0.8fr) minmax(210px, 1fr) auto; gap: 10px; align-items: end; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.workflow-meta { grid-column: 1 / -1; min-height: 32px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--surface-soft); font-size: 11px; overflow-wrap: anywhere; }
.workflow-meta.ok { color: var(--primary); border-color: #bad7cb; background: var(--primary-soft); }
.workflow-meta.error { color: var(--danger); border-color: #e2baba; background: var(--danger-soft); }
.template-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; margin-bottom: 16px; }
.dynamic-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.json-editor { min-height: 140px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.boolean-control { display: flex; align-items: center; justify-content: space-between; min-height: var(--control-height); padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 6px; }
.boolean-control input { width: 18px; height: 18px; accent-color: var(--primary); }

.media-control { display: grid; gap: 8px; }
.media-control-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; }
.selected-source { min-height: 0; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.media-preview { padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.media-preview img { display: block; width: min(220px, 100%); max-height: 150px; object-fit: contain; }
.media-preview video { display: block; width: min(380px, 100%); max-height: 210px; background: #101418; }
.media-preview audio { display: block; width: min(440px, 100%); }
.media-preview span { color: var(--muted); font-size: 11px; }

.reference-group { padding: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.reference-add-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; }
.reference-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 9px; }
.reference-empty { grid-column: 1 / -1; display: grid; place-items: center; gap: 7px; min-height: 94px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 6px; font-size: 11px; }
.reference-item { position: relative; min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.reference-thumb { display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; background: #eceff1; color: var(--muted); }
.reference-thumb img { width: 100%; height: 100%; object-fit: cover; }
.reference-order { position: absolute; top: 6px; left: 6px; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; background: rgba(18, 25, 29, 0.76); font-size: 10px; font-weight: 700; }
.reference-name { min-height: 34px; padding: 7px 8px 3px; overflow: hidden; color: #3e474e; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.reference-actions { display: flex; justify-content: flex-end; gap: 2px; padding: 2px 5px 6px; }

.cost-strip { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; margin-top: 18px; padding: 11px 13px; border: 1px solid #bad7cb; border-radius: 6px; background: var(--primary-soft); }
.cost-strip > div { display: grid; min-width: 0; }
.cost-strip span { color: var(--primary); font-size: 11px; font-weight: 700; }
.cost-strip small { color: #4b695f; font-size: 10px; overflow-wrap: anywhere; }
.cost-strip strong { color: var(--primary); font-size: 19px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }

.video-stage { display: grid; place-items: center; width: 100%; aspect-ratio: 16 / 9; min-height: 260px; overflow: hidden; border: 1px solid #20262b; border-radius: 6px; background: #101418; }
.video-stage video { width: 100%; height: 100%; object-fit: contain; background: #0c1013; }
.video-stage.has-video { aspect-ratio: auto; min-height: 0; }
.video-stage.has-video video { display: block; width: auto; max-width: 100%; height: auto; max-height: min(72dvh, 760px); object-fit: contain; }
.video-empty { display: grid; place-items: center; gap: 9px; color: #9da7ae; text-align: center; }
.video-empty svg { width: 34px; height: 34px; color: #66737c; }
.preview-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 7px; margin-top: 11px; }

.task-state { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 13px; color: var(--muted); background: var(--surface-strong); font-size: 10px; font-weight: 700; }
.task-state.running { color: var(--blue); background: var(--blue-soft); }
.task-state.queued { color: var(--amber); background: var(--amber-soft); }
.task-state.success { color: var(--primary); background: var(--primary-soft); }
.task-state.failed { color: var(--danger); background: var(--danger-soft); }
.task-message { color: #3c454c; font-weight: 650; overflow-wrap: anywhere; }
.task-id-row { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: 7px; margin-top: 8px; color: var(--muted); }
.task-id-row code { overflow: hidden; font-family: "Cascadia Mono", Consolas, monospace; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.progress-track { height: 7px; margin-top: 13px; overflow: hidden; border-radius: 4px; background: #e8ecee; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width 250ms ease; }
.progress-bar.indeterminate { width: 34%; animation: progress-move 1.3s ease-in-out infinite; }
@keyframes progress-move { from { transform: translateX(-110%); } to { transform: translateX(300%); } }
.task-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; color: var(--muted); font-size: 10px; }

.workspace-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; padding: 12px 14px; border: 1px solid #d9bd84; border-radius: 7px; background: var(--amber-soft); }
.workspace-banner > div { display: grid; min-width: 0; }
.workspace-banner strong { color: #67450a; }
.workspace-banner > div > span { color: #795c28; font-size: 11px; overflow-wrap: anywhere; }

.page-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.page-toolbar > div:not(.toolbar-fields) { display: grid; }
.toolbar-fields { display: flex; gap: 9px; min-width: 0; }
.toolbar-fields select { width: 150px; }
.search-field { position: relative; display: block; width: min(400px, 44vw); }
.search-field svg { position: absolute; top: 11px; left: 11px; width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 36px; }

.task-section-header { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 14px; min-width: 0; margin-bottom: 12px; }
.task-section-header > div:first-child { display: grid; min-width: 0; }
.task-section-header h2 { margin: 0; font-size: 15px; letter-spacing: 0; }
.task-section-header > div:first-child > span { color: var(--muted); font-size: 10px; }
.task-section-actions { display: flex; flex: 1 1 520px; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; min-width: 0; }
.task-section-actions .search-field { flex: 1 1 240px; width: auto; min-width: 180px; max-width: 360px; }
.task-section-actions select { flex: 0 0 140px; width: 140px; }
.task-list { display: grid; gap: 9px; }
.task-list-empty { display: grid; place-items: center; min-height: 140px; padding: 20px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 7px; background: var(--surface); text-align: center; }
.task-state.draft { color: #5f4a13; background: #f5edcf; }
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.editor-toolbar > div { display: grid; min-width: 0; text-align: right; }
.editor-toolbar strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.editor-toolbar span { color: var(--muted); font-size: 10px; }

.account-summary { display: grid; grid-template-columns: minmax(250px, 0.7fr) minmax(0, 1.3fr); gap: 14px; margin-bottom: 16px; }
.account-identity { display: grid; grid-template-columns: 54px minmax(0, 1fr); align-items: center; gap: 13px; padding: 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.account-avatar { display: grid; place-items: center; width: 54px; height: 54px; overflow: hidden; border: 1px solid var(--line); border-radius: 50%; color: var(--primary); background: var(--primary-soft); }
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-identity > div:last-child { display: grid; min-width: 0; }
.account-identity small, .account-identity span { color: var(--muted); font-size: 10px; }
.account-identity strong { overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.stat-item { display: grid; align-content: center; min-width: 0; min-height: 98px; padding: 13px; border-right: 1px solid var(--line); }
.stat-item:last-child { border-right: 0; }
.stat-item span { color: var(--muted); font-size: 10px; }
.stat-item strong { margin-top: 3px; color: var(--text); font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-item:first-child strong { color: var(--primary); }
.stat-item small { margin-top: 2px; overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-history-panel { overflow: hidden; }
.dashboard-table-wrap { position: relative; min-height: 220px; overflow-x: auto; }
.dashboard-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.dashboard-table th, .dashboard-table td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.dashboard-table th { color: var(--muted); background: var(--surface-soft); font-size: 10px; font-weight: 650; }
.dashboard-table td { color: #3d464d; font-variant-numeric: tabular-nums; }
.dashboard-table td:nth-child(n+2), .dashboard-table th:nth-child(n+2) { text-align: right; }
.dashboard-empty { display: grid; place-items: center; min-height: 170px; color: var(--muted); }

.history-list { display: grid; gap: 9px; }
.history-empty, .page-empty { display: grid; place-items: center; min-height: 260px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 7px; background: var(--surface); }
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.history-main { min-width: 0; }
.history-prompt { margin: 0; overflow: hidden; color: #30383e; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-top: 6px; color: var(--muted); font-size: 10px; }
.history-actions { display: flex; align-items: center; gap: 5px; }

.template-list { display: grid; gap: 9px; }
.template-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.template-item h3 { margin: 0; font-size: 13px; }
.template-item p { display: -webkit-box; margin: 5px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.template-actions { display: flex; align-items: center; gap: 5px; }

.reference-toolbar { display: grid; grid-template-columns: minmax(150px, 0.45fr) minmax(260px, 1fr) auto auto; align-items: end; }
.reference-library { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.library-item { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.library-preview { display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; background: #e9edef; color: var(--muted); }
.library-preview img { width: 100%; height: 100%; object-fit: cover; }
.library-body { padding: 10px; }
.library-body strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.library-body span { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.library-actions { display: flex; justify-content: space-between; gap: 5px; padding: 0 8px 8px; }

.workspace-page-grid { display: grid; grid-template-columns: minmax(0, 0.85fr) minmax(420px, 1.15fr); gap: 18px; align-items: start; }
.workspace-span { grid-column: 1 / -1; }
.workspace-overview { display: grid; gap: 15px; }
.workspace-current { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 11px; align-items: center; }
.workspace-current > svg { width: 34px; height: 34px; color: var(--primary); }
.workspace-current > div { display: grid; min-width: 0; }
.workspace-current small, .workspace-current span { color: var(--muted); font-size: 10px; }
.workspace-current strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.workspace-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.workspace-file-list { display: grid; border-top: 1px solid var(--line); }
.workspace-file-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); color: #404950; font-size: 11px; }
.workspace-file-row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.setting-toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 52px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.setting-toggle > span { display: grid; }
.setting-toggle strong { font-size: 12px; }
.setting-toggle small { color: var(--muted); font-size: 10px; }
.setting-toggle input, .check-control input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--primary); }
.password-control { position: relative; display: block; }
.password-control input { padding-right: 44px; }
.password-control button { position: absolute; top: 0; right: 0; }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; }
.test-result { min-height: 34px; padding: 7px 9px; border-radius: 6px; color: var(--muted); background: var(--surface-soft); font-size: 11px; }
.test-result.ok { color: var(--primary); background: var(--primary-soft); }
.test-result.error { color: var(--danger); background: var(--danger-soft); }
.migration-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.check-control { display: flex; align-items: center; gap: 8px; font-size: 12px; white-space: nowrap; }
.migration-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

dialog { width: min(650px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(17, 23, 28, 0.5); }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-footer { justify-content: flex-end; border-top: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 15px; }
.dialog-body { display: grid; gap: 14px; max-height: calc(100vh - 180px); padding: 16px; overflow: auto; }
.snapshot-editor { min-height: 340px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; }

.toast-stack { position: fixed; right: 17px; bottom: 17px; z-index: 60; display: grid; gap: 8px; width: min(360px, calc(100vw - 34px)); }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 11px 12px; border: 1px solid var(--line-strong); border-radius: 7px; color: #2c343a; background: var(--surface); box-shadow: var(--shadow); }
.toast.success { border-color: #abd0c1; }
.toast.error { border-color: #ddb2b2; }
.toast-message { min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 1180px) {
  .generation-layout { grid-template-columns: minmax(0, 1fr) minmax(340px, 0.8fr); }
  .reference-library { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .account-summary { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .sidebar { transform: translateX(-100%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main-shell { margin-left: 0; }
  .mobile-menu { display: inline-flex !important; }
  .generation-layout { grid-template-columns: 1fr; }
  .preview-column { position: static; grid-row: 1; }
  .operation-panel { grid-row: 2; }
  .preview-column { grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr); align-items: stretch; }
  .workspace-page-grid { grid-template-columns: 1fr; }
  .workspace-span { grid-column: auto; }
}

@media (max-width: 720px) {
  :root { --topbar-height: 58px; }
  .topbar { padding: 0 12px; }
  .topbar-left span, .connection-state, .quick-workspace-label { display: none; }
  .topbar-actions .button span { display: none; }
  .topbar-actions .button { width: var(--control-height); padding: 0; }
  .main-content { padding: 12px; }
  .preview-column { grid-template-columns: 1fr; }
  .preview-panel { grid-row: 1; }
  .task-panel { grid-row: 2; }
  .video-stage { min-height: 190px; }
  .video-stage.has-video { min-height: 0; }
  .video-stage.has-video video { max-height: 68dvh; }
  .panel-header { padding: 9px 13px; }
  .panel-body { padding: 13px; }
  .workflow-picker { grid-template-columns: 1fr; }
  .workflow-meta { grid-column: auto; }
  .dynamic-form { grid-template-columns: 1fr; }
  .form-field.full { grid-column: auto; }
  textarea { min-height: 175px; }
  .reference-add-row { grid-template-columns: minmax(0, 1fr) auto; }
  .reference-add-row > .button:last-of-type { grid-column: 1 / -1; }
  .reference-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .media-control-row { grid-template-columns: minmax(0, 1fr) auto; }
  .media-control-row .icon-button { grid-column: 1 / -1; width: 100%; }
  .workspace-banner { align-items: stretch; flex-direction: column; }
  .page-toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-fields { flex-direction: column; }
  .toolbar-fields select, .search-field { width: 100%; }
  .task-section-header, .history-section-header { align-items: stretch; flex-direction: column; }
  .task-section-actions { flex: none; align-items: stretch; flex-direction: column; width: 100%; }
  .task-section-actions .search-field { flex: none; width: 100%; min-width: 0; max-width: none; }
  .task-section-actions select { flex: none; width: 100%; }
  .task-section-actions .button { justify-content: center; }
  .editor-toolbar { align-items: stretch; flex-direction: column; }
  .editor-toolbar > div { text-align: left; }
  .history-item, .template-item { grid-template-columns: 1fr; }
  .history-actions, .template-actions { justify-content: flex-end; }
  .reference-toolbar { grid-template-columns: 1fr; }
  .reference-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-stats { grid-template-columns: 1fr 1fr; }
  .stat-item { border-bottom: 1px solid var(--line); }
  .stat-item:nth-child(2) { border-right: 0; }
  .stat-item:nth-child(3), .stat-item:nth-child(4) { border-bottom: 0; }
  .settings-grid { grid-template-columns: 1fr; }
  .migration-row { align-items: stretch; flex-direction: column; }
  .migration-actions { justify-content: flex-start; }
  .form-actions .button { flex: 1; }
  .dialog-footer .button { flex: 1; }
}

@media (max-width: 430px) {
  .reference-list, .reference-library { grid-template-columns: 1fr; }
  .preview-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .preview-actions .button:last-child { grid-column: 1 / -1; }
  .cost-strip { grid-template-columns: 1fr; }
  .cost-strip strong { font-size: 17px; }
  .dashboard-stats { grid-template-columns: 1fr; }
  .stat-item { border-right: 0; border-bottom: 1px solid var(--line) !important; }
  .stat-item:last-child { border-bottom: 0 !important; }
}
