:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-2: #7c3aed;
  --green: #16a34a;
  --orange: #ea580c;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(37, 99, 235, .14), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(124, 58, 237, .12), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.center { text-align: center; }

/* ==================== 登录 ==================== */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 30px 26px;
  border: 1px solid rgba(255, 255, 255, .8);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 24px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .3);
}
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .5px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.field { margin-top: 16px; }
.field label { display: block; font-size: 13px; color: #374151; margin-bottom: 6px; font-weight: 600; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.textarea { min-height: 104px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), #3b82f6);
  cursor: pointer;
  transition: transform .08s, filter .15s, opacity .15s;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .22);
  font-family: inherit;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.block { width: 100%; }
.btn.ghost {
  background: #fff;
  color: #374151;
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.soft { background: #eef2ff; color: #3730a3; box-shadow: none; }
.btn.green { background: linear-gradient(135deg, #16a34a, #22c55e); box-shadow: 0 6px 16px rgba(22, 163, 74, .2); }
.btn.orange { background: linear-gradient(135deg, #ea580c, #f97316); box-shadow: 0 6px 16px rgba(234, 88, 12, .2); }
.btn.red { background: linear-gradient(135deg, #dc2626, #ef4444); box-shadow: 0 6px 16px rgba(220, 38, 38, .2); }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btn.xs { padding: 5px 9px; font-size: 12px; border-radius: 7px; }

.login-error { min-height: 20px; color: var(--red); font-size: 13px; margin-top: 10px; }
.login-foot { margin-top: 18px; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ==================== 主框架 ==================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
  background: rgba(255, 255, 255, .78);
  border-bottom: 1px solid rgba(229, 231, 235, .8);
}
.app-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-header .brand-logo { width: 38px; height: 38px; font-size: 20px; border-radius: 12px; }
.app-header h1 { font-size: 16px; margin: 0; }
.app-header .sub { font-size: 11px; color: var(--muted); }
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #374151; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2ff;
  color: #3730a3;
  white-space: nowrap;
}
.pill.green { background: #dcfce7; color: #166534; }
.pill.gray { background: #f3f4f6; color: #4b5563; }
.pill.orange { background: #ffedd5; color: #9a3412; }
.pill.red { background: #fee2e2; color: #991b1b; }

.tabs {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 18px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-family: inherit;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 16px;
}
.card {
  background: var(--card);
  border: 1px solid rgba(229, 231, 235, .85);
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(15, 23, 42, .05);
  padding: 16px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
}
.card-title .hint { font-size: 12px; font-weight: 400; color: var(--muted); }

/* ==================== 教室选择 ==================== */
.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 9px;
}
.room-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s, transform .08s;
  font-size: 14px;
}
.room-chip:active { transform: scale(.99); }
.room-chip .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #cbd5e1; flex: none;
}
.room-chip.online .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .16); }
.room-chip.selected {
  border-color: var(--brand);
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .08);
}
.room-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-chip .check { margin-left: auto; color: var(--brand); font-weight: 700; opacity: 0; }
.room-chip.selected .check { opacity: 1; }
.room-chip .meta { font-size: 11px; color: var(--muted); margin-left: 2px; }

/* ==================== 发送 ==================== */
.quick-cmds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip-btn {
  border: 1px solid var(--line);
  background: #f9fafb;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: #374151;
  font-family: inherit;
}
.chip-btn:hover { border-color: var(--brand); color: var(--brand); }
.chip-btn.danger { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .app-header-inner { flex-wrap: wrap; }
  .main { padding: 12px; gap: 12px; }
  .card { padding: 13px; }
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
}
.switch input { width: 16px; height: 16px; accent-color: var(--brand); }

.media-box {
  border: 1px dashed #cbd5e1;
  border-radius: 11px;
  padding: 12px;
  background: #fafcff;
}
.media-preview {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
.media-preview img {
  max-width: 160px;
  max-height: 120px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
}
.media-preview audio { max-width: 260px; height: 36px; }
.record-btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  box-shadow: 0 6px 16px rgba(220, 38, 38, .2);
  font-family: inherit;
}
.record-btn.recording { background: #991b1b; animation: pulse 1.1s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .35); } 50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); } }

.send-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 12px 18px;
  margin: 8px -18px -18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.send-bar .target-summary { font-size: 13px; color: var(--muted); }
.send-bar .btn { margin-left: auto; min-width: 140px; }

/* ==================== 历史 ==================== */
.history-list { display: grid; gap: 9px; }
.history-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  background: #fff;
}
.history-item .top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.history-item .content { margin-top: 6px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.history-item .time { font-size: 11px; color: var(--muted); margin-left: auto; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #f3f4f6; color: #4b5563; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.orange { background: #ffedd5; color: #9a3412; }

/* ==================== 管理 ==================== */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 720px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(180deg, #fff, #fafcff);
}
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 800; margin-top: 4px; }

.list { display: grid; gap: 8px; }
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  flex-wrap: wrap;
}
.list-item .grow { flex: 1; min-width: 140px; }
.list-item .title { font-weight: 600; font-size: 14px; }
.list-item .sub { font-size: 11px; color: var(--muted); margin-top: 2px; word-break: break-all; }

.assign-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.assign-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 13px;
  cursor: pointer;
}
.assign-item input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ==================== 弹窗 / Toast ==================== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
  padding: 18px;
  max-height: 82vh;
  overflow: auto;
}
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(17, 24, 39, .92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(153, 27, 27, .95); }
.toast.success { background: rgba(22, 101, 52, .95); }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 28px 10px;
}
.loading { font-size: 12px; color: var(--muted); }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
