/* 共通モバイルシェル — ScienceHUB アプリ横断 */

:root {
  --bp-md: 768px;
  --bp-sm: 640px;
  --app-header-h: 3.5rem;
  --app-safe-top: env(safe-area-inset-top, 0px);
  --app-safe-right: env(safe-area-inset-right, 0px);
  --app-safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-safe-left: env(safe-area-inset-left, 0px);
}

@media (max-width: 768px) {
  html,
  body {
    overflow-x: clip;
    max-width: 100%;
  }
}

/* 汎用アプリヘッダー */
.app-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  min-width: 0;
  padding-left: max(1rem, var(--app-safe-left));
  padding-right: max(1rem, var(--app-safe-right));
}

.app-header-title {
  margin: 0;
  min-width: 0;
  flex: 1 1 auto;
}

.app-header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-left: auto;
}

/* オーバーフローメニュー — hidden は全幅で有効 */
.app-overflow-menu[hidden] {
  display: none !important;
}

/* カードリスト（テーブル代替） */
.app-card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-card {
  padding: 0.875rem 1rem;
  border: 1px solid #e2e5e9;
  border-radius: 8px;
  background: #fff;
}

.app-card-title {
  margin: 0 0 0.35rem;
  font-size: 0.9375rem;
  font-weight: 600;
  word-break: break-word;
}

.app-card-meta {
  margin: 0;
  font-size: 0.8125rem;
  color: #6b7280;
}

.app-card-bar {
  margin-top: 0.5rem;
  height: 6px;
  background: #f6f8fa;
  border-radius: 999px;
  overflow: hidden;
}

.app-card-bar-fill {
  height: 100%;
  background: #0ea5e9;
  border-radius: 999px;
}

.app-card-bar-fill.is-warning {
  background: #f59e0b;
}

.app-card-bar-fill.is-danger {
  background: #dc2626;
}

@media (max-width: 768px) {
  .app-touch-target {
    min-height: 44px;
  }

  .app-overflow-menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    z-index: 50;
    min-width: 11rem;
    max-width: min(20rem, calc(100vw - 2rem));
    padding: 0.35rem;
    background: #fff;
    border: 1px solid #e2e5e9;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .app-overflow-menu .cs-btn,
  .app-overflow-menu .cs-sort-controls {
    width: 100%;
    margin-left: 0 !important;
  }

  .app-overflow-menu .cs-sort-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .app-overflow-menu .cs-sort-select {
    width: 100%;
  }

  .app-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(15, 23, 42, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .app-drawer-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .app-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    width: min(280px, calc(100vw - 3rem));
    max-width: 100%;
    padding-top: var(--app-safe-top);
    padding-bottom: var(--app-safe-bottom);
    background: #f6f8fa;
    border-right: 1px solid #e2e5e9;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-drawer.is-open {
    transform: translateX(0);
  }
}
