  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --border: #e3e6eb;
    --text: #1b1f24;
    --muted: #6b7280;
    --primary: #1f5eff;
    --primary-soft: #e8efff;
    --ok: #12805c;
    --ok-soft: #e3f5ee;
    --warn: #b25e00;
    --warn-soft: #fff3e0;
    --bad: #c62828;
    --bad-soft: #fdecec;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #0f1115;
      --surface: #171a20;
      --surface-2: #1d2128;
      --border: #2a2f38;
      --text: #e8eaee;
      --muted: #9aa3b2;
      --primary: #5b8cff;
      --primary-soft: #1c2742;
      --ok: #3ccf95;
      --ok-soft: #13291f;
      --warn: #ffb44d;
      --warn-soft: #2e2213;
      --bad: #ff6b6b;
      --bad-soft: #321718;
      --shadow: none;
    }
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: "IBM Plex Sans Thai", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }
  .wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
  h1, h2, h3 { margin: 0; line-height: 1.3; }
  h1 { font-size: 20px; font-weight: 700; }
  h2 { font-size: 17px; font-weight: 600; }
  h3 { font-size: 15px; font-weight: 600; }
  .muted { color: var(--muted); }
  .small { font-size: 13px; }
  .hidden { display: none !important; }

  /* Header */
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
  .brand { display: flex; align-items: center; gap: 10px; }
  .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
  .user-chip { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 4px 4px 12px; font-size: 13px; }
  .user-chip button { border: 0; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 4px 10px; font: inherit; cursor: pointer; }

  /* Cards */
  .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
  .card + .card { margin-top: 12px; }
  .stack > * + * { margin-top: 12px; }

  /* Tabs */
  .tabs { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 4px 0 12px; margin: 0 0 4px; }
  .tabs-inner { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 5px; box-shadow: var(--shadow); }
  .tab { border: 0; background: none; font: inherit; color: var(--muted); padding: 8px 4px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 13px; line-height: 1.2; text-align: center; }
  .tab svg { width: 22px; height: 22px; }
  .tab:hover { background: var(--surface-2); }
  .tab.active { background: var(--primary); color: #fff; }
  .tab.active { font-weight: 600; }
  .tab { white-space: nowrap; }
  @media (max-width: 420px) { .tab { font-size: 11.5px; padding: 8px 2px; } .tab svg { width: 20px; height: 20px; } }

  /* Forms */
  label.field { display: block; }
  .field > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
  .req::after { content: " *"; color: var(--bad); }
  input, select, textarea {
    width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none;
  }
  input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
  textarea { min-height: 80px; resize: vertical; }
  .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  @media (max-width: 420px) { .row.collapse { grid-template-columns: 1fr; } }

  .seg { display: flex; flex-wrap: wrap; gap: 8px; }
  .seg input { position: absolute; opacity: 0; pointer-events: none; }
  .seg label { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 14px; }
  .seg input:checked + label { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
  .seg input:focus-visible + label { box-shadow: 0 0 0 3px var(--primary-soft); }

  .btn { border: 0; border-radius: 10px; padding: 12px 16px; font: inherit; font-weight: 600; cursor: pointer; background: var(--primary); color: #fff; width: 100%; }
  .btn:disabled { opacity: .45; cursor: not-allowed; }
  .btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); width: auto; padding: 8px 12px; font-weight: 500; }
  .btn.link { background: none; color: var(--primary); padding: 4px 0; width: auto; font-weight: 500; }

  /* Upload */
  .drop { border: 1.5px dashed var(--border); border-radius: 12px; padding: 16px; text-align: center; cursor: pointer; background: var(--surface-2); }
  .drop:hover { border-color: var(--primary); }
  .thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
  .thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: grid; place-items: center; font-size: 12px; text-align: center; padding: 4px; }
  .thumb img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
  .thumb button { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 22px; padding: 0; z-index: 1; }

  /* Balance */
  .balances { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .bal { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
  .bal .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .bal .bar { height: 4px; border-radius: 4px; background: var(--border); margin-top: 6px; overflow: hidden; }
  .bal .bar i { display: block; height: 100%; background: var(--primary); }

  .summary { display: flex; justify-content: space-between; align-items: center; background: var(--primary-soft); border-radius: 12px; padding: 12px 14px; }
  .summary b { font-size: 18px; font-variant-numeric: tabular-nums; }

  .notice { border-radius: 12px; padding: 12px 14px; font-size: 14px; }
  .notice.warn { background: var(--warn-soft); color: var(--warn); }
  .notice.bad { background: var(--bad-soft); color: var(--bad); }
  .notice.ok { background: var(--ok-soft); color: var(--ok); }
  .notice.info { background: var(--primary-soft); color: var(--primary); }

  /* Travel items */
  .item { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: var(--surface-2); position: relative; }
  .item .rm { position: absolute; top: 8px; right: 8px; }

  /* History */
  .req-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .req-item:last-child { border-bottom: 0; }
  .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; font-size: 18px; background: var(--surface-2); }
  .badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
  .badge.pending { background: var(--warn-soft); color: var(--warn); }
  .badge.approved { background: var(--ok-soft); color: var(--ok); }
  .badge.rejected { background: var(--bad-soft); color: var(--bad); }
  .filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

  /* Login */
  .login { min-height: 80vh; display: grid; place-items: center; }
  .login .card { width: 100%; max-width: 400px; }

  .avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex: none; position: relative; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.avatar.lg { width: 88px; height: 88px; font-size: 32px; }
.avatar.edit { cursor: pointer; }
.avatar.edit::after { content: "📷"; position: absolute; right: -2px; bottom: -2px; font-size: 12px; background: var(--surface); border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; box-shadow: 0 0 0 1px var(--border); }
.avatar.sm.edit::after { width: 14px; height: 14px; font-size: 8px; right: -4px; bottom: -3px; }
.avatar.lg.edit::after { width: 28px; height: 28px; font-size: 16px; right: 0; bottom: 0; }

.install { display: flex; gap: 12px; align-items: flex-start; background: var(--primary-soft); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 12px; position: relative; }
.install img { width: 44px; height: 44px; border-radius: 10px; flex: none; }
.install .x { position: absolute; top: 6px; right: 8px; border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.login .install { margin: 4px 0 0; }
.logo { background: #5AAEF5 !important; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }

/* Pop-up */
.popup { border: 0; border-radius: 20px; padding: 0; background: var(--surface); color: var(--text); width: min(420px, calc(100% - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 24px 64px rgba(0,0,0,.35); }
.popup::backdrop { background: rgba(0,0,0,.5); }
.popup[open] { animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
.pop-body { padding: 24px 20px 20px; text-align: center; }
.pop-body h2 { font-size: 19px; margin: 12px 0 8px; }
.pop-body p { margin: 8px 0; }
.pop-icon { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; font-size: 30px; font-weight: 700; }
.pop-icon.ok { background: var(--ok-soft); color: var(--ok); }
.pop-icon.bad { background: var(--bad-soft); color: var(--bad); }
.pop-icon.info { background: var(--primary-soft); color: var(--primary); }
.pop-content { text-align: left; }
.pop-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-top: 8px; }
.pop-card.approved { border-left: 4px solid var(--ok); }
.pop-card.rejected { border-left: 4px solid var(--bad); }
.pop-row { display: flex; gap: 10px; align-items: flex-start; }
.pop-row > span:first-child { font-size: 20px; line-height: 1.2; }
.pop-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; margin-top: 16px; }
.pop-actions .btn.ghost { width: 100%; padding: 12px 16px; }
.tab { position: relative; }
.tab .dot { position: absolute; top: 4px; right: 14%; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 5px; }
