:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --line: #e6e8ef;
  --text: #1e2233;
  --muted: #7c8296;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --danger: #ef4444;
  --ok: #10b981;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 25, 60, .06), 0 6px 20px rgba(20, 25, 60, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1b1e29;
    --line: #2c3040;
    --text: #eef0f7;
    --muted: #9aa1b7;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

/* ---------------- app bar / tabs ---------------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.appbar h1 { font-size: 18px; margin: 0; white-space: nowrap; }

.tabs-top { display: none; gap: 4px; }
.tabs-top .tab {
  border: none; background: none; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tabs-top .tab:hover { background: var(--bg); }
.tabs-top .tab.active { background: var(--primary); color: #fff; }

.tabs-bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-bottom .tab {
  border: none; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 1px 7px; font-size: 9.5px; cursor: pointer; overflow: hidden;
}
.tabs-bottom .tab .tab-icon { font-size: 18px; }
@media (max-width: 380px) {
  .tabs-bottom .tab { font-size: 8.5px; letter-spacing: -.3px; }
  .tabs-bottom .tab .tab-icon { font-size: 17px; }
}
.tabs-bottom .tab .tab-icon { font-size: 19px; line-height: 1; }
.tabs-bottom .tab.active { color: var(--primary); }

/* タブ名（カスタマイズ可能）。長い名前を入れても崩れないよう省略表示にする */
.tab-label {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tabs-bottom .tab .tab-label { max-width: calc(100% - 4px); }

@media (min-width: 760px) {
  .tabs-top { display: flex; }
  .tabs-bottom { display: none; }
}

/* ---------------- layout ---------------- */
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 14px calc(78px + env(safe-area-inset-bottom));
}
@media (min-width: 760px) { main { padding-bottom: 40px; } }

.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .cards { grid-template-columns: repeat(4, 1fr); } }
.stat { padding: 14px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 11px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; }
.stat.warn .stat-value { color: var(--danger); }

/* ---------------- forms ---------------- */
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.row > input, .row > select { flex: 1 1 140px; min-width: 0; }
.w-sm { flex: 0 1 120px !important; }
.w-color { flex: 0 0 48px !important; padding: 2px; height: 40px; }
.lbl { font-size: 12px; color: var(--muted); flex: 0 0 66px; }

input, select, textarea {
  font: inherit; font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
  min-height: 42px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

button {
  font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 10px; border: 1px solid transparent;
  padding: 10px 16px; cursor: pointer; min-height: 42px;
}
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
button.ghost:hover { background: var(--bg); }
button.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button {
  border: none; border-radius: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; min-height: 32px; font-size: 12px;
}
.seg button.active { background: var(--primary); color: #fff; }

/* ---------------- lists ---------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: none; }
.list .empty { color: var(--muted); font-size: 13px; justify-content: center; padding: 22px 0; }

/* カテゴリ別グループ */
.cat-group + .cat-group { margin-top: 14px; }
.cat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 0 2px; padding: 6px 10px;
  font-size: 12.5px; font-weight: 700;
  background: var(--bg); border-radius: 8px;
  position: sticky; top: 0;
}
.cat-count { font-size: 11px; font-weight: 600; color: var(--muted); }
.cat-group .list li { padding-left: 4px; }

/* 設定画面のメンバー名インライン編集 */
.name-edit {
  flex: 1 1 auto; min-width: 0;
  background: transparent; border-color: transparent;
  font-weight: 600;
}
.name-edit:hover { border-color: var(--line); background: var(--bg); }
.name-edit:focus { border-color: var(--primary); background: var(--bg); }

/* タブ設定リストのアイコン表示（変更不可・目印用） */
.tab-icon-preview { flex: 0 0 auto; font-size: 17px; line-height: 1; }

.check {
  flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent; padding: 0; min-height: 0;
  cursor: pointer; display: grid; place-items: center; color: transparent; font-size: 13px;
}
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }

.item-main { flex: 1 1 auto; min-width: 0; }
.item-title { font-size: 15px; word-break: break-word; }
.item-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.done .item-title { text-decoration: line-through; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--line);
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.overdue { color: var(--danger); font-weight: 700; }
.chip.fx-chip { background: #eef2ff; color: #4338ca; border-color: #e0e7ff; }

/* 立替フォーム：かんたん／こだわり の切り替えと、こだわり欄の余白 */
.expense-detail { margin-top: 4px; }
.expense-detail.hidden { display: none; }
#expense-currency-other { flex: 0 0 90px !important; }

.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.del {
  background: none; border: none; color: var(--muted); font-size: 17px;
  padding: 4px 6px; min-height: 0; line-height: 1;
}
.del:hover { color: var(--danger); }

/* ---------------- settlement ---------------- */
.settle-box { display: flex; flex-direction: column; gap: 10px; }
.settle-result {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; border-radius: 12px; padding: 16px; text-align: center;
}
.settle-result .big { font-size: 26px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.settle-result.even { background: linear-gradient(135deg, #10b981, #059669); }
.settle-result.closed { background: linear-gradient(135deg, #64748b, #475569); }

.balance-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; gap: 8px; }
.balance-row .nums { color: var(--muted); font-variant-numeric: tabular-nums; }

/* 月次精算カード全体の開閉トグル（頻繁に見ない人向けに、既定で閉じておく） */
.settle-toggle summary {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 700; /* .card h2 と揃える */
}
.settle-toggle summary::-webkit-details-marker { display: none; }
.settle-toggle summary::after { content: '▾'; color: var(--muted); font-weight: 400; margin-left: 8px; }
.settle-toggle[open] summary::after { content: '▴'; }
.settle-toggle[open] summary { margin-bottom: 12px; }
.settle-toggle > div, .settle-toggle > .row { margin-top: 10px; }

.month-bar { display: flex; align-items: center; gap: 8px; padding: 10px; }
.month-bar input { flex: 1; text-align: center; }
.month-bar button { flex: 0 0 44px; padding: 0; font-size: 20px; }

.shares { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.shares .row { margin: 0; }
.shares input[type=number] { flex: 0 0 90px; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.muted.small { font-size: 12px; line-height: 1.6; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* 担当を使わない設定のとき、担当の選択欄を隠す（APP_CONFIG.showAssignees） */
body.no-assignee .assignee-field { display: none !important; }

/* ---------------- つくりたいごはん ---------------- */
.recipe-list li { align-items: flex-start; }
.recipe-thumb { width: 76px; height: 56px; object-fit: cover; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.item-actions button { padding: 5px 10px; min-height: 30px; font-size: 12px; }

.chip.src-youtube { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.chip.src-instagram { background: #fce7f3; color: #9d174d; border-color: #fbcfe8; }
.chip.src-tiktok { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }

.unit { flex: 0 0 auto; font-size: 13px; color: var(--muted); }
.shares .lbl { flex: 0 0 auto; min-width: 80px; display: flex; align-items: center; gap: 5px; }

/* ---------------- 編集ダイアログ ---------------- */
.editor-card {
  width: 100%; max-width: 440px; margin: 0;
  max-height: 88vh; overflow-y: auto;
}
.edit-field { margin-bottom: 10px; }
.edit-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.edit-field input, .edit-field select, .edit-field textarea { width: 100%; }
.editor-actions { margin: 14px 0 0; }
.editor-actions button { flex: 1 1 auto; }

.edit {
  flex: 0 0 auto; background: none; border: none;
  font-size: 15px; padding: 4px 6px; min-height: 0; line-height: 1; opacity: .65;
}
.edit:hover { opacity: 1; }

.item-note {
  font-size: 12.5px; color: var(--muted); margin-top: 2px;
  white-space: pre-wrap; word-break: break-word;
}
.chip.link { text-decoration: none; color: var(--primary); border-color: var(--primary); }
.chip.link:hover { background: var(--primary); color: #fff; }

.extra { margin-top: 6px; }
.extra summary { cursor: pointer; padding: 4px 0; }
.extra > .row { margin-top: 8px; }

/* ---------------- ファイル共有 ---------------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: 12px;
  padding: 22px 14px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  font-size: 13px; margin-bottom: 10px; transition: .15s;
}
.dropzone:hover { border-color: var(--primary); background: var(--bg); }
.dropzone.over { border-color: var(--primary); background: var(--bg); transform: scale(1.01); }
.drop-icon { font-size: 30px; line-height: 1; }

/* 精算フォームのレシート貼り付け欄はコンパクトに（ファイル共有タブの大きい版とは別扱い） */
.receipt-drop {
  flex-direction: row; justify-content: flex-start; text-align: left;
  padding: 8px 12px; gap: 8px; font-size: 12.5px; margin-bottom: 8px;
}
.receipt-drop .drop-icon { font-size: 16px; }

.thumb-link { flex: 0 0 auto; display: block; }
.thumb {
  width: 46px; height: 46px; border-radius: 8px; object-fit: cover;
  background: var(--bg); border: 1px solid var(--line); display: block;
}
.thumb.icon { display: grid; place-items: center; font-size: 22px; }
a.dl {
  flex: 0 0 auto; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 12px; font-size: 13px; font-weight: 600;
}
a.dl:hover { background: var(--bg); }

.up-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-top: 6px; }
.up-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-row .meter { flex: 0 0 90px; margin: 0; }
.up-pct { flex: 0 0 34px; text-align: right; color: var(--muted); }

/* ---------------- 容量アラート ---------------- */
.banner {
  position: sticky; top: 0; z-index: 19;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; font-size: 13px; line-height: 1.5;
  background: #fef3c7; color: #92400e; border-bottom: 1px solid #fde68a;
}
.banner.critical { background: #fee2e2; color: #991b1b; border-bottom-color: #fecaca; }
.banner button { margin-left: auto; flex: 0 0 auto; background: rgba(255, 255, 255, .6); }

.metric { margin-bottom: 12px; }
.metric-head { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.meter {
  height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-bottom: 4px;
}
.meter i { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.meter i.warning { background: #f59e0b; }
.meter i.critical { background: var(--danger); }

.sub-head { font-size: 12px; color: var(--muted); margin: 14px 0 4px; }
#data-info code { word-break: break-all; }

/* ---------------- リクエストボード ---------------- */
.req { align-items: flex-start; }
.req-detail { font-size: 13px; color: var(--muted); margin-top: 3px; white-space: pre-wrap; word-break: break-word; }

.vote {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 40px; min-height: 42px; padding: 4px 6px; font-size: 10px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}
.vote b { font-size: 14px; color: var(--text); }
.vote:hover { border-color: var(--primary); color: var(--primary); }

.status-sel {
  flex: 0 0 auto; min-height: 34px; padding: 5px 8px;
  font-size: 11.5px; font-weight: 700; border-radius: 999px;
  border: 1px solid var(--line);
}
.status-sel.st-new { background: var(--bg); }
.status-sel.st-planned { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.status-sel.st-doing { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.status-sel.st-done { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.status-sel.st-rejected { background: var(--bg); color: var(--muted); }

textarea { width: 100%; resize: vertical; font-family: inherit; }
.row > textarea { flex: 1 1 100%; }

/* ---------------- ログイン画面 ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: grid; place-items: center; padding: 20px;
}
.login-card { width: 100%; max-width: 360px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.login-card h2 { margin: 0; font-size: 20px; text-align: center; }
.login-card input, .login-card button { width: 100%; }
#login-error:empty { display: none; }
#login-error { color: var(--danger); text-align: center; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 20px);
  background: #1e2233; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ============================================================
 * 🧳 旅行タブ（Wanderlogの旅程を見る）— Wanderlog風の見た目
 * 色・角丸・フォントは wanderlog.com の実際のCSSから採取した値を採用。
 * 他のタブには影響しない（#view-wanderlog にスコープ）。
 * ============================================================ */
#view-wanderlog {
  --wl-primary: #3f52e3;
  --wl-primary-dark: #2e3a87;
  --wl-primary-tint: #ebedfc;
  --wl-primary-tint-text: #2e3a87;
  --wl-line: #dee2e6;
  --wl-muted: #6c757d;
  --wl-text: #212529;
  --wl-yellow-tint: #fdf5eb;
  --wl-yellow-tint-text: #8a5a1a;
  --wl-purple-tint: #e2daef;
  --wl-purple-tint-text: #5a378c;
  --wl-green: #17b978;
  font-family: Roboto, "Noto Sans JP", system-ui, sans-serif;
}
/* ダークモードでも読める配色に切り替える（淡色タイントは背景色だけ濃く・文字色を明るく） */
@media (prefers-color-scheme: dark) {
  #view-wanderlog {
    --wl-primary: #7c8cf0;
    --wl-primary-dark: #98a5f5;
    --wl-primary-tint: rgba(63, 82, 227, .28);
    --wl-primary-tint-text: #c7cffa;
    --wl-line: var(--line);
    --wl-muted: var(--muted);
    --wl-text: var(--text);
    --wl-yellow-tint: rgba(236, 155, 59, .22);
    --wl-yellow-tint-text: #f0c987;
    --wl-purple-tint: rgba(122, 78, 184, .3);
    --wl-purple-tint-text: #ddc8f5;
  }
}
#view-wanderlog h2 { color: var(--wl-text); font-weight: 700; }
#view-wanderlog .card {
  border-radius: 8px;
  box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .08);
  border: 1px solid var(--wl-line);
}
#view-wanderlog input[type="url"] {
  border-radius: 999px;
  border-color: var(--wl-line);
  padding-left: 16px;
}
#view-wanderlog button#wanderlog-load {
  background: var(--wl-primary);
  border-radius: 999px;
  font-weight: 700;
}
#view-wanderlog button#wanderlog-load:hover { background: var(--wl-primary-dark); }

/* 移動のタイムライン・日ごとの一覧を、縦線でつないだタイムライン表示にする */
.wl-timeline { position: relative; list-style: none; margin: 0; padding: 4px 0 4px 26px; }
.wl-timeline::before {
  content: ''; position: absolute; left: 9px; top: 4px; bottom: 4px; width: 2px;
  background: var(--wl-line);
}
.wl-timeline > li { position: relative; padding: 8px 0; }
.wl-timeline > li::before {
  content: ''; position: absolute; left: -26px; top: 14px; width: 8px; height: 8px;
  border-radius: 50%; background: #fff; border: 2px solid var(--wl-primary); z-index: 1;
}
.wl-timeline > li.wl-note::before { border-color: var(--wl-muted); }
.wl-timeline > li.wl-transit::before { border-color: var(--wl-green); background: var(--wl-green); }

/* 日付・区間見出し（丸バッジ付き） */
.wl-day-head { display: flex; align-items: center; gap: 10px; }
.wl-day-badge {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  background: var(--wl-primary); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}

/* 移動手段バッジ（「🚌 公共交通機関で」等） */
.wl-travel-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--wl-primary-tint); color: var(--wl-primary-tint-text);
  padding: 3px 12px; border-radius: 999px; font-size: 11px; font-weight: 700;
}

/* 移動（フライト・電車）カード：区間を大きめの矢印でつなぐ */
.wl-transit-route { font-size: 15px; font-weight: 700; color: var(--wl-text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wl-transit-arrow { color: var(--wl-primary); }
.wl-transit-time { display: inline-flex; align-items: center; gap: 4px; background: var(--wl-yellow-tint); color: var(--wl-yellow-tint-text); padding: 3px 12px; border-radius: 999px; font-size: 11px; font-weight: 700; }

/* 宿泊バッジ（チェックイン〜チェックアウト） */
.wl-stay-badge { background: var(--wl-purple-tint); color: var(--wl-purple-tint-text); padding: 3px 12px; border-radius: 999px; font-size: 11px; font-weight: 700; }

/* メモ（note）はやわらかい黄色背景のカードで目立たせる */
.wl-timeline .wl-note .item-note {
  background: var(--wl-yellow-tint); border-radius: 8px; padding: 8px 12px; color: var(--wl-text);
}
