/*
 * =====================================================
 * ECHO B2B Admin Console — responsive.css
 * ブレークポイント:
 *   tablet  : max 1023px
 *   mobile  : max 767px
 * =====================================================
 */

:root {
  --sidebar-width: 240px;
  --header-height: 64px;
}


/* =====================================================
   1. タブレット (〜1023px)
   ===================================================== */
@media (max-width: 1023px) {

  /* サイドバー: アイコンのみ */
  .sidebar {
    width: 64px;
    overflow: hidden;
  }
  .sidebar-logo-text,
  .sidebar-nav-label,
  .sidebar-nav-item span,
  .sidebar-nav-badge,
  .sidebar-tenant-info {
    display: none;
  }
  .sidebar-nav-item {
    justify-content: center;
    padding: 10px 0;
  }
  .sidebar-nav-item svg {
    margin: 0;
  }
  .sidebar-logo {
    justify-content: center;
    padding: 16px 0;
  }
  .sidebar-tenant {
    justify-content: center;
  }

  /* メインエリア: サイドバー幅を64pxに */
  .main-area {
    margin-left: 64px;
  }

  /* KPIカード1行目(2列) → そのまま */
  /* KPIカード2行目(4列) → 2列 */
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* グラフ横並び → 縦 */
  .grid-2 {
    grid-template-columns: 1fr;
  }

  /* テーブル非表示列 */
  .table-col-hide-tablet {
    display: none;
  }

  /* コンテンツカード: 3列→2列 */
  .content-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* レポート */
  .report-template-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}


/* =====================================================
   2. スマートフォン (〜767px)
   ===================================================== */
@media (max-width: 767px) {

  /* --- サイドバー: ハンバーガー制御でオーバーレイ表示 --- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.15);
    overflow: visible;
  }
  /* サイドバー開いたときにテキスト再表示 */
  .sidebar-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-open .sidebar-logo-text,
  .sidebar-open .sidebar-nav-label,
  .sidebar-open .sidebar-nav-item span,
  .sidebar-open .sidebar-nav-badge,
  .sidebar-open .sidebar-tenant-info {
    display: block;
  }
  .sidebar-open .sidebar-nav-item {
    justify-content: flex-start;
    padding: 10px 20px;
  }
  .sidebar-open .sidebar-logo {
    justify-content: flex-start;
    padding: 20px;
  }
  .sidebar-open .sidebar-tenant {
    justify-content: flex-start;
  }

  /* オーバーレイ */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
  }
  .sidebar-open .sidebar-overlay {
    display: block;
  }

  /* --- メインエリア: サイドバーなし --- */
  .main-area {
    margin-left: 0;
  }

  /* --- ヘッダー --- */
  .top-header {
    padding: 0 12px;
  }
  .header-search {
    display: none;
  }
  .header-search.search-visible {
    display: flex;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    z-index: 100;
  }
  .header-period-select {
    display: none;
  }
  .header-user-name {
    display: none;
  }

  /* ハンバーガーボタン */
  .hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    color: var(--color-gray-500);
    flex-shrink: 0;
  }
  .hamburger-btn:hover {
    background: var(--color-gray-100);
  }

  /* --- ページコンテンツ --- */
  .page-content {
    padding: 16px;
  }
  .page-header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .page-actions .btn {
    flex: 1;
    justify-content: center;
  }

  /* --- KPIカード --- */
  /* 1行目(2列) → 1列 */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* 2行目(4列) → 1列 */
  .grid-4 {
    grid-template-columns: 1fr;
  }
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .kpi-card {
    padding: 16px;
  }
  .kpi-card-value {
    font-size: 28px;
  }

  /* --- グラフ --- */
  .chart-container {
    height: 200px !important;
  }

  /* --- テーブル --- */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-col-hide-mobile {
    display: none;
  }
  .table-col-hide-tablet {
    display: none;
  }

  /* --- タブ: 横スクロール --- */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* --- フィルターバー --- */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-bar select,
  .filter-bar input {
    width: 100%;
  }

  /* --- コンテンツカード: 1列 --- */
  .content-card-grid {
    grid-template-columns: 1fr;
  }

  /* --- グループ管理 --- */
  .group-layout {
    grid-template-columns: 1fr !important;
  }

  /* --- レポート --- */
  .report-template-grid {
    grid-template-columns: 1fr;
  }
  .report-layout {
    grid-template-columns: 1fr !important;
  }

  /* --- 設定 --- */
  .settings-layout {
    grid-template-columns: 1fr !important;
  }
  .settings-nav {
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: 8px 0;
  }
  .settings-nav-item {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* --- モーダル --- */
  .modal {
    margin: 16px;
    max-width: calc(100% - 32px);
  }

  /* --- アラートバナー --- */
  .alert-banner {
    flex-direction: column;
    align-items: flex-start;
  }

  /* --- ページネーション --- */
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* --- ユーザー詳細 --- */
  .compare-cols {
    grid-template-columns: 1fr !important;
    text-align: center;
  }
}


/* =====================================================
   3. ハンバーガーボタン — PC/tablet では非表示
      ※ メディアクエリより前に定義すること（後に書くとスマホでも上書きされる）
   ===================================================== */
.hamburger-btn {
  display: none;
}

.sidebar-overlay {
  display: none;
}

/* スマホ幅では表示（メディアクエリ内の display:flex が優先されるよう !important で保護） */
@media (max-width: 767px) {
  .hamburger-btn {
    display: flex !important;
  }
}


/* =====================================================
   4. プリント対応
   ===================================================== */
@media print {
  .sidebar,
  .hamburger-btn,
  .header-actions,
  .filter-bar,
  .pagination,
  .sidebar-overlay {
    display: none !important;
  }
  .main-area {
    margin-left: 0 !important;
  }
  .grid-4 {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  .grid-2 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}
