:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #b91c1c;
  --primary-dark: #991b1b;
  --primary-soft: #fef2f2;
  --green: #047857;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --danger: #dc2626;
  --radius: 18px;
  --shadow: 0 8px 28px rgba(31, 41, 55, .08);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 58px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--border); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.02em; }
.icon-button { border: 0; background: transparent; font-size: 22px; color: var(--muted); padding: 8px; }
.inline-form { margin: 0; }
.page-shell { width: min(100%, 900px); margin: 0 auto; padding: 20px 14px 104px; }
.centered-shell { min-height: calc(100vh - 58px); display: grid; place-items: center; padding-bottom: 30px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(1.45rem, 4vw, 2rem); line-height: 1.2; margin-bottom: 4px; letter-spacing: -.03em; }
h2 { font-size: 1.08rem; margin-bottom: 0; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 3px 14px rgba(31,41,55,.04); }
.auth-card { width: min(100%, 420px); padding: 28px 22px; text-align: center; }
.hero-icon { font-size: 46px; margin-bottom: 6px; }
.stack-form { display: grid; gap: 15px; text-align: left; }
.form-card { padding: 18px; }
label, .field-label { display: grid; gap: 7px; font-weight: 700; font-size: .9rem; }
input, select, textarea {
  width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 12px 13px; background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(185,28,28,.1); }
textarea { resize: vertical; }
.required { color: var(--danger); }
.help { color: var(--muted); font-weight: 500; line-height: 1.45; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent; border-radius: 12px;
  padding: 12px 16px; font-weight: 800; min-height: 44px;
}
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.button.ghost { background: transparent; border-color: var(--border); }
.button.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.button.compact { min-height: 38px; padding: 8px 11px; font-size: .86rem; }
.button.full { width: 100%; }
.alert { border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; line-height: 1.5; }
.alert.error { color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; }
.alert.success { color: #065f46; background: #ecfdf5; border: 1px solid #a7f3d0; }
.alert ul { margin: 5px 0 0 18px; padding: 0; }
.summary-card { border-radius: 24px; padding: 20px; color: #fff; background: linear-gradient(140deg, #991b1b, #dc2626); box-shadow: var(--shadow); margin-bottom: 14px; }
.summary-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.summary-top span { opacity: .85; font-size: .86rem; }
.summary-top strong { display: block; font-size: clamp(1.8rem, 8vw, 2.7rem); line-height: 1.1; margin-top: 5px; letter-spacing: -.04em; }
.summary-top strong small { font-size: .8rem; letter-spacing: 0; }
.pill { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.2); border-radius: 999px; padding: 6px 9px; white-space: nowrap; }
.budget-row { display: flex; justify-content: space-between; gap: 10px; font-size: .78rem; margin: 16px 0 7px; }
.progress { height: 7px; border-radius: 99px; background: rgba(255,255,255,.25); overflow: hidden; }
.progress span { display: block; height: 100%; background: #fff; border-radius: inherit; }
.summary-card .text-link { display: inline-block; margin-top: 15px; color: #fff; font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.stat { padding: 15px; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat strong { display: block; font-size: 1.25rem; margin-top: 4px; }
.stat small { color: var(--muted); }
.section-block { margin-top: 24px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-title a { color: var(--primary); font-size: .85rem; font-weight: 800; }
.balance-list { overflow: hidden; }
.balance-row { display: flex; align-items: center; gap: 10px; padding: 13px; border-bottom: 1px solid var(--border); }
.balance-row:last-child { border-bottom: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 900; flex: 0 0 auto; }
.grow { min-width: 0; flex: 1; }
.grow strong, .grow small { display: block; }
.grow strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow small { color: var(--muted); font-size: .75rem; margin-top: 3px; line-height: 1.35; }
.balance-amount { text-align: right; font-weight: 900; }
.balance-amount small { display: block; color: var(--muted); font-size: .68rem; font-weight: 600; }
.positive { color: var(--green) !important; }
.negative { color: var(--danger) !important; }
.settlement-suggestions { display: grid; gap: 7px; margin-top: 9px; }
.settlement-suggestions div { border: 1px dashed #f59e0b; background: #fffbeb; border-radius: 12px; padding: 10px 12px; font-size: .83rem; }
.settlement-suggestions strong { display: block; margin-top: 3px; color: var(--amber); }
.category-card { padding: 14px; }
.category-row + .category-row { margin-top: 13px; }
.category-label { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 7px; margin-bottom: 7px; }
.category-label em { font-style: normal; font-weight: 800; font-size: .82rem; }
.mini-progress { height: 6px; background: #f3f4f6; border-radius: 99px; overflow: hidden; }
.mini-progress span { display: block; height: 100%; background: var(--primary); border-radius: inherit; min-width: 3px; }
.expense-cards { display: grid; gap: 9px; }
.expense-card { display: flex; align-items: center; gap: 11px; padding: 12px; transition: transform .15s ease, border-color .15s ease; }
.expense-card:hover { transform: translateY(-1px); border-color: #d1d5db; }
.expense-icon { width: 40px; height: 40px; border-radius: 13px; background: #f9fafb; display: grid; place-items: center; font-size: 20px; flex: 0 0 auto; }
.expense-money { text-align: right; }
.expense-money b, .expense-money small { display: block; }
.expense-money small { color: var(--muted); font-size: .7rem; }
.participants { color: var(--primary) !important; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.simple-list { overflow: hidden; }
.simple-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 9px; padding: 12px 13px; border-bottom: 1px solid var(--border); }
.simple-row:last-child { border-bottom: 0; }
.link-danger, .link-button { border: 0; background: transparent; color: var(--danger); font-weight: 700; padding: 4px; }
.filter-card { padding: 12px; margin-bottom: 13px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 8px; }
.export-links { display: flex; gap: 18px; margin: 18px 2px; font-size: .85rem; font-weight: 700; color: var(--primary); }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: .9rem; font-weight: 700; margin-bottom: 7px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented label { display: block; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 11px; border: 1px solid var(--border); border-radius: 12px; text-align: center; background: #fff; }
.segmented input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.check-card { display: block; }
.check-card input { position: absolute; opacity: 0; pointer-events: none; }
.check-card span { display: block; text-align: center; padding: 10px; border-radius: 11px; border: 1px solid var(--border); background: #fff; }
.check-card input:checked + span { background: var(--green-soft); border-color: #34d399; color: var(--green); font-weight: 800; }
.money-box { padding: 13px; border-radius: 14px; background: #f9fafb; border: 1px solid var(--border); display: grid; gap: 12px; }
.amount-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scan-preview { display: grid; grid-template-columns: 90px 1fr; gap: 13px; padding: 12px; margin-bottom: 14px; }
.scan-preview img { width: 90px; height: 110px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.scan-preview p { color: var(--muted); font-size: .78rem; line-height: 1.45; margin: 4px 0; }
.scan-preview details { font-size: .76rem; }
.scan-preview pre { max-height: 220px; overflow: auto; white-space: pre-wrap; background: #f9fafb; padding: 8px; border-radius: 8px; }
.danger-zone { margin-top: 14px; }
.camera-card { padding: 24px 18px; text-align: center; }
.camera-icon { font-size: 54px; }
.camera-card h2 { margin: 8px 0; }
.camera-card p { color: var(--muted); line-height: 1.6; font-size: .9rem; }
.file-picker input { position: absolute; opacity: 0; pointer-events: none; }
.file-picker span { display: block; text-align: center; border: 2px dashed #fca5a5; background: var(--primary-soft); color: var(--primary); border-radius: 15px; padding: 22px 12px; font-size: 1rem; }
.tip-card { margin-top: 12px; padding: 13px 15px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 14px; }
.tip-card p { margin: 4px 0 0; color: #92400e; font-size: .82rem; line-height: 1.5; }
.traveler-row { display: flex; align-items: center; gap: 10px; padding: 12px; border-bottom: 1px solid var(--border); }
.traveler-row:last-child { border-bottom: 0; }
.status { font-size: .68rem; padding: 4px 7px; background: var(--green-soft); color: var(--green); border-radius: 99px; font-weight: 800; }
.status.inactive { background: #f3f4f6; color: var(--muted); }
.text-link { color: var(--primary); font-weight: 800; font-size: .82rem; }
.settings-links { margin-top: 16px; overflow: hidden; }
.settings-links a { display: flex; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: .88rem; }
.settings-links a:last-child { border-bottom: 0; }
.bottom-nav {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: rgba(255,255,255,.96); border-top: 1px solid var(--border); backdrop-filter: blur(16px);
}
.bottom-nav a { display: grid; place-items: center; gap: 2px; color: var(--muted); min-height: 50px; }
.bottom-nav a span { font-size: 20px; line-height: 1; }
.bottom-nav a small { font-size: .66rem; font-weight: 700; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .nav-add span { width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; margin-top: -19px; box-shadow: 0 7px 18px rgba(185,28,28,.28); }

@media (min-width: 720px) {
  .page-shell { padding: 28px 24px 110px; }
  .summary-card { padding: 26px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .checkbox-grid { grid-template-columns: repeat(4, 1fr); }
  .form-card { padding: 24px; }
  .expense-cards { grid-template-columns: 1fr 1fr; }
  .filter-card { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
  .filter-row { margin-top: 0; }
}
@media (max-width: 420px) {
  .two-col { grid-template-columns: 1fr; }
  .filter-row { grid-template-columns: 1fr 1fr; }
  .filter-row .button { grid-column: 1 / -1; }
  .quick-actions { grid-template-columns: 1fr; }
  .traveler-row { flex-wrap: wrap; }
}
