/* ─── Variables (Black / Gray / Red) ─── */
:root {
  --red: #ef4444;
  --red-dark: #991b1b;
  --red-light: #2d0808;
  --red-accent: #fc8181;
  --green: #34d399;
  --green-light: #052e16;
  --amber: #fbbf24;
  --amber-light: #451a03;
  --danger: #ef4444;
  /* สีแบรนด์ (โลโก้ + PWA icon) — แยกจาก --red ที่เป็น accent ของ UI ทั้งแอป */
  --brand: #0d9488;
  --brand-accent: #5eead4;
  --gray-50: #0c0c0c;
  --gray-100: #181818;
  --gray-200: #272727;
  --gray-400: #636363;
  --gray-600: #999999;
  --gray-700: #c8c8c8;
  --gray-800: #060606;
  --gray-900: #f0f0f0;
  --white: #181818;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 72px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  height: 100%; height: -webkit-fill-available;
  touch-action: pan-x pan-y;              /* กัน pinch-zoom / double-tap zoom - เลื่อนจอได้อย่างเดียว */
  -webkit-text-size-adjust: 100%;
}
body {
  height: 100%;
  height: -webkit-fill-available;
  overflow: hidden;
  font-family: -apple-system, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;   /* กันลากเลือกข้อความ/long-press เหมือน native */
  -webkit-touch-callout: none;
}
input, select, textarea { -webkit-user-select: text; user-select: text; }
.slip-viewer img { -webkit-touch-callout: default; }   /* ยกเว้นรูปสลิป - long-press เซฟรูปได้ */
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select { font-family: inherit; font-size: inherit; }
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ─── Screens ─── */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.screen.hidden { display: none; }

/* ─── Center Wrap (Login / Setup) ─── */
.center-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  padding-top: calc(var(--safe-top) + 32px);
  padding-bottom: calc(var(--safe-bottom) + 32px);
  background: var(--gray-50);
}
.logo-big { font-size: 40px; font-weight: 800; color: var(--brand-accent); letter-spacing: -1px;
  display: flex; align-items: center; gap: 12px; }
.logo-big svg { width: 44px; height: 44px; flex-shrink: 0; }
.logo-big .in { color: var(--gray-900); }
.logo-sub { font-size: 14px; color: var(--gray-400); margin-top: 6px; text-align: center; }
.setup-card {
  width: 100%; max-width: 400px;
  background: var(--white); border-radius: var(--radius);
  padding: 20px; margin-top: 28px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.6);
}
.setup-step-label { font-size: 13px; font-weight: 600; color: var(--red-accent); margin-bottom: 4px; }
.setup-hint { font-size: 12px; color: var(--gray-400); margin-top: 6px; line-height: 1.5; text-align: center; }

/* Google Login Button */
.btn-google {
  display: flex; align-items: center; gap: 10px;
  background: var(--white); color: var(--gray-700);
  border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm);
  padding: 14px 24px; font-size: 15px; font-weight: 600;
  margin-top: 28px; box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  width: 100%; max-width: 280px; justify-content: center;
}
.btn-google:active { opacity: 0.8; }
/* Dev login (localhost only) */
.dev-login { width: 100%; max-width: 300px; margin: 22px auto 0; display: flex; flex-direction: column; gap: 8px;
  padding: 14px; border: 1px dashed var(--gray-200); border-radius: var(--radius-sm); }
.dev-login-title { font-size: 12px; color: var(--gray-400); text-align: center; margin-bottom: 2px; }
.dev-login .field-input { text-align: center; }
.dev-login-btn { width: 100%; padding: 11px; font-size: 14px; font-weight: 500; cursor: pointer;
  background: var(--gray-200); color: var(--gray-900); border: none; border-radius: var(--radius-sm); }
.dev-login-btn:active { opacity: 0.8; }
.dev-login-btn:disabled { opacity: 0.5; }
.btn-text { font-size: 13px; color: var(--gray-400); margin-top: 20px; text-decoration: underline; }

/* Loading Spinner */
.spinner-big {
  width: 40px; height: 40px;
  border: 3px solid var(--red-light);
  border-top-color: var(--red-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── App Screen ─── */
#screen-app { background: var(--gray-50); overflow: hidden; }

/* ─── Header ─── */
.app-header {
  background: #111111;
  padding: 0 20px 16px;
  padding-top: calc(var(--safe-top) + 8px);
  flex-shrink: 0;
  color: white;
  border-bottom: 1px solid var(--gray-200);
}
.header-top {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 8px; margin-bottom: 16px;
}
.header-logo { font-size: 22px; font-weight: 800; color: var(--brand-accent); letter-spacing: -0.5px;
  display: inline-flex; align-items: center; gap: 8px; }
.header-logo svg { width: 26px; height: 26px; flex-shrink: 0; }
.header-logo .in { color: var(--gray-900); }
.btn-settings {
  background: rgba(255,255,255,.1); border: none; color: var(--gray-600);
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer;
}
.header-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum-card { background: rgba(255,255,255,.06); border: 1px solid var(--gray-200); border-radius: 12px; padding: 12px 14px; }
.sum-lbl { font-size: 11px; color: var(--gray-400); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
.sum-val { font-size: 20px; font-weight: 700; color: white; }
.sum-sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* ─── Year Bar ─── */
.year-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px; background: var(--gray-50);
}
.year-bar-title { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.year-pill {
  appearance: none; -webkit-appearance: none;
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: 20px; padding: 5px 24px 5px 12px;
  font-size: 13px; font-weight: 600; color: var(--gray-900); cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23fc8181'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}

/* ─── Main / Views ─── */
.app-main {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 80px);
  position: relative;
}
.view { display: none; }
.view.active { display: block; }

/* ─── Pull to Refresh ─── */
#ptr {
  position: absolute; top: 6px; left: 50%;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--white); box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 5; opacity: 0; pointer-events: none;
  transform: translateX(-50%) translateY(-48px);
}
.ptr-spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--gray-200); border-top-color: var(--red-accent);
}
#ptr.spin .ptr-spinner { animation: ptr-rot .7s linear infinite; }
@keyframes ptr-rot { to { transform: rotate(360deg); } }

/* ─── Bottom Nav ─── */
.bottom-nav {
  display: flex;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #111111; border-top: 1px solid var(--gray-200);
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  flex-shrink: 0;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--gray-400); padding-top: 6px;
}
.nav-item.active { color: var(--red-accent); }
.nav-icon { display: flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 24px; height: 24px; display: block; }
.nav-label { font-size: 11px; font-weight: 500; }

/* ─── FAB ─── */
.fab {
  position: fixed; right: 20px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--red); color: white; font-size: 28px;
  box-shadow: 0 4px 20px rgba(239,68,68,0.5);
  z-index: 20; display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }
.fab.hidden { display: none !important; }

/* ─── Month Group ─── */
.month-group { margin-bottom: 4px; }
.month-header {
  background: var(--gray-50); padding: 10px 16px 6px;
  font-size: 12px; font-weight: 700; color: var(--red-accent);
  text-transform: uppercase; letter-spacing: .8px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 5;
}
.month-count { font-size: 11px; color: var(--gray-400); font-weight: 500; letter-spacing: 0; text-transform: none; }

/* ─── Row Card ─── */
.row-card {
  background: var(--white); margin: 0 12px 8px; border-radius: 14px;
  padding: 14px 16px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  display: flex; flex-direction: column; gap: 8px;
  -webkit-user-select: none; user-select: none;
  transition: transform .1s;
}
.row-card:active { transform: scale(0.98); }
.row-top { display: flex; justify-content: space-between; align-items: flex-start; }
.row-name { font-size: 15px; font-weight: 700; color: var(--gray-900); }
.row-client { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* ─── Money Row ─── */
.row-money { display: flex; }
.money-item { flex: 1; }
.money-label { font-size: 10px; color: var(--gray-400); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 2px; }
.money-val { font-size: 14px; font-weight: 600; }
.money-val.price { color: var(--gray-900); }
.money-val.net { color: var(--green); }
.money-val.empty { color: var(--gray-400); }
.divider-v { width: 1px; background: var(--gray-200); margin: 0 12px; align-self: stretch; }

/* ─── Tax Row (in card) ─── */
.row-tax {
  background: var(--gray-100); border-radius: 8px; padding: 6px 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.row-tax-label { font-size: 11px; color: var(--gray-400); }
.tax-vals { display: flex; gap: 12px; }
.row-tax .tax-val { font-size: 12px; font-weight: 600; color: var(--red-accent); }
.tap-hint { font-size: 11px; color: var(--gray-400); text-align: center; }

/* ─── Status Badge ─── */
.status-badge {
  display: inline-flex; align-items: center;
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  cursor: pointer; white-space: nowrap; flex-shrink: 0; margin-left: 8px;
  -webkit-tap-highlight-color: transparent; transition: opacity 0.1s;
}
.status-badge:active { opacity: 0.7; }
.badge-paid { background: var(--green-light); color: #6ee7b7; }
.badge-wait { background: var(--amber-light); color: #fcd34d; }
.badge-partial { background: #0b2540; color: #7dd3fc; }

/* ─── Summary Table ─── */
.summary-section { margin: 8px 12px 16px; }
.summary-title { font-size: 13px; font-weight: 700; color: var(--gray-600); padding: 8px 4px; }
.summary-table { background: var(--white); border-radius: 14px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
.sum-head { display: grid; grid-template-columns: 60px 40px 1fr 1fr; padding: 8px 14px; background: var(--gray-800); }
.sum-head span { font-size: 11px; font-weight: 700; color: rgba(255,255,255,.45); text-align: right; }
.sum-head span:first-child { text-align: left; }
.sum-head span:nth-child(2) { text-align: center; }
.sum-row { display: grid; grid-template-columns: 60px 40px 1fr 1fr; padding: 10px 14px; border-bottom: 1px solid var(--gray-200); }
.sum-row span { font-size: 13px; text-align: right; color: var(--gray-900); }
.sum-row span:first-child { text-align: left; font-weight: 700; color: var(--red-accent); }
.sum-row span:nth-child(2) { color: var(--gray-400); text-align: center; }
.sum-total { display: grid; grid-template-columns: 60px 40px 1fr 1fr; padding: 10px 14px; background: var(--gray-800); }
.sum-total span { font-size: 13px; font-weight: 700; text-align: right; color: white; }
.sum-total span:first-child { text-align: left; }
.sum-total span:nth-child(2) { text-align: center; }

/* ─── Client Card ─── */
.client-card {
  background: var(--white); border-bottom: 1px solid var(--gray-200);
  padding: 14px 16px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  -webkit-user-select: none; user-select: none;
}
.client-card:active { background: var(--gray-100); }
.client-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(239,68,68,0.15); color: var(--red-accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.client-info { flex: 1; min-width: 0; }
.client-name-text { font-size: 15px; font-weight: 600; }
.client-meta { font-size: 13px; color: var(--gray-400); margin-top: 2px; }
.chevron { color: var(--gray-400); font-size: 18px; margin-left: auto; }

/* ─── iOS Toggle ─── */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; margin-top: 4px;
}
.toggle-text .toggle-label { font-size: 14px; font-weight: 600; color: var(--gray-700); }
.toggle-text .toggle-sub { font-size: 12px; color: var(--gray-400); margin-top: 2px; }
.ios-toggle { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.ios-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.ios-toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--gray-200); border-radius: 26px; transition: background .2s;
}
.ios-toggle-slider:before {
  position: absolute; content: "";
  height: 20px; width: 20px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: transform .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.ios-toggle input:checked + .ios-toggle-slider { background: var(--red); }
.ios-toggle input:checked + .ios-toggle-slider:before { transform: translateX(18px); }

/* ─── Tax Exclude Badge ─── */
.tax-exclude-tag {
  display: inline-block; font-size: 10px; font-weight: 700;
  background: var(--gray-200); color: var(--gray-600);
  border-radius: 6px; padding: 2px 8px; letter-spacing: .3px;
}

/* ─── Report Mode Toggle ─── */
.report-mode-bar {
  display: flex; gap: 8px; padding: 12px 16px 4px; background: var(--gray-50);
}
.mode-btn {
  flex: 1; padding: 8px 12px; border-radius: 20px;
  font-size: 13px; font-weight: 600;
  background: var(--white); color: var(--gray-600);
  border: 1.5px solid var(--gray-200); cursor: pointer;
}
.mode-btn.active { background: var(--red); color: white; border-color: var(--red); }

/* ─── Report ─── */
.report-section { padding: 16px; }
.report-summary-card {
  background: #1a0a0a; border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; color: white;
}
.rsc-label { font-size: 13px; color: var(--gray-400); }
.rsc-value { font-size: 30px; font-weight: 800; margin: 4px 0; color: var(--gray-900); }
.rsc-sub { font-size: 13px; color: var(--gray-400); }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.report-mini-card {
  background: var(--white); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.rmc-label { font-size: 12px; color: var(--gray-400); font-weight: 500; }
.rmc-value { font-size: 20px; font-weight: 700; color: var(--gray-900); margin-top: 6px; }
.report-table-card {
  background: var(--white); border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.4); margin-bottom: 16px;
}
.rtc-title { padding: 14px 16px 8px; font-size: 14px; font-weight: 600; color: var(--gray-700); }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th {
  text-align: right; padding: 8px 12px;
  font-size: 11px; font-weight: 500; color: var(--gray-400);
  border-bottom: 1px solid var(--gray-200);
}
.report-table th:first-child { text-align: left; }
.report-table td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--gray-200); }
.report-table td:first-child { text-align: left; font-weight: 500; }
.report-table tr:last-child td { border-bottom: none; }
.report-table tfoot td { font-weight: 700; background: var(--gray-100); border-top: 2px solid var(--gray-200); border-bottom: none; }
.btn-export {
  display: block; width: 100%;
  background: var(--red-light); color: var(--red-accent);
  padding: 14px; border-radius: var(--radius);
  font-size: 15px; font-weight: 600; text-align: center;
  border: 1px solid rgba(239,68,68,0.2);
}
.btn-export:active { opacity: 0.8; }

/* ─── Overlay / Bottom Sheet ─── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 30; }
.bottom-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #141414; border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--gray-200);
  z-index: 40; max-height: 92vh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--safe-bottom) + 16px);
}
.sheet-handle {
  width: 36px; height: 4px; background: var(--gray-200);
  border-radius: 2px; margin: 12px auto 0;
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; font-size: 16px; font-weight: 700;
}
.sheet-body { padding: 4px 16px 8px; }

/* ─── Form Fields ─── */
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-600); margin: 14px 0 6px; }
.req { color: var(--red-accent); }
.field-input {
  width: 100%; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 15px; color: var(--gray-900);
  background: var(--gray-100); outline: none; transition: border-color 0.15s;
  appearance: none; -webkit-appearance: none;
}
.field-input:focus { border-color: var(--red-accent); }
select.field-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23636363'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.field-large { font-size: 24px; font-weight: 700; padding: 14px; }
.field-error { font-size: 13px; color: var(--red-accent); margin-top: 6px; }

/* ─── Payment Sheet ─── */
.pay-info-box { background: var(--gray-100); border-radius: 12px; padding: 12px 14px; margin-top: 4px; }
.pi-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; border-bottom: 1px solid var(--gray-200); }
.pi-row:last-child { border-bottom: none; }
.pi-lbl { color: var(--gray-400); }
.pi-val { font-weight: 600; color: var(--gray-900); }
.tax-preview { background: var(--red-light); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 10px; border: 1px solid rgba(239,68,68,0.2); }
.tax-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; }
.tax-label { font-size: 14px; color: var(--red-accent); font-weight: 500; }
.tax-val { font-size: 16px; font-weight: 700; color: var(--red-accent); }

/* ─── Buttons ─── */
.btn-primary {
  display: block; width: 100%; background: var(--red); color: white;
  padding: 15px; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 600; text-align: center; margin-top: 16px;
}
.btn-primary:active { opacity: 0.85; }
.btn-outline {
  display: block; width: 100%; background: transparent; color: var(--red-accent);
  border: 1.5px solid rgba(252,129,129,0.4); padding: 13px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; text-align: center;
}
.btn-outline:active { opacity: 0.8; }
.btn-danger-outline {
  display: block; width: 100%; background: transparent; color: var(--red-accent);
  border: 1.5px solid rgba(239,68,68,0.35); padding: 13px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; text-align: center;
}
.btn-danger-outline:active { opacity: 0.8; }
.btn-icon {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-400); font-size: 14px; background: var(--gray-200);
}

/* ─── Settings Sheet ─── */
.settings-user {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--gray-200); margin-bottom: 12px;
}
.settings-user-img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.settings-user-name { font-size: 15px; font-weight: 600; }
.settings-user-email { font-size: 13px; color: var(--gray-400); }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--gray-200);
}
.settings-label { font-size: 14px; font-weight: 500; }
.settings-value-small { font-size: 11px; color: var(--gray-400); max-width: 180px; word-break: break-all; text-align: right; }

/* ─── Empty State ─── */
.empty-state { text-align: center; padding: 80px 32px; color: var(--gray-400); }
.empty-icon { margin-bottom: 14px; color: var(--gray-400); display: flex; justify-content: center; }
.empty-icon svg { width: 52px; height: 52px; }
.empty-state p { font-size: 15px; line-height: 1.7; }

/* ─── Line-art icons ─── */
.btn-settings svg { width: 19px; height: 19px; display: block; }
.btn-icon svg { width: 16px; height: 16px; display: block; }
.btn-ico { width: 18px; height: 18px; vertical-align: -4px; margin-right: 8px; }
.badge-ico { width: 13px; height: 13px; vertical-align: -2px; margin-right: 2px; }
.row-tax-ico { width: 12px; height: 12px; vertical-align: -1px; margin-right: 2px; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 70px);
  left: 50%; transform: translateX(-50%);
  background: #f0f0f0; color: #0c0c0c;
  padding: 10px 20px; border-radius: 24px;
  font-size: 14px; font-weight: 600; z-index: 100; white-space: nowrap;
  animation: fadeInUp 0.2s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Filter Bar (ค้นหา + กรองสถานะ) ─── */
.filter-bar { padding: 0 16px 6px; }
.search-wrap { position: relative; margin-bottom: 8px; }
.search-ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--gray-400); pointer-events: none;
}
.search-input {
  width: 100%; background: var(--white); border: 1px solid var(--gray-200);
  border-radius: 10px; padding: 9px 36px; font-size: 14px; color: var(--gray-900);
  outline: none; appearance: none; -webkit-appearance: none;
}
.search-input:focus { border-color: var(--red-accent); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--gray-200); color: var(--gray-600); font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.chip-row { display: flex; gap: 8px; }
.chip {
  padding: 6px 14px; border-radius: 16px; font-size: 12px; font-weight: 600;
  background: var(--white); color: var(--gray-600); border: 1px solid var(--gray-200);
}
.chip.active { background: var(--red); border-color: var(--red); color: white; }
.filter-result { padding: 0 16px 8px; font-size: 12px; color: var(--gray-600); font-weight: 600; }

/* ─── 50 ทวิ ─── */
.wht-tag {
  display: inline-block; font-size: 10px; font-weight: 700;
  border-radius: 6px; padding: 1px 6px; margin-left: 6px; letter-spacing: .2px;
}
.wht-tag.ok { background: var(--green-light); color: #6ee7b7; }
.wht-tag.wait { background: var(--amber-light); color: #fcd34d; }
.wht-count {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; margin-left: 8px;
}
.wht-count.ok { background: var(--green-light); color: #6ee7b7; }
.wht-count.warn { background: var(--amber-light); color: #fcd34d; }
.wht-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--gray-200); font-size: 13px;
}
.wht-row:last-child { border-bottom: none; }
.wht-row .wr-client { font-weight: 600; }
.wht-row .wr-meta { color: var(--gray-400); font-size: 12px; }
.wht-ok { padding: 14px 16px; color: var(--green); font-size: 13px; font-weight: 600; }
.wht-hint { padding: 0 16px 12px; font-size: 11px; color: var(--gray-400); line-height: 1.5; }

/* ─── Slip (สลิปโอนเงิน) ─── */
.slip-add {
  display: flex; width: 100%; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; border: 1.5px dashed var(--gray-200); border-radius: var(--radius-sm);
  color: var(--gray-600); font-size: 14px; font-weight: 600; background: var(--gray-100);
}
.slip-add:active { opacity: .8; }
.slip-add svg { width: 16px; height: 16px; }
.slip-thumb-wrap {
  display: flex; align-items: center; gap: 12px;
  background: var(--gray-100); border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm); padding: 10px;
}
.slip-thumb {
  width: 64px; height: 64px; object-fit: cover; border-radius: 8px;
  background: var(--gray-200); cursor: pointer; flex-shrink: 0;
}
.slip-info { flex: 1; font-size: 12px; color: var(--gray-400); line-height: 1.5; }
.slip-btn {
  font-size: 13px; font-weight: 600; color: var(--red-accent);
  padding: 6px 12px; border-radius: 8px; background: rgba(239,68,68,.08);
  white-space: nowrap;
}
.slip-uploading { font-size: 13px; color: var(--gray-400); padding: 12px; text-align: center; }
.clip-ico { width: 11px; height: 11px; vertical-align: -1px; margin-left: 6px; }
.slip-viewer {
  position: fixed; inset: 0; background: rgba(0,0,0,.93); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.slip-viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ─── Tax Estimator (ประมาณการภาษี) ─── */
.tax-est-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4); margin-bottom: 16px; overflow: hidden;
}
.tec-body { padding: 2px 16px 14px; }
.tec-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; font-size: 13px; border-bottom: 1px dashed var(--gray-200);
}
.tec-row .tl { color: var(--gray-400); }
.tec-row .tv { font-weight: 600; color: var(--gray-900); }
.tec-row.strong .tl { color: var(--gray-700); font-weight: 600; }
.tec-inputs { margin-top: 10px; }
.tec-inputs .field-label { margin-top: 10px; }
.field-input.compact { padding: 8px 12px; font-size: 14px; }
.tax-result {
  border-radius: 10px; padding: 14px; text-align: center;
  margin-top: 14px; font-size: 13px; font-weight: 600;
}
.tax-result.refund { background: var(--green-light); color: #6ee7b7; }
.tax-result.owe { background: var(--red-light); color: var(--red-accent); border: 1px solid rgba(239,68,68,0.2); }
.tax-result.even { background: var(--gray-100); color: var(--gray-600); }
.tax-result .tr-big { font-size: 24px; font-weight: 800; display: block; margin-top: 2px; }
.tec-note { font-size: 11px; color: var(--gray-400); margin-top: 12px; line-height: 1.6; }

/* ─── Payment: รับเงินเป็นงวด ─── */
.pay-summary { margin-top: 14px; }
.ps-bar { height: 8px; background: var(--gray-200); border-radius: 6px; overflow: hidden; }
.ps-fill { height: 100%; background: var(--green); border-radius: 6px; transition: width .3s; }
.ps-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 13px; color: var(--gray-600); }
.ps-row b { color: var(--gray-900); font-weight: 700; }
.ps-due { color: var(--amber); font-weight: 700; }
.ps-done { color: var(--green); font-weight: 700; }
.ps-tax {
  margin-top: 8px; padding: 10px 12px; border-radius: 8px;
  background: var(--red-light); border: 1px solid rgba(239,68,68,0.2);
  font-size: 13px; color: var(--red-accent);
}
.ps-tax b { font-weight: 800; }
.ps-tax.ps-notax { background: var(--gray-100); border-color: var(--gray-200); color: var(--gray-600); }

.pay-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.pay-empty { font-size: 13px; color: var(--gray-400); text-align: center; padding: 14px 8px; line-height: 1.6; }
.pay-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--gray-100); border: 1px solid var(--gray-200);
  border-radius: 10px; padding: 8px 10px;
}
.pi-main { flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.pi-amt { font-size: 15px; font-weight: 700; color: var(--gray-900); }
.pi-date { font-size: 11px; color: var(--gray-400); }
.pi-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.pi-chip {
  font-size: 12px; font-weight: 600; color: var(--red-accent);
  background: rgba(239,68,68,.08); border-radius: 8px; padding: 6px 10px; white-space: nowrap;
}
.pi-chip.ghost { color: var(--gray-600); background: var(--gray-200); }
.pi-chip svg { width: 11px; height: 11px; vertical-align: -1px; margin-right: 3px; }
.pi-del {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  background: var(--gray-200); color: var(--gray-600); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.btn-add-pay {
  display: block; width: 100%; margin-top: 12px;
  background: transparent; color: var(--red-accent);
  border: 1.5px dashed rgba(252,129,129,0.4); border-radius: var(--radius-sm);
  padding: 12px; font-size: 14px; font-weight: 600; text-align: center;
}
.btn-add-pay:active { opacity: .8; }
.pay-form {
  margin-top: 12px; background: var(--gray-100);
  border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 4px 14px 14px;
}
.pay-form-title { font-size: 14px; font-weight: 700; color: var(--gray-900); padding: 12px 0 2px; }
.pay-form-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-top: 16px; }
.pay-form-actions .btn-outline { margin-top: 0; }
.link-btn {
  font-size: 12px; font-weight: 600; color: var(--red-accent);
  background: none; text-decoration: underline; margin-left: 8px;
}

/* ─── Help / คู่มือในแอป ─── */
.btn-help {
  display: flex; width: 100%; align-items: center; justify-content: center; gap: 8px;
  background: var(--red-light); color: var(--red-accent);
  border: 1px solid rgba(239,68,68,0.2); border-radius: var(--radius-sm);
  padding: 13px; font-size: 15px; font-weight: 600; margin-top: 12px;
}
.btn-help:active { opacity: .8; }
.btn-help svg { width: 18px; height: 18px; }
.help-intro { font-size: 13px; color: var(--gray-400); line-height: 1.6; padding: 4px 2px 14px; }
.help-item { border-bottom: 1px solid var(--gray-200); }
.help-item:first-of-type { border-top: 1px solid var(--gray-200); }
.help-q {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 15px 4px; font-size: 15px; font-weight: 600; color: var(--gray-900);
  cursor: pointer; list-style: none; -webkit-user-select: none; user-select: none;
}
.help-q::-webkit-details-marker { display: none; }
.help-chevron { color: var(--gray-400); font-size: 20px; flex-shrink: 0; transition: transform .2s; }
.help-item[open] .help-chevron { transform: rotate(90deg); }
.help-a { padding: 0 4px 16px; font-size: 14px; line-height: 1.75; color: var(--gray-700); }
.help-a b { color: var(--gray-900); font-weight: 700; }
.help-a .kbd {
  display: inline-block; background: var(--gray-200); color: var(--gray-900);
  border-radius: 5px; padding: 0 6px; font-weight: 700; font-size: 13px;
}
.help-a ul { margin: 6px 0 0; padding-left: 18px; }
.help-a li { margin-bottom: 4px; }
.help-warn { color: var(--amber); }

/* ─── Utilities ─── */
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--gray-200); margin: 16px 0; }
