/* 自主事業集計アプリ - スタイルシート */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600;700&display=swap');

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #a5b4fc;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f0f4ff;
  --card-bg: rgba(255,255,255,0.85);
  --border: rgba(99,102,241,0.15);
  --text: #1e293b;
  --text-muted: #64748b;
  --shadow: 0 4px 24px rgba(99,102,241,0.10);
  --radius: 14px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ---- Header ---- */
.app-header {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
  box-shadow: 0 2px 12px rgba(99,102,241,0.25);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-title {
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.facility-selector {
  background: rgba(255,255,255,0.18);
  border: 1.5px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 7px 16px;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  backdrop-filter: blur(8px);
  transition: background 0.2s;
  font-family: inherit;
}
.facility-selector:hover { background: rgba(255,255,255,0.28); }

/* ---- Tab Nav ---- */
.tab-nav {
  background: rgba(255,255,255,0.9);
  border-bottom: 1.5px solid var(--border);
  position: sticky;
  top: 60px;
  z-index: 90;
  backdrop-filter: blur(12px);
}
.tab-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-nav-inner::-webkit-scrollbar { display: none; }
.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.tab-btn i { font-size: 1rem; }
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

/* ---- Main ---- */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}
.tab-panel { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Cards ---- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px;
  backdrop-filter: blur(8px);
  margin-bottom: 16px;
}
.card-header {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
}

/* ---- Section Header ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 8px;
}
.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
}

/* ---- KPI Grid ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 640px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 16px 18px;
  backdrop-filter: blur(8px);
  transition: transform 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.kpi-value { font-size: 1.45rem; font-weight: 700; color: var(--primary-dark); margin-top: 4px; }

/* ---- Skeleton ---- */
.skeleton {
  background: linear-gradient(90deg, #e8eaf6 25%, #f0f2ff 50%, #e8eaf6 75%);
  background-size: 400% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer { 0%{background-position:100% 50%} 100%{background-position:0% 50%} }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--primary-dark) 0%, #3730a3 100%); transform: translateY(-1px); }
.btn-secondary {
  background: rgba(99,102,241,0.08);
  color: var(--primary-dark);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: rgba(99,102,241,0.15); }
.btn-success {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(34,197,94,0.3);
}
.btn-success:hover:not(:disabled) { background: linear-gradient(135deg, #16a34a 0%, #166534 100%); transform: translateY(-1px); }
.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}
.btn-danger:hover:not(:disabled) { background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%); transform: translateY(-1px); }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s, transform 0.15s;
}
.btn-icon:hover { background: rgba(0,0,0,0.06); transform: scale(1.1); }

/* ---- Forms ---- */
.form-group { margin-bottom: 12px; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.form-label.required::after { content: ' *'; color: var(--danger); }
.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.9);
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }
.form-input:read-only { background: #f3f4f6; }

textarea.form-input { resize: vertical; }

/* ---- Age Grid ---- */
.age-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (min-width: 640px) { .age-grid { grid-template-columns: repeat(6, 1fr); } }
.age-input { text-align: right; }

/* ---- Dropdown ---- */
.dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  margin-top: 2px;
}
.dropdown-list.hidden { display: none; }
.dropdown-item {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.15s;
}
.dropdown-item:hover { background: rgba(99,102,241,0.08); color: var(--primary); }

/* ---- Table ---- */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-sm); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  background: linear-gradient(135deg, rgba(99,102,241,0.12) 0%, rgba(139,92,246,0.08) 100%);
  color: var(--primary-dark);
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: rgba(99,102,241,0.04); }
.data-table td.text-right, .data-table th.text-right { text-align: right; }

/* ---- Rank Badge ---- */
.rank-badge {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
  background: #e5e7eb;
  color: #6b7280;
}
.rank-1 { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; }
.rank-2 { background: linear-gradient(135deg, #9ca3af, #6b7280); color: #fff; }
.rank-3 { background: linear-gradient(135deg, #b45309, #92400e); color: #fff; }

/* ---- Badge ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-primary { background: rgba(99,102,241,0.15); color: var(--primary-dark); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30,20,80,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal-container {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(30,20,80,0.2);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn { from { opacity:0; transform: scale(0.92) translateY(16px); } to { opacity:1; transform: scale(1) translateY(0); } }
.modal-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 1rem;
  transition: background 0.2s;
}
.modal-close:hover { background: rgba(255,255,255,0.35); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* ---- Facility List in Modal ---- */
.facility-item { border-radius: var(--radius-sm); transition: background 0.15s; }

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  opacity: 0;
  transform: translateX(40px);
  transition: all 0.3s ease;
  pointer-events: auto;
  min-width: 220px;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { background: linear-gradient(135deg, #22c55e, #16a34a); }
.toast-error { background: linear-gradient(135deg, #ef4444, #dc2626); }
.toast-info { background: linear-gradient(135deg, #6366f1, #4f46e5); }

/* ---- Empty State ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

/* ---- Utilities ---- */
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.min-w-0 { min-width: 0; }
