/**
 * レイアウトスタイル - Equus Cloud
 * モダンなサイドバーナビゲーション & 3カラムレイアウト
 */

/* ===== アプリケーションコンテナ ===== */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: #f5f7fa;
}

/* ===== ヘッダー ===== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: #ffffff;
  border-bottom: 1px solid #e5e5e5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

/* ハンバーガーメニュー */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  color: #0a0a0a;
  font-size: 1.5rem;
  border-radius: 6px;
  transition: background-color 0.15s ease;
}

.menu-toggle:hover {
  background: #f5f5f5;
}

.hamburger {
  display: block;
  width: 20px;
  height: 2px;
  background: #0a0a0a;
  position: relative;
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 2px;
  background: #0a0a0a;
  transition: all 0.2s;
}

.hamburger::before {
  top: -6px;
}

.hamburger::after {
  top: 6px;
}

/* ロゴ */
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: #0a0a0a;
  font-weight: 600;
  font-size: 1rem;
  transition: opacity 0.15s;
}

.logo:hover {
  opacity: 0.7;
}

.logo-icon {
  font-size: 1.5rem;
  line-height: 1;
  display: none;
}

.logo-text {
  font-size: 15px;
  letter-spacing: -0.01em;
}

.logo-img {
  height: 40px;
  width: auto;
  display: block;
}

/* ヘッダーアイテム */
.header-item {
  position: relative;
}

.icon-btn {
  background: #fafafa;
  border: 1px solid #e5e5e5;
  color: #0a0a0a;
  font-size: 1.125rem;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: #f5f5f5;
  border-color: #d4d4d4;
}

.badge-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff6b6b;
  color: white;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.125rem 0.375rem;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ユーザーメニュー */
.user-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #fafafa;
  border: 1px solid #e5e5e5;
  color: #0a0a0a;
  padding: 0.375rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
  font-size: 13px;
}

.user-btn:hover {
  background: #f5f5f5;
  border-color: #d4d4d4;
}

.user-avatar {
  font-size: 1.125rem;
}

.user-name {
  font-size: 13px;
}

.dropdown-arrow {
  font-size: 0.625rem;
  transition: transform 0.15s;
  color: #737373;
}

.user-btn:hover .dropdown-arrow {
  transform: rotate(90deg);
}

/* ドロップダウンメニュー */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  min-width: 220px;
  max-height: calc(100vh - 80px); /* ビューポート高さからヘッダーとマージンを引く */
  overflow-y: auto; /* 縦スクロールを有効化 */
  -webkit-overflow-scrolling: touch; /* iOSでスムーズスクロール */
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s;
  z-index: 100;
}

.dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ドロップダウンメニューのスクロールバースタイル */
.dropdown-menu::-webkit-scrollbar {
  width: 6px;
}

.dropdown-menu::-webkit-scrollbar-track {
  background: #f8f9fa;
  border-radius: 10px;
}

.dropdown-menu::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 10px;
}

.dropdown-menu::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

.dropdown-header {
  padding: 1rem;
  border-bottom: 1px solid #e9ecef;
}

.user-info .user-name-large {
  font-weight: 600;
  font-size: 1rem;
  color: #212529;
  margin-bottom: 0.25rem;
}

.user-info .user-email {
  font-size: 0.8125rem;
  color: #6c757d;
}

.dropdown-divider {
  height: 1px;
  background: #e9ecef;
  margin: 0.5rem 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: #212529;
  text-decoration: none;
  font-size: 0.9375rem;
  transition: background 0.2s;
}

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

.item-icon {
  font-size: 1.125rem;
  width: 24px;
  text-align: center;
}

/* ===== ヘッダーナビゲーション ===== */
.header-nav {
  flex: 1;
  max-width: 600px;
  margin: 0 2rem;
}

.header-nav .nav-list {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.header-nav .nav-item {
  position: relative;
}

.header-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #525252;
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}

.header-nav .nav-link:hover {
  background: #f5f5f5;
  color: #0a0a0a;
}

.header-nav .dropdown-arrow {
  font-size: 0.75rem;
  margin-left: 0.25rem;
  transition: transform 0.2s;
}

.header-nav .has-dropdown:hover .dropdown-arrow,
.header-nav .has-dropdown.open .dropdown-arrow {
  transform: rotate(90deg);
}

/* ヘッダーナビゲーションのドロップダウンメニュー */
.header-nav .dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s;
  z-index: 1001;
  border: 1px solid #e9ecef;
  list-style: none;
  padding: 0.5rem 0;
  margin: 0;
}

.header-nav .dropdown-menu.show,
.header-nav .has-dropdown:hover .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.header-nav .dropdown-menu li {
  list-style: none;
  margin: 0;
  padding: 0;
}

.header-nav .dropdown-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: #374151;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  border-radius: 4px;
  margin: 0.25rem;
}

.header-nav .dropdown-menu .dropdown-item:hover {
  background: #f3f4f6;
  color: #667eea;
}

.header-nav .dropdown-menu .item-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

/* サブメニュー（マスタ管理） */
.dropdown-submenu {
  position: relative;
}

.dropdown-item.has-submenu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
}

.submenu-arrow {
  font-size: 0.75rem;
  margin-left: auto;
  transition: transform 0.2s;
}

.dropdown-submenu-content {
  position: absolute;
  left: 100%;
  top: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-10px);
  transition: all 0.2s;
  z-index: 1002;
  border: 1px solid #e9ecef;
}

.dropdown-submenu-content.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

/* デスクトップ表示制御 */
.desktop-only {
  display: block;
}

/* 1150px以下でデスクトップ専用要素を非表示 */
@media (max-width: 1150px) {
  .desktop-only {
    display: none !important;
  }
}

/* ===== メインラッパー ===== */
.main-wrapper {
  display: flex;
  flex: 1;
  margin-top: 56px;
  position: relative;
}

/* ===== サイドバー ===== */
.sidebar {
  position: fixed;
  left: -260px; /* デフォルトでは非表示 */
  top: 56px;
  bottom: 0;
  width: 260px;
  height: calc(100vh - 56px); /* ビューポート高さからヘッダーを引いた高さ */
  background: white;
  border-right: 1px solid #e5e5e5;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* iOSでスムーズスクロール */
  transition: left 0.3s ease;
  z-index: 900;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
}

/* サイドバーが開いた状態（全画面サイズで有効） */
.sidebar.open {
  left: 0 !important;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: #f8f9fa;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

/* サイドバーナビゲーション */
.sidebar-nav {
  padding: 1.5rem 0;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  margin-bottom: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.625rem 1rem;
  color: #525252;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  position: relative;
  border-left: 2px solid transparent;
  border-radius: 0;
}

.nav-link:hover {
  background: #fafafa;
  color: #0a0a0a;
  border-left-color: #d4d4d4;
}

.nav-link.active {
  background: #fafafa;
  color: #0a0a0a;
  font-weight: 600;
  border-left-color: #0a0a0a;
}

.nav-link.active::before {
  content: '';
  position: absolute;
  right: 1rem;
  width: 4px;
  height: 4px;
  background: #0a0a0a;
  border-radius: 50%;
}

.nav-icon {
  font-size: 1.375rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.nav-text {
  flex: 1;
}

.nav-divider {
  height: 1px;
  background: #e9ecef;
  margin: 1rem 1.5rem;
}

/* ナビゲーショングループ */
.nav-group {
  margin-bottom: 0;
}

.nav-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.nav-toggle .nav-link {
  display: flex;
  width: 100%;
}

.nav-arrow {
  font-size: 0.75rem;
  margin-left: auto;
  transition: transform 0.2s;
}

.nav-group.open .nav-arrow {
  transform: rotate(90deg);
}

.nav-sublist {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.nav-group.open .nav-sublist {
  max-height: 500px;
}

.nav-subitem {
  margin: 0;
}

.nav-subitem .nav-link {
  padding-left: 4rem;
  font-size: 0.875rem;
  font-weight: 400;
}

/* ===== コンテンツエリア ===== */
.content-area {
  flex: 1;
  margin-left: 0; /* デスクトップでもサイドバーは非表示なので0 */
  padding: 2rem;
  min-height: calc(100vh - 56px);
  transition: margin-left 0.3s ease;
  max-width: 100%;
  overflow-x: hidden;
  width: 100%;
}

/* ===== AIパネル ===== */
.ai-panel {
  position: fixed;
  right: 0;
  top: 56px;
  bottom: 0;
  width: 320px;
  background: white;
  border-left: 1px solid #e5e5e5;
  overflow-y: auto;
  z-index: 850;
  transition: all 0.3s ease;
}

/* ===== オーバーレイ（モバイル用） ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 899;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
  display: block !important;
  opacity: 1 !important;
}

/* ===== レスポンシブ ===== */

/* デスクトップ大画面（1400px以上）：ヘッダーナビゲーション表示、ハンバーガーメニュー非表示 */
@media (min-width: 1400px) {
  .header-nav {
    display: block;
  }

  .menu-toggle {
    display: none !important;
  }
}

/* 1151px〜1300px：ヘッダーのスペーシングを調整 */
@media (min-width: 1151px) and (max-width: 1300px) {
  .app-header {
    padding: 0 0.75rem;
  }

  .header-left {
    gap: 0.5rem;
  }

  .header-right {
    gap: 0.75rem;
  }
}

/* タブレット・モバイル（1150px以下）：ヘッダーナビゲーション非表示、ハンバーガーメニュー表示 */
@media (max-width: 1150px) {
  .ai-panel {
    display: none;
  }

  .content-area {
    margin-right: 0;
  }

  /* ヘッダーナビゲーションを非表示にしてハンバーガーメニューを表示 */
  .header-nav {
    display: none !important;
  }

  .menu-toggle {
    display: block !important;
  }
}

/* モバイル（768px以下）- 追加のモバイル最適化 */
@media (max-width: 768px) {
  .app-header {
    padding: 0 1rem;
    height: 56px;
  }

  .logo-text {
    font-size: 14px;
  }

  .logo-img {
    height: 36px;
  }

  .user-name {
    display: none;
  }

  .content-area {
    margin-left: 0;
    padding: 1rem;
    overflow-x: hidden;
  }

  .dropdown-menu {
    right: 0;
    left: auto;
    max-width: calc(100vw - 2rem);
  }

  /* サブメニューをモバイルで調整 */
  .dropdown-submenu-content {
    position: static;
    background: #f8f9fa;
    box-shadow: none;
    border: none;
    border-radius: 4px;
    margin-top: 0.5rem;
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: none;
  }
}

/* iPhone 12以下（414px以下）- 詳細調整 */
@media (max-width: 414px) {
  .app-header {
    padding: 0 0.75rem;
    height: 56px;
  }

  .logo-icon {
    font-size: 1.25rem;
  }

  .logo-text {
    font-size: 13px;
  }

  .logo-img {
    height: 34px;
  }

  .user-btn {
    padding: 0.375rem 0.625rem;
  }

  .user-avatar {
    font-size: 1rem;
  }

  .content-area {
    padding: 0.75rem;
    margin-top: 56px;
  }

  .main-wrapper {
    margin-top: 56px;
  }
}

/* 小モバイル（375px以下）- iPhone SE */
@media (max-width: 375px) {
  .app-header {
    padding: 0 0.5rem;
    height: 56px;
  }

  .logo-icon {
    font-size: 1.125rem;
  }

  .logo-text {
    font-size: 12px;
  }

  .logo-img {
    height: 32px;
  }

  .content-area {
    padding: 0.5rem;
  }
}


/* ===== テーブル横スクロール ===== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

.table-responsive::-webkit-scrollbar {
  height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* テーブル最小幅を設定（モバイルでスクロール可能に） */
.table-responsive .table {
  min-width: 600px;
}

/* モバイルでのテーブルスクロールヒント */
@media (max-width: 768px) {
  .table-responsive {
    position: relative;
  }

  .table-responsive::after {
    content: '← スワイプして全体を表示 →';
    display: block;
    text-align: center;
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 0.5rem;
    font-style: italic;
  }

  /* スクロールバーを常に表示（モバイル） */
  .table-responsive {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
  }
}

/* ダークモード対応（将来用）*/
@media (prefers-color-scheme: dark) {
  /* ダークモードのスタイルは将来実装 */
}
