:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e6f0;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #3b6cf6;
  --primary-dark: #2c55cc;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #3b6cf6, #7aa2ff);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.sub, .hint { color: var(--muted); font-size: 12px; margin: 0; }

.user-box { display: flex; align-items: center; gap: 10px; }
.user-label { color: var(--muted); font-size: 13px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 18px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs button {
  border: none;
  background: transparent;
  padding: 9px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); background: #f0f3fb; }
.tabs button.active { color: var(--primary); background: #eef2ff; font-weight: 600; }

.app { padding: 18px 22px 60px; max-width: 1400px; margin: 0 auto; }
.view.hidden, .hidden { display: none !important; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .value small { font-size: 12px; color: var(--muted); font-weight: 400; }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--success); }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { background: #f5f7fd; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f3c2c2; }
.btn-danger:hover { background: #fdf1f1; }
.btn-ghost { color: var(--muted); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

input[type="text"], input[type="password"], input[type="number"], input[type="file"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, Consolas, monospace; }
label { display: block; font-size: 13px; margin-bottom: 10px; }
label > span { display: block; color: var(--muted); margin-bottom: 4px; font-size: 12px; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
label.inline input { width: auto; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.toolbar .field { min-width: 130px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; background: #fafbff; position: sticky; top: 0; }
tbody tr:hover { background: #fafbff; }
.table-wrap { overflow: auto; max-height: 62vh; border: 1px solid var(--border); border-radius: 8px; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2ff;
  color: var(--primary);
  margin-right: 4px;
}
.tag.ok { background: #e7f8ee; color: var(--success); }
.tag.warn { background: #fdf3e3; color: var(--warn); }
.tag.danger { background: #fdeeee; color: var(--danger); }
.tag.muted { background: #f1f2f6; color: var(--muted); }

.dropzone {
  border: 2px dashed #c7d2fe;
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  color: var(--muted);
  background: #f8faff;
  cursor: pointer;
}
.dropzone.dragover { border-color: var(--primary); background: #eef2ff; color: var(--primary); }

.toast-area { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: #1f2430; color: #fff; padding: 10px 14px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 380px; word-break: break-all;
}
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

.gate { position: fixed; inset: 0; background: rgba(24, 30, 46, 0.45); display: grid; place-items: center; z-index: 80; padding: 20px; }
.gate-card { background: #fff; border-radius: 14px; padding: 24px; width: min(420px, 100%); box-shadow: var(--shadow); }
.gate-actions { display: flex; gap: 10px; margin-bottom: 8px; }

.modal { position: fixed; inset: 0; background: rgba(24, 30, 46, 0.45); display: grid; place-items: center; z-index: 70; padding: 20px; }
.modal-body { background: #fff; border-radius: 14px; padding: 20px; width: min(1080px, 100%); max-height: 88vh; overflow: auto; position: relative; }
.modal-close { position: absolute; top: 10px; right: 12px; border: none; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); }

.timetable { width: 100%; border-collapse: collapse; font-size: 12px; }
.timetable th, .timetable td { border: 1px solid var(--border); padding: 4px 6px; }
.timetable td.slot { background: #fafbff; color: var(--muted); text-align: center; white-space: nowrap; }
.timetable .course { background: #eef2ff; border-radius: 6px; padding: 4px 6px; margin: 2px 0; }
.timetable .course b { display: block; font-weight: 600; }
.timetable .course small { color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 22px; font-size: 13px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- 空闲表网格 */

.freegrid-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 8px; }
table.freegrid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12px; table-layout: fixed; }
table.freegrid th, table.freegrid td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px; }
table.freegrid thead th {
  position: sticky; top: 0; z-index: 6; background: #fafbff; text-align: center;
  font-weight: 600; color: var(--text); white-space: nowrap;
}
table.freegrid .fg-section {
  width: 96px; background: #fafbff; color: var(--muted); text-align: center; white-space: nowrap;
  position: sticky; left: 0; z-index: 5;
}
table.freegrid .fg-section b { display: block; color: var(--text); font-size: 12px; }
table.freegrid tr.fg-allday .fg-section { background: #eef2ff; color: var(--primary); font-weight: 600; }
table.freegrid tr.fg-allday td { background: #f7f9ff; }

.fg-cell { position: relative; vertical-align: top; cursor: pointer; height: 62px; }
.fg-cell:hover { z-index: 20; }
.fg-cell .fg-count { font-size: 16px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.fg-cell .fg-count small { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.fg-cell .fg-names { color: var(--muted); font-size: 11px; margin-top: 2px; word-break: break-all; }
.fg-cell.fg-zero .fg-count { color: #b9bfcc; font-weight: 400; }
.fg-cell.fg-hot { background: #f2f7ff; }

.fg-hover {
  display: none; position: absolute; left: 0; top: 100%; z-index: 40;
  min-width: 240px; max-width: 360px; max-height: 320px; overflow: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.16); padding: 10px 12px; text-align: left;
}
.fg-cell:hover .fg-hover { display: block; }
.fg-hover-title { font-weight: 600; margin-bottom: 6px; color: var(--text); }
.fg-hover-title small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.fg-hover .tag { margin: 0 4px 4px 0; }
.fg-cell.fg-zero .fg-hover { display: none; }

.fg-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
.fg-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }

/* ---------------------------------------------------------------- 周总览矩阵 */

.matrix-wrap { overflow: auto; max-height: 68vh; border: 1px solid var(--border); border-radius: 8px; }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 12px; white-space: nowrap; }
table.matrix th, table.matrix td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px 6px; text-align: center; }
table.matrix thead th {
  position: sticky; top: 0; z-index: 6; background: #fafbff; color: var(--text); font-weight: 600;
  min-width: 42px; cursor: pointer;
}
table.matrix thead th.mx-name, table.matrix thead th.mx-total { cursor: default; }
table.matrix th.mx-week:hover { background: #eef2ff; color: var(--primary); }
table.matrix td.mx-name, table.matrix th.mx-name {
  position: sticky; left: 0; z-index: 5; background: #fff; text-align: left; min-width: 128px;
  border-right: 1px solid var(--border);
}
table.matrix thead th.mx-name { z-index: 7; background: #fafbff; }
table.matrix td.mx-name { cursor: pointer; }
table.matrix td.mx-cell { cursor: pointer; }
table.matrix td.mx-cell:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
table.matrix td.mx-busy { background: #eef2ff; color: var(--primary); font-weight: 600; }
table.matrix td.mx-free { background: #f6f7fa; color: #b3b9c7; font-weight: 600; }
table.matrix td.mx-unknown { background: repeating-linear-gradient(45deg, #fdf6ea, #fdf6ea 6px, #fbf0dd 6px, #fbf0dd 12px); color: var(--warn); font-weight: 700; }
table.matrix td.mx-total { background: #fafbff; color: var(--muted); }
table.matrix tbody tr:hover td.mx-name { background: #f7f9ff; }



.toolbar .field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
