/* 時刻表モーダル */
.timetable-modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
}

.timetable-modal[hidden] {
  display: none;
}

.timetable-modal-body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  padding: 20px 0;
}

.timetable-modal-content {
  background-color: #fff;
  padding: 0;
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin: 0 auto;
}

/* モーダルヘッダー */
.timetable-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  background-color: #f5f5f5;
  border-radius: 8px 8px 0 0;
}

.timetable-modal-header h2,
.timetable-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.timetable-close-button {
  background: none;
  border: none;
  font-size: 28px;
  font-weight: 300;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

.timetable-close-button:hover {
  background-color: #e0e0e0;
  color: #333;
}

.timetable-close-button:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* 戻るボタン */
.timetable-back-button {
  display: block;
  width: calc(100% - 40px);
  margin: 16px 20px;
  padding: 10px 16px;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.2s;
}

.timetable-back-button:hover {
  background-color: #e0e0e0;
}

.timetable-back-button:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* 路線選択画面 */
.timetable-instruction {
  padding: 16px 20px;
  margin: 0;
  font-size: 14px;
  color: #666;
  border-bottom: 1px solid #e0e0e0;
}

.timetable-route-list {
  padding: 0;
}

.timetable-route-item {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  cursor: pointer;
  transition: background-color 0.2s;
}

.timetable-route-item:hover {
  background-color: #f5f5f5;
}

.timetable-route-item:focus {
  outline: 2px solid #007bff;
  outline-offset: -2px;
  background-color: #f5f5f5;
}

.timetable-route-item:last-child {
  border-bottom: none;
}

.timetable-route-number {
  font-size: 16px;
  font-weight: 600;
  color: #666;
  margin-right: 12px;
  min-width: 24px;
}

.timetable-route-info {
  flex: 1;
}

.timetable-route-name {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin-bottom: 4px;
}

.timetable-agency-name {
  font-size: 13px;
  color: #666;
}

/* タブ */
.timetable-tabs {
  display: flex;
  border-bottom: 2px solid #e0e0e0;
  margin: 16px 20px 0;
}

.timetable-tab {
  flex: 1;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 15px;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.timetable-tab:hover {
  color: #333;
}

.timetable-tab:focus {
  outline: 2px solid #007bff;
  outline-offset: -2px;
}

.timetable-tab.active {
  color: #007bff;
  border-bottom-color: #007bff;
}

/* 地図表示ボタン */
.timetable-map-button {
  display: block;
  width: calc(100% - 40px);
  margin: 16px 20px;
  padding: 12px 16px;
  background-color: #007bff;
  border: none;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
  transition: background-color 0.2s;
}

.timetable-map-button:hover {
  background-color: #0056b3;
}

.timetable-map-button:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* 時刻表コンテンツ */
.timetable-content {
  padding: 0 20px 20px;
}

.timetable-tab-content {
  display: block;
}

.timetable-tab-content[hidden] {
  display: none;
}

.timetable-table-container {
  margin-top: 16px;
}

.timetable-no-data {
  text-align: center;
  padding: 40px 20px;
  color: #666;
  font-size: 14px;
}

/* 時刻表テーブル */
.timetable-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.timetable-table thead {
  background-color: #f5f5f5;
  border-bottom: 2px solid #e0e0e0;
}

.timetable-table th {
  padding: 12px 8px;
  text-align: left;
  font-weight: 600;
  color: #333;
}

.timetable-table tbody tr {
  border-bottom: 1px solid #e0e0e0;
}

.timetable-table tbody tr:last-child {
  border-bottom: none;
}

.timetable-table tbody tr:hover {
  background-color: #f9f9f9;
}

.timetable-table td {
  padding: 12px 8px;
  color: #333;
}

.timetable-time {
  font-weight: 500;
  white-space: nowrap;
  width: 80px;
}

.timetable-destination {
  color: #666;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
  .timetable-modal-content {
    width: 95%;
    margin: 2% auto;
    max-height: 90vh;
  }

  .timetable-modal-header h2 {
    font-size: 16px;
  }

  .timetable-route-name {
    font-size: 15px;
  }

  .timetable-agency-name {
    font-size: 12px;
  }

  .timetable-tab {
    font-size: 14px;
    padding: 10px 12px;
  }

  .timetable-table {
    font-size: 13px;
  }

  .timetable-table th,
  .timetable-table td {
    padding: 10px 6px;
  }

  .timetable-time {
    width: 70px;
  }
}

@media (max-width: 480px) {
  .timetable-modal-content {
    width: 100%;
    margin: 0;
    max-height: 100vh;
    border-radius: 0;
  }

  .timetable-modal-header {
    border-radius: 0;
  }

  .timetable-modal-header h2 {
    font-size: 15px;
  }

  .timetable-route-item {
    padding: 14px 16px;
  }

  .timetable-route-name {
    font-size: 14px;
  }

  .timetable-agency-name {
    font-size: 11px;
  }

  .timetable-tab {
    font-size: 13px;
    padding: 8px 10px;
  }

  .timetable-map-button,
  .timetable-back-button {
    width: calc(100% - 32px);
    margin: 12px 16px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .timetable-content {
    padding: 0 16px 16px;
  }

  .timetable-table {
    font-size: 12px;
  }

  .timetable-table th,
  .timetable-table td {
    padding: 8px 4px;
  }

  .timetable-time {
    width: 60px;
  }
}

/* アクセシビリティ: ハイコントラストモード対応 */
@media (prefers-contrast: high) {
  .timetable-modal-content {
    border: 2px solid #000;
  }

  .timetable-tab.active {
    border-bottom-width: 4px;
  }

  .timetable-close-button:focus,
  .timetable-back-button:focus,
  .timetable-tab:focus,
  .timetable-map-button:focus,
  .timetable-route-item:focus {
    outline: 3px solid #000;
  }
}

/* アクセシビリティ: 縮小モーション設定 */
@media (prefers-reduced-motion: reduce) {
  .timetable-modal-content,
  .timetable-close-button,
  .timetable-back-button,
  .timetable-route-item,
  .timetable-tab,
  .timetable-map-button {
    transition: none;
  }
}

/* ========================================
   方向情報表示スタイル
   ======================================== */

/* 方向ラベル */
.direction-label {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  margin-left: 8px;
  white-space: nowrap;
}

.direction-label-outbound {
  background-color: #e3f2fd;
  color: #1976d2;
}

.direction-label-inbound {
  background-color: #fff3e0;
  color: #f57c00;
}

.direction-label-unknown {
  background-color: #f5f5f5;
  color: #757575;
}

/* 方向ラベルのアイコン */
.direction-label-icon {
  display: none;
  margin-right: 4px;
}

.direction-label-text {
  display: inline;
}

/* 方向フィルタ */
.direction-filter {
  display: flex;
  gap: 8px;
  margin: 16px 20px;
  padding: 12px;
  background-color: #f5f5f5;
  border-radius: 8px;
}

.direction-filter-button {
  flex: 1;
  padding: 8px 16px;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  color: #333;
  font-weight: 500;
}

.direction-filter-button:hover {
  background-color: #f0f0f0;
}

.direction-filter-button:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

.direction-filter-button[aria-pressed="true"] {
  background-color: #007bff;
  color: #fff;
  border-color: #007bff;
}

/* 方向判定バッジ */
.detection-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  margin-left: 8px;
}

.detection-badge-warning {
  background-color: #ffebee;
  color: #c62828;
}

.detection-badge-caution {
  background-color: #fff3e0;
  color: #f57c00;
}

.detection-badge-success {
  background-color: #e8f5e9;
  color: #2e7d32;
}

.detection-badge-na {
  background-color: #f5f5f5;
  color: #757575;
}

/* ツールチップ表示 */
.detection-badge {
  position: relative;
  cursor: help;
}

.detection-badge:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  background-color: #333;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 1000;
  margin-bottom: 4px;
}

.detection-badge:hover::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #333;
  z-index: 1000;
}

/* ========================================
   レスポンシブデザイン対応
   ======================================== */

/* モバイル画面（480px以下）: アイコンのみ表示 */
@media (max-width: 480px) {
  .direction-label {
    padding: 2px 6px;
    margin-left: 4px;
  }

  .direction-label-text {
    display: none;
  }

  .direction-label-icon {
    display: inline;
    margin-right: 0;
  }

  .direction-label-icon::before {
    font-size: 14px;
  }

  .direction-label-outbound .direction-label-icon::before {
    content: '→';
  }

  .direction-label-inbound .direction-label-icon::before {
    content: '←';
  }

  .direction-label-unknown .direction-label-icon::before {
    content: '?';
  }

  .direction-filter {
    flex-direction: column;
    margin: 12px 16px;
    padding: 10px;
    gap: 6px;
  }

  .direction-filter-button {
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
  }

  .detection-badge {
    font-size: 10px;
    padding: 2px 4px;
    margin-left: 4px;
  }
}

/* タブレット画面（481px-768px）: 短縮形表示 */
@media (min-width: 481px) and (max-width: 768px) {
  .direction-label {
    padding: 2px 6px;
    margin-left: 6px;
  }

  .direction-label-text::before {
    content: attr(data-short);
  }

  .direction-filter {
    margin: 14px 18px;
    padding: 10px;
    gap: 6px;
  }

  .direction-filter-button {
    padding: 8px 14px;
    font-size: 13px;
  }
}

/* デスクトップ画面（769px以上）: 完全形表示 */
@media (min-width: 769px) {
  .direction-label-text::before {
    content: attr(data-full);
  }
}

/* ========================================
   アクセシビリティ対応
   ======================================== */

/* ハイコントラストモード対応 */
@media (prefers-contrast: high) {
  .direction-label {
    border: 2px solid currentColor;
  }

  .direction-label-outbound {
    background-color: #bbdefb;
    color: #0d47a1;
  }

  .direction-label-inbound {
    background-color: #ffe0b2;
    color: #e65100;
  }

  .direction-label-unknown {
    background-color: #e0e0e0;
    color: #424242;
  }

  .direction-filter-button {
    border: 2px solid #333;
  }

  .direction-filter-button[aria-pressed="true"] {
    background-color: #0056b3;
    border-color: #0056b3;
    border-width: 3px;
  }

  .direction-filter-button:focus {
    outline: 3px solid #000;
    outline-offset: 2px;
  }

  .detection-badge {
    border: 2px solid currentColor;
  }

  .detection-badge-warning {
    background-color: #ffcdd2;
    color: #b71c1c;
  }

  .detection-badge-caution {
    background-color: #ffe0b2;
    color: #e65100;
  }

  .detection-badge-success {
    background-color: #c8e6c9;
    color: #1b5e20;
  }

  .detection-badge-na {
    background-color: #e0e0e0;
    color: #424242;
  }
}

/* 縮小モーション設定 */
@media (prefers-reduced-motion: reduce) {
  .direction-filter-button {
    transition: none;
  }

  .detection-badge:hover::after,
  .detection-badge:hover::before {
    transition: none;
  }
}

/* ========================================
   タッチデバイス対応
   ======================================== */

/* タッチデバイスでのタップ領域確保 */
@media (hover: none) and (pointer: coarse) {
  .direction-filter-button {
    min-height: 44px;
    padding: 12px 16px;
  }

  .detection-badge {
    cursor: pointer;
  }

  /* タッチデバイスではホバーではなくタップでツールチップ表示 */
  .detection-badge:active::after,
  .detection-badge:active::before {
    display: block;
  }
}

/* ========================================
   時刻表テーブルの方向列
   ======================================== */

/* 方向列のスタイル */
.timetable-table .timetable-direction {
  width: 80px;
  text-align: center;
  white-space: nowrap;
}

.timetable-table th.timetable-direction {
  font-weight: 600;
}

/* モバイルでは方向列の幅を最小限に */
@media (max-width: 480px) {
  .timetable-table .timetable-direction {
    width: 50px;
    padding: 8px 2px;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .timetable-table .timetable-direction {
    width: 60px;
    padding: 10px 4px;
  }
}
