/* ============================================================
   気管切開児向け遠隔相談プラットフォーム - メインスタイル
   ============================================================ */

:root {
  --primary:      #0f6cbd;
  --primary-dark: #0a4d96;
  --primary-light:#e6f2ff;
  --success:      #107c10;
  --warning:      #c67c00;
  --danger:       #d13438;
  --emergency:    #c50f1f;
  --bg:           #f5f7fa;
  --surface:      #ffffff;
  --border:       #e0e0e0;
  --text:         #1a1a2e;
  --text-muted:   #6b7280;
  --radius:       10px;
  --shadow:       0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.14);
  --nav-width:    240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ---- 認証画面 ---- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f6cbd 0%, #1a3a6b 100%);
}

.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-logo i { font-size: 2.5rem; color: var(--primary); }
.auth-logo h1 { font-size: 1.25rem; font-weight: 700; margin-top: .5rem; }
.auth-logo p  { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

/* ---- アプリレイアウト ---- */
#app-screen { display: none; min-height: 100vh; }

.app-layout {
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
}

/* ---- トップバー ---- */
.topbar {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  color: var(--primary);
  width: var(--nav-width);
  flex-shrink: 0;
}

.topbar-brand i { font-size: 1.3rem; }
.topbar-brand span { font-size: .95rem; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .75rem; }

.notif-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-muted);
  padding: .25rem .5rem;
}

.notif-badge {
  position: absolute;
  top: 0; right: 0;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  width: 16px; height: 16px;
  font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--primary-light);
  border-radius: 20px;
  padding: .3rem .75rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary-dark);
}

/* ---- サイドナビ ---- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  overflow-y: auto;
}

.nav-section-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: .08em;
  padding: .5rem 1.25rem .25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.25rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  font-size: .88rem;
  transition: all .15s;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg); color: var(--primary); }
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-item i { width: 18px; text-align: center; font-size: 1rem; }

/* ---- メインコンテンツ ---- */
.main-content {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(100vh - 56px);
}

/* ---- ページ ---- */
.page { display: none; }
.page.active { display: block; }

/* ---- ページヘッダー ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .5rem;
}

.page-title i { color: var(--primary); }

/* ---- 統計カード ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.blue    { background: #dbeafe; color: #1d4ed8; }
.stat-icon.yellow  { background: #fef3c7; color: #d97706; }
.stat-icon.green   { background: #d1fae5; color: #059669; }
.stat-icon.red     { background: #fee2e2; color: #dc2626; }

.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }

/* ---- テーブル ---- */
.table-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.table-title { font-weight: 700; font-size: .95rem; }

table { width: 100%; border-collapse: collapse; }

thead th {
  background: var(--bg);
  padding: .75rem 1rem;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: .05em;
  text-align: left;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}

tbody tr:hover { background: var(--bg); }
tbody tr:last-child { border-bottom: none; }

tbody td { padding: .8rem 1rem; font-size: .88rem; vertical-align: middle; }

/* ---- バッジ ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-pending    { background: #fef3c7; color: #92400e; }
.badge-in_review  { background: #dbeafe; color: #1e40af; }
.badge-responded  { background: #d1fae5; color: #065f46; }
.badge-closed     { background: #f3f4f6; color: #6b7280; }
.badge-normal     { background: #f3f4f6; color: #6b7280; }
.badge-urgent     { background: #fef3c7; color: #92400e; }
.badge-emergency  { background: #fee2e2; color: #991b1b; }

/* ---- フォーム ---- */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .35rem; }
.form-label .required { color: var(--danger); margin-left: .2rem; }

input, textarea, select {
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,108,189,.12);
}

textarea { resize: vertical; min-height: 80px; }

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  font-family: inherit;
}

.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-outline  { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-ghost    { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm  { padding: .35rem .7rem; font-size: .8rem; }
.btn-lg  { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* ---- モーダル ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1.05rem;
  position: sticky;
  top: 0;
  background: var(--surface);
}

.modal-body    { padding: 1.5rem; }
.modal-footer  { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; }

/* ---- 画像アップロードゾーン ---- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  background: var(--bg);
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone i { font-size: 2rem; color: var(--primary); margin-bottom: .5rem; }
.upload-zone p { font-size: .88rem; color: var(--text-muted); }

.upload-previews {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .5rem;
  margin-top: 1rem;
}

.preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--bg);
}

.preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-item .preview-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .65rem;
  text-align: center;
  padding: .15rem;
}

.preview-item .preview-del {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px; height: 20px;
  cursor: pointer;
  font-size: .65rem;
  display: flex; align-items: center; justify-content: center;
}

/* ---- アラート ---- */
.alert {
  display: none;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .88rem;
  margin-bottom: 1rem;
  align-items: center;
  gap: .5rem;
}

.alert.show { display: flex; }
.alert-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--danger); }
.alert-success { background: #d1fae5; color: #065f46; border-left: 4px solid var(--success); }
.alert-warning { background: #fef3c7; color: #92400e; border-left: 4px solid var(--warning); }

/* ---- ケース詳細 ---- */
.case-detail-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.case-meta {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: .75rem;
}

.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  margin-top: .75rem;
}

.gallery-img {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.gallery-img img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.gallery-img:hover img { transform: scale(1.03); }

/* 撮影方向ラベル */
.photo-label-tag {
  position: absolute;
  top: .4rem;
  left: .4rem;
  z-index: 2;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: 4px;
  pointer-events: none;
  letter-spacing: .04em;
}

/* フルスクリーンオーバーレイ */
#img-fullscreen-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.92);
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
#img-fullscreen-overlay.open { display: flex; }
#img-fullscreen-overlay img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
#img-fullscreen-label {
  color: #fff;
  font-size: .95rem;
  margin-top: .75rem;
  font-weight: 600;
  letter-spacing: .06em;
}
#img-fullscreen-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#img-fullscreen-close:hover { background: rgba(255,255,255,.3); }

.reply-card {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--primary);
}

.reply-card.draft {
  background: #fef9c3;
  border-color: var(--warning);
}

/* ---- 通知パネル ---- */
.notif-panel {
  position: fixed;
  top: 56px; right: 0;
  width: 360px;
  max-height: calc(100vh - 56px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: none;
  flex-direction: column;
  overflow-y: auto;
}

.notif-panel.open { display: flex; }
.notif-panel-header { padding: 1rem; border-bottom: 1px solid var(--border); font-weight: 700; }

.notif-item {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}

.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: var(--primary-light); }
.notif-item-title { font-weight: 600; font-size: .88rem; }
.notif-item-body  { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }
.notif-item-time  { font-size: .72rem; color: var(--text-muted); margin-top: .25rem; }

/* ---- ユーティリティ ---- */
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.spinner { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- ハンバーガーボタン（PC では非表示） ---- */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text);
  cursor: pointer;
  padding: .4rem .6rem;
  border-radius: var(--radius);
  margin-right: .25rem;
  flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--bg); }

/* ---- モバイルオーバーレイ ---- */
.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 199;
}
.mobile-nav-overlay.open { display: block; }

/* ---- レスポンシブ ---- */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
  }
  .hamburger-btn { display: flex; align-items: center; justify-content: center; }

  /* サイドバーをドロワーに変更 */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    width: 240px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,.18);
    padding-top: calc(56px + env(safe-area-inset-top));
  }
  .sidebar.open { transform: translateX(0); }

  .topbar-brand { width: auto; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .upload-previews { grid-template-columns: repeat(3, 1fr); }

  /* iPhone safe-area 対応 */
  #auth-screen  { padding-bottom: env(safe-area-inset-bottom); }
  #app-screen   { padding-bottom: env(safe-area-inset-bottom); }
  .main-content { padding: 1rem; }
}

/* ---- タブボタン ---- */
.tab-btn {
  padding: .45rem 1.1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
