/* ==========================================================
   AI 课件工坊 · 样式
   简洁高效的办公风 + 教育感
   ========================================================== */

:root {
  --bg:        #f2f5fa;
  --card:      #ffffff;
  --line:      #e3e8f1;
  --line-soft: #eef2f8;
  --ink:       #172033;
  --ink-2:     #3d4a63;
  --muted:     #6b7992;
  --brand:     #2563eb;
  --brand-2:   #0ea5e9;
  --brand-ink: #1d4ed8;
  --ok:        #0f9d6e;
  --danger:    #c93a3a;
  --radius:    16px;
  --shadow:    0 8px 28px rgba(23, 43, 77, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14.5px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  flex: 0 0 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .28);
}

.brand-text h1 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: .01em;
}
.brand-text p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.top-actions { display: flex; align-items: center; gap: 10px; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink-2);
  font-size: 13.5px;
  cursor: pointer;
  transition: background .16s, border-color .16s, color .16s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fd; border-color: #d4dced; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
a.btn { text-decoration: none; }

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .22);
}
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: #f2f5fa; }

.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }

.btn.big {
  width: 100%;
  height: 48px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 11px;
  margin-top: 4px;
}

.badge {
  min-width: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: #e9effc;
  color: var(--brand-ink);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 19px;
  text-align: center;
}

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .16s, color .16s;
}
.icon-btn:hover { background: #f1f4f9; color: var(--ink); }

/* ---------------- 主布局 ---------------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 388px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 700; }
.panel-note { font-size: 12.5px; color: var(--muted); }

/* ---------------- 表单 ---------------- */
.form-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 22px;
}

.field { margin-bottom: 17px; }

.label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.req { color: var(--danger); font-weight: 700; }
.opt { color: var(--muted); font-weight: 400; font-size: 12px; }

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  color: var(--ink);
  font-size: 14px;
  outline: none;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.input::placeholder { color: #a3aec2; }
.input:focus {
  border-color: #9db8f5;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea.input { resize: vertical; min-height: 74px; line-height: 1.6; }

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7992' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
  max-height: 92px;
  overflow-y: auto;
  padding-right: 2px;
}
.chip {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: #b6c9f2; background: #f5f8ff; color: var(--brand-ink); }

/* 课件类型卡片 */
.type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.type-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: all .16s;
}
.type-card:hover { border-color: #c6d4ef; background: #fafcff; }
.type-card .tc-icon { font-size: 18px; line-height: 1.2; }
.type-card .tc-name { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.type-card .tc-desc { font-size: 11.5px; color: var(--muted); }
.type-card.active {
  border-color: var(--brand);
  background: #f2f7ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}
.type-card.active .tc-name { color: var(--brand-ink); }

/* 风格分段 */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: #f1f4f9;
}
.seg button {
  flex: 1;
  padding: 7px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: all .16s;
}
.seg button:hover { color: var(--ink-2); }
.seg button.active {
  background: #fff;
  color: var(--brand-ink);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(23, 43, 77, .1);
}

.hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------------- 预览区 ---------------- */
.preview-panel { position: relative; }

.preview-head {
  flex-wrap: wrap;
  padding: 10px 14px;
  min-height: 56px;
}
.pv-title {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}
.pv-sub {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.pv-tools { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 9px;
  background: #f1f4f9;
}
.tabs button {
  padding: 5px 13px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: all .16s;
}
.tabs button.active {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(23, 43, 77, .12);
}

.preview-body {
  flex: 1;
  min-height: 0;
  position: relative;
  background-color: #eef1f7;
  background-image: radial-gradient(#dde3ee 1px, transparent 1px);
  background-size: 18px 18px;
}

.state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  gap: 9px;
}
.state h3 { margin: 4px 0 0; font-size: 17.5px; font-weight: 700; }
.state > p {
  margin: 0;
  max-width: 440px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.75;
}

.empty-icon { color: #b3c0d7; margin-bottom: 2px; }
.empty-icon.danger { color: #e2a3a3; }

.empty-points {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 12px;
}
.empty-points span {
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

/* 生成中 */
.generating .gen-ring {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 3px solid #dbe5f5;
  border-top-color: var(--brand);
  border-right-color: var(--brand-2);
  animation: spin 1s linear infinite;
  margin-bottom: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gen-topic {
  font-size: 13.5px;
  color: var(--ink-2);
  max-width: 460px;
  overflow-wrap: anywhere;
}

.gen-bar {
  width: min(440px, 82%);
  height: 6px;
  margin: 10px 0 2px;
  border-radius: 999px;
  background: #e4eaf4;
  overflow: hidden;
}
.gen-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #0ea5e9);
  transition: width .5s ease;
}

.gen-meta {
  display: flex;
  gap: 20px;
  font-size: 12.5px;
  color: var(--muted);
}

.gen-tip {
  margin: 4px 0 10px !important;
  font-size: 13px !important;
  color: #5b6b88 !important;
}

/* 结果 */
.state.result { padding: 0; display: block; }
.state.result iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.state.result pre {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 18px 20px;
  overflow: auto;
  background: #0f172a;
  color: #d7e3f7;
  font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.error { background: #fff; }
#error-text { color: var(--ink-2); overflow-wrap: anywhere; }

/* ---------------- 抽屉 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .35);
  z-index: 55;
  opacity: 1;
  transition: opacity .25s;
}

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  display: flex;
  flex-direction: column;
  background: #fff;
  z-index: 60;
  transform: translateX(102%);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
  box-shadow: -24px 0 60px rgba(15, 23, 42, .16);
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.drawer-head h2 { margin: 0; font-size: 15.5px; font-weight: 700; }

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafd;
}

.lib-empty {
  margin: auto;
  padding: 40px 0;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.lib-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .16s, box-shadow .16s, transform .06s;
}
.lib-item:hover { border-color: #c2d2f0; box-shadow: 0 4px 14px rgba(23, 43, 77, .07); }
.lib-item:active { transform: scale(.995); }

.lib-title { font-size: 13.8px; font-weight: 600; overflow-wrap: anywhere; }
.lib-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}
.lib-actions { display: flex; gap: 6px; margin-top: 9px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(10px);
  padding: 10px 18px;
  border-radius: 10px;
  background: #1b2436;
  color: #fff;
  font-size: 13.5px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  max-width: 84vw;
  text-align: center;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #b02a2a; }
.toast.ok { background: #0d7a55; }

/* ---------------- 滚动条 ---------------- */
.form-scroll::-webkit-scrollbar,
.drawer-body::-webkit-scrollbar,
.chips::-webkit-scrollbar,
pre::-webkit-scrollbar { width: 9px; height: 9px; }
.form-scroll::-webkit-scrollbar-thumb,
.drawer-body::-webkit-scrollbar-thumb,
.chips::-webkit-scrollbar-thumb,
pre::-webkit-scrollbar-thumb {
  background: #cfd8e6;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 980px) {
  body { overflow: auto; display: block; height: auto; }
  .topbar { position: sticky; top: 0; }
  .layout {
    display: block;
    padding: 12px;
  }
  .panel { margin-bottom: 14px; }
  .form-scroll { max-height: none; overflow: visible; }
  .preview-panel { height: 72vh; min-height: 460px; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 14px; }
  .brand-text p { display: none; }
  .layout { padding: 10px; gap: 10px; }
  .type-grid { grid-template-columns: 1fr; }
  .seg { flex-wrap: wrap; }
  .seg button { flex: 1 0 40%; }
}
