/* 主题：白蓝（浅色）
   —— 底色偏冷蓝灰，面板纯白，主色蓝。状态色（红/黄/绿）都调深了保证白底可读。 */
:root {
  --bg: #eef3fa;
  --panel: #ffffff;
  --panel-2: #f5f8fd;
  --panel-3: #e9f1fb;
  --line: #d7e2f0;
  --line-strong: #bccfe6;
  --text: #14243d;
  --text-soft: #3d5170;
  --muted: #6d80a0;
  --accent: #1a73e8;
  --accent-soft: #e7f0fe;
  --green: #12864a;
  --amber: #b26a05;
  --red: #d3202a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 36, 61, .06), 0 4px 12px rgba(20, 36, 61, .05);
}

* { box-sizing: border-box; }

/* 必须带 !important：.panel / .layout 等都用了 display:flex，作者样式的 display
   会盖过浏览器默认的 [hidden]{display:none}，导致设了 hidden 的元素照样渲染成空框。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

h1, h2 { margin: 0; font-weight: 500; }
h1 { font-size: 16px; }
h2 { font-size: 14px; color: var(--muted); }

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line-strong);
}
.dot.online { background: var(--green); }
.dot.offline { background: var(--red); }

.status-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.chip.ok { color: var(--green); border-color: rgba(18,134,74,.35); background: rgba(18,134,74,.08); }
.chip.warn { color: var(--amber); border-color: rgba(178,106,5,.35); background: rgba(178,106,5,.08); }
.chip.err { color: var(--red); border-color: rgba(211,32,42,.35); background: rgba(211,32,42,.08); }

.btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1665cd; border-color: #1665cd; color: #fff; }
.btn-danger { background: transparent; border-color: rgba(211,32,42,.45); color: var(--red); }
.btn-danger:hover { background: rgba(211,32,42,.08); border-color: var(--red); color: var(--red); }
.btn-light { background: #fff; color: #111; border-color: #fff; font-size: 15px; padding: 10px 24px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- 布局 ---------------- */
.layout {
  display: grid;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 61px);
}
/* 一级：房间网格（单列全宽） */
.layout.rooms-mode { grid-template-columns: 1fr; }
/* 二级：工单列表 + 详情 */
.layout.tickets-mode { grid-template-columns: 380px 1fr; }

/* ---------------- 房间网格 ---------------- */
.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.view-head h2 { font-size: 15px; color: var(--text); }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  align-content: start;
  overflow-y: auto;
  padding-right: 4px;
}

.room-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.room-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.room-card.busy { border-left: 3px solid var(--amber); }
.room-card.sos { border-left: 3px solid var(--red); animation: pulse 1.2s infinite; }
.room-card.unbound { opacity: .8; border-style: dashed; background: var(--panel-2); }

/* 末尾的「虚拟添加框」：虚线卡片，点了直接登记新客房 */
.room-card.add-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 132px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}
.room-card.add-card:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-plus { font-size: 28px; line-height: 1; }
.add-text { font-size: 13px; }

.room-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.room-no { font-size: 19px; font-weight: 500; flex: none; }
/* 设备名过长时省略，别把徽章和删除按钮挤到换行 */
.room-name { font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-top .badge { margin-left: auto; }
/* 卡片上的删除按钮：平时淡，悬停/聚焦才明显，避免误点 */
.room-del {
  flex: none;
  width: 22px; height: 22px; line-height: 1;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: var(--muted);
  font-size: 15px; cursor: pointer; opacity: .35;
  transition: opacity .15s, color .15s, border-color .15s, background .15s;
}
.room-card:hover .room-del { opacity: 1; }
.room-del:hover { color: var(--red); border-color: rgba(211,32,42,.45); background: rgba(211,32,42,.08); }
.room-mac {
  font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace;
  margin-bottom: 8px;
}
.room-latest {
  font-size: 13px; color: var(--text-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.room-latest.muted { color: var(--muted); font-size: 12px; }
.room-time { font-size: 11px; color: var(--muted); margin-top: 4px; }

.head-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 100%; }
.head-left > div { min-width: 0; }
.head-left h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-left .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-back { padding: 4px 8px; font-size: 12px; }
/* 面板头部窄（380px）时按钮别折成两行 */
.panel-head .btn, .panel-head .tag { white-space: nowrap; flex: none; }

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

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* 列表面板只有 380px，标题与按钮必须整行换行，
     否则 filters 溢出会盖住左边的「返回」按钮，点不到 */
  flex-wrap: wrap;
  row-gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.filters { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; row-gap: 6px; }
.panel-head .filters { flex: 0 0 auto; }

/* 状态筛选按钮组：与右侧操作按钮分开，避免挤在一起 */
.tag-group {
  display: flex;
  gap: 4px;
  padding: 3px;
  margin-right: 4px;
  border-radius: 8px;
  background: var(--panel-3);
}

/* 跨房间看全部工单时，卡片上的房号标签 */
.room-tag {
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.tag {
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.ticket-list { overflow-y: auto; padding: 8px; flex: 1; background: var(--panel-2); }

.empty { color: var(--muted); padding: 24px; text-align: center; font-size: 13px; }

/* ---------------- 工单卡片 ---------------- */
.ticket {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--panel);
  transition: border-color .15s;
}
.ticket:hover { border-color: var(--accent); }
.ticket.selected { border-color: var(--accent); background: var(--accent-soft); }
.ticket.urgent { border-left: 3px solid var(--amber); }
.ticket.sos { border-left: 3px solid var(--red); animation: pulse 1.2s infinite; }
.ticket.done { opacity: .6; }
.ticket.cancelled { opacity: .5; text-decoration: line-through; }

.ticket-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.room { font-size: 15px; font-weight: 500; }
.cat {
  font-size: 12px; color: var(--text-soft);
  background: rgba(20,36,61,.06);
  padding: 1px 8px; border-radius: 4px;
}
.badge {
  font-size: 11px; padding: 1px 7px; border-radius: 4px; margin-left: auto;
  white-space: nowrap; flex: none;
}
.badge.pending { background: rgba(26,115,232,.12); color: var(--accent); }
.badge.processing { background: rgba(178,106,5,.14); color: var(--amber); }
.badge.done { background: rgba(18,134,74,.14); color: var(--green); }
.badge.cancelled { background: rgba(109,128,160,.16); color: var(--muted); }
.badge.sos { background: rgba(211,32,42,.14); color: var(--red); }

.ticket-content {
  font-size: 13px; color: var(--text-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.ticket-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(211,32,42,.35); }
  50% { box-shadow: 0 0 0 6px rgba(211,32,42,0); }
}

/* ---------------- 详情 ---------------- */
.detail { padding: 16px; overflow-y: auto; flex: 1; }

.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.detail-room { font-size: 20px; font-weight: 500; }
.detail-content {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px; margin: 10px 0 16px;
  font-size: 14px;
}

.advice-grid { display: grid; gap: 10px; }
.advice-card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--panel-2);
}
.advice-card.action { border-left-color: var(--green); }
.advice-card.script { border-left-color: var(--amber); }
.advice-card.escalate { border-left-color: var(--red); }
.advice-card h3 {
  margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 500;
}
.advice-card p { margin: 0; font-size: 14px; white-space: pre-wrap; }

.detail-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.push-state {
  margin-top: 14px; font-size: 12px; color: var(--muted);
  border-top: 1px dashed var(--line); padding-top: 10px;
}
.push-state.ok { color: var(--green); }
.push-state.err { color: var(--red); }

/* ---------------- SOS 全屏 ---------------- */
.sos-overlay {
  position: fixed; inset: 0;
  background: rgba(211, 32, 42, .16);
  display: flex; align-items: center; justify-content: center;
  z-index: 99;
  animation: flash 1s infinite;
}
.sos-inner {
  background: #fff;
  border: 2px solid var(--red);
  border-radius: 16px;
  padding: 36px 56px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(211,32,42,.25);
}
.sos-title { font-size: 30px; color: var(--red); letter-spacing: 6px; }
.sos-room { font-size: 46px; font-weight: 500; margin: 12px 0; color: var(--text); }
.sos-content { color: var(--text-soft); margin-bottom: 20px; max-width: 420px; }

@keyframes flash {
  0%, 100% { background: rgba(211, 32, 42, .08); }
  50% { background: rgba(211, 32, 42, .26); }
}

/* ---------------- 回复住客（回播客房设备） ---------------- */
.reply-box { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.reply-box h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.reply-note { margin-left: 8px; font-size: 11px; color: var(--accent); }
.reply-target { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.reply-target.warn { color: var(--amber); }
#reply-input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line-strong);
  color: var(--text); border-radius: 8px; padding: 8px 10px;
  font-family: inherit; font-size: 13px; resize: vertical;
}
#reply-input:focus { outline: none; border-color: var(--accent); }
.reply-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.reply-state { margin-top: 8px; font-size: 12px; color: var(--muted); }
.reply-state.ok { color: var(--green); }
.reply-state.err { color: var(--red); }

/* ---------------- 接入点管理 ---------------- */
.admin-view {
  display: flex; flex-direction: column; min-height: 0;
  gap: 14px; overflow-y: auto; padding-right: 4px;
}
.admin-list { display: grid; gap: 10px; }
.admin-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.admin-top {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 4px;
}
.admin-mac {
  font-size: 12px; color: var(--muted);
  font-family: ui-monospace, monospace;
}
.admin-endpoint {
  margin-top: 4px; font-size: 12px; color: var(--text-soft);
  word-break: break-all;
}
.admin-endpoint.muted { color: var(--muted); }
.admin-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.pipe-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap;
}
.pipe-badge.running { color: var(--green); border-color: rgba(18,134,74,.4); background: rgba(18,134,74,.08); }
.pipe-badge.stopped { color: var(--text-soft); background: var(--panel-2); }
.pipe-badge.warn { color: var(--amber); border-color: rgba(178,106,5,.4); background: rgba(178,106,5,.08); }

.admin-add {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}
.admin-add h3 { margin: 0 0 10px; font-size: 14px; font-weight: 500; }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(20,36,61,.42);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-inner {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; width: 480px; max-width: 92vw;
  box-shadow: 0 18px 50px rgba(20,36,61,.2);
}
.modal-inner.wide { width: 780px; }
.modal-inner h2 { font-size: 15px; margin-bottom: 6px; color: var(--text); }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.dev-list { max-height: 220px; overflow-y: auto; margin-bottom: 12px; }
.dev-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; font-size: 13px;
  background: var(--panel-2);
}
.dev-room { font-weight: 500; }
.dev-mac { color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
.dev-name { color: var(--muted); font-size: 12px; }
.dev-row .btn { margin-left: auto; }
.dev-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.dev-form label { font-size: 12px; color: var(--muted); flex: 0 0 84px; }
.dev-form input {
  flex: 1; min-width: 120px; background: var(--panel-2); border: 1px solid var(--line-strong);
  color: var(--text); border-radius: 8px; padding: 6px 10px;
  font-family: inherit; font-size: 13px;
}
.dev-form input:focus { outline: none; border-color: var(--accent); }
.dev-form .btn { flex: 0 0 auto; }
.dev-form .grow { flex: 1 1 260px; }

/* ---------------- 管道日志 ---------------- */
.log-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.log-body {
  margin: 0; max-height: 50vh; overflow: auto;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.55; color: var(--text-soft);
  white-space: pre-wrap; word-break: break-all;
}
/* 提示词：中文为主，别用等宽字体，行高放宽便于阅读和整段复制 */
.prompt-body {
  margin: 0; max-height: 52vh; overflow: auto;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px; line-height: 1.75; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}

/* ---------------- 模拟住客请求 ---------------- */
.sim-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.sim-form label { font-size: 12px; color: var(--muted); }
.sim-form select, .sim-form textarea {
  background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font-family: inherit; font-size: 13px; resize: vertical;
}
.sim-form select:focus, .sim-form textarea:focus { outline: none; border-color: var(--accent); }
.sim-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
}
