/* ============================================================
   教学工作台 v4 · 自托管版
   作者：WorkBuddy  |  2026-10-01
   数据层：Supabase（多端实时同步）
   AI 层：自建后端代理（Key 不落前端）
   ============================================================ */

:root {
  --bg:        #F7F7F5;
  --surface:   #FFFFFF;
  --border:    #E4E4E0;
  --text:      #1F1F1E;
  --text2:     #6B6B67;
  --text3:     #9A9A95;
  --blue:      #2563EB;
  --blue-bg:   #EFF4FF;
  --green:     #15803D;
  --green-bg:  #F0FDF4;
  --amber:     #B45309;
  --amber-bg:  #FFFBEB;
  --red:       #B91C1C;
  --red-bg:    #FEF2F2;
  --purple:    #6D28D9;
  --purple-bg: #F5F3FF;
  --radius:    10px;
  --radius-lg: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* ---------- 登录页 ---------- */
#login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px 36px;
  width: 100%; max-width: 400px;
}
.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.login-card p.sub { color: var(--text2); font-size: 13px; margin-bottom: 28px; }
.login-card label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px; outline: none;
  transition: border-color .15s;
}
.login-card input:focus { border-color: var(--blue); }
.btn-primary {
  width: 100%; padding: 12px; background: var(--blue); color: #fff;
  border-radius: var(--radius); font-weight: 500;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .9; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.login-msg { margin-top: 16px; font-size: 13px; line-height: 1.6; }
.login-msg.ok  { color: var(--green); }
.login-msg.err { color: var(--red); }

/* ---------- 主界面 ---------- */
#app { display: none; }
#app.ready { display: block; }

header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
header h1 { font-size: 16px; font-weight: 600; }
header .spacer { flex: 1; }
header .user { font-size: 12px; color: var(--text3); }
.icon-btn {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); font-size: 13px; transition: all .15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

nav.tabs {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; display: flex; gap: 4px; overflow-x: auto;
  position: sticky; top: 57px; z-index: 49;
}
nav.tabs button {
  padding: 12px 16px; color: var(--text2); font-size: 13px;
  border-bottom: 2px solid transparent; white-space: nowrap;
  transition: all .15s;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 500; }

main { padding: 24px; max-width: 1200px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.card h3 { font-size: 14px; font-weight: 500; margin-bottom: 10px; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ---------- 教案卡片 ---------- */
.plan-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; cursor: pointer;
  transition: all .15s; position: relative;
}
.plan-card:hover { border-color: var(--blue); transform: translateY(-1px); }
.plan-card .code {
  font-size: 11px; color: var(--text3); font-family: ui-monospace, monospace;
  margin-bottom: 6px;
}
.plan-card .title { font-size: 15px; font-weight: 500; margin-bottom: 8px; }
.plan-card .ppt { font-size: 12px; color: var(--text2); margin-bottom: 10px; }
.plan-card .meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; }
.plan-card .stats { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; gap: 16px; font-size: 11px; color: var(--text3); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 11px; font-weight: 500;
}
.badge.draft    { background: var(--amber-bg);  color: var(--amber); }
.badge.active   { background: var(--green-bg);  color: var(--green); }
.badge.archived { background: var(--bg);        color: var(--text3); }
.badge.grade    { background: var(--blue-bg);   color: var(--blue); }
.badge.know     { background: var(--purple-bg); color: var(--purple);
  font-family: ui-monospace, monospace; font-size: 10px; }

/* ---------- 工具条 ---------- */
.toolbar {
  display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center;
}
.toolbar input[type=text], .toolbar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  outline: none; background: var(--surface);
}
.toolbar input[type=text] { flex: 1; min-width: 180px; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--blue); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; outline: none; background: var(--surface);
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); }
.field textarea { resize: vertical; min-height: 100px; line-height: 1.7; }
.field .hint { font-size: 11px; color: var(--text3); margin-top: 4px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35);
  z-index: 100; padding: 24px; overflow-y: auto;
}
.modal-mask.open { display: flex; align-items: flex-start; justify-content: center; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 640px; margin: auto; padding: 26px;
}
.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.btn-ghost {
  padding: 10px 20px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); transition: all .15s;
}
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 8px; }

/* ---------- 空状态 / 加载 ---------- */
.empty {
  text-align: center; padding: 48px 20px; color: var(--text3); font-size: 13px;
}
.empty .big { font-size: 15px; color: var(--text2); margin-bottom: 6px; }
.loading { text-align: center; padding: 40px; color: var(--text3); font-size: 13px; }

/* ---------- 提示 ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1F1F1E; color: #fff; padding: 11px 20px; border-radius: 8px;
  font-size: 13px; z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--red); }

/* ---------- 教案详情 ---------- */
.detail-section { margin-bottom: 20px; }
.detail-section h3 { font-size: 13px; color: var(--text2); margin-bottom: 8px;
  text-transform: none; font-weight: 500; }
.know-list { display: flex; gap: 6px; flex-wrap: wrap; }
.md-body {
  background: var(--bg); border-radius: 8px; padding: 14px;
  font-size: 13px; line-height: 1.8; white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  max-height: 400px; overflow-y: auto;
}
.timeline { border-left: 2px solid var(--border); padding-left: 14px; }
.timeline-item { margin-bottom: 12px; font-size: 12px; }
.timeline-item .date { color: var(--text3); font-family: ui-monospace, monospace; }

/* ---------- AI 区块 ---------- */
.ai-box {
  background: var(--purple-bg); border: 1px solid #DDD6FE;
  border-radius: var(--radius); padding: 16px; margin-top: 14px;
}
.ai-box h4 { font-size: 13px; color: var(--purple); margin-bottom: 10px; font-weight: 500; }
.ai-result { font-size: 13px; line-height: 1.8; white-space: pre-wrap; }

@media (max-width: 640px) {
  main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  header { padding: 12px 16px; }
  nav.tabs { padding: 0 16px; }
}

/* ---------- 演示模式标记 ---------- */
.demo-flag a { text-decoration: underline; }
.demo-ribbon {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  background: var(--amber); color: #fff; font-size: 11px;
  padding: 3px 14px; border-radius: 0 0 8px 8px; z-index: 300;
}

/* ---------- 列表 / 表格 ---------- */
.info-row {
  display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 12px; color: var(--text2);
}
.info-row b { color: var(--text); font-weight: 500; }

/* 小程序式窄屏适配：Tab 横向滚动不换行 */
@media (max-width: 640px) {
  nav.tabs { -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav.tabs::-webkit-scrollbar { display: none; }
  .plan-card .title { font-size: 14px; }
  .modal { padding: 20px; }
}

