/* =====================================================================
 * AI 智能排座（AI Smart Seating）· spimes 主题独立页面
 * 全部样式以 .ais-app 作用域隔离，不影响主题其他部分
 * ===================================================================== */

.ais-app {
  --ais-primary: #4f6ef7;
  --ais-primary-2: #6366f1;
  --ais-primary-3: #3b82f6;
  --ais-bg: #ffffff;
  --ais-bg-soft: #f6f8fd;
  --ais-border: #e2e8f0;
  --ais-text: #1e293b;
  --ais-text-2: #64748b;
  --ais-danger: #ef4444;
  --ais-ok: #10b981;
  --ais-warn: #f59e0b;
  --ais-cell-w: 96px;
  --ais-cell-h: 72px;
  --ais-radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', Roboto, sans-serif;
  color: var(--ais-text);
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 8px 60px;
  font-size: 14px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

.ais-app *,
.ais-app *::before,
.ais-app *::after { box-sizing: border-box; }

.ais-app p { margin: 0 0 8px; }
.ais-app h2, .ais-app h3, .ais-app h4 { margin: 0; font-weight: 600; color: var(--ais-text); }

/* ---------- 顶部标题栏 ---------- */
.ais-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.ais-head .ais-logo {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px;
  box-shadow: 0 8px 20px -8px rgba(99, 102, 241, .6);
}
.ais-head .ais-tt { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.ais-head .ais-sub { color: var(--ais-text-2); font-size: 12.5px; margin-top: 1px; }

/* ---------- 顶部统计 ---------- */
.ais-headstats { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.ais-stat {
  background: var(--ais-bg); border: 1px solid var(--ais-border); border-radius: 10px;
  padding: 4px 12px; font-size: 12px; color: var(--ais-text-2);
}
.ais-stat b { color: var(--ais-primary); font-size: 15px; margin-right: 3px; }

/* ---------- Tabs ---------- */
.ais-tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px;
  background: var(--ais-bg); border: 1px solid var(--ais-border);
  padding: 6px; border-radius: 14px;
  position: sticky; top: 0; z-index: 30;
}
.ais-tab {
  border: none; background: transparent; cursor: pointer;
  padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  color: var(--ais-text-2); font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .18s ease; white-space: nowrap;
}
.ais-tab:hover { background: var(--ais-bg-soft); color: var(--ais-text); }
.ais-tab.active {
  background: linear-gradient(135deg, var(--ais-primary-2), var(--ais-primary-3));
  color: #fff; box-shadow: 0 6px 16px -6px rgba(99, 102, 241, .55);
}
.ais-tab .ais-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ais-warn); display: none; }
.ais-tab.has-warn .ais-dot { display: inline-block; }

/* ---------- 卡片 ---------- */
.ais-card {
  background: var(--ais-bg); border: 1px solid var(--ais-border);
  border-radius: var(--ais-radius); padding: 18px 20px; margin-bottom: 14px;
}
.ais-card > .ais-card-t {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 15px; font-weight: 600; margin-bottom: 12px;
}
.ais-card > .ais-card-t .ais-hint { font-weight: 400; font-size: 12px; color: var(--ais-text-2); }
.ais-card-t .ais-sp { flex: 1; }
.ais-hint { color: var(--ais-text-2); font-size: 12.5px; }
.ais-mini { color: var(--ais-text-2); font-size: 12px; }

/* ---------- 按钮 ---------- */
.ais-btn {
  border: 1px solid var(--ais-border); background: var(--ais-bg); color: var(--ais-text);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 13px; font-family: inherit;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  transition: all .16s ease; text-decoration: none; line-height: 1.4;
}
.ais-btn:hover { border-color: var(--ais-primary); color: var(--ais-primary); }
.ais-btn:active { transform: scale(.97); }
.ais-btn:disabled { opacity: .45; cursor: not-allowed; }
.ais-btn:disabled:hover { border-color: var(--ais-border); color: var(--ais-text); }
.ais-btn.pri {
  background: linear-gradient(135deg, var(--ais-primary-2), var(--ais-primary-3));
  border: none; color: #fff; font-weight: 500;
  box-shadow: 0 6px 16px -6px rgba(99, 102, 241, .55);
}
.ais-btn.pri:hover { filter: brightness(1.06); color: #fff; }
.ais-btn.danger { color: var(--ais-danger); border-color: #fecaca; }
.ais-btn.danger:hover { background: #fef2f2; border-color: var(--ais-danger); }
.ais-btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.ais-btn.lg { padding: 11px 22px; font-size: 15px; border-radius: 11px; }
.ais-btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 表单 ---------- */
.ais-app input[type="text"], .ais-app input[type="number"], .ais-app input[type="password"],
.ais-app select, .ais-app textarea {
  font-family: inherit; font-size: 13px; color: var(--ais-text);
  background: var(--ais-bg); border: 1px solid var(--ais-border); border-radius: 8px;
  padding: 7px 10px; outline: none; transition: border .15s ease, box-shadow .15s ease;
  max-width: 100%;
}
.ais-app input:focus, .ais-app select:focus, .ais-app textarea:focus {
  border-color: var(--ais-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .13);
}
.ais-app textarea { resize: vertical; width: 100%; }
.ais-app label.ais-fl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ais-text-2); }
.ais-frow { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.ais-app input[type="checkbox"], .ais-app input[type="radio"] { accent-color: var(--ais-primary); cursor: pointer; }
.ais-app input[type="file"] { font-size: 12px; color: var(--ais-text-2); }

/* ---------- 班级 chips ---------- */
.ais-classbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.ais-class {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--ais-border); background: var(--ais-bg);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 13px;
  transition: all .15s ease; font-family: inherit; color: var(--ais-text);
}
.ais-class:hover { border-color: var(--ais-primary); }
.ais-class.active {
  background: linear-gradient(135deg, var(--ais-primary-2), var(--ais-primary-3));
  border-color: transparent; color: #fff; font-weight: 500;
}
.ais-class .cls-del {
  display: inline-flex; width: 16px; height: 16px; border-radius: 50%;
  align-items: center; justify-content: center; font-size: 11px;
  background: rgba(0,0,0,.08); cursor: pointer;
}
.ais-class.active .cls-del { background: rgba(255,255,255,.25); }

/* ---------- 表格 ---------- */
.ais-app table.ais-table {
  width: 100%; border-collapse: collapse; font-size: 13px; background: var(--ais-bg);
}
.ais-table th, .ais-table td {
  padding: 7px 8px; border-bottom: 1px solid var(--ais-border); text-align: left; vertical-align: middle;
}
.ais-table th { color: var(--ais-text-2); font-weight: 500; font-size: 12px; background: var(--ais-bg-soft); position: sticky; top: 0; }
.ais-table tr:hover td { background: rgba(99, 102, 241, .04); }
.ais-table .td-inp { width: 100%; min-width: 0; }
.ais-table td input[type="number"] { width: 76px; }
.ais-table td select { padding: 4px 6px; }
.ais-tablewrap { max-height: 480px; overflow: auto; border: 1px solid var(--ais-border); border-radius: 10px; }

/* ---------- chips ---------- */
.ais-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--ais-bg-soft); border: 1px solid var(--ais-border);
  border-radius: 999px; padding: 4px 12px; font-size: 12.5px; cursor: pointer;
  transition: all .15s ease; font-family: inherit; color: var(--ais-text);
}
.ais-chip:hover { border-color: var(--ais-primary); color: var(--ais-primary); background: rgba(99,102,241,.06); }
.ais-chiplist { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 约束列表 ---------- */
.ais-cst {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--ais-border); border-radius: 10px; margin-bottom: 6px;
  background: var(--ais-bg); font-size: 13px;
}
.ais-cst .ico { font-size: 15px; }
.ais-cst .del { margin-left: auto; cursor: pointer; color: var(--ais-text-2); border: none; background: none; font-size: 15px; font-family: inherit; padding: 2px 6px; border-radius: 6px; }
.ais-cst .del:hover { color: var(--ais-danger); background: #fef2f2; }

/* ---------- 教室网格 ---------- */
.ais-gridwrap { overflow-x: auto; padding: 6px 2px 12px; }
.ais-stage { display: inline-block; min-width: 100%; }
.ais-podium {
  margin: 0 auto 14px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  color: #fff; display: flex; align-items: center; justify-content: center;
  letter-spacing: 12px; font-size: 15px; font-weight: 600; text-indent: 12px;
  box-shadow: 0 8px 18px -8px rgba(99, 102, 241, .6);
  width: 56%;
}
.ais-grid {
  display: grid; gap: 8px;
  grid-template-columns: 40px;
}
.ais-colhead {
  display: flex; align-items: flex-end; justify-content: center;
  font-size: 11px; color: var(--ais-text-2); height: 18px;
}
.ais-rowhead {
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; color: var(--ais-text-2); white-space: nowrap;
}
.ais-seat {
  width: var(--ais-cell-w); height: var(--ais-cell-h);
  border-radius: 10px; border: 1.5px dashed #cbd5e1; background: var(--ais-bg-soft);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; position: relative; cursor: pointer; user-select: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .12s ease, background .15s ease;
  font-size: 13px; overflow: hidden; padding: 4px 5px; text-align: center;
}
.ais-seat:hover { border-color: var(--ais-primary); }
.ais-seat .seat-name { font-weight: 600; font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ais-seat .seat-sub { font-size: 10.5px; color: var(--ais-text-2); display: flex; align-items: center; gap: 4px; max-width: 100%; white-space: nowrap; overflow: hidden; }
.ais-seat .seat-g { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.ais-seat .seat-g.m { background: #60a5fa; }
.ais-seat .seat-g.f { background: #f472b6; }
.ais-seat .seat-empty { color: #b6c2d4; font-size: 12px; }
.ais-seat.occupied {
  border-style: solid; border-color: #c7d2fe; background: var(--ais-bg);
  box-shadow: 0 2px 8px -2px rgba(30, 41, 59, .12);
}
.ais-seat.occupied:hover { transform: translateY(-2px); box-shadow: 0 8px 16px -6px rgba(99, 102, 241, .35); }
.ais-seat .seat-lock { position: absolute; top: 3px; right: 5px; font-size: 10px; opacity: .8; }
.ais-seat.dragging { opacity: .45; }
.ais-seat.drop-hint { border-color: var(--ais-primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, .3); transform: scale(1.05); }
.ais-seat.disabled-seat {
  background: repeating-linear-gradient(45deg, #eef1f6, #eef1f6 6px, #e4e9f1 6px, #e4e9f1 12px);
  border-style: solid; border-color: #dbe2ec; cursor: not-allowed;
}
.ais-seat.disabled-seat .seat-empty { color: #c3cbd9; }
.ais-seat.violated { border-color: var(--ais-danger) !important; box-shadow: 0 0 0 2px rgba(239, 68, 68, .3); }
.ais-seat .seat-badge {
  position: absolute; top: 3px; left: 5px; font-size: 9px; line-height: 1;
  background: var(--ais-warn); color: #fff; padding: 2px 4px; border-radius: 4px;
}
.ais-ghost {
  position: fixed; z-index: 9999; pointer-events: none;
  width: var(--ais-cell-w); height: var(--ais-cell-h);
  border-radius: 10px; background: #fff; border: 1.5px solid var(--ais-primary);
  box-shadow: 0 14px 30px -8px rgba(99, 102, 241, .5);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px;
  opacity: .92;
}
.ais-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 11.5px; color: var(--ais-text-2); align-items: center; }
.ais-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 4px; vertical-align: -1px; }

/* ---------- 约束检查条 ---------- */
.ais-check {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 14px; border-radius: 10px;
  font-size: 12.5px; margin-bottom: 12px; border: 1px solid;
}
.ais-check.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.ais-check.bad { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.ais-check ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- AI ---------- */
.ais-seg { display: inline-flex; background: var(--ais-bg-soft); border: 1px solid var(--ais-border); border-radius: 10px; padding: 3px; gap: 2px; }
.ais-seg button {
  border: none; background: transparent; cursor: pointer; font-family: inherit;
  padding: 6px 14px; border-radius: 8px; font-size: 13px; color: var(--ais-text-2);
}
.ais-seg button.active { background: var(--ais-bg); color: var(--ais-primary); font-weight: 600; box-shadow: 0 1px 4px rgba(15, 23, 42, .12); }
.ais-aibox { border: 1px solid #c7d2fe; background: linear-gradient(135deg, rgba(99,102,241,.05), rgba(59,130,246,.05)); }
.ais-ai-out {
  white-space: pre-wrap; background: var(--ais-bg-soft); border: 1px solid var(--ais-border);
  border-radius: 10px; padding: 12px 14px; font-size: 13px; margin-top: 10px; display: none;
}
.ais-spin {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: ais-spin .8s linear infinite; vertical-align: -2px;
}
.ais-spin.dark { border-color: rgba(99,102,241,.25); border-top-color: var(--ais-primary); }
@keyframes ais-spin { to { transform: rotate(360deg); } }

/* ---------- Popover ---------- */
.ais-pop {
  position: fixed; z-index: 9998; background: var(--ais-bg);
  border: 1px solid var(--ais-border); border-radius: 12px;
  box-shadow: 0 18px 40px -12px rgba(15, 23, 42, .3);
  padding: 6px; min-width: 150px; display: none;
}
.ais-pop.show { display: block; }
.ais-pop button {
  display: flex; width: 100%; align-items: center; gap: 8px; border: none; background: none;
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  font-family: inherit; color: var(--ais-text); text-align: left;
}
.ais-pop button:hover { background: var(--ais-bg-soft); }
.ais-pop button.red { color: var(--ais-danger); }
.ais-pop .pop-t { font-size: 11px; color: var(--ais-text-2); padding: 5px 12px 3px; }

/* ---------- Toast ---------- */
.ais-toasts { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 10000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.ais-toast {
  background: rgba(15, 23, 42, .92); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5);
  animation: ais-toast-in .25s ease; max-width: 86vw;
}
.ais-toast.err { background: rgba(190, 18, 60, .95); }
.ais-toast.ok { background: rgba(6, 95, 70, .95); }
@keyframes ais-toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
.ais-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 9990; display: none; align-items: center; justify-content: center; padding: 16px; }
.ais-mask.show { display: flex; }
.ais-modal {
  background: var(--ais-bg); border-radius: 16px; width: 560px; max-width: 96vw;
  max-height: 86vh; overflow: auto; padding: 20px 22px;
  box-shadow: 0 30px 60px -20px rgba(15, 23, 42, .4);
}
.ais-modal h3 { font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; }
.ais-modal .m-close { margin-left: auto; border: none; background: none; font-size: 20px; cursor: pointer; color: var(--ais-text-2); font-family: inherit; line-height: 1; }

/* ---------- 空状态 ---------- */
.ais-empty { text-align: center; padding: 42px 16px; color: var(--ais-text-2); }
.ais-empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- 长桌（合并）与选桌模式 ---------- */
.ais-seat.merged { flex-direction: row; align-items: stretch; justify-content: stretch; gap: 6px; padding: 5px 6px; }
.ais-seat.merged .ais-slot {
  flex: 1 1 0; min-width: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 2px 4px; text-align: center; overflow: hidden;
  border-right: 1px dashed var(--ais-border);
}
.ais-seat.merged .ais-slot:last-child { border-right: none; }
.ais-seat.merged .ais-slot .seat-name { font-weight: 600; font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ais-seat.merged .ais-slot .seat-empty { color: #b6c2d4; font-size: 12px; }
.ais-seat.merged .ais-slot .seat-lock { position: absolute; top: 0; right: 2px; font-size: 10px; opacity: .8; }
.ais-slot.violated { box-shadow: inset 0 0 0 2px rgba(239, 68, 68, .55); border-radius: 6px; }
.ais-seat.ais-sel, .ais-seat.ais-sel .ais-slot { border-color: var(--ais-primary) !important; }
.ais-seat.ais-sel { outline: 3px solid rgba(99, 102, 241, .8); outline-offset: -3px; box-shadow: 0 0 0 4px rgba(99, 102, 241, .18); }
.ais-mergebar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: linear-gradient(135deg, rgba(99,102,241,.08), rgba(59,130,246,.08));
  border: 1px dashed #c7d2fe; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 12px; font-size: 12.5px; color: var(--ais-text-2);
}
.ais-mergebar b { color: var(--ais-primary); }
.ais-mergebar .ais-sp { flex: 1; }

/* ---------- 打印 ---------- */
@media print {
  body * { visibility: hidden !important; }
  .ais-print-area, .ais-print-area * { visibility: visible !important; }
  .ais-print-area { position: absolute !important; left: 0; top: 0; width: 100%; padding: 0 !important; margin: 0 !important; }
  .ais-app .no-print { display: none !important; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .ais-app { --ais-cell-w: 74px; --ais-cell-h: 60px; padding: 10px 4px 40px; }
  .ais-headstats { margin-left: 0; }
  .ais-tab { padding: 8px 12px; font-size: 13px; }
  .ais-card { padding: 14px; }
  .ais-podium { width: 70%; }
}

/* ---------- 深色模式（随主题） ---------- */
body.sp-dark-mode .ais-app, body.night .ais-app {
  --ais-bg: #1e293b;
  --ais-bg-soft: #172033;
  --ais-border: #334155;
  --ais-text: #e2e8f0;
  --ais-text-2: #94a3b8;
}
body.sp-dark-mode .ais-seat.occupied, body.night .ais-seat.occupied { box-shadow: 0 2px 10px -2px rgba(0,0,0,.5); }
body.sp-dark-mode .ais-check.ok, body.night .ais-check.ok { background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.4); color: #6ee7b7; }
body.sp-dark-mode .ais-check.bad, body.night .ais-check.bad { background: rgba(249,115,22,.1); border-color: rgba(249,115,22,.4); color: #fdba74; }
body.sp-dark-mode .ais-seat.disabled-seat, body.night .ais-seat.disabled-seat {
  background: repeating-linear-gradient(45deg, #1b2537, #1b2537 6px, #202c44 6px, #202c44 12px);
  border-color: #2c3a52;
}
body.sp-dark-mode .ais-btn.pri, body.night .ais-btn.pri { color: #fff; }
body.sp-dark-mode .ais-modal, body.night .ais-modal { box-shadow: 0 30px 60px -20px rgba(0,0,0,.8); }
body.sp-dark-mode .ais-toast, body.night .ais-toast { background: rgba(226, 232, 240, .95); color: #0f172a; }
body.sp-dark-mode .ais-toast.err, body.night .ais-toast.err { background: rgba(251, 113, 133, .95); color: #450a0a; }
body.sp-dark-mode .ais-toast.ok, body.night .ais-toast.ok { background: rgba(110, 231, 183, .95); color: #064e3b; }
