:root {
  --bg-color: #f5f5f5;
  --surface-color: #ffffff;
  --text-color: #222222;
  --sub-text-color: #666666;
  --accent-color: #1a73e8;
  --accent-soft: #e3f2fd;
  --danger-color: #e53935;
  --border-color: #dddddd;
  --shadow-soft: 0 4px 10px rgba(0, 0, 0, 0.06);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-pill: 999px;
}

/* 全体レイアウト */

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
    "Segoe UI", sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: 80px; /* ナビ分 */
}

/* ヘッダー */

.app-header {
  padding: 16px 16px 8px;
  background: var(--bg-color);
  position: sticky;
  top: 0;
  z-index: 5;
}

.app-title {
  font-size: 18px;
  font-weight: 600;
}

.today-label {
  margin-top: 6px;
  font-size: 13px;
  color: var(--sub-text-color);
}

/* メイン */

.app-main {
  padding: 8px 16px 16px;
  flex: 1;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.section-title {
  font-size: 18px;
  margin: 8px 0 12px;
}

.section-block {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  padding: 14px 14px 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-soft);
}

.block-label {
  margin: 0 0 10px;
  font-size: 14px;
}

/* ボタン系 */

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.select-button {
  flex: 1 1 calc(50% - 4px);
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: #fafafa;
  font-size: 14px;
  text-align: center;
  outline: none;
  cursor: pointer;
}

.button-group.multi .select-button {
  flex: 1 1 calc(50% - 4px);
}

.select-button.selected {
  background: var(--accent-soft);
  border-color: var(--accent-color);
  color: var(--accent-color);
  font-weight: 600;
}

.select-button:active {
  opacity: 0.8;
}

/* テキスト入力 */

.text-input,
.note-input {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  font-size: 14px;
  outline: none;
  resize: vertical;
}

.text-input:focus,
.note-input:focus {
  border-color: var(--accent-color);
}

/* プライマリボタン */

.primary-button {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--accent-color);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(26, 115, 232, 0.3);
}

.primary-button:active {
  opacity: 0.9;
}


/* 追加：保存済み状態のボタン */
.primary-button--saved {
  background: #9e9e9e;
  box-shadow: none;
  cursor: default;
}
.primary-button--saved:active {
  opacity: 1;
}


/* セカンダリボタン */

.secondary-button {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: #f5f5f5;
  font-size: 14px;
  cursor: pointer;
}

.secondary-button:active {
  opacity: 0.9;
}

/* メッセージ */

.save-message {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--sub-text-color);
}

.save-message.success {
  color: #2e7d32; /* 緑 */
  font-weight: 600;
}

.save-message.error {
  color: #c62828; /* 赤 */
  font-weight: 600;
}

/* 履歴リスト */

.history-list-empty {
  font-size: 14px;
  color: var(--sub-text-color);
  margin: 0;
}

.history-item {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-soft);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.history-date {
  font-size: 14px;
  font-weight: 600;
}

.history-condition {
  font-size: 13px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
}

.history-condition--great {
  background: #e8f5e9;
  border-color: #66bb6a;
  color: #2e7d32;
}

.history-condition--ok {
  background: #e3f2fd;
  border-color: #64b5f6;
  color: #1e88e5;
}

.history-condition--little-bad {
  background: #fff8e1;
  border-color: #ffb74d;
  color: #f57c00;
}

.history-condition--bad {
  background: #ffebee;
  border-color: #ef5350;
  color: #c62828;
}

.history-row {
  font-size: 13px;
  margin-bottom: 4px;
}

.history-label {
  color: var(--sub-text-color);
}

/* グラフ */

#conditionChart {
  width: 100%;
  height: 180px;
  display: block;
  border-radius: var(--radius-md);
  background: #fafafa;
}

/* ナビゲーション */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  border-top: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-around;
  padding: 6px 8px 6px;
  z-index: 10;
}

.nav-button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 4px;
  font-size: 13px;
  color: var(--sub-text-color);
  border-radius: var(--radius-pill);
}

.nav-button.active {
  color: var(--accent-color);
  background: var(--accent-soft);
  font-weight: 600;
}

/* 緊急ボタン */

.emergency-button {
  position: fixed;
  right: 16px;
  bottom: 56px;
  background: var(--danger-color);
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  text-decoration: none;
  border: none;
  box-shadow: 0 6px 10px rgba(229, 57, 53, 0.35);
  z-index: 9;
  cursor: pointer;
}

.emergency-button:active {
  opacity: 0.9;
}

/* 緊急連絡先設定 */

.emergency-settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.emergency-settings-item .history-label {
  display: block;
  margin-top: 6px;
  margin-bottom: 2px;
}

/* 緊急モーダル */

.emergency-modal.hidden {
  display: none;
}

.emergency-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.emergency-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.emergency-modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border-radius: 16px 16px 0 0;
  padding: 16px 16px 20px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
}

.emergency-contact-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 12px;
}

.emergency-contact-button {
  display: block;
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: #fafafa;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  color: var(--text-color);
}

.emergency-contact-button:active {
  background: var(--accent-soft);
}

/* ヒント */

.hint-text {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--sub-text-color);
}

/* スマホ調整 */

@media (max-width: 360px) {
  .select-button {
    font-size: 13px;
    padding: 8px 6px;
  }

  .primary-button {
    font-size: 14px;
  }
}
