/**
 * スマホ（iPhone 等）向けシェル — Teams モバイルを参考にした全体レイアウト
 * ブレークポイント: max-width 768px（タブレット横・小さめ PC は 769px〜 のまま）
 */

@media (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
  }

  body {
    overflow-x: hidden;
    max-width: 100vw;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body.manage-page {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* ========== ドロワー（左メニュー） ========== */
  #site-main-contents #site-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: -100% !important;
    width: min(88vw, 320px) !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    height: 100% !important;
    height: 100dvh !important;
    padding: 12px 14px !important;
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 2100 !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2) !important;
    overflow-x: hidden !important;
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  #site-main-contents #site-sidebar #sidebar-content {
    overflow: visible !important;
    min-height: min-content;
  }

  html.mobile-sidebar-open,
  html.mobile-sidebar-open body {
    overflow: hidden;
    height: 100%;
  }

  html.mobile-sidebar-open #site-main-contents #site-sidebar.mobile-open {
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch;
  }

  #site-main-contents #site-sidebar.mobile-open,
  #site-main-contents #site-sidebar.closed.mobile-open {
    left: 0 !important;
  }

  #site-main-contents #site-sidebar.closed:not(.mobile-open) {
    left: -100% !important;
  }

  .mobile-sidebar-overlay {
    z-index: 2090 !important;
  }

  /* ハンバーガー色は base.jinja2 の #343A40 を維持（上書きしない） */
  .mobile-menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  .mobile-menu-toggle ion-icon {
    font-size: 22px;
  }

  #site-main-contents #site-sidebar {
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mobile-sidebar-overlay {
    transition: opacity 0.25s ease;
  }

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

  /* ========== トップバー（スマホはタイトル＋ユーザーのみ。来店数などはハンバーガー内「統計」） ========== */
  #site-main #site-header {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    width: 100% !important;
    max-width: 100vw !important;
    z-index: 2000 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    padding: 0 10px 0 64px !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    box-sizing: border-box !important;
    min-height: 48px !important;
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
  }

  #site-main #site-header > div:first-child {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    padding-right: 0 !important;
  }

  #site-main #site-header h1 {
    font-size: 17px !important;
    font-weight: 600 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  #site-main #site-header #site-header-time {
    display: none !important;
  }

  #site-main #site-header > .margin-left-small {
    display: none !important;
  }

  #site-main #site-header #site-header-right-cluster {
    display: flex !important;
    flex: 0 0 auto !important;
    align-items: center !important;
    margin-left: auto !important;
    width: auto !important;
  }

  #site-main #site-header #site-header-stats {
    display: none !important;
  }

  #site-main #site-header #site-header-user-box {
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #site-main #site-header #site-header-user-box img {
    width: 32px !important;
    height: 32px !important;
  }

  #site-main #site-header #site-header-user-box span {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px !important;
  }

  /* スマホ専用ドロワー / PC は従来 DOM */
  .sidebar-drawer-desktop-only {
    display: none !important;
  }

  .sidebar-drawer-mobile-only {
    display: block;
  }

  #site-fixed-header-spacer {
    height: 0 !important;
    min-height: 0 !important;
    display: none !important;
  }

  /* ========== メイン領域 ========== */
  #site-main,
  #site-right,
  #site-main-contents,
  #site-content {
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
  }

  .main-content,
  .main-content2 {
    margin: 0 !important;
    padding: 12px 12px 10px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    font-size: 15px !important;
    line-height: 1.45;
  }

  .main-content .box,
  .box {
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  }

  .main-content .box > header.left-right,
  .main-content.box > header.left-right {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .main-content .box > header .button,
  .main-content .box > header a.button,
  .main-content .box > header form .button {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .main-content .box > header form {
    width: 100% !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .main-content .box > header form .input-item {
    width: 100% !important;
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }

  /* タッチしやすいボタン・入力（iOS のフォーカズーム防止） */
  .button,
  a.button,
  button.button {
    min-width: 0 !important;
    min-height: 44px !important;
    padding: 10px 14px !important;
    font-size: 15px !important;
    box-sizing: border-box;
  }

  .button.small {
    min-height: 36px !important;
    padding: 6px 10px !important;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,
  textarea,
  .form-control {
    font-size: 16px !important;
  }

  /* 表はラッパ内横スクロール */
  .table-wrapper,
  .main-content .table-wrapper,
  .table-scroll-enabled .table-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .global-push-permission-banner {
    bottom: env(safe-area-inset-bottom, 0px) !important;
  }

  /* モーダル・ポップアップ */
  .modal {
    padding: env(safe-area-inset-top, 0) 8px env(safe-area-inset-bottom, 0) !important;
    box-sizing: border-box !important;
  }

  .modal .modal-content,
  .popup-overlay .popup-inner {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    margin: 8px auto !important;
    max-height: calc(100dvh - 16px) !important;
  }

  .popup-overlay {
    padding: 8px !important;
    align-items: center !important;
  }

  /* 顧客入力など横並びレイアウト */
  .layout-side.full,
  .customer-input-page main.layout-side.full {
    flex-direction: column !important;
  }

  .dl-form {
    flex-direction: column !important;
  }

  .dl-form > dl {
    margin-left: 0 !important;
    width: 100% !important;
  }

  /* タブ */
  .tab {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }

  .tab li {
    flex: 0 0 auto;
  }

  /* ========== サイドバー：チャネル／チャット アコーディオン ========== */
  #site-sidebar .sidebar-header2-menu {
    margin-bottom: 8px;
  }

  #site-sidebar .sidebar-icon-menu {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  #site-sidebar .sidebar-icon-menu .icon-title {
    margin: 0;
    text-align: center;
  }

  #site-sidebar .sidebar-icon-menu .icon-title dd {
    font-size: 10px;
    margin-top: 4px;
  }

  .sidebar-drawer-accordions {
    margin-top: 0;
    margin-bottom: 12px;
  }

  .sidebar-acc-permission-msg--top {
    margin-bottom: 12px;
  }

  .mobile-sidebar-acc {
    margin-bottom: 8px;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .mobile-sidebar-acc__trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 12px 14px;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-sidebar-acc__icon {
    font-size: 20px;
    flex-shrink: 0;
    opacity: 0.95;
  }

  .mobile-sidebar-acc__label {
    flex: 1;
    min-width: 0;
  }

  .mobile-sidebar-acc__badge {
    flex-shrink: 0;
    margin-right: 4px;
  }

  .mobile-sidebar-acc__chev {
    font-size: 18px;
    flex-shrink: 0;
    transition: transform 0.22s ease;
    opacity: 0.85;
  }

  .mobile-sidebar-acc.is-open .mobile-sidebar-acc__chev {
    transform: rotate(180deg);
  }

  .mobile-sidebar-acc.is-open .mobile-sidebar-acc__trigger {
    background: rgba(255, 255, 255, 0.12);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .mobile-sidebar-acc:not(.is-open) .mobile-sidebar-acc__body {
    display: none !important;
  }

  .mobile-sidebar-acc.is-open .mobile-sidebar-acc__body {
    display: block;
    max-height: none;
    overflow: visible;
    padding: 0 0 8px;
  }

  .mobile-sidebar-acc .sidebar-acc-desktop-bar,
  .mobile-sidebar-acc .store-icon-view--sidebar-acc {
    display: none !important;
  }

  .sidebar-acc-panel-inner {
    padding: 4px 8px 8px;
  }

  .sidebar-acc-panel-actions {
    padding: 8px 6px;
  }

  .sidebar-acc-panel-btn {
    width: 100%;
    min-height: 40px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
  }

  .sidebar-acc-panel-btn--primary {
    background: #6e42cc;
    border-color: transparent;
  }

  .sidebar-acc-inline-panel {
    padding: 8px 6px 12px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .sidebar-acc-label {
    display: block;
    font-size: 11px;
    opacity: 0.85;
    margin-bottom: 4px;
    color: #fff;
  }

  .sidebar-acc-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    margin-bottom: 8px;
    font-size: 16px;
  }

  .sidebar-acc-member-list {
    max-height: 140px;
    overflow-y: auto;
    margin-bottom: 8px;
  }

  .sidebar-acc-member-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 2px;
    font-size: 13px;
    color: #fff;
    cursor: pointer;
  }

  .sidebar-acc-link {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    padding: 10px 10px;
    border-radius: 8px;
    margin-bottom: 2px;
    line-height: 1.35;
  }

  .sidebar-acc-link:active {
    background: rgba(255, 255, 255, 0.1);
  }

  .sidebar-acc-link.sidebar-active {
    background: rgba(255, 255, 255, 0.18);
  }

  .sidebar-acc-link__title {
    font-weight: 600;
    font-size: 14px;
  }

  .sidebar-acc-link__sub {
    display: block;
    font-size: 11px;
    opacity: 0.75;
  }

  .sidebar-acc-empty-hint {
    color: rgba(255, 255, 255, 0.55);
    font-size: 12px;
    padding: 10px;
  }

  .sidebar-acc-empty-hint--indent {
    margin-left: 10px;
  }

  #site-sidebar .team-item {
    margin-bottom: 12px;
  }

  #site-sidebar .team-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    color: #fff;
    padding: 10px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  }

  #site-sidebar .team-header__main {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
  }

  #site-sidebar .team-header__name {
    flex: 1;
    min-width: 0;
    font-size: 14px;
  }

  #site-sidebar .team-toggle-icon {
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.2s;
  }

  #site-sidebar .drag-handle-team,
  #site-sidebar .drag-handle-channel {
    opacity: 0.5;
    cursor: move;
  }

  #site-sidebar .team-channels {
    margin-left: 8px;
  }

  #site-sidebar .channel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
  }

  #site-sidebar .channel-item__main {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
  }

  #site-sidebar .channel-item__link {
    flex: 1;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    padding: 4px 0;
    min-width: 0;
  }

  .sidebar-acc-permission-msg {
    color: rgba(255, 255, 255, 0.55);
    font-size: 13px;
    padding: 12px 10px;
    margin: 0;
    line-height: 1.5;
  }

  /* ========== ボトムナビ（Teams モバイル風）— 全体で非表示のためスタイルのみ残す ========== */
  .mobile-bottom-nav {
    display: none !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2080;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    justify-content: space-around;
    align-items: stretch;
    box-sizing: border-box;
  }

  .mobile-bottom-nav__item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px 4px;
    text-decoration: none;
    color: #6b7280;
    font-size: 10px;
    font-weight: 600;
    min-width: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }

  .mobile-bottom-nav__item ion-icon {
    font-size: 23px;
    flex-shrink: 0;
  }

  .mobile-bottom-nav__item.is-active {
    color: #2d8659;
  }

  .mobile-bottom-nav__item.is-active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: #2d8659;
  }

  .mobile-bottom-nav__item--menu {
    color: #374151;
  }

  /* base.jinja2 の 480px で h1 が 130% になりハンバーガーと被るのを防ぐ */
  @media (max-width: 480px) {
    #site-main #site-header h1 {
      font-size: 17px !important;
    }
  }

  /* リスト表: PC は .table-scroll-enabled で内側スクロール、スマホはページ縦スクロール */
  html.table-scroll-enabled,
  body.table-scroll-enabled {
    height: auto !important;
    min-height: 100%;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  body.table-scroll-enabled #site-content,
  body.table-scroll-enabled #site-main-contents,
  body.table-scroll-enabled #site-right {
    height: auto !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
  }

  body.table-scroll-enabled .main-content {
    height: auto !important;
    display: block !important;
    overflow: visible !important;
  }

  body.table-scroll-enabled .box {
    display: block !important;
    overflow: visible !important;
    flex: none !important;
    min-height: 0 !important;
  }

  body.table-scroll-enabled .box form {
    display: block !important;
  }

  body.table-scroll-enabled .table-wrapper,
  body.table-scroll-enabled .table-wrapper-container,
  body.table-scroll-enabled #table-wrapper,
  body.table-scroll-enabled #customer-purchase-list-scroll {
    flex: none !important;
    max-height: none !important;
    height: auto !important;
    min-height: 0 !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* タブレット・PC：従来の channel/chat ドロワー（アコーディオンは非表示） */
@media (min-width: 769px) {
  .sidebar-drawer-mobile-only {
    display: none !important;
  }

  .sidebar-drawer-desktop-only {
    display: block !important;
  }
}

/* モバイル下部ナビ（ホーム/新着/チャネル等）: URL・画面サイズ・印刷問わず常に非表示 */
#mobile-bottom-nav,
.mobile-bottom-nav {
  display: none !important;
  visibility: hidden !important;
}

@media print {
  #mobile-bottom-nav,
  .mobile-bottom-nav {
    display: none !important;
    visibility: hidden !important;
  }
}
