/* ============================================================
   admin.css — 管理画面専用CSS（main.cssと併用）
   ============================================================ */

/* レイアウト */
.admin-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   スクロールバー カスタマイズ
   ============================================================ */

/* サイドバー（ダークテーマ） */
.sidebar::-webkit-scrollbar       { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: #1e293b; }
.sidebar::-webkit-scrollbar-thumb { background: #0891b2; border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: #06b6d4; }

/* メインコンテンツエリア */
.main-content::-webkit-scrollbar       { width: 6px; }
.main-content::-webkit-scrollbar-track { background: #f1f5f9; }
.main-content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
.main-content::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Firefox */
.sidebar      { scrollbar-width: thin; scrollbar-color: #0891b2 #1e293b; }
.main-content { scrollbar-width: thin; scrollbar-color: #cbd5e1 #f1f5f9; }

/* サイドバー */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.25s ease;
}
.sidebar-logo {
  padding: 5px 16px;
  border-bottom: 1px solid #334155;
}
.sidebar-logo span {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  display: block;
  line-height: 1.3;
}
.sidebar-logo small {
  font-size: 0.7rem;
  color: #94a3b8;
}
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-group-label {
  padding: 8px 16px 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #64748b;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #94a3b8;
  font-size: 0.875rem;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: #273449; color: #e2e8f0; text-decoration: none; }
.nav-link.active { background: #1e3a5f; color: #60a5fa; border-left-color: #2563eb; }
.nav-link .nav-icon { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #334155;
  font-size: 0.8rem;
}
.sidebar-footer a { color: #94a3b8; }
.sidebar-footer a:hover { color: #e2e8f0; }

/* メインコンテンツ */
.main-content {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;        /* flex item のデフォルト min-width:auto を解除 → overflow が正しく機能する */
  overflow-x: clip;    /* hidden と異なりスクロールコンテナを生成しない（CSS Overflow Lv4）
                          → window scroll イベントが正常に発火し、横はみ出しも防げる */
}

/* トップバー */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s ease;
}
.topbar--hidden {
  transform: translateY(-100%);
}
.topbar-title { font-size: 1rem; font-weight: 700; color: var(--color-text); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: 0.875rem; color: var(--color-text-muted); }

/* ページコンテンツ */
.page-content {
  padding: 24px;
  flex: 1;
}
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}
.page-subtitle {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-bottom: 20px;
}

/* KPIカード */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.kpi-info-icon {
  font-size: 0.68rem;
  color: #94a3b8;
  vertical-align: middle;
  cursor: help;
  font-style: normal;
}
.kpi-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #e2e8f0;
  font-size: 0.75rem;
  line-height: 1.65;
  padding: 10px 13px;
  border-radius: 8px;
  width: 230px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
  pointer-events: none;
  white-space: normal;
  font-weight: 400;
}
.kpi-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1e293b;
}
.kpi-tip-title {
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 5px;
  font-size: 0.78rem;
}
.kpi-tip-status {
  margin-top: 7px;
  color: #7dd3fc;
  font-size: 0.7rem;
}
.kpi-card:hover .kpi-tip { display: block; }
.kpi-card .kpi-label { font-size: 0.8rem; color: var(--color-text-muted); font-weight: 600; margin-bottom: 8px; }
.kpi-card .kpi-value { font-size: 2rem; font-weight: 700; color: var(--color-text); line-height: 1; }
.kpi-card .kpi-unit  { font-size: 0.875rem; font-weight: 400; color: var(--color-text-muted); margin-left: 4px; }
.kpi-card .kpi-icon  { font-size: 1.5rem; float: right; margin-top: -4px; }

/* テーブル */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* iOS慣性スクロール */
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  /* white-space: nowrap は廃止 — モバイルで横スクロールの主因だったため
     折り返しを許可する。nowrap が必要なセルは .cell-nowrap クラスを使う */
}
.table th {
  background: #f8fafc;
  font-weight: 700;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap; /* ヘッダー見出しは折り返さない */
}
.table tbody tr:hover { background: #f8fafc; }
.table td a { color: var(--color-primary); }
/* 特定セルで nowrap が必要な場合のユーティリティ */
.cell-nowrap { white-space: nowrap !important; }

/* 検索・フィルターバー */
.filter-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { min-width: 160px; }

/* フォームパネル */
.form-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.form-panel-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
  padding: 14px 20px;
  font-weight: 700;
  font-size: 0.95rem;
}
.form-panel-body { padding: 20px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ステータスバッジ */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap; /* ステータス文字列は折り返さない */
}
/* 受注ステータス */
.status-新規         { background: #dbeafe; color: #1d4ed8; }
.status-スタッフ準備中 { background: #fef9c3; color: #92400e; }
.status-稼働待ち     { background: #e0e7ff; color: #4338ca; }
.status-稼働中       { background: #dcfce7; color: #166534; }
.status-入金待ち     { background: #ffedd5; color: #9a3412; }
.status-請求書発行待ち { background: #f3e8ff; color: #7e22ce; }
.status-全完了       { background: #f1f5f9; color: #475569; }
.status-強制終了     { background: #fee2e2; color: #991b1b; }
/* スタッフステータス */
.status-契約前       { background: #fce7f3; color: #9d174d; }
.status-未稼働       { background: #f1f5f9; color: #475569; }
.status-稼働待ち     { background: #e0e7ff; color: #4338ca; }
.status-稼働中       { background: #dcfce7; color: #166534; }
.status-一時停止中   { background: #fef9c3; color: #92400e; }
.status-退会済み     { background: #fee2e2; color: #991b1b; }

/* ランク表示 */
.rank-stars { color: #f59e0b; letter-spacing: 2px; }

/* ページネーション */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 20px;
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  text-decoration: none;
  transition: background var(--transition);
}
.pagination a:hover { background: var(--color-primary-light); color: var(--color-primary); }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ハンバーガー（スマホ用） */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  font-size: 1.4rem;
}

/* ログインページ */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #071728 0%, #0b2a42 45%, #0d5c6e 100%);
  padding: 20px;
}
.login-box {
  background: rgba(255,255,255,0.97);
  border-radius: 16px;
  padding: 44px 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.08);
  animation: loginBoxIn 0.5s cubic-bezier(0.22,1,0.36,1) both;
}
@keyframes loginBoxIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo-img {
  width: 140px;
  height: auto;
  display: block;
  margin: 0 auto 14px;
}
.login-subtitle {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #64748b;
  margin: 0;
}

/* ログインボタン（ブランドカラー） */
.btn-brand {
  background: linear-gradient(135deg, #0d5c6e 0%, #0891b2 100%);
  color: #fff;
  border: none;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-brand:hover  { opacity: 0.9; color: #fff; }
.btn-brand:active { transform: scale(0.98); }

/* ---- スプラッシュ共通 ---- */
#login-splash,
#entry-splash {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #071728 0%, #0b2a42 45%, #0d5c6e 100%);
  z-index: 9999;
}

/* ---- ログイン中スプラッシュ（ボタン押下） ---- */
#login-splash {
  display: none;
}
#login-splash.active {
  display: flex;
  animation: splashFadeIn 0.2s ease both;
}
@keyframes splashFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
#login-splash img {
  width: 150px;
  height: auto;
  animation: splashLogoIn 0.4s cubic-bezier(0.22,1,0.36,1) 0.1s both;
}
.splash-msg {
  color: rgba(255,255,255,0.5);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 20px 0 14px;
}
.splash-dots {
  display: flex;
  gap: 8px;
}
.splash-dots span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(13,145,178,0.7);
  animation: dotBounce 1s ease-in-out infinite;
}
.splash-dots span:nth-child(2) { animation-delay: 0.18s; }
.splash-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%           { transform: translateY(-8px); opacity: 1; }
}

/* ---- ログイン後スプラッシュ（ダッシュボード入場） ---- */
#entry-splash {
  animation: entrySplashFade 0.35s ease 0.7s both;
}
@keyframes entrySplashFade {
  from { opacity: 1; }
  to   { opacity: 0; }
}
#entry-splash img {
  width: 160px;
  height: auto;
  animation: splashLogoIn 0.5s cubic-bezier(0.22,1,0.36,1) both;
}
.splash-label {
  color: rgba(255,255,255,0.4);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 18px;
  animation: splashLogoIn 0.5s cubic-bezier(0.22,1,0.36,1) 0.15s both;
}

@keyframes splashLogoIn {
  from { opacity: 0; transform: scale(0.88) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* セクション区切り */
.section { margin-bottom: 28px; }
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-primary-light);
}

/* ============================================================
   サイドバーオーバーレイ
   モバイルでサイドバーを開いた時に背面に表示し、タップで閉じる
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99; /* sidebar(100)の下・コンテンツの上 */
  cursor: pointer;
}
.sidebar-overlay.active { display: block; }

/* ============================================================
   【条件A】サイドバー引き込み式 —「縦長」または「横幅768px以下」
   ─────────────────────────────────────────────────────────────
   orientation: portrait = 縦幅 > 横幅（縦長）のとき
     → スマホ縦、タブレット縦（iPad含む）、大型タブレット縦など
       画面の向きに関係なく縦長なら引き込み式
   max-width: 768px      = それ以外の小さい横向き端末
     → スマホ横向きなど、縦長ではないが横幅が狭いケース
   ============================================================ */
@media (orientation: portrait), (max-width: 768px) {

  /* サイドバーを画面左外に隠し、.open クラスで引き出す */
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .sidebar-toggle { display: block; }

  /* タブレット縦向き：ヘッダーを fixed に変更（transform と sticky の干渉を避けるため） */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 105;
  }
  /* fixed にした分、コンテンツがヘッダーの下に隠れないよう余白を追加 */
  .page-content {
    padding-top: 80px; /* 56px(ヘッダー高) + 24px(元のpadding) */
  }
  .topbar-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ============================================================
   【条件B】コンテンツ表示の調整 — 横幅768px以下
   ─────────────────────────────────────────────────────────────
   サイドバー引き込みとは独立して横幅だけで制御する。
   幅の広い縦長タブレット（例: iPad Pro縦 1024px）では
   コンテンツの余白・フォントサイズは PC 相当のままにする。
   ============================================================ */
@media (max-width: 768px) {

  /* ── トップバーをコンパクトに ── */
  .topbar {
    padding: 0 12px;
    height: 48px;
    gap: 8px;
  }
  .topbar-title   { font-size: 0.875rem; }
  .topbar-user    { display: none; }  /* ユーザー名は横幅不足時のみ非表示 */
  .topbar-actions { flex-shrink: 0; gap: 6px; }
  .training-mode-badge { font-size: 0.72rem; padding: 3px 8px; }

  /* ── ページコンテンツ ── */
  .page-content { padding: 12px; padding-top: 60px; } /* 48px(ヘッダー高) + 12px */
  .page-title   { font-size: 1.2rem; }

  /* ── フォームグリッド ── */
  .form-row   { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }

  /* ── KPIカード ── */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  /* ── フィルターバー（縦並び・全幅） ── */
  .filter-bar { flex-direction: column; gap: 8px; }
  .filter-bar .form-group   { width: 100%; margin-bottom: 0; }
  .filter-bar .form-control { min-width: 0; width: 100%; }
  .filter-bar > .btn,
  .filter-bar .form-group:last-of-type .btn { width: 100%; }

  /* ── テーブルセルを圧縮 ── */
  .table th,
  .table td { padding: 8px 6px; font-size: 0.8rem; }
  .table th  { font-size: 0.72rem; }
}

/* ============================================================
   【条件C】スマホ縦向き — 480px以下
   ============================================================ */
@media (max-width: 480px) {

  .page-content { padding: 10px; }
  .kpi-grid     { grid-template-columns: 1fr 1fr; }
  .btn-sm       { min-height: 36px; }

  .table th,
  .table td { padding: 6px 4px; font-size: 0.75rem; }

  .page-title    { font-size: 1.1rem; }
  .page-subtitle { font-size: 0.8rem; }

  .pagination a,
  .pagination span { width: 30px; height: 30px; font-size: 0.8rem; }
}
