/* ===== Thailand Tax Portal — Dark Mode ===== */
:root {
  --bg: #0b0f14;
  --bg-elevated: #121820;
  --bg-panel: #151c26;
  --bg-hover: #1a2330;
  --bg-input: #0e141c;
  --border: #243041;
  --border-soft: #1c2633;
  --text: #e8eef6;
  --text-muted: #8b9bb0;
  --text-dim: #5c6b7e;
  --accent: #3d9cf0;
  --accent-soft: rgba(61, 156, 240, 0.12);
  --accent-hover: #5aaff5;
  --success: #3ecf8e;
  --success-soft: rgba(62, 207, 142, 0.12);
  --warn: #f0b429;
  --warn-soft: rgba(240, 180, 41, 0.12);
  --danger: #f07178;
  --danger-soft: rgba(240, 113, 120, 0.12);
  --income: #3ecf8e;
  --deduction: #3d9cf0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --sidebar-w: 260px;
  /* หัวแบรนด์ซ้าย + topbar ขวา ใช้ความสูงเดียวกัน → เส้นคั่นตรงกันทุกหน้า */
  --app-header-h: 64px;
  --topbar-h: var(--app-header-h);
  --header-border: 1px solid var(--border-soft);
  --page-subnav-h: 54px;
  --page-sticky-offset: calc(var(--topbar-h) + var(--page-subnav-h) + 10px);
  /* ฟอนต์เดียวทั้งเว็บ — รวมตัวเลขในกรอบ/ตาราง/อินพุต */
  --font: "Google Sans", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  --mono: "Google Sans", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  --transition: 0.18s ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100dvh;
  overflow-x: hidden;
  font-feature-settings: "kern" 1, "liga" 1;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* บังคับฟอนต์เดียวกันทุกองค์ประกอบ (รวม input ตัวเลข / ตัวเลขในกรอบ) */
button,
input,
select,
textarea,
code,
.stat-value,
.panel-total,
.big-number,
.flow-val,
.bracket-rate,
.bracket-tax,
.recent-amount,
.data-table .num,
.auto-list li span:last-child,
.breakdown-row span:last-child {
  font-family: var(--font) !important;
}

/* subtle grid background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(61, 156, 240, 0.08), transparent 50%),
    radial-gradient(ellipse 60% 40% at 90% 100%, rgba(62, 207, 142, 0.05), transparent 45%);
  pointer-events: none;
  z-index: 0;
}

button,
input,
select,
textarea {
  font-family: var(--font);
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--accent);
}

code {
  font-family: var(--font);
  font-size: 0.85em;
  background: var(--bg-input);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
}

/* ===== Layout ===== */
.app {
  display: flex;
  min-height: 100dvh;
  position: relative;
  z-index: 1;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  /* Above .sidebar-overlay (45) when both are inside #appRoot */
  z-index: 50;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  will-change: transform;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  height: var(--app-header-h);
  min-height: var(--app-header-h);
  max-height: var(--app-header-h);
  padding: 0 12px 0 16px;
  flex-shrink: 0;
  border-bottom: var(--header-border);
  background: linear-gradient(
    180deg,
    rgba(61, 156, 240, 0.08) 0%,
    transparent 100%
  );
}

.sidebar-collapse-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.sidebar-collapse-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
  background: var(--bg-hover);
}

/* Desktop: พับเมนู → เนื้อหาเต็มจอ */
.app.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  box-shadow: none;
  pointer-events: none;
}

.app.sidebar-collapsed .main-wrap {
  margin-left: 0;
}

.app.sidebar-collapsed .content {
  max-width: none;
}

.app.sidebar-collapsed .menu-btn {
  background: var(--accent-soft);
  border-radius: 8px;
}

.app.sidebar-collapsed .menu-btn span {
  background: var(--accent);
}

.brand-home {
  flex: 1;
  min-width: 0;
  display: block;
  padding: 4px 6px 4px 2px;
  margin: -4px 0 -4px -2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
}

.brand-home:hover {
  background: var(--bg-hover);
}

.brand-home:focus-visible {
  outline: 2px solid rgba(61, 156, 240, 0.55);
  outline-offset: 1px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.brand-text strong {
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: #f4f8fc;
}

.brand-text span {
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-muted);
}

.nav {
  display: flex;
  flex-direction: column;
  /* เว้นระหว่างกลุ่ม / ภาพรวม — ภายในกลุ่มใช้ gap ของ .nav-group */
  gap: 10px;
  padding: 10px 10px 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ภาพรวม (อยู่นอกกลุ่ม) — ระยะชิดกับกลุ่มแรกพอดี */
.nav > .nav-item {
  margin: 0 2px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 1px; /* รายได้ / ลดหย่อน / จำลอง ชิดกันเป็นก้อน */
  margin-top: 0;
  padding: 5px 4px 5px;
  border-top: none;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.025);
}

.nav-group:first-of-type {
  margin-top: 0;
}

.nav-group-label {
  padding: 6px 10px 5px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.25;
  /* ไม่บังคับ uppercase — ไทยอ่านชัดกว่าเป็นตัวปกติ */
  text-transform: none;
  color: #c5d2e3;
  user-select: none;
}

/* Year chip — โชว์ปี + Edit · ไม่โชว์ select ตลอด */
.nav-tax-year {
  margin: 0 4px 3px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-tax-year-display {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-soft);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.nav-tax-year-display:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: rgba(61, 156, 240, 0.35);
}

.nav-tax-year.is-editing .nav-tax-year-display {
  border-style: solid;
  border-color: rgba(61, 156, 240, 0.4);
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-tax-year-value {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: inherit;
}

.nav-tax-year-edit {
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
}

.nav-tax-year-display:hover .nav-tax-year-edit {
  color: var(--accent);
  border-color: rgba(61, 156, 240, 0.35);
}

.nav-tax-year-editor {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 12px;
  margin: 0 2px;
  border-radius: 8px;
  border: 1px solid rgba(61, 156, 240, 0.3);
  background: var(--bg-input);
}

.nav-tax-year-editor[hidden] {
  display: none !important;
}

.nav-tax-year-editor select {
  flex: 1;
  min-width: 0;
  padding: 4px 2px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  outline: none;
}

.nav-tax-year-editor .btn {
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  /* ลด padding แนวตั้ง — เมนูในกลุ่มไม่ดูห่างจนแยกก้อน */
  padding: 7px 10px;
  min-height: 36px;
  box-sizing: border-box;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.88rem;
  line-height: 1.25;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.nav-group .nav-item {
  /* ในกลุ่ม: มุมมนน้อยลงเล็กน้อย ให้อ่านเป็นลิสต์ต่อเนื่อง */
  border-radius: 8px;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 0.92;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.nav-item > span:last-child {
  min-width: 0;
}

.sidebar-footer {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border-soft);
  margin-top: auto;
}

.sidebar-save-status {
  display: block;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-dim);
  line-height: 1.35;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}

/* ปกติใช้สีเดียวกับข้อความอื่น — ไม่เน้นเขียว */
.sidebar-save-status.linked {
  color: var(--text-dim);
}

.sidebar-save-status.error {
  color: var(--danger);
  cursor: pointer;
}

.sidebar-save-status.pending {
  color: var(--warn);
  cursor: pointer;
}

.year-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.year-picker label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.year-picker select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.privacy-note {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.45;
}

.privacy-note-tax {
  display: inline-block;
  margin-top: 6px;
  opacity: 0.9;
}

button.linkish {
  display: inline;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

button.linkish:hover {
  color: var(--text);
}

.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  transition: margin-left 0.22s ease;
}

.topbar {
  box-sizing: border-box;
  height: var(--app-header-h);
  min-height: var(--app-header-h);
  max-height: var(--app-header-h);
  display: flex;
  align-items: center;
  gap: 10px 14px;
  padding: 0 18px;
  border-bottom: var(--header-border);
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
  /* ไม่ wrap — กันความสูงเปลี่ยนตามหน้า → เส้นคั่นกับ brand เลื่อน */
  flex-wrap: nowrap;
  overflow: hidden;
}

.page-title {
  font-size: 1.2rem;
  font-weight: 750;
  flex: 0 0 auto;
  letter-spacing: -0.02em;
  line-height: 1.15;
  white-space: nowrap;
  color: #f4f8fc;
  min-width: 0;
  margin-right: 0;
}

.topbar-stats {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  margin-left: auto; /* ดันกล่องสถิติไปชิดขวา ห่างจากชื่อหน้า */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.topbar-stats::-webkit-scrollbar {
  display: none;
}

.topbar-stat-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-stat-group[hidden] {
  display: none !important;
}

/* topbar-stat: กระชับให้พอดีความสูง header คงที่ */
.topbar .topbar-stat {
  min-width: 7.5rem;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(61, 156, 240, 0.28);
  background: linear-gradient(
    155deg,
    rgba(61, 156, 240, 0.12) 0%,
    #121a24 60%
  );
  display: flex;
  flex-direction: column;
  gap: 1px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.topbar .topbar-stat > span {
  font-size: 0.68rem !important;
  font-weight: 650 !important;
  color: #b6c3d4 !important;
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.topbar .topbar-stat > strong {
  font-size: 1rem !important;
  font-weight: 750 !important;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  color: #f2f6fb !important;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.topbar .topbar-stat > strong.warn {
  color: #f0b429 !important;
}

.topbar .topbar-stat > strong.success {
  color: #3ecf8e !important;
}

.topbar .topbar-stat > strong.accent {
  color: #5aaff5 !important;
}

.topbar-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* legacy class ถ้ายังถูกอ้าง */
.file-status {
  font-size: 0.75rem;
  font-weight: 550;
  color: var(--text-dim);
}

@keyframes pulse-pending {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

.file-reconnect-banner {
  border-color: rgba(240, 180, 41, 0.45) !important;
  background: var(--warn-soft) !important;
  margin-bottom: 14px;
}

.storage-card {
  margin: 14px 0;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.storage-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 0.88rem;
}

.storage-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.storage-row strong {
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}

#settings-cloud .storage-row {
  align-items: center;
}

.cloud-token-fallback {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.cloud-token-fallback summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.cloud-token-fallback[open] summary {
  margin-bottom: 10px;
  color: var(--text);
}

#settings-cloud .checkbox-label {
  font-size: 0.88rem;
  color: var(--text);
  justify-content: flex-end;
  text-align: right;
}

.error-text {
  color: #f07178;
  margin-top: 8px;
}

#pwaModeBadge.is-app {
  color: var(--success);
}

/* PWA / notched phones: keep UI out of home indicator */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* เปิด drawer มือถือ: กันเลื่อนพื้นหลัง */
html.drawer-open,
html.drawer-open body {
  overflow: hidden;
  overscroll-behavior: none;
}

/* บัญชี Microsoft ไม่อยู่ใน allowlist */
.access-gate {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 12, 18, 0.92);
  backdrop-filter: blur(10px);
}

.access-gate[hidden] {
  display: none !important;
}

.access-gate-card {
  max-width: 420px;
  width: 100%;
  padding: 28px 24px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.access-gate-card h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 12px;
}

.access-gate-card code {
  font-size: 0.8em;
}

body.access-denied #appRoot {
  visibility: hidden;
  pointer-events: none;
}

/* Standalone (home-screen app): slightly tighter top chrome */
@media (display-mode: standalone) {
  .topbar {
    padding-top: max(10px, env(safe-area-inset-top));
  }
}

#cloudCard .storage-row:last-child {
  flex-wrap: wrap;
}

.storage-compare {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.storage-compare h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.storage-compare ul {
  padding-left: 1.2em;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.7;
}

.storage-compare strong {
  color: var(--text);
}

.menu-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  margin-left: -4px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}

.menu-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-soft);
}

.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.content {
  padding: 24px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  transition: max-width 0.22s ease;
}

/* ===== Views ===== */
.view {
  display: none;
  animation: fadeIn 0.2s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ===== สรุปตัวเลขหน้า (ชื่อหน้าอยู่ที่ topbar แล้ว — ไม่ซ้ำ) ===== */
.page-hero {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 10px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 0;
}

.page-hero-stats-only {
  justify-content: flex-end;
}

.page-hero-kicker,
.page-hero-desc,
.page-hero-title {
  display: none;
}

.page-hero-year {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 4px 8px 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.18);
  width: fit-content;
  max-width: 100%;
}

.page-hero-year label {
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.page-hero-year select {
  min-width: 0;
  width: auto;
  max-width: 9.5rem;
  padding: 3px 4px 3px 2px;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  outline: none;
}

.page-hero-year select:focus {
  color: var(--accent);
}

.page-hero-year-compact {
  margin-top: 10px;
}

/* แถบสรุป: จ่ายเพิ่ม / คืน — กระชับ */
.tax-outcome-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-panel);
}

.tax-outcome-strip .tos-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.tax-outcome-strip .tos-kicker {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.tax-outcome-strip .tos-outcome {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tax-outcome-strip .tos-meta {
  font-size: 0.75rem;
}

.tax-outcome-strip.tax-outcome-pay {
  border-color: rgba(240, 177, 41, 0.35);
  background: linear-gradient(135deg, rgba(240, 177, 41, 0.1), transparent 60%),
    var(--bg-panel);
}

.tax-outcome-strip.tax-outcome-pay .tos-outcome {
  color: var(--warn, #f0b129);
}

.tax-outcome-strip.tax-outcome-refund {
  border-color: rgba(62, 207, 142, 0.35);
  background: linear-gradient(135deg, rgba(62, 207, 142, 0.1), transparent 60%),
    var(--bg-panel);
}

.tax-outcome-strip.tax-outcome-refund .tos-outcome {
  color: var(--success);
}

.tax-outcome-strip.tax-outcome-even .tos-outcome {
  color: var(--text);
}

.tax-outcome-strip .tos-sim-btn {
  flex-shrink: 0;
}

/* จำลองภาษี */
.tax-sim-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.sim-goal-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 14px;
  align-items: start;
  margin-bottom: 12px;
}

.sim-goal-actions {
  grid-column: 1 / -1;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.sim-goal-results {
  margin-top: 4px;
}

.sim-goal-summary {
  margin-bottom: 10px;
  line-height: 1.45;
}

.sim-goal-table tr.is-partial {
  opacity: 0.85;
}

.sim-goal-table .warn-badge {
  background: rgba(240, 177, 41, 0.15);
  color: var(--warn, #f0b129);
}

.sim-scenario-list {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}

.sim-scenario-head {
  margin-bottom: 8px;
}

.sim-scenario-ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sim-scenario-ul li {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.sim-scenario-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sim-scenario-btn:hover {
  border-color: rgba(61, 156, 240, 0.4);
  background: var(--accent-soft);
}

@media (max-width: 900px) {
  .sim-goal-form {
    grid-template-columns: 1fr;
  }
}

.sim-room-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.sim-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.sim-chip:hover {
  border-color: rgba(61, 156, 240, 0.45);
  background: var(--accent-soft);
}

.sim-chip-label {
  font-size: 0.78rem;
  font-weight: 600;
}

.sim-chip-amt {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.sim-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sim-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.12);
}

.sim-row .field {
  margin: 0;
}

.sim-compare-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: stretch;
}

.sim-col {
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sim-col.is-sim {
  border-color: rgba(61, 156, 240, 0.35);
  background: rgba(61, 156, 240, 0.06);
}

.sim-col-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.2rem;
  padding: 0;
}

.sim-col-h {
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sim-metric {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
}

.sim-metric strong {
  font-variant-numeric: tabular-nums;
}

.sim-metric.sim-outcome-pay strong {
  color: var(--warn, #f0b129);
}

.sim-metric.sim-outcome-refund strong {
  color: var(--success);
}

.sim-save-block {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.12);
}

.sim-save-block.is-good {
  border-color: rgba(62, 207, 142, 0.3);
  background: rgba(62, 207, 142, 0.06);
}

.sim-save-block > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.sim-save-block strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.sim-callout {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  font-size: 0.86rem;
  line-height: 1.45;
}

.sim-callout-bracket {
  border-color: rgba(61, 156, 240, 0.35);
  background: rgba(61, 156, 240, 0.08);
}

.sim-callout-warn {
  border-color: rgba(240, 177, 41, 0.35);
  background: rgba(240, 177, 41, 0.08);
}

.sim-bracket-table .data-table tr.is-active td {
  color: var(--text);
  font-weight: 550;
}

@media (max-width: 900px) {
  .tax-sim-grid {
    grid-template-columns: 1fr;
  }
  .sim-compare-grid {
    grid-template-columns: 1fr;
  }
  .sim-col-arrow {
    display: none;
  }
  .sim-save-block {
    grid-template-columns: 1fr;
  }
  .sim-row {
    grid-template-columns: 1fr;
  }
}

.page-hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: stretch;
}

.mini-stat {
  min-width: 0;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.mini-stat span {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}

.mini-stat strong {
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.mini-stat strong.accent {
  color: var(--accent);
}

.mini-stat strong.warn {
  color: var(--warn);
}

.mini-stat strong.success {
  color: var(--success);
}

/* Insight หน้ารายการผ่อน */
.install-insight-block {
  margin-bottom: 14px;
  scroll-margin-top: var(--page-sticky-offset);
}

.install-insight-grid {
  margin-bottom: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.install-insight-grid-2 {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

/* หมวด (ซ้าย) vs ครบกำหนด (ขวา) — ไม่ยืดความสูงเท่ากัน */
.exp-cat-due-grid {
  align-items: start;
}

.exp-cat-due-grid > .panel {
  height: auto;
  align-self: start;
}

@media (max-width: 1100px) {
  .install-insight-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .install-insight-grid,
  .install-insight-grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ค่าใช้จ่าย — สรุป + due */
.exp-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}

.income-overview-block {
  margin: 0 0 4px;
}

.income-summary-strip .exp-sum-card strong {
  font-size: 1.15rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.income-summary-strip .exp-sum-card.is-accent strong {
  color: #c4b5fd;
}

/* ค่าลดหย่อน — แผงสิทธิ์ + กล่องอัตโนมัติ/หลังเพดาน */
.deduction-rights-extra {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

@media (max-width: 800px) {
  .deduction-rights-extra {
    grid-template-columns: 1fr;
  }
}

.exp-sum-card {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.exp-sum-card strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.exp-sum-card.is-accent {
  border-color: rgba(61, 156, 240, 0.35);
  background: rgba(61, 156, 240, 0.08);
}

.exp-due-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 40px;
  max-height: min(480px, 58vh);
  overflow-y: auto;
  padding-right: 2px;
}

.exp-due-month-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 4px 4px;
  margin-top: 4px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: var(--bg-panel, var(--bg-card, #12161c));
  z-index: 1;
}

.exp-due-month-head:first-child {
  margin-top: 0;
  padding-top: 0;
}

.exp-due-month-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.exp-due-month-sum {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.exp-due-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
  cursor: default;
}

.exp-due-row.is-install {
  border-color: rgba(251, 113, 133, 0.28);
  background: rgba(251, 113, 133, 0.05);
}

.exp-hub-note {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(61, 156, 240, 0.06);
  line-height: 1.45;
}

/* ฟอร์มจ่ายผ่อน · ดอกเบี้ยบ้าน */
.install-pay-modal {
  max-width: 480px;
  width: min(480px, 96vw);
}

.inst-home-interest-banner {
  margin-top: 12px;
}

.inst-home-int-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#installPayKindToggle {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

#installPayKindToggle .mode-btn {
  flex: 1;
  min-width: 120px;
}

.exp-due-date {
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.exp-due-date.is-soon {
  color: var(--warn);
}

.exp-due-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.exp-due-meta strong {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exp-due-amt {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--warn);
  flex-shrink: 0;
}

.due-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--warn);
  background: rgba(232, 119, 34, 0.12);
  vertical-align: middle;
}

.due-badge.due-done {
  color: var(--success);
  background: rgba(62, 207, 142, 0.12);
}

.btn-pay-exp {
  flex-shrink: 0;
  font-size: 0.78rem !important;
  padding: 4px 8px !important;
  color: var(--success) !important;
  border-color: rgba(62, 207, 142, 0.35) !important;
}

/* ความครอบคลุมเงินสำรอง — ตารางกระชับ */
.exp-coverage-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.cov-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
  min-width: 88px;
}

.cov-chip strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.cov-chip.is-ok {
  border-color: rgba(62, 207, 142, 0.3);
  background: rgba(62, 207, 142, 0.06);
}

.cov-chip.is-warn {
  border-color: rgba(232, 119, 34, 0.3);
  background: rgba(232, 119, 34, 0.06);
}

.exp-coverage-list {
  display: block;
  min-height: 24px;
  max-height: min(360px, 48vh);
  overflow: auto;
}

.exp-coverage-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 520px;
}

.exp-coverage-tr {
  display: grid;
  grid-template-columns: minmax(140px, 1.6fr) minmax(72px, 0.7fr) minmax(72px, 0.7fr) minmax(100px, 1fr) minmax(64px, 0.55fr);
  gap: 8px 12px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.82rem;
  cursor: default;
}

.exp-coverage-tr:last-child {
  border-bottom: none;
}

.exp-coverage-tr.is-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-panel, var(--bg-card, #12161c));
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-top: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
}

.exp-coverage-tr.is-gap {
  background: rgba(232, 119, 34, 0.04);
}

.exp-coverage-tr.is-ok {
  background: rgba(62, 207, 142, 0.03);
}

.cov-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.cov-name strong {
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cov-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  vertical-align: middle;
  color: var(--accent);
  background: rgba(61, 156, 240, 0.14);
}

.cov-tag-dca {
  color: #059669;
  background: rgba(52, 211, 153, 0.18);
}

.recurring-row.is-dca {
  border-color: rgba(52, 211, 153, 0.28);
  background: rgba(52, 211, 153, 0.04);
}

.recurring-row.is-home-loan {
  border-color: rgba(251, 113, 133, 0.25);
  background: rgba(251, 113, 133, 0.04);
}

.cov-num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cov-bar-cell {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.cov-mini-bar {
  height: 6px !important;
  min-height: 6px;
}

.cov-pct {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 2.4em;
  text-align: right;
}

.cov-gap-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  white-space: nowrap;
}

.cover-gap {
  color: var(--warn);
  font-weight: 600;
}

.cover-ok {
  color: var(--success);
  font-weight: 600;
}

@media (max-width: 700px) {
  .exp-coverage-list {
    max-height: min(420px, 55vh);
  }
}

/* ค่าใช้จ่ายประจำ — visualization */
.exp-viz-grid {
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
  gap: 20px 28px;
  align-items: start;
}

.exp-viz-side {
  min-width: 0;
}

.exp-viz-side .exp-month-chart {
  margin-top: 2px;
}

.exp-viz-side .exp-month-scale-note {
  padding-left: 40px;
}

.exp-viz-sub {
  margin: 0 0 8px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.exp-viz-sub-note {
  font-weight: 500;
  opacity: 0.75;
  font-size: 0.92em;
}

.exp-donut-wrap {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 0 auto 12px;
}

.exp-donut-wrap .asset-donut,
.exp-donut-wrap .share-donut-host {
  width: 180px;
  height: 180px;
}

/* SVG โดนัทสัดส่วน (เงินออก) — มุมตามยอดจริง */
.share-donut-host {
  position: relative;
  border-radius: 50%;
  overflow: visible;
  border: none;
  background: transparent;
}

.share-donut-host[data-share-ready="1"] {
  background: transparent;
}

.share-donut-host:not([data-share-ready="1"]) {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
}

.share-donut-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.share-donut-seg {
  transition: opacity 0.12s ease, filter 0.12s ease;
  stroke: var(--bg-panel);
  stroke-width: 0.6;
}

.share-donut-host:hover .share-donut-seg {
  opacity: 0.72;
}

.share-donut-seg:hover {
  opacity: 1 !important;
  filter: brightness(1.08);
}

.share-donut-pct {
  fill: #f4f7fb;
  font-size: 7px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  paint-order: stroke;
  stroke: rgba(11, 15, 20, 0.75);
  stroke-width: 0.8px;
  pointer-events: none;
}

.exp-donut-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.exp-legend-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.82rem;
  cursor: default;
}

.exp-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.exp-legend-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exp-legend-val {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ช่องทางจ่าย — stacked 100% (ชิ้นต่อกันเต็มแท่ง) */
.exp-pay-stack-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exp-pay-stack {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 22px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-soft);
}

.exp-pay-seg {
  position: relative;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: filter 0.12s ease, opacity 0.12s ease;
}

.exp-pay-stack:hover .exp-pay-seg {
  opacity: 0.72;
}

.exp-pay-seg:hover {
  opacity: 1 !important;
  filter: brightness(1.1);
}

.exp-pay-seg-label {
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #f4f7fb;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  white-space: nowrap;
}

.exp-pay-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.exp-vs-income {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exp-vs-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exp-vs-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.84rem;
}

.exp-vs-labels .warn {
  color: var(--warn);
}

/* ชาร์ต 12 เดือน + แกน Y / เส้น grid / เส้นอ้างอิง */
.exp-month-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.exp-month-chart-inner {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
}

.exp-month-yaxis {
  position: relative;
  /* ความสูงเท่า plot (bar area) — ไม่รวม label เดือน */
  height: 120px;
  margin-top: 0;
  flex-shrink: 0;
}

.exp-month-ytick {
  position: absolute;
  right: 0;
  transform: translateY(50%);
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

.exp-month-plot {
  position: relative;
  min-width: 0;
}

.exp-month-grid {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 120px;
  pointer-events: none;
  z-index: 0;
}

.exp-month-gridline {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  transform: translateY(50%);
}

.exp-month-gridline.is-max {
  border-top-style: solid;
  border-top-color: rgba(255, 255, 255, 0.14);
}

.exp-month-refline {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1.5px dashed rgba(240, 180, 41, 0.65);
  transform: translateY(50%);
  z-index: 1;
}

.exp-month-refline.is-avg {
  border-top-color: rgba(167, 139, 250, 0.75);
}

.exp-month-refline.is-income {
  border-top-color: rgba(52, 211, 153, 0.7);
}

.exp-month-reflabel {
  position: absolute;
  right: 2px;
  top: -1.05em;
  font-size: 0.6rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0.9;
}

.exp-month-refline.is-avg .exp-month-reflabel {
  color: #c4b5fd;
}

.exp-month-refline.is-income .exp-month-reflabel {
  color: #6ee7b7;
}

.exp-month-scale-note {
  margin: 0;
  padding-left: 46px;
  font-size: 0.72rem;
}

.exp-month-bars {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
  padding: 0;
}

.exp-month-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  cursor: default;
}

.exp-month-bar-wrap {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-sizing: border-box;
}

.exp-month-bar {
  width: 70%;
  max-width: 28px;
  min-height: 0;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #f0b429, #e87722);
  transition: height 0.2s ease;
}

.exp-month-col.is-empty .exp-month-bar {
  background: rgba(255, 255, 255, 0.08);
  height: 3px !important;
  min-height: 3px;
}

.exp-month-col.is-hot .exp-month-bar,
.exp-month-col.has-chart-tip.is-hot .exp-month-bar {
  filter: brightness(1.12);
}

.exp-month-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

.exp-month-amt {
  font-size: 0.62rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .exp-month-chart-inner {
    grid-template-columns: 32px minmax(0, 1fr);
  }
  .exp-month-scale-note {
    padding-left: 36px;
  }
  .exp-month-reflabel {
    display: none;
  }
}

@media (max-width: 900px) {
  .exp-viz-grid {
    grid-template-columns: 1fr;
  }
  .exp-donut-wrap {
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 600px) {
  .exp-month-amt {
    display: none;
  }
}

.locked-amt {
  color: #fb923c !important;
}

.cash-lock-tag {
  color: #fb923c;
  font-weight: 600;
}

.cash-free-tag {
  color: #34d399;
  font-weight: 600;
}

/* สภาพคล่องเงินสด — ใช้ .portfolio-mega เหมือนองค์ประกอบพอร์ต */
.cash-liq-mega {
  margin-top: 2px;
}

/* สรุปสภาพคล่อง: รวม / ใช้ได้ / ล็อก — จัดเป็นชิปอ่านง่าย */
.liq-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.liq-sum-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
}

.liq-sum-item.is-free {
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.07);
}

.liq-sum-item.is-lock {
  border-color: rgba(251, 146, 60, 0.4);
  background: rgba(251, 146, 60, 0.08);
}

.liq-sum-item.is-warn {
  border-color: rgba(240, 113, 120, 0.45);
  background: rgba(240, 113, 120, 0.08);
}

.liq-sum-item.is-solo {
  grid-column: 1 / -1;
}

.liq-sum-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.liq-sum-val {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  word-break: break-word;
}

.liq-sum-item.is-free .liq-sum-val {
  color: var(--success, #34d399);
}

.liq-sum-item.is-lock .liq-sum-val {
  color: #fb923c;
}

.liq-sum-item.is-warn .liq-sum-val {
  color: var(--danger, #f07178);
}

.liq-sum-pct {
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.liq-sum-item.is-free .liq-sum-pct {
  color: rgba(52, 211, 153, 0.9);
}

.liq-sum-item.is-lock .liq-sum-pct {
  color: rgba(251, 146, 60, 0.95);
}

@media (max-width: 520px) {
  .liq-summary {
    grid-template-columns: 1fr;
  }
}

.asset-liq-grid .panel-head {
  margin-bottom: 8px;
}

.asset-liq-grid .panel-head h2 {
  margin: 0;
}

.cash-liq-account {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
  cursor: default;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cash-liq-account.is-usd {
  border-color: rgba(34, 211, 238, 0.28);
}

.cash-liq-account.is-over {
  border-color: rgba(240, 113, 120, 0.45);
  background: rgba(240, 113, 120, 0.06);
}

.cash-liq-acc-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
  margin-bottom: 0;
  min-width: 0;
}

.cash-liq-acc-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 0.84rem;
}

.cash-liq-acc-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.cash-liq-acc-vals {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
}

.cash-liq-acc-bar {
  display: flex;
  height: 7px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 0;
}

.cash-liq-acc-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.cash-free-txt {
  color: #34d399;
  font-weight: 600;
}

.cash-lock-txt {
  color: #fb923c;
  font-weight: 600;
}

.cov-tag-fcd {
  color: #0891b2;
  background: rgba(34, 211, 238, 0.14);
}

.roadmap-notes li {
  margin: 0 0 6px;
  line-height: 1.45;
}

.roadmap-notes li:last-child {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .exp-summary-strip {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .exp-due-row {
    grid-template-columns: 1fr auto;
  }
  .exp-due-date {
    grid-column: 1 / -1;
  }
}

.inst-bar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40px;
}

.inst-bar-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inst-bar-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  font-size: 0.84rem;
}

.inst-bar-label {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inst-bar-val {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--text-muted);
  flex-shrink: 0;
}

.inst-bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.inst-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e87722, #f0b429);
}

#instInsightByCardRemain .inst-bar-fill {
  background: linear-gradient(90deg, #3d9cf0, #6bb8ff);
}

/* ความคืบหน้าปิดผ่อน — compact · แยกบัตรชัด แต่กินพื้นที่น้อย */
.inst-card-progress-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  align-items: start;
}

.inst-card-progress-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

@media (max-width: 720px) {
  .inst-card-progress-list {
    grid-template-columns: 1fr;
  }
}

.inst-prog-card {
  --prog-accent: var(--accent);
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 8px 10px 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--prog-accent);
  background: var(--bg-input);
  cursor: default;
}

.inst-prog-card.is-done {
  border-left-color: var(--success);
  opacity: 0.88;
}

.inst-prog-card-head {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.inst-prog-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-top: 5px;
  flex-shrink: 0;
}

.inst-prog-card-title-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.inst-prog-card-title-text strong {
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inst-prog-meta {
  font-size: 0.7rem;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.inst-prog-meta em {
  font-style: normal;
  color: var(--warn);
  font-weight: 650;
}

.inst-prog-card-pct {
  flex-shrink: 0;
  font-size: 0.88rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  padding-top: 1px;
}

.inst-card-progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.inst-card-progress-fill {
  height: 100%;
  border-radius: inherit;
  min-width: 0;
  transition: width 0.2s ease;
}

.inst-prog-items {
  list-style: none;
  margin: 1px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inst-prog-items li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 0;
  font-size: 0.72rem;
  line-height: 1.3;
  border: none;
  background: none;
}

.inst-prog-item-name {
  font-weight: 550;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.inst-prog-item-meta {
  flex-shrink: 0;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#instInsightRecurring .inst-bar-fill {
  background: linear-gradient(90deg, #9b6dff, #c4a8ff);
}

.install-total-out.strip-stat {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(232, 119, 34, 0.08);
}

.install-total-out.strip-stat strong {
  display: block;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.empty-inline[hidden] {
  display: none !important;
}

/* รายจ่ายประจำ — จัดกลุ่มตามหมวด */
.recurring-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.recurring-cat-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recurring-cat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 2px 2px 4px;
  border-bottom: 1px solid var(--border-soft);
}

.recurring-cat-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.recurring-cat-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.recurring-cat-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.recurring-cat-meta {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.recurring-cat-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recurring-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
}

.recurring-row.is-inactive {
  opacity: 0.55;
}

.recurring-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.recurring-meta strong {
  font-size: 0.9rem;
  font-weight: 650;
}

.recurring-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--warn);
  flex-shrink: 0;
  text-align: right;
}

/* บัตรของฉัน (รายการผ่อน) */
.my-cards-layout {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(220px, 1fr);
  gap: 16px;
  align-items: start;
}

.my-cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.my-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
}

.my-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.my-card-meta strong {
  font-size: 0.9rem;
  font-weight: 650;
}

@media (max-width: 800px) {
  .my-cards-layout {
    grid-template-columns: 1fr;
  }
}

/* sticky ใต้ topbar — กดแล้วกระโดดไปส่วนยาว ๆ (โดยเฉพาะหน้าสินทรัพย์) */
.page-subnav {
  position: sticky;
  top: var(--topbar-h);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin: 0 0 16px;
  /* บน–ล่างเท่ากัน (เดิม 8px ดูเฉียงเพราะ line-height ปุ่ม + border hover) */
  padding: 10px 0;
  background: linear-gradient(
    to bottom,
    rgba(11, 15, 20, 0.96) 70%,
    rgba(11, 15, 20, 0.88)
  );
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}

.page-subnav::-webkit-scrollbar {
  display: none;
}

.page-subnav-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* ไม่สืบทอด line-height 1.55 จาก body — ไม่งั้นกรอบ hover ดูเว้นบนน้อย / ล่างมาก */
  line-height: 1.2;
  padding: 0 14px;
  min-height: 34px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid transparent;
  background: transparent;
  box-sizing: border-box;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.page-subnav-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border-soft);
}

.page-subnav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(61, 156, 240, 0.35);
  font-weight: 600;
}

/* แท็บซ้าย + ปุ่ม action ขวา (เช่น หน้าค่าใช้จ่าย) */
.page-subnav-split {
  justify-content: space-between;
  gap: 10px 14px;
  overflow: visible;
}

.page-subnav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.page-subnav-tabs::-webkit-scrollbar {
  display: none;
}

.page-subnav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.page-subnav-actions .btn {
  white-space: nowrap;
}

@media (max-width: 560px) {
  .page-subnav-split {
    flex-wrap: wrap;
  }
  .page-subnav-tabs {
    order: 2;
    width: 100%;
  }
  .page-subnav-actions {
    order: 1;
    width: 100%;
    justify-content: flex-end;
  }
}

/* กันหัวข้อถูก sticky nav บังตอน scroll-to */
[id="assets-overview"],
[id="assets-funds"],
[id="assets-equity"],
[id="assets-manage"],
[id="income-form"],
[id="income-overview"],
[id="income-list"],
[id="deduction-form"],
[id="deduction-rights"],
[id="deduction-list"],
[id="install-form"],
[id="install-list"],
[id="exp-insight"],
[id="exp-due"],
[id="exp-list"],
[id="reserve-panel"],
[id="settings-profile"],
[id="settings-storage"],
[id="settings-backup"] {
  scroll-margin-top: var(--page-sticky-offset);
}

.section-anchor-title {
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 8px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}

/* ===== Dashboard sections — แบ่งโซนชัด ลดลายตา ===== */
.dash-section {
  margin: 0 0 28px;
  padding: 0 0 8px;
  scroll-margin-top: var(--page-sticky-offset);
}

.dash-section + .dash-section {
  margin-top: 8px;
  padding-top: 22px;
  border-top: 1px solid var(--border-soft);
}

.dash-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 0 0 14px;
}

.dash-section-kicker {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 4px;
}

.dash-section-title {
  font-size: 1.2rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: #f2f6fb;
  margin: 0;
  line-height: 1.2;
}

.dash-section-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
  max-width: 36ch;
  line-height: 1.4;
  text-align: right;
}

.dash-section .insight-panel {
  margin-bottom: 0;
}

.dash-section .stat-grid,
.dash-section .panel-grid {
  margin-bottom: 14px;
}

.dash-section .panel-grid:last-child,
.dash-section .stat-grid:last-child {
  margin-bottom: 0;
}

.dash-subnav {
  margin-bottom: 16px;
}

@media (max-width: 640px) {
  .dash-section-desc {
    text-align: left;
    max-width: none;
  }
  .dash-section-title {
    font-size: 1.1rem;
  }
}

/* ===== Stats ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-grid-5 {
  grid-template-columns: repeat(5, 1fr);
}

.stat-grid-tax {
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 20px;
}

.stat-card.refund {
  border-color: rgba(62, 207, 142, 0.4);
  background: linear-gradient(160deg, var(--bg-panel), rgba(62, 207, 142, 0.08));
}

.stat-value.success {
  color: var(--success);
}

/* calc flow */
.calc-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px 6px;
}

.flow-step {
  flex: 1 1 120px;
  min-width: 110px;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.flow-step.highlight {
  border-color: rgba(61, 156, 240, 0.35);
  background: var(--accent-soft);
}

.flow-step.highlight.warn {
  border-color: rgba(240, 180, 41, 0.4);
  background: var(--warn-soft);
}

.flow-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.3;
}

.flow-val {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

.flow-val.accent { color: var(--accent); }
.flow-val.warn { color: var(--warn); }
.flow-val.success { color: var(--success); }

.flow-op {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 1.1rem;
  min-width: 18px;
  padding: 0 2px;
}

.panel-total-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.field-help {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.35;
}

.disclaimer ol {
  padding-left: 1.2em;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.7;
  margin-bottom: 12px;
}

.disclaimer ol strong {
  color: var(--text);
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card.highlight {
  border-color: rgba(240, 180, 41, 0.35);
  background: linear-gradient(160deg, var(--bg-panel), rgba(240, 180, 41, 0.06));
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-family: var(--font);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

.stat-value.accent { color: var(--accent); }
.stat-value.warn { color: var(--warn); }

/* บรรทัดรองใต้ยอดหลัก เช่น % กำไร/ขาดทุน */
.stat-value-sub {
  display: block;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.2;
  margin-top: -2px;
}

.stat-value-sub.success {
  color: var(--success, #3ecf8e);
}

.stat-value-sub.warn {
  color: var(--warn);
}

.stat-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ===== Panels ===== */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

.panel-head h3,
.allowance-box h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.panel-total {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.panel-total.accent { color: var(--accent); }

/* สรุปยอดเหนือตาราง (รายได้ ฯลฯ) */
.table-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.14);
}

.table-summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 2px 4px;
}

.table-summary-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.table-summary-value {
  font-size: 0.95rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  color: var(--text);
}

.table-summary-item.is-projected .table-summary-value {
  color: #c4b5fd;
}

@media (max-width: 700px) {
  .table-summary {
    grid-template-columns: 1fr 1fr;
  }
}

.panel-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
  margin-bottom: 4px;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}

.form-panel { position: sticky; top: calc(var(--topbar-h) + 16px); }

/* ===== Forms ===== */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* สำคัญ: .form { display:flex } ทับ hidden ของเบราว์เซอร์ — ต้องบังคับซ่อน */
[hidden],
.form[hidden],
.field[hidden],
.hint-box[hidden] {
  display: none !important;
}

.mode-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  padding: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}

.mode-btn {
  flex: 1;
  padding: 10px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  text-align: center;
  line-height: 1.35;
}

.mode-btn small {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.85;
  margin-top: 2px;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.mode-toggle-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mode-toggle-3 .mode-btn small {
  font-size: 0.68rem;
}

.form-projected {
  padding-top: 4px;
}

.mode-explain {
  margin-bottom: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.mode-explain strong {
  color: var(--text);
}

.form-payslip {
  padding-top: 4px;
  border-top: 1px solid rgba(61, 156, 240, 0.2);
}

/* แท็กสถานะแถว: Projected / Payslip — ชัด อ่านง่าย */
.tag-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin-left: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.03em;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.tag-projected {
  background: linear-gradient(135deg, #6d28d9, #7c3aed);
  color: #f5f3ff;
  border: 1px solid rgba(196, 181, 253, 0.55);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.tag-payslip {
  background: linear-gradient(135deg, #0369a1, #0284c7);
  color: #e0f2fe;
  border: 1px solid rgba(125, 211, 252, 0.45);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

/* รองรับ class เก่า */
.badge-projected {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 750;
  background: linear-gradient(135deg, #6d28d9, #7c3aed);
  color: #f5f3ff;
  border: 1px solid rgba(196, 181, 253, 0.55);
}

tr.is-projected td {
  background: rgba(124, 58, 237, 0.07);
}

tr.is-projected td:first-child {
  box-shadow: inset 3px 0 0 #8b5cf6;
}

.proj-salary-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.proj-salary-meta {
  line-height: 1.5;
  padding: 8px 0;
}

@media (max-width: 900px) {
  .proj-salary-form {
    grid-template-columns: 1fr 1fr;
  }
}

.badge.payslip {
  background: var(--warn-soft);
  color: var(--warn);
  margin-left: 4px;
}

/* Cap usage bars */
.cap-bars {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cap-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cap-head,
.cap-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.82rem;
}

.cap-label {
  font-weight: 500;
  color: var(--text);
}

.cap-nums {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}

.cap-bar-track {
  height: 8px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

.cap-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #5aaff5);
  border-radius: 99px;
  transition: width 0.35s ease;
  min-width: 0;
}

.cap-row.cap-full .cap-bar-fill {
  background: linear-gradient(90deg, var(--warn), #f5c842);
}

.cap-foot {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.cap-remain {
  color: var(--success);
  font-weight: 500;
  white-space: nowrap;
}

.cap-remain.is-full {
  color: var(--warn);
}

.live-cap {
  border-color: rgba(61, 156, 240, 0.35);
}

.live-cap-full {
  border-color: rgba(240, 180, 41, 0.45);
  background: var(--warn-soft);
}

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* Projection table */
.proj-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.proj-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border-soft);
  align-items: center;
}

.proj-row:last-child {
  border-bottom: none;
}

.proj-row span:nth-child(2),
.proj-row span:nth-child(3) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.proj-head {
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.proj-val {
  font-weight: 600;
}

.proj-val.warn { color: var(--warn); }
.proj-val.success { color: var(--success); }

.proj-emphasis {
  background: var(--accent-soft);
  font-weight: 500;
}

@media (max-width: 560px) {
  .proj-row {
    grid-template-columns: 1fr 1fr;
    gap: 4px 8px;
  }
  .proj-row span:first-child {
    grid-column: 1 / -1;
    font-weight: 500;
    margin-bottom: 2px;
  }
  .proj-head span:first-child {
    display: none;
  }
}

/* Installments */
.form-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .form-inline {
    grid-template-columns: 1fr;
  }
}

/* รายการผ่อน | ตัดบัตร ซ้าย–ขวา */
.install-lists-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 900px) {
  .install-lists-split {
    grid-template-columns: 1fr;
  }
}

/* timeline รอบชำระบัตร — คอลัมน์ตามเดือน */
.inst-due-timeline {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

@media (max-width: 720px) {
  .inst-due-timeline {
    grid-template-columns: 1fr;
  }
}

.inst-due-month {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
}

.inst-due-month.is-empty {
  opacity: 0.65;
}

.inst-due-month-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
}

.inst-due-month-head strong {
  font-size: 0.92rem;
  font-weight: 700;
}

.inst-due-month-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 40px;
}

.inst-due-empty-m {
  margin: 4px 0 0;
  font-size: 0.75rem;
}

.inst-due-chip {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--chip-color, var(--accent));
  background: var(--bg-input);
  cursor: default;
  min-width: 0;
}

.inst-due-chip.is-soon {
  border-color: rgba(240, 180, 41, 0.45);
  background: rgba(240, 180, 41, 0.08);
}

.inst-due-chip.is-stmt {
  opacity: 0.85;
}

.inst-due-chip-day {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: #fff;
  background: var(--chip-color, var(--accent));
}

.inst-due-chip-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.inst-due-chip-main strong {
  font-size: 0.82rem;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inst-due-chip-amt {
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--warn);
  white-space: nowrap;
}

.install-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.install-card {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.install-card.done {
  opacity: 0.88;
  border-color: rgba(62, 207, 142, 0.25);
}

.install-card.closed-early {
  border-color: rgba(61, 156, 240, 0.35);
}

.install-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
}

.install-check input {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  accent-color: var(--success);
  flex-shrink: 0;
}

.install-check span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.install-check small {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 400;
  line-height: 1.4;
}

.install-form-check {
  padding-top: 0 !important;
}

.badge-active {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-done {
  background: var(--success-soft);
  color: var(--success);
}

.install-card-recurring {
  border-color: rgba(61, 156, 240, 0.35);
  background: rgba(61, 156, 240, 0.04);
}

.badge-recurring {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--accent);
  background: rgba(61, 156, 240, 0.14);
  vertical-align: middle;
}

.badge-early {
  background: var(--accent-soft);
  color: var(--accent);
}

.cap-bar-fill.early {
  background: linear-gradient(90deg, var(--accent), #5aaff5);
}

.btn-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== Asset visualizations ===== */
.stat-grid-assets {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 16px;
}

.asset-viz-grid {
  margin-bottom: 16px;
  align-items: start;
}

/* คอลัมน์ขวา: เงินสดแยกธนาคาร + มูลค่ากองทุนแยกตามแอป ซ้อนแนวตั้ง */
.asset-viz-right-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.asset-viz-right-stack > .panel {
  margin-bottom: 0;
  min-width: 0;
}

.asset-viz-right-stack .portfolio-mega-bar {
  height: 48px;
}



/* เงินสดใช้ได้/ล็อก (ซ้าย) + สภาพคล่องกองทุน (ขวา) */
.asset-liq-grid {
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

.asset-liq-grid > .panel {
  margin-bottom: 0;
  min-width: 0;
}

.asset-liq-grid .portfolio-mega-bar {
  height: 48px;
}

.asset-liq-grid .portfolio-stack-legend,
.asset-liq-grid .portfolio-legend-block {
  font-size: 0.86rem;
}

@media (max-width: 900px) {
  .asset-liq-grid {
    grid-template-columns: 1fr;
  }

  .asset-viz-grid {
    grid-template-columns: 1fr;
  }

  .asset-viz-right-stack {
    width: 100%;
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  .liq-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .liq-summary {
    grid-template-columns: 1fr;
  }

  .stat-grid-assets {
    grid-template-columns: 1fr 1fr;
  }
}

.asset-donut-wrap {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 8px auto 16px;
}

.asset-donut {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  /* conic-gradient set by JS */
}

/* ไอคอนบนวงโดนัท (กลางแต่ละชิ้น) */
.asset-donut-icons {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.donut-seg-ico {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
  background: rgba(11, 15, 20, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* ไอคอนในแท่งกราฟ */
.asset-bar-fill.has-ico,
.cap-bar-fill.has-ico,
.cf-bar-fill.has-ico,
.inst-bar-fill.has-ico {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-width: 1.4rem;
  padding-left: 4px;
  box-sizing: border-box;
  overflow: hidden;
}

.bar-ico-in {
  flex-shrink: 0;
  font-size: 0.78rem;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
  opacity: 0.95;
}

.bar-ico-in.bar-ico-bank {
  display: inline-flex;
  transform: scale(0.85);
  transform-origin: left center;
}

.bar-ico-in.bar-ico-bank .bank-logo,
.bar-ico-in.bar-ico-bank .bank-mono {
  font-size: 0.65rem !important;
}

.mega-group-ico {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  font-size: 0.95rem;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
  opacity: 0.95;
}

.asset-donut-center {
  position: absolute;
  /* วงในกว้างขึ้นเล็กน้อย ใส่ตัวเลขใหญ่ได้ */
  inset: 24%;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  text-align: center;
  padding: 6px 8px;
  overflow: hidden;
  box-sizing: border-box;
  z-index: 3;
}

.asset-donut-center .muted {
  font-size: 0.68rem;
  line-height: 1.1;
  flex-shrink: 0;
}

.asset-donut-center strong {
  font-size: 0.82rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  /* ห้ามตัดกลางตัวเลข / ขึ้นบรรทัดพัง */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  letter-spacing: -0.02em;
}

/* ตัวเลขยาวมาก (ล้าน+) — ย่อฟอนต์อัตโนมัติจาก class ที่ JS ใส่ */
.asset-donut-center strong.is-compact {
  font-size: 0.72rem;
}

.asset-donut-center strong.is-tiny {
  font-size: 0.64rem;
}

/* legend โดนัท — ใช้ portfolio-legend พับรายการย่อย */
.asset-donut-legend {
  margin-top: 4px;
  max-height: min(420px, 55vh);
  overflow-y: auto;
  padding-right: 2px;
}

.asset-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.asset-legend-row {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: 8px 10px;
  align-items: center;
  font-size: 0.85rem;
}

.asset-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.asset-legend-row .pct {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

.asset-legend-row .val {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  text-align: right;
  min-width: 72px;
}

.asset-bar-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.asset-bar-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.asset-bar-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
}

.asset-bar-head strong {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.asset-bar-track {
  height: 10px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

.asset-bar-fill {
  height: 100%;
  border-radius: 99px;
  min-width: 2px;
  transition: width 0.4s ease;
}

/* แท่งใหญ่ก้อนเดียว: กลุ่มประเภท + ย่อยรายการข้างใน */
.portfolio-mega {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portfolio-mega-bar {
  display: flex;
  width: 100%;
  height: 56px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-input);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.portfolio-mega-group {
  position: relative;
  display: flex;
  height: 100%;
  min-width: 3px;
  overflow: hidden;
  /* ขอบกลุ่ม = แยกประเภทชัด */
  box-shadow: inset -2px 0 0 rgba(11, 15, 20, 0.55);
}

.portfolio-mega-group:last-child {
  box-shadow: none;
}

.portfolio-mega-item {
  position: relative;
  height: 100%;
  min-width: 2px;
  transition: width 0.3s ease, filter 0.15s ease;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ป้าย % / เงิน บนแท่ง — เฉพาะชิ้น/กลุ่มที่กว้างพอ */
.portfolio-mega-seg-label,
.portfolio-mega-group-label {
  pointer-events: none;
  z-index: 2;
  color: #f8fafc;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  padding: 0 4px;
}

.portfolio-mega-seg-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.78rem;
  font-weight: 700;
}

.portfolio-mega-seg-label b {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.portfolio-mega-seg-label i {
  font-style: normal;
  font-weight: 700;
  opacity: 0.98;
  font-size: 0.78rem;
}

.portfolio-mega-group-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.8rem;
  font-weight: 700;
}

.portfolio-mega-group-label b {
  font-size: 0.88rem;
  font-weight: 800;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.portfolio-mega-group-label span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  font-size: 0.8rem;
  font-weight: 700;
}

.portfolio-mega-item:hover,
.portfolio-mega-group:hover {
  filter: brightness(1.1);
}

.portfolio-mega-item.is-hot,
.portfolio-mega-group.is-hot {
  filter: brightness(1.18);
  outline: 1px solid rgba(255, 255, 255, 0.35);
  outline-offset: -1px;
  z-index: 1;
}

/* Tooltip กราฟ / สรุปด่วน — อยู่บน body เสมอ */
.chart-tooltip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 24px));
  max-height: min(70vh, 440px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 14px;
  border-radius: 10px;
  background: #1a2330;
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text);
  transform: translate(-50%, calc(-100% - 12px));
  left: 0;
  top: 0;
  box-sizing: border-box;
}

.chart-tooltip[hidden],
.chart-tooltip[style*="display: none"] {
  display: none !important;
}

.chart-tooltip.is-below::after {
  top: -6px;
  bottom: auto;
  border-top-color: transparent;
  border-bottom-color: #1a2330;
}

.chart-tooltip .tt-type {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.chart-tooltip .tt-name {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 8px;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.chart-tooltip .tt-row {
  display: grid;
  grid-template-columns: minmax(4.2rem, 28%) minmax(0, 1fr);
  gap: 8px 12px;
  align-items: start;
  padding: 4px 0;
  border-top: 1px solid var(--border-soft);
  font-size: 0.82rem;
}

/* หลายบรรทัด (รอบซื้อ): label บน · ข้อความเต็มความกว้าง ด้านล่าง */
.chart-tooltip .tt-row-stack {
  grid-template-columns: 1fr;
  gap: 3px;
}

.chart-tooltip .tt-row:first-of-type {
  border-top: none;
}

.chart-tooltip .tt-label {
  color: var(--text-muted);
  min-width: 0;
  word-break: break-word;
}

.chart-tooltip .tt-row-stack .tt-label {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.chart-tooltip .tt-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.4;
  color: var(--text);
}

.chart-tooltip .tt-val-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  width: 100%;
}

/* บรรทัดแรก: ซื้อ → วันขาย — พยายามอยู่บรรทัดเดียว */
.chart-tooltip .tt-val-main {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.35;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* บรรทัดย่อย (เหลือ 3 ปี 2 เดือน / หน่วย) */
.chart-tooltip .tt-val-sub {
  display: block;
  font-weight: 500;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: normal;
}

.chart-tooltip .tt-swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}

.chart-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1a2330;
}

/* ===== Insights + collapsible panels ===== */
.insight-panel {
  margin-bottom: 16px;
  border-color: rgba(61, 156, 240, 0.25);
  background: linear-gradient(160deg, var(--bg-panel), rgba(61, 156, 240, 0.04));
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.insight-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  cursor: default;
  transition: border-color 0.15s ease, transform 0.15s ease;
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
}

button.insight-card {
  cursor: pointer;
}

button.insight-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.insight-card .insight-kicker {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.insight-card .insight-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
}

.insight-card .insight-body {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.insight-card.tone-ok {
  border-color: rgba(62, 207, 142, 0.35);
  background: linear-gradient(160deg, var(--bg-input), rgba(62, 207, 142, 0.08));
}
.insight-card.tone-ok .insight-kicker { color: var(--success); }

.insight-card.tone-warn {
  border-color: rgba(240, 180, 41, 0.4);
  background: linear-gradient(160deg, var(--bg-input), rgba(240, 180, 41, 0.08));
}
.insight-card.tone-warn .insight-kicker { color: var(--warn); }

.insight-card.tone-danger {
  border-color: rgba(240, 113, 120, 0.4);
  background: linear-gradient(160deg, var(--bg-input), rgba(240, 113, 120, 0.08));
}
.insight-card.tone-danger .insight-kicker { color: var(--danger); }

.insight-card.tone-info {
  border-color: rgba(61, 156, 240, 0.35);
  background: linear-gradient(160deg, var(--bg-input), rgba(61, 156, 240, 0.08));
}
.insight-card.tone-info .insight-kicker { color: var(--accent); }

.panel-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.collapse-toggle {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 0.2s ease, color 0.15s ease;
  flex-shrink: 0;
}

.collapse-toggle:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.panel.is-collapsible > .panel-head {
  cursor: default;
}

.panel.is-collapsible > .panel-head.panel-head-toggle,
.panel.is-collapsible > .panel-head[data-collapse-head] {
  cursor: pointer;
  user-select: none;
  gap: 12px;
}

.panel-head-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.panel-head-main h2 {
  margin: 0;
}

.panel.is-collapsed > .panel-body {
  display: none;
}

.panel.is-collapsed .collapse-toggle {
  transform: rotate(-90deg);
}

.panel.is-collapsible > .panel-body {
  animation: fadeIn 0.15s ease;
}

/* แผง Projected เงินเดือน — ตอนพับยังอ่านสถานะได้ */
#income-projected.is-collapsed {
  border-style: dashed;
  border-color: rgba(139, 92, 246, 0.28);
}

#income-projected:not(.is-collapsed) {
  border-color: rgba(139, 92, 246, 0.35);
}

@media (max-width: 900px) {
  .insight-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .insight-grid {
    grid-template-columns: 1fr;
  }
}

.has-chart-tip {
  cursor: pointer;
}

.has-chart-tip.is-hot {
  filter: brightness(1.08);
}

.cap-row.has-chart-tip,
.bracket-row.has-chart-tip,
.cf-row.has-chart-tip,
.asset-bar-item.has-chart-tip,
.install-dash-item.has-chart-tip,
.install-card.has-chart-tip {
  transition: background 0.15s ease, filter 0.15s ease;
}

.cap-row.has-chart-tip.is-hot,
.bracket-row.has-chart-tip.is-hot,
.cf-row.has-chart-tip.is-hot,
.asset-bar-item.has-chart-tip.is-hot {
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}

.pvd-stack-emp.has-chart-tip,
.pvd-stack-er.has-chart-tip {
  cursor: pointer;
  min-height: 100%;
}

.portfolio-mega-cats {
  display: flex;
  width: 100%;
  margin-bottom: 6px;
}

.portfolio-mega-cat-label {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.3;
}

.portfolio-mega-cat-label span {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
  border-bottom: 2px solid transparent;
}

.portfolio-legend-block {
  border-radius: 8px;
}

.portfolio-legend-block + .portfolio-legend-block {
  margin-top: 2px;
}

.portfolio-legend-cat {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.portfolio-legend-cat.is-toggle {
  display: grid;
  grid-template-columns: 12px 1fr auto auto 14px;
  gap: 8px 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background 0.12s ease;
}

.portfolio-legend-cat.is-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border-soft);
}

.portfolio-legend-block.is-open .portfolio-legend-cat.is-toggle {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border-soft);
  border-radius: 8px 8px 0 0;
}

.portfolio-legend-count {
  font-weight: 500;
  font-size: 0.75rem;
  margin-left: 6px;
}

.portfolio-legend-chev {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-align: center;
}

.portfolio-legend-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 4px 8px 10px;
  border: 1px solid var(--border-soft);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: rgba(0, 0, 0, 0.12);
  margin-bottom: 4px;
}

.portfolio-legend-item .portfolio-legend-name {
  padding-left: 6px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.portfolio-legend-item.is-other .portfolio-legend-name {
  font-style: italic;
}

.portfolio-legend-items .portfolio-legend-row {
  grid-template-columns: 12px 1fr auto auto;
  padding: 4px 4px;
  border-radius: 6px;
}

.portfolio-legend-items .portfolio-legend-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

/* แท่งเรียบง่าย (ใช้ที่อื่น) */
.portfolio-stack {
  display: flex;
  width: 100%;
  height: 28px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  margin-bottom: 4px;
}

.portfolio-stack-seg {
  height: 100%;
  min-width: 2px;
  transition: width 0.35s ease;
}

.portfolio-stack-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portfolio-legend-row {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: 8px 12px;
  align-items: center;
  font-size: 0.88rem;
}

.portfolio-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.portfolio-legend-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portfolio-legend-pct {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
}

.portfolio-legend-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 88px;
}

@media (max-width: 1100px) {
  .stat-grid-assets {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 420px) {
  .stat-grid-assets {
    grid-template-columns: 1fr;
  }
}

/* PVD portfolio */
.pvd-stat-grid {
  margin-top: 4px;
  margin-bottom: 16px;
}

.pvd-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pvd-form-col {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pvd-form-col h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0;
}

.pvd-cards {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* แยกตามแอป / ช่องทางซื้อ */
.fund-channel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fund-channel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 4px 2px 2px;
  border-bottom: 1px solid var(--border-soft);
}

.fund-channel-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* สัดส่วน: แอป (ซ้าย) · ประเภท (ขวา) — ใต้กล่องสถิติ / เหนือรายการ */
.fund-share-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 0 0 18px;
  align-items: stretch;
}

.fund-share-grid > .fund-share-panel,
.fund-share-grid > .fund-channel-share {
  margin: 0;
  min-width: 0;
  height: 100%;
}

/* สัดส่วนพอร์ตกองทุนตามแอป / ประเภท — โดนัท */
.fund-channel-share {
  margin: 0;
  padding: 14px 16px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
  box-sizing: border-box;
}

.fund-channel-share-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
  margin-bottom: 8px;
}

.fund-channel-share-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.fund-share-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.fund-share-donut-wrap {
  width: 168px;
  height: 168px;
  margin: 2px auto 4px;
}

.fund-share-donut-wrap .asset-donut,
.fund-share-donut-wrap .share-donut-host {
  width: 168px;
  height: 168px;
}

.fund-share-donut-wrap .asset-donut-center {
  inset: 26%;
}

.fund-share-donut-wrap .asset-donut-center strong {
  font-size: 0.78rem;
}

.fund-channel-share-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.fund-ch-share-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1.3fr) auto auto auto auto;
  gap: 8px 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background 0.12s ease;
}

.fund-ch-share-row:hover {
  background: var(--bg-hover);
  border-color: var(--border-soft);
}

.fund-ch-share-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.fund-ch-share-name {
  font-weight: 650;
  font-size: 0.88rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fund-ch-share-count {
  font-size: 0.78rem;
  white-space: nowrap;
}

.fund-ch-share-pct {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  text-align: right;
  min-width: 3.6rem;
  color: var(--text);
}

.fund-ch-share-pl {
  font-variant-numeric: tabular-nums;
  font-size: 0.86rem;
  font-weight: 800;
  text-align: right;
  min-width: 4.2rem;
  white-space: nowrap;
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.fund-ch-share-pl.pl-up {
  color: #047857;
  background: rgba(52, 211, 153, 0.18);
  border: 1px solid rgba(52, 211, 153, 0.45);
}

.fund-ch-share-pl.pl-down {
  color: #b91c1c;
  background: rgba(240, 113, 120, 0.16);
  border: 1px solid rgba(240, 113, 120, 0.4);
}

.fund-ch-share-val {
  font-variant-numeric: tabular-nums;
  font-size: 0.86rem;
  font-weight: 600;
  text-align: right;
  min-width: 5.5rem;
  white-space: nowrap;
}

@media (max-width: 960px) {
  .fund-share-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .fund-channel-share {
    padding: 12px 12px 10px;
  }

  .fund-share-donut-wrap {
    width: 148px;
    height: 148px;
  }

  .fund-share-donut-wrap .asset-donut,
  .fund-share-donut-wrap .share-donut-host {
    width: 148px;
    height: 148px;
  }

  .fund-ch-share-row {
    grid-template-columns: 10px minmax(0, 1fr) auto;
    gap: 6px 8px;
  }

  .fund-ch-share-count {
    display: none;
  }

  .fund-ch-share-pl {
    grid-column: 2;
    justify-self: start;
    min-width: 0;
  }

  .fund-ch-share-val {
    grid-column: 3;
    grid-row: 1 / span 2;
    align-self: center;
    min-width: 0;
  }

  .fund-ch-share-pct {
    grid-column: 2;
  }

  .fund-portfolio-table th.num,
  .fund-portfolio-table td.fund-td-num {
    width: auto;
    min-width: 4.5rem;
    font-size: 0.8rem;
  }

  .fund-portfolio-table th.fund-th-actions,
  .fund-portfolio-table td.fund-td-actions {
    min-width: 4.5rem;
  }

  .fund-table-actions .btn-sm {
    padding: 3px 6px;
    font-size: 0.7rem;
  }

  .filters-multi {
    gap: 8px;
  }
}

.fund-td-pct strong {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* แถวรวมท้ายตาราง — ตรงคอลัมน์มูลค่า / % / ทุน / P/L */
.fund-portfolio-table tfoot td {
  border-top: 2px solid var(--border);
  border-bottom: none;
  padding-top: 12px;
  padding-bottom: 12px;
  background: rgba(255, 255, 255, 0.03);
  vertical-align: top;
  font-size: 0.9rem;
}

.fund-portfolio-table tfoot tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.fund-table-total-row td:first-child strong {
  font-size: 0.95rem;
  font-weight: 700;
}

.fund-foot-liq {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.fund-foot-lock {
  color: var(--warn, #f0b429);
}

.fund-portfolio-table tfoot .num strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

/* พอร์ตกองทุน — ตารางกะทัดรัด: ชื่อ+badge | มูลค่า | % | ทุน | P/L | ปุ่ม */
.fund-table-wrap {
  margin-top: 4px;
  overflow-x: auto;
}

.fund-portfolio-table {
  font-size: 0.88rem;
  width: 100%;
  table-layout: auto;
  border-collapse: collapse;
}

.fund-portfolio-table thead th {
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.03em;
  text-transform: none; /* อย่า uppercase เล็กจม */
  padding: 12px 10px;
  border-bottom: 2px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.fund-portfolio-table thead th.num {
  color: var(--text);
}

.fund-portfolio-table thead th.fund-sort-th {
  cursor: pointer;
  user-select: none;
  transition: color 0.12s ease, background 0.12s ease;
}

.fund-portfolio-table thead th.fund-sort-th:hover {
  color: var(--accent, #3d9cf0);
  background: rgba(61, 156, 240, 0.08);
}

.fund-portfolio-table thead th.fund-sort-th.is-sorted {
  color: var(--accent, #3d9cf0);
}

.fund-portfolio-table td {
  vertical-align: top; /* ปุ่ม/ตัวเลขชิดบน ไม่ลอยกลางแถว (กันดูเหมือนมีเส้นขีดทับ) */
  padding-top: 12px;
  padding-bottom: 12px;
}

.fund-portfolio-table th:first-child,
.fund-portfolio-table td.fund-td-name {
  width: 42%;
  min-width: 12rem;
}

.fund-portfolio-table th.num,
.fund-portfolio-table td.fund-td-num {
  width: 7.5rem;
  min-width: 6.5rem;
  white-space: nowrap;
  vertical-align: top;
  padding-top: 14px; /* จัดแนวกับชื่อกอง */
}

.fund-portfolio-table th.fund-th-actions,
.fund-portfolio-table td.fund-td-actions {
  width: 1%;
  min-width: 6.75rem;
  white-space: nowrap;
  padding-left: 10px;
  padding-right: 8px;
  padding-top: 12px;
  vertical-align: top;
  /* อย่าใช้ .data-table .actions { width:80px } */
  text-align: right;
}

.fund-td-name {
  min-width: 0;
  max-width: none;
  padding-right: 14px;
}

.fund-name-line {
  display: block;
}

.fund-td-name strong {
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.35;
  word-break: break-word;
  color: var(--text);
}

/* แถว badge ใต้ชื่อ: สถานะ · ช่องทาง · ประเภท */
.fund-badge-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 6px;
  margin-top: 6px;
}

/* Badge ร่วม: สถานะ · ช่องทาง · ประเภท — ทรงเดียวกัน มีกรอบ */
.fund-status,
.fund-meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  min-width: 0;
  max-width: 12rem;
  font-size: 0.7rem;
  font-weight: 650;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}

.fund-status {
  cursor: help;
}

.fund-status-ico {
  font-size: 0.78rem;
  line-height: 1;
  flex-shrink: 0;
}

/* ช่องทาง / ประเภท — กรอบโทนเดียวกับสถานะ */
.fund-meta-badge {
  color: var(--text-muted);
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.1);
  cursor: default;
}

.fund-meta-badge > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.fund-ch-badge {
  cursor: help;
  /* border/background ตั้งจากสีแบรนด์ใน JS */
}

.fund-type-badge {
  color: #93c5fd;
  border-color: rgba(96, 165, 250, 0.4);
  background: rgba(59, 130, 246, 0.12);
}

.fund-type-badge .fund-type-ico {
  font-size: 0.78rem;
  line-height: 1;
  opacity: 0.95;
  flex-shrink: 0;
}

.fund-form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.fund-form-actions .form-actions-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.btn.danger,
.btn-ghost.danger {
  color: var(--danger, #f07178);
  border-color: rgba(240, 113, 120, 0.35);
}

.btn-ghost.danger:hover {
  background: rgba(240, 113, 120, 0.1);
}

.fund-status.is-liquid {
  color: #059669;
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.35);
}

.fund-status.is-locked {
  color: #c2410c;
  background: rgba(251, 146, 60, 0.14);
  border-color: rgba(251, 146, 60, 0.4);
}

.fund-status.is-mixed {
  color: #b45309;
  background: rgba(240, 180, 41, 0.16);
  border-color: rgba(240, 180, 41, 0.4);
}

.fund-td-sub {
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.fund-td-ch {
  white-space: nowrap;
  font-size: 0.84rem;
  color: var(--text-muted);
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fund-ch-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.fund-ch-label {
  vertical-align: middle;
}

.fund-td-type {
  white-space: nowrap;
}

.fund-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.fund-type-ico {
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.9;
}

.fund-table-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
  /* อยู่ใน div ภายใน td — ไม่ flex ที่ td */
}

.fund-table-actions .btn-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
  line-height: 1.2;
  height: auto;
  min-height: 28px;
}

.fund-table-actions .btn-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* แถบสถานะซ้าย — อย่าทับเนื้อหา/ปุ่ม */
.fund-row-liquid td:first-child {
  box-shadow: inset 3px 0 0 rgba(52, 211, 153, 0.55);
}

.fund-row-locked td:first-child {
  box-shadow: inset 3px 0 0 rgba(251, 146, 60, 0.45);
}

.fund-portfolio-table tr {
  /* เส้นคั่นแถวชัด อยู่ใต้ทั้งแถว ไม่ตัดกลางปุ่ม */
  isolation: isolate;
}

.fund-td-name.has-chart-tip,
.fund-status.has-chart-tip,
.fund-td-ch.has-chart-tip {
  cursor: help;
}

#fundCards.pvd-cards {
  display: block;
}

/* บาร์ปลดล็อกตามปี (หน่วย × NAV ปัจจุบัน) */
.fund-unlock-bar-wrap {
  margin-top: 8px;
  min-width: 0;
}

.fund-unlock-bar-wrap.is-compact {
  margin-top: 6px;
  max-width: 16rem;
}

.fund-unlock-bar-hint {
  font-size: 0.7rem;
  margin-bottom: 4px;
}

.fund-unlock-bar {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
}

.fund-unlock-bar-wrap.is-compact .fund-unlock-bar {
  height: 7px;
  border-radius: 4px;
}

.fund-unlock-seg {
  height: 100%;
  min-width: 2px;
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.25);
}

.fund-unlock-seg.is-liq {
  /* เขียว = ขายได้แล้ว */
}

.fund-unlock-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 6px;
}

.fund-unlock-leg-item {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.fund-unlock-leg-item i {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: center;
}

.fund-unlock-leg-item b {
  font-weight: 650;
  color: var(--text);
}

.fund-unlock-leg-item em {
  font-style: normal;
  font-weight: 600;
  color: var(--text);
}

.fund-unlock-bar-wrap.is-compact .fund-unlock-legend {
  margin-top: 4px;
  gap: 2px 8px;
}

.fund-unlock-bar-wrap.is-compact .fund-unlock-leg-item {
  font-size: 0.68rem;
}

/* ใน tooltip */
.chart-tooltip .fund-unlock-bar-wrap {
  margin: 4px 0 10px;
  max-width: none;
}

.chart-tooltip .fund-unlock-bar {
  height: 12px;
}

.chart-tooltip .fund-unlock-legend {
  gap: 6px 12px;
}

.chart-tooltip .fund-unlock-leg-item {
  font-size: 0.78rem;
}

.pvd-card {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.pvd-card.is-fund-tile {
  padding: 12px 14px;
  gap: 8px;
}

.pvd-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.fund-card-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pvd-card-top h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.35;
  word-break: break-word;
}

.pvd-card.is-fund-tile .pvd-card-top h3 {
  font-size: 0.9rem;
}

/* chips แทนข้อความพืด */
.fund-meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.fund-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  max-width: 100%;
}

.fund-chip.is-lock {
  color: var(--warn);
  border-color: rgba(240, 180, 41, 0.35);
  background: rgba(240, 180, 41, 0.1);
}

.fund-chip.is-ok {
  color: var(--success);
  border-color: rgba(62, 207, 142, 0.35);
  background: rgba(62, 207, 142, 0.1);
}

.fund-countdown {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
}

.fund-countdown-label {
  font-size: 0.68rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.fund-countdown strong {
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.35;
}

.fund-countdown.is-wait {
  border-color: rgba(240, 180, 41, 0.4);
  background: rgba(240, 180, 41, 0.08);
}

.fund-countdown.is-wait strong {
  color: var(--warn);
}

.fund-countdown.is-done {
  border-color: rgba(62, 207, 142, 0.4);
  background: rgba(62, 207, 142, 0.08);
}

.fund-countdown.is-done strong {
  color: var(--success);
}

.fund-countdown.is-unknown {
  opacity: 0.9;
}

.fund-lot-schedule {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fund-lot-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.4;
  padding: 6px 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.06);
}

.fund-lot-line:first-child {
  border-top: none;
  padding-top: 0;
}

.fund-lot-l1 {
  display: block;
}

.fund-lot-l2 {
  display: block;
  font-weight: 650;
  opacity: 0.95;
  padding-left: 0.15em;
}

.fund-lot-line.is-liquid {
  color: var(--success);
}

.fund-lot-line.is-locked {
  color: var(--warn);
}

.fund-lot-line.is-unknown {
  color: var(--text-muted);
}

.fund-nav-line {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.fund-nav-line.is-stale {
  color: var(--warn);
  font-weight: 600;
}

.fund-nav-line.is-fresh {
  color: var(--success);
}

.fund-note {
  margin: 0;
  line-height: 1.35;
}

/* ซื้อกองลดหย่อนตามปี */
.fund-tax-year-select {
  min-width: 9.5rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.88rem;
}

.fund-tax-summary {
  margin-bottom: 12px;
}

.fund-tax-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fund-tax-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
}

.fund-tax-cat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.fund-tax-sub {
  margin-top: 4px;
  line-height: 1.4;
}

.fund-tax-amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  color: var(--success);
  white-space: nowrap;
}

.pvd-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pvd-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pvd-metric span {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.pvd-metric strong {
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.pvd-metric small {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.pvd-metric.pl-pos strong { color: var(--success); }
.pvd-metric.pl-neg strong { color: var(--warn); }

.pvd-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pvd-side {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.pvd-side-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.pvd-stack-bar {
  display: flex;
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

.pvd-stack-emp {
  background: var(--accent);
  min-width: 0;
}

.pvd-stack-er {
  background: var(--success);
  min-width: 0;
}

.pvd-totals-foot {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
  line-height: 1.5;
}

@media (max-width: 700px) {
  .pvd-form-grid,
  .pvd-split,
  .pvd-metrics {
    grid-template-columns: 1fr;
  }

  .pvd-card.is-fund-tile .pvd-metrics {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.pvd-card.fund-liquid {
  border-color: rgba(62, 207, 142, 0.35);
}

.pvd-card.fund-locked {
  border-color: rgba(240, 180, 41, 0.3);
}

.fund-liq-bar {
  margin-bottom: 14px;
}

/* แท็บโหมดฟอร์มกองทุน: ทีละกอง | bulk */
.fund-form-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
  padding: 4px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
}

.fund-form-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.fund-form-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.fund-form-tab.is-active {
  color: var(--text);
  background: var(--bg-panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-soft);
}

.fund-form-tabs.is-edit-only .fund-form-tab[data-fund-mode="bulk"] {
  opacity: 0.4;
  pointer-events: none;
}

/* แถว bulk ซื้อหลายกอง */
.fund-bulk-table-wrap {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
}

.fund-bulk-head,
.fund-bulk-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(5.5rem, 0.7fr) minmax(5.5rem, 0.7fr) minmax(4.5rem, 0.55fr) 2rem;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
}

.fund-bulk-head {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.12);
}

.fund-bulk-rows {
  display: flex;
  flex-direction: column;
}

.fund-bulk-row {
  border-bottom: 1px solid var(--border-soft);
}

.fund-bulk-row:last-child {
  border-bottom: none;
}

/* แถว bulk: กล่องสว่าง + ตัวอักษรเข้ม อ่านง่ายตอนกรอกหลายแถว */
.fund-bulk-row input[type="text"],
.fund-bulk-row input[type="number"],
.fund-bulk-row input.money-input {
  width: 100%;
  min-width: 0;
  font-size: 0.9rem;
  padding: 8px 10px;
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid #94a3b8;
  border-radius: 8px;
  color-scheme: light;
  font-variant-numeric: tabular-nums;
}

.fund-bulk-row input::placeholder {
  color: #64748b;
  opacity: 1;
}

.fund-bulk-row input:focus {
  outline: none;
  border-color: #3d9cf0;
  box-shadow: 0 0 0 3px rgba(61, 156, 240, 0.25);
  background: #fff;
  color: #0f172a;
}

.fund-bulk-meta {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fund-bulk-meta.is-empty {
  color: var(--text-muted);
  font-weight: 500;
}

.fund-bulk-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
}

.fund-bulk-remove:hover {
  color: #f07178;
  background: rgba(240, 113, 120, 0.12);
}

@media (max-width: 640px) {
  .fund-bulk-head {
    display: none;
  }

  .fund-bulk-row {
    grid-template-columns: 1fr 1fr auto;
    grid-template-areas:
      "name name remove"
      "cost units meta";
    gap: 6px 8px;
    padding: 10px;
  }

  .fund-bulk-row .fund-bulk-name {
    grid-area: name;
  }

  .fund-bulk-row .fund-bulk-cost {
    grid-area: cost;
  }

  .fund-bulk-row .fund-bulk-units {
    grid-area: units;
  }

  .fund-bulk-row .fund-bulk-meta {
    grid-area: meta;
    align-self: center;
  }

  .fund-bulk-row .fund-bulk-remove {
    grid-area: remove;
    justify-self: end;
  }
}

/* หน่วย + NAV กองทุน / วันซื้อ+ปลดล็อก */
.fund-unit-row,
.fund-date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

/* ถ้าซ่อนช่องปลดล็อก — วันซื้อเต็มแถว */
.fund-date-row:has(#fundUnlockField[hidden]) {
  grid-template-columns: 1fr;
}

.fund-unit-derived {
  margin-top: 4px;
  margin-bottom: 4px;
}

@media (max-width: 560px) {
  .fund-unit-row,
  .fund-date-row {
    grid-template-columns: 1fr;
  }
}

input.is-derived {
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: default;
}

/* Popup อัปเดต NAV — เกือบเต็มจอ (ทับ .modal max-width:400px) */
#fundNavBackdrop.modal-backdrop {
  display: grid;
  place-items: stretch;
  padding: 10px;
  box-sizing: border-box;
}

#fundNavBackdrop .fund-nav-modal.modal,
#fundNavBackdrop .fund-nav-modal {
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  max-height: none !important;
  margin: 0;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  overflow: hidden;
  box-sizing: border-box;
}

.fund-nav-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.fund-nav-modal-head h3 {
  margin: 0;
  font-size: 1.2rem;
}

.fund-nav-channel-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.12);
  max-height: 160px;
  overflow-y: auto;
  flex-shrink: 0;
}

.fund-nav-tab {
  appearance: none;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.fund-nav-tab:hover {
  border-color: var(--accent);
}

.fund-nav-tab.is-active {
  background: rgba(61, 156, 240, 0.16);
  border-color: rgba(61, 156, 240, 0.45);
  color: var(--accent);
}

.fund-nav-tab-count {
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.fund-nav-modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 24px 16px;
  min-height: 0;
}

.fund-nav-modal-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.fund-nav-modal-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.fund-nav-update-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}

.fund-nav-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.8fr) minmax(160px, 1fr) minmax(180px, 0.9fr) minmax(160px, 1fr);
  gap: 16px 22px;
  align-items: center;
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
}

.fund-nav-row.is-stale {
  border-color: rgba(240, 180, 41, 0.4);
  background: rgba(240, 180, 41, 0.06);
}

.fund-nav-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.fund-nav-meta strong {
  font-size: 1rem;
  font-weight: 650;
}

.fund-nav-stats {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 0;
}

.fund-nav-stats strong {
  color: var(--text);
  font-weight: 600;
}

.fund-nav-asof {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.fund-nav-asof.is-stale {
  color: var(--warn);
  font-weight: 650;
}

.fund-nav-asof.is-fresh {
  color: var(--success);
}

.fund-nav-input {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fund-nav-input-el {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.fund-nav-input-el:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.fund-nav-live {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.fund-nav-live strong {
  font-size: 1.05rem;
}

.fund-nav-live small {
  font-size: 0.82rem;
  font-weight: 600;
}

@media (max-width: 900px) {
  .fund-nav-row {
    grid-template-columns: 1fr 1fr;
  }
  .fund-nav-live {
    text-align: left;
  }
}

@media (max-width: 700px) {
  .fund-unit-row,
  .fund-nav-row {
    grid-template-columns: 1fr;
  }

  .fund-nav-live {
    text-align: left;
  }

  #fundNavBackdrop {
    padding: 0;
  }

  #fundNavBackdrop .fund-nav-modal,
  .fund-nav-modal {
    border-radius: 0;
    height: 100%;
  }
}

/* Equity market refresh bar + manual pricing */
.eq-market-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin: 0 0 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(61, 156, 240, 0.3);
  background: linear-gradient(145deg, rgba(61, 156, 240, 0.1), var(--bg-panel));
}

.eq-market-bar-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.eq-market-bar-text strong {
  font-size: 0.92rem;
}

.eq-market-bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.eq-market-bar .btn.is-loading,
#eqRefreshMarketHold.is-loading {
  opacity: 0.75;
  pointer-events: none;
}

.eq-market-last {
  font-size: 0.75rem !important;
  color: var(--text-dim) !important;
}

.eq-manual-pricing {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.eq-manual-pricing.is-collapsed {
  display: none;
}

.eq-manual-fx-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.eq-manual-fx-row label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.eq-manual-fx-row input {
  width: 7.5rem;
  max-width: 40vw;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.eq-manual-grants {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.eq-manual-grant-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(100px, 0.9fr) minmax(90px, 0.7fr);
  gap: 8px 12px;
  align-items: end;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.14);
}

@media (max-width: 640px) {
  .eq-manual-grant-row {
    grid-template-columns: 1fr 1fr;
  }
  .eq-manual-grant-label {
    grid-column: 1 / -1;
  }
}

.eq-manual-grant-label {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.eq-manual-grant-label strong {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eq-manual-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.eq-manual-field span {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.eq-manual-field input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.eq-manual-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.eq-hold-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Equity lots form */
.eq-lots-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.eq-lot-row {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.9fr auto;
  gap: 8px;
  align-items: center;
}

.eq-lot-row .eq-lot-sold-label {
  grid-column: 1 / -1;
  margin-top: -2px;
}

.eq-tl-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.eq-tl-item.eq-tl-sold {
  opacity: 0.95;
  border-color: rgba(240, 180, 41, 0.25);
}

.eq-sell-modal {
  max-width: 480px;
  width: min(480px, 94vw);
  max-height: 90dvh;
  overflow-y: auto;
}

.eq-lot-row input,
.eq-lot-row select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.85rem;
}

/* Equity hold: ซ้ายไทม์ไลน์ · ขวา grant / ขาย */
.eq-horizon-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.eq-horizon-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.eq-horizon-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.eq-horizon-card.is-active {
  border-color: rgba(61, 156, 240, 0.45);
  background: linear-gradient(160deg, var(--bg-input), rgba(61, 156, 240, 0.1));
  box-shadow: 0 0 0 1px rgba(61, 156, 240, 0.15);
}

.eq-horizon-kicker {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.eq-horizon-card strong {
  font-size: 1.05rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.eq-layout-split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.eq-layout-main,
.eq-layout-side {
  min-width: 0;
}

.eq-layout-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: calc(var(--topbar-h) + 12px);
}

.eq-side-block {
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.12);
}

.eq-side-title {
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.eq-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.eq-filter-btn {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid transparent;
  background: transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.eq-filter-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border-soft);
}

.eq-filter-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(61, 156, 240, 0.35);
  font-weight: 600;
}

.eq-month-trend {
  margin-bottom: 14px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
}

.eq-month-trend-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.eq-month-trend-head h3 {
  font-size: 0.88rem;
  font-weight: 600;
  margin: 0;
}

.eq-month-bars {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 120px;
}

.eq-month-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.eq-month-bar-track {
  width: 100%;
  height: 88px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.eq-month-bar-fill {
  width: 70%;
  max-width: 36px;
  min-height: 4px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
  transition: height 0.2s ease;
}

.eq-month-bar-col.is-soon .eq-month-bar-fill {
  background: linear-gradient(180deg, #5aaff5, #22d3ee);
}

.eq-month-bar-col.is-empty .eq-month-bar-fill {
  background: var(--border-soft);
  opacity: 0.5;
  height: 4px !important;
}

.eq-month-bar-label {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.25;
}

.eq-month-bar-val {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.eq-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(52vh, 520px);
  overflow-y: auto;
  padding-right: 2px;
}

.eq-layout-side .eq-timeline {
  max-height: 220px;
}

.eq-tl-item {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.eq-tl-item.done {
  opacity: 0.75;
  border-color: rgba(62, 207, 142, 0.3);
}

.eq-tl-item.is-soon {
  border-color: rgba(34, 211, 238, 0.35);
  background: linear-gradient(160deg, var(--bg-input), rgba(34, 211, 238, 0.06));
}

.eq-tl-date {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.eq-tl-date small {
  display: block;
  font-weight: 500;
  font-size: 0.68rem;
  color: var(--accent);
  margin-top: 2px;
}

.eq-tl-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.eq-tl-body span {
  color: var(--text-dim);
  font-size: 0.78rem;
}

@media (max-width: 960px) {
  .eq-layout-split {
    grid-template-columns: 1fr;
  }

  .eq-layout-side {
    position: static;
  }

  .eq-month-bars {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .eq-lot-row {
    grid-template-columns: 1fr 1fr;
  }

  .eq-horizon-stats {
    grid-template-columns: 1fr;
  }

  .eq-tl-item {
    grid-template-columns: 1fr;
  }

  .eq-month-bars {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.install-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.install-card-top h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.install-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.install-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.install-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.install-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.install-stat span {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.install-stat strong {
  font-size: 0.88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.install-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.install-progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Dashboard install list */
.install-dash-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.install-dash-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.install-dash-item .cap-head {
  font-size: 0.85rem;
}

/* Cashflow viz bars */
.cashflow-viz {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cf-sub {
  margin-top: 4px;
  line-height: 1.35;
}

.cf-scale-note {
  margin: 0 0 4px;
  line-height: 1.4;
}

.cf-row-stock {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-soft);
}

.cf-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cf-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.cf-bar-track {
  height: 28px;
  background: var(--bg-input);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  position: relative;
}

.cf-bar-fill {
  height: 100%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 4px;
  transition: width 0.4s ease;
  white-space: nowrap;
  color: #0a121c;
}

.cf-bar-fill.income {
  background: linear-gradient(90deg, var(--success), #5ee0a8);
}

.cf-bar-fill.install {
  background: linear-gradient(90deg, var(--warn), #f5c842);
}

.cf-bar-fill.cash {
  background: linear-gradient(90deg, var(--accent), #5aaff5);
  color: #0a121c;
}

.cf-bar-fill.thin {
  opacity: 0.85;
}

.form-wide .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="search"],
.field select,
.search-input,
.filters select,
.searchable-select-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  color-scheme: dark;
}

.field input::placeholder,
.search-input::placeholder,
.searchable-select-input::placeholder {
  color: var(--text-dim);
  opacity: 1;
}

.field input:focus,
.field select:focus,
.search-input:focus,
.filters select:focus,
.searchable-select-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ===== Searchable select (combobox) ===== */
.searchable-select {
  position: relative;
  width: 100%;
}

/* เก็บ native <select> ไว้ในฟอร์ม (value / required) แต่ไม่โชว์ */
.searchable-select-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.searchable-select-input {
  padding-right: 36px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b9bb0' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: text;
}

.searchable-select.is-open .searchable-select-input {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.searchable-select-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% - 1px);
  z-index: 40;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-top: 1px solid var(--border-soft);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 4px;
}

.searchable-select-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  line-height: 1.35;
}

.searchable-select-option:hover,
.searchable-select-option.is-highlight {
  background: var(--bg-hover);
  color: var(--text);
}

.searchable-select-option.is-selected {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
}

.searchable-select-option.is-selected.is-highlight {
  background: rgba(61, 156, 240, 0.2);
}

.searchable-select-option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.searchable-select-empty {
  padding: 12px;
  font-size: 0.84rem;
  color: var(--text-muted);
  text-align: center;
}

.searchable-select-group {
  padding: 8px 12px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  text-transform: none;
  border-top: 1px solid var(--border-soft);
  margin-top: 4px;
}

.searchable-select-group:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 6px;
}

.year-picker .searchable-select,
.filters .searchable-select {
  min-width: 0;
}

.filters .searchable-select-input {
  min-width: 140px;
}

.checkbox-label {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.88rem !important;
  color: var(--text) !important;
  cursor: pointer;
  padding-top: 8px;
}

.checkbox-label input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.hint-box {
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(61, 156, 240, 0.12);
  border: 1px solid rgba(61, 156, 240, 0.28);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.5;
}

.hint-box strong {
  color: #f4f8fc;
  font-weight: 700;
}

.hint-box .muted {
  color: var(--text-muted);
}

.allowance-box {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.auto-list {
  list-style: none;
  margin-top: 10px;
}

.auto-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.85rem;
}

.auto-list li span:last-child {
  font-family: var(--font);
  color: var(--accent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.coming-soon {
  margin-top: 16px;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--accent);
  color: #0a121c;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-dim);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(240, 113, 120, 0.3);
}

.btn-danger:hover {
  background: rgba(240, 113, 120, 0.22);
}

.btn-icon {
  padding: 6px 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-radius: 6px;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-icon.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

/* ===== Tables ===== */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.filters .search-input {
  flex: 1;
  min-width: 0;
}

.filters select {
  width: auto;
  min-width: 140px;
}

/* ===== แถบค้นหา/กรองมาตรฐานทั้งเว็บ =====
   ค้นหา = กว้าง · ตัวกรอง select = แคบคงที่ · มีป้ายกำกับชัด */
.filters-labeled {
  align-items: flex-end;
  flex-wrap: nowrap;
  gap: 10px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0; /* ค้นหาได้พื้นที่หลัก */
}

/* ตัวกรอง dropdown: ไม่แย่งช่องค้นหา */
.filter-field-select {
  flex: 0 0 10.5rem;
  width: 10.5rem;
  max-width: 10.5rem;
  min-width: 9rem;
}

/* หลายตัวกรองเรียง (เช่น กองทุน) — ไม่มีช่องค้นหา */
.filters-multi {
  flex-wrap: wrap;
}

.filters-multi .filter-field-select {
  flex: 1 1 9.5rem;
  width: auto;
  max-width: 14rem;
  min-width: 8.5rem;
}

.filter-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.filters-labeled .search-input,
.filters-labeled .searchable-select,
.filters-labeled select {
  width: 100%;
  min-width: 0;
}

.filters-labeled .filter-field-select .searchable-select,
.filters-labeled .filter-field-select .searchable-select-input,
.filters-labeled .filter-field-select select {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
}

.filters-labeled .filter-field-select .searchable-select-input {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 28px !important;
}

/* dropdown ยังอ่านชื่อยาวได้ แม้ช่องแคบ */
.filters-labeled .filter-field-select .searchable-select-dropdown {
  min-width: 100%;
  width: max(100%, 14rem);
  max-width: min(20rem, 90vw);
}

/* บังคับทุก .filters ที่มี select+search ให้สัดส่วนดี (กันหน้าเก่าหลุด) */
.filters:not(.filters-multi) > .search-input {
  flex: 1 1 auto;
  min-width: 0;
}

.filters:not(.filters-multi) > select,
.filters:not(.filters-multi) > .searchable-select {
  flex: 0 0 10.5rem;
  max-width: 10.5rem;
  min-width: 0;
}

@media (max-width: 640px) {
  .filters-labeled {
    flex-wrap: wrap;
  }

  .filter-field-select {
    flex: 1 1 calc(50% - 6px);
    width: auto;
    max-width: none;
    min-width: 0;
  }

  .filters-labeled > .filter-field:not(.filter-field-select) {
    flex: 1 1 100%;
  }

  .filters-multi .filter-field-select {
    flex: 1 1 calc(50% - 6px);
    max-width: none;
  }
}

/* ช่องเงินมีคอมม่าคั่นหลักพัน */
input.money-input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* ===== โลโก้ธนาคาร (monogram สีแบรนด์) ===== */
.bank-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
  border-radius: 8px;
  background: var(--bank-bg, #475569);
  color: var(--bank-fg, #fff);
  font-weight: 750;
  font-size: 0.62rem;
  letter-spacing: -0.03em;
  line-height: 1;
  vertical-align: middle;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  user-select: none;
  white-space: nowrap;
  padding: 0 5px;
}

/* ความกว้างยืดตามข้อความ (เช่น KBank, ClicX) — ความสูงคงที่ */
.bank-logo-sm {
  min-width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 0.5rem;
  padding: 0 4px;
}

.bank-logo-md {
  min-width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 0.58rem;
  padding: 0 6px;
}

.bank-logo-lg {
  min-width: 40px;
  height: 40px;
  border-radius: 11px;
  font-size: 0.68rem;
  padding: 0 8px;
}

.asset-port-pct {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 0.9em;
  white-space: nowrap;
  min-width: 3.5rem;
}

.asset-row-bank {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.breakdown-row-bank .breakdown-bank-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.asset-bar-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* ไอคอนในกราฟ / แท่ง / โดนัท */
.chart-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25em;
  margin-right: 0.28em;
  font-size: 0.95em;
  line-height: 1;
  vertical-align: -0.05em;
  flex-shrink: 0;
}

.insight-kicker .chart-ico {
  margin-right: 0.35em;
}

.asset-legend-name {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.cap-label {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.panel-head h2 .chart-ico,
.stat-label .chart-ico {
  margin-right: 0.2em;
}

.cf-label-row span {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
}

.asset-bank-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
}

.asset-bank-group {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  overflow: hidden;
}

.asset-bank-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.02);
}

.asset-bank-group-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.asset-bank-group-meta strong {
  font-size: 0.9rem;
  font-weight: 650;
}

/* หัวกลุ่มธนาคารในตารางเดียว — คอลัมน์ชื่อ/วันที่/มูลค่าตรงทั้งตาราง */
.asset-section .data-table {
  table-layout: fixed;
  width: 100%;
}

.asset-section .data-table th:nth-child(1),
.asset-section .data-table td:nth-child(1) {
  width: 42%;
}

.asset-section .data-table th:nth-child(2),
.asset-section .data-table td:nth-child(2) {
  width: 18%;
}

.asset-section .data-table th:nth-child(3),
.asset-section .data-table td:nth-child(3) {
  width: 26%;
}

.asset-section .data-table th:nth-child(4),
.asset-section .data-table td:nth-child(4) {
  width: 14%;
}

.asset-bank-subheader td {
  padding: 0 !important;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
}

.asset-bank-subheader-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.asset-bank-subheader + tr td {
  border-top: none;
}

.asset-section .data-table tr.asset-bank-subheader:hover td {
  background: rgba(255, 255, 255, 0.03);
}

/* ===== อสังหา: สัดส่วนผ่อน (ราคาเต็มไม่นับในพอร์ต) ===== */
.asset-prop-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.88rem;
}

.asset-prop-bar {
  height: 8px;
  border-radius: 999px;
}

.asset-row-prop {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  max-width: 220px;
}

.asset-row-prop-meta {
  display: block;
}

.asset-prop-bar-sm {
  display: block;
  height: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.asset-prop-bar-sm .cap-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #f07178;
}

/* ===== รายการสินทรัพย์: ซ้ายประเภท · ขวารายการกลุ่ม ===== */
.asset-list-layout {
  display: grid;
  grid-template-columns: minmax(160px, 200px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.asset-cat-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: calc(var(--topbar-h) + 12px);
  max-height: min(70vh, 640px);
  overflow-y: auto;
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, 0.15);
}

.asset-cat-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.asset-cat-nav-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-soft);
}

.asset-cat-nav-btn.is-active {
  background: var(--accent-soft);
  border-color: rgba(61, 156, 240, 0.35);
}

.asset-cat-nav-btn .acn-label {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
}

.asset-cat-nav-btn .acn-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.asset-cat-nav-btn.is-active .acn-label {
  color: var(--accent);
}

.asset-list-main {
  min-width: 0;
}

.asset-list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.asset-sort-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.asset-sort-btn {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid transparent;
  background: transparent;
}

.asset-sort-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.asset-sort-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(61, 156, 240, 0.35);
  font-weight: 600;
}

.asset-sort-btn .sort-arrow {
  margin-left: 2px;
  opacity: 0.85;
}

.asset-list-sections {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.asset-section {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  overflow: hidden;
}

.asset-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(61, 156, 240, 0.06);
}

.asset-section-head h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}

.asset-section-head .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.asset-section-head .sec-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.asset-section .data-table {
  margin: 0;
}

.asset-section .data-table th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.asset-section .data-table th:hover {
  color: var(--accent);
}

.asset-section .data-table th.is-sorted {
  color: var(--accent);
}

.asset-section .data-table th .sort-ind {
  font-size: 0.7em;
  opacity: 0.9;
  margin-left: 3px;
}

.asset-section .data-table td.actions {
  white-space: nowrap;
  width: 1%;
}

.asset-val-primary {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 768px) {
  .asset-list-layout {
    grid-template-columns: 1fr;
  }

  .asset-cat-nav {
    position: static;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
  }

  .asset-cat-nav-btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 7.5rem;
  }
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  text-align: left;
  font-weight: 500;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

.data-table .num {
  text-align: right;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table .actions {
  text-align: right;
  white-space: nowrap;
  width: 80px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--bg-hover);
  color: var(--text-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 16px;
  font-size: 0.9rem;
  display: none;
}

.empty-state.visible {
  display: block;
}

/* ===== Tax brackets ===== */
.tax-brackets {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bracket-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  font-size: 0.85rem;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.bracket-row.active {
  background: var(--warn-soft);
  border: 1px solid rgba(240, 180, 41, 0.2);
}

.bracket-range {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.bracket-rate {
  font-family: var(--font);
  color: var(--warn);
  font-weight: 500;
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bracket-tax {
  font-family: var(--font);
  min-width: 90px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bracket-bar-wrap {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--border-soft);
  border-radius: 2px;
  overflow: hidden;
  margin-top: -2px;
}

.bracket-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--warn), #f5c842);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ===== Assets summary ===== */
.asset-summary {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.big-number {
  font-family: var(--font);
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--text-muted);
}

.muted.small,
.small {
  font-size: 0.8rem;
}

.asset-breakdown {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
}

.breakdown-row span:last-child {
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

/* ===== Recent list ===== */
.recent-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.recent-item {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.recent-item:hover {
  background: var(--bg-hover);
}

.recent-type {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.recent-type.income { color: var(--income); }
.recent-type.deduction { color: var(--deduction); }
.recent-type.asset { color: var(--warn); }

.recent-desc {
  min-width: 0;
}

.recent-desc strong {
  display: block;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-desc span {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.recent-amount {
  font-family: var(--font);
  font-size: 0.88rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.recent-amount.pos { color: var(--income); }
.recent-amount.neg { color: var(--deduction); }

/* ===== Settings ===== */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 900px;
}

.settings-cards-block {
  max-width: none;
  margin: 12px 0 4px;
  scroll-margin-top: var(--page-sticky-offset, 72px);
}

.retire-age-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.retire-age-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
}

.retire-age-card strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  .retire-age-grid {
    grid-template-columns: 1fr;
  }
}

.settings-actions p {
  line-height: 1.6;
  font-size: 0.9rem;
}

.disclaimer ul {
  padding-left: 1.2em;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.7;
}

/* ===== Toast ===== */
.toast-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: slideIn 0.25s ease;
  max-width: 320px;
}

.toast.success { border-color: rgba(62, 207, 142, 0.4); }
.toast.error { border-color: rgba(240, 113, 120, 0.4); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ===== List-first: ฟอร์มอยู่ใน popup ไม่แย่งพื้นที่รายการ ===== */
.form-panel-parked {
  display: none !important;
}

.split-list-first {
  grid-template-columns: 1fr;
}

.split-list-first > .list-panel {
  max-width: 100%;
}

.form-panel-home[hidden] {
  display: none !important;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  z-index: 90;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
}

/* Record editor popup */
.record-editor-modal {
  max-width: min(560px, 96vw);
  width: 100%;
  max-height: min(92dvh, 900px);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.record-editor-head {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px 10px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(160deg, rgba(61, 156, 240, 0.08), transparent 70%);
}

.record-editor-titles {
  min-width: 0;
}

.record-editor-kicker {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 2px;
}

.record-editor-modal h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.record-editor-nav {
  min-width: 36px;
  font-size: 1.25rem;
  line-height: 1;
  padding: 6px 10px;
}

.record-editor-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.record-editor-x {
  margin-left: 2px;
}

.record-editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.record-editor-body .form-panel,
.record-editor-body .form-panel-parked {
  display: block !important;
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 0;
  margin: 0;
}

.record-editor-body .panel-head {
  display: none; /* ใช้ title ใน header modal */
}

.record-editor-body .form-actions {
  display: none; /* ใช้ footer modal */
}

.record-editor-body .allowance-box {
  margin-top: 12px;
}

.record-editor-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-elevated);
}

.record-editor-foot-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.record-editor-foot-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

body.record-editor-open {
  overflow: hidden;
}

@media (max-width: 520px) {
  .record-editor-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .record-editor-foot-right {
    flex-direction: column;
  }

  .record-editor-foot .btn {
    width: 100%;
  }
}

.modal h3 {
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.modal p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== Sidebar overlay (mobile) =====
 * Must live inside #appRoot (same stacking context as .sidebar).
 * Overlay on <body> with z-index:35 sat ABOVE the whole .app (z-index:1),
 * so the drawer was visible under the dim layer but taps never hit nav items.
 */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 45;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.visible {
  display: block;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .stat-grid-5 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1100px) {
  .stat-grid,
  .stat-grid-5,
  .stat-grid-tax {
    grid-template-columns: repeat(2, 1fr);
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }

  .flow-op {
    display: none;
  }
}

@media (max-width: 768px) {
  .page-hero {
    padding: 8px 10px;
  }

  .page-hero-title {
    font-size: 1rem;
  }

  .page-hero-stats {
    width: 100%;
  }

  .mini-stat {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  /* มือถือ: เมนูเป็น drawer — ไม่ใช้โหมด collapsed ของเดสก์ท็อป */
  .app.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .app.sidebar-collapsed .sidebar.open,
  .sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }

  .sidebar {
    transform: translateX(-100%);
    pointer-events: none; /* ปิดอยู่: อย่าดัก touch แม้โผล่ขอบ */
  }

  .main-wrap,
  .app.sidebar-collapsed .main-wrap {
    margin-left: 0;
  }

  .sidebar-collapse-btn {
    display: none;
  }

  .menu-btn {
    display: flex;
    position: relative;
    z-index: 30;
    /* ใหญ่ขึ้นนิดสำหรับนิ้ว */
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
  }

  .nav-item {
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(61, 156, 240, 0.15);
  }

  .brand-home {
    touch-action: manipulation;
  }

  .content {
    padding: 16px;
  }

  .topbar {
    padding: 0 16px;
  }

  .topbar-actions .btn span.full {
    display: none;
  }

  .form-wide .field-row {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: 1.15rem;
  }

  .filters {
    flex-direction: column;
  }

  .filters select {
    width: 100%;
  }

  .data-table th:nth-child(3),
  .data-table td:nth-child(3) {
    /* hide note on very small if needed — keep for now */
  }

  .bracket-row {
    grid-template-columns: 1fr auto;
  }

  .bracket-tax {
    grid-column: 1 / -1;
    text-align: left;
  }

  .recent-item {
    grid-template-columns: 60px 1fr;
  }

  .recent-amount {
    grid-column: 2;
    justify-self: start;
  }

  .toast-wrap {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 420px) {
  .stat-grid,
  .stat-grid-5,
  .stat-grid-tax {
    grid-template-columns: 1fr;
  }

  .btn-row {
    flex-direction: column;
  }

  .btn-row .btn {
    width: 100%;
  }
}

/* print-friendly optional */
@media print {
  .sidebar,
  .topbar,
  .page-subnav,
  .form-panel,
  .menu-btn {
    display: none !important;
  }

  .main-wrap {
    margin: 0;
  }

  body {
    background: #fff;
    color: #000;
  }
}
