@font-face {
  font-family: "Noto Sans Thai";
  src: url("/fonts/noto-sans-thai-thai-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0E00-0E7F;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("/fonts/noto-sans-thai-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("/fonts/noto-sans-thai-thai-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0E00-0E7F;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("/fonts/noto-sans-thai-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("/fonts/noto-sans-thai-thai-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0E00-0E7F;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("/fonts/noto-sans-thai-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F;
}

:root {
  color-scheme: light;
  --bg: #f3f1ec;
  --paper: #fffcf8;
  --ink: #1c1b19;
  --muted: #6f6a62;
  --line: #e4e0d8;
  --chip: #e8e4dc;
  --black: #1c1b19;
  --ok-bg: #edf3ec;
  --ok: #3d5c45;
  --wait-bg: #fbf3db;
  --wait: #8a5a12;
  --bad-bg: #fdebec;
  --bad: #9f2f2d;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 34px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.15; }
h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.35; }

.app { display: grid; grid-template-columns: 96px minmax(0, 1fr); min-height: 100dvh; }
.rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 10px 16px;
}
.brand {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--paper);
  display: grid;
  place-items: center;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(28, 27, 25, 0.05);
}
.brand strong { font-size: 14px; font-weight: 600; }
.rail nav { display: flex; flex-direction: column; gap: 6px; width: 100%; flex: 1; }
.rail nav a {
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 10px 4px;
  border-radius: 14px;
  transition: background-color 160ms ease-out, color 160ms ease-out;
}
.rail nav a[aria-current="page"] { background: var(--black); color: var(--paper); }
.rail form { margin: 0; }
.canvas { width: min(1120px, 100%); padding: 40px 40px 80px; }
.page-head, .trip-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; }
.page-head { margin-bottom: 28px; }
.eyebrow { color: var(--muted); font-size: 13px; margin: 0 0 6px; }
.lead, .meta, .hint { color: var(--muted); }
.lead { margin-bottom: 16px; max-width: 62ch; }
.hint { margin-top: 18px; font-size: 13px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 22px; align-items: start; }
.stack { display: grid; gap: 18px; }
.panel, .trip-card, .empty, .login {
  background: var(--paper);
  border: 1px solid rgba(228, 224, 216, 0.9);
  border-radius: 28px;
  box-shadow: 0 12px 32px rgba(28, 27, 25, 0.04);
}
.panel, .trip-card, .empty { padding: 22px 24px; }
.summary article { padding: 14px 0; }
.summary article + article { border-top: 1px solid var(--line); }
.summary span, .stats span { display: block; color: var(--muted); font-size: 13px; }
.summary strong, .stats strong { display: block; margin-top: 2px; font-size: 28px; font-weight: 600; letter-spacing: -0.03em; }
.summary.flat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.summary.flat article { border: 0; padding: 0; }
.rows { display: grid; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
  padding: 16px 4px;
  text-decoration: none;
  color: inherit;
  border-radius: 12px;
  transition: background-color 160ms ease-out;
}
.rows .row + .row { box-shadow: inset 0 1px 0 var(--line); }
.row:hover { background: #faf7f2; }
.row h2 { margin: 0; }
.state { margin: 0; font-size: 13px; font-weight: 500; white-space: nowrap; }
.state.wait { color: var(--wait); }
.state.ok { color: var(--ok); }
.state.bad { color: var(--bad); }
.test { color: var(--muted); font-weight: 400; margin-right: 8px; }
.panel.form, .form { display: grid; gap: 16px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.badge { font-size: 13px; font-weight: 500; color: var(--wait); }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--bad); }
.badge.wait { color: var(--wait); }
.notice { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.trip { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 8px 0 18px; background: transparent; display: grid; gap: 14px; box-shadow: none; }
.trip legend { padding: 0; font-weight: 600; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffcf8;
  padding: 12px 14px;
  font-weight: 400;
  color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(28, 27, 25, 0.16); border-color: #cfc8bf; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.place { position: relative; }
button.place-trigger {
  width: 100%;
  justify-content: flex-start;
  min-height: 48px;
  background: #fffcf8;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 400;
}
button.place-trigger.is-set { color: var(--ink); }
.place-pop {
  position: absolute;
  z-index: 6;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  gap: 8px;
  padding: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(28, 27, 25, 0.06);
}
.place-pop:not([hidden]) { display: grid; }
.place-pop[hidden] { display: none !important; }
.place-list { display: grid; max-height: 220px; overflow: auto; }
.place-list button {
  justify-content: flex-start;
  min-height: 40px;
  background: transparent;
  color: var(--ink);
  font-weight: 500;
  border-radius: 8px;
}
.place-list button:hover { background: var(--chip); }
.place-empty { margin: 0; padding: 8px; color: var(--muted); font-size: 13px; }
button.place-add { width: 100%; }
.align-end { align-items: end; }
button, .button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--black);
  color: white;
  text-decoration: none;
  font-weight: 600;
  transition: background-color 160ms ease-out, color 160ms ease-out, transform 120ms ease-out;
}
button:active, .button:active { transform: scale(0.98); }
button.ghost, a.button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.week-nav { display: flex; gap: 8px; }
button.text { min-height: 0; padding: 8px; background: transparent; color: var(--muted); font-weight: 500; border-radius: 10px; }
.cost-form { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 10px; align-items: end; margin-top: 14px; }
pre {
  white-space: pre-wrap;
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 0.95rem;
}
.table-wrap { overflow-x: auto; }
.table-wrap.panel { padding: 8px 8px 4px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 0.86rem; }
td.num, th:last-child { text-align: right; }
.login-body { min-height: 100dvh; display: grid; place-items: center; }
.login { width: min(440px, calc(100% - 40px)); padding: 32px; }
.login h1 { margin-bottom: 8px; }
.empty { display: grid; gap: 10px; justify-items: start; }
.panel .remove-trip { display: none; }

.page-head, .panel, .trip-card, .login, .notice, .trip {
  animation: rise 400ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.rows .row { animation: rise 400ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.rows .row:nth-child(1) { animation-delay: 40ms; }
.rows .row:nth-child(2) { animation-delay: 70ms; }
.rows .row:nth-child(3) { animation-delay: 100ms; }
.rows .row:nth-child(4) { animation-delay: 130ms; }
.rows .row:nth-child(5) { animation-delay: 160ms; }
.rows .row:nth-child(6) { animation-delay: 190ms; }
.rows .row:nth-child(7) { animation-delay: 220ms; }
.rows .row:nth-child(n + 8) { animation-delay: 250ms; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 800px) {
  .app { display: block; }
  .rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    flex-direction: row;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(255, 252, 248, 0.96);
    border-top: 1px solid var(--line);
    z-index: 5;
  }
  .brand { display: none; }
  .rail nav { flex-direction: row; overflow-x: auto; }
  .rail nav a { min-width: 64px; padding: 10px 8px; }
  .canvas { padding: 24px 16px 108px; }
  .split, .summary.flat, .pair, .cost-form { grid-template-columns: 1fr; }
  .page-head, .trip-head { flex-direction: column; align-items: flex-start; }
  .badges { justify-content: flex-start; }
  .cost-form button { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .page-head, .panel, .trip-card, .login, .notice, .trip, .rows .row {
    animation-name: fade-in;
    animation-duration: 120ms;
    animation-delay: 0ms;
  }
  button:active, .button:active { transform: none; }
}
