* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --panel: #f7f7f8;
  --side: #f9f9f9;
  --border: #e5e7eb;
  --text: #111827;
  --soft: #4b5563;
  --muted: #8a94a6;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --danger: #dc2626;
  --shadow: 0 16px 50px rgba(15, 23, 42, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202123;
    --panel: #2f3033;
    --side: #17181a;
    --border: #3f4248;
    --text: #f3f4f6;
    --soft: #c2c7d0;
    --muted: #8d96a5;
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.app { height: 100vh; display: flex; overflow: hidden; }
.sidebar { width: 260px; flex: 0 0 260px; background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-header { height: 57px; padding: 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.logo-icon, .welcome-icon { display: inline-flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; font-weight: 800; letter-spacing: 0; }
.logo-icon { width: 28px; height: 28px; border-radius: 7px; font-size: 11px; }
.icon-button, .menu-button { width: 34px; height: 34px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: var(--soft); }
.icon-button:hover, .menu-button:hover, .footer-btn:hover { background: var(--panel); color: var(--text); }
.sidebar-section { flex: 1; min-height: 0; overflow: auto; padding: 8px; }
.section-title { padding: 8px 8px 6px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.history-list { display: flex; flex-direction: column; gap: 2px; }
.history-item { width: 100%; padding: 9px 10px; border-radius: 8px; display: flex; gap: 8px; align-items: center; color: var(--soft); text-align: left; }
.history-item:hover, .history-item.active { background: var(--panel); color: var(--text); }
.history-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.history-status { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.history-status.success { background: #16a34a; }
.history-status.running { background: var(--accent-2); }
.history-status.failed { background: var(--danger); }
.history-del { opacity: 0; color: var(--muted); width: 24px; height: 24px; border-radius: 6px; }
.history-item:hover .history-del { opacity: 1; }
.history-del:hover { color: var(--danger); background: rgba(220, 38, 38, 0.1); }
.sidebar-footer { padding: 8px; border-top: 1px solid var(--border); }
.footer-btn { width: 100%; padding: 10px; border-radius: 8px; display: flex; align-items: center; gap: 10px; text-align: left; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { min-height: 57px; display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.menu-button { display: none; }
select, input { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 7px 10px; outline: none; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
#modelSelect { min-width: min(360px, 42vw); }

.result-area { flex: 1; min-height: 0; overflow: auto; padding: 24px 20px 8px; }
.welcome { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.welcome-icon { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 18px; font-size: 20px; }
.welcome h1 { font-size: 30px; margin-bottom: 8px; letter-spacing: 0; }
.welcome p { color: var(--soft); max-width: 560px; line-height: 1.6; }
.messages { width: min(920px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.message { display: flex; flex-direction: column; gap: 10px; }
.prompt { align-self: flex-end; max-width: min(760px, 88%); background: var(--panel); padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.result { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.video-card, .loading-card, .error-card { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); overflow: hidden; }
.video-card { width: min(760px, 100%); }
.video-card video { display: block; width: 100%; max-height: min(62vh, 560px); background: #050505; }
.video-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: 4px 9px; font-size: 12px; color: var(--soft); background: var(--bg); }
.action { border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; color: var(--text); background: var(--bg); }
.action:hover { border-color: var(--accent); color: var(--accent); }
.loading-card { width: min(420px, 100%); padding: 20px; }
.loading-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; color: var(--soft); }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
.progress { height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s; }
.error-card { width: min(760px, 100%); padding: 12px 14px; color: var(--danger); background: rgba(220, 38, 38, 0.08); white-space: pre-wrap; word-break: break-word; }

.composer { border-top: 1px solid var(--border); padding: 12px 20px 16px; }
.media-tools {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 0 2px 1px 0;
  flex: 0 0 auto;
}
.media-tool {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.media-tool:hover { border-color: var(--accent); color: var(--accent); }
.media-tool.disabled { opacity: .38; cursor: not-allowed; }
.media-tool.has-media { border-color: var(--accent); color: white; background: var(--accent); }
.tool-label { font-size: 13px; font-weight: 700; line-height: 1; }
.tool-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tool-label.over-thumb {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: inline-flex;
  align-items: end;
  justify-content: center;
  padding-bottom: 3px;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  color: #fff;
  font-size: 11px;
}
.tool-count {
  position: absolute;
  right: -1px;
  top: -1px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
}
.tool-count.hidden { display: none; }
.ref-thumb { width: 42px; height: 42px; border-radius: 8px; background: var(--bg); object-fit: cover; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
.composer-box { width: min(920px, 100%); margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 8px; }
.composer-box:focus-within { border-color: var(--muted); }
textarea { flex: 1; min-height: 38px; max-height: 180px; resize: none; border: 0; outline: 0; background: transparent; padding: 9px 2px; line-height: 1.5; }
.send-btn { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; background: var(--text); color: var(--bg); display: inline-flex; align-items: center; justify-content: center; }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.send-btn.loading svg { animation: spin 1s linear infinite; }
.composer-hint { margin-top: 8px; text-align: center; color: var(--muted); font-size: 12px; }

.modal.hidden, .toast.hidden { display: none; }
.modal { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.36); backdrop-filter: blur(2px); }
.modal-card { position: relative; width: min(480px, calc(100vw - 32px)); background: var(--bg); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.modal-card.small { width: min(430px, calc(100vw - 32px)); }
.modal-header, .modal-footer { padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); border-bottom: 0; background: var(--panel); }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-body label { display: flex; flex-direction: column; gap: 6px; color: var(--soft); font-size: 13px; }
.modal-body input { width: 100%; }
.upload-choice { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; line-height: 1.45; }
.btn { padding: 8px 14px; border-radius: 8px; }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.ghost { color: var(--soft); }
.btn.ghost:hover { color: var(--danger); background: rgba(220, 38, 38, 0.09); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg); border-radius: 10px; padding: 10px 14px; z-index: 100; box-shadow: var(--shadow); }
.sidebar-mask { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .menu-button { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; box-shadow: 5px 0 24px rgba(0,0,0,.18); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask.show { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.38); }
  .topbar { padding: 8px 10px; gap: 7px; overflow-x: auto; }
  #modelSelect { min-width: 220px; }
  .result-area { padding: 16px 12px 6px; }
  .composer { padding: 10px 12px 14px; }
  .media-tools { gap: 5px; }
  .media-tool { width: 32px; height: 32px; border-radius: 9px; }
  .prompt { max-width: 94%; }
}
