:root{
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-10: rgba(37,99,235,.12);
  --green: #059669;
  --red: #dc2626;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

*{ box-sizing: border-box; }
html,body{
  margin:0; padding:0;
  font-family: ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,"Apple Color Emoji","Segoe UI Emoji";
  color:var(--text); background:var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

.wrap{ max-width:1100px; margin:0 auto; padding:0 20px; }

.app-header{
  background:
    radial-gradient(1200px 400px at 20% -20%, rgba(37,99,235,.18), transparent 60%),
    radial-gradient(1200px 400px at 80% 0%, rgba(99,102,241,.14), transparent 60%),
    linear-gradient(180deg,#eef4ff,transparent);
  border-bottom:1px solid var(--line);
}
.app-header .wrap{ padding:48px 20px 36px; }
h1{ margin:0 0 6px; font-size:30px; letter-spacing:.2px; }
.subtitle{ margin:0; color:var(--muted); max-width:800px; line-height:1.6; }

main .wrap{ padding-top:24px; padding-bottom:64px; }

.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:22px;
  margin:18px 0;
}
.card-head{ margin-bottom:12px; }
h2{ margin:0 0 4px; font-size:21px; }
.h3{ margin:0 0 10px; font-size:18px; }

.muted{ color:var(--muted); }
.center{ text-align:center; }
.mt-lg{ margin-top:28px; }

.row{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.row.space-between{ justify-content:space-between; }
.gap{ gap:10px; }
.grid-2{ display:grid; grid-template-columns:1fr 1fr; }
.grid-3{ display:grid; grid-template-columns:repeat(3,1fr); }
.grid-2, .grid-3{ gap:14px; }
@media (max-width:900px){ .grid-2,.grid-3{ grid-template-columns:1fr; } }

.field{ display:flex; flex-direction:column; gap:6px; }
.label{ font-size:13px; color:var(--muted); }

.input, select{
  width:100%; padding:11px 12px;
  border:1px solid var(--line); border-radius:12px; background:#fff; font-size:14px;
  transition: box-shadow .2s ease, border-color .2s ease, transform .02s ease;
}
.input:focus, select:focus{
  outline:none; border-color:var(--primary); box-shadow:0 0 0 6px var(--primary-10);
}

.btn{
  appearance:none; border:none; background:var(--primary); color:#fff;
  padding:10px 14px; border-radius:12px; cursor:pointer; box-shadow:var(--shadow);
  transition: filter .15s ease, transform .08s ease, box-shadow .15s ease;
  font-weight:600;
}
.btn:hover{ filter:brightness(.98); }
.btn:active{ transform:translateY(1px); }
.btn:disabled{ opacity:.5; cursor:not-allowed; }
.btn-ghost{
  background:#3dffa4; color:var(--text); border:1px solid var(--line);
}
.btn-ghost:hover{ background:#f8fafc; }

.chips{ display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; }
.chip{
  background:#f8fafc; border:1px solid var(--line); padding:7px 10px;
  border-radius:999px; display:flex; align-items:center; gap:8px;
}
.chip .x{
  background:#fff; border:1px solid var(--line); border-radius:8px; padding:2px 6px; cursor:pointer;
  transition: background .15s ease;
}
.chip .x:hover{ background:#f1f5f9; }

.checks{
  display:flex; gap:10px; flex-wrap:wrap; background:#f8fafc; border:1px dashed var(--line);
  padding:12px; border-radius:12px;
}
.check{
  display:flex; align-items:center; gap:8px; padding:6px 10px; background:#fff; border:1px solid var(--line); border-radius:10px;
  transition: background .15s ease, border-color .15s ease;
}
.check:hover{ background:#f9fafb; border-color:#dbe2ea; }

.table-wrap{
  width:100%; overflow:auto; border:1px solid var(--line); border-radius:12px; background:#fff;
}
.table{
  width:100%; border-collapse:collapse; min-width:720px;
}
.table th, .table td{
  border-bottom:1px solid var(--line); padding:11px 12px; text-align:left; vertical-align:top; font-size:16px;
}
.table th{
  background:#f8fafc; font-weight:700; color:#0f172a;
}
.table tr:last-child td{ border-bottom:none; }

.table tfoot td{
  background:#f8fafc; font-weight:700; border-top:2px solid var(--line);
}
.table tfoot td.right{ text-align:right; }

.badge{
  display:inline-block; padding:4px 10px; border-radius:999px; border:1px solid var(--line); font-size:12px; background:#fff;
}
.badge.green{ color:var(--green); border-color:#a7f3d0; background:#ecfdf5; }
.badge.red{ color:var(--red); border-color:#fecaca; background:#fef2f2; }

.actions{ display:flex; gap:8px; }
.action{
  padding:6px 10px; border:1px solid var(--line); border-radius:10px; background:#fff; cursor:pointer;
  transition: background .15s ease;
}
.action:hover{ background:#f1f5f9; }

.settlement-list{
  border:1px solid var(--line); border-radius:12px; background:#fff; padding:12px; min-height:54px;
}
.settlement-item{
  display:flex; justify-content:space-between; align-items:center;
  border-bottom:1px dashed var(--line); padding:10px 6px; font-size:15px;
  transition: background .15s ease, border-radius .15s ease;
}
.settlement-item:last-child{ border-bottom:none; }
.settlement-item:hover{ background:var(--primary-10); border-radius:8px; }
.settlement-item strong{ color:var(--primary); }
.settlement-item .amount{ font-weight:700; color:var(--green); }

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.chip,
#expensesTable tbody tr,
.settlement-item { animation: fadeIn 0.35s ease-out; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  padding: 12px 18px;
  border-radius: 999px;
  background-color: var(--green);
  color: #fff;
  box-shadow: var(--shadow);
  transition: all 0.5s cubic-bezier(0.68,-0.55,0.27,1.55);
  opacity: 0;
  z-index: 9999;
  font-weight: 600;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast-error { background-color: var(--red); }

/* Responsive tweaks */
@media (max-width: 680px) {
  .table th, .table td { font-size: 13px; padding: 8px; }
  .btn, .input, select { font-size: 13px; padding: 9px 12px; }
  h1 { font-size: 24px; }
  h2 { font-size: 18px; }
}


#summaryTable .badge {
  font-size: 16px;
  padding: 2px 8px;
}

.back-home-btn {
  position: fixed;         /* ✅ ให้ลอยอยู่กับที่ตลอด */
  top: 20px;               /* ระยะห่างจากด้านบน */
  right: 20px;             /* ระยะห่างจากด้านขวา */
  background: #1e88e5;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transition: background 0.2s, transform 0.15s;
  z-index: 1000;          /* ✅ ป้องกันโดนตารางบัง */
    position: absolute;
  top: 20px;
  right: 20px;
}
.back-home-btn:hover {
  background: #1565c0;
  transform: translateY(-2px);
}
