:root {
  --ink: #253238;
  --muted: #66737f;
  --line: #d7e4e8;
  --panel: #ffffff;
  --bg: #f3f9f9;
  --green: #0c7a92;
  --teal: #1088a8;
  --red: #c83349;
  --amber: #f5a300;
  --blue: #0d84a0;
  --cyan: #31bdd2;
  --violet: #6a5fd2;
  --official-dark: #0a4c5e;
  --official-green: #0c7a92;
  --official-teal: #1088a8;
  --official-sky: #67c7d8;
  --shadow: 0 10px 30px rgba(32, 47, 56, 0.08);
  --content-max: 1680px;
  --space-1: clamp(8px, 1vw, 10px);
  --space-2: clamp(10px, 1.2vw, 14px);
  --space-3: clamp(14px, 1.6vw, 18px);
  --space-4: clamp(18px, 2vw, 24px);
  --space-5: clamp(22px, 2.6vw, 32px);
  --panel-pad: clamp(14px, 1.6vw, 20px);
  --sidebar-width: clamp(252px, 18vw, 306px);
  --case-header-offset: 214px;
  --workspace-height: calc(100vh - clamp(132px, 15vh, 170px));
  --split-primary: minmax(0, 1.55fr);
  --split-secondary: minmax(320px, 0.85fr);
  --detail-column: minmax(320px, 0.42fr);
  --sticky-header-offset: 64px;
  --app-pad-top: var(--space-5);
  --app-inline-pad: var(--space-5);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(17, 143, 168, 0.12), rgba(0, 140, 120, 0) 310px),
    var(--bg);
  color: var(--ink);
  font-family: Arial, "Noto Sans TC", sans-serif;
}

html {
  scroll-behavior: smooth;
}

button,
input,
select {
  font: inherit;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-height: 0;
  min-width: 0;
  max-width: 100vw;
  padding: var(--space-4) var(--space-3);
  background: linear-gradient(180deg, #0a5164 0%, #0c647b 52%, #073d4c 100%);
  color: #f8fbfc;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.brand {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
}

.brand-logo {
  width: 80px;
  height: 32px;
  object-fit: contain;
  flex: 0 0 auto;
  padding: 3px 5px;
  border-radius: 5px;
  background: #fff;
}

.brand small,
.system-note span {
  display: block;
  color: #abc0c8;
  margin-top: 4px;
}

.brand strong,
.brand small {
  overflow-wrap: anywhere;
}

.brand strong {
  font-size: 14px;
  white-space: nowrap;
}

.access-control {
  margin-top: auto;
  display: grid;
  gap: var(--space-2);
  flex: 0 0 auto;
}

.area-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid #31515a;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.area-switch button {
  padding: 9px 10px;
  border-radius: 6px;
  color: #b8cdd4;
  background: transparent;
  box-shadow: none;
}

.area-switch button.active {
  color: var(--official-dark);
  background: #ffffff;
}

.area-switch.single-area {
  display: none;
}

.nav {
  display: grid;
  gap: var(--space-1);
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.nav-section-label {
  margin: 8px 10px 2px;
  color: #8fb4ba;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.nav-section-label:first-child {
  margin-top: 0;
}

.nav button {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  background: transparent;
  color: #dbe9ed;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.nav button.active,
.nav button:hover {
  background: #10485a;
  color: #ffffff;
  transform: translateX(2px);
}

.nav button.out-of-area {
  opacity: 0.62;
}

.nav button.locked {
  position: relative;
  color: #8aa0a8;
}

.nav button.locked::after {
  content: "鎖";
  float: right;
  font-size: 12px;
  color: #c4d1d6;
}

/* OCC 未確認警訊數：待確認件數直接標在導覽上，人不在 OCC 分頁也看得到。
   .locked 的鎖頭一樣走 ::after，鎖住時不顯示件數以免兩者打架。 */
.nav button.has-alert:not(.locked) {
  position: relative;
  color: #ffffff;
}

.nav button.has-alert:not(.locked)::after {
  content: attr(data-alert-count);
  float: right;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--red);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  animation: alertPulse 1.4s ease-in-out infinite;
}

.access-notice {
  display: none;
  padding: 10px 12px;
  border: 1px solid rgba(245, 163, 0, 0.42);
  border-radius: 8px;
  color: #ffe8a8;
  background: rgba(245, 163, 0, 0.13);
  line-height: 1.5;
}

.access-notice.show {
  display: block;
}

.system-note {
  padding: var(--space-2);
  border: 1px solid #31515a;
  border-radius: 8px;
}

.app {
  width: min(100%, var(--content-max));
  height: 100vh;
  min-width: 0;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  padding: var(--app-pad-top) var(--app-inline-pad);
  padding-bottom: 0;
  overflow-y: hidden;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.topbar {
  position: relative;
  top: auto;
  flex: 0 0 auto;
  z-index: 24;
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: flex-start;
  margin-bottom: var(--space-4);
  margin-left: calc(var(--app-inline-pad) * -1);
  margin-right: calc(var(--app-inline-pad) * -1);
  padding: 8px calc(10px + var(--app-inline-pad)) 10px;
  border-bottom: 1px solid rgba(0, 140, 120, 0.16);
  border-radius: 0 0 8px 8px;
  background: var(--bg);
  box-shadow: 0 10px 22px rgba(0, 55, 55, 0.06);
  backdrop-filter: blur(12px);
}

body[data-active-view="overview"] {
  --sticky-header-offset: 90px;
}

body:not([data-active-view="overview"]) .topbar {
  margin-bottom: var(--space-3);
}

body:not([data-active-view="overview"]) .topbar h1 {
  font-size: 24px;
}

body:not([data-active-view="overview"]) .subhead {
  display: none;
}

.top-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.audience-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #edf3f3;
}

.audience-switch a {
  min-width: 86px;
  padding: 8px 12px;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.audience-switch a:hover {
  color: var(--official-dark);
  background: rgba(255, 255, 255, 0.7);
}

.audience-switch a.active {
  color: #fff;
  background: var(--official-dark);
}

.role-picker {
  display: grid;
  gap: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.access-control .role-picker {
  border-color: #31515a;
  background: rgba(255, 255, 255, 0.08);
}

.role-picker span {
  color: var(--muted);
  font-size: 12px;
}

select[data-enhanced="true"],
.role-picker select {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  min-width: 0 !important;
  max-width: 1px !important;
  opacity: 0;
  pointer-events: none;
}

.access-control .role-picker span {
  color: #abc0c8;
}

.access-control .role-picker option {
  color: var(--ink);
}

.custom-select {
  position: relative;
  min-width: 0;
}

.custom-select-button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: none;
  text-align: left;
  font-weight: 700;
}

.custom-select-button::after {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  opacity: 0.75;
}

.custom-select.open .custom-select-button::after {
  transform: rotate(225deg) translate(-2px, -1px);
}

.custom-select-menu {
  position: absolute;
  z-index: 80;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: none;
  max-height: min(280px, 48vh);
  overflow: auto;
  padding: 6px;
  border: 1px solid rgba(17, 143, 168, 0.28);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(37, 50, 56, 0.18);
}

.access-control .custom-select-menu {
  top: auto;
  bottom: calc(100% + 4px);
  max-height: 220px;
}

.custom-select.open .custom-select-menu {
  display: grid;
  gap: 4px;
}

.custom-select-option {
  width: 100%;
  padding: 9px 10px;
  border-radius: 7px;
  color: var(--ink);
  background: transparent;
  box-shadow: none;
  text-align: left;
  overflow-wrap: anywhere;
}

.custom-select-option:hover,
.custom-select-option[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(90deg, var(--official-teal), var(--official-green));
}

.access-control .custom-select-button {
  border-color: rgba(103, 199, 216, 0.25);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.access-control .custom-select-menu {
  background: #ffffff;
}

.eyebrow {
  color: var(--official-green);
  font-weight: 700;
  margin: 0 0 6px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.18;
}

h2 {
  font-size: 18px;
}

.subhead,
.panel-title p {
  color: var(--muted);
  line-height: 1.55;
}

.subhead {
  margin-top: 8px;
}

.status {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 10px var(--space-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
}

.dot.ok {
  background: var(--green);
}

.ntmetro-hero {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) 1.45fr;
  gap: var(--space-2);
  align-items: stretch;
  margin-bottom: var(--space-2);
  padding: var(--space-3);
  border-radius: 8px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(16, 136, 168, 0.95), rgba(7, 58, 74, 0.98)),
    var(--official-dark);
  box-shadow: var(--shadow);
}

.hero-kicker {
  display: inline-flex;
  margin-bottom: 6px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  color: #e9fff7;
}

.ntmetro-hero h2 {
  font-size: 25px;
  margin-bottom: 6px;
}

.ntmetro-hero p {
  color: #d7f8ee;
}

.line-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
}

.line-card {
  min-height: 78px;
  padding: var(--space-2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.line-card b,
.line-card span {
  display: block;
}

.line-card b {
  font-size: 17px;
}

.line-card span {
  color: #d7f8ee;
  margin-top: 4px;
}

.line-card .badge {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--official-dark);
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: 72px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.metrics article,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  position: relative;
  padding: 12px 14px;
  overflow: visible;
}

.metrics article::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 38px;
  height: 38px;
  border-radius: 38px 0 7px;
  background: rgba(21, 151, 165, 0.12);
  pointer-events: none;
}

.metrics span {
  color: var(--muted);
}

.metrics strong {
  display: block;
  font-size: 27px;
  margin-top: 6px;
}

.grid {
  display: grid;
  gap: var(--space-3);
}

.grid.two,
.report-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.overview-grid {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-areas:
    "route route route route route route route route route route route route"
    "trend trend trend trend trend trend trend trend channel channel channel channel"
    "cost cost cost cost heat heat heat heat heat heat heat heat"
    "sync sync sync sync sync sync sync sync sync sync sync sync"
    "actions actions actions actions actions actions actions actions actions actions actions actions"
    ;
  align-items: stretch;
}

.overview-grid > .panel {
  height: auto;
  align-self: start;
}

.trend-panel,
.channel-panel {
  min-height: 245px;
}

.cost-panel,
.heat-panel,
.sync-panel {
  min-height: 0;
  overflow: hidden;
  container-type: inline-size;
}

.overview-section-bar {
  position: static;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-3) 0 var(--space-2);
  padding: 10px 14px;
  border: 1px solid rgba(0, 140, 120, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 28px rgba(0, 55, 55, 0.08);
  backdrop-filter: blur(10px);
}

.overview-section-bar div {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.overview-section-bar strong {
  color: var(--official-dark);
  font-size: 16px;
  white-space: nowrap;
}

.overview-section-bar span,
.overview-section-bar small {
  color: var(--muted);
}

.overview-section-bar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overview-section-bar small {
  flex: 0 0 auto;
}

.trend-panel {
  grid-area: trend;
}

.channel-panel {
  grid-area: channel;
  container-name: channel-panel;
  container-type: inline-size;
}

@container channel-panel (max-width: 300px) {
  .channel-panel .bar-row {
    grid-template-columns: minmax(54px, 0.72fr) minmax(48px, 1fr) max-content;
    gap: 6px;
  }
}

.cost-panel {
  grid-area: cost;
}

.action-panel {
  grid-area: actions;
}

.heat-panel {
  grid-area: heat;
}

.sync-panel {
  grid-area: sync;
}

.route-panel {
  grid-area: route;
}

.occ-grid {
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.78fr);
}

.agent-layout {
  display: grid;
  grid-template-columns: clamp(230px, 21%, 280px) minmax(0, 1fr) clamp(260px, 24%, 320px);
  gap: var(--space-3);
  align-items: stretch;
  height: 100%;
  min-height: 0;
}

#chat.view.active {
  padding-bottom: 0;
}

.panel {
  padding: var(--panel-pad);
  position: relative;
  min-width: 0;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: flex-start;
  margin-bottom: var(--space-3);
}

.panel-title input,
.panel-title select,
.chat-form input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 220px;
  max-width: 100%;
  background: #fff;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  background: var(--green);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(13, 127, 102, 0.18);
}

button.secondary {
  border: 1px solid var(--line);
  color: var(--official-dark);
  background: #fff;
  box-shadow: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  box-shadow: none;
}

button.is-busy {
  cursor: progress;
}

.button-spinner {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: buttonSpin 0.7s linear infinite;
}

@keyframes buttonSpin {
  to { transform: rotate(360deg); }
}

.view-toolbar {
  position: sticky;
  top: 0;
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 18px rgba(32, 47, 56, 0.06);
  backdrop-filter: blur(10px);
}

#lost > .panel > .panel-title {
  position: sticky;
  top: 0;
  z-index: 16;
  padding: 8px 0 10px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(10px);
}

.view-toolbar > div:first-child {
  display: grid;
  gap: 3px;
}

.view-toolbar > div:first-child span {
  color: var(--muted);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.toolbar-actions input {
  min-width: min(360px, 38vw);
}

.workflow-strip,
.knowledge-kpis,
.budget-alerts,
.maintenance-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.workflow-strip article,
.knowledge-kpis article,
.budget-alerts article,
.maintenance-status article {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.workflow-strip article {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 2px 8px;
}

.workflow-strip article > b {
  grid-row: 1 / 3;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--official-green);
}

.workflow-strip small,
.knowledge-kpis small,
.maintenance-status span {
  color: var(--muted);
}

.knowledge-kpis article,
.maintenance-status article {
  display: grid;
  gap: 4px;
}

.knowledge-kpis b,
.maintenance-status b {
  color: var(--official-dark);
  font-size: 22px;
}

.knowledge-layout {
  display: grid;
  grid-template-columns: minmax(210px, 0.48fr) minmax(0, 1.7fr) minmax(250px, 0.62fr);
  gap: var(--space-3);
  align-items: start;
}

.knowledge-folder-panel {
  position: sticky;
  top: var(--sticky-header-offset);
}

.knowledge-folder-panel .panel-title {
  align-items: center;
}

.knowledge-folder-panel .panel-title > button {
  width: 34px;
  height: 34px;
  padding: 0;
}

.knowledge-folder-tree {
  display: grid;
  gap: 3px;
}

.knowledge-folder-node {
  position: relative;
  display: flex;
  gap: 3px;
  align-items: center;
  padding-left: calc(var(--folder-depth, 0) * 15px);
  border-radius: 7px;
}

.knowledge-folder-node > button:first-child {
  min-width: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
  padding: 8px 7px;
  color: #44545c;
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.knowledge-folder-node > button b {
  overflow: hidden;
  text-overflow: ellipsis;
}

.knowledge-folder-node > button em {
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
}

.knowledge-folder-node.active {
  background: #e5f3f1;
}

.knowledge-folder-node.active > button:first-child {
  color: var(--official-dark);
}

.knowledge-folder-actions {
  display: none;
  gap: 2px;
}

.knowledge-folder-node:hover .knowledge-folder-actions,
.knowledge-folder-node:focus-within .knowledge-folder-actions {
  display: flex;
}

.knowledge-folder-actions button {
  width: 25px;
  height: 25px;
  padding: 0;
  color: #52636b;
  background: #fff;
  box-shadow: none;
}

.knowledge-folder-hint {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.knowledge-folder-move {
  max-width: 150px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.knowledge-list {
  display: grid;
  gap: 9px;
}

.knowledge-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.38fr);
  gap: var(--space-3);
  padding: 11px 12px;
  border: 1px solid #dce8eb;
  border-radius: 8px;
  background: #fbfdfd;
}

.knowledge-row h3 {
  margin: 3px 0 5px;
  color: var(--official-dark);
}

.knowledge-row h3,
.knowledge-row p,
.channel-config-card,
.action-card,
td,
th {
  min-width: 0;
  overflow-wrap: anywhere;
}

.knowledge-row p {
  color: #506069;
  line-height: 1.5;
}

.knowledge-row small {
  color: var(--muted);
}

.knowledge-row dl,
.channel-config-card dl {
  margin: 0;
}

.knowledge-row dl > div,
.channel-config-card dl > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #e7eff1;
}

.knowledge-row dl > div:last-child,
.channel-config-card dl > div:last-child {
  border-bottom: 0;
}

.knowledge-row dt,
.channel-config-card dt {
  color: var(--muted);
}

.knowledge-row dd,
.channel-config-card dd {
  margin: 0;
  text-align: right;
}

.knowledge-actions {
  grid-column: 1 / -1;
  display: flex !important;
  justify-content: flex-end !important;
  gap: 6px !important;
  padding-top: 8px !important;
}

.knowledge-actions button {
  padding: 6px 9px;
  font-size: 12px;
}

.knowledge-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.knowledge-tags span {
  padding: 2px 7px;
  border-radius: 999px;
  color: #0c6f88;
  background: #e6f5f3;
  font-size: 12px;
}

.governance-flow {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: governance;
}

.governance-flow li {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 10px 10px 10px 42px;
  border-radius: 8px;
  background: #eff8f7;
}

.governance-flow li::before {
  counter-increment: governance;
  content: counter(governance);
  position: absolute;
  top: 10px;
  left: 10px;
  display: grid;
  width: 23px;
  height: 23px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--official-dark);
  font-size: 12px;
}

.governance-flow span {
  color: var(--muted);
  line-height: 1.45;
}

.channel-config-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.channel-config-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.channel-config-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 17px;
}

.channel-config-card > label,
.app-dialog label {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.channel-config-card input,
.channel-config-card textarea,
.app-dialog input,
.app-dialog textarea,
.app-dialog select {
  width: 100%;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

.channel-config-card textarea,
.app-dialog textarea {
  resize: vertical;
  line-height: 1.45;
}

.inline-check {
  display: inline-flex !important;
  align-items: center;
  gap: 5px;
  margin: 0 !important;
  color: var(--official-green) !important;
}

.inline-check input {
  width: auto;
}

.app-dialog {
  width: min(680px, calc(100vw - 30px));
  max-height: calc(100vh - 40px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 28px 80px rgba(23, 32, 38, 0.3);
}

.app-dialog::backdrop {
  background: rgba(5, 38, 40, 0.58);
  backdrop-filter: blur(2px);
}

.app-dialog form {
  padding: 16px;
}

.app-dialog header,
.app-dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.app-dialog header {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: -16px -16px 4px;
  padding: 14px 16px 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
}

.app-dialog header > div {
  display: grid;
  gap: 3px;
}

.app-dialog header b {
  font-size: 19px;
}

.app-dialog header span {
  color: var(--muted);
}

.app-dialog footer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  margin: 8px -16px -16px;
  padding: 12px 16px;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
}

.app-dialog .dialog-close {
  flex: 0 0 auto;
  padding: 7px 10px;
}

.lost-item-dialog {
  width: min(760px, calc(100vw - 30px));
}

.decision-dialog {
  width: min(430px, calc(100vw - 30px));
}

.decision-message {
  margin: 16px 0 10px;
  color: #44545c;
  line-height: 1.6;
  white-space: pre-line;
}

.decision-message:empty {
  display: none;
}

.danger-button {
  color: #fff !important;
  background: #c83232 !important;
}

.dialog-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 4px 12px;
}

.dialog-wide {
  grid-column: 1 / -1;
}

.field-span-3 {
  grid-column: span 3;
}

.field-span-4 {
  grid-column: span 4;
}

.field-span-5 {
  grid-column: span 5;
}

.field-span-8 {
  grid-column: span 8;
}

.channel-config-card dl > div {
  align-items: flex-start;
}

.channel-config-card dd {
  max-width: 68%;
  color: #40515a;
  line-height: 1.4;
}

.policy-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
}

.policy-grid article {
  display: grid;
  gap: 5px;
  padding: 10px;
  border-left: 3px solid var(--official-teal);
  border-radius: 6px;
  background: #f3f8f9;
}

.policy-grid span {
  color: var(--muted);
  line-height: 1.45;
}

.budget-alerts article {
  display: flex;
  align-items: center;
  gap: 9px;
  box-shadow: none;
}

.budget-alerts article span {
  display: grid;
  min-width: 42px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  color: #775100;
  background: #fff0c7;
  font-weight: 700;
}

.budget-alerts article:last-child span {
  color: #fff;
  background: var(--red);
}

.bars {
  display: grid;
  gap: var(--space-2);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(92px, 128px) minmax(90px, 1fr) minmax(42px, 56px);
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
}

.bar-row span {
  color: #3f4c55;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row b {
  min-width: 0;
  text-align: right;
  white-space: nowrap;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e8eef1;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--official-green), var(--cyan));
}

.chart {
  min-height: clamp(210px, 25vh, 280px);
  overflow: hidden;
}

.chart.small {
  min-height: clamp(180px, 22vh, 230px);
}

.chart svg,
.donut svg {
  display: block;
  width: 100%;
  height: auto;
}

.axis-label {
  fill: #66737f;
  font-size: 11px;
}

.chart-line {
  fill: none;
  stroke: var(--teal);
  stroke-width: 3;
}

.chart-area {
  fill: rgba(21, 151, 165, 0.14);
}

.chart-point {
  fill: #ffffff;
  stroke: var(--teal);
  stroke-width: 2;
}

.donut {
  min-height: clamp(220px, 25vh, 280px);
}

.donut.compact {
  min-height: 0;
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: var(--space-2);
  align-items: center;
}

.donut.compact svg {
  max-width: 132px;
}

.donut.compact .donut-legend {
  margin-top: 0;
}

.donut-legend {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.legend-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  color: var(--muted);
}

.legend-row > span {
  min-width: 0;
  line-height: 1.4;
  word-break: keep-all;
}

.legend-row b {
  color: var(--ink);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
}

.heat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: var(--space-2);
}

.heat-cell {
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(23, 32, 38, 0.08);
  background: #eef5f7;
}

.heat-cell strong,
.heat-cell span {
  display: block;
}

.heat-cell strong {
  font-size: 21px;
  margin-bottom: 4px;
}

.heat-cell span {
  color: #51616c;
  line-height: 1.35;
}

.route-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  align-items: stretch;
}

.route-map {
  aspect-ratio: 1040 / 452;
  width: 100%;
  height: auto;
  max-height: min(56vh, 560px);
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f7fafb;
}

.route-map .train {
  filter: drop-shadow(0 3px 8px rgba(23, 32, 38, 0.22));
}

.route-map .route-case-label {
  fill: #22313a;
  font-size: 12px;
  font-weight: 700;
}

.route-map .incident-ring {
  fill: none;
  stroke: var(--red);
  stroke-width: 3;
  opacity: 0.85;
  transform-origin: center;
  animation: incidentPulse 1.8s ease-out infinite;
}

.route-map svg {
  display: block;
  width: 100%;
  height: 100%;
}

.station-node text {
  fill: #394952;
  font-size: 12px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.route-map .route-badge rect {
  filter: drop-shadow(0 3px 8px rgba(23, 32, 38, 0.18));
}

.route-map .route-badge-name {
  fill: #fff;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 2px;
}

.route-map .route-badge-sub {
  fill: rgba(255, 255, 255, 0.88);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.route-legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.route-legend header {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.route-legend header span {
  color: var(--muted);
}

.route-legend article {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 7px;
  align-items: center;
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.route-legend i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.route-legend span {
  font-weight: 700;
}

.route-legend b {
  color: var(--muted);
}

.route-legend .route-live {
  color: var(--green);
}

@keyframes incidentPulse {
  0% {
    r: 8;
    opacity: 0.9;
  }
  100% {
    r: 22;
    opacity: 0;
  }
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.action-card {
  display: block;
  min-height: 98px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: var(--space-2);
  text-align: left;
  color: var(--ink);
  background: #fff;
  box-shadow: none;
}

.action-card:last-child {
  border-right: 0;
}

.action-card:hover {
  background: #f2fbf7;
}

.action-card.urgent {
  border-color: rgba(200, 51, 73, 0.3);
  background: #fff8f9;
}

.action-card.urgent:hover {
  border-color: var(--red);
}

.action-card b,
.action-card span {
  display: block;
}

.action-card b {
  color: var(--official-dark);
  margin-bottom: 6px;
}

.action-card span {
  color: var(--muted);
  line-height: 1.4;
}

.sync-layout {
  display: grid;
  grid-template-columns: minmax(150px, 0.34fr) minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  min-width: 0;
}

/* 天氣每日快照狀態：沿用同一組 sync-stat 視覺，右側放來源說明與手動補撈 */
.weather-sync {
  display: grid;
  grid-template-columns: minmax(150px, 0.34fr) minmax(0, 1fr);
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--line);
}

.weather-sync-side {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.weather-sync-side p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  min-width: 0;
}

.weather-sync-side button {
  margin-left: auto;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .weather-sync {
    grid-template-columns: 1fr;
  }

  .weather-sync-side button {
    margin-left: 0;
  }
}

.sync-panel {
  overflow: hidden;
}

.sync-panel .bars,
.sync-panel .bar-row,
.sync-panel .bar-track {
  min-width: 0;
}

.sync-panel .bars {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 18px;
}

.sync-panel .bar-row {
  grid-template-columns: minmax(0, 1.1fr) minmax(60px, 0.9fr) max-content;
  gap: 8px;
}

.sync-panel .bar-row span {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.sync-panel .bar-row b {
  color: var(--official-dark);
}

.sync-stat {
  border-radius: 8px;
  padding: var(--space-3);
  background: linear-gradient(135deg, rgba(16, 136, 168, 0.12), rgba(49, 189, 210, 0.08));
  border: 1px solid var(--line);
}

.sync-stat span,
.sync-stat small {
  display: block;
  color: var(--muted);
}

.sync-stat strong {
  display: block;
  margin: 8px 0;
  font-size: 34px;
}

/* Dashboard widgets respond to their own card width, not only the viewport.
   This keeps labels readable when the sidebar or display scaling narrows a card. */
@container (max-width: 480px) {
  .sync-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .sync-stat {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 3px 10px;
    padding: 10px 12px;
  }

  .sync-stat span,
  .sync-stat small {
    grid-column: 1;
  }

  .sync-stat strong {
    grid-column: 2;
    grid-row: 1 / 3;
    margin: 0;
  }

  .sync-panel .bar-row {
    grid-template-columns: minmax(88px, 1fr) minmax(72px, 0.9fr) max-content;
  }
}

@container (max-width: 390px) {
  .donut.compact {
    grid-template-columns: minmax(92px, 108px) minmax(0, 1fr);
    gap: 10px;
  }

  .donut.compact svg {
    max-width: 108px;
  }

  .donut-legend {
    gap: 5px;
  }

  .legend-row {
    gap: 6px;
    font-size: 12px;
  }

  .legend-dot {
    width: 8px;
    height: 8px;
    margin-right: 5px;
  }
}

.layers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.layers div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.layers b,
.layers span {
  display: block;
}

.layers span {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
}

.queue-panel,
.context-panel {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.queue-panel,
.chat-panel,
.context-panel {
  border-color: rgba(17, 143, 168, 0.16);
  box-shadow: 0 8px 24px rgba(32, 47, 56, 0.06);
}

.queue-panel .panel-title,
.context-panel .panel-title {
  padding-bottom: 10px;
  border-bottom: 1px solid #e6eef0;
}

.queue-panel .panel-title p,
.context-panel .panel-title p {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.4;
}

.queue-panel {
  container-name: queue-panel;
  container-type: inline-size;
}

.context-panel {
  container-name: context-panel;
  container-type: inline-size;
}

@container queue-panel (max-width: 200px) {
  .service-stats {
    gap: 5px;
  }

  .service-stat {
    padding: 7px 5px;
  }

  .service-stat span {
    font-size: 10px;
    white-space: nowrap;
  }
}

@container context-panel (max-width: 240px) {
  .handoff-actions {
    gap: 6px;
  }

  .handoff-actions button {
    padding: 8px 6px;
    font-size: 12px;
    white-space: nowrap;
  }
}

@container context-panel (max-width: 300px) {
  .context-list article {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .context-list b {
    text-align: left;
  }
}

.queue-list,
.context-list,
.advisor-list {
  display: grid;
  gap: 8px;
}

.queue-list {
  max-height: calc(var(--workspace-height) - 100px);
  overflow: auto;
  padding-right: 2px;
}

.service-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid rgba(0, 140, 120, 0.18);
  border-radius: 8px;
  background: #f4fbf9;
}

.service-stat {
  min-width: 0;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7px 5px;
  border: 0;
  border-right: 1px solid rgba(0, 140, 120, 0.15);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
  cursor: pointer;
}

.service-stat:last-child {
  border-right: 0;
}

.service-stat:hover {
  color: var(--official-dark);
  background: #e8f5f3;
}

.service-stat.active {
  color: #fff;
  background: var(--official-dark);
}

.service-stat.active span,
.service-stat.active b {
  color: #fff;
}

.service-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
}

.service-stat b {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.15;
}

.queue-item {
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: 8px;
  padding: 10px 11px;
  text-align: left;
  color: var(--ink);
  background: #fff;
  box-shadow: none;
}

.queue-item.active {
  border-left-color: var(--official-green);
  background: #f3fbf7;
}

.queue-item.urgent {
  border-left-color: var(--red);
  background: #fff8f9;
}

.queue-item b,
.queue-item span,
.queue-item small {
  display: block;
}

.queue-item span {
  margin-top: 6px;
  color: var(--official-dark);
  font-weight: 700;
}

.queue-item small {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.4;
}

.queue-item em {
  display: block;
  margin-top: 7px;
  color: var(--official-teal);
  font-style: normal;
  font-weight: 800;
}

.service-session-list {
  max-height: calc(var(--workspace-height) - 190px);
}

.service-session b,
.service-session small,
.service-session em:not(.session-confidence) {
  overflow-wrap: anywhere;
}

.session-state,
.session-confidence {
  display: flex !important;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 6px;
  row-gap: 2px;
}

.session-state {
  font-size: 13px;
}

.session-state .session-status {
  padding: 2px 6px;
  border-radius: 999px;
  color: #0c6f88;
  background: #e4f4f0;
  font-size: 12px;
}

.session-state i,
.session-confidence i {
  font-style: normal;
  line-height: 1.35;
  white-space: nowrap;
}

.session-confidence i + i {
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--official-dark);
  background: #eaf5f4;
  font-size: 12px;
}

.ui-icon,
.button-icon,
.context-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.session-topline {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 0 !important;
  color: var(--ink) !important;
}

.session-contact,
.session-status,
.session-footer,
.confidence-visual,
.session-case,
.conversation-channel {
  display: inline-flex !important;
  align-items: center;
}

.session-contact {
  min-width: 0;
  gap: 6px;
  margin-top: 0 !important;
  color: var(--ink) !important;
}

.session-contact b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-status {
  flex: 0 0 auto;
  gap: 4px;
  margin-top: 0 !important;
  padding: 3px 6px;
  border-radius: 999px;
  color: #0c6f88 !important;
  background: #e4f4f0;
  font-size: 11px;
  line-height: 1;
}

.session-status.waiting_human {
  color: #9a5a00 !important;
  background: #fff2d8;
}

.session-status i,
.session-case i,
.conversation-channel i {
  font-style: normal;
  white-space: nowrap;
}

.queue-item .session-intent {
  margin-top: 7px;
  color: var(--official-dark);
  font-size: 13px;
  line-height: 1.3;
}

.session-preview {
  display: block !important;
  min-height: 0;
  overflow: visible;
  white-space: normal;
  word-break: break-word;
}

.session-footer {
  width: 100%;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px !important;
  color: var(--official-teal) !important;
}

.session-footer .session-intent {
  width: auto;
  max-width: 100%;
  margin: 0 auto 0 0;
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--official-dark);
  background: #eef7f6;
  font-size: 12px;
  line-height: 1.25;
}

.service-filter-empty {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 150px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.service-filter-empty b {
  color: var(--ink);
}

.service-filter-empty span {
  margin-top: 5px;
  font-size: 12px;
}

.channel-switch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(135deg, #ffffff, #eef7f6);
}

.channel-switch-label {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.channel-switch-label b {
  font-size: 15px;
  color: var(--official-dark);
}

.channel-switch-label span {
  font-size: 12px;
  color: var(--muted);
}

.service-channel-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.service-channel-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  box-shadow: none;
  font-size: 13.5px;
  font-weight: 700;
}

.service-channel-tabs button .ch-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  background: var(--muted);
}

.service-channel-tabs button .ch-ic.ch-all { background: var(--official-dark); }
.service-channel-tabs button .ch-ic.ch-web { background: #0c7a92; }
.service-channel-tabs button .ch-ic.ch-line { background: #06c755; }
.service-channel-tabs button .ch-ic.ch-fb { background: #1877f2; }

.service-channel-tabs button b {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  color: inherit;
  background: rgba(37, 50, 56, 0.08);
  font-size: 12px;
  text-align: center;
}

.service-channel-tabs button:hover {
  border-color: var(--official-teal);
  color: var(--official-dark);
}

.service-channel-tabs button.active {
  border-color: var(--official-dark);
  color: #fff;
  background: var(--official-dark);
}

.service-channel-tabs button.active b {
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
}

@media (max-width: 720px) {
  .service-channel-tabs button .ch-name { display: none; }
  .service-channel-tabs { width: 100%; }
  .service-channel-tabs button { flex: 1; justify-content: center; }
}

.confidence-visual {
  min-width: 0;
  gap: 5px;
  margin-top: 0 !important;
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--official-teal) !important;
  background: #e9f5f4;
}

.confidence-track {
  width: 42px;
  height: 5px;
  margin-top: 0 !important;
  overflow: hidden;
  border-radius: 999px;
  background: #dce9ec;
}

.confidence-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: currentColor;
}

.confidence-visual b {
  font-size: 12px;
  line-height: 1;
}

.session-case {
  gap: 4px;
  margin-top: 0 !important;
  padding: 2px 5px;
  border-radius: 6px;
  color: var(--official-dark) !important;
  background: #eaf5f4;
  font-size: 11px;
}

.chat-tools {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.chat-tools button,
.handoff-actions button,
.chat-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
}

.chat-panel {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  container-name: chat-panel;
  container-type: inline-size;
}

.chat-panel > .panel-title {
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid #e6eef0;
}

.chat-panel > .panel-title p {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.4;
}

@container chat-panel (max-width: 620px) {
  .chat-panel .panel-title {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-tools {
    justify-content: flex-end;
  }

  .chat-tools .custom-select {
    min-width: 108px;
  }

  .chat-tools button {
    white-space: nowrap;
  }

  .service-conversation-meta {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .service-conversation-meta small {
    grid-column: 1 / -1;
    margin-left: 0;
    text-align: right;
  }
}

.service-conversation-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: 10px;
  padding: 9px 11px;
  border: 1px solid rgba(17, 143, 168, 0.2);
  border-radius: 8px;
  background: #f4fbfb;
}

.service-conversation-meta span {
  color: var(--blue);
  font-weight: 900;
  white-space: nowrap;
}

.service-conversation-meta b {
  color: var(--official-dark);
  white-space: nowrap;
}

.conversation-channel {
  gap: 5px;
}

.service-conversation-meta small {
  margin-left: auto;
  color: var(--muted);
}

@container chat-panel (max-width: 620px) {
  .chat-panel .service-conversation-meta {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .chat-panel .service-conversation-meta small {
    grid-column: 1 / -1;
    margin-left: 0;
    text-align: right;
  }
}

.chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: 12px;
  background: #f6fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.message {
  max-width: 76%;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.6;
  background: #e7eef4;
  box-shadow: 0 2px 6px rgba(32, 47, 56, 0.06);
}

.handoff-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  margin-top: 12px;
}

.handoff-actions button {
  min-height: 44px;
  gap: 6px;
}

.button-icon {
  width: 18px;
  height: 18px;
}

.handoff-actions button + button {
  color: var(--official-dark);
  background: #e9f6f3;
  box-shadow: none;
}

.message a,
.assistant-message a {
  color: var(--blue);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  background: #d9efe9;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.chat-form input {
  min-width: 0;
}

.context-list article,
.advisor-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.context-list {
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
}

.context-list article {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(88px, auto) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #e6eef0;
  border-radius: 0;
  background: transparent;
}

.context-list article:last-child {
  border-bottom: 0;
}

.context-list .context-summary-item {
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 10px;
}

.context-icon {
  width: 20px;
  height: 20px;
  color: var(--official-teal);
}

.context-copy {
  min-width: 0;
}

.context-copy span {
  margin: 0;
}

.context-copy b {
  margin-top: 3px;
  text-align: left;
}

.context-list span,
.advisor-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.context-list span {
  line-height: 1.35;
}

.context-list b {
  display: block;
  margin-top: 0;
  line-height: 1.4;
  text-align: right;
  overflow-wrap: anywhere;
}

.assistant-advisor {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #e6eef0;
}

.assistant-advisor h3 {
  margin: 0 0 var(--space-2);
  font-size: 16px;
}

.advisor-card h4 {
  margin: 6px 0;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.advisor-card p {
  color: var(--muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.advisor-card a {
  display: inline-block;
  margin-top: 8px;
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.advisor-list {
  max-height: 330px;
  overflow: auto;
  padding-right: 2px;
}

.inspector {
  display: none;
  margin-top: var(--space-3);
  min-height: 120px;
  max-height: 180px;
  padding: 12px;
  white-space: pre-wrap;
  background: #0f3540;
  color: #d9f4ec;
  border-radius: 8px;
  overflow: auto;
}

.table-wrap {
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--muted);
  font-size: 14px;
  background: #fff;
  white-space: nowrap;
}

#lost table th:nth-child(1),
#lost table td:nth-child(1) {
  width: 15ch;
}

#lost table th:nth-child(2),
#lost table td:nth-child(2),
#lost table th:nth-child(7),
#lost table td:nth-child(7) {
  width: 9ch;
}

#lost table th:nth-child(3),
#lost table td:nth-child(3) {
  min-width: 24ch;
}

.case-table th:nth-child(1),
.case-table td:nth-child(1) {
  width: 15ch;
}

.case-table th:nth-child(2),
.case-table td:nth-child(2),
.case-table th:nth-child(3),
.case-table td:nth-child(3) {
  width: 8ch;
}

.case-table th:nth-child(6),
.case-table td:nth-child(6),
.case-table th:nth-child(7),
.case-table td:nth-child(7) {
  min-width: 14ch;
}

tbody tr:hover {
  background: #f7fafb;
}

tbody tr.selected {
  background: #eef8f4;
  box-shadow: inset 3px 0 0 var(--official-green);
}

.link-button {
  padding: 0;
  border-radius: 0;
  color: var(--blue);
  background: transparent;
  box-shadow: none;
  font-weight: 800;
}

.case-workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--space-3);
  height: min(760px, calc(100vh - 150px));
  min-height: 520px;
  padding-top: 0;
}

.case-sticky-header {
  position: relative;
  z-index: 12;
  display: grid;
  gap: 10px;
  margin: calc(var(--panel-pad) * -1) calc(var(--panel-pad) * -1) 0;
  padding: 12px var(--panel-pad);
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 22px rgba(32, 47, 56, 0.06);
  backdrop-filter: blur(10px);
}

.case-sticky-header .panel-title {
  margin-bottom: 0;
}

.case-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.case-stats article {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7fafb;
}

.case-stats span,
.case-detail span,
.case-summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.case-stats b {
  display: inline;
  margin-top: 0;
  font-size: 15px;
}

.case-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(145px, 170px) minmax(145px, 170px);
  gap: var(--space-2);
}

.case-toolbar input,
.case-toolbar select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.case-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.58fr) minmax(360px, 0.78fr);
  gap: var(--space-3);
  align-items: start;
  min-height: 0;
  overflow: hidden;
}

.case-table {
  min-width: 0;
  table-layout: fixed;
}

.case-table th:nth-child(1),
.case-table td:nth-child(1) {
  width: 15%;
}

.case-table th:nth-child(2),
.case-table td:nth-child(2),
.case-table th:nth-child(3),
.case-table td:nth-child(3) {
  width: 10%;
}

.case-table th:nth-child(4),
.case-table td:nth-child(4),
.case-table th:nth-child(5),
.case-table td:nth-child(5) {
  width: 13%;
}

.case-table th:nth-child(6),
.case-table td:nth-child(6),
.case-table th:nth-child(7),
.case-table td:nth-child(7),
.case-table th:nth-child(8),
.case-table td:nth-child(8) {
  width: 13%;
}

.case-table td {
  overflow-wrap: anywhere;
}

.case-table th {
  top: 0;
}

.case-table small,
.sla small,
.case-detail small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.summary-cell {
  max-width: 260px;
  line-height: 1.45;
}

.sla {
  display: inline-block;
  font-weight: 800;
}

.sla.overdue,
.sla-text.overdue {
  color: var(--red);
}

.sla.due_soon,
.sla-text.due_soon {
  color: var(--amber);
}

.sla.on_track,
.sla-text.on_track,
.sla.closed,
.sla-text.closed {
  color: var(--green);
}

.case-detail {
  position: static;
  display: grid;
  gap: var(--space-3);
  height: 100%;
  min-height: 420px;
  overflow: auto;
  padding: var(--panel-pad);
  padding-bottom: calc(var(--panel-pad) + 96px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.case-detail header {
  display: grid;
  gap: 8px;
}

.case-detail header b {
  font-size: 22px;
}

.case-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.case-detail-grid article {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
}

.case-detail-grid b {
  display: block;
  margin-top: 6px;
  line-height: 1.4;
}

.case-summary {
  display: grid;
  gap: 8px;
}

.case-summary p {
  line-height: 1.6;
}

.case-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.case-actions button {
  min-height: 44px;
  padding: 9px 10px;
}

.empty-state {
  display: grid;
  place-content: center;
  gap: 8px;
  min-height: 280px;
  text-align: center;
  color: var(--muted);
}

.empty-state b {
  color: var(--ink);
}

.case-table-wrap {
  height: 100%;
  min-height: 0;
}

.voice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
}

.voice-command {
  display: grid;
  gap: var(--space-3);
}

.voice-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(0, 140, 120, 0.22);
  border-radius: 8px;
  background: #f5fbf9;
  color: var(--official-dark);
}

.voice-agent-controls {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
}

.voice-agent-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.voice-agent-controls .custom-select {
  width: 150px;
}

.voice-agent-controls .custom-select-button {
  min-height: 38px;
  padding: 8px 10px;
}

.voice-kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-2);
}

.voice-kpis article {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #fff, #f2fbfa);
}

.voice-kpis span,
.voice-kpis small,
.voice-section-title span,
.voice-detail span,
.voice-transcript span,
.scenario-card span,
.scenario-card small {
  color: var(--muted);
}

.voice-kpis b {
  display: block;
  margin: 5px 0 2px;
  font-size: 23px;
}

.voice-main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
  gap: var(--space-3);
  min-height: 0;
}

/* 三欄：左=所有案件、中=案件資訊/摘要、右=訊息 */
.voice-main-grid.voice-triple {
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1fr) minmax(0, 1.25fr);
  align-items: stretch;
}

/* 中窄寬度（筆電/側欄佔位）：訊息獨占整列，避免三欄擠壓橫向溢出 */
@media (max-width: 1180px) and (min-width: 901px) {
  .voice-main-grid.voice-triple {
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  }

  .voice-main-grid.voice-triple .voice-messages {
    grid-column: 1 / -1;
  }
}

.voice-messages {
  display: flex;
  flex-direction: column;
  min-height: 560px;
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.voice-messages-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.voice-messages-head b { font-size: 17px; }
.voice-messages-head small { color: var(--muted); }

.voice-messages-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.voice-messages .voice-thread {
  display: grid;
  gap: 10px;
}

.voice-messages .voice-reply-form {
  margin-top: 12px;
  flex-shrink: 0;
}

.voice-calls {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.voice-section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.voice-queue-toolbar {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.voice-queue-toolbar h3 {
  margin: 0;
  font-size: 17px;
}

.voice-filter-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f8f9;
}

.voice-filter-tabs button {
  min-width: 0;
  padding: 7px 5px;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
  font-size: 12px;
  white-space: nowrap;
}

.voice-filter-tabs button.active {
  color: #fff;
  background: var(--official-dark);
}

.voice-filter-tabs b {
  display: inline-block;
  margin-left: 3px;
}

.voice-section-title h3 {
  margin: 0;
  font-size: 18px;
}

.voice-call-list {
  display: grid;
  gap: var(--space-2);
  min-height: 0;
  max-height: 520px;
  overflow: auto;
  padding-right: 2px;
}

.voice-call-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--official-teal);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.voice-call-card.selected {
  border-color: rgba(0, 140, 120, 0.46);
  border-left-color: var(--official-green);
  background: #eef8f4;
}

.voice-call-card.queued {
  border-left-color: var(--amber);
}

.voice-call-card.handoff,
.voice-call-card.alert {
  border-left-color: var(--red);
}

.voice-call-card.fallback {
  border-left-color: var(--blue);
}

.voice-call-card.completed {
  border-left-color: #91a1a8;
  background: #fafcfc;
}

.voice-call-top,
.voice-call-meta {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}

.voice-call-top b,
.voice-call-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-call-top i {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e9f6f3;
  color: var(--official-dark);
  font-style: normal;
  font-size: 13px;
  font-weight: 800;
}

.voice-call-meta em,
.voice-call-meta small {
  min-width: 0;
  color: var(--muted);
  font-style: normal;
}

.voice-detail {
  display: grid;
  gap: var(--space-3);
  min-height: 520px;
  overflow: auto;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.voice-detail header {
  display: grid;
  gap: 8px;
}

.voice-detail header b {
  font-size: 22px;
}

/* ── 中欄重新設計：案件重點資訊卡 ── */
.voice-info-hero {
  position: relative;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    radial-gradient(120px 120px at 88% -20%, rgba(255, 255, 255, 0.12), transparent 70%),
    linear-gradient(135deg, #0a4c5e, #0c7a92);
  color: #fff;
  overflow: hidden;
}

.voice-info-hero.human_active {
  background:
    radial-gradient(120px 120px at 88% -20%, rgba(255, 255, 255, 0.14), transparent 70%),
    linear-gradient(135deg, #0d6f57, #12a67f);
}
.voice-info-hero.alert,
.voice-info-hero.handoff {
  background:
    radial-gradient(120px 120px at 88% -20%, rgba(255, 255, 255, 0.14), transparent 70%),
    linear-gradient(135deg, #a12f3f, #d94272);
}
.voice-info-hero.completed {
  background:
    radial-gradient(120px 120px at 88% -20%, rgba(255, 255, 255, 0.12), transparent 70%),
    linear-gradient(135deg, #55676e, #7d9199);
}

.voice-info-hero-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.voice-status-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 13px;
  border-radius: 999px;
  background: #fff;
  color: var(--official-dark);
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.voice-info-hero.human_active .voice-status-chip { color: #0d6f57; }
.voice-info-hero.alert .voice-status-chip,
.voice-info-hero.handoff .voice-status-chip { color: #a12f3f; }
.voice-info-hero.completed .voice-status-chip { color: #55676e; }

.voice-info-time {
  position: relative;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
}

.voice-info-callno {
  position: relative;
  margin: 12px 0 10px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.voice-info-caller {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.voice-info-caller b { font-weight: 800; }

.voice-info-caller span {
  color: rgba(255, 255, 255, 0.75);
  font-size: 12.5px;
}

.voice-caller-ic {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 1.8;
}

.voice-info-list {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.voice-info-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 15px;
}

.voice-info-row + .voice-info-row {
  border-top: 1px solid var(--line);
}

.voice-info-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 9px;
  background: #e9f5f4;
}

.voice-info-ic svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--official-dark);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.voice-info-copy {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 3px;
}

.voice-info-copy > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.voice-info-copy > b {
  font-size: 15px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.voice-info-copy small {
  color: var(--muted);
  font-size: 12px;
}

.voice-conf {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 10px;
}

.voice-conf b {
  grid-row: 1;
  font-size: 18px;
  font-weight: 800;
  color: var(--official-dark);
}

.voice-conf-bar {
  grid-row: 1;
  height: 7px;
  border-radius: 999px;
  background: #e4edee;
  overflow: hidden;
}

.voice-conf-bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--official-teal);
}

.voice-conf-bar.high i { background: var(--official-green); }
.voice-conf-bar.mid i { background: var(--official-teal); }
.voice-conf-bar.low i { background: var(--amber); }

.voice-conf small {
  grid-column: 1 / -1;
  grid-row: 2;
}

.voice-transcript {
  display: grid;
  gap: 8px;
}

.voice-transcript p {
  margin: 0 0 4px;
  line-height: 1.65;
}

.voice-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.voice-actions button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  font-weight: 700;
}

.voice-actions button span {
  color: inherit;
}

.voice-actions button.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #0a4c5e, #0c7a92);
  box-shadow: 0 6px 16px rgba(12, 122, 146, 0.28);
}

.voice-actions button.ghost {
  border: 1px solid var(--line);
  color: var(--official-dark);
  background: #fff;
  box-shadow: none;
}

.voice-actions button.ghost:hover:not(:disabled) {
  border-color: var(--official-teal);
  background: #f2fbfa;
}

.voice-actions button:disabled {
  opacity: 0.5;
  box-shadow: none;
  cursor: not-allowed;
}

.voice-actions .fallback-active {
  color: #6d4900;
  background: #fff1cf;
  box-shadow: none;
}

.voice-action-feedback {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid rgba(0, 140, 120, 0.22);
  border-radius: 8px;
  color: #0c6f88;
  background: #edf9f5;
  font-size: 13px;
  font-weight: 700;
}

.voice-queue-empty {
  min-height: 180px;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
}

.voice-history {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.voice-history-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.voice-history-title span {
  font-size: 12px;
}

.voice-summary-card {
  padding: 13px 15px;
  border: 1px solid #cfe6e3;
  border-left: 4px solid var(--official-teal);
  border-radius: 10px;
  background: linear-gradient(135deg, #f4fbfa, #eef8f6);
}

.voice-summary-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}

.voice-summary-head b {
  font-size: 14px;
  color: var(--official-dark);
}

.voice-summary-head svg {
  width: 16px;
  height: 16px;
  fill: var(--official-teal);
  stroke: none;
}

.voice-summary-card p {
  margin: 0;
  color: #445862;
  font-size: 13.5px;
  line-height: 1.65;
}

.voice-history-list {
  display: grid;
  gap: 7px;
}

.voice-history-item {
  max-width: 88%;
  padding: 9px 10px;
  border-radius: 8px;
  background: #e8eff4;
}

.voice-history-item.passenger {
  justify-self: end;
  background: #dff1ec;
}

.voice-history-item.system,
.voice-history-item.agent {
  max-width: 100%;
  justify-self: stretch;
  border: 1px dashed rgba(17, 143, 168, 0.3);
  background: #f4f9fa;
}

.voice-history-item header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.voice-history-item time {
  color: var(--muted);
  font-size: 11px;
}

.voice-history-item p {
  margin: 0;
  line-height: 1.45;
}

.voice-side {
  display: grid;
  gap: var(--space-3);
}

.voice-bars + .voice-bars {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

.scenario-list {
  display: grid;
  gap: var(--space-2);
}

.scenario-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 6px 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.scenario-card.pass {
  border-left: 4px solid var(--official-green);
}

.scenario-card.watch {
  border-left: 4px solid var(--amber);
}

.scenario-card b,
.scenario-card span,
.scenario-card small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.scenario-card strong {
  color: var(--official-dark);
}

.scenario-card small {
  grid-column: 1 / -1;
}

.pill {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8eef1;
  color: var(--ink);
  white-space: nowrap;
}

.budget-alerts article span {
  min-width: 52px;
}

.pill.urgent,
.alarm-label {
  background: #ffe4e8;
  color: var(--red);
}

.pill.low {
  background: #edf5ff;
  color: var(--blue);
}

.pill.normal {
  background: #e8f5f1;
  color: var(--green);
}

.pill.reserved,
.pill.in_progress {
  background: #fff3d6;
  color: var(--amber);
}

.pill.closed,
.pill.claimed {
  background: #eef1f3;
  color: var(--muted);
}

.emergency-list {
  display: grid;
  gap: var(--space-2);
}

/* ===== OCC 緊急事件看板 =====
   嚴重度用左側色條分層、時間顯示「幾分鐘前」、位置與案號拆成獨立標籤，
   控制員掃一眼就能排出處理順序。 */
.occ-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
  margin-bottom: var(--space-2);
}

.occ-stat {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff, #f7fbfc);
}

.occ-stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.occ-stat b {
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--official-dark);
}

.occ-stat b small {
  margin-left: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.occ-stat.pending:not(.is-zero) { border-color: rgba(245, 163, 0, 0.5); background: linear-gradient(180deg, #fffaf0, #fff6e6); }
.occ-stat.pending:not(.is-zero) b { color: #a4600b; }
.occ-stat.critical:not(.is-zero) { border-color: rgba(200, 51, 73, 0.5); background: linear-gradient(180deg, #fff6f7, #ffedef); }
.occ-stat.critical:not(.is-zero) b { color: var(--red); }
.occ-stat.await:not(.is-zero) { border-color: rgba(13, 132, 160, 0.42); background: linear-gradient(180deg, #f4fbfd, #eaf6fa); }
.occ-stat.is-zero b { color: var(--muted); }

.occ-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line);
}

.occ-filters button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  box-shadow: none;
  cursor: pointer;
}

.occ-filters button em {
  font-style: normal;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #eef4f6;
  color: var(--ink);
  font-size: 12px;
  text-align: center;
}

.occ-filters button:hover { border-color: var(--official-teal); color: var(--official-dark); }
.occ-filters button.active { border-color: var(--official-dark); background: var(--official-dark); color: #fff; }
.occ-filters button.active em { background: rgba(255, 255, 255, 0.22); color: #fff; }
.occ-filters button.is-zero:not(.active) { opacity: 0.55; }

.emg-card {
  position: relative;
  display: grid;
  grid-template-columns: 5px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(32, 47, 56, 0.05);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.emg-card:hover { box-shadow: 0 8px 20px rgba(32, 47, 56, 0.1); transform: translateY(-1px); }
.emg-rail { background: var(--sev, #8fa3ab); }
.emg-body { padding: 12px 14px; min-width: 0; }

.emg-card.sev-critical { --sev: #c83349; }
.emg-card.sev-high { --sev: #f5a300; }
.emg-card.sev-medium { --sev: #0d84a0; }

/* 已確認的單降低視覺重量，待處理的才搶眼 */
.emg-card.is-done { background: #fbfdfd; }
.emg-card.is-done .emg-body { opacity: 0.72; }
.emg-card.is-pending.sev-critical { border-color: rgba(200, 51, 73, 0.55); background: linear-gradient(100deg, rgba(200, 51, 73, 0.07), #fff 46%); }
.emg-card.is-pending.sev-high { border-color: rgba(245, 163, 0, 0.5); }

.emg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.emg-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  min-width: 0;
}

.emg-sev {
  flex: 0 0 auto;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--sev);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.emg-time {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.emg-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.emg-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7fafb;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}

.emg-chip.line i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #8fa3ab); }
.emg-chip.station::before { content: "📍"; font-size: 11px; }
.emg-chip.station.pendingloc { border-style: dashed; border-color: rgba(214, 158, 46, 0.6); background: #fff8e8; color: #8a6d00; }
.emg-chip.type { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.4px; }
.emg-chip.stale { border-color: rgba(200, 51, 73, 0.45); background: #fff1f3; color: var(--red); }

.emg-transcript {
  margin: 9px 0 0;
  padding: 8px 11px;
  border-left: 3px solid var(--line);
  border-radius: 0 8px 8px 0;
  background: #f6fafb;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.emg-foot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.emg-state { color: var(--muted); font-size: 12.5px; font-weight: 700; }
.emg-card.is-pending.sev-critical .emg-state { color: var(--red); }
.emg-foot button { margin-left: auto; padding: 7px 16px; font-size: 13px; }
.emg-done { margin-left: auto; color: var(--official-green); font-size: 12.5px; font-weight: 700; }

/* 待確認超過 5 分鐘：整張卡呼吸式提示，避免被漏在清單裡 */
.emg-card.is-stale { animation: alertPulse 1.6s ease-in-out infinite; }

.emg-empty {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 34px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fbfdfd;
  text-align: center;
}

.emg-empty b { font-size: 15px; }
.emg-empty span { color: var(--muted); font-size: 13px; }

.ops-list,
.sla-list {
  display: grid;
  gap: var(--space-2);
}

.admin-layout,
.aiops-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.9fr);
  gap: var(--space-3);
  align-items: start;
}

.permission-table td:not(:first-child),
.permission-table th:not(:first-child) {
  text-align: center;
}

.admin-layout table {
  min-width: 0;
  table-layout: fixed;
}

.admin-layout th,
.admin-layout td {
  padding: 11px 10px;
  overflow-wrap: anywhere;
}

.permission-table th,
.permission-table td {
  font-size: 14px;
}

.usage-mix {
  display: grid;
  gap: var(--space-2);
}

.usage-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: var(--space-2);
  background: #fff;
}

.usage-card header,
.usage-card footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: center;
}

.usage-card h3 {
  margin: 0;
  font-size: 16px;
}

.usage-card header span,
.usage-card footer {
  color: var(--muted);
}

.usage-card footer {
  margin-top: 8px;
  font-size: 13px;
  flex-wrap: wrap;
}

.stacked-bar {
  display: flex;
  height: 14px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef1;
}

.stacked-bar i {
  display: block;
  min-width: 4px;
}

.stacked-bar .input {
  width: var(--input);
  background: var(--official-green);
}

.stacked-bar .output {
  width: var(--output);
  background: var(--blue);
}

.stacked-bar .cached {
  width: var(--cached);
  background: var(--amber);
}

.ops-card,
.sla-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: var(--space-2);
  background: #fff;
}

.ops-card header,
.sla-card header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: 10px;
}

.ops-card h3,
.sla-card h3 {
  margin: 0;
  font-size: 16px;
}

.ops-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  color: var(--muted);
}

.ops-meta b {
  display: block;
  color: var(--ink);
  font-size: 18px;
}

.progress {
  height: 8px;
  background: #e8eef1;
  border-radius: 999px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--cyan));
}

.assistant-widget {
  position: fixed;
  right: clamp(14px, 2vw, 28px);
  bottom: clamp(20px, 3vw, 42px);
  z-index: 40;
}

.assistant-toggle {
  min-width: 92px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  background: var(--official-dark);
}

.assistant-toggle svg {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.assistant-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: min(420px, calc(100vw - 28px));
  max-height: min(640px, calc(100vh - 100px));
  display: none;
  grid-template-rows: auto minmax(220px, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 64px rgba(23, 32, 38, 0.22);
}

.assistant-panel.open {
  display: grid;
}

.assistant-panel header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3);
  color: #fff;
  background: linear-gradient(135deg, var(--official-dark), var(--green));
}

.assistant-panel header span {
  display: block;
  margin-top: 4px;
  color: #d7f8ee;
  font-size: 13px;
}

.assistant-panel header button {
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: none;
}

.assistant-log {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  overflow: auto;
  background: #f7faf9;
}

.assistant-message {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.6;
  white-space: pre-wrap;
  background: #e7eef4;
}

.assistant-message.user {
  align-self: flex-end;
  background: #d9efe9;
}

.assistant-message small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.assistant-sources {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(23, 32, 38, 0.1);
}

.assistant-sources a {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  text-decoration: none;
}

.assistant-sources a:hover {
  border-color: var(--blue);
}

.assistant-sources a[aria-disabled="true"] {
  color: var(--muted);
  pointer-events: none;
}

.assistant-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--line);
}

.assistant-form input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 90;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid rgba(17, 143, 168, 0.24);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(37, 50, 56, 0.18);
  pointer-events: auto;
  animation: toastIn 0.18s ease-out;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(-6px);
}

.toast.success {
  border-color: rgba(0, 140, 120, 0.32);
}

.toast.success .toast-dot {
  background: var(--official-green);
}

.toast.error {
  border-color: rgba(200, 51, 73, 0.38);
  background: #fff8f9;
}

.toast.error .toast-dot {
  background: var(--red);
}

/* OCC 新警訊：一般等級用琥珀色，危險等級用紅色並持續閃動，讓人在其他分頁也會注意到 */
.toast.warning {
  border-color: rgba(214, 158, 46, 0.42);
  background: #fffaf0;
}

.toast.warning .toast-dot {
  background: #d69e2e;
}

.toast.danger {
  border-color: rgba(200, 51, 73, 0.55);
  background: #fff5f6;
  font-weight: 700;
}

.toast.danger .toast-dot {
  background: var(--red);
  animation: alertPulse 1s ease-in-out infinite;
}

.toast-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--official-teal);
}

.toast button {
  padding: 0 4px;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
  font-size: 18px;
  line-height: 1;
}

@keyframes alertPulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(200, 51, 73, 0);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(200, 51, 73, 0.14);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 1440px) {
  .overview-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }

  .case-layout {
    grid-template-columns: minmax(0, 1.95fr) minmax(360px, 0.78fr);
  }
}

@media (max-width: 1280px) {
  .channel-config-grid,
  .policy-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .route-legend {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .route-legend header {
    grid-column: 1 / -1;
  }

  .line-status {
    grid-template-columns: repeat(2, 1fr);
  }

  .sync-layout {
    grid-template-columns: 1fr;
  }

  .route-layout,
  .admin-layout,
  .aiops-grid,
  .case-layout,
  .voice-layout {
    grid-template-columns: 1fr;
  }

  .route-map {
    max-height: none;
  }

  .case-detail {
    position: static;
    height: auto;
    overflow: visible;
  }

  .case-sticky-header {
    position: static;
  }

  .case-table th {
    top: 0;
  }

  .case-workspace {
    height: auto;
    min-height: 0;
  }

  .case-layout {
    overflow: visible;
  }

  .case-table-wrap {
    height: auto;
  }

  .voice-call-list {
    max-height: none;
  }

  .action-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-card:nth-child(3n) {
    border-right: 0;
  }
}

@media (min-width: 901px) and (max-width: 1080px) {
  .chat-tools .custom-select-menu {
    left: auto;
    width: min(220px, calc(100vw - 32px));
  }
}

@media (min-width: 901px) and (max-width: 1500px) {
  :root {
    --space-1: 6px;
    --space-2: 9px;
    --space-3: 12px;
    --space-4: 15px;
    --space-5: 18px;
    --panel-pad: 13px;
    --sidebar-width: 180px;
    --sticky-header-offset: 56px;
    --app-pad-top: 12px;
    --app-inline-pad: 14px;
  }

  body[data-active-view="overview"] {
    --sticky-header-offset: 76px;
  }

  body {
    font-size: 13px;
  }

  .agent-layout {
    grid-template-columns: minmax(185px, 0.72fr) minmax(0, 1.58fr) minmax(215px, 0.84fr);
    gap: 10px;
  }

  .context-list article {
    grid-template-columns: 1fr;
    gap: 3px;
    min-height: 52px;
    padding: 8px 9px;
  }

  .context-list b {
    text-align: left;
  }

  .sidebar {
    padding: 15px 12px;
    gap: 14px;
  }

  .brand-logo {
    width: 76px;
    height: 30px;
  }

  .brand small,
  .system-note span {
    margin-top: 2px;
  }

  .nav {
    gap: 4px;
  }

  .nav button {
    padding: 9px 10px;
    font-size: 14px;
  }

  .role-picker,
  .system-note {
    padding: 7px 9px;
  }

  .role-picker select,
  .custom-select-button {
    font-size: 15px;
  }

  .app {
    padding: var(--app-pad-top) var(--app-inline-pad);
    padding-bottom: 0;
  }

  h1 {
    font-size: 23px;
  }

  .eyebrow,
  .subhead {
    font-size: 13px;
  }

  .status {
    padding: 7px 9px;
    font-size: 13px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 12px;
  }

  .ntmetro-hero {
    grid-template-columns: minmax(190px, 0.58fr) minmax(0, 1.72fr);
    gap: 8px;
    padding: 10px;
  }

  .ntmetro-hero h2 {
    font-size: 19px;
    margin-bottom: 4px;
  }

  .ntmetro-hero p {
    font-size: 13px;
  }

  .hero-kicker {
    margin-bottom: 5px;
    padding: 3px 8px;
  }

  .line-status {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
  }

  .line-card {
    min-height: 58px;
    padding: 7px;
  }

  .line-card b {
    font-size: 14px;
  }

  .line-card span {
    margin-top: 2px;
    font-size: 12px;
  }

  .line-card .badge {
    margin-top: 5px;
    padding: 3px 6px;
    font-size: 12px;
  }

  .metrics article {
    padding: 8px 10px;
  }

  .metrics strong {
    font-size: 20px;
    margin-top: 3px;
  }

  .panel-title {
    margin-bottom: 10px;
  }

  .panel-title h2 {
    font-size: 16px;
  }

  .overview-section-bar {
    margin: 10px 0 8px;
    padding: 7px 10px;
  }

  .assistant-toggle {
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
  }

  .assistant-toggle span {
    display: none;
  }

  .route-map {
    width: 100%;
    height: auto;
    aspect-ratio: 1040 / 452;
    max-height: min(52vh, 520px);
  }

  .route-layout {
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: stretch;
  }

  .route-legend {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-content: stretch;
  }

  .route-legend header {
    grid-column: 1 / -1;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
  }

  .route-legend header span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .route-legend article {
    grid-template-columns: 12px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-content: center;
  }

  .route-legend article i {
    grid-row: 1 / 3;
    width: 12px;
    height: 12px;
  }

  .route-legend article b {
    grid-column: 2;
  }

  .action-card {
    min-height: 82px;
    padding: 8px 9px;
  }

  .action-card b {
    margin-bottom: 4px;
  }

  .chart {
    min-height: 180px;
  }

  .chart.small,
  .donut {
    min-height: 160px;
  }

  .trend-panel,
  .channel-panel {
    min-height: 215px;
  }

  .cost-panel,
  .heat-panel,
  .sync-panel {
    min-height: 225px;
  }

  .sync-stat {
    padding: 9px;
  }

  .sync-stat strong {
    margin: 4px 0;
    font-size: 26px;
  }

  .sync-panel .sync-layout {
    grid-template-columns: minmax(150px, 0.26fr) minmax(0, 1fr);
  }

  .sync-panel .bars {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .case-sticky-header {
    position: sticky;
    top: 0;
  }

  .voice-command {
    gap: 10px;
  }

  .voice-kpis {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
  }

  .voice-kpis article {
    min-height: 58px;
    padding: 7px 9px;
  }

  .voice-kpis b {
    margin: 2px 0 0;
    font-size: 19px;
  }

  .voice-kpis small {
    display: none;
  }

  .voice-main-grid {
    grid-template-columns: minmax(240px, 0.72fr) minmax(0, 1.28fr);
    gap: 10px;
    height: clamp(300px, calc(100vh - 250px), 560px);
  }

  .voice-section-title span {
    display: none;
  }

  .voice-call-list {
    flex: 1;
    max-height: none;
  }

  .voice-call-card {
    gap: 5px;
    padding: 9px 10px;
  }

  .voice-detail {
    height: 100%;
    min-height: 0;
    gap: 9px;
    padding: 10px;
  }

  .voice-detail header {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 4px 8px;
  }

  .voice-detail header b {
    font-size: 18px;
  }

  .voice-detail header small {
    grid-column: 1 / -1;
  }

  .voice-detail-grid article {
    padding: 8px;
  }

  .voice-detail-grid b {
    margin-top: 3px;
  }

  .voice-actions {
    gap: 6px;
    padding: 6px 0;
  }

  .voice-actions button {
    min-height: 38px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .voice-kpis article,
  .scenario-card,
  .ops-card,
  .sla-card,
  .usage-card {
    padding: 8px 9px;
  }

  .scenario-list,
  .ops-list,
  .sla-list,
  .usage-mix {
    gap: 6px;
  }
}

@media (max-width: 900px) {
  :root {
    --sticky-header-offset: 62px;
    --app-pad-top: var(--space-3);
    --app-inline-pad: var(--space-3);
  }

  body[data-active-view="overview"] {
    --sticky-header-offset: 84px;
  }
  body {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: auto;
    min-height: auto;
    padding: var(--space-2) var(--space-3);
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    grid-template-areas:
      "brand controls"
      "nav nav";
    align-items: center;
    gap: 10px var(--space-3);
  }

  .brand {
    grid-area: brand;
    align-items: center;
  }

  .nav {
    grid-area: nav;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav button {
    text-align: center;
    white-space: nowrap;
  }

  .nav button.active,
  .nav button:hover {
    transform: none;
  }

  .system-note {
    display: block;
  }

  .access-control {
    grid-area: controls;
    margin-top: 0;
    grid-template-columns: minmax(180px, 220px) minmax(150px, 190px);
    align-items: stretch;
    overflow-x: auto;
  }

  .access-control .role-picker,
  .access-control .system-note {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .app {
    width: 100%;
    height: auto;
    display: block;
    overflow-x: hidden;
    overflow-y: visible;
    padding-bottom: 92px;
  }

  .topbar {
    position: sticky;
    top: 0;
  }

  .view.active {
    overflow: visible;
    padding-bottom: 0;
  }

  .overview-grid,
  .report-grid,
  .occ-grid,
  .agent-layout,
  .ntmetro-hero,
  .knowledge-layout {
    grid-template-columns: 1fr;
  }

  .workflow-strip,
  .knowledge-kpis,
  .budget-alerts,
  .maintenance-status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .agent-layout {
    min-height: 0;
  }

  .voice-main-grid,
  .voice-main-grid.voice-triple {
    grid-template-columns: 1fr;
    height: auto;
  }

  .voice-messages {
    min-height: 420px;
  }

  .voice-agent-controls {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .voice-detail {
    height: auto;
  }

  .queue-panel,
  .chat-panel,
  .context-panel {
    height: auto;
    min-height: 0;
  }

  .queue-list,
  .advisor-list {
    max-height: none;
  }

  .overview-grid {
    grid-template-areas:
      "route"
      "trend"
      "channel"
      "cost"
      "heat"
      "sync"
      "actions";
  }

  .sync-panel .bars {
    grid-template-columns: 1fr;
  }

  .line-status {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 980px) {
  .grid.two,
  .layers {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

  .status {
    width: fit-content;
  }

  .top-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  :root,
  body[data-active-view="overview"] {
    --sticky-header-offset: 118px;
  }
  .sidebar {
    display: flex;
    align-items: stretch;
    gap: var(--space-2);
  }

  .access-control {
    grid-template-columns: minmax(180px, 220px);
  }

  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .dialog-wide,
  .field-span-3,
  .field-span-4,
  .field-span-5,
  .field-span-8 {
    grid-column: 1;
  }

  .view-toolbar,
  .panel-title {
    align-items: stretch;
  }

  .view-toolbar,
  .toolbar-actions {
    flex-direction: column;
  }

  .toolbar-actions input,
  .toolbar-actions button {
    width: 100%;
    min-width: 0;
  }

  .knowledge-row {
    grid-template-columns: 1fr;
  }

  .channel-config-grid,
  .policy-grid {
    grid-template-columns: 1fr;
  }

  .app {
    padding: var(--space-3);
  }

  .topbar,
  .panel-title {
    flex-direction: column;
    align-items: stretch;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  .case-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .case-stats article {
    justify-content: space-between;
    border-radius: 8px;
  }

  .case-toolbar {
    grid-template-columns: 1fr;
  }

  .case-detail-grid,
  .case-actions,
  .voice-detail-grid,
  .voice-actions {
    grid-template-columns: 1fr;
  }

  .voice-kpis {
    grid-template-columns: 1fr 1fr;
  }

  .voice-section-title,
  .voice-call-top,
  .voice-call-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .line-status {
    grid-template-columns: 1fr;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .message {
    max-width: 100%;
  }

  .bar-row {
    grid-template-columns: minmax(82px, 110px) 1fr 42px;
  }

  .donut.compact {
    grid-template-columns: 1fr;
  }

  .donut.compact svg {
    justify-self: center;
  }

  .route-map {
    width: 100%;
    max-width: 100%;
    aspect-ratio: auto;
    height: 250px;
    overflow-x: auto;
  }

  .route-map svg {
    min-width: 620px;
  }

  .route-legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-card,
  .action-card:nth-child(3n) {
    border-right: 1px solid var(--line);
  }

  .action-card:nth-child(2n) {
    border-right: 0;
  }

  .ops-meta {
    grid-template-columns: 1fr;
  }

  .emg-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .emg-foot button,
  .emg-done {
    margin-left: 0;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
    background: transparent;
  }

  .case-table {
    min-width: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  tbody {
    display: grid;
    gap: var(--space-2);
  }

  tr {
    padding: var(--space-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
  }

  td {
    display: grid;
    grid-template-columns: 98px minmax(0, 1fr);
    gap: var(--space-2);
    padding: 9px 0;
    border-bottom: 1px solid #edf1f3;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  .assistant-widget {
    left: auto;
    right: var(--space-3);
    bottom: var(--space-3);
  }

  .assistant-toggle {
    width: auto;
    min-width: 92px;
  }

  .assistant-panel {
    left: auto;
    right: 0;
    width: min(360px, calc(100vw - 28px));
  }
}

@media (max-width: 520px) {
  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .status {
    width: 100%;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .case-stats {
    grid-template-columns: 1fr;
  }

  .ntmetro-hero {
    padding: var(--space-3);
  }

  .overview-section-bar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .overview-section-bar div {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .panel-title input,
  .panel-title select,
  .chat-form input {
    min-width: 0;
    width: 100%;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

  .bar-row b {
    justify-self: end;
  }

  td {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .assistant-form {
    grid-template-columns: 1fr;
  }

  .action-grid,
  .route-legend {
    grid-template-columns: 1fr;
  }

  .action-card,
  .action-card:nth-child(2n),
  .action-card:nth-child(3n) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .action-card:last-child {
    border-bottom: 0;
  }
}

/* ===== 危險即時警報 overlay（紅燈閃爍 + 逼逼聲）===== */
.danger-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(150, 0, 0, 0.55);
  animation: dangerFlash 0.7s steps(1) infinite;
}
.danger-overlay.active { display: flex; }
@keyframes dangerFlash {
  0%   { background: rgba(200, 0, 0, 0.82); }
  50%  { background: rgba(90, 0, 0, 0.35); }
  100% { background: rgba(200, 0, 0, 0.82); }
}
.danger-box {
  background: #1b0000;
  border: 4px solid #ff2d2d;
  border-radius: 18px;
  padding: 40px 56px;
  text-align: center;
  color: #fff;
  max-width: 560px;
  box-shadow: 0 0 60px rgba(255, 45, 45, 0.9);
  animation: dangerPulse 0.7s ease-in-out infinite;
}
@keyframes dangerPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.03); } }
.danger-box .danger-icon { font-size: 64px; line-height: 1; }
.danger-box h1 { font-size: 34px; margin: 12px 0; color: #ff5b5b; letter-spacing: 4px; }
.danger-box p { font-size: 17px; margin-bottom: 24px; color: #ffd5d5; }
.danger-box button {
  background: #ff2d2d; color: #fff; border: 0; border-radius: 10px;
  padding: 14px 28px; font-size: 17px; font-weight: 700; cursor: pointer;
}
.danger-box button:hover { background: #ff5b5b; }

/* 未確認的危險等級：整張卡閃爍邊框，和全螢幕紅燈警報同一組視覺語言 */
.emg-card.is-pending.sev-critical {
  border-width: 2px;
  animation: cardBlink 1s steps(1) infinite;
}
@keyframes cardBlink { 0%,100% { border-color: #ff2d2d; } 50% { border-color: rgba(255,45,45,0.35); } }

/* 位置詢問中：站別還沒到手，讓控制員一眼看出這張單在等旅客回覆 */
.emergency-await {
  margin-top: 6px;
  padding: 7px 10px;
  border: 1px dashed rgba(214, 158, 46, 0.55);
  border-radius: 8px;
  background: rgba(255, 244, 214, 0.55);
  color: #8a6d00;
  font-size: 13px;
}

/* ===== 遺失物：登錄表單 + 協尋對話 ===== */
.lost-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}
.lost-grid.single { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 1100px) { .lost-grid { grid-template-columns: 1fr; } }
.lost-intake-form label,
.lost-intake-form .form-row label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px; font-weight: 600; margin-bottom: 10px;
}
.lost-intake-form .form-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
.lost-intake-form .lost-dynamic {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  padding: 10px; border: 1px dashed var(--border, #d0d5dd); border-radius: 10px; margin: 6px 0 12px;
}
.lost-intake-form input, .lost-intake-form select {
  padding: 8px 10px; border: 1px solid var(--border, #d0d5dd); border-radius: 8px; font-size: 14px;
}
.lost-intake-form .form-actions { text-align: right; }
.lost-intake-form .form-actions button {
  background: var(--brand, #ffc500); color: #1a1a1a; border: 0; border-radius: 9px;
  padding: 10px 22px; font-weight: 700; cursor: pointer;
}

.match-log {
  height: 320px; overflow-y: auto; padding: 12px;
  background: var(--surface-muted, #f6f7f9); border-radius: 12px; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.match-message {
  max-width: 82%; padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.5;
}
.match-message.user { align-self: flex-end; background: var(--brand, #ffc500); color: #1a1a1a; }
.match-message.ai { align-self: flex-start; background: #fff; border: 1px solid var(--border, #e3e6ea); }
.match-message.system {
  align-self: center; background: #e8f5e9; border: 1px solid #a5d6a7; color: #1b5e20;
  font-size: 13px; text-align: center; max-width: 96%;
}
.match-form { display: flex; gap: 8px; }
.match-form input { flex: 1; padding: 10px 12px; border: 1px solid var(--border, #d0d5dd); border-radius: 9px; }
.match-form button {
  background: var(--brand, #ffc500); color: #1a1a1a; border: 0; border-radius: 9px;
  padding: 10px 20px; font-weight: 700; cursor: pointer;
}
.pill.success { background: #e8f5e9; color: #1b5e20; }

/* 遺失物表單/動態欄位在窄螢幕堆疊，避免水平溢出 */
@media (max-width: 720px) {
  .lost-intake-form .form-row { grid-template-columns: 1fr; }
  .lost-intake-form .lost-dynamic { grid-template-columns: 1fr; }
  .match-message { max-width: 92%; }
}
.lost-intake-form input, .lost-intake-form select { max-width: 100%; box-sizing: border-box; }

/* 員工端：真人/系統訊息 + 語音回覆框 */
.chat-log .message.agent { align-self: flex-start; background: #e8f5e9; border: 1px solid #a5d6a7; }
.chat-log .message.system { align-self: center; background: transparent; color: var(--muted, #667085); font-size: 12.5px; text-align: center; }
.chat-log .message .msg-who { display: block; font-size: 11px; opacity: .7; }
.voice-reply-form { display: flex; gap: 8px; margin-top: 12px; }
.voice-reply-form input { flex: 1; padding: 10px 12px; border: 1px solid var(--border, #d0d5dd); border-radius: 9px; }
.voice-reply-form button { background: var(--brand, #ffc500); color: #1a1a1a; border: 0; border-radius: 9px; padding: 10px 16px; font-weight: 700; cursor: pointer; white-space: nowrap; }

/* 即時列車看板（取代原假動畫路線圖） */
.train-board { display: flex; flex-direction: column; gap: 14px; padding: 4px; }
.tb-line header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tb-line header b { font-size: 15px; }
.tb-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.tb-count { margin-left: auto; font-size: 12.5px; color: var(--muted, #667085); font-weight: 700; }
.tb-direction-guide { display: flex; justify-content: space-between; gap: 12px; margin: 2px 0 6px; color: #415159; font-size: 11px; }
.tb-direction-guide strong { display: flex; align-items: center; gap: 5px; }
.tb-direction-guide strong > span { padding: 2px 6px; border-radius: 999px; color: var(--official-dark); background: #e8f3f1; }
.tb-direction-guide i { color: var(--line-color); font-size: 18px; font-style: normal; }
.tb-track-scroll { overflow-x: auto; padding: 2px 2px 7px; scrollbar-width: thin; }
.tb-single-track {
  position: relative;
  min-width: max(760px, calc(var(--station-count) * 78px));
  display: grid;
  grid-template-columns: repeat(var(--station-count), minmax(68px, 1fr));
  align-items: start;
}
.tb-single-track::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: 68px;
  left: calc(50% / var(--station-count));
  right: calc(50% / var(--station-count));
  height: 7px;
  border-radius: 99px;
  background: var(--line-color);
  box-shadow: inset 0 -2px rgba(0,0,0,.12);
}

/* 有分支的線（淡海輕軌）：主幹在左、分支在右上下堆疊，幾何對齊官網營運路線圖。
   --tb-rail-y 是軌道中心線的高度，主幹與各分支都用同一個值才接得上。 */
.tb-topology { --tb-rail-y: 68px; display: flex; align-items: flex-start; }
.tb-topology > .tb-single-track { flex: 1 1 auto; }
/* 主幹右端要延伸到分支起點，不能停在末站圓心 */
.tb-single-track.has-branch::before { right: 0; }
.tb-branches { flex: 0 0 auto; display: flex; flex-direction: column; }
.tb-branch { position: relative; }
/* 第一條分支與主幹同一水平線；第二條以後從主幹拉一段垂直線下來再往右 */
.tb-branch + .tb-branch::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: 0;
  top: calc(var(--tb-rail-y) - 100%);
  height: 100%;
  width: 7px;
  background: var(--line-color);
}
/* 分支軌道左端要貼齊分歧點（不縮半個站距），才會接上主幹或垂直線 */
.tb-single-track.branch::before { left: 0; }
/* 分支站數少，給固定站距不隨主幹一起被拉伸；主幹 flex:1 吃剩下的寬度 */
.tb-single-track.branch { width: auto; min-width: calc(var(--station-count) * 74px); }
.tb-error {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 12px;
  border: 1px solid #f0d3c6;
  border-radius: 10px;
  background: #fff6f1;
  color: #8a4a2c;
  font-size: 12.5px;
}
.tb-error button { margin-left: auto; }
.tb-branch-note {
  margin: 0 0 6px;
  font-size: 11.5px;
  color: #5d6b72;
}
.tb-branch-note::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 4px;
  border-radius: 99px;
  background: var(--line-color);
  margin-right: 6px;
  vertical-align: middle;
}
.tb-stop {
  position: relative;
  z-index: 1;
  min-width: 0;
  display: grid;
  /* 轉乘排在案件數之後、逆行車輛槽之前，岔出才會緊貼站點而不是被推到最下面 */
  grid-template-rows: 62px 20px auto auto auto 62px;
  justify-items: center;
  align-items: center;
  color: #34434a;
}
/* 轉乘站往其他路線的岔出。是「轉乘」而非本線分支，所以用該轉乘線的顏色、與本線色帶區隔 */
.tb-xfers {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.tb-xfer {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  min-width: 0;
}
.tb-xfer-rail {
  width: 5px;
  height: 13px;
  border-radius: 99px;
  background: var(--x);
}
/* 官方標示的站外轉乘畫成虛線段 */
.tb-xfer-rail.out {
  background: repeating-linear-gradient(to bottom, var(--x) 0 3px, transparent 3px 6px);
  border-radius: 0;
}
.tb-xfer > b {
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--x);
  color: #fff;
  font-size: 9.5px;
  line-height: 1.5;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}
.tb-xfer > em {
  margin-top: 2px;
  color: #6b7880;
  font-size: 9px;
  font-style: normal;
  line-height: 1.3;
  text-align: center;
  max-width: 100%;
  overflow-wrap: anywhere;
}
/* 轉乘站的站點圓點加一圈，和一般站有區別（對應官方圖的雙圈轉乘符號） */
.tb-station-dot.transfer {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #8a97a0;
}
.tb-station-dot {
  width: 17px;
  height: 17px;
  border: 4px solid var(--line-color);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px #fff;
}
.tb-stop > b { max-width: 72px; margin-top: 3px; text-align: center; font-size: 10px; line-height: 1.2; }
.tb-stop > em { margin-top: 3px; padding: 1px 5px; border-radius: 999px; color: #78858b; background: #eef2f3; font-size: 9.5px; font-style: normal; font-weight: 700; }
.tb-stop > em.has-cases { color: #a43c20; background: #fff0e9; }
.tb-train-slot {
  width: 100%;
  min-width: 0;
  display: flex;
  gap: 3px;
  align-items: flex-end;
  justify-content: center;
}
.tb-train-slot.reverse { align-items: flex-start; }
.tb-train-marker {
  position: relative;
  min-width: 48px;
  display: grid;
  justify-items: center;
  color: #34434a;
  outline: none;
}
.tb-train-marker svg { width: 31px; height: 24px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.18)); }
.tb-train-marker > span { display: grid; justify-items: center; line-height: 1.05; }
.tb-train-marker > span b { font-size: 9px; }
.tb-train-marker > span small { max-width: 65px; overflow: hidden; color: var(--muted); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.tb-foot { font-size: 11.5px; color: var(--muted, #667085); margin-top: 4px; }
.tb-line-cases { padding: 3px 7px; border-radius: 999px; color: #a43c20; background: #fff0e9; font-size: 11px; font-weight: 800; }
.tb-disclaimer { margin: 7px 0 0; color: #8a6400; font-size: 11.5px; }
@media (max-width: 720px) {
  .tb-direction-guide { align-items: flex-start; font-size: 9.5px; }
  .tb-direction-guide strong { flex-wrap: wrap; }
  .tb-single-track { min-width: max(680px, calc(var(--station-count) * 72px)); }
}

/* 路線視圖切換 + 官方即時圖嵌入 */
.route-view-tabs { display: flex; gap: 4px; }
.route-view-tabs button, .official-line-tabs button { border: 1px solid var(--border, #d0d5dd); background: #fff; border-radius: 8px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; color: #555; }
.route-view-tabs button.active, .official-line-tabs button.active { background: var(--brand, #ffc500); border-color: var(--brand, #ffc500); color: #1a1a1a; font-weight: 700; }
.official-map { display: flex; flex-direction: column; gap: 8px; }
.official-line-tabs { display: flex; gap: 6px; }
.official-map iframe { width: 100%; height: 620px; border: 1px solid var(--border, #e3e6ea); border-radius: 10px; background: #fff; }
.official-note { font-size: 12px; color: var(--muted, #667085); }
.official-unavailable { min-height: 280px; padding: 48px 24px; border: 1px dashed #bdc9d0; border-radius: 10px; background: #f7fafb; text-align: center; }
.official-unavailable b { display: block; margin-bottom: 8px; color: var(--official-dark); font-size: 20px; }
.official-unavailable p { margin-bottom: 14px; color: var(--muted); }
.official-unavailable a { color: #066b7a; font-weight: 800; }

/* 2026-07：精簡列車總覽、固定資料夾列、表格式知識庫與快速遺失物比對 */
.knowledge-layout {
  grid-template-columns: 250px minmax(0, 1fr);
}

.knowledge-folder-node {
  min-height: 42px;
  padding-right: 3px;
}

.knowledge-folder-node > button:first-child {
  height: 40px;
}

.knowledge-folder-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.knowledge-folder-more,
.knowledge-folder-more-placeholder {
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
}

.knowledge-folder-more {
  display: grid;
  place-items: center;
  padding: 0;
  color: #52636b;
  background: transparent;
  box-shadow: none;
  letter-spacing: 1px;
}

.knowledge-folder-more:hover,
.knowledge-folder-more[aria-expanded="true"] {
  color: var(--official-dark);
  background: #dcefed;
}

.knowledge-folder-menu {
  position: absolute;
  z-index: 20;
  top: 36px;
  right: 2px;
  display: none;
  width: 150px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(20, 51, 57, .18);
}

.knowledge-folder-menu.open {
  display: grid;
}

.knowledge-folder-menu button {
  padding: 8px 10px;
  color: #34464d;
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.knowledge-folder-menu button:hover {
  background: #eef7f6;
}

.knowledge-folder-menu .danger-menu-item {
  color: #ad3434;
}

.knowledge-table-wrap {
  max-height: min(650px, calc(100vh - 330px));
}

.knowledge-table {
  min-width: 820px;
}

.knowledge-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f1f8f8;
}

.knowledge-table td {
  vertical-align: middle;
}

.knowledge-title-button {
  display: grid;
  min-width: 220px;
  max-width: 390px;
  gap: 3px;
  padding: 0;
  color: var(--official-dark);
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.knowledge-title-button:hover b {
  text-decoration: underline;
}

.knowledge-title-button small {
  overflow: hidden;
  color: var(--muted);
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knowledge-table-actions {
  display: flex;
  min-width: 150px;
  gap: 6px;
}

.knowledge-table-actions button {
  padding: 6px 8px;
  font-size: 11.5px;
  white-space: nowrap;
}

.knowledge-preview-dialog {
  width: min(860px, calc(100vw - 30px));
}

.knowledge-preview-body {
  min-height: 360px;
  padding: 16px 4px;
}

.knowledge-preview-body pre {
  margin: 0;
  color: #34464d;
  font: 14px/1.8 "Noto Sans TC", system-ui, sans-serif;
  white-space: pre-wrap;
  word-break: break-word;
}

.train-line-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 8px;
  margin: 4px 0 12px;
}

.route-panel .route-map {
  aspect-ratio: auto;
  min-width: 0;
  max-width: 100%;
  max-height: none;
  overflow: hidden;
}

.route-panel,
.route-layout,
.train-board,
.tb-line,
.tb-track-scroll {
  min-width: 0;
  max-width: 100%;
}

.train-line-tabs button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 12px;
  border: 1px solid #cadcdf;
  color: #415159;
  background: #fff;
  box-shadow: none;
}

.train-line-tabs button.active {
  border-color: var(--official-teal);
  color: #fff;
  background: var(--official-dark);
  box-shadow: 0 5px 14px rgba(10, 76, 94, .18);
}

.train-line-tabs button em {
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 99px;
  color: #9b3d27;
  background: #fff0e9;
  font-size: 10px;
  font-style: normal;
}

.official-map-open {
  white-space: nowrap;
}

.official-map-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
}

.official-map-dialog form {
  padding-bottom: 12px;
}

.official-line-tabs {
  position: sticky;
  top: 62px;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 0;
  background: #fff;
}

.official-line-tabs button.active,
.route-view-tabs button.active {
  border-color: var(--official-teal);
  color: #fff;
  background: var(--official-dark);
}

.official-frame-wrap {
  position: relative;
  height: min(680px, calc(100vh - 210px));
  min-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fafb;
}

.official-map iframe {
  height: 900px;
  border: 0;
  border-radius: 0;
}

.official-view-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.official-view-controls button {
  padding: 6px 10px;
  font-size: 12px;
}

.official-view-controls button.active {
  color: #fff;
  background: var(--official-dark);
}

.official-frame-wrap.overview {
  overflow: hidden;
}

.official-frame-wrap.overview iframe {
  position: absolute;
  top: 0;
  max-width: none;
  border: 0;
  transform: scale(var(--official-overview-scale, .4));
  transform-origin: top left;
}

.official-frame-wrap:not(.overview) iframe {
  position: static;
  width: 100% !important;
  height: 1200px !important;
  transform: none;
}

.lost-quick-panel {
  position: relative;
  z-index: 20;
  margin-bottom: 16px;
  border-top: 4px solid var(--official-teal);
}

.lost-quick-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: flex-end;
}

.lost-quick-form > label,
.lost-quick-form > .lost-quick-actions {
  min-width: 0;
}

.lost-quick-form .lost-quick-description {
  flex: 3 1 260px;
}

.lost-quick-form .lost-quick-when { flex: 1 1 150px; }
.lost-quick-form .lost-quick-exact { flex: 1 1 220px; }
.lost-quick-form .lost-quick-line { flex: 1 1 150px; }
.lost-quick-form .lost-quick-loc { flex: 1 1 170px; }

.lost-quick-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.lost-quick-actions button {
  min-height: 40px;
  white-space: nowrap;
}

/* 下拉選單不被裁切、給足寬度看得到全部選項，且不被下方面板蓋住 */
.lost-quick-form .custom-select-menu {
  min-width: 150px;
  z-index: 200;
}

.lost-quick-form label {
  display: grid;
  gap: 5px;
  color: #44545c;
  font-size: 12.5px;
  font-weight: 700;
}

.lost-quick-form input,
.lost-quick-form select,
.lost-quick-form textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

.lost-quick-form textarea {
  resize: vertical;
}

.lost-quick-form button {
  min-height: 40px;
  white-space: nowrap;
}

.lost-quick-results {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.lost-quick-result-head,
.lost-quick-result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

/* 工作台維持固定外框，將滾動限制在清單、對話或詳細內容內。 */
@media (min-width: 901px) {
  #knowledge.view.active,
  #chat.view.active,
  #voice.view.active,
  #cases.view.active,
  #lost.view.active {
    display: flex;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0;
  }

  #knowledge.view.active,
  #chat.view.active,
  #voice.view.active,
  #lost.view.active {
    flex-direction: column;
  }

  #chat .channel-switch-bar {
    flex: 0 0 auto;
  }

  #knowledge.view.active {
    padding-bottom: var(--space-3);
  }

  #knowledge .view-toolbar,
  #knowledge .knowledge-kpis {
    flex: 0 0 auto;
  }

  #knowledge .knowledge-layout {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
  }

  #knowledge .knowledge-folder-panel,
  #knowledge .knowledge-layout > section {
    position: relative;
    top: auto;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #knowledge .knowledge-folder-tree,
  #knowledge .knowledge-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: auto;
  }

  #chat .agent-layout {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
  }

  #chat .queue-panel,
  #chat .context-panel {
    display: flex;
    flex-direction: column;
  }

  #chat .queue-panel > .panel-title,
  #chat .service-stats {
    flex: 0 0 auto;
  }

  #chat .service-session-list,
  #chat .context-list,
  #chat .advisor-list {
    min-height: 0;
    max-height: none;
    overflow: auto;
  }

  #chat .service-session-list {
    flex: 1 1 auto;
  }

  #chat .context-panel {
    overflow-y: auto;
  }

  #voice .voice-layout,
  #voice .voice-command {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  #voice .voice-command {
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
  }

  #voice .voice-main-grid,
  #voice .voice-calls,
  #voice .voice-detail,
  #voice .voice-messages {
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  #voice .voice-call-list,
  #voice .voice-detail {
    max-height: none;
    overflow-y: auto;
  }

  #voice .voice-messages {
    display: flex;
    flex-direction: column;
  }

  #voice .voice-call-list {
    flex: 1 1 auto;
  }

  #lost .lost-quick-panel {
    flex: 0 0 auto;
  }

  #lost .lost-scroll-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0 2px var(--space-3) 0;
  }

  #cases .case-workspace {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  #cases .case-layout,
  #cases .case-table-wrap,
  #cases .case-detail {
    min-height: 0;
    height: 100%;
  }

  #cases .case-table-wrap,
  #cases .case-detail {
    overflow: auto;
  }
}

/* 客服清單改為精簡資訊密度，單筆卡片可在同一畫面看到更多項目。 */
.service-stat {
  min-height: 48px;
  padding: 5px 4px;
}

.queue-item {
  padding: 7px 9px;
}

.queue-item .session-intent {
  margin-top: 0;
}

.session-preview {
  min-height: auto;
  -webkit-line-clamp: unset;
}

.session-footer {
  margin-top: 4px !important;
}

.voice-kpis article {
  padding: 8px 10px;
}

.voice-kpis b {
  margin: 2px 0 1px;
  font-size: 20px;
}

.voice-call-list {
  gap: 6px;
}

.service-session-list,
.voice-call-list {
  align-content: start;
  grid-auto-rows: max-content;
}

.voice-call-card {
  gap: 4px;
  padding: 8px 10px;
}

.voice-call-top i {
  padding: 2px 6px;
}

.voice-control-card .panel-title {
  margin-bottom: 0;
}

.voice-card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.voice-card-title h3 {
  margin: 0;
  font-size: 16px;
}

.voice-card-title span {
  color: var(--muted);
  font-size: 12px;
}

.voice-calls.panel,
.voice-detail.panel {
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
}

.lost-scroll-content {
  min-width: 0;
}

.lost-scroll-content > .panel {
  margin-bottom: var(--space-3);
}

.lost-scroll-content .lost-quick-results {
  margin-top: 0;
  padding-top: var(--panel-pad);
  border-top: 1px solid var(--line);
}

.knowledge-folder-tree {
  align-content: start;
  grid-auto-rows: 42px;
}

.knowledge-folder-node {
  height: 42px;
  min-height: 42px;
  max-height: 42px;
}

.lost-quick-result-head span,
.lost-quick-result-actions span {
  color: var(--muted);
  font-size: 12px;
}

.lost-match-cards {
  display: grid;
  gap: 7px;
}

.lost-match-cards article {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  padding: 10px;
  border: 1px solid #dce8eb;
  border-radius: 9px;
  background: #fbfdfd;
}

.lost-match-cards article.best {
  border-color: #67b7b2;
  background: #eef8f7;
}

.lost-match-rank {
  display: grid;
  justify-items: center;
  padding: 5px;
  border-right: 1px solid #dce8eb;
}

.lost-match-rank b {
  color: var(--official-dark);
  font-size: 18px;
}

.lost-match-rank span,
.lost-match-cards small {
  color: var(--muted);
  font-size: 11px;
}

.lost-match-cards h3 {
  margin: 0 0 3px;
  font-size: 14px;
}

.lost-match-cards p {
  margin: 0 0 2px;
  color: #506069;
  font-size: 12px;
}

.lost-quick-result-actions {
  margin: 10px 0 0;
}

.lost-match-side {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.lost-verify-btn {
  padding: 6px 12px;
  border: 1px solid var(--official-dark);
  border-radius: 8px;
  color: var(--official-dark);
  background: #fff;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.lost-verify-btn:hover {
  color: #fff;
  background: var(--official-dark);
}

/* 身分核對面板 */
.lost-verify-panel {
  margin-top: 14px;
  border-top: 4px solid var(--official-dark);
}

.lost-verify-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.lost-verify-head b { font-size: 16px; }
.lost-verify-head span { display: block; color: var(--muted); font-size: 12.5px; }

.lost-verify-score {
  display: grid;
  justify-items: center;
  min-width: 68px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fafb;
}

.lost-verify-score b { font-size: 20px; color: var(--ink); }
.lost-verify-score span { color: var(--muted); font-size: 12px; }

.lost-verify-score.passed {
  border-color: #67b7b2;
  background: #e9f7f4;
}

.lost-verify-score.passed b { color: var(--official-green); }

.lost-verify-hint {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 12.5px;
}

.lost-verify-list {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.lost-verify-q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.lost-verify-q-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 240px;
  flex: 1;
}

.lost-verify-q-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--official-dark);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.lost-verify-question {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
}

.lost-verify-answer {
  margin: 0;
  color: #506069;
  font-size: 12.5px;
}

.lost-verify-answer span {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #e9f5f4;
  color: var(--official-teal);
  font-size: 11px;
  font-weight: 700;
}

.lost-verify-marks {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.lost-verify-marks button {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.lost-verify-marks .mark-yes.active {
  border-color: var(--official-green);
  background: var(--official-green);
  color: #fff;
}

.lost-verify-marks .mark-no.active {
  border-color: #d94272;
  background: #d94272;
  color: #fff;
}

.lost-reserve-form {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #67b7b2;
  border-radius: 12px;
  background: #f2fbf9;
}

.lost-reserve-pass {
  color: var(--official-green);
  font-weight: 700;
}

.lost-reserve-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.lost-reserve-fields label {
  display: grid;
  gap: 5px;
  color: #44545c;
  font-size: 12.5px;
  font-weight: 700;
}

.lost-reserve-fields input {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.lost-reserve-form > button[type="submit"] {
  justify-self: start;
  min-height: 40px;
  padding: 0 20px;
}

.lost-reserve-locked {
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
}

.lost-verify-done {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid #67b7b2;
  border-radius: 12px;
  background: #f2fbf9;
  line-height: 1.6;
}

.lost-verify-done button {
  justify-self: start;
  margin-top: 4px;
}

@media (max-width: 1180px) {
  .knowledge-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .lost-quick-form {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .lost-quick-description {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .route-panel .route-map {
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .knowledge-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow: visible;
    border: 1px solid var(--line);
  }
  .knowledge-table {
    display: block;
    width: 100%;
    min-width: 0;
  }
  .knowledge-table thead {
    position: absolute;
    display: block;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .knowledge-table tbody {
    display: grid;
  }
  .knowledge-table tr {
    display: block;
    width: 100%;
  }
  .knowledge-table th,
  .knowledge-table td {
    display: grid;
    width: 100%;
    min-width: 0;
  }
  .knowledge-table td::before {
    display: block;
  }
  .train-line-tabs {
    grid-template-columns: 1fr 1fr;
  }
  .official-line-tabs {
    grid-template-columns: 1fr 1fr;
    top: 82px;
  }
  .official-frame-wrap {
    height: calc(100vh - 270px);
    min-height: 360px;
  }
  .lost-quick-form {
    grid-template-columns: 1fr;
  }
  .lost-quick-description {
    grid-column: auto;
  }
  .lost-quick-result-head,
  .lost-quick-result-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .lost-quick-result-actions button {
    width: 100%;
  }
  .lost-match-cards article {
    grid-template-columns: 48px minmax(0, 1fr);
  }
  .lost-match-cards article > .pill {
    grid-column: 2;
    justify-self: start;
  }
}

/* 全站不使用橫向捲動：內容改為縮排、換行或窄螢幕卡片。 */
html,
body,
.app,
.view,
.panel,
.table-wrap,
.queue-list,
.inspector {
  max-width: 100%;
  overflow-x: hidden;
}

/* 快速比對面板需讓「遺失時間」等下拉選單溢出顯示，不被自身或下方面板裁切／蓋住。 */
#lost .lost-quick-panel {
  overflow: visible;
}

.brand-logo {
  width: 132px;
  height: 42px;
  padding: 4px 7px;
}

.service-session {
  max-width: 100%;
  overflow: hidden;
}

.session-topline,
.session-footer {
  min-width: 0;
  flex-wrap: wrap;
}

.session-contact,
.session-status,
.session-footer > * {
  min-width: 0;
  max-width: 100%;
}

.session-contact b {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
}

.service-session {
  height: 94px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-content: start;
  gap: 4px;
}

.service-session .session-preview {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.3;
}

.service-session .session-footer {
  align-self: end;
  margin-top: 0 !important;
}

.service-session .confidence-visual .ui-icon {
  width: 14px;
  height: 14px;
}

.approx-time-fields {
  display: grid !important;
  width: 100%;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.85fr);
  gap: 6px;
}

.approx-time-fields input,
.approx-time-fields select {
  width: 100%;
  min-width: 0;
}

.knowledge-folder-move {
  width: 100%;
  min-width: 0;
  font-size: 11px;
}

@media (min-width: 901px) {
  #voice .voice-detail {
    align-content: start;
    gap: 6px;
    padding: 8px 10px;
  }

  #voice .voice-detail > header {
    grid-template-columns: auto auto minmax(0, 1fr);
    gap: 4px 8px;
  }

  #voice .voice-detail > header small {
    grid-column: 3;
    justify-self: end;
    text-align: right;
  }

  #voice .voice-actions {
    gap: 5px;
    padding: 3px 0;
  }

  #voice .voice-actions button {
    min-height: 34px;
    padding: 5px 7px;
  }

  #voice .voice-detail-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  #voice .voice-detail-grid article {
    padding: 6px 8px;
  }

  #voice .voice-detail-grid article span,
  #voice .voice-detail-grid article small {
    font-size: 11px;
  }

  #voice .voice-detail-grid b {
    margin-top: 2px;
    font-size: 14px;
  }
}

@media (max-width: 760px) {
  .approx-time-fields {
    grid-template-columns: 1fr;
  }
}

.session-status i,
.session-case i {
  white-space: normal;
  overflow-wrap: anywhere;
}

table,
.knowledge-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

th {
  white-space: normal;
}

th,
td,
td > * {
  min-width: 0 !important;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.knowledge-title-button {
  width: 100%;
  min-width: 0;
}

.knowledge-title-button small {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.knowledge-table-actions {
  min-width: 0;
  flex-wrap: wrap;
}

.knowledge-table-actions button {
  min-width: 0;
  white-space: normal;
}

.knowledge-table-wrap {
  overflow-x: hidden;
}

.tb-track-scroll {
  overflow-x: hidden;
}

.tb-single-track {
  width: 100%;
  min-width: 0;
  grid-template-columns: repeat(var(--station-count), minmax(0, 1fr));
}

.tb-train-slot {
  min-width: 0;
  flex-wrap: wrap;
}

.tb-train-marker {
  width: min(48px, 100%);
  min-width: 0;
  flex: 1 1 20px;
}

.tb-train-marker svg {
  width: min(31px, 100%);
  min-width: 0;
}

.tb-train-marker > span,
.tb-train-marker > span small {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.tb-stop > b {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.pill {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .sidebar {
    overflow-x: hidden;
  }

  .nav {
    display: flex;
    flex-wrap: wrap;
    overflow: visible;
    padding-bottom: 0;
  }

  .nav-section-label {
    flex: 1 0 100%;
  }

  .nav button {
    flex: 1 1 120px;
    min-width: 0;
    white-space: normal;
  }

  .access-control {
    width: 100%;
    min-width: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    width: 100%;
    min-width: 0 !important;
  }

  thead {
    display: none;
  }

  .knowledge-table thead {
    display: none;
  }

  td {
    grid-template-columns: minmax(78px, 98px) minmax(0, 1fr);
  }

  #lost table td,
  .case-table td {
    width: 100% !important;
  }

  .knowledge-title-button small {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 720px) {
  .tb-track-scroll {
    padding-bottom: 2px;
  }

  .tb-single-track {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
  }

  .tb-single-track::before {
    top: 12px;
    bottom: 12px;
    left: 83px;
    right: auto;
    width: 6px;
    height: auto;
  }

  .tb-stop {
    grid-column: 1;
    width: 100%;
    min-height: 62px;
    grid-template-columns: 72px 22px minmax(0, 1fr) 72px;
    grid-template-rows: auto auto;
    gap: 2px 0;
    justify-items: stretch;
  }

  .tb-train-slot.forward {
    grid-column: 1;
    grid-row: 1 / 3;
  }

  .tb-station-dot {
    grid-column: 2;
    grid-row: 1 / 3;
    place-self: center;
  }

  .tb-stop > b {
    grid-column: 3;
    grid-row: 1;
    align-self: end;
    padding: 0 5px;
    text-align: left;
    font-size: 11px;
  }

  .tb-stop > em {
    grid-column: 3;
    grid-row: 2;
    align-self: start;
    justify-self: start;
    margin: 1px 5px 0;
  }

  .tb-train-slot.reverse {
    grid-column: 4;
    grid-row: 1 / 3;
  }

  .tb-train-slot {
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .tb-train-marker {
    width: 48px;
    flex: 0 1 auto;
  }
}

/* 手機版導覽：預設收合成漢堡選單，收起狀態下選單不再擋住畫面，
   讓標題列（含「民眾／新北捷運」切換）不用先滑過一排分頁按鈕才看得到。
   兩顆按鈕走跟 .area-switch 作用中分頁一樣的「白底深字」樣式，
   在深色側欄上才會看起來像同一套設計，而不是隨手放上去的方框。 */
.nav-toggle,
.controls-toggle,
.mobile-audience-switch,
.mobile-logout {
  display: none;
}

@media (max-width: 900px) {
  .brand {
    justify-content: flex-start;
  }

  .nav-toggle,
  .controls-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 8px 13px;
    border-radius: 20px;
    border: 0;
    background: #fff;
    color: var(--official-dark);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 20, 20, 0.22);
  }

  .nav-toggle:active,
  .controls-toggle:active {
    transform: translateY(1px);
  }

  .controls-toggle {
    margin-left: auto;
  }

  .nav-toggle .button-icon,
  .controls-toggle .button-icon {
    width: 16px;
    height: 16px;
    color: var(--official-teal);
  }

  .sidebar.nav-open .nav-toggle,
  .sidebar.controls-open .controls-toggle {
    background: var(--official-dark);
    color: #fff;
    box-shadow: none;
  }

  .sidebar.nav-open .nav-toggle .button-icon,
  .sidebar.controls-open .controls-toggle .button-icon {
    color: #fff;
  }

  .nav {
    display: none;
  }

  .sidebar.nav-open .nav {
    display: flex;
    margin-top: 4px;
  }

  .access-control {
    display: none;
    margin-top: 8px;
  }

  /* 面板改用跟報表/服務通路這些卡片一致的白底樣式，而不是硬塞進深色側欄配色——
     整個 app 九成都是白卡＋teal 強調色，面板跟著這套語言看起來才會像「原本就設計好的」，
     不是拿側欄的深色元件湊出來的。裡面幾顆本來是給深色側欄寫的子元件（角色選單、
     前台/後台）要跟著換回淺色，不然白卡上會看不清楚。 */
  .sidebar.controls-open .access-control {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
    border-radius: 16px;
    background: #ffffff;
    border: 0;
    box-shadow: 0 18px 38px rgba(4, 30, 38, 0.32);
  }

  .sidebar.controls-open .access-control .role-picker {
    border-color: var(--line);
    background: #f4f9f9;
  }

  .sidebar.controls-open .access-control .role-picker span {
    color: var(--muted);
  }

  .sidebar.controls-open .access-control .custom-select-button {
    border-color: var(--line);
    color: var(--ink);
    background: #fff;
  }

  .sidebar.controls-open .access-control .custom-select-menu {
    top: calc(100% + 6px);
    bottom: auto;
  }

  .sidebar.controls-open .mobile-audience-switch {
    display: grid;
    width: 100%;
  }

  .sidebar.controls-open .access-control .area-switch {
    border-color: var(--line);
    background: #f4f9f9;
  }

  .sidebar.controls-open .access-control .area-switch button {
    color: var(--muted);
  }

  .sidebar.controls-open .access-control .area-switch button.active {
    color: var(--official-dark);
    background: #fff;
    box-shadow: 0 2px 8px rgba(4, 30, 38, 0.12);
  }

  .sidebar.controls-open .mobile-logout {
    display: inline-flex;
    justify-content: center;
    width: 100%;
    margin-top: 2px;
    padding-top: 12px;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    color: var(--red);
    background: transparent;
    box-shadow: none;
    font-weight: 700;
  }

  /* 手機版切換面板已含「民眾／新北捷運」與「登出」，頂欄那組不用再重複顯示一次。 */
  .top-actions .audience-switch,
  .top-actions #logoutBtn {
    display: none;
  }
}
