/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #FBF8F1;
  --bg-deep: #F2EDE0;
  --surface: #FFFFFF;
  --accent: #7B9E89;
  --accent-dark: #5F7E6C;
  --accent-soft: #E8F0EA;
  --text: #2C2C2C;
  --text-sub: #7A7A7A;
  --text-mute: #AFAFAF;
  --border: #ECE7DA;
  --danger: #C77861;
  --warn-bg: #FBEFE8;

  --cat-health: #C6DECD;
  --cat-health-bg: #E4F0E5;
  --cat-beauty: #F4D1D4;
  --cat-beauty-bg: #FBE9EA;
  --cat-exercise_care: #F8D9B5;
  --cat-exercise_care-bg: #FBECD2;
  --cat-life: #EAE0CB;
  --cat-life-bg: #F4ECDA;
  --cat-car_belongings: #CFE0EA;
  --cat-car_belongings-bg: #E5EEF4;
  --cat-other: #DDDDDD;
  --cat-other-bg: #ECECEC;

  --radius: 14px;
  --radius-sm: 10px;
  --tap-min: 44px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-card: 0 2px 6px rgba(60, 80, 70, 0.06);
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
               "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: none;
}

input, textarea, select {
  font: inherit;
  color: inherit;
}

/* ===== Layout ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 96px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100dvh;
}

.loading {
  text-align: center;
  color: var(--text-sub);
  padding: 80px 0;
}

/* ===== Header ===== */
.app-header {
  text-align: center;
  padding: 12px 0 4px;
}

.app-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-dark);
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.app-title-icon {
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  line-height: 32px;
  text-align: center;
}

.app-subtitle {
  font-size: 13px;
  color: var(--text-sub);
  margin-top: 4px;
}

.screen-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 8px;
  min-height: var(--tap-min);
}

.screen-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-dark);
  flex: 1;
  text-align: center;
}

.back-btn {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--accent-dark);
  border-radius: 50%;
}

.back-btn:active {
  background: var(--accent-soft);
}

.header-spacer {
  min-width: var(--tap-min);
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 8px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap-min);
  padding: 0 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  border: 1px solid transparent;
  transition: opacity 0.15s, background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:active {
  background: var(--accent-dark);
}

.btn-primary:disabled {
  background: #C4D2C9;
  color: #fff;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--border);
}

.btn-ghost:active {
  background: var(--accent-soft);
}

.btn-outline {
  background: var(--surface);
  color: var(--accent-dark);
  border: 1px solid var(--accent);
}

.btn-outline:active {
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-block {
  width: 100%;
}

.btn-small {
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
}

/* ===== Category filter chips ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
}

.filter-chip {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-sub);
}

.filter-chip[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.filter-chip.cat-health[aria-pressed="true"]         { background: var(--cat-health); color: var(--accent-dark); border-color: var(--cat-health); }
.filter-chip.cat-beauty[aria-pressed="true"]         { background: var(--cat-beauty); color: #8C5560; border-color: var(--cat-beauty); }
.filter-chip.cat-exercise_care[aria-pressed="true"]  { background: var(--cat-exercise_care); color: #8C6A3A; border-color: var(--cat-exercise_care); }
.filter-chip.cat-life[aria-pressed="true"]           { background: var(--cat-life); color: #7B6A4A; border-color: var(--cat-life); }
.filter-chip.cat-car_belongings[aria-pressed="true"] { background: var(--cat-car_belongings); color: #4A6678; border-color: var(--cat-car_belongings); }
.filter-chip.cat-other[aria-pressed="true"]          { background: var(--cat-other); color: #555; border-color: var(--cat-other); }

/* ===== Item cards (Home) ===== */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 12px 14px;
}

.item-card-main {
  flex: 1;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: transparent;
  min-height: var(--tap-min);
  padding: 0;
}

.item-card-main:active {
  opacity: 0.7;
}

/* ===== Drag handle / reorder ===== */
.drag-handle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  min-height: 44px;
  margin-left: 2px;
  margin-right: -4px;
  color: var(--text-mute);
  font-size: 18px;
  line-height: 1;
  letter-spacing: -2px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}

.item-list.reorderable .drag-handle {
  display: inline-flex;
}

.drag-handle:active {
  cursor: grabbing;
  color: var(--accent-dark);
}

.item-card.dragging {
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(60, 80, 70, 0.18);
  border-color: var(--accent);
  opacity: 0.98;
}

.item-list.dragging-active .item-card-main,
.item-list.dragging-active .item-card .btn {
  pointer-events: none;
}

.item-list.dragging-active {
  user-select: none;
  -webkit-user-select: none;
}

.item-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--cat-health-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.item-icon.cat-health         { background: var(--cat-health-bg); }
.item-icon.cat-beauty         { background: var(--cat-beauty-bg); }
.item-icon.cat-exercise_care  { background: var(--cat-exercise_care-bg); }
.item-icon.cat-life           { background: var(--cat-life-bg); }
.item-icon.cat-car_belongings { background: var(--cat-car_belongings-bg); }
.item-icon.cat-other          { background: var(--cat-other-bg); }

.item-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.item-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.item-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12.5px;
  color: var(--text-sub);
}

.item-dates .label {
  color: var(--text-mute);
  margin-right: 4px;
}

.item-dates .value {
  color: var(--text-sub);
}

.item-dates .value.muted {
  color: var(--text-mute);
}

.item-dates .days {
  color: var(--accent-dark);
  font-size: 11.5px;
  margin-left: 4px;
}

.item-action {
  display: flex;
  align-items: center;
}

/* ===== Empty / info ===== */
.empty {
  text-align: center;
  color: var(--text-sub);
  padding: 32px 8px;
  font-size: 14px;
}

.info-text {
  font-size: 13.5px;
  color: var(--text-sub);
  line-height: 1.7;
}

/* ===== Onboarding ===== */
.onboarding-intro {
  text-align: center;
  padding: 8px 0 4px;
}

.onboarding-intro h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-dark);
  margin-bottom: 6px;
}

.onboarding-intro p {
  font-size: 13.5px;
  color: var(--text-sub);
}

.onboarding-group {
  margin-bottom: 4px;
}

.onboarding-group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
}

.onboarding-group-title::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.onboarding-group.cat-health         .onboarding-group-title::before { background: var(--cat-health); }
.onboarding-group.cat-beauty         .onboarding-group-title::before { background: var(--cat-beauty); }
.onboarding-group.cat-exercise_care  .onboarding-group-title::before { background: var(--cat-exercise_care); }
.onboarding-group.cat-life           .onboarding-group-title::before { background: var(--cat-life); }
.onboarding-group.cat-car_belongings .onboarding-group-title::before { background: var(--cat-car_belongings); }
.onboarding-group.cat-other          .onboarding-group-title::before { background: var(--cat-other); }

.choice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  min-height: var(--tap-min);
  cursor: pointer;
}

.choice-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  margin-left: auto;
}

.choice-row .choice-icon {
  font-size: 20px;
  width: 32px;
  text-align: center;
}

.choice-row .choice-name {
  font-size: 15px;
  font-weight: 500;
}

.choice-row.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.sticky-action {
  position: sticky;
  bottom: 12px;
  padding-top: 8px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}

/* ===== Forms ===== */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
}

.field-note {
  font-size: 12px;
  color: var(--text-mute);
  margin-top: 4px;
  line-height: 1.6;
}

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap-min);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.6;
}

.form-item-header {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.form-item-header .item-icon {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.form-item-header .item-name {
  font-size: 16px;
  font-weight: 600;
}

.amount-wrap {
  position: relative;
}

.amount-wrap .input {
  padding-right: 40px;
}

.amount-wrap .suffix {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-sub);
  font-size: 14px;
  pointer-events: none;
}

/* ===== Detail ===== */
.detail-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.detail-hero .item-icon {
  width: 56px;
  height: 56px;
  font-size: 26px;
}

.detail-hero .item-name {
  font-size: 18px;
  font-weight: 700;
}

.detail-hero .item-cat {
  font-size: 12px;
  color: var(--text-sub);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.summary-box {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 12px;
  text-align: center;
}

.summary-box .summary-label {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.summary-box .summary-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.summary-box .summary-value.muted {
  color: var(--text-mute);
  font-weight: 500;
}

.summary-box .summary-days {
  font-size: 11.5px;
  color: var(--accent-dark);
  margin-top: 2px;
}

.section-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-sub);
  margin: 8px 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-label .hint {
  font-size: 12px;
  color: var(--text-mute);
  font-weight: 500;
}

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

.history-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.history-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

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

.history-amount {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-dark);
}

.history-next {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.history-memo {
  font-size: 13.5px;
  color: var(--text-sub);
  white-space: pre-wrap;
  word-break: break-word;
}

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

.history-actions .btn {
  padding: 0 12px;
  min-height: 34px;
  font-size: 13px;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.detail-actions .detail-danger-action {
  grid-column: 1 / -1;
}

/* ===== Settings ===== */
.settings-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

.settings-block h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-dark);
  margin-bottom: 6px;
}

.settings-block p {
  font-size: 13.5px;
  color: var(--text-sub);
  line-height: 1.7;
}

.hidden-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.hidden-row:first-of-type {
  border-top: none;
}

.hidden-row .item-icon {
  width: 36px;
  height: 36px;
  font-size: 16px;
}

.hidden-row .item-name {
  flex: 1;
  font-size: 14px;
}

/* ===== Bottom bar ===== */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 0 calc(env(safe-area-inset-bottom, 0) + 4px);
  z-index: 10;
}

.bottom-bar-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.bottom-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  font-size: 11px;
  color: var(--text-mute);
  padding: 6px 0;
}

.bottom-btn .icon {
  font-size: 22px;
  line-height: 1;
}

.bottom-btn[aria-current="page"] {
  color: var(--accent-dark);
}

.bottom-btn:active {
  color: var(--accent);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  background: var(--accent-dark);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  z-index: 100;
  max-width: 90vw;
}

.toast[hidden] {
  display: none;
}

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

/* ===== Confirm dialog ===== */
.confirm-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  max-width: 360px;
  width: calc(100vw - 32px);
  height: fit-content;
  max-height: calc(100dvh - 32px);
}

.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.32);
}

.confirm-form {
  background: var(--surface);
  padding: 20px 18px 14px;
  border-radius: var(--radius);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.18);
}

.confirm-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.confirm-message {
  font-size: 14px;
  color: var(--text-sub);
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-form .btn {
  min-height: 40px;
  padding: 0 16px;
}

.confirm-form.danger #confirm-ok {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ===== Section spacing helpers ===== */
.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Add: Category picker ===== */
.cat-card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 16px;
  min-height: 64px;
}

.cat-card:active {
  background: var(--accent-soft);
}

.cat-card-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cat-card.cat-health         .cat-card-dot { background: var(--cat-health); }
.cat-card.cat-beauty         .cat-card-dot { background: var(--cat-beauty); }
.cat-card.cat-exercise_care  .cat-card-dot { background: var(--cat-exercise_care); }
.cat-card.cat-life           .cat-card-dot { background: var(--cat-life); }
.cat-card.cat-car_belongings .cat-card-dot { background: var(--cat-car_belongings); }
.cat-card.cat-other          .cat-card-dot { background: var(--cat-other); }

.cat-card-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cat-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.cat-card-sub {
  font-size: 12.5px;
  color: var(--text-sub);
}

.cat-card-chevron {
  color: var(--text-mute);
  font-size: 22px;
  line-height: 1;
}

/* ===== Add: Suggested items ===== */
.suggest-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.suggest-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 12px 14px;
  min-height: 60px;
}

.suggest-row:active:not([disabled]) {
  background: var(--accent-soft);
}

.suggest-row[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
}

.suggest-row .item-icon {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.suggest-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.suggest-plus {
  color: var(--accent-dark);
  font-size: 20px;
  font-weight: 700;
  width: 28px;
  text-align: center;
}

.suggest-badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.suggest-badge.added {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.suggest-badge.hidden-mark {
  background: var(--cat-life-bg);
  color: #7B6A4A;
}

.suggest-row-custom {
  margin-top: 12px;
  border-style: dashed;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.suggest-row-custom .item-icon {
  background: var(--surface);
}

.suggest-row-custom .suggest-name {
  color: var(--accent-dark);
  font-weight: 600;
}
