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

:root {
  /* カテゴリカラー */
  --color-hr-shift: #3B82F6;
  --color-facility: #F59E0B;
  --color-patient: #10B981;
  --color-meeting: #8B5CF6;
  --color-director: #EF4444;
  --color-other: #6B7280;

  /* 期限アラートカラー */
  --color-overdue: #EF4444;
  --color-today: #F59E0B;
  --color-soon: #FBBF24;
  --color-safe: #10B981;

  /* UIカラー */
  --color-bg: #F9FAFB;
  --color-surface: #FFFFFF;
  --color-text: #1F2937;
  --color-text-secondary: #6B7280;
  --color-border: #E5E7EB;
  --color-primary: #3B82F6;
  --color-primary-hover: #2563EB;

  /* レイアウト */
  --header-height: 52px;
  --nav-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

/* === ヘッダー === */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}

#header-title {
  font-size: 1.1rem;
  font-weight: 600;
}

/* === メインコンテンツ === */
#app-content {
  min-height: calc(100vh - var(--header-height) - var(--nav-height));
}

.view {
  display: none;
  padding: 12px;
}

.view.active {
  display: block;
}

/* === ボトムナビゲーション === */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  font-size: 0.7rem;
  cursor: pointer;
  transition: color 0.2s;
}

.nav-item.active {
  color: var(--color-primary);
}

.nav-icon {
  font-size: 1.4rem;
}

.nav-label {
  font-weight: 500;
}

/* === カレンダー === */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 12px;
}

.calendar-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

.calendar-nav-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
}

.calendar-nav-btn:active {
  background: var(--color-bg);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}

.calendar-dow {
  background: #F3F4F6;
  text-align: center;
  padding: 6px 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.calendar-dow.sun { color: var(--color-overdue); }
.calendar-dow.sat { color: var(--color-primary); }

.calendar-cell {
  background: var(--color-surface);
  min-height: 52px;
  padding: 4px;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.calendar-cell:active {
  background: #EFF6FF;
}

.calendar-cell.other-month {
  opacity: 0.35;
}

.calendar-cell.today {
  background: #EFF6FF;
}

.calendar-cell.today .cell-day {
  background: var(--color-primary);
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell-day {
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.cell-day.sun { color: var(--color-overdue); }
.cell-day.sat { color: var(--color-primary); }

.cell-holiday {
  font-size: 0.6rem;
  color: #EF4444;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.cell-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.cell-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

/* === フィルタータブ === */
.filter-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 0 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-tab {
  padding: 6px 14px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: all 0.2s;
}

.filter-tab.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

/* === カード共通 === */
.card {
  background: var(--color-surface);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  border-left: 4px solid var(--color-other);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-meta {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.card-description {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.card-image {
  margin-bottom: 8px;
}

.card-image img {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
}

.card-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}

/* === タスクステータスバッジ === */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}

.status-badge.pending {
  background: #FEF3C7;
  color: #92400E;
}

.status-badge.in_progress {
  background: #DBEAFE;
  color: #1E40AF;
}

.status-badge.completed {
  background: #D1FAE5;
  color: #065F46;
}

/* === 期限アラートバッジ === */
.deadline-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}

.deadline-badge.overdue {
  background: #FEE2E2;
  color: #991B1B;
}

.deadline-badge.today {
  background: #FEF3C7;
  color: #92400E;
}

.deadline-badge.soon {
  background: #FEF9C3;
  color: #854D0E;
}

.deadline-badge.safe {
  background: #D1FAE5;
  color: #065F46;
}

/* === カテゴリバッジ === */
.category-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
}

/* === ボタン === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:active {
  background: var(--color-primary-hover);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 6px;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.btn-outline:active {
  background: var(--color-bg);
}

.btn-danger {
  background: transparent;
  border: 1px solid #FCA5A5;
  color: #DC2626;
}

.btn-danger:active {
  background: #FEE2E2;
}

/* === 検索バー === */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 8px 0;
}

.search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.8rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  min-width: 100px;
}

/* === モーダル === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  background: var(--color-surface);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--color-bg);
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
}

#day-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: center;
  padding-bottom: calc(12px + var(--safe-bottom));
}

.modal-footer .btn {
  width: 100%;
  justify-content: center;
}

/* === 日付詳細セクション === */
.detail-section {
  margin-bottom: 16px;
}

.detail-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--color-border);
}

.detail-empty {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  padding: 8px 0;
}

/* === スピナー === */
#loading {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
}

#loading.hidden {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === トースト === */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 250;
  background: #1F2937;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  white-space: nowrap;
  animation: fadeInUp 0.3s ease-out;
}

.toast.hidden {
  display: none;
}

.toast.error {
  background: var(--color-overdue);
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === 空の状態 === */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--color-text-secondary);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 0.9rem;
}

/* === 検索結果 === */
.search-count {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  padding: 4px 0 8px;
}

.search-type-badge {
  font-size: 0.75rem;
  font-weight: 600;
}

/* === FAB（新規作成ボタン） === */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  z-index: 90;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  font-size: 1.5rem;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* === フォーム === */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.form-label .required {
  color: var(--color-overdue);
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.form-textarea {
  resize: vertical;
  min-height: 60px;
}

.form-row {
  display: flex;
  gap: 10px;
}

#create-type-tabs {
  margin-bottom: 14px;
}
