/* =====================================================================
   여행가계부 스타일 — 모바일 우선, 768px 이상은 PC 배치 (기본 설계서 3장)
   ===================================================================== */
:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1d2330; --sub: #6b7280; --line: #e5e7eb;
  --pri: #2563eb; --pri-soft: #eef2ff; --plus: #059669; --minus: #dc2626; --warn: #b45309;
  --radius: 12px; --tap: 44px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
       background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; padding-bottom: 72px; }
a { color: var(--pri); text-decoration: none; }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 15px; margin: 0 0 12px; }
code { background: #f1f5f9; padding: 1px 4px; border-radius: 4px; }

/* 레이아웃 */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; }
.top-right { display: flex; align-items: center; gap: 10px; }
.logout-link { font-size: 13px; color: var(--sub); }
.login-wrap { max-width: 360px; margin: 10vh auto 0; }
.login-wrap h2 { margin-top: 0; }
.user-chip { background: var(--pri-soft); color: var(--pri); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.brand { font-weight: 700; color: var(--ink); }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.footer { text-align: center; padding: 16px; font-size: 12px; color: var(--sub); }
.footer .warn, #ping.warn { color: var(--minus); font-weight: 600; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card.narrow { max-width: 560px; }
.empty { text-align: center; }
.muted { color: var(--sub); } .small { font-size: 13px; } .pad { padding: 16px; }
.err { color: var(--minus); font-size: 13px; min-height: 1em; margin: 8px 0 0; }
.warn { color: var(--warn); }
.plus { color: var(--plus); font-weight: 700; } .minus { color: var(--minus); font-weight: 700; }

/* 입력 */
label { display: block; font-size: 13px; color: var(--sub); }
input, select { display: block; width: 100%; margin-top: 4px; padding: 10px; min-height: var(--tap);
                border: 1px solid var(--line); border-radius: 8px; font-size: 16px; background: #fff; color: var(--ink); }
input[type=radio], input[type=checkbox] { display: inline-block; width: auto; min-height: 0; margin: 0 4px 0 0; }
.form > * + * { margin-top: 12px; }
.form-title { display: flex; justify-content: space-between; align-items: center; }
.form-title h2 { margin: 0; }
.row { display: flex; gap: 8px; align-items: flex-end; } .row > * { flex: 1; } .row > .grow { flex: 2; }
.row > .btn { flex: 0 0 auto; }
.label-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--sub); margin-bottom: 6px; }

/* 버튼 */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 16px;
       border: 0; border-radius: 8px; background: var(--pri); color: #fff; font-size: 15px; cursor: pointer; white-space: nowrap; }
.btn.ghost { background: var(--pri-soft); color: var(--pri); }
.btn.danger { background: #fef2f2; color: var(--minus); }
.btn.full { width: 100%; } .btn.grow { flex: 1; }
.btn:disabled { opacity: .5; cursor: default; }
.small-btn { min-height: 34px; padding: 0 12px; font-size: 13px; }
.link-btn { background: none; border: 0; color: var(--pri); cursor: pointer; padding: 6px 0; font-size: 13px; }
.icon-btn { background: rgba(0,0,0,.55); color: #fff; border: 0; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; font-size: 16px; line-height: 1; }
.chip-btn { background: rgba(255,255,255,.9); border: 0; border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.tag { display: inline-block; background: var(--pri-soft); color: var(--pri); border-radius: 6px; padding: 1px 6px; font-size: 12px; }
.tag.personal { background: #fff7ed; color: var(--warn); } .tag.ghost { background: #f3f4f6; color: var(--sub); }
.seg { display: flex; gap: 8px; } .seg label { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--ink); font-size: 14px; cursor: pointer; }
.small-seg label { padding: 6px 10px; flex: 0 0 auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; color: var(--ink); font-size: 14px; cursor: pointer; }

/* S1 여행 목록 */
.add-link { display: flex; gap: 8px; align-items: center; }
.add-link input { margin: 0; }
.trip-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.trip-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.trip-card-body { padding: 12px 16px; } .trip-card h2 { margin: 0 0 4px; }
.trip-card .amt { margin: 6px 0 0; font-weight: 700; }
.hide-btn { position: absolute; top: 8px; right: 8px; }
.card-cover, .trip-cover { aspect-ratio: 16 / 9; background-size: cover; background-position: center; }
.cover-empty { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 40px; font-weight: 700; }
.cover-preview { max-width: 360px; border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.who-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 12px 0; }
.add-row input { margin: 0; }

/* 여행 화면 */
.trip-head { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; background: #111; }
.trip-head .trip-cover { aspect-ratio: auto; height: 140px; opacity: .85; }
.trip-head-text { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 16px; color: #fff;
                  background: linear-gradient(transparent, rgba(0,0,0,.65)); }
.trip-head-text p { margin: 2px 0 0; font-size: 13px; opacity: .9; }
.trip-head #meBtn { position: absolute; top: 10px; right: 10px; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line);
        padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; text-align: center; padding: 14px 0; color: var(--sub); font-size: 14px; min-height: var(--tap); }
.tabs a.on { color: var(--pri); font-weight: 700; }
.total-card { display: flex; justify-content: space-between; align-items: center; }
.total-card strong, .stat-head strong { display: block; font-size: 22px; }
.day-group { margin-bottom: 12px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 4px 6px; font-weight: 600; }
.exp-item { display: flex; width: 100%; text-align: left; gap: 8px; justify-content: space-between; background: var(--card); border: 1px solid var(--line);
            border-radius: 10px; padding: 12px; margin-bottom: 6px; cursor: pointer; font: inherit; color: inherit; min-height: var(--tap); }
.exp-item.active { border-color: var(--pri); box-shadow: 0 0 0 1px var(--pri); }
.exp-title { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.exp-amt { text-align: right; white-space: nowrap; display: flex; flex-direction: column; }
.col-pc { display: none; }
.fab { position: fixed; right: 20px; bottom: 80px; z-index: 15; width: 56px; height: 56px; border-radius: 50%; background: var(--pri); color: #fff;
       font-size: 30px; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(37,99,235,.4); }
.rate-box { background: #f8fafc; border-radius: 8px; padding: 10px; }
.rate-box p { margin: 6px 0 0; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.thumb { position: relative; width: 88px; height: 88px; border-radius: 8px; overflow: hidden; background: #f3f4f6; display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .icon-btn { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; font-size: 14px; }
.thumb .badge { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 10px; text-align: center; }

/* 모바일: S4는 목록만, S5는 폼만 */
.split:not(.editing) .form-pane { display: none; }
.split.editing .list-pane, .split.editing ~ .fab { display: none; }

/* 통계·정산 */
.stat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 76px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--pri); border-radius: 6px; }
.bar-val { text-align: right; white-space: nowrap; }
.line { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.line:first-of-type { border-top: 0; }
.line-right { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.cat-list { list-style: none; padding: 0; margin: 0 0 12px; }
.cat-list li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 50; max-width: 90vw; }

/* ===== PC (768px 이상) ===== */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .trip-grid { grid-template-columns: repeat(3, 1fr); }
  .trip-head .trip-cover { height: 200px; }
  .trip-layout { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: start; }
  .tabs { position: sticky; top: 64px; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
  .tabs a { text-align: left; padding: 10px 12px; border-radius: 8px; }
  .tabs a.on { background: var(--pri-soft); }
  .split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
  .split:not(.editing) .form-pane, .split.editing .list-pane { display: block; }
  .form-pane { position: sticky; top: 64px; }
  .fab { display: none; }
  .col-pc { display: block; }
  .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-grid .card:first-child { grid-column: 1 / -1; }
  .settle-grid, .settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .toast { bottom: 24px; }
  .btn:hover { filter: brightness(.95); }
  .exp-item:hover { border-color: #c7d2fe; }
}

/* 확인 대화상자 */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--card); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 400px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal-msg { color: var(--sub); font-size: 14px; margin-bottom: 12px; line-height: 1.5; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.btn.danger-solid { background: var(--minus); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
/* 사용자 목록 (선택 + 삭제) */
.user-item { position: relative; }
.user-item > .btn { width: 100%; }
.user-del { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; font-size: 13px; }
.danger-card h2 { color: var(--minus); }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; cursor: pointer; }
.check-row input { width: auto; margin: 0; }
