/* ============================================================
 * DDL 管家 · 样式
 * 设计原则：不用任何外部字体/图标库（离线可跑、答辩现场不联网也不裂）
 * ============================================================ */

:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f4f6fa;
  --card: #ffffff;
  --brand: #2563eb;
  --brand-soft: #eff4ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --ok: #059669;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .18);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(120deg, #0b1220 0%, #16233d 55%, #1e3a8a 100%);
  color: #fff;
}

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

.logo {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 11px;
  font-weight: 800; font-size: 13px; letter-spacing: .5px;
  background: linear-gradient(140deg, #3b82f6, #8b5cf6);
  box-shadow: 0 6px 16px -6px rgba(59, 130, 246, .9);
}

.brand h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.brand p { margin: 1px 0 0; font-size: 12px; color: #9fb0cc; }

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

.semester {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: #9fb0cc;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 5px 9px;
}

.semester input {
  background: transparent; border: 0; color: #fff;
  font-size: 12px; width: 112px; padding: 0;
  color-scheme: dark;
}

/* ---------------- 按钮 ---------------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 6px 16px -8px rgba(37, 99, 235, .9);
}
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost {
  background: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .16);
  color: #dbe6f7;
}
.btn.ghost:hover { background: rgba(255, 255, 255, .16); }
.btn.wide { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.linkbtn {
  border: 0; background: none; color: var(--brand);
  cursor: pointer; padding: 0; font-size: 13px;
}

/* ---------------- 主区 ---------------- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 372px minmax(320px, 1fr) 430px;
  gap: 14px;
  padding: 14px 20px 8px;
  min-height: 0;
  overflow: hidden;
}

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

.panel-head {
  flex: 0 0 auto;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .3px; }
.panel-head .hint { font-size: 11px; color: var(--muted); }
.panel-head .count {
  font-size: 11px; color: var(--muted);
  background: var(--brand-soft); color: #1d4ed8;
  border-radius: 999px; padding: 2px 8px; font-weight: 600;
}

/* ---------------- 输入面板 ---------------- */
.input-panel { padding-bottom: 12px; }
.input-panel textarea {
  flex: 1 1 auto;
  margin: 12px 14px 0;
  min-height: 150px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.75;
  background: #fbfcfe;
  outline: none;
  transition: .15s;
}
.input-panel textarea:focus { border-color: #93b4fb; background: #fff; box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }

.dropzone {
  margin: 8px 14px 0;
  border: 1px dashed #cdd8e8;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
  transition: .15s;
}
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); }

.row { display: flex; gap: 8px; padding: 10px 14px 0; }
.row .btn { flex: 1 1 auto; }

.samples { padding: 8px 14px 0; font-size: 11.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.samples button {
  border: 1px solid var(--line); background: #fbfcfe; border-radius: 999px;
  padding: 2px 9px; font-size: 11.5px; cursor: pointer; color: var(--ink-2);
}
.samples button:hover { border-color: #93b4fb; color: var(--brand); background: var(--brand-soft); }

/* AI 配置抽屉 */
.ai-box { margin: 8px 14px 0; border-top: 1px dashed var(--line); padding-top: 8px; }
.ai-box summary { font-size: 11.5px; color: var(--muted); cursor: pointer; }
.ai-box .fields { display: grid; gap: 6px; margin-top: 8px; }
.ai-box input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; font-size: 11.5px; background: #fbfcfe; outline: none;
}
.ai-box input:focus { border-color: #93b4fb; }
.ai-box .tip { font-size: 11px; color: var(--muted); margin: 6px 0 0; }

/* ---------------- 待办清单 ---------------- */
.list-panel .list { flex: 1 1 auto; overflow: auto; padding: 10px 12px 14px; display: grid; gap: 8px; align-content: start; }

.item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: .15s;
}
.item::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px;
  width: 4px; border-radius: 0 4px 4px 0; background: var(--brand);
  opacity: .85;
}
.item.soon::before { background: var(--warn); }
.item.overdue::before { background: var(--danger); }
.item:hover { border-color: #c7d7f5; box-shadow: 0 6px 18px -14px rgba(15, 23, 42, .5); }
.item.done { opacity: .55; background: #fafbfd; }
.item.done .item-title { text-decoration: line-through; }

.item-main { min-width: 0; }
.item-title {
  font-size: 13.5px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 5px; }

.tag {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: #f1f5f9; color: var(--ink-2); white-space: nowrap;
}
.tag.course { background: var(--brand-soft); color: #1d4ed8; }
.tag.type { background: #f5f3ff; color: #6d28d9; }
.tag.hot { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.tag.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.duedate { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.item-side { display: flex; align-items: center; gap: 4px; }
.iconbtn {
  border: 0; background: none; cursor: pointer; color: #94a3b8;
  width: 26px; height: 26px; border-radius: 7px; line-height: 1;
  display: grid; place-items: center; font-size: 13px;
}
.iconbtn:hover { background: #f1f5f9; color: var(--ink); }
.iconbtn.ok:hover { background: #ecfdf5; color: var(--ok); }
.iconbtn.del:hover { background: var(--danger-soft); color: var(--danger); }

.empty {
  text-align: center; color: var(--muted); font-size: 12.5px;
  padding: 40px 20px; line-height: 2;
}

/* ---------------- 日历 ---------------- */
.cal-panel .cal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.cal-head .ym { font-weight: 700; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.cal-head .nav { display: flex; gap: 4px; }

.cal-grid { padding: 8px 10px 12px; flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
/* minmax(0,1fr) 是关键：普通 1fr 的最小宽度是 auto，会被“不换行的长标题”撑破列宽 */
.cal-week, .cal-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-week { flex: 0 0 auto; }
.cal-days { flex: 1 1 auto; grid-auto-rows: minmax(52px, 1fr); min-height: 0; }
.cal-week span {
  text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0 6px;
}
.cal-day {
  min-height: 0;
  overflow: hidden;
  border: 1px solid #eef2f7;
  border-radius: 9px;
  padding: 3px 4px;
  background: #fff;
  display: flex; flex-direction: column; gap: 2px;
  transition: .12s;
}
.cal-day.out { background: #fafbfd; opacity: .45; }
.cal-day.today { border-color: #93b4fb; background: var(--brand-soft); }
.cal-day.today .dnum { color: var(--brand); font-weight: 800; }
.cal-day .dnum { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cal-chip {
  flex: 0 0 auto;
  height: 14px;
  line-height: 14px;
  max-width: 100%;
  font-size: 9.5px;
  padding: 0 3px;
  border-radius: 4px;
  background: #eef2ff; color: #3730a3;
  overflow: hidden; white-space: nowrap;
}
.cal-chip.soon { background: #fef3c7; color: #92400e; }
.cal-chip.overdue { background: #fee2e2; color: #991b1b; }
.cal-more { font-size: 9.5px; color: var(--muted); }

/* ---------------- 底部操作条 ---------------- */
.actionbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px -18px rgba(15, 23, 42, .5);
}
.stat { font-size: 12.5px; color: var(--muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stat b { color: var(--ink); }
.stat .alert {
  color: var(--danger); background: var(--danger-soft);
  padding: 1px 8px; border-radius: 999px; font-weight: 600;
}
.actionbar .spacer { flex: 1 1 auto; }

/* ---------------- 弹窗 ---------------- */
dialog {
  border: 0; border-radius: 16px; padding: 0;
  box-shadow: 0 24px 60px -20px rgba(15, 23, 42, .5);
  max-width: min(560px, 92vw);
  width: 100%;
}
dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.dlg-body { padding: 16px 18px; display: grid; gap: 10px; }
.dlg-body label { font-size: 11.5px; color: var(--muted); display: grid; gap: 4px; }
.dlg-body input, .dlg-body select {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  font-size: 13px; background: #fbfcfe; outline: none; width: 100%;
}
.dlg-body input:focus, .dlg-body select:focus { border-color: #93b4fb; background: #fff; }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
pre.ics {
  margin: 0; max-height: 50vh; overflow: auto;
  background: #0f172a; color: #cbd5e1;
  border-radius: 10px; padding: 12px;
  font: 11px/1.7 ui-monospace, Consolas, "Courier New", monospace;
  white-space: pre;
}

/* ---------------- 提示条 ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 74px; transform: translate(-50%, 12px);
  background: #0f172a; color: #fff; font-size: 12.5px;
  padding: 9px 16px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .22s;
  box-shadow: 0 12px 30px -14px rgba(0, 0, 0, .6);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 窄屏 ---------------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 320px 1fr; grid-template-rows: 1fr auto; overflow: auto; }
  .cal-panel { grid-column: 1 / -1; }
}
@media (max-width: 780px) {
  html { overflow-x: hidden; }
  html, body { height: auto; max-width: 100%; }
  body { display: block; overflow-x: hidden; }

  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .topbar > * { min-width: 0; }
  .top-actions { width: 100%; min-width: 0; }
  .top-actions > * { min-width: 0; }
  .semester { flex: 1 1 auto; white-space: nowrap; padding: 5px 8px; }
  .semester input { width: 100px; }

  /* 手机改成正常文档流：三块依次往下排，整页滚动 */
  .layout {
    display: flex; flex-direction: column; gap: 12px;
    padding: 12px; overflow: visible; height: auto; min-width: 0;
  }
  .layout > .panel { min-width: 0; max-width: 100%; }
  .panel { max-height: none; }
  .input-panel textarea { min-height: 130px; width: auto; max-width: 100%; margin: 12px 12px 0; }
  .samples, .row, .dropzone, .ai-box { margin-left: 12px; margin-right: 12px; }
  .row { padding-left: 0; padding-right: 0; }
  .samples { padding-left: 0; padding-right: 0; }
  .list-panel .list { max-height: 460px; }
  .cal-grid { min-height: 400px; }

  .actionbar {
    position: sticky; bottom: 0;
    flex-wrap: wrap; gap: 8px; padding: 8px 12px;
  }
  .actionbar .stat { flex: 1 1 100%; font-size: 12px; }
  .actionbar .spacer { display: none; }
  .actionbar .btn { flex: 1 1 auto; padding: 9px 6px; font-size: 12.5px; }

  dialog { max-width: 94vw; }
}