/* ===== 设计变量 ===== */
:root {
  --bg: #f5f3f7;
  --bg-soft: #faf9fb;
  --card: #ffffff;
  --primary: #7a6fa8;
  --primary-soft: #ece8f5;
  --primary-deep: #5f5587;
  --sage: #8fa88a;
  --sage-soft: #eef2ea;
  --coral: #e08a6e;
  --coral-soft: #faeae2;
  --text: #4a4658;
  --text-2: #8a8698;
  --text-3: #b5b1c0;
  --border: #e6e2ec;
  --danger: #d06a6a;
  --danger-soft: #f9e8e8;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --shadow: 0 2px 12px rgba(90, 80, 120, 0.06);
  --shadow-md: 0 8px 28px rgba(90, 80, 120, 0.12);
  --sidebar-w: 232px;
  --topbar-h: 56px;
  --bottombar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* 主题 */
[data-theme="default"] { --primary:#7a6fa8; --primary-soft:#ece8f5; --primary-deep:#5f5587; --sage:#8fa88a; --sage-soft:#eef2ea; --coral:#e08a6e; --coral-soft:#faeae2; }
[data-theme="sage"]    { --primary:#6f9a7f; --primary-soft:#e5f0e6; --primary-deep:#4f7a5f; --sage:#8fa88a; --sage-soft:#eef2ea; --coral:#e08a6e; --coral-soft:#faeae2; }
[data-theme="coral"]   { --primary:#d9856a; --primary-soft:#f9e9e1; --primary-deep:#b5654c; --sage:#8fa88a; --sage-soft:#eef2ea; --coral:#e08a6e; --coral-soft:#faeae2; }
[data-theme="blue"]    { --primary:#6a8fb8; --primary-soft:#e5edf6; --primary-deep:#4f7098; --sage:#8fa88a; --sage-soft:#eef2ea; --coral:#e08a6e; --coral-soft:#faeae2; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
a { color: var(--primary); text-decoration: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d8d3e0; border-radius: 4px; }

/* ===== 整体布局 ===== */
.app { min-height: 100vh; display: flex; }

/* ===== 顶部栏（移动端） ===== */
.topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  align-items: center; justify-content: space-between;
  padding: 0 12px;
}
.topbar-title { font-weight: 700; font-size: 16px; }

/* ===== 侧边栏 ===== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 60;
}
.brand { padding: 22px 20px 16px; display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px; flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.3; }
.brand-sub { font-size: 12px; color: var(--text-2); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name, .brand-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { flex: 1; overflow-y: auto; padding: 6px 12px; }
.nav-group { font-size: 11px; color: var(--text-3); padding: 14px 14px 6px; letter-spacing: 1px; }
.nav-group:first-child { padding-top: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px; margin-bottom: 4px;
  color: var(--text); font-size: 14px; width: 100%; text-align: left;
  transition: background .15s;
}
.nav-item:hover { background: var(--bg-soft); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-deep); font-weight: 600; }
.nav-item .nav-ico { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.avatar-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 12px; }
.avatar-btn:hover { background: var(--bg-soft); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--sage-soft); color: var(--sage);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.avatar-text { display: flex; flex-direction: column; text-align: left; min-width: 0; }
.avatar-name { font-weight: 600; font-size: 14px; }
.avatar-sub { font-size: 12px; color: var(--text-2); }

.sidebar-mask { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 55; }

/* ===== 主内容区 ===== */
.main { flex: 1; padding: 28px 32px 40px; max-width: 1280px; margin: 0 auto; width: 100%; }
.page-head { margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 700; }
.page-desc { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* ===== 卡片 ===== */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 16px 18px; }
.card-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); display: inline-block; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; font-size: 14px;
  background: var(--primary); color: #fff; transition: opacity .15s;
}
.btn:hover { opacity: .88; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--bg-soft); }
.btn.soft { background: var(--primary-soft); color: var(--primary-deep); }
.btn.text { background: transparent; color: var(--primary); padding: 4px 8px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; justify-content: center; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  color: var(--text);
}
.icon-btn:hover { background: var(--bg-soft); }

/* ===== 表单 ===== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field .req { color: var(--coral); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-soft); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { resize: vertical; min-height: 80px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* ===== 弹窗 ===== */
.modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(40,36,52,.4); pointer-events: auto; }
.modal {
  position: absolute; inset: 0; margin: auto;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  pointer-events: auto;
  background: var(--card); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-md);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-title { font-weight: 700; font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* ===== 首页布局 ===== */
.home-grid { display: grid; gap: 18px; }

/* 课表 */
.schedule-wrap { overflow-x: auto; }
.schedule { display: grid; grid-template-columns: 60px repeat(5, 1fr); gap: 6px; }
.schedule .corner { font-size: 12px; color: var(--text-3); }
.schedule .day-head {
  text-align: center; padding: 8px 4px; font-weight: 600; font-size: 13px;
  border-radius: 8px; color: var(--text-2);
}
.schedule .day-head.today { background: var(--primary); color: #fff; }
.schedule .period-label { font-size: 12px; color: var(--text-3); text-align: center; padding: 10px 4px; }
.schedule .cell { min-height: 58px; border-radius: 8px; padding: 2px; }
.schedule .cell.empty-cell { cursor: pointer; position: relative; transition: background .15s; display: flex; align-items: center; justify-content: center; }
.schedule .cell.empty-cell::after { content: "+"; color: var(--text-3); font-size: 16px; opacity: 0; transition: opacity .15s; }
.schedule .cell.empty-cell:hover { background: var(--bg-soft); }
.schedule .cell.empty-cell:hover::after { opacity: 1; }
.course {
  height: 100%; border-radius: 8px; padding: 6px 8px; cursor: pointer;
  background: var(--primary-soft); color: var(--primary-deep);
  display: flex; flex-direction: column; justify-content: center;
  font-size: 12px; transition: transform .12s;
}
.course:hover { transform: translateY(-1px); }
.course .c-name { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.course .c-class { color: var(--text-2); font-size: 11px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course.variant-green { background: var(--sage-soft); color: var(--sage); }
.course.variant-coral { background: var(--coral-soft); color: var(--coral); }

/* 待办 */
.todo-item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.todo-item:last-child { border-bottom: none; }
.todo-check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; transition: all .15s; }
.todo-check:hover { border-color: var(--primary); }
.todo-item.done .todo-check { background: var(--sage); border-color: var(--sage); }
.todo-item.done .todo-check::after { content: "✓"; color: #fff; font-size: 12px; display: flex; justify-content: center; line-height: 16px; }
.todo-main { flex: 1; min-width: 0; cursor: pointer; }
.todo-title { font-size: 14px; }
.todo-item.done .todo-title { color: var(--text-3); text-decoration: line-through; }
.todo-meta { font-size: 12px; color: var(--text-2); display: flex; gap: 8px; align-items: center; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 20px; }
.pill.high { background: var(--coral-soft); color: var(--coral); }
.pill.mid { background: #fdf3dd; color: #c79a4a; }
.pill.low { background: var(--sage-soft); color: var(--sage); }
.todo-ops { display: flex; gap: 2px; flex-shrink: 0; }
.todo-ops .icon-btn { width: 30px; height: 30px; font-size: 14px; }
.seg { display: flex; background: var(--bg-soft); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 14px; border-radius: 8px; font-size: 13px; color: var(--text-2); }
.seg button.active { background: var(--card); color: var(--primary-deep); font-weight: 600; box-shadow: var(--shadow); }

/* 校历 */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-title { font-weight: 600; font-size: 15px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: 11px; color: var(--text-3); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1; border-radius: 8px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 13px; position: relative; cursor: pointer; padding: 2px;
}
.cal-day:hover { background: var(--bg-soft); }
.cal-day.empty { cursor: default; }
.cal-day.today { background: var(--primary-soft); color: var(--primary-deep); font-weight: 600; }
.cal-day .cal-num { position: relative; line-height: 1.1; }
.cal-day .cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--coral); position: absolute; top: -2px; right: -7px; }
.cal-day .cal-lunar { font-size: 10px; color: var(--text-3); line-height: 1.1; margin-top: 2px; }
.cal-day.today .cal-lunar { color: var(--primary-deep); }
.cal-day.festival .cal-lunar { color: var(--coral); }

/* 工具 */
.tools-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tool-group-title { font-size: 12px; color: var(--text-2); margin: 4px 0 8px; }
.tool-group-title:not(:first-child) { margin-top: 14px; }
.tool-item {
  border: 1px solid var(--border); border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer;
  transition: transform .12s, box-shadow .12s; position: relative;
}
.tool-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.tool-logo {
  width: 44px; height: 44px; border-radius: 12px; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
}
.tool-name { font-size: 13px; font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.tool-del { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--bg-soft); color: var(--text-2); font-size: 12px; display: none; align-items: center; justify-content: center; }
.tool-item:hover .tool-del { display: flex; }

/* 座位排布 */
.seat-grid { display: grid; gap: 6px; max-width: 620px; }
.seat {
  aspect-ratio: 1; border-radius: 8px; background: var(--bg-soft);
  border: 1px dashed var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-3); cursor: pointer; overflow: hidden;
  transition: background .12s;
}
.seat:hover { background: var(--primary-soft); color: var(--primary-deep); }
.seat.occupied { background: var(--primary-soft); color: var(--primary-deep); border-style: solid; border-color: var(--primary); font-weight: 600; }

/* 空状态 */
.empty { text-align: center; padding: 28px 16px; color: var(--text-3); font-size: 13px; }
.empty .empty-ico { font-size: 30px; margin-bottom: 8px; }

/* 统计卡片（成绩分析） */
.stat-box { background: var(--bg-soft); border-radius: 10px; padding: 14px 10px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 700; color: var(--primary-deep); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-2); margin-top: 4px; }

/* ===== 列表通用 ===== */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; font-size: 14px; }
.list-sub { font-size: 12px; color: var(--text-2); }
.list-ops { display: flex; gap: 2px; flex-shrink: 0; }

/* ===== 表格 ===== */
.table-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; padding: 10px 12px; background: var(--bg-soft); color: var(--text-2); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 10px 12px; border-top: 1px solid var(--border); white-space: nowrap; }
.tbl tr:hover td { background: var(--bg-soft); }

/* ===== 底部导航（移动端） ===== */
.bottombar {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  align-items: stretch;
}
.bottombar .bb-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--text-2);
}
.bottombar .bb-item .bb-ico { font-size: 20px; }
.bottombar .bb-item.active { color: var(--primary-deep); font-weight: 600; }

/* ===== 本地助手 ===== */
.assistant-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 26px;
  box-shadow: var(--shadow-md); display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.assistant-fab:hover { transform: scale(1.06); }
.assistant-panel {
  position: fixed; right: 20px; bottom: 84px; z-index: 95;
  width: min(360px, calc(100vw - 24px)); max-height: 480px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); display: flex; flex-direction: column; overflow: hidden;
}
.assistant-panel[hidden] { display: none; }
.assistant-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.assistant-avatar { font-size: 20px; }
.assistant-title { font-weight: 700; font-size: 14px; flex: 1; }
.assistant-body { padding: 12px 14px; overflow-y: auto; }
.assistant-result { margin-top: 10px; }
.assistant-group { font-size: 11px; color: var(--text-3); margin: 10px 0 4px; }
.assistant-item { padding: 8px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.assistant-item:hover { background: var(--bg-soft); }
.assistant-item .a-sub { font-size: 11px; color: var(--text-2); }
.assistant-empty { text-align: center; color: var(--text-3); font-size: 13px; padding: 20px 0; }

/* ===== 初始化向导 ===== */
.wizard { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px; }
.wizard[hidden] { display: none; }
.wizard-card { width: min(520px, 100%); background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 28px; }
.wizard-steps { display: flex; gap: 6px; margin-bottom: 20px; }
.wizard-steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--border); }
.wizard-steps span.on { background: var(--primary); }
.wizard-title { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.wizard-desc { font-size: 13px; color: var(--text-2); margin-bottom: 20px; }

/* ===== 提示条 ===== */
.toast-root { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-md); animation: pop .2s ease; }

/* ===== 响应式 ===== */
@media (min-width: 1200px) {
  /* 首页桌面布局：课表满宽，下方左列(待办/效率表) + 右列(校历/工具) */
  .home-grid { grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); align-items: start; }
  .home-grid > .card:nth-child(1) { grid-column: 1 / -1; }
  .home-grid > .card:nth-child(2) { grid-column: 1; }
  .home-grid > .card:nth-child(3) { grid-column: 2; }
  .home-grid > .card:nth-child(4) { grid-column: 2; }
  .home-grid > .card:nth-child(5) { grid-column: 1; }
}

@media (max-width: 1199px) {
  .main { padding: 24px 20px 80px; }
}

@media (max-width: 767px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%);
    transition: transform .25s ease; width: 260px; min-width: 260px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask.show { display: block; }
  .main { padding: calc(var(--topbar-h) + 16px) 14px calc(var(--bottombar-h) + 24px); }
  .bottombar { display: flex; }
  .page-title { font-size: 19px; }
  .tools-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .tool-item { padding: 10px 6px; }
  .tool-logo { width: 38px; height: 38px; font-size: 15px; }
  .modal { width: calc(100vw - 20px); max-height: calc(100vh - 24px); }
  .field-row { flex-direction: column; gap: 0; }
  .home-grid { gap: 14px; }
  .schedule { min-width: 720px; }
}
@media (max-width: 480px) {
  .tools-grid { grid-template-columns: repeat(4, 1fr); }
}
