/* ============ 全体レイアウト ============ */
body {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  height: 100vh;
}

/* --- ヘッダー --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px;
  background: #18829b55;
  border-bottom: 1px solid #18829b66;
}

@media (max-width:768px){
  .app-header{
    padding: max(6px, 2vw);
  }
}

.app-title {
  color: var(--color-accent);
  font-size: 18px; 
  line-height: 1em;
  font-weight: 700;
  display: flex;
  flex; align-items: center;
  gap: 10px;
}

.title-img{
  width: auto;
  height: 16px;
}

@media (max-width:768px){
  .title-img{
    max-width:158px;
    width: 26vw;
    height: auto;
  }
}

@media (max-width:450px){
  span:has(.title-img){
    display: none;
  }
}

.header-tools { display: flex; align-items: center; gap: 4px; }

.search-input {
  min-height:26px;
  width: 158px;
  padding: 5px 8px;
  border: 1px solid #18829baa;
  border-radius: 5px;
  background: #ffffff99;
}

@media (max-width:768px){
  .search-input{
    width: 100px;
    height: max(10px, 1.4vw);
  }
}

/* --- タブバー --- */
.tab-bar {
  display: flex;
  align-items: center;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  padding: 0 10px;
}

@media (max-width:768px){
  .tab-bar{
    padding: 0 max(6px, 1.6vw);
  }
}

.tab-list {
  display: flex;
  list-style: none;
  margin-top: 6px;
  padding: 0;
  overflow-x: auto;
  flex: 1;
  gap: 3px;
}

@media(max-width:768px){
  .tab-list{
    margin-top: max(4px, 1vw);
    gap:max(1px, 0.6vw);
  }
}

.tab-add {
 display: flex;
 align-items: center;
 border: transparent;
 color: var(--color-accent);
 font-size: var(--ft-16);
 border-radius: var(--radius-4);
 padding: 2px;
}

/* --- 新着通知エリア --- */
.notify-area {
  background: var(--color-pane);
  border-bottom: 1px solid var(--color-border);
  padding: 6px 8px;
  min-width: 0;          /* gridアイテムがはみ出さないように */
  overflow: hidden;      /* カードが画面外に出ても親をはみ出させない */
}
.notify-scroll {
  display: flex;
  gap: 8px;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
  scrollbar-width: none;       /* Firefox */
  -ms-overflow-style: none;    /* IE/Edge */
  cursor: grab;
  user-select: none;
  overscroll-behavior-x: contain;
  touch-action: pan-x;         /* iOSで横スワイプを優先 */
  -webkit-overflow-scrolling: touch; /* iOS慣性スクロール */
}
.notify-scroll::-webkit-scrollbar { display: none; } /* Chrome/Safari */
.notify-scroll.is-dragging { cursor: grabbing; }

/* --- メインエリア（PC：2カラム） --- */
.main-area {
  display: grid;
  /* 幅に応じて 280〜420px の範囲で可変、残りを詳細カラムへ */
  grid-template-columns: clamp(280px, 32vw, 420px) minmax(0, 1fr);
  min-height: 0; /* gridでoverflowを正しく動かす */
}
.main-area[hidden] { display: none; } /* hidden属性をgridより優先 */
.pane {
  background: var(--color-pane);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pane-list {
  border-right: 1px solid var(--color-border);
}

/* 左：ツールバー + 一覧スクロール */
.list-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--color-border);
}
.list-toolbar .sort-select {
  min-width: 0;
  max-width: 50%;
}
.list-toolbar .sort-select[hidden] { display: none; }
.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden; /* 横スクロール防止 */
  flex: 1;
}

/* 右：詳細 ─ flex column で返信欄を画面下端に固定 */
.pane-detail {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.detail-empty {
  padding: 32px;
  color: var(--color-text-sub);
  text-align: center;
  flex: 1; /* 何も選ばれてないときは中央寄せの空表示 */
}
.detail-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.detail-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.message-thread {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;          /* ← メッセージ少なくても残りスペースを吸収 */
  min-height: 0;    /* flex子要素のスクロールを正しく動かす */
}
.detail-side {
  padding: 8px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
}
.reply-area {
  border-top: 1px solid var(--color-border);
  padding: 8px 12px;
  background: var(--color-pane);
}

/* iPhoneでだけ出すボタンはデフォルト非表示 */
.back-btn { display: none; }

/* ============ レスポンシブ：768px未満は1カラム（一覧⇄詳細遷移） ============ */
@media (max-width: 768px) {
  .main-area {
    /* 1カラム化：左パネルだけ表示し、詳細は body.is-detail-open で切替 */
    grid-template-columns: 1fr;
  }
  .pane-list {
    border-right: none;
  }
  /* 通常時：一覧のみ表示、詳細は隠す */
  .pane-detail {
    display: none;
  }
  /* 詳細を開いた時：一覧を隠して詳細だけ表示 */
  body.is-detail-open .pane-list {
    display: none;
  }
  body.is-detail-open .pane-detail {
    display: flex;
  }
  /* 戻るボタンを表示 */
  body.is-detail-open .back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    margin: 8px;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-accent);
    font-size: 14px;
    cursor: pointer;
  }
  body.is-detail-open .back-btn:hover {
    background: var(--color-bg);
  }
}
