/* =========================================================
   買っちゃった / 耐えたリスト - style.css
   G&B Diary 風のシンプル・ミニマル(白基調) デザイン
   ========================================================= */

:root {
  --bg: #faf9f5;
  --surface: #ffffff;
  --ink: #2b2b26;
  --ink-soft: #7a786f;
  --border: #e8e5db;

  --endured: #5f8a68;
  --endured-bg: #e7f0e5;
  --endured-strong: #4b7154;

  --wasted: #c96a4e;
  --wasted-bg: #f7e6de;
  --wasted-strong: #a8503a;

  --diff-plus: #4b7154;
  --diff-minus: #a8503a;

  --line-color: #3d6ae0;
  --line-bg: #e6ebfb;

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 22px;

  --shadow-1: 0 2px 8px rgba(43, 43, 38, 0.06);
  --shadow-2: 0 8px 24px rgba(43, 43, 38, 0.12);

  --ad-height: 60px;
  --tabbar-height: 64px;
  --linkbar-height: 34px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  overscroll-behavior-y: none;
  touch-action: manipulation;
}

textarea, input {
  -webkit-user-select: text;
  user-select: text;
}

button {
  font-family: inherit;
  touch-action: manipulation;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- ヘッダー ---------- */
.app-header {
  padding: 20px 20px 10px;
  text-align: center;
}

.logo {
  margin: 0;
  font-family: "Zen Maru Gothic", sans-serif;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.logo .amp {
  color: var(--ink-soft);
  font-weight: 500;
  margin: 0 2px;
}

.logo-diary {
  color: var(--ink-soft);
  font-weight: 500;
}

/* ---------- タブコンテンツ ---------- */
.tab-content {
  flex: 1;
  padding: 4px 20px calc(var(--tabbar-height) + var(--linkbar-height) + var(--ad-height) + env(safe-area-inset-bottom) + 24px);
}

.tab-panel {
  display: none;
  animation: fadeIn 0.18s ease;
}

.tab-panel.is-active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-lead {
  margin: 12px 4px 18px;
  font-size: 15px;
  color: var(--ink-soft);
}

.block-title {
  font-family: "Zen Maru Gothic", sans-serif;
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 10px 2px;
}

.field-label {
  display: block;
  margin: 14px 2px 6px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 500;
}

.text-input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
  font-size: 15px;
  color: var(--ink);
  font-family: inherit;
}

.text-input:focus {
  outline: none;
  border-color: var(--ink-soft);
}

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

.datetime-row .text-input {
  flex: 1;
  min-width: 0;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
  margin: 20px 0;
}

/* ---------- 区分選択（記録） ---------- */
.type-select {
  display: flex;
  gap: 10px;
}

.type-btn {
  flex: 1;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-m);
  padding: 18px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.type-btn:active {
  transform: scale(0.96);
}

.type-btn-label {
  font-family: "Zen Maru Gothic", sans-serif;
  font-weight: 700;
  font-size: 15px;
}

.type-btn-sub {
  font-size: 11px;
  color: var(--ink-soft);
}

.type-btn.type-wasted .type-btn-label { color: var(--wasted-strong); }
.type-btn.type-endured .type-btn-label { color: var(--endured-strong); }

.type-btn.type-wasted.is-selected { background: var(--wasted-bg); border-color: var(--wasted); }
.type-btn.type-endured.is-selected { background: var(--endured-bg); border-color: var(--endured); }

.type-select-modal .type-btn {
  padding: 12px 6px;
}

/* ---------- 記録フォーム ---------- */
.entry-form {
  margin-top: 20px;
}

.selected-type-chip {
  display: inline-block;
  font-family: "Zen Maru Gothic", sans-serif;
  font-weight: 700;
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.selected-type-chip.type-wasted { background: var(--wasted-bg); color: var(--wasted-strong); }
.selected-type-chip.type-endured { background: var(--endured-bg); color: var(--endured-strong); }

.tag-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}

.tag-field-header .field-label {
  margin: 0;
}

.tag-chip-select {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tag-chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.tag-chip.is-selected {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.tag-empty-hint {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 8px 2px 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.primary-btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-m);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 15px;
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.primary-btn:active {
  transform: scale(0.97);
}

.secondary-btn {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: var(--radius-m);
  font-size: 14px;
  padding: 15px 16px;
  cursor: pointer;
}

.text-btn {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 13px;
  padding: 6px;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- 最近の記録 ---------- */
.recent-entries-block {
  margin-top: 30px;
}

.recent-entry-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recent-entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px 14px;
  box-shadow: var(--shadow-1);
}

.recent-entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.recent-entry-tag-type {
  font-family: "Zen Maru Gothic", sans-serif;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.recent-entry-tag-type.type-wasted { background: var(--wasted-bg); color: var(--wasted-strong); }
.recent-entry-tag-type.type-endured { background: var(--endured-bg); color: var(--endured-strong); }

.recent-entry-datetime {
  font-size: 11px;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.recent-entry-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.recent-entry-name {
  font-size: 14px;
  color: var(--ink);
  word-break: break-word;
}

.recent-entry-place {
  font-size: 11.5px;
  color: var(--ink-soft);
}

.recent-entry-amount {
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.recent-entry-amount.type-wasted { color: var(--wasted-strong); }
.recent-entry-amount.type-endured { color: var(--endured-strong); }

.recent-entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.recent-entry-tag-pill {
  font-size: 10.5px;
  background: var(--bg);
  color: var(--ink-soft);
  padding: 3px 9px;
  border-radius: 999px;
}

.recent-entry-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  justify-content: flex-end;
}

.icon-btn {
  border: none;
  background: var(--bg);
  color: var(--ink-soft);
  border-radius: var(--radius-s);
  font-size: 12px;
  padding: 7px 12px;
  cursor: pointer;
}

.icon-btn.danger {
  color: #b0524f;
}

/* ---------- 確認：期間切替 ---------- */
.period-toggle {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.seg-btn {
  flex: 1;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}

.seg-btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.period-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 14px 0;
}

.period-nav-btn {
  border: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}

.period-label {
  font-family: "Zen Maru Gothic", sans-serif;
  font-weight: 700;
  font-size: 15px;
  min-width: 110px;
  text-align: center;
}

/* ---------- サマリーカード ---------- */
.summary-cards {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.summary-card {
  flex: 1;
  border-radius: var(--radius-m);
  padding: 12px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-card-label {
  font-size: 10.5px;
  color: var(--ink-soft);
}

.summary-card-value {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary-wasted { background: var(--wasted-bg); }
.summary-wasted .summary-card-value { color: var(--wasted-strong); }
.summary-endured { background: var(--endured-bg); }
.summary-endured .summary-card-value { color: var(--endured-strong); }
.summary-diff { background: var(--line-bg); }
.summary-diff .summary-card-value { color: var(--line-color); }

/* ---------- グラフ ---------- */
.graph-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-1);
}

.graph-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.graph-title {
  margin: 0;
  font-family: "Zen Maru Gothic", sans-serif;
  font-size: 14px;
  font-weight: 700;
}

.graph-type-toggle {
  display: flex;
  gap: 6px;
}

.mini-seg-btn {
  flex: 1;
  border: 1.5px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 7px 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
}

.mini-seg-btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.chart-legend {
  display: flex;
  gap: 16px;
  margin: 8px 2px 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ink-soft);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.legend-swatch.legend-bar { background: var(--endured); }
.legend-swatch.legend-line { background: var(--line-color); border-radius: 50%; }

.chart-wrapper {
  width: 100%;
  margin-top: 6px;
}

.chart-wrapper svg {
  width: 100%;
  height: auto;
  display: block;
}

/* ---------- タグ別集計 ---------- */
.tag-summary-block {
  margin-bottom: 10px;
}

.tag-summary-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tag-summary-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 10px 12px;
}

.tag-summary-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.tag-summary-amounts {
  display: flex;
  gap: 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.tag-summary-amounts .wasted-amt { color: var(--wasted-strong); }
.tag-summary-amounts .endured-amt { color: var(--endured-strong); }

/* ---------- 計画タブ ---------- */
.plan-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}

.plan-header-title {
  margin: 0;
}

.gear-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.plan-chart-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.legend-swatch.legend-target {
  background: none;
  border-radius: 0;
  border-top: 2px dashed var(--wasted-strong);
  height: 0;
  width: 14px;
  align-self: center;
}

.plan-delete-btn {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 14px;
  color: #b0524f;
}

.plan-empty-block {
  text-align: center;
  padding: 20px 0 10px;
}

.plan-empty-block .primary-btn {
  display: inline-block;
  width: auto;
  padding: 13px 28px;
  margin-top: 6px;
}

.plan-complete-btn {
  margin-top: 16px;
  background: linear-gradient(90deg, var(--endured-strong), var(--endured));
}

.plan-history-block {
  margin-top: 28px;
}

.plan-history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plan-history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px 14px;
  box-shadow: var(--shadow-1);
}

.plan-history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.plan-history-name {
  font-family: "Zen Maru Gothic", sans-serif;
  font-weight: 700;
  font-size: 14px;
}

.plan-history-date {
  font-size: 11px;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.plan-history-amounts {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--endured-strong);
  font-variant-numeric: tabular-nums;
}

.plan-history-reward {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-soft);
}

.plan-history-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.plan-progress-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 18px;
  margin: 14px 0 20px;
  box-shadow: var(--shadow-1);
}

.progress-bar-outer {
  width: 100%;
  height: 16px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar-inner {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--endured), var(--endured-strong));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-numbers {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 10px;
}

.progress-percent {
  font-family: "Zen Maru Gothic", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--endured-strong);
}

.progress-amounts {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.plan-meta-row {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.plan-meta {
  font-size: 12px;
  color: var(--ink-soft);
}

.plan-form {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.switch-label {
  margin: 0;
  flex: 1;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #d8d5c9;
  transition: .2s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider { background-color: var(--endured); }
input:checked + .slider:before { transform: translateX(20px); }

/* ---------- タブバー・リンク・広告（下部固定スタック） ---------- */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--ad-height) + var(--linkbar-height) + env(safe-area-inset-bottom));
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  height: var(--tabbar-height);
  box-shadow: 0 -2px 10px rgba(43, 43, 38, 0.05);
  z-index: 950;
  max-width: 480px;
  margin: 0 auto;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  padding: 8px 0;
  border-radius: var(--radius-s);
  color: var(--ink-soft);
  cursor: pointer;
}

.tab-btn.is-active {
  color: var(--ink);
  background: var(--bg);
}

.tab-icon {
  font-size: 18px;
}

.tab-label {
  font-size: 11px;
  font-weight: 500;
}

.mrs-tools-link-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--ad-height) + env(safe-area-inset-bottom));
  height: var(--linkbar-height);
  margin: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 940;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.mrs-tools-link {
  color: var(--ink-soft);
  font-size: 12.5px;
  text-decoration: underline;
}

.ad-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: var(--ad-height);
  background-color: #121212;
  z-index: 1000;
  padding-top: 1px;
  padding-bottom: calc(1px + env(safe-area-inset-bottom));
  border-top: 1px solid #333;
}

/* ---------- モーダル ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 43, 38, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-2);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-title {
  margin: 0 0 14px;
  font-family: "Zen Maru Gothic", sans-serif;
  font-size: 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- タグ管理モーダル ---------- */
.tag-manage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 40vh;
  overflow-y: auto;
}

.tag-manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-radius: var(--radius-s);
  padding: 10px 12px;
}

.tag-manage-name {
  font-size: 14px;
}

.tag-manage-delete {
  border: none;
  background: none;
  color: #b0524f;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  padding: 4px 8px;
}

.tag-add-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.tag-add-row .text-input {
  flex: 1;
}

.tag-add-btn {
  flex: 0 0 auto;
  padding: 12px 20px;
}

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--ad-height) + var(--linkbar-height) + var(--tabbar-height) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 999px;
  z-index: 1200;
  box-shadow: var(--shadow-2);
  animation: toastIn 0.2s ease;
  max-width: 90%;
  text-align: center;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
