body {
  margin: 0;
  padding: 0;
  font-family: sans-serif;
}

.header {
  color: white;
  background-color: #003366;
  border-bottom: 1px solid #ccc;
  padding: 20px 30px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.system-title {
  font-size: 24px;
  font-weight: bold;
}

.header-user {
  text-align: right;
  font-size: 14px;
}

.header-user .user-name {
  margin-bottom: 5px;
  font-weight: bold;
}

.layout-container {
  display: flex;
  min-height: 100vh;
  flex-direction: row;
  align-items: stretch;
  /* サイドバーもメインと同じ高さに伸ばす */
}

/* PC用サイドバー */
.sidebar {
  width: 240px;
  background-color: #f8f9fa;
  border-right: 1px solid #ccc;
  padding: 10px;
  overflow-y: auto;
  flex-shrink: 0;
  /* 幅が縮まないよう固定 */
  height: auto;
  /* 明示してflexで高さが伸びるように */
}

.sidebar h5 {
  font-weight: bold;
  margin-bottom: 10px;
}

.sidebar .section {
  margin-bottom: 20px;
}

.sidebar a {
  display: block;
  padding: 8px 12px;
  margin-bottom: 5px;
  color: #000;
  text-decoration: none;
  border: 1px dashed #ccc;
  border-radius: 4px;
}

.sidebar a:hover {
  background-color: #e9ecef;
}

.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.content-area {
  flex-grow: 1;
  padding: 20px;
  min-height: 600px;
}

.bottom-right-toggle {
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 9999;
}

/* ChatBot */
#chatbot-container {
  position: fixed;
  bottom: 60px;
  right: 20px;
  display: none;
  transform: translateY(20px);
  opacity: 0;
  border: 1px solid #ccc;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 9999;
  background: white;
  border-radius: 8px;
  width: 400px;
  height: 500px;
}

#chatbot-container.active {
  transform: translateY(0);
  opacity: 1;
}

#chatbot-frame {
  width: 100%;
  height: 100%;
  border: none;
}

/* スマホ対応 */
@media (max-width: 767px) {
  .layout-container {
    flex-direction: column;
  }

  .sidebar {
    display: none;
  }

  .main-content {
    width: 100%;
  }

  #chatbot-container {
    right: 10px;
    left: 10px;
    width: auto;
    height: 80vh;
  }
}

/* ベース: 既存のままでOK */

/* --- 追加: 見やすさ＆タッチ操作最適化 --- */
:root {
  --sp-pad: 12px;
}

* {
  box-sizing: border-box;
}

img,
video {
  max-width: 100%;
  height: auto;
}

/* スマホ時はヘッダーの余白を少し詰める */
@media (max-width: 767px) {
  .header {
    padding: 12px var(--sp-pad);
    gap: 8px;
  }

  .system-title {
    font-size: 20px;
  }

  .header-user {
    text-align: left;
    font-size: 13px;
  }
}

/* レイアウト: 既存の切替は流用。PCはflexで2カラム、SPは縦積み */
.layout-container {
  display: flex;
  min-height: 100vh;
}

@media (max-width: 767px) {
  .layout-container {
    flex-direction: column;
  }
}

/* PCサイドバーはそのまま。SPはオフキャンバスに置き換えるので非表示 */
.sidebar {
  width: 240px;
  background: #f8f9fa;
  border-right: 1px solid #ccc;
  padding: 10px;
  overflow-y: auto;
  flex-shrink: 0;
}

@media (max-width: 767px) {
  .sidebar {
    display: none;
  }
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.content-area {
  flex: 1;
  padding: 20px;
  min-height: 600px;
}

@media (max-width: 767px) {
  .content-area {
    padding: var(--sp-pad);
    min-height: auto;
  }
}

/* 右下ボタン＆チャットボックスをSPで馴染ませる */
.bottom-right-toggle {
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 9999;
}

#chatbot-container {
  position: fixed;
  bottom: 60px;
  right: 20px;
  display: none;
  transform: translateY(20px);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 10px;
  z-index: 9999;
  width: 400px;
  height: 500px;
}

#chatbot-container.active {
  transform: translateY(0);
  opacity: 1;
}

#chatbot-frame {
  width: 100%;
  height: 100%;
  border: none;
}

@media (max-width: 767px) {
  .bottom-right-toggle {
    bottom: calc(10px + env(safe-area-inset-bottom));
    right: 12px;
  }

  #chatbot-container {
    left: 10px;
    right: 10px;
    width: auto;
    height: 75vh;
    bottom: calc(70px + env(safe-area-inset-bottom));
  }
}

/* 表・フォームのスマホ最適化 */
.table-responsive {
  overflow-x: auto;
}

form input[type="text"],
form input[type="email"],
form input[type="tel"],
form select,
form textarea {
  max-width: 100%;
}

/* アニメ苦手な方に配慮 */
@media (prefers-reduced-motion: reduce) {
  #chatbot-container {
    transition: none;
  }
}

/* --- Sidebarの見た目（既存継承） --- */
.sidebar a {
  display: block;
  padding: 8px 12px;
  margin-bottom: 6px;
  color: #000;
  text-decoration: none;
  border: 1px dashed #ccc;
  border-radius: 4px;
}

.sidebar a:hover {
  background: #e9ecef;
}

/* 補助: ページャーが折り返しても詰まらないように */
.pager,
.pagination {
  flex-wrap: wrap;
  gap: 6px;
}

/* 実行中オーバーレイを最前面に & iOS の 100vh 問題回避 */
#globalOverlay {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 12000;
  /* offcanvas(1045) より上, chatbot(9999) より上 */
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
}

/* iOS Safari の動的バーでオーバーレイが欠けないように */
@supports (-webkit-touch-callout: none) {
  #globalOverlay {
    height: 100dvh;
    /* 100vh ではなく dynamic vh を使用 */
  }
}

/* オフキャンバスやチャットより常に優先 */
#chatbot-container {
  z-index: 9999;
}

/* 既定より下げないが overlay が超える */
.offcanvas {
  z-index: 1045;
}
