/* まぬい家計簿 ブランドカラー（スプレッドシート配色から抽出） */
:root {
  --bg: #F8F5F2;
  --surface: #FFFFFF;
  --surface-muted: #F3EFEA;
  --mauve: #8C8790;
  --mauve-dark: #716C75;
  --sage: #D9E3DD;
  --sage-ink: #384B41;
  --border: #E4DFDA;
  --border-strong: #D0D0D0;
  --text: #333333;
  --text-muted: #827D86;
  --error: #B85C5C;
  --warn: #B5894A;
  --radius-sm: 10px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

/* Header */
.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-mark {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--mauve);
}

.brand-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
  white-space: nowrap;
}

.header-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--text-muted);
}

.status-pill.ok { background: var(--sage); border-color: transparent; color: var(--sage-ink); }
.status-pill.ok .status-dot { background: var(--sage-ink); }
.status-pill.syncing { color: var(--warn); border-color: rgba(181, 137, 74, 0.4); }
.status-pill.syncing .status-dot { background: var(--warn); }
.status-pill.error { color: var(--error); border-color: rgba(184, 92, 92, 0.45); }
.status-pill.error .status-dot { background: var(--error); }

.icon-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:active { background: var(--surface-muted); }

/* Mode switcher */
.mode-wrap { flex-shrink: 0; padding: 4px 16px 8px; }

.segment {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.segment button {
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 7px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.segment button.active { background: var(--mauve); color: #FFFFFF; }

/* Main input stack */
.main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 2px 16px 10px;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.main > * { flex-shrink: 0; }

/* Amount card */
.amount-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

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

.micro-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.sheet-target {
  font-size: 11px;
  font-weight: 600;
  color: var(--sage-ink);
  background: var(--sage);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.amount-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
  overflow: hidden;
}

.currency {
  flex-shrink: 0;
  font-family: "Roboto", sans-serif;
  font-size: 18px;
  font-weight: 500;
  color: var(--text-muted);
}

.amount-value {
  font-family: "Roboto", -apple-system, sans-serif;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amount-value.empty { color: var(--border-strong); }

/* Category chips */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.chip {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
}

.chip:active { transform: scale(0.97); }
.chip.selected { background: var(--sage); border-color: #B4C8BC; color: var(--sage-ink); font-weight: 700; }

/* Meta inputs */
.meta-stack { display: flex; flex-direction: column; gap: 7px; }
.meta-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.meta-row.single { grid-template-columns: minmax(0, 1fr); }

.control {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 40px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  display: block;
  overflow: hidden;
}

input[type="date"].control { padding: 0 10px; line-height: 38px; text-align: left; }
input[type="date"].control::-webkit-date-and-time-value { text-align: left; margin: 0; }

select.control {
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23827D86' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  text-overflow: ellipsis;
}

.control:focus { border-color: var(--mauve); }
.control::placeholder { color: #ACA7B0; font-size: 13px; }

/* Keypad */
.keypad-wrap {
  flex-shrink: 0;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.key {
  width: 100%;
  min-width: 0;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", "Noto Sans JP", sans-serif;
  font-size: 19px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background 0.1s ease, transform 0.06s ease;
}

.key:active { transform: scale(0.96); background: var(--surface-muted); }
.key.sub { font-size: 14px; color: var(--text-muted); }
.key.submit {
  grid-row: span 2;
  height: auto;
  background: var(--mauve);
  border-color: var(--mauve);
  color: #FFFFFF;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.key.submit:active { background: var(--mauve-dark); }
.key.submit:disabled { opacity: 0.38; cursor: not-allowed; }

/* Onboarding Overlay (Login / Sheet Picker / Access Code) */
.setup-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 40;
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px;
}

.setup-overlay.open { display: flex; }

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 20px;
  text-align: center;
}

.setup-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  display: block;
  border-radius: 12px;
}

.setup-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: 0.04em;
}

.setup-desc {
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.google-btn {
  width: 100%;
  height: 46px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: #FFFFFF;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  text-decoration: none;
}

.google-btn:active { background: var(--surface-muted); }

.setup-footer {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: center;
  gap: 14px;
}

.setup-footer a {
  color: var(--text-muted);
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #333333;
  color: #FFFFFF;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: 0 8px 24px rgba(51, 51, 51, 0.16);
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s ease;
  z-index: 100;
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(51, 51, 51, 0.36);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-backdrop.open { display: flex; }

.modal {
  width: 100%;
  max-width: 430px;
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 20px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.modal-title { font-size: 15px; font-weight: 700; margin: 0; letter-spacing: 0.04em; }

.info-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
  font-size: 12px;
}

.info-box-label { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.info-box-value { font-weight: 700; word-break: break-all; }

.btn-stack { display: flex; flex-direction: column; gap: 8px; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }

.btn {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary { background: var(--mauve); border-color: var(--mauve); color: #FFFFFF; }
.btn.danger { color: var(--error); border-color: rgba(184, 92, 92, 0.35); background: #FFFFFF; }

.history-list { display: flex; flex-direction: column; gap: 7px; }
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}
.history-info { min-width: 0; flex: 1; }
.history-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-amount-wrap { flex-shrink: 0; text-align: right; }

.badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; display: inline-block; margin-top: 2px; }
.badge.sent { background: var(--sage); color: var(--sage-ink); }
.badge.pending { background: rgba(181, 137, 74, 0.16); color: var(--warn); }
.badge.failed { background: rgba(184, 92, 92, 0.16); color: var(--error); }
