/* 首頁選單保留清楚的鍵盤焦點。 */
#__kimPicker button:focus-visible {
  outline: 3px solid #0D8F95;
  outline-offset: 3px;
}

#__kimPicker .kim-tool-card {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  align-items: center;
  padding: 14px 16px !important;
}
#__kimPicker .kim-tool-card > div:nth-child(1),
#__kimPicker .kim-tool-card > div:nth-child(2) { grid-column: 1; }
#__kimPicker .kim-tool-card > div:nth-child(3) { grid-column: 2; grid-row: 1 / 3; }
#__kimPicker .kim-tool-card:hover { border-color: #0B6F73 !important; }
#__riskMeta input:focus-visible, #__kimNav button:focus-visible, #__shareBtn button:focus-visible {
  outline: 3px solid #0D8F95;
  outline-offset: 2px;
}

/* 結果頁的品牌資訊與 KIM 原有來源標示分開呈現。 */
#__resultBrand {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid #E6E1D6;
  border-radius: 10px;
  background: #FAF8F5;
  color: #2C302E;
  text-align: left;
  line-height: 1.5;
}
#__resultBrand a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: #1E5641;
  font-size: 18px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}
#__resultBrand a:focus-visible { outline: 3px solid #1E5641; outline-offset: 2px; }
#__resultBrand span { display: block; font-size: 14px; overflow-wrap: anywhere; }
#__resultBrand p { margin: 8px 0 0; color: #514E48; font-size: 13px; }

/* KIM Tool 2019 — 手機響應式修復層
   手機評估不顯示專案/作業側欄（外框頁），評估工具直接全寬顯示。
   評估表對齊手機寬度；支援捏合縮放看細節；頁面順滑垂直捲動。 */
@media (max-width: 767px) {
  .app {
    flex-direction: column !important;
    height: auto !important;
    min-height: 100vh;
  }
  /* 手機不需要 project 外框，隱藏側欄與拖曳把手 */
  .app > .sidebar,
  .app > .react-draggable {
    display: none !important;
  }
  .app > .main {
    width: 100% !important;
    flex: none !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }
  /* 評估表對齊手機寬度；觸控允許捏合縮放（pan 交給瀏覽器原生處理） */
  .react-transform-component {
    width: 100% !important;
    min-width: 0 !important;
  }
  .react-transform-wrapper {
    overflow: visible !important;
    touch-action: manipulation !important;
  }
  body, .app, .main {
    touch-action: manipulation !important;
  }

  /* Keep the page switchers in normal flow so they cannot cover the form. */
  #KIM {
    padding: 12px 12px 24px !important;
    box-sizing: border-box !important;
  }
  #__kimNav {
    position: sticky !important;
    top: 0 !important;
    left: 0 !important;
    box-sizing: border-box;
    max-width: none !important;
    width: 100%;
    padding: max(8px, env(safe-area-inset-top)) 12px 8px;
    background: #FAF9F5;
    border-bottom: 1px solid #E9E2D7;
    gap: 8px !important;
  }
  #__kimNav button {
    min-height: 48px !important;
    padding: 8px 12px !important;
    font-size: 16px !important;
    background: #0B6F73 !important;
    border-radius: 12px !important;
    white-space: nowrap;
  }
  #__kimNav button[aria-pressed="true"] {
    background: #173B3D !important;
    box-shadow: inset 0 0 0 2px #A8DEE0;
  }
  #__shareBtn {
    position: static !important;
    transform: none !important;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    padding: 16px 16px max(24px, env(safe-area-inset-bottom));
  }
  #__shareBtn button { min-width: 120px; white-space: nowrap; }
  #__riskMeta > div { font-size: 16px !important; }
  #__riskMeta > div:first-child > span:first-child { flex-basis: 100%; }
  #__riskMeta input { min-height: 44px !important; font-size: 16px !important; }
  #__riskMeta input[aria-label="評估日期：年"] { width: 68px !important; }
  #__riskMeta > div > span { min-width: 0; }
  #__riskCompact { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  #__riskCompact > div > div:first-child { font-size: 14px !important; line-height: 1.4 !important; }
  #__riskCompact > div > div:nth-child(2) { font-size: 18px !important; }
  #KIM > .sc-jSUZER {
    position: static !important;
    float: left !important;
    width: 56px !important;
    height: 48px !important;
    margin: 8px 6px !important;
    z-index: 2 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 14px !important;
    font-size: 15px !important;
    line-height: 1 !important;
    box-sizing: border-box !important;
  }
  #KIM > .css-qbal4r {
    clear: both !important;
    float: none !important;
    position: relative !important;
    left: 0 !important;
    top: 0 !important;
    margin: 8px 0 !important;
    width: fit-content !important;
  }
  #__teamwork {
    clear: both;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    margin: 4px 0 8px;
    font-size: 16px;
    color: #173B3D;
  }
  #__teamwork input { width: 22px; height: 22px; accent-color: #0B6F73; }
  .kim-teamwork-original { display: none !important; }
  #KIM .react-transform-wrapper {
    clear: both !important;
    overflow: visible !important;
  }

  /* 內插按鈕預設隱藏，避免遮住評估表；開啟「輸入」時才顯示 */
  #Page-1 > div:has(> button),
  #Page-2 > div:has(> button) {
    display: none !important;
  }
  body.kim-input-on #Page-1 > div:has(> button),
  body.kim-input-on #Page-2 > div:has(> button) {
    display: block !important;
  }
  /* 內插模式保留圖表比例，橫向捲動後可點選各欄位。 */
  body.kim-input-on #KIM .react-transform-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    touch-action: manipulation !important;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  body.kim-input-on #KIM .react-transform-component {
    width: 1200px !important;
    min-width: 1200px !important;
  }
  body.kim-input-on #Page-1 > div:has(> button) button,
  body.kim-input-on #Page-2 > div:has(> button) button {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 20px !important;
    height: 100% !important;
    padding: 0 !important;
    line-height: 1 !important;
  }

  /* 風險值卡片：更緊湊、乾淨的雙欄列表 */
  #Rating {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 8px !important;
    box-sizing: border-box !important;
  }
  #Rating > div:first-child {
    position: relative !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 10px 12px !important;
    box-sizing: border-box !important;
    border-radius: 16px !important;
  }
  #Rating > div:first-child > p {
    position: static !important;
    margin: 0 0 6px !important;
    text-align: center !important;
    font-size: 16px !important;
    font-weight: 700 !important;
    line-height: 1.3 !important;
  }
  #Rating > div:first-child > .sc-gKPRtg {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(56px, 72px) !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    gap: 0 !important;
  }
  #Rating .sc-iBYQkv {
    display: flex !important;
    flex-direction: column !important;
    width: auto !important;
    height: auto !important;
    min-width: 0 !important;
  }
  #Rating .sc-ftTHYK,
  #Rating .sc-pyfCe {
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 26px !important;
    height: auto !important;
    padding: 2px 6px !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    overflow: visible !important;
    white-space: normal !important;
    overflow-wrap: break-word !important;
    word-break: normal !important;
    line-height: 1.2 !important;
    flex: 0 0 auto !important;
    border: none !important;
    border-bottom: none !important;
  }
  #Rating .sc-iBYQkv > .sc-ftTHYK,
  #Rating .sc-iBYQkv > .sc-pyfCe {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  /* 隱藏原始表格的空白分隔列（第 7 列） */
  #Rating .sc-iBYQkv > :nth-child(7) {
    display: none !important;
  }
  #Rating .sc-ftTHYK {
    justify-content: flex-start !important;
    text-align: left !important;
    font-size: 13px !important;
  }
  #Rating .sc-pyfCe {
    justify-content: center !important;
    text-align: center !important;
    font-size: 15px !important;
    font-weight: 600 !important;
  }

  /* 內插高亮：由 JS 加上 kim-hl，把黃底改成細紅框 */
  .sc-csuSiG.kim-hl,
  .sc-eDWCr.kim-hl {
    background: transparent !important;
    border: 2px solid #e53935 !important;
    box-sizing: border-box !important;
  }
}

/* ===== 桌面 / 寬螢幕：風險值卡片也用優化版面 ===== */
@media (min-width: 768px) {
  #Rating {
    position: relative !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 12px !important;
  }
  #Rating > div:first-child {
    position: relative !important;
    height: auto !important;
    min-height: 0 !important;
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box !important;
    border-radius: 16px !important;
    padding: 16px !important;
  }
  #Rating > div:first-child > p {
    position: static !important;
    margin: 0 0 10px !important;
    font-size: 20px !important;
    font-weight: 700 !important;
    text-align: center !important;
  }
  #Rating > div:first-child > .sc-gKPRtg {
    display: grid !important;
    width: 100% !important;
    max-width: none !important;
  }
  #Rating .sc-ftTHYK,
  #Rating .sc-pyfCe {
    min-height: 32px !important;
    padding: 4px 8px !important;
    border: none !important;
    border-bottom: none !important;
  }
  #Rating .sc-iBYQkv > :nth-child(7) {
    display: none !important;
  }
  #__riskCompact {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  }
}
