:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #111827;
  --muted: #64748b;
  --border: #dbe3ef;
  --accent: #275bd8;
  --accent-dark: #1f49b4;
  --danger: #c73535;
  --danger-bg: #fef2f2;
  --ok: #16834a;
  --ok-bg: #f0fdf4;
  --warning: #9a5b00;
  --warning-bg: #fff7ed;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.09);
  --radius: 12px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101417;
  --surface: #171d22;
  --surface-2: #20272e;
  --text: #f3f6f8;
  --muted: #a7b2bd;
  --border: #33404a;
  --accent: #5f8cff;
  --accent-dark: #7aa0ff;
  --danger: #ff8585;
  --danger-bg: #351d22;
  --ok: #76d49a;
  --ok-bg: #173021;
  --warning: #f2bd67;
  --warning-bg: #332818;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .62; }
.hidden { display: none !important; }

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  width: 30px; height: 30px; display: inline-grid; place-items: center;
  border-radius: 8px; background: var(--accent); color: white; font-size: 12px;
}
.top-actions, .head-actions, .workspace-actions, .dialog-actions {
  display: flex; gap: 10px; align-items: center;
}

main { padding: 28px; }
.auth-view {
  min-height: calc(100vh - 112px);
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(320px, 1fr);
  gap: 24px;
  align-items: stretch;
  max-width: 1180px;
  margin: 0 auto;
}
.auth-card, .auth-aside, .upload-panel, .project-card, .preview-panel, .slides-panel, .notes-panel, .llm-list, .llm-editor, dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-card { padding: 34px; display: flex; flex-direction: column; gap: 22px; }
.auth-aside { padding: 34px; display: flex; flex-direction: column; justify-content: center; }
.auth-aside li { margin: 12px 0; color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 13px; font-weight: 700; letter-spacing: .04em; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 30px; line-height: 1.2; }
.muted { color: var(--muted); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.auth-tabs button { border: 0; background: transparent; padding: 10px; border-radius: 8px; color: var(--muted); }
.auth-tabs .is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 8px rgba(15,23,42,.08); }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 8px; font-weight: 650; font-size: 14px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(39,91,216,.18); border-color: var(--accent); }
.captcha-row { display: grid; grid-template-columns: 1fr 160px; gap: 10px; }
.captcha-box {
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}
.captcha-box img { width: 100%; height: 100%; display: block; }
.primary-btn, .secondary-btn, .ghost-btn {
  border-radius: 10px;
  border: 1px solid transparent;
  min-height: 40px;
  padding: 0 16px;
  font-weight: 650;
}
.primary-btn { background: var(--accent); color: white; }
.primary-btn:hover { background: var(--accent-dark); }
.secondary-btn { background: var(--surface); color: var(--text); border-color: var(--border); }
.ghost-btn { background: transparent; color: var(--text); border-color: transparent; }
.ghost-btn:hover, .secondary-btn:hover { background: var(--surface-2); }
.danger-btn { color: var(--danger); border-color: rgba(199,53,53,.28); }
.danger-btn:hover { background: var(--danger-bg); }
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}
.danger-icon { color: var(--danger); border-color: rgba(199,53,53,.24); }
.danger-icon:hover { background: var(--danger-bg); }
.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-weight: 650;
  text-align: left;
}
.link-btn:hover { text-decoration: underline; }
.error-text { color: var(--danger); min-height: 20px; margin: 0; font-size: 14px; }

.dashboard { max-width: 1280px; margin: 0 auto; }
.page-head, .workspace-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.upload-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: none;
  border-style: dashed;
}
.upload-panel p { margin: 6px 0 0; color: var(--muted); }
.upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 130px;
  min-height: 42px;
  border-radius: 10px;
  background: var(--text);
  color: white;
}
.upload-btn input { display: none; }
.project-grid, .template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.project-card { padding: 18px; box-shadow: none; display: flex; flex-direction: column; gap: 18px; }
.project-meta { color: var(--muted); font-size: 13px; word-break: break-all; }
.project-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: auto; flex-wrap: wrap; }
.project-actions button { flex: 1 1 92px; }
.empty-state { text-align: center; padding: 64px 20px; color: var(--muted); }

.template-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: none;
}
.template-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.template-head h3 { margin-bottom: 6px; }
.template-actions {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.template-slots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.template-slot {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
}
.template-slot.has-asset { background: var(--surface); }
.template-preview {
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
}
.template-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.template-slot-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 9px 0;
  font-size: 13px;
}
.template-slot-meta span { color: var(--muted); }
.template-slot-actions {
  display: flex;
  gap: 8px;
}
.template-slot-actions label {
  margin: 0;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 10px;
}
.template-slot-actions input { display: none; }

.llm-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
}
.llm-list, .llm-editor {
  padding: 16px;
  box-shadow: none;
}
.llm-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.llm-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
}
.llm-item.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(39,91,216,.13); }
.llm-select {
  width: 100%;
  padding: 4px;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
}
.llm-select strong, .llm-select span, .llm-select small { display: block; }
.llm-select span, .llm-select small { margin-top: 5px; color: var(--muted); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.inline-check {
  flex-direction: row;
  align-items: center;
  font-weight: 500;
}
.inline-check input { width: auto; }
.code-textarea {
  min-height: 90px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.search-actions {
  min-width: min(420px, 100%);
}
.metric-grid, .plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.metric-card, .plan-card, .admin-panel, .settings-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: none;
}
.metric-card span, .metric-card small {
  display: block;
  color: var(--muted);
}
.metric-card strong {
  display: block;
  margin: 8px 0;
  font-size: 26px;
}
.meter {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
  margin-top: 12px;
}
.meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.plan-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.plan-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(39,91,216,.13);
}
.plan-card strong {
  font-size: 22px;
}
.marketplace-meta {
  margin: 10px 0 0;
  font-size: 13px;
}
.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}
.panel-title-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.admin-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
}
.admin-item strong, .admin-item span, .admin-item small {
  display: block;
}
.admin-item span, .admin-item small {
  margin-top: 5px;
  color: var(--muted);
}
.admin-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.settings-panel {
  max-width: 520px;
  display: grid;
  gap: 16px;
}

.workspace { height: calc(100vh - 112px); display: flex; flex-direction: column; }
.workspace-top { margin-bottom: 14px; align-items: center; }
.workspace-top h1 { margin-bottom: 3px; font-size: 22px; }
.workspace-actions { flex-wrap: wrap; justify-content: flex-end; }
.workspace-actions .secondary-btn, .workspace-actions .primary-btn { min-height: 36px; padding: 0 12px; }
.workspace-grid {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 240px minmax(680px, 1fr) 300px;
  gap: 14px;
}
.slides-panel, .notes-panel, .preview-panel { min-height: 0; box-shadow: none; }
.slides-panel, .notes-panel { padding: 14px; overflow: auto; }
.panel-title { font-weight: 750; margin-bottom: 12px; }
.slide-list { display: flex; flex-direction: column; gap: 8px; }
.slide-item {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 12px;
  text-align: left;
}
.slide-item.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(39,91,216,.13); }
.slide-item small { color: var(--muted); display: block; margin-bottom: 6px; }
.preview-panel { display: flex; flex-direction: column; overflow: hidden; }
.preview-toolbar {
  height: 52px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.slide-frame-wrap {
  flex: 1;
  min-height: 0;
  padding: 12px;
  display: grid;
  place-items: center;
  background: #111827;
}
#slide-frame {
  width: min(100%, calc((100vh - 190px) * 16 / 9));
  aspect-ratio: 16 / 9;
  height: auto;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(15,23,42,.18);
}
#note-content {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
  min-height: 160px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.validation-box { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 16px; color: var(--muted); }
.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.compact-btn {
  min-height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  font-size: 12px;
}
.danger-text { color: var(--danger); }
.mini-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
}
.mini-upload input { display: none; }
.asset-list, .snapshot-list, .comment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.asset-item, .snapshot-item, .comment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px;
  background: var(--surface-2);
}
.asset-item span, .snapshot-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.asset-item small, .snapshot-item small, .comment-item small { color: var(--muted); }
.asset-item button, .snapshot-item button { justify-self: end; }
.comment-item {
  display: block;
}
.comment-item strong { color: var(--text); }
.comment-item p {
  margin: 6px 0;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.comment-form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.comment-form textarea {
  min-height: 70px;
}
.share-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.share-result input { font-size: 13px; }
.share-list-wrap {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.share-list-wrap h3 {
  margin-bottom: 10px;
  font-size: 15px;
}
.share-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}
.share-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
}
.share-item strong, .share-item span, .share-item small { display: block; }
.share-item span {
  margin-top: 5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-item small { margin-top: 5px; color: var(--muted); }
.share-item-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.share-item.is-revoked { opacity: .62; }
.share-view {
  height: calc(100vh - 112px);
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.share-layout {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 240px minmax(640px, 1fr) 300px;
  gap: 14px;
}
.warning-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #8a5a00;
}
.warning-list li { margin-bottom: 6px; }
.job-list { display: flex; flex-direction: column; gap: 8px; }
.job-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
}
.job-item strong, .job-item span, .job-item small { display: block; }
.job-item span {
  margin-top: 5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-completed { border-color: rgba(22,131,74,.35); background: #f0fdf4; }
.job-failed { border-color: rgba(199,53,53,.35); background: #fef2f2; }

dialog { width: min(480px, calc(100vw - 32px)); border: 0; padding: 0; }
#ai-slide-dialog { width: min(560px, calc(100vw - 32px)); }
#edit-slide-dialog { width: min(1080px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 23, 42, .42); }
.dialog-body { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.edit-dialog { max-height: calc(100vh - 48px); }
.code-editor {
  min-height: 46vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
}
.dialog-actions { justify-content: flex-end; }
.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}
.toast {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  opacity: 1;
  transform: translateY(0);
  transition: opacity .18s ease, transform .18s ease;
}
.toast-success { border-color: rgba(22,131,74,.3); background: var(--ok-bg); color: var(--ok); }
.toast-warning { border-color: rgba(154,91,0,.3); background: var(--warning-bg); color: var(--warning); }
.toast-error { border-color: rgba(199,53,53,.3); background: var(--danger-bg); color: var(--danger); }
.toast.is-hiding { opacity: 0; transform: translateY(8px); }
.global-loading {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 120;
  width: 100%;
  height: 3px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease;
}
.global-loading::before {
  content: "";
  display: block;
  width: 38%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  transform: translateX(-100%);
}
.global-loading.is-active {
  opacity: 1;
}
.global-loading.is-active::before {
  animation: loading-sweep 1s ease-in-out infinite;
}
.skeleton-card {
  position: relative;
  min-height: 150px;
  overflow: hidden;
  background: linear-gradient(90deg, #eef2f7 0%, #f8fafc 45%, #eef2f7 90%);
  background-size: 220% 100%;
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}
:root[data-theme="dark"] .skeleton-card {
  background: linear-gradient(90deg, #1d252b 0%, #2a333b 45%, #1d252b 90%);
  background-size: 220% 100%;
}
.skeleton-template { min-height: 260px; }
.skeleton-llm { min-height: 86px; }
.skeleton-job { min-height: 72px; }

@keyframes loading-sweep {
  to { transform: translateX(260%); }
}

@keyframes skeleton-pulse {
  to { background-position: -220% 0; }
}

@media (max-width: 1024px) {
  main { padding: 16px; }
  .auth-view { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .page-head, .upload-panel, .workspace-top { flex-direction: column; align-items: stretch; }
  .workspace { height: calc(100vh - 88px); }
  .workspace-grid { grid-template-columns: minmax(170px, 220px) minmax(0, 1fr); }
  .share-view { height: calc(100vh - 88px); }
  .share-layout { grid-template-columns: minmax(170px, 220px) minmax(0, 1fr); }
  .notes-panel { grid-column: 1 / -1; max-height: 220px; }
  .llm-layout, .form-grid, .admin-grid { grid-template-columns: 1fr; }
  #slide-frame { width: 100%; }
}

@media (max-width: 600px) {
  .topbar {
    height: auto;
    min-height: 56px;
    padding: 10px 14px;
    align-items: flex-start;
    gap: 10px;
  }
  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
  }
  .top-actions .ghost-btn {
    min-height: 34px;
    padding: 0 10px;
  }
  main { padding: 12px; }
  h1 { font-size: 24px; }
  .captcha-row { grid-template-columns: 1fr; }
  .head-actions, .workspace-actions, .dialog-actions {
    flex-wrap: wrap;
    align-items: stretch;
  }
  .workspace {
    height: auto;
    min-height: calc(100vh - 86px);
  }
  .share-view {
    height: auto;
    min-height: calc(100vh - 86px);
  }
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .share-layout {
    grid-template-columns: 1fr;
  }
  .slides-panel, .notes-panel {
    max-height: 260px;
  }
  .slide-frame-wrap {
    padding: 8px;
  }
  .preview-toolbar {
    height: auto;
    min-height: 52px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .project-actions, .template-head, .upload-panel, .admin-item {
    flex-direction: column;
    align-items: stretch;
  }
  .admin-item { display: flex; }
  .primary-btn, .secondary-btn, .ghost-btn {
    min-height: 42px;
  }
}
