/* 四合一工作台：部門 KM／語音報修（單鍵啟動）／郵件後台／客服台。
   只作用在 body.simpleConsolePage，不影響 index / km / agent 既有畫面。 */

body.simpleConsolePage {
  min-height: 100vh;
  overflow: hidden;
}

body.simpleConsolePage .simpleConsole {
  height: calc(100vh - 72px);
  display: block;
}

body.simpleConsolePage .consoleView {
  display: none;
  height: 100%;
}

body.simpleConsolePage .consoleView.active {
  display: block;
}

/* ===== 可點的標題：回主選單 ===== */

body.simpleConsolePage .brandHome {
  border-radius: var(--r-lg);
  padding: 4px 8px;
  margin: -4px -8px;
  cursor: pointer;
  transition: background 0.16s ease;
}

body.simpleConsolePage .brandHome:hover {
  background: var(--brand-soft);
}

body.simpleConsolePage .brandHome:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* 已經在主選單就不必再提示可點 */
body.simpleConsolePage.atHome .brandHome {
  cursor: default;
}

body.simpleConsolePage.atHome .brandHome:hover {
  background: transparent;
}

/* 「回主選單」只在進入功能後出現。用 opacity 而非 display，
   讓頂欄高度固定，切換畫面時標題不會上下跳動。 */
body.simpleConsolePage .brandBack {
  color: var(--brand);
  font-weight: 600;
  transition: opacity 0.16s ease;
}

body.simpleConsolePage.atHome .brandBack {
  opacity: 0;
}

/* ===== 主選單：四張卡 ===== */

/* 主選單不出捲軸：改為「內容隨可用高度收縮」。垂直方向的固定成本（外距、卡片
   內距、圖示尺寸）一律用 vh 為主的 clamp()，視窗變矮時整體等比壓縮而不是溢出。 */
body.simpleConsolePage .homeView {
  overflow: hidden;
}

/* 內容錨在視窗上三分之一，而不是垂直置中——置中會讓上下各留一大塊空白，
   在 900px 高的視窗裡看起來像沒排版。 */
body.simpleConsolePage .homeInner {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(18px, 4vh, 64px) 24px clamp(18px, 3vh, 40px);
}

body.simpleConsolePage .homeHead {
  width: 100%;
  max-width: 860px;
  flex: 0 0 auto;
  margin-bottom: clamp(12px, 2.2vh, 26px);
}

body.simpleConsolePage .homeEyebrow {
  display: block;
  margin-bottom: 6px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

body.simpleConsolePage .homeTitle {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--ink);
}

body.simpleConsolePage .homeLede {
  margin-top: 8px;
  max-width: 52ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

/* 首頁分三排（三類）：部門 KM／語音報修＋客服台／郵件後台。
   語音報修與客服台是同一條受理動線（AI 受理 → 真人接管），排在同一排並列，
   讓分組本身就表達出關聯；其餘兩類各自獨占一排。 */
body.simpleConsolePage .homeGrid {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.6vh, 16px);
  /* 可縮不可脹：視窗夠高時卡片維持自然高度（不被拉長），變矮時才壓縮。
     min-height:0 是讓 flex 子項真的能縮到內容以下的必要條件。 */
  flex: 0 1 auto;
  min-height: 0;
}

body.simpleConsolePage .homeRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(10px, 1.6vh, 16px);
  min-height: 0;
}

/* 同一排並列兩張卡（語音報修｜客服台） */
body.simpleConsolePage .homeRow.homeRowPair {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* 卡片是三段：頂列（圖示徽章＋前往箭頭）／標題與說明／功能標籤。
   箭頭給出「可以進去」的操作暗示；標籤讓卡片有實際內容，
   而不是四個等大空框浮在版面上。 */
body.simpleConsolePage .homeCard {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 14px);
  padding: clamp(12px, 1.7vh, 18px) 20px clamp(10px, 1.5vh, 16px);
  min-height: 0;
  overflow: hidden;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.14s ease;
}

/* 箭頭與標題同一行：放在右上角會離標題太遠，讀起來是斷開的元素 */
/* 標題列：標題｜功能標籤｜前往箭頭。標籤放在標題右側（而不是卡片底部）——
   卡片改成整排寬之後標題右邊是一大片空白，標籤移過來既填滿版面，
   也省掉底部那一排的垂直高度（含髮線與上內距），讓三排在不捲動下放得進去。 */
body.simpleConsolePage .homeCardTitleRow {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 箭頭永遠靠最右：標籤數量／寬度不一，用 auto margin 而非 space-between 才穩定 */
body.simpleConsolePage .homeCardGo {
  margin-left: auto;
}

body.simpleConsolePage .homeCard:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-brand);
  transform: translateY(-2px);
}

body.simpleConsolePage .homeCard:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

body.simpleConsolePage .homeCard:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* 圖示徽章：預設淡品牌底＋品牌色描邊，hover 反轉成品牌實底白線 */
body.simpleConsolePage .homeCardChip {
  flex: 0 0 auto;
  width: clamp(36px, 4.6vh, 46px);
  height: clamp(36px, 4.6vh, 46px);
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: var(--brand-soft);
  color: var(--brand);
  transition: background 0.18s ease, color 0.18s ease;
}

body.simpleConsolePage .homeCard:hover .homeCardChip {
  background: var(--brand);
  color: var(--panel);
}

body.simpleConsolePage .homeCardChip svg {
  width: 23px;
  height: 23px;
  display: block;
}

body.simpleConsolePage .homeCardBody {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

body.simpleConsolePage .homeCardTitle {
  display: inline-flex;
  align-items: center;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.1px;
  color: var(--ink);
}

body.simpleConsolePage .homeCardDesc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

/* 功能標籤：跟在標題右側，以左側髮線與標題分隔，不畫成實心色塊搶走圖示的焦點。
   nowrap + overflow:hidden：卡片被壓窄時寧可截掉尾端標籤，也不要換行把標題列撐高。 */
body.simpleConsolePage .homeCardMeta {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

body.simpleConsolePage .homeTag {
  padding: 3px 8px;
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* 標籤刻意不隨 hover 變化：卡片已有邊框、徽章、箭頭、浮起四個回饋訊號，
   再讓標籤跟著變只會讓 hover 變得吵雜，而 brand-soft 在白卡上也幾乎看不見。 */

body.simpleConsolePage .homeCardGo {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: var(--line-strong);
  transition: color 0.18s ease, transform 0.18s ease;
}

body.simpleConsolePage .homeCard:hover .homeCardGo {
  color: var(--brand);
  transform: translateX(2px);
}

body.simpleConsolePage .homeCardGo svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* 分頁上的通話中提示 */
body.simpleConsolePage .liveDot {
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(26, 138, 82, 0.55);
  animation: consolePulseDot 1.6s ease-out infinite;
}

@keyframes consolePulseDot {
  70% { box-shadow: 0 0 0 7px rgba(26, 138, 82, 0); }
  100% { box-shadow: 0 0 0 0 rgba(26, 138, 82, 0); }
}

/* ===== 報修：單鍵啟動 ===== */

body.simpleConsolePage .repairHero {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  text-align: center;
}

body.simpleConsolePage .callHalo {
  width: 168px;
  height: 168px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(239, 49, 35, 0.10) 0%, rgba(239, 49, 35, 0) 68%);
}

body.simpleConsolePage .callDisc {
  width: 118px;
  height: 118px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 8px 26px rgba(32, 32, 32, 0.08);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

body.simpleConsolePage .callIcon {
  font-size: 44px;
  line-height: 1;
}

/* 連線中 / 通話中 */
body.simpleConsolePage.isConnecting .callDisc {
  border-color: var(--warn);
}

body.simpleConsolePage.isLive .callDisc {
  border-color: var(--brand);
  box-shadow: 0 8px 30px rgba(239, 49, 35, 0.18);
}

body.simpleConsolePage.isLive .callHalo {
  animation: consoleHalo 2s ease-out infinite;
}

@keyframes consoleHalo {
  0% { box-shadow: 0 0 0 0 rgba(239, 49, 35, 0.22); }
  70% { box-shadow: 0 0 0 26px rgba(239, 49, 35, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 49, 35, 0); }
}

body.simpleConsolePage .callStatus {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 44px;
}

body.simpleConsolePage .callStateText {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--muted);
}

body.simpleConsolePage.isLive .callStateText {
  color: var(--ink);
}

body.simpleConsolePage .callMeter {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--brand);
  letter-spacing: 1px;
}

body.simpleConsolePage .heroBtn {
  min-width: 260px;
  min-height: 56px;
  padding: 0 34px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--brand);
  color: var(--panel);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-brand);
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

body.simpleConsolePage .heroBtn:hover {
  background: var(--brand-dark);
}

body.simpleConsolePage .heroBtn:active {
  transform: translateY(1px);
}

body.simpleConsolePage .heroBtn:disabled {
  background: var(--bg-strong);
  box-shadow: none;
  cursor: progress;
}

body.simpleConsolePage.isLive .heroBtn {
  background: var(--panel);
  color: var(--brand);
  border: 1px solid var(--brand);
  box-shadow: none;
}

body.simpleConsolePage.isLive .heroBtn:hover {
  background: var(--brand-soft);
}

body.simpleConsolePage .heroHint {
  max-width: 420px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== KM / 郵件後台 / 客服台：直接內嵌現有頁面 ===== */

body.simpleConsolePage .embedSlot {
  height: 100%;
}

body.simpleConsolePage .embedSlot iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

/* app.js 需要的元素：留在畫面外，不顯示但保持可操作 */
body.simpleConsolePage .offscreen {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  pointer-events: none;
}

/* 極矮視窗（筆電 768p 以下、或開了開發者工具）：clamp 已壓到下限仍可能不夠時，
   才捨棄說明文字。功能標籤已移到標題列、不佔額外高度，因此一律保留不隱藏。 */
@media (max-height: 620px) {
  body.simpleConsolePage .homeLede,
  body.simpleConsolePage .homeEyebrow {
    display: none;
  }

  body.simpleConsolePage .homeCardDesc {
    display: none;
  }
}

/* 最後防線：低於 450px 連壓到底都放不下三排，此時寧可捲動也不要裁掉卡片。 */
@media (max-height: 450px) {
  body.simpleConsolePage .homeView {
    overflow-y: auto;
  }

  body.simpleConsolePage .homeInner {
    height: auto;
    min-height: 100%;
  }
}

@media (max-width: 720px) {
  body.simpleConsolePage .simpleConsole {
    height: calc(100vh - 108px);
  }

  body.simpleConsolePage .heroBtn {
    min-width: min(320px, calc(100vw - 48px));
  }

  body.simpleConsolePage .homeGrid {
    gap: 12px;
  }

  /* 窄螢幕：並列那排改為上下堆疊，避免兩張卡被壓到讀不了 */
  body.simpleConsolePage .homeRow,
  body.simpleConsolePage .homeRow.homeRowPair {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  /* 堆疊後變成四排、必然比視窗高，此時恢復捲動：手機上捲動是預期行為，
     若沿用 overflow:hidden 會直接裁掉最後一張卡（郵件後台）而點不到。 */
  body.simpleConsolePage .homeView {
    overflow-y: auto;
  }

  body.simpleConsolePage .homeInner {
    height: auto;
    min-height: 100%;
  }

  body.simpleConsolePage .homeInner {
    padding: 24px 16px 36px;
  }

  body.simpleConsolePage .homeTitle {
    font-size: 21px;
  }

  body.simpleConsolePage .homeCard {
    padding: 16px;
    gap: 13px;
  }

  body.simpleConsolePage .homeCardChip {
    width: 40px;
    height: 40px;
  }
}
