:root {
  --surface: #f9f9f9;
  --surface-lowest: #ffffff;
  --surface-low: #f3f3f3;
  --surface-mid: #eeeeee;
  --surface-high: #e8e8e8;
  --surface-variant: #e2e2e2;
  --text: #1a1c1c;
  --muted: #45464c;
  --outline: #76777d;
  --outline-soft: #c6c6cd;
  --hairline: #f3f4f6;
  --primary: #111827;
  --on-primary: #ffffff;
  --accent: #5d6300;
  --success: #5d6300;
  --blue-soft: #d0e4ff;
  --blue-text: #25496c;
  --danger: #ba1a1a;
  --danger-soft: #ffdad6;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #ebebeb;
  color: var(--text);
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
textarea { resize: vertical; }
.material-symbols-outlined { font-size: 20px; line-height: 1; vertical-align: -4px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-variant); border-radius: 999px; }

.desk-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100dvh; overflow: hidden; background: #ebebeb; }
.app-nav { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 18px; align-items: center; margin: 16px 24px 0; padding: 10px 18px; border: 1px solid rgba(198, 198, 205, 0.35); border-radius: 999px; background: rgba(232, 232, 232, 0.88); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.08); position: sticky; top: 16px; z-index: 20; }
.brand-area { display: flex; gap: 12px; align-items: center; padding: 0; }
.brand-icon { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.brand-area h1, .brand-area p { margin: 0; }
.brand-area h1 { font-family: Geist, sans-serif; font-size: 24px; line-height: 32px; font-weight: 600; }
.app-nav .brand-area p { display: none; }
.brand-area p, .section-head p, .section-toolbar p, .ticket-meta, small { color: var(--muted); font-size: 13px; }
.nav-stack { display: flex; align-items: center; justify-content: center; gap: 6px; overflow-x: auto; padding: 4px 2px; min-width: 0; scrollbar-width: none; }
.nav-stack::-webkit-scrollbar { display: none; }
.nav-item { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; border: 1px solid transparent; border-radius: 999px; padding: 9px 14px; background: transparent; color: var(--muted); text-align: left; transition: 160ms ease; white-space: nowrap; }
.nav-item:hover, .nav-item.active { color: var(--on-primary); background: #000000; border-color: #000000; box-shadow: none; }
.nav-item.active { font-weight: 600; }
.staff-chip { display: flex; align-items: center; gap: 10px; border: 1px solid rgba(198, 198, 205, 0.45); border-radius: 999px; padding: 7px 10px; background: rgba(255, 255, 255, 0.72); color: var(--muted); text-align: left; }
.staff-chip:hover { background: var(--surface-low); border-color: var(--hairline); }
.staff-chip span:last-child { display: grid; gap: 1px; }
.staff-chip strong { color: var(--text); font-size: 13px; }

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

.main-shell { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 22px 24px 14px; }
.page-heading h2 { margin: 0; font-family: Geist, sans-serif; font-size: 18px; line-height: 24px; font-weight: 700; }
.page-heading p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.heading-actions { display: flex; align-items: center; gap: 10px; }

.icon-button, .line-button, .primary-button { min-height: 34px; border-radius: 8px; border: 1px solid var(--outline-soft); background: transparent; color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 7px 12px; transition: 160ms ease; white-space: nowrap; }
.icon-button { width: 34px; padding: 0; border-color: transparent; position: relative; color: var(--muted); }
.icon-button:hover, .line-button:hover { background: var(--surface-high); color: var(--primary); }
.primary-button { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.primary-button:hover { opacity: 0.9; }
.has-dot::after { content: ""; position: absolute; right: 8px; top: 7px; width: 7px; height: 7px; border-radius: 999px; background: var(--danger); }

.workspace { overflow: auto; padding: 24px 24px 32px; background: #ebebeb; }
.view { display: none; }
.active-view { display: block; }
.ticket-workspace.active-view { display: grid; grid-template-columns: minmax(0, 1fr) minmax(390px, 460px); gap: 24px; height: 100%; min-height: 0; }
.panel { background: var(--surface-lowest); border: 1px solid var(--hairline); border-radius: 8px; box-shadow: var(--shadow); }
.table-panel { display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; min-height: 0; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 16px; border-bottom: 1px solid var(--hairline); background: var(--surface-lowest); }
input, select, textarea { border: 1px solid var(--hairline); border-radius: 8px; background: var(--surface); color: var(--text); outline: 0; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { border-color: var(--outline-soft); background: var(--surface-lowest); }
.search-field { width: min(280px, 100%); display: flex; align-items: center; gap: 8px; border: 1px solid var(--hairline); border-radius: 8px; padding: 0 10px; background: var(--surface); }
.search-field input { flex: 1; min-width: 0; border: 0; background: transparent; padding-left: 0; }
.inline-check { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }

.table-scroll { overflow: auto; }
.ticket-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.ticket-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-lowest); color: var(--muted); font-family: Geist, sans-serif; font-size: 10px; line-height: 16px; font-weight: 600; text-align: left; text-transform: uppercase; padding: 12px 14px; border-bottom: 1px solid var(--hairline); }
.ticket-table td { padding: 14px; border-bottom: 1px solid var(--hairline); vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-row { cursor: pointer; transition: 120ms ease; }
.ticket-row:hover, .ticket-row.active { background: var(--surface-low); }
.ticket-row.timeout { background: rgba(255, 218, 214, 0.28); }
.mono { font-family: "Berkeley Mono", Consolas, monospace; font-size: 13px; }
.tag { display: inline-flex; align-items: center; gap: 5px; border-radius: 4px; padding: 2px 7px; font-size: 10px; font-weight: 600; background: var(--surface-high); color: var(--text); }
.tag.type-送物 { background: var(--blue-soft); color: var(--blue-text); }
.tag.type-维修 { background: #fff1cf; color: #664a00; }
.tag.type-清洁 { background: #ddeedc; color: #2e5b35; }
.tag.type-转人工, .tag.danger { background: var(--danger-soft); color: var(--danger); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--outline); display: inline-block; margin-right: 7px; }
.status-dot.active { background: var(--success); }
.status-dot.danger { background: var(--danger); }

.detail-panel { min-height: 0; padding: 0; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; align-self: stretch; }
.empty-detail { min-height: 520px; display: grid; place-items: center; color: var(--muted); text-align: center; }
.detail-header { min-width: 0; padding: 20px 20px 16px; border-bottom: 1px solid var(--hairline); position: relative; background: var(--surface-lowest); }
.detail-header h3 { margin: 0; min-width: 0; font-family: Geist, sans-serif; font-size: 18px; line-height: 24px; font-weight: 600; }
.detail-kicker { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; color: var(--muted); font-family: Geist, sans-serif; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.detail-title-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; min-width: 0; }
.detail-subline { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 4px; color: var(--muted); font-size: 13px; }
.detail-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.detail-metric { min-width: 0; border: 1px solid var(--hairline); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.detail-metric span { display: block; margin-bottom: 4px; color: var(--outline); font-family: Geist, sans-serif; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.detail-metric strong { display: block; min-width: 0; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.detail-metric .tag { vertical-align: middle; }
.status-pill { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--hairline); border-radius: 999px; padding: 5px 10px; background: var(--surface); font-size: 12px; font-weight: 600; }
.status-pill.active { color: var(--success); }
.status-pill.danger { color: var(--danger); background: #fff7f6; border-color: rgba(186, 26, 26, 0.18); }
.status-pill.done { color: var(--muted); }
.detail-scroll { min-height: 0; overflow: auto; padding: 16px; display: grid; gap: 14px; align-content: start; background: var(--surface-lowest); }
.detail-block { min-width: 0; border: 1px solid var(--hairline); border-radius: 8px; padding: 14px; background: var(--surface-lowest); }
.detail-block h4, .quick-card h3, .trace-card h3, .chart-panel h3 { margin: 0 0 12px; font-family: Geist, sans-serif; font-size: 14px; }
.meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.meta-label { color: var(--outline); font-family: Geist, sans-serif; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.analysis-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.analysis-grid p { margin: 4px 0 0; overflow-wrap: anywhere; }
.analysis-main { grid-column: 1 / -1; }
.note-block textarea { width: 100%; min-height: 84px; resize: vertical; }
.history-block { padding-bottom: 12px; }
.conversation-list, .log-list { display: grid; gap: 10px; min-width: 0; }
.detail-actions { display: flex; flex-wrap: nowrap; justify-content: space-between; gap: 8px; padding: 12px; border-top: 1px solid var(--hairline); background: var(--surface-lowest); }
.detail-actions .line-button, .detail-actions .primary-button { flex: 1 1 0; min-width: 0; padding-inline: 8px; }
.chat-line { min-width: 0; display: flex; gap: 8px; align-items: flex-start; }
.chat-line.guest { flex-direction: row-reverse; }
.chat-line.guest .message-body { align-items: flex-end; }
.avatar { width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; background: var(--surface-high); color: var(--muted); flex: 0 0 auto; }
.chat-line.assistant .avatar { background: var(--primary); color: var(--on-primary); }
.message-body { min-width: 0; max-width: calc(100% - 32px); display: grid; gap: 4px; }
.message-body > span { color: var(--outline); font-size: 11px; }
.bubble { max-width: 100%; border: 1px solid var(--hairline); border-radius: 10px; padding: 9px 11px; background: var(--surface); line-height: 1.55; text-align: left; overflow-wrap: anywhere; white-space: pre-wrap; }
.guest .bubble { background: var(--surface-lowest); }
.assistant .bubble { background: var(--surface-high); }

.handoff-layout.active-view { display: block; }
.section-head, .section-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-head h3, .section-toolbar h3 { margin: 0; font-family: Geist, sans-serif; font-size: 24px; line-height: 32px; }
.section-head p, .section-toolbar p { margin: 4px 0 0; }
.section-toolbar span { color: var(--muted); font-size: 14px; font-family: Inter, sans-serif; font-weight: 400; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { width: 110px; }
.bulk-strip { padding: 14px; margin-bottom: 20px; }
.bulk-strip form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.room-card { min-height: 330px; padding: 20px; display: grid; grid-template-rows: auto 148px auto auto; gap: 14px; background: var(--surface-lowest); border: 1px solid var(--hairline); border-radius: 8px; transition: 160ms ease; }
.room-card:hover { background: var(--surface); }
.room-card img { width: 128px; height: 128px; object-fit: contain; border: 1px solid rgba(118, 119, 125, 0.25); padding: 8px; background: white; justify-self: center; align-self: center; }
.room-card .empty-detail { min-height: 128px; border: 1px dashed var(--outline-soft); border-radius: 8px; background: var(--surface); }
.room-top { display: flex; justify-content: space-between; gap: 10px; }
.room-tags { display: grid; justify-items: end; align-content: start; gap: 6px; }
.room-no { font-family: Geist, sans-serif; font-size: 18px; font-weight: 600; display: block; }

.agent-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.agent-card { padding: 22px; background: var(--surface-lowest); border: 1px solid var(--hairline); border-radius: 8px; }
.agent-card.wide { grid-column: span 2; }
.agent-card.full { grid-column: 1 / -1; }
.agent-card h3 { margin: 0 0 14px; font-family: Geist, sans-serif; font-size: 16px; }
.kv-list, .tool-list, .guard-list { display: grid; gap: 10px; }
.kv-row, .tool-row, .guard-row { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--hairline); padding-bottom: 9px; }
.kv-row:last-child, .tool-row:last-child, .guard-row:last-child { border-bottom: 0; padding-bottom: 0; }
.agent-mode { font-family: Geist, sans-serif; font-size: 24px; font-weight: 600; margin-bottom: 8px; }

.stats-layout.active-view { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card { min-height: 112px; background: var(--surface-lowest); border: 1px solid var(--hairline); border-radius: 8px; padding: 18px; display: grid; align-content: space-between; }
.kpi-card.warn { border-color: rgba(186, 26, 26, 0.25); background: rgba(255, 218, 214, 0.22); }
.kpi-card span { color: var(--muted); font-family: Geist, sans-serif; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.kpi-card strong { font-family: "Berkeley Mono", Consolas, monospace; font-size: 24px; font-weight: 500; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.chart-panel { padding: 22px; min-height: 280px; }
.chart-panel.wide { grid-column: 1 / -1; }
.chart-row { display: grid; grid-template-columns: 110px 1fr 56px; align-items: center; gap: 12px; margin: 12px 0; }
.bar-track { height: 10px; border-radius: 999px; background: var(--surface-mid); overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); }

.simulator-layout.active-view { display: grid; grid-template-columns: 375px minmax(0, 1fr); gap: 48px; align-items: start; }
.phone-frame { width: 375px; height: 812px; border: 14px solid var(--surface-high); border-radius: 42px; background: white; overflow: hidden; position: relative; display: grid; grid-template-rows: auto 1fr auto; box-shadow: 0 22px 60px rgba(31,42,35,0.18); }
.phone-notch { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 150px; height: 28px; background: var(--surface-high); border-radius: 0 0 22px 22px; z-index: 2; }
.phone-header { padding: 48px 14px 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--hairline); background: white; }
.chat-log { overflow: auto; padding: 16px; background: var(--surface-low); display: grid; gap: 12px; align-content: start; }
.chat-bubble { max-width: 82%; padding: 9px 12px; border: 1px solid var(--hairline); border-radius: 16px; line-height: 1.55; background: white; white-space: pre-wrap; }
.chat-bubble.guest { justify-self: end; border-top-right-radius: 4px; }
.chat-bubble.system { justify-self: start; border-top-left-radius: 4px; }
.chat-bubble.info { justify-self: start; background: var(--blue-soft); color: var(--blue-text); }
.phone-input { padding: 12px 12px 28px; display: grid; grid-template-columns: 1fr 36px; gap: 8px; border-top: 1px solid var(--hairline); }
.phone-input input { border-radius: 999px; }
.phone-input button { border: 0; border-radius: 999px; background: var(--primary); color: white; }
.sim-tools { display: grid; gap: 18px; }
.context-card { padding: 18px; display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
.context-card label { display: grid; gap: 6px; }
.context-card span { font-family: Geist, sans-serif; font-size: 10px; font-weight: 600; color: var(--muted); }
.quick-card { padding: 20px; display: grid; gap: 10px; }
.quick-card button { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--hairline); border-radius: 8px; background: white; padding: 12px 14px; text-align: left; }
.quick-card button:hover { background: var(--surface-low); }
.quick-card .danger { color: var(--danger); border-color: rgba(186, 26, 26, 0.28); }
.trace-card { border: 1px solid var(--hairline); border-radius: 8px; background: #1a1c1c; color: #dadada; padding: 18px; }
.trace-card h3 { color: white; display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
.trace-log { max-height: 260px; overflow: auto; display: grid; gap: 7px; font-family: Consolas, monospace; font-size: 12px; }
.trace-line span:first-child { color: #76777d; margin-right: 8px; }

.staff-dialog { border: 1px solid var(--hairline); border-radius: 14px; padding: 0; box-shadow: 0 20px 70px rgba(0,0,0,0.18); }
.staff-dialog::backdrop { background: rgba(26, 28, 28, 0.35); }
.staff-dialog form { width: 340px; display: grid; gap: 12px; padding: 22px; }
.staff-dialog h3 { margin: 0; font-family: Geist, sans-serif; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 1200px) {
  .ticket-workspace.active-view, .simulator-layout.active-view { grid-template-columns: 1fr; }
  .detail-panel { min-height: 520px; }
  .agent-grid, .chart-grid { grid-template-columns: 1fr; }
  .agent-card.wide { grid-column: auto; }
  .context-card { grid-template-columns: 1fr; }
  .app-nav { grid-template-columns: 1fr; }
  .nav-stack { order: 3; }
  .top-actions { order: 2; justify-content: flex-start; }
  .page-heading { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 780px) {
  .desk-shell { grid-template-rows: auto minmax(0, 1fr); }
  .app-nav { grid-template-columns: 1fr; gap: 14px; margin: 12px 12px 0; padding: 14px 16px; border-radius: 24px; top: 12px; }
  .brand-area { padding: 0; }
  .nav-stack { padding: 0; }
  .top-actions { flex-wrap: wrap; justify-content: flex-start; }
  .heading-actions { flex-wrap: wrap; }
  .page-heading { padding: 18px 16px 12px; }
  .workspace { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bulk-strip form { grid-template-columns: 1fr; }
  .phone-frame { width: 100%; max-width: 375px; justify-self: center; }
}

.flat-panel { min-height: 520px; }
.staff-layout.active-view, .notifications-layout.active-view { display: block; }
.ticket-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tag.ok { background: #ddeedc; color: #2e5b35; }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.danger-text { color: var(--danger); border-color: rgba(186, 26, 26, 0.25); }
.danger-text:hover { background: var(--danger-soft); }
.room-card.active-stay { border-color: rgba(63, 111, 73, 0.28); background: #fbfcf8; }
.room-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; justify-content: space-between; }
.room-actions .line-button { flex: 1; min-width: 0; padding-inline: 8px; }
.ticket-table th:last-child, .ticket-table td:last-child { width: 160px; }
.staff-layout .ticket-table th:nth-child(4), .staff-layout .ticket-table td:nth-child(4) { width: 220px; }
.notifications-layout .ticket-table th:nth-child(6), .notifications-layout .ticket-table td:nth-child(6) { width: 28%; }
.notifications-layout .ticket-table th:nth-child(7), .notifications-layout .ticket-table td:nth-child(7) { width: 64px; }
.notifications-layout .ticket-table th:nth-child(8), .notifications-layout .ticket-table td:nth-child(8) { width: 22%; }
.empty-cell { color: var(--muted); text-align: center; padding: 32px !important; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.room-meta {
  min-height: 68px;
  display: grid;
  gap: 4px;
  align-content: center;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
}
.room-meta span {
  color: var(--outline);
  font-family: Geist, sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.room-meta strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 600;
}
.room-meta small { font-size: 12px; }

.empty-state {
  min-height: 108px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  color: var(--muted);
}
.empty-state .material-symbols-outlined {
  color: var(--outline);
  font-size: 26px;
}
.empty-state strong {
  color: var(--text);
  font-size: 14px;
}
.empty-state small {
  max-width: 320px;
  color: var(--muted);
  text-wrap: pretty;
}

@media (max-width: 520px) {
  .room-actions { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
}
