/*
 * HSMS - Hospital Safety Management System
 * メインスタイルシート
 */

/* =============================
   基本レイアウト
   ============================= */
:root {
  --hsms-primary: #0d6efd;
  --hsms-sidebar-width: 250px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background-color: #f5f6fa;
  min-height: 100vh;
}

/* Keyboard focus (do not remove outlines for a11y) */
:focus-visible {
  outline: 2px solid var(--hsms-primary);
  outline-offset: 2px;
}

a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible {
  outline: 2px solid var(--hsms-primary);
  outline-offset: 2px;
}

/* Navbar on primary: ensure WCAG AA contrast for nav links */
.navbar.navbar-dark.bg-primary .nav-link,
.navbar.navbar-dark.bg-primary .navbar-brand {
  color: #ffffff !important;
}
.navbar.navbar-dark.bg-primary .nav-link:hover,
.navbar.navbar-dark.bg-primary .nav-link:focus,
.navbar.navbar-dark.bg-primary .nav-link:focus-visible,
.navbar.navbar-dark.bg-primary .nav-link.active {
  color: #ffffff !important;
  opacity: 1;
}
.navbar.navbar-dark.bg-primary .navbar-toggler {
  border-color: rgba(255, 255, 255, 0.55);
}

/* =============================
   カード系
   ============================= */
.card {
  border-radius: 0.5rem;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 0.25rem 0.75rem rgba(0,0,0,0.1);
}

.card-header {
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

/* =============================
   テーブル
   ============================= */
.table th {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}

.table td {
  font-size: 0.9rem;
  vertical-align: middle;
}

tr.cursor-pointer {
  cursor: pointer;
}

tr.cursor-pointer:hover {
  background-color: rgba(13, 110, 253, 0.04);
}

/* =============================
   バッジ（重症度・状態）
   ============================= */
.badge {
  font-weight: 500;
}

.badge-severity-1, .badge-severity-2 {
  background-color: #198754 !important;
  color: #fff;
}

.badge-severity-3, .badge-severity-4 {
  background-color: #ffc107 !important;
  color: #212529;
}

.badge-severity-5, .badge-severity-6 {
  background-color: #fd7e14 !important;
  color: #fff;
}

.badge-severity-7, .badge-severity-8 {
  background-color: #dc3545 !important;
  color: #fff;
}

.badge-status-draft   { background-color: #6c757d !important; }
.badge-status-open    { background-color: #0dcaf0 !important; color: #212529; }
.badge-status-review  { background-color: #ffc107 !important; color: #212529; }
.badge-status-confirmed { background-color: #0d6efd !important; }
.badge-status-closed  { background-color: #198754 !important; }

/* =============================
   フォーム
   ============================= */
.form-label {
  font-weight: 600;
  font-size: 0.875rem;
}

.form-text {
  font-size: 0.8rem;
}

/* =============================
   ダッシュボードカード
   ============================= */
.stat-card .display-6 {
  font-weight: 700;
}

.quick-action-card {
  transition: transform 0.15s ease;
}

.quick-action-card:hover {
  transform: translateY(-2px);
}

/* =============================
   通知ベル
   ============================= */
.notification-bell .badge {
  position: absolute;
  top: -4px;
  right: -6px;
  font-size: 0.65rem;
  min-width: 18px;
}

/* =============================
   タイムライン
   ============================= */
.timeline-item {
  position: relative;
  padding-left: 2rem;
  padding-bottom: 1rem;
  border-left: 2px solid #dee2e6;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 0.25rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #0d6efd;
}

.timeline-item:last-child {
  border-left-color: transparent;
}

/* =============================
   モバイル対応（〜768px）
   ============================= */
@media (max-width: 768px) {
  .card-body {
    padding: 0.75rem;
  }

  .display-6 {
    font-size: 1.5rem;
  }

  .table-responsive {
    font-size: 0.85rem;
  }

  .breadcrumb {
    font-size: 0.8rem;
  }
}

/* =============================
   スマートフォン小型（〜480px）
   ============================= */
@media (max-width: 480px) {
  /* ナビゲーション */
  .navbar-brand {
    font-size: 1rem;
  }

  .navbar .nav-link {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    font-size: 0.9rem;
  }

  /* カード */
  .card {
    border-radius: 0.375rem;
  }
  .card-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  /* ダッシュボード統計カード */
  .stat-card .display-6 {
    font-size: 1.4rem;
  }

  /* ボタン最小タップ領域 44px */
  .btn {
    min-height: 44px;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* フォームラベル */
  .form-label {
    font-size: 0.8rem;
  }
}

/* =============================
   ウェアラブル / 超小型画面（〜320px）
   Apple Watch / Wear OS等の参照想定
   ============================= */
@media (max-width: 320px) {
  /* ベースフォントを縮小 */
  body {
    font-size: 0.8rem;
  }

  /* ナビバーを最小化 */
  .navbar {
    padding: 0.25rem 0.5rem;
  }
  .navbar-brand {
    font-size: 0.85rem;
  }
  /* ウェアラブルではメニューを非表示にし必須ボタンのみ表示 */
  .navbar-collapse {
    display: none !important;
  }
  .navbar-toggler {
    display: none !important;
  }

  /* ヘッダー固定ショートカットバーを表示（ウェアラブル専用） */
  .wearable-action-bar {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--hsms-primary);
    z-index: 1000;
    padding: 0.25rem;
    justify-content: space-around;
  }
  .wearable-action-bar a {
    color: #fff;
    font-size: 0.7rem;
    text-align: center;
    text-decoration: none;
    flex: 1;
    padding: 0.25rem;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .wearable-action-bar .bi {
    font-size: 1.2rem;
    display: block;
  }

  /* コンテンツ余白をウェアラブル用に最適化 */
  main .container,
  main .container-fluid {
    padding-left: 0.375rem;
    padding-right: 0.375rem;
  }

  /* カード */
  .card-body {
    padding: 0.5rem;
  }
  .card-header {
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
  }

  /* テーブル：超小型では重要列のみ表示 */
  .table th,
  .table td {
    font-size: 0.72rem;
    padding: 0.25rem 0.3rem;
  }
  .table-wearable-hide {
    display: none !important;
  }

  /* バッジを小さく */
  .badge {
    font-size: 0.65rem;
    padding: 0.2em 0.4em;
  }

  /* 統計数値 */
  .stat-card .display-6 {
    font-size: 1.1rem;
  }

  /* ボタン全幅・最小タップ領域 */
  .btn {
    font-size: 0.8rem;
    min-height: 44px;
    width: 100%;
    margin-bottom: 0.25rem;
  }
  .btn-group .btn {
    width: auto;
  }

  /* ページタイトルを非表示（画面節約） */
  .page-title-row .display-5,
  .page-title-row .display-6 {
    font-size: 1rem;
  }

  /* パンくず非表示 */
  .breadcrumb {
    display: none;
  }

  /* モーダルを全画面表示 */
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    min-height: 100vh;
  }
  .modal-content {
    border-radius: 0;
    min-height: 100vh;
  }
}

/* =============================
   超小型デバイス（〜240px）
   Gear Fit 等の極小解像度向け
   ============================= */
@media (max-width: 240px) {
  body {
    font-size: 0.72rem;
  }

  .card-body {
    padding: 0.3rem;
  }

  .btn {
    font-size: 0.72rem;
    padding: 0.3rem 0.4rem;
  }

  /* 表は1列（ラベル＋値）に強制折返し */
  .table,
  .table thead,
  .table tbody,
  .table th,
  .table td,
  .table tr {
    display: block;
    width: 100%;
  }
  .table thead {
    display: none;
  }
  .table td {
    border: none;
    border-bottom: 1px solid #dee2e6;
    position: relative;
    padding-left: 40%;
    font-size: 0.7rem;
  }
  .table td::before {
    position: absolute;
    top: 0.25rem;
    left: 0.25rem;
    width: 38%;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.65rem;
    color: #6c757d;
    content: attr(data-label);
  }
}

/* =============================
   音声入力ボタン
   ============================= */
.voice-input-btn {
  border: none;
  background: none;
  color: #6c757d;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  transition: color 0.15s ease, background 0.15s ease;
}

.voice-input-btn:hover {
  color: #dc3545;
  background: rgba(220, 53, 69, 0.1);
}

/* =============================
   ダークモード対応
   prefers-color-scheme: dark
   OSレベルのダークモード設定に自動追従
   ============================= */
@media (prefers-color-scheme: dark) {
  :root {
    --hsms-primary: #4d94ff;
    --bs-body-bg: #1a1d21;
    --bs-body-color: #e0e0e0;
    --bs-card-bg: #252830;
    --bs-border-color: #3a3d45;
  }

  /* 背景・文字色 */
  body {
    background-color: #1a1d21;
    color: #e0e0e0;
  }

  /* ナビバー */
  .navbar.navbar-dark {
    background-color: #0f1114 !important;
  }
  .navbar-brand,
  .nav-link {
    color: #e0e0e0 !important;
  }

  /* カード */
  .card {
    background-color: #252830;
    border-color: #3a3d45;
  }
  .card-header {
    background-color: #2d3038;
    border-bottom-color: #3a3d45;
    color: #e0e0e0;
  }
  .card-body {
    color: #e0e0e0;
  }
  .card:hover {
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.4);
  }

  /* テーブル */
  .table {
    --bs-table-bg: #252830;
    --bs-table-striped-bg: #2d3038;
    --bs-table-hover-bg: #343740;
    --bs-table-border-color: #3a3d45;
    color: #e0e0e0;
  }
  .table th {
    background-color: #2d3038;
    color: #c0c0c0;
    border-color: #3a3d45;
  }
  .table td {
    border-color: #3a3d45;
  }
  tr.cursor-pointer:hover {
    background-color: rgba(77, 148, 255, 0.08);
  }

  /* フォーム */
  .form-control,
  .form-select {
    background-color: #2d3038;
    border-color: #4a4d57;
    color: #e0e0e0;
  }
  .form-control:focus,
  .form-select:focus {
    background-color: #2d3038;
    border-color: #4d94ff;
    color: #e0e0e0;
    box-shadow: 0 0 0 0.25rem rgba(77, 148, 255, 0.25);
  }
  .form-control::placeholder {
    color: #888;
  }
  .form-label {
    color: #c0c0c0;
  }
  .form-text {
    color: #888;
  }

  /* モーダル */
  .modal-content {
    background-color: #252830;
    border-color: #3a3d45;
  }
  .modal-header {
    border-bottom-color: #3a3d45;
    background-color: #2d3038;
  }
  .modal-footer {
    border-top-color: #3a3d45;
    background-color: #2d3038;
  }

  /* ドロップダウン */
  .dropdown-menu {
    background-color: #2d3038;
    border-color: #3a3d45;
  }
  .dropdown-item {
    color: #e0e0e0;
  }
  .dropdown-item:hover,
  .dropdown-item:focus {
    background-color: #343740;
    color: #fff;
  }
  .dropdown-item-text {
    color: #888;
  }
  .dropdown-divider {
    border-color: #3a3d45;
  }

  /* アラート・フラッシュメッセージ */
  .alert {
    border-color: #3a3d45;
  }

  /* リスト・パンくず */
  .list-group-item {
    background-color: #252830;
    border-color: #3a3d45;
    color: #e0e0e0;
  }
  .list-group-item:hover {
    background-color: #2d3038;
  }
  .breadcrumb-item a {
    color: #4d94ff;
  }
  .breadcrumb-item.active {
    color: #888;
  }

  /* ページネーション */
  .page-link {
    background-color: #252830;
    border-color: #3a3d45;
    color: #4d94ff;
  }
  .page-link:hover {
    background-color: #2d3038;
    color: #77aaff;
  }
  .page-item.active .page-link {
    background-color: #4d94ff;
    border-color: #4d94ff;
  }
  .page-item.disabled .page-link {
    background-color: #1a1d21;
    color: #555;
  }

  /* フッター */
  footer.bg-light {
    background-color: #1e2126 !important;
    border-top-color: #3a3d45 !important;
    color: #888 !important;
  }

  /* バッジ */
  .badge-status-open {
    background-color: #0ba3c7 !important;
  }

  /* タイムライン */
  .timeline-item {
    border-left-color: #3a3d45;
  }
  .timeline-item::before {
    background: #4d94ff;
  }

  /* ウェアラブルバー (320px以下で使用) */
  .wearable-action-bar {
    background: #0f1114;
  }

  /* スクロールバー（Webkit） */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  ::-webkit-scrollbar-track {
    background: #1a1d21;
  }
  ::-webkit-scrollbar-thumb {
    background: #3a3d45;
    border-radius: 3px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: #4a4d57;
  }
}

.voice-input-btn.recording {
  color: #dc3545;
  animation: voice-pulse 1s infinite;
}

@keyframes voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* =============================
   カメラ撮影ボタン
   ============================= */
.camera-btn {
  border: 2px dashed #dee2e6;
  background: #f8f9fa;
  border-radius: 0.5rem;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease;
  color: #6c757d;
}

.camera-btn:hover {
  border-color: #0d6efd;
  color: #0d6efd;
}

/* =============================
   印刷
   ============================= */
@media print {
  .navbar, .breadcrumb, .btn, footer {
    display: none !important;
  }

  .card {
    border: 1px solid #dee2e6;
    box-shadow: none;
  }

  body {
    background: #fff;
  }
}

/* =============================
   アニメーション
   ============================= */
.fade-in {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =============================
   HTMX ローディング
   ============================= */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

/* =============================
   期限超過ハイライト
   ============================= */
tr.overdue-row {
  background-color: rgba(220, 53, 69, 0.05) !important;
}

tr.overdue-row td {
  color: #dc3545;
}

/* =============================
   フィルターパネル
   ============================= */
.filter-panel {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

/* ===================================
   二要素認証（TOTP）
   =================================== */
.totp-qr {
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
}
.totp-input {
  letter-spacing: 0.35em;
  font-variant-numeric: tabular-nums;
}
.totp-secret {
  word-break: break-all;
}
.totp-steps {
  padding-left: 1.25rem;
}
