/* ============================================
   layout-header.css - グローバルヘッダー共通
   正: 営業管理（/deal）= patch.css 適用済みの完成形
   参照モック: ref/kdcs_mock/sales/s004.html
   ============================================ */

:root {
  --header-user-name-color: #333;
  --header-company-chevron-bg: #808080;
  --header-company-chevron-bg-hover: #757575;
  --header-avatar-bg: #b0c4de;
}

/* ============================================
   ヘッダーバー
   ============================================ */
.header-bar {
  display: flex;
  align-items: center;
  height: 50px;
  background: #fff;
  color: #333;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 100;
  border-bottom: 1px solid #e2e5ea;
  overflow: visible;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* KDCS_PRJ-393 (D-7): ヘッダーの青が薄く視認しづらいため、
   アクセント青 --deal-page-accent(#2870c4) と同色へ揃える。 */
.sidebar-toggle {
  background: none;
  border: none;
  color: #2870c4;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

/* KDCS_PRJ-393 (D-7): 通常時を濃くしたぶん、hover は更に暗い側へ落とす */
.sidebar-toggle:hover {
  background: #eef5fb;
  color: #1f5ba0;
}

.sidebar-toggle .hamburger-icon {
  color: inherit;
  line-height: 1;
}

/* KDCS_PRJ-393 (D-7): ヘッダーのシステム名もアクセント青へ統一 */
.system-name {
  font-size: 15px;
  font-weight: 600;
  color: #2870c4;
  letter-spacing: 0.3px;
}

.header-tabs {
  display: flex;
  gap: 6px;
}

/* === KDCS_PRJ-215: タブ背景色をトークン化 === */
.header-tab {
  box-sizing: border-box;
  margin: 0;
  background: var(--bg-card, #fff);
  border: 1px solid #d6d9de;
  border-bottom: 1px solid #e0e0e0;
  border-radius: 0;
  color: #5f6368;
  padding: 6px 14px 7px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.header-tab:hover {
  background: #f8f9fa;
  color: #202124;
  border-color: #d6d9de;
  border-bottom-color: #e0e0e0;
}

/* === KDCS_PRJ-212 / KDCS_PRJ-215: アクティブタブ背景をコンテンツ背景と同色化（間の線を出さない） === */
.header-tab.active {
  background: var(--bg-tab-active, #f2f3f5);
  color: #202124;
  border-color: #d6d9de;
  border-top: 3px solid #2c5f9f;
  border-bottom: 1px solid var(--bg-tab-active, #f2f3f5);
  padding-top: 4px;
  padding-bottom: 7px;
  font-weight: 500;
  position: relative;
  z-index: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.header-search {
  position: relative;
}

.header-search-input {
  width: 200px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  background: #f8f9fa;
}

.header-search-input:focus {
  outline: none;
  border-color: #5b9bd5;
  background: #fff;
}

.header-icon-btn {
  background: none;
  border: none;
  color: #5b9bd5;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

.header-icon-btn:hover {
  background: #eef5fb;
  color: #4a8bc4;
}

.header-user {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 2px;
}

.header-user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px 4px 10px;
  /* KDCS_PRJ-207: 50% だと横長ボタンのホバーが楕円になるため矩形の角丸に */
  border-radius: var(--radius-sm, 4px);
  transition: background 0.15s;
}

.header-user-btn:hover {
  background: #f5f5f5;
}

.user-info-text {
  font-size: 13px;
  font-weight: 400;
  color: var(--header-user-name-color);
  line-height: 1.2;
  white-space: nowrap;
}

/* === KDCS_PRJ-207: アバター border-radius をトークン化 === */
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-circle, 50%);
  background: #b3c8e6;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.header-user .header-user-btn .user-avatar.user-icon-shape {
  width: 34px;
  height: 34px;
  background: var(--header-avatar-bg);
  flex-shrink: 0;
}

.user-icon-shape {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 40px;
}

.header-user .header-user-btn .user-avatar.user-icon-shape::before {
  top: 10px;
  width: 7px;
  height: 7px;
}

.header-user .header-user-btn .user-avatar.user-icon-shape::after {
  bottom: 8px;
  width: 13px;
  height: 8px;
  border-radius: 8px 8px 3px 3px;
}

.user-icon-shape::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

.user-icon-shape::after {
  content: "";
  position: absolute;
  bottom: 9px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 10px;
  border-radius: 10px 10px 4px 4px;
  background: #fff;
}

.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  z-index: 200;
  padding: 4px 0;
  margin-top: 4px;
  max-height: min(70vh, 28rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: none;
  text-align: left;
  font-size: 13px;
  color: #333;
  cursor: pointer;
  transition: background 0.1s;
  text-decoration: none;
}

.dropdown-item:hover {
  background: #f0f2f5;
}

/* グローバルナビタブあり：サイドバー幅(--sidebar-width)に合わせ、タブ列をメイン左端に揃える */
.header-bar:has(.header-tabs) {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  height: auto;
  min-height: 40px;
  padding: 0 16px 0 0;
  /* KDCS_PRJ-210: overflow:hidden だと .company-dropdown がヘッダー下端で切れる */
  overflow: visible;
}

.header-bar:has(.header-tabs) .header-left {
  flex: 0 0 var(--sidebar-width, 240px);
  width: var(--sidebar-width, 240px);
  min-width: var(--sidebar-width, 240px);
  box-sizing: border-box;
  padding-left: 16px;
  padding-right: 0;
  justify-content: space-between;
}

.header-bar:has(.header-tabs) .header-left .sidebar-toggle {
  flex-shrink: 0;
  order: 2;
}

.header-bar:has(.header-tabs) .header-left .system-name {
  order: 1;
}

.header-bar:has(.header-tabs) .header-tabs {
  display: flex;
  flex: 1 1 auto;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: -1px;
  padding: 0 8px 0 20px;
  min-width: 0;
  overflow: hidden;
  contain: paint;
}

.header-bar:has(.header-tabs) .header-right {
  flex: 0 0 auto;
  flex-shrink: 0;
  margin-left: 12px;
  position: relative;
  z-index: 5;
  background: #fff;
  overflow: visible;
}

/* PC（1024px〜）: 右領域上限 + ユーザー名省略（タブサイズは固定） */
@media (min-width: 1024px) {
  .header-bar:has(.header-tabs) {
    padding-right: 12px;
  }

  .header-bar:has(.header-tabs) .header-right {
    max-width: min(360px, calc(100% - var(--sidebar-width, 240px) - 300px));
    margin-left: 12px;
  }

  .header-bar:has(.header-tabs) .header-user {
    min-width: 0;
    overflow: hidden;
  }

  .header-bar:has(.header-tabs) .header-tabs {
    gap: 2px;
    padding-left: 8px;
    padding-right: 4px;
    overflow-x: clip;
    overflow-y: hidden;
  }

  .header-bar:has(.header-tabs) .user-info-text {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (min-width: 1280px) {
  .header-bar:has(.header-tabs) .header-right {
    max-width: none;
    margin-left: 12px;
  }

  .header-bar:has(.header-tabs) .header-tabs {
    gap: 6px;
    padding-left: 20px;
    overflow: hidden;
  }

  .header-bar:has(.header-tabs) .user-info-text {
    max-width: 200px;
  }
}

/* サイドバー折りたたみ時: ヘッダー左列をハンバーガー幅に縮小 */
@media (min-width: 1024px) {
  .layout.sidebar-collapsed .header-bar:has(.header-tabs) .header-left {
    flex: 0 0 auto;
    width: auto;
    min-width: 48px;
    padding-right: 8px;
  }
}

.header-left .system-name {
  order: 1;
}

.header-left .sidebar-toggle {
  order: 2;
}

/* ============================================
   ヘッダー: 拠点・支社
   ============================================ */
.header-company {
  position: relative;
  flex-shrink: 0;
  width: max-content;
  max-width: min(340px, calc(100vw - 200px));
}

.header-company form {
  margin: 0;
  padding: 0;
}

.header-company-btn {
  display: inline-flex;
  align-items: stretch;
  height: 30px;
  min-height: 30px;
  min-width: 160px;
  width: fit-content;
  max-width: min(340px, calc(100vw - 200px));
  padding: 0;
  border: 1px solid #d5d9df;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  background: none;
  color: #5f6368;
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.header-company-btn:hover {
  background: none;
  border-color: #c9ced6;
}

.header-company-btn:hover .company-name {
  background: #fafbfc;
}

.header-company-btn:hover .dropdown-arrow {
  background: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") center / 12px no-repeat var(--header-company-chevron-bg-hover);
}

.header-company-btn:focus-visible {
  outline: 2px solid #5b9bd5;
  outline-offset: 2px;
}

.company-name {
  display: flex;
  align-items: center;
  align-self: stretch;
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.2;
  color: #333;
  background: #fff;
  white-space: nowrap;
}

.dropdown-arrow {
  box-sizing: border-box;
  flex-shrink: 0;
  align-self: stretch;
  width: 30px;
  min-width: 30px;
  margin: 0 0 0 auto;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  line-height: 0;
  color: transparent;
  border: none;
  border-left: 1px solid rgba(0, 0, 0, 0.12);
  background: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") center / 12px no-repeat var(--header-company-chevron-bg);
}

/* === KDCS_PRJ-210: 本支店ドロップダウンの z-index 引き上げ (200 → 1200) === */
/* モーダル(1000)/over-overlay(1100-1101) より前面、通知(5000)より背面 */
.company-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: auto;
  width: max-content;
  min-width: 100%;
  margin-top: 0;
  background: #fff;
  border: 1px solid #dadce0;
  border-radius: var(--radius-sm, 4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 0;
  z-index: 1200;
  max-height: min(70vh, 28rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.header-company .company-dropdown .dropdown-item {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.3;
}

.header-company .company-dropdown .dropdown-item:hover {
  background: #f0f2f5;
}

/* 会社セレクト Tom Select（モック s004 準拠） */
.header-company .ts-wrapper.single {
  min-width: 160px;
  max-width: min(340px, calc(100vw - 200px));
  width: max-content;
}

.header-company .ts-wrapper.single .ts-control {
  height: 30px;
  min-height: 30px;
  padding: 0 30px 0 10px !important;
  border: 1px solid #d5d9df !important;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  font-size: 13px;
  font-weight: 400;
  color: #333;
  cursor: pointer;
  white-space: nowrap;
  flex-wrap: nowrap;
  display: flex;
  align-items: center;
  background-color: #fff !important;
  background-image:
    url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"),
    linear-gradient(to right, #fff calc(100% - 30px), var(--header-company-chevron-bg) calc(100% - 30px)) !important;
  background-repeat: no-repeat, no-repeat;
  background-position: right 8px center, left top;
  background-size: 12px, 100%;
  overflow: hidden !important;
}

.header-company .ts-wrapper.single .ts-control .item {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  max-width: 100%;
  line-height: 1.2;
  flex: 1 1 auto;
  min-width: 0;
}

.header-company .ts-wrapper.single .ts-control::after,
.header-company .ts-wrapper.single .ts-control::before {
  display: none !important;
  content: none !important;
}

.header-company .ts-wrapper.single.focus .ts-control,
.header-company .ts-wrapper.single:hover .ts-control {
  background-image:
    url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"),
    linear-gradient(to right, #fafbfc calc(100% - 30px), var(--header-company-chevron-bg-hover) calc(100% - 30px)) !important;
  background-color: transparent !important;
  background-repeat: no-repeat, no-repeat;
  background-position: right 8px center, left top;
  background-size: 12px, 100%;
}

.header-right form {
  position: relative;
}

/* ============================================
   SP モバイルナビ（app-mobile-nav）: PC では非表示
   ============================================ */
.app-mobile-nav {
  display: none;
}

/* ============================================
   タブレット・SP レスポンシブ（≤1023px）
   KDCS_PRJ-120: SP≤767 / タブレット768-1023 / PC≥1024
   ============================================ */
@media (max-width: 1023px) {
  /* タブレット・SP では PC ヘッダーを非表示 → app-mobile-nav に置き換え */
  .header-bar {
    display: none !important;
  }

  /* ------------------------------------------
     app-mobile-nav: タブレット・SP 表示
     ------------------------------------------ */
  .app-mobile-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 6px 8px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 200;
  }

  .app-mobile-nav-left {
    display: flex;
    align-items: center;
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
  }

  /* セクションボタン（検索フォーム TomSelect と同スタイル） */
  .app-mobile-nav-section-btn {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0;
    width: 100%;
    max-width: 165px;
    height: 32px;
    border: 1px solid #dadce0;
    border-radius: 4px;
    background: #f5f5f5;
    color: #333;
    padding: 0;
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    cursor: pointer;
  }

  .app-mobile-nav-section-btn > span:first-child {
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
  }

  /* 矢印（検索 TomSelect の ::after と同デザイン） */
  .app-mobile-nav-arrow {
    display: inline-block;
    flex-shrink: 0;
    width: 32px;
    height: 100%;
    background: #2c5f9f url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") center/14px no-repeat;
    border-left: 1px solid #2c5f9f;
    border-radius: 0 4px 4px 0;
  }

  /* セクションドロップダウン */
  .app-mobile-nav-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 160px;
    background: #fff;
    border: 1px solid #d7dde5;
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    z-index: 300;
    overflow: hidden;
  }

  .app-mobile-nav-dropdown-item {
    display: block;
    width: 100%;
    border: none;
    background: #fff;
    text-align: left;
    padding: 8px 10px;
    font-size: 12px;
    color: #374151;
    cursor: pointer;
    text-decoration: none;
  }

  .app-mobile-nav-dropdown-item:hover {
    background: #f3f6fb;
  }

  /* 右側: 支社セレクタ + アイコン群 */
  .app-mobile-nav-right {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
    flex-shrink: 1;
    min-width: 0;
    justify-content: flex-end;
  }

  .app-mobile-nav .header-company {
    flex-shrink: 0;
    min-width: 0;
    max-width: 165px;
  }

  .app-mobile-nav .header-company-btn {
    min-width: 130px;
    max-width: 165px;
    width: 130px;
    height: 32px;
    min-height: 32px;
  }

  .app-mobile-nav .company-name {
    font-size: 12px;
    padding: 0 6px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .app-mobile-nav .dropdown-arrow {
    width: 28px;
    min-width: 28px;
  }

  .app-mobile-nav .company-dropdown {
    right: 0;
    left: auto;
  }

  .app-mobile-icon-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #d5d9e0;
    border-radius: 50%;
    background: #fff;
    color: #5f6368;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ユーザーボタン */
  .app-mobile-user-btn {
    background: #b3c8e6;
    border-color: transparent;
  }

  /* ユーザーアイコン形 */
  .app-mobile-user-icon {
    position: relative;
    display: inline-block;
    width: 14px;
    height: 14px;
  }

  .app-mobile-user-icon::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
  }

  .app-mobile-user-icon::after {
    content: "";
    position: absolute;
    bottom: -2px;
    left: 1px;
    width: 12px;
    height: 8px;
    border-radius: 6px 6px 0 0;
    background: #fff;
  }

  /* ハンバーガーボタン */
  /* KDCS_PRJ-393 (D-7): SP幅のハンバーガーもPC幅と同じアクセント青へ */
  .app-mobile-menu-btn {
    border: none;
    background: transparent;
    color: #2870c4;
    width: 24px;
    height: 32px;
    font-size: 20px;
    border-radius: 0;
  }

  /* ユーザードロップダウン */
  .app-mobile-user-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 120px;
    background: #fff;
    border: 1px solid #d7dde5;
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    z-index: 300;
    overflow: hidden;
  }
}
