/* ===== リセット & 基本 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== Royal Navy デザイン — カラートークン ===== */
:root {
  --primary:        #0D2144;   /* ロイヤルネイビー */
  --primary-dark:   #0A1628;   /* ナビゲーション用ダーク紺 */
  --primary-light:  #1A3A6B;   /* ホバー・アクセント紺 */
  --accent:         #C4972A;   /* ゴールド */
  --accent-light:   #E8D08A;   /* ライトゴールド */
  --green:          #1B6B3A;   /* 深い緑 */
  --red:            #B71C1C;   /* エラーレッド */
  --orange:         #C84B00;   /* 警告オレンジ */
  --bg:             #F4F7FB;   /* ライトブルーグレー背景 */
  --card-bg:        #FFFFFF;   /* カード白 */
  --border:         #D8E2F0;   /* ライトブルーボーダー */
  --text:           #1A2744;   /* ダークネイビーテキスト */
  --text-muted:     #6B7A99;   /* ミュートブルーグレー */
  --shadow:         0 2px 12px rgba(13,33,68,0.10);
  --shadow-md:      0 4px 20px rgba(13,33,68,0.14);
  --radius:         10px;
}

body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: -webkit-fill-available;  /* iOS Safari fallback */
  min-height: 100dvh;                   /* modern browsers (override) */
  -webkit-text-size-adjust: 100%;       /* iOS Safari: 横向きで text 自動拡大を無効化 */
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== ナビゲーション ===== */
/* 旧 .navbar / .nav-hamburger CSS は削除。サイドバーは aside.sidebar に統合（末尾参照） */

/* ===== メインコンテンツ ===== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 36px 28px;
}
.page-title {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 28px;
  padding-bottom: 14px;
  border-bottom: 3px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.02em;
}

/* ===== カード ===== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.card + .card { margin-top: 14px; }
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
}
.card-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: filter 0.2s, transform 0.1s, box-shadow 0.2s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:hover  { filter: brightness(1.08); }
.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(13,33,68,0.25);
}
.btn-accent  { background: var(--accent); color: white; box-shadow: 0 2px 8px rgba(196,151,42,0.30); }
.btn-green   { background: var(--green);  color: white; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); filter: none; }
.btn-danger  { background: var(--red); color: white; }
.btn-sm      { padding: 5px 12px; font-size: 0.8rem; }
.btn-icon    { padding: 5px 8px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ===== フォーム ===== */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 16px;  /* iOS Safari: focus 時のオートズームを防止 (16px 未満で zoom 発生) */
  background: #FFFFFF;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,33,68,0.10);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* ===== 認証ページ ===== */
.auth-wrap {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #0A1628 0%, #0D2144 55%, #1A3A6B 100%);
  padding: 24px;
  position: relative;
  overflow: hidden;
}
/* 装飾ライン */
.auth-wrap::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.auth-card {
  background: white;
  border-radius: 16px;
  padding: 44px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.30);
  border-top: 3px solid var(--accent);
}
.auth-logo {
  text-align: center;
  margin-bottom: 30px;
}
.auth-logo .logo-icon { font-size: 2.8rem; }
.auth-logo h1 { font-size: 1.3rem; color: var(--primary); font-weight: 700; margin-top: 10px; letter-spacing: 0.04em; }
.auth-logo p  { font-size: 0.84rem; color: var(--text-muted); margin-top: 5px; }

/* ===== メッセージ ===== */
.msg-error {
  background: #FFF0F0;
  border-left: 4px solid var(--red);
  padding: 10px 14px;
  border-radius: 5px;
  color: var(--red);
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: none;
}
.msg-success {
  background: #F0F8F2;
  border-left: 4px solid var(--green);
  padding: 10px 14px;
  border-radius: 5px;
  color: var(--green);
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: none;
}

/* ===== 星評価 ===== */
.stars { display: inline-flex; gap: 1px; }
.star { font-size: 1.1rem; color: #C8D4E8; }
.star.filled { color: var(--accent); }

/* インタラクティブ星 */
.star-input {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 3px;
}
.star-input input { display: none; }
.star-input label {
  font-size: 1.6rem;
  color: #C8D4E8;
  cursor: pointer;
  transition: color 0.15s;
}
.star-input input:checked ~ label,
.star-input label:hover,
.star-input label:hover ~ label {
  color: var(--accent);
}

/* ===== バッジ ===== */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.badge-green  { background: #E8F5EE; color: var(--green); border: 1px solid #C0DEC8; }
.badge-orange { background: #FFF3E6; color: var(--orange); border: 1px solid #FCCFA0; }
.badge-red    { background: #FFECEC; color: var(--red);    border: 1px solid #FFBCBC; }
.badge-gray   { background: #EFF3FA; color: var(--text-muted); border: 1px solid var(--border); }
.badge-accent { background: #FFF8E6; color: var(--accent); border: 1px solid #F0D890; }
.badge-blue   { background: #E3F2FD; color: #0D47A1; border: 1px solid #90CAF9; }

/* ===== RSVP ボタングループ ===== */
.rsvp-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.rsvp-btn {
  padding: 7px 16px;
  border-radius: 20px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  transition: all 0.2s;
}
.rsvp-btn.going  { border-color: var(--green);  color: var(--green);  background: #E8F5EE; }
.rsvp-btn.maybe  { border-color: var(--orange); color: var(--orange); background: #FFF3E6; }
.rsvp-btn.no     { border-color: var(--red);    color: var(--red);    background: #FFECEC; }
.rsvp-btn.going.active  { background: var(--green);  color: white; }
.rsvp-btn.maybe.active  { background: var(--orange); color: white; }
.rsvp-btn.no.active     { background: var(--red);    color: white; }
.rsvp-btn:hover { filter: brightness(0.94); }

/* ===== 投票オプション ===== */
.poll-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.poll-option:last-child { border-bottom: none; }
.poll-option-vote {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  cursor: pointer;
  background: white;
  transition: all 0.2s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.poll-option-vote.voted {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(13,33,68,0.3);
}
.poll-option-info { flex: 1; }
.poll-option-name { font-weight: 600; color: var(--text); }
.poll-option-bar-wrap {
  flex: 1;
  background: var(--border);
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
  min-width: 60px;
}
.poll-option-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 4px;
  transition: width 0.4s ease;
}
.poll-option-count {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 28px;
  text-align: right;
}
.poll-option-voters {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== ダッシュボード ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  padding: 26px;
  display: flex;
  align-items: center;
  gap: 18px;
  border-bottom: 3px solid var(--accent);
  box-shadow: 0 4px 16px rgba(13,33,68,0.22);
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(13,33,68,0.30);
}
.stat-card .icon   { font-size: 2.2rem; opacity: 0.9; }
.stat-card .number { font-size: 2.1rem; font-weight: 700; color: var(--accent-light); }
.stat-card .label  { font-size: 0.82rem; opacity: 0.72; margin-top: 2px; letter-spacing: 0.02em; }

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,22,40,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  backdrop-filter: blur(2px);
}
.modal {
  background: white;
  border-radius: var(--radius);
  padding: 30px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 16px 56px rgba(10,22,40,0.35);
  border-top: 3px solid var(--accent);
}
.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  letter-spacing: 0.02em;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ===== ユーティリティ ===== */
.flex          { display: flex; }
.flex-wrap     { flex-wrap: wrap; }
.gap-2         { gap: 8px; }
.gap-3         { gap: 12px; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2  { margin-top: 8px; }
.mt-3  { margin-top: 12px; }
.mt-4  { margin-top: 16px; }
.mb-4  { margin-bottom: 16px; }
.text-muted   { color: var(--text-muted); font-size: 0.87rem; }
.text-center  { text-align: center; }
.empty-state {
  text-align: center;
  padding: 52px 24px;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.empty-state .icon { font-size: 3rem; margin-bottom: 14px; opacity: 0.5; }
.loading { text-align: center; padding: 44px; color: var(--text-muted); }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===== ページネーター ===== */
.paginator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.pgn-info { font-size: 0.82rem; color: var(--text-muted); }
.pgn-controls { display: flex; align-items: center; gap: 4px; }
.pgn-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.pgn-btn:hover:not([disabled]) { border-color: var(--primary); color: var(--primary); }
.pgn-btn.pgn-active { background: var(--primary); color: white; border-color: var(--primary); }
.pgn-btn[disabled] { opacity: 0.35; cursor: default; }
.pgn-ellipsis { font-size: 0.82rem; color: var(--text-muted); padding: 0 4px; line-height: 32px; }

/* オプション追加リスト */
.options-list { margin-bottom: 8px; }
.option-item {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}
.option-item input { flex: 1; }

/* ===== レスポンシブ ===== */
@media (max-width: 600px) {
  /* モバイル時のサイドバー挙動は末尾の aside.sidebar セクション内 media query で定義 */
  /* コンテナ余白 */
  .container { padding: 16px 12px; }
  .auth-card { padding: 28px 16px; }

  /* モーダル: 画面外に出ないよう修正 */
  .modal-overlay {
    padding: 10px;
    align-items: flex-start;
    overflow-y: auto;
  }
  .modal {
    padding: 20px 14px;
    max-height: none;
    margin-top: auto;
    margin-bottom: auto;
  }

  /* カードヘッダー: ボタンが多い場合に折り返し */
  .card-header { flex-wrap: wrap; }

  /* ダッシュボードのstat-card余白調整 */
  .stat-card { padding: 18px 16px; gap: 14px; }
  .stat-card .number { font-size: 1.7rem; }

  /* 投票オプション: バーを非表示にして名前を優先 */
  .poll-option-bar-wrap { display: none; }
  .poll-option-count { min-width: 36px; }
}

/* ===== グルーピングサイドバー ===== */
/* 管理者なり替わりバナーが出ているときに使うオフセット高さ */
:root { --impersonation-banner-h: 40px; }

aside.sidebar {
  background: var(--primary-dark);
  color: white;
  width: 240px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-left: env(safe-area-inset-left);
  border-right: 2px solid var(--accent);
  overflow-y: auto;
}
/* なり替わりバナー表示中はサイドバーをバナー高さ分下げる */
body.has-impersonation-banner aside.sidebar { top: var(--impersonation-banner-h); }
body.has-impersonation-banner { padding-top: var(--impersonation-banner-h); }
aside.sidebar .sb-hamburger {
  display: none;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 14px 16px;
  flex-direction: column;
  gap: 5px;
}
aside.sidebar .sb-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: white;
  border-radius: 2px;
}
aside.sidebar .sb-inner { display: flex; flex-direction: column; gap: 16px; }
aside.sidebar .sb-user {
  padding: 8px 16px;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 16px;
}
aside.sidebar .sb-user-name { font-weight: 700; font-size: 0.95rem; }
aside.sidebar .sb-user-tier { font-size: 0.78rem; color: var(--accent-light); margin-top: 2px; }
aside.sidebar .sb-group { display: flex; flex-direction: column; }
aside.sidebar .sb-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255,255,255,0.5);
  padding: 8px 16px 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
aside.sidebar .sb-group-upgrade .sb-group-title { color: var(--accent); }
aside.sidebar .sb-link {
  display: block;
  padding: 8px 16px;
  color: rgba(255,255,255,0.75);
  font-size: 0.9rem;
  text-decoration: none;
}
aside.sidebar .sb-link:hover { background: rgba(255,255,255,0.08); color: var(--accent-light); }
aside.sidebar .sb-link.active { background: rgba(196,151,42,0.18); color: var(--accent-light); }
aside.sidebar .sb-link-upgrade { color: var(--accent); }

/* メイン content 領域を sidebar 分ずらす */
body.has-sidebar { padding-left: 240px; }

/* ===== モバイル ===== */
@media (max-width: 600px) {
  body.has-sidebar { padding-left: 0; }
  aside.sidebar {
    width: 100%;
    height: 52px;
    bottom: auto;
    flex-direction: row;
    align-items: center;
    padding: 0;
    border-right: none;
    border-bottom: 2px solid var(--accent);
    overflow: visible;
  }
  aside.sidebar .sb-hamburger { display: flex; margin-left: auto; padding: 14px 16px; }
  aside.sidebar .sb-inner {
    display: none;
    position: absolute;
    top: 52px;
    left: 0; right: 0;
    background: var(--primary-dark);
    flex-direction: column;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    max-height: calc(100vh - 52px);
    overflow-y: auto;
  }
  aside.sidebar.sb-open .sb-inner { display: flex; }
  aside.sidebar .sb-user { padding: 12px 20px; }
  aside.sidebar .sb-link { padding: 12px 20px; }
  /* なり替わりバナー表示中はモバイルでも 52px ヘッダーの下にバナー分の余白を確保。
     ドロップダウン (sb-inner) は absolute なので親 aside の top に追随する */
  body.has-impersonation-banner aside.sidebar .sb-inner {
    max-height: calc(100vh - 52px - var(--impersonation-banner-h));
  }
}

/* ===== ペイウォール ===== */
.paywall {
  margin: 40px auto;
  max-width: 480px;
  padding: 32px 24px;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.paywall-icon { font-size: 2.8rem; margin-bottom: 8px; }
.paywall-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 8px; line-height: 1.5; }
.paywall-desc { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 20px; }
.paywall .btn { display: inline-block; margin-bottom: 12px; }
.paywall-compare { display: block; font-size: 0.85rem; color: var(--primary); text-decoration: none; }
.paywall-compare:hover { text-decoration: underline; }

/* ===== アップグレードバナー ===== */
.upgrade-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent-light, #fef3c7);
  border: 1px solid var(--accent, #f59e0b);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: 0.9rem;
}
.upgrade-banner .ub-text { flex: 1; }
.upgrade-banner .ub-detail { color: var(--primary); font-weight: 600; text-decoration: none; }
.upgrade-banner .ub-detail:hover { text-decoration: underline; }
.upgrade-banner .ub-dismiss {
  background: transparent; border: none; cursor: pointer; font-size: 1.2rem;
  color: var(--text-muted);
}
