:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
}

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

body {
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ヘッダー */
.app-header {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.logo {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.5px;
}
.logo i { margin-right: 8px; }
.main-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.nav-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.85);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.nav-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.nav-btn.active { background: rgba(255,255,255,0.25); color: #fff; }
.nav-btn i { margin-right: 6px; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.tab-content { display: none; animation: fadeIn 0.3s; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.section-head { margin-bottom: 24px; }
.section-head h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.section-head h2 i { color: var(--primary); margin-right: 8px; }
.section-head h3 { font-size: 1.2rem; font-weight: 700; }
.section-head h3 i { color: var(--primary); margin-right: 6px; }
.lead { color: var(--text-muted); font-size: 0.95rem; }

/* ダッシュボード */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid;
}
.stat-blue { border-color: #3b82f6; }
.stat-blue .stat-icon { background: #dbeafe; color: #3b82f6; }
.stat-green { border-color: #10b981; }
.stat-green .stat-icon { background: #d1fae5; color: #10b981; }
.stat-orange { border-color: #f59e0b; }
.stat-orange .stat-icon { background: #fef3c7; color: #f59e0b; }
.stat-purple { border-color: #8b5cf6; }
.stat-purple .stat-icon { background: #ede9fe; color: #8b5cf6; }
.stat-icon {
  width: 50px; height: 50px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.stat-label { font-size: 0.85rem; color: var(--text-muted); }
.stat-value { font-size: 1.8rem; font-weight: 700; }

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.chart-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-card.chart-wide { grid-column: 1 / -1; }
.chart-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
}
.chart-card h3 i { color: var(--primary); margin-right: 6px; }
.chart-wrap { position: relative; height: 280px; }

/* 週スケジュール */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
}
.day-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}
.day-card.today { box-shadow: 0 0 0 2px var(--primary), var(--shadow); }
.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.day-name { font-weight: 700; font-size: 1rem; }
.day-name.sun { color: var(--danger); }
.day-name.sat { color: #3b82f6; }
.day-add-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--primary-light);
  color: var(--primary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.day-add-btn:hover { background: var(--primary); color: #fff; }
.schedule-items { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.schedule-item {
  background: var(--primary-light);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  cursor: default;
}
.schedule-item-info { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.schedule-item-icon { font-size: 1.1rem; }
.schedule-item-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schedule-item-target { color: var(--text-muted); font-size: 0.75rem; }
.schedule-item-del {
  background: none; border: none;
  color: var(--danger);
  cursor: pointer;
  opacity: 0.5;
  font-size: 0.85rem;
}
.schedule-item-del:hover { opacity: 1; }
.empty-day {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 20px 0;
  font-style: italic;
}

/* 達成記録 */
.record-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card-bg);
  padding: 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.record-toolbar label { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.record-toolbar input[type="date"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
}
.day-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
}

.record-list { display: flex; flex-direction: column; gap: 12px; }
.record-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  border-left: 4px solid var(--border);
  transition: all 0.2s;
}
.record-card.achieved { border-color: var(--success); background: #f0fdf4; }
.record-card.partial { border-color: var(--warning); }
.record-icon { font-size: 2rem; }
.record-info { flex: 1; }
.record-name { font-weight: 700; font-size: 1.05rem; }
.record-target { color: var(--text-muted); font-size: 0.85rem; }
.record-progress {
  margin-top: 6px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  width: 200px; max-width: 100%;
}
.record-progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}
.record-progress-bar.full { background: var(--success); }
.record-actual {
  text-align: right;
  font-weight: 700;
}
.record-actual-value { font-size: 1.4rem; color: var(--primary); }
.record-actual-value.achieved { color: var(--success); }
.record-actual-empty { color: var(--text-muted); font-style: italic; font-size: 0.9rem; }
.record-actions { display: flex; gap: 8px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--card-bg);
  border-radius: 12px;
  color: var(--text-muted);
}
.empty-state i { font-size: 3rem; color: var(--border); margin-bottom: 12px; display: block; }

.history-table-wrap {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.history-table th, .history-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.history-table th {
  background: #f9fafb;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.history-table tr:last-child td { border-bottom: none; }
.achieved-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.achieved-badge.yes { background: #d1fae5; color: #065f46; }
.achieved-badge.no { background: #fee2e2; color: #991b1b; }

/* マスタ */
.master-toolbar { margin-bottom: 20px; }
.master-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.master-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.2s;
}
.master-card:hover { transform: translateY(-2px); }
.master-icon { font-size: 2rem; }
.master-info { flex: 1; min-width: 0; }
.master-name { font-weight: 700; }
.master-meta { font-size: 0.8rem; color: var(--text-muted); }
.master-actions { display: flex; flex-direction: column; gap: 4px; }
.icon-btn {
  background: none; border: none;
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}
.icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.icon-btn.danger:hover { background: #fee2e2; color: var(--danger); }
.category-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  margin-right: 4px;
}

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #f3f4f6; color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }

/* データ管理 */
.data-info {
  background: #eff6ff;
  border-left: 4px solid #3b82f6;
  border-radius: 8px;
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 24px;
  font-size: 0.9rem;
  color: #1e3a8a;
}
.data-info i { font-size: 1.2rem; color: #3b82f6; margin-top: 2px; }
.data-tools {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.data-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.data-card-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.data-card-danger .data-card-icon { background: #fee2e2; color: var(--danger); }
.data-card-body { flex: 1; }
.data-card-title { font-weight: 700; margin-bottom: 4px; }
.data-card-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 12px; line-height: 1.5; }

/* モーダル */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.active { display: flex; }
.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none; border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-with-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}
.input-with-unit input { flex: 1; }
.unit-label {
  background: var(--primary-light);
  color: var(--primary);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}
.record-modal-info {
  background: var(--primary-light);
  padding: 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.record-modal-info .info-icon { font-size: 1.8rem; }
.record-modal-info .info-name { font-weight: 700; }
.record-modal-info .info-target { font-size: 0.85rem; color: var(--text-muted); }

/* トースト */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2937;
  color: #fff;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  transition: all 0.3s;
  z-index: 2000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* レスポンシブ */
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .week-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .main-nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav-btn { white-space: nowrap; }
  .container { padding: 20px 14px; }
  .week-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 1.4rem; }
  .record-card { flex-wrap: wrap; }
  .record-progress { width: 100%; }
}
