/*
 * kakeibon デザインシステム。スマホ前提のモバイルファースト。
 * Propshaft でそのまま配信(プリプロセスなし)のため素の CSS で書く。
 *
 * 設計方針:
 *  - 1px 境界の多用をやめ、影(elevation)で面を浮かせて情報の階層を作る。
 *  - 金額は最重要要件なので tabular-nums で桁を揃え、常に読みやすく。
 *  - モバイルは下タブ、デスクトップは上ナビに自動で切り替える。
 */

:root {
  /* 面・文字 */
  --bg: #eef0f4;
  --surface: #ffffff;
  --surface-sunken: #f6f7f9;
  --text: #15171c;
  --text-soft: #424755;
  --muted: #8b909c;
  --border: #e7e9ef;
  --border-strong: #d4d8e0;

  /* ブランド(藍) */
  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --primary-soft: #eef1ff;
  --on-primary: #ffffff;

  /* 状態色 */
  --success: #15803d;
  --success-soft: #e9f8ef;
  --warning: #b45309;
  --warning-soft: #fff5e6;
  --danger: #dc2626;
  --danger-soft: #fdeced;
  --info-soft: #eef1ff;

  /* 二人の色(夫=藍緑 / 妻=薔薇)。性別記号ではなく区別用のトーン。 */
  --role-husband: #0d9488;
  --role-husband-soft: #e6f6f4;
  --role-wife: #db2777;
  --role-wife-soft: #fdeaf3;

  /* 形状・影 */
  --radius: 16px;
  --radius-sm: 11px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, .05), 0 1px 3px rgba(20, 24, 40, .06);
  --shadow-md: 0 6px 16px rgba(20, 24, 40, .09);
  --shadow-lg: 0 18px 40px rgba(20, 24, 40, .16);
  --ring: 0 0 0 3px rgba(79, 70, 229, .22);

  --maxw: 760px;
  --header-h: 60px;
  --bottomnav-h: 64px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", -apple-system,
    BlinkMacSystemFont, "Segoe UI", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 16px;
  letter-spacing: .01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(79, 70, 229, .18); }

/* ============================ ヘッダー(上) ============================ */
.site-header {
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.site-header .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 16px;
}
.site-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.18rem;
  letter-spacing: -.02em;
  color: var(--text);
  margin-right: auto;
  /* 日本語は文字間で改行されるため、幅が詰まるとブランド名が2行に折れる。固定して防ぐ。 */
  white-space: nowrap;
  flex-shrink: 0;
}
.site-header .brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #7c6cf0);
  color: #fff;
  font-size: .95rem;
  box-shadow: var(--shadow-sm);
}

/* デスクトップ用の文字ナビ(モバイルでは隠す) */
.top-nav { display: none; align-items: center; gap: 4px; }
.top-nav a {
  color: var(--text-soft);
  font-size: .92rem;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.top-nav a:hover { background: var(--surface-sunken); text-decoration: none; }
.top-nav a.is-active { color: var(--primary); background: var(--primary-soft); }

.header-actions { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.header-actions .who {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  max-width: 8em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

/* ============================ 本文 ============================ */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px calc(var(--bottomnav-h) + 28px);
}
@media (min-width: 720px) {
  main { padding-bottom: 40px; }
}

.page-head { margin: 4px 0 20px; }
h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.02em;
  margin: 0 0 4px;
  line-height: 1.3;
}
.page-head .sub, h1 + .muted { margin: 0; }
h2 {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin: 28px 0 12px;
}

/* ============================ カード ============================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
a.card, .card-link { transition: transform .12s ease, box-shadow .12s ease; }
a.card:hover, .card-link:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ============================ ボタン ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  line-height: 1.2;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  background-image: linear-gradient(135deg, #5b52ee, var(--primary-strong));
  color: var(--on-primary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: filter .12s ease, transform .06s ease, box-shadow .12s ease;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; color: var(--on-primary); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-secondary {
  background: var(--surface);
  background-image: none;
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--surface-sunken); filter: none; color: var(--text); }

.btn-danger { background: var(--danger); background-image: linear-gradient(135deg, #e7404a, #c81e1e); }
.btn-danger:hover { color: #fff; }
.btn-success { background: var(--success); background-image: linear-gradient(135deg, #1e9e4e, #137333); }
.btn-success:hover { color: #fff; }

.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 7px 13px; font-size: .85rem; border-radius: var(--radius-pill); }
.btn:disabled { opacity: .55; cursor: default; filter: none; transform: none; }

/* ============================ バッジ ============================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 11px;
  border-radius: var(--radius-pill);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
}
.badge-pending      { background: #eef0f4; color: #5b616e; }
.badge-done         { background: var(--success-soft); color: var(--success); }
.badge-needs_review { background: var(--warning-soft); color: var(--warning); }
.badge-failed       { background: var(--danger-soft);  color: var(--danger); }
.badge-duplicate    { background: #fff1e6; color: #c2410c; }
.badge-rejected     { background: #eef0f4; color: var(--muted); }
/* レシート状態ではない汎用バッジ(例: 世帯切替の「表示中」)。 */
.badge-active       { background: var(--success-soft); color: var(--success); }

/* ============================ フラッシュ ============================ */
.flash {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-weight: 600;
  font-size: .95rem;
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
}
.flash::before { font-size: 1.05em; line-height: 1.4; }
.flash-notice { background: var(--success-soft); color: #11663a; border-color: #bbe8cd; }
.flash-notice::before { content: "✓"; }
.flash-alert  { background: var(--danger-soft);  color: #a51c1c; border-color: #f5c6c9; }
.flash-alert::before  { content: "!"; font-weight: 800; }

/* ============================ フォーム ============================ */
form .field { margin-bottom: 16px; }
label {
  display: block;
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-soft);
  margin-bottom: 6px;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="month"], select, textarea {
  width: 100%;
  padding: 11px 13px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .12s ease, box-shadow .12s ease;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b909c' stroke-width='2.5' 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 12px center;
  padding-right: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
input[type="file"] { font-size: 1rem; }

/* ============================ テーブル ============================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th {
  font-size: .74rem;
  text-transform: none;
  letter-spacing: .02em;
  color: var(--muted);
  font-weight: 700;
  background: var(--surface-sunken);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--surface-sunken); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 「値の確認」用の縦並び定義テーブル(_values) */
.kv th {
  width: 38%;
  color: var(--muted);
  font-weight: 600;
  background: transparent;
  font-size: .85rem;
}
.kv td { font-weight: 600; }

/* 品目編集テーブル(レビューで金額・カテゴリを直す) */
.line-items td { vertical-align: middle; }
.line-items td input[type="text"],
.line-items td input[type="number"],
.line-items td select { padding: 8px 10px; font-size: .92rem; }
.line-items td.num input { width: 96px; text-align: right; }
.line-items tfoot td { border-top: 2px solid var(--border); border-bottom: none; }
.line-items .li-adj { background: var(--surface-sunken); }
.line-items .li-adj td:first-child { font-weight: 700; }
.del-check {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .72rem; font-weight: 700; color: var(--muted);
  white-space: nowrap; cursor: pointer;
}
.del-check input { width: 16px; height: 16px; accent-color: var(--danger); }

.amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.muted { color: var(--muted); }
.text-center { text-align: center; }

/* ============================ ダッシュボードの数値カード ============================ */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 16px 18px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--muted);
}
.stat--husband::before { background: var(--role-husband); }
.stat--wife::before    { background: var(--role-wife); }
.stat .label {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat--husband .label::before,
.stat--wife .label::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
}
.stat--husband .label::before { background: var(--role-husband); }
.stat--wife .label::before    { background: var(--role-wife); }
.stat .value {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* ============================ 精算ヒーロー ============================ */
.hero {
  position: relative;
  border-radius: var(--radius);
  padding: 26px 22px;
  margin-bottom: 16px;
  color: #fff;
  background: radial-gradient(120% 140% at 0% 0%, #6d63f0 0%, var(--primary) 42%, var(--primary-strong) 100%);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  text-align: center;
}
.hero::after {
  content: "";
  position: absolute;
  right: -40px; top: -60px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
}
.hero .hero-label {
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  opacity: .85;
  margin: 0 0 6px;
}
.hero .hero-flow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.02rem;
  font-weight: 700;
  margin-bottom: 6px;
  position: relative;
}
.hero .hero-flow .arrow { opacity: .75; }
.hero .hero-amount {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  position: relative;
}
.hero .hero-settled {
  font-size: 1.35rem;
  font-weight: 800;
  position: relative;
}
.hero--settled {
  background: radial-gradient(120% 140% at 0% 0%, #2bb673 0%, var(--success) 60%, #0f6b34 100%);
}
.hero-actions { margin-top: 6px; }
.hero-actions a { color: #fff; font-weight: 700; opacity: .92; }

/* ============================ レビュー: 画像と読取値 ============================ */
.review-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .review-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.review-image img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* レビュー待ちリスト項目 */
.review-item {
  display: flex;
  gap: 14px;
  align-items: center;
  color: inherit;
}
.review-item:hover { text-decoration: none; color: inherit; }
.review-item .thumb {
  width: 60px; height: 60px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.review-item .body { flex: 1; min-width: 0; }
.review-item .title-row {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700;
}
.review-item .title-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-item .meta { color: var(--muted); font-size: .86rem; }
.review-item .chev { color: var(--border-strong); flex-shrink: 0; }

/* 状態説明バー(レシート詳細)。対応要否で色を変え、要対応は左に色帯。 */
.status-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  border-left: 4px solid var(--border-strong);
}
.status-bar--action { border-left-color: var(--warning); background: var(--warning-soft); }
.status-bar--good   { border-left-color: var(--success); background: var(--success-soft); }
.status-bar--wait   { border-left-color: var(--primary);  background: var(--primary-soft); }
.status-bar--off    { border-left-color: var(--muted); }

/* ============================ 空状態 ============================ */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: .95rem;
}
.empty .emoji { font-size: 2.4rem; display: block; margin-bottom: 10px; }

/* ============================ アップロード ============================ */
.upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 38px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  text-align: center;
  cursor: pointer;
  margin-bottom: 14px;
  transition: border-color .12s ease, background .12s ease;
}
.upload-drop:hover { border-color: var(--primary); background: var(--primary-soft); }
.upload-drop:active { background: var(--primary-soft); }
.upload-drop-icon {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 1.7rem;
}
.upload-input { display: none; }
.upload-previews { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.upload-thumb {
  width: 84px; height: 84px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ============================ セグメント(状態フィルタ) ============================ */
.segmented {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px;
  background: var(--surface-sunken);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}
.segmented a {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: .86rem;
  font-weight: 700;
  color: var(--text-soft);
}
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ============================ ボトムナビ(モバイル) ============================ */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: .66rem;
  font-weight: 700;
}
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav a svg { width: 23px; height: 23px; }
.bottom-nav a.is-active { color: var(--primary); }

/* 中央の強調アクション(アップロード) */
.bottom-nav .nav-fab { position: relative; }
.bottom-nav .nav-fab .fab {
  display: grid;
  place-items: center;
  width: 50px; height: 50px;
  margin-top: -18px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b52ee, var(--primary-strong));
  color: #fff;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .45);
}
.bottom-nav .nav-fab .fab svg { width: 26px; height: 26px; }
.bottom-nav .nav-fab span { color: var(--muted); }

/* ============================ レスポンシブ切替 ============================ */
@media (min-width: 720px) {
  .top-nav { display: flex; }
  .bottom-nav { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================ 認証(ログイン) ============================ */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(90% 60% at 50% -10%, #e6e3ff 0%, transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  text-align: center;
}
.auth-brand .brand-mark { width: 52px; height: 52px; border-radius: 15px; font-size: 1.5rem; }
.auth-brand h1 { font-size: 1.5rem; margin: 0; }
.auth-brand p { margin: 0; color: var(--muted); font-size: .9rem; }
.auth-card .field { margin-bottom: 14px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: .9rem; }
