/* ダッシュボードレイアウト: PC=左サイドバー / SP=トグルメニュー */

:root {
  --sidebar-width: 260px;
  --mobile-header-height: 56px;
  --font-sans: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --radius-sm: 12px;
  --shadow-sm: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
html[data-theme="dark"] {
  --bg: #0f172a;
  --card-bg: #1e293b;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --shadow-sm: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
}

.app-body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
  padding-top: 0;
}

/* ========== PC: 左サイドバー ========== */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--card-bg);
  border-right: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.app-sidebar-logo {
  padding: 20px 20px 16px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-sidebar-logo:hover {
  color: var(--primary);
}
.app-sidebar-logo svg {
  flex-shrink: 0;
}
.app-sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.app-sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9375rem;
  transition: background 0.2s, color 0.2s;
}
.app-sidebar-nav a:hover {
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
}
.app-sidebar-nav a.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}
.app-sidebar-auth {
  margin-top: auto;
  padding: 16px 12px;
  border-top: 1px solid var(--border-color);
}
.app-sidebar-auth a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
}
.app-sidebar-auth a:hover {
  color: var(--primary);
}

/* ========== メインコンテンツ（PC でサイドバー分オフセット） ========== */
.app-main {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.2s;
}
.app-main-inner {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 768px) {
  .app-main-inner { padding: 32px; }
}

/* ========== スマホ: 上部ヘッダー + ハンバーガーメニュー ========== */
.app-mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--mobile-header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  z-index: 101;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: var(--shadow-sm);
}
.app-mobile-header-logo {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
}
.app-mobile-header-logo:hover {
  color: var(--primary);
}
.app-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}
.app-menu-toggle:hover {
  background: rgba(0, 0, 0, 0.05);
}
html[data-theme="dark"] .app-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}
.app-menu-toggle-icon {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.app-menu-toggle-icon span {
  display: block;
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}
.app-menu-toggle[aria-expanded="true"] .app-menu-toggle-icon span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.app-menu-toggle[aria-expanded="true"] .app-menu-toggle-icon span:nth-child(2) {
  opacity: 0;
}
.app-menu-toggle[aria-expanded="true"] .app-menu-toggle-icon span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* スマホ時: サイドバー非表示・ヘッダー表示・メインに上余白 */
@media (max-width: 1023px) {
  .app-sidebar {
    display: none;
  }
  .app-main {
    margin-left: 0;
    padding-top: var(--mobile-header-height);
  }
  .app-mobile-header {
    display: flex;
  }
}

/* モバイルメニュー（オーバーレイ + パネル） */
.app-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 102;
  opacity: 0;
  transition: opacity 0.2s;
}
.app-mobile-overlay.is-open {
  display: block;
  opacity: 1;
}
.app-mobile-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, 85vw);
  height: 100vh;
  background: var(--card-bg);
  z-index: 103;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  transform: translateX(-100%);
  transition: transform 0.25s ease-out;
  overflow-y: auto;
}
.app-mobile-overlay.is-open .app-mobile-menu {
  transform: translateX(0);
}
.app-mobile-menu-header {
  padding: 20px 20px 16px;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
}
.app-mobile-menu-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.app-mobile-menu-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  text-decoration: none;
  font-weight: 500;
  font-size: 1rem;
}
.app-mobile-menu-nav a:hover {
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
}
.app-mobile-menu-auth {
  margin-top: auto;
  padding: 16px 12px;
  border-top: 1px solid var(--border-color);
}
.app-mobile-menu-auth a {
  display: block;
  padding: 12px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9375rem;
}
.app-mobile-menu-auth a:hover {
  color: var(--primary);
}

/* ボディのスクロールロック（メニュー開時） */
body.app-menu-open {
  overflow: hidden;
}

/* サイドバー・モバイルメニュー内のダークモードボタン */
.app-sidebar-dark-toggle,
.app-mobile-dark-toggle {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  cursor: pointer;
  text-align: left;
}
.app-sidebar-dark-toggle:hover,
.app-mobile-dark-toggle:hover {
  color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
}
.app-mobile-dark-toggle {
  margin-top: 12px;
  font-size: 0.9375rem;
}

/* ログイン・登録など中央寄せページ用（フォームとフッターを縦に分離） */
.app-main-inner.page-center {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: calc(100vh - var(--mobile-header-height));
  padding-bottom: 24px;
  box-sizing: border-box;
}
.app-main-inner.page-center > :not(.mag-footer-strip) {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  padding: 16px 0 24px;
}
.app-main-inner.page-center .mag-footer-strip {
  flex: 0 0 auto;
  margin-top: 0;
  width: 100%;
}
@media (min-width: 1024px) {
  .app-main-inner.page-center {
    min-height: 100vh;
  }
}

/* Plotly グラフ 全画面表示オーバーレイ */
.plotly-fullscreen-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.92);
  align-items: center;
  justify-content: center;
  padding: 48px 16px 16px;
  box-sizing: border-box;
}
.plotly-fullscreen-overlay.is-open {
  display: flex;
}
.plotly-fullscreen-overlay .plotly-fullscreen-inner {
  position: relative;
  width: 100%;
  max-width: 1200px;
  height: 100%;
  max-height: calc(100vh - 80px);
  background: var(--card-bg, #fff);
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.plotly-fullscreen-overlay .plotly-fullscreen-chart {
  width: 100%;
  height: 100%;
  min-height: 400px;
}
.plotly-fullscreen-overlay .plotly-fullscreen-close {
  position: absolute;
  top: -44px;
  right: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--card-bg, #fff);
  color: var(--text-main, #0f172a);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1;
  transition: background 0.2s, transform 0.2s;
}
.plotly-fullscreen-overlay .plotly-fullscreen-close:hover {
  background: #e2e8f0;
  transform: scale(1.05);
}
.plotly-expand-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.9);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  z-index: 10;
  transition: background 0.2s, transform 0.2s;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}
.plotly-expand-btn:hover {
  background: #1d4ed8;
  transform: scale(1.08);
}
[data-plotly-chart] {
  position: relative;
}
