/* =====================================================================
   Budget App — UI v2 (premium dashboard)
   Design tokens อยู่ที่ :root ทั้งหมด เปลี่ยนสี/มุมโค้ง/เงาได้จากจุดเดียว
   ===================================================================== */
:root {
    color-scheme: light;

    /* พื้นผิว */
    --bg:          #F4F5FA;
    --surface:     #FFFFFF;
    --surface-2:   #F8F9FC;
    --line:        #ECEDF3;
    --line-strong: #DFE1EA;

    /* ตัวอักษร */
    --ink:   #101325;
    --ink-2: #3F4460;
    --muted: #7C819A;

    /* สีเน้น */
    --brand:      #5B4CFF;
    --brand-2:    #8B5CF6;
    --brand-soft: #EEEBFF;

    /* ความหมายของข้อมูล */
    --spent:      #5B4CFF;   /* รายจ่ายจริง */
    --debt:       #FF9F1C;   /* ลูกหนี้ */
    --debt-soft:  #FFF3E0;
    --track:      #ECEDF3;   /* คงเหลือ */
    --good:       #0FB57E;
    --good-soft:  #E3F8EF;
    --warn:       #E58A00;
    --warn-soft:  #FFF4DD;
    --bad:        #F03E5E;
    --bad-soft:   #FFE8EC;

    /* รูปทรง */
    --r-xl: 24px;
    --r-lg: 18px;
    --r-md: 12px;
    --shadow-sm: 0 1px 2px rgba(16, 19, 37, .04);
    --shadow:    0 1px 2px rgba(16, 19, 37, .04), 0 10px 30px -14px rgba(16, 19, 37, .10);
    --shadow-lg: 0 2px 4px rgba(16, 19, 37, .04), 0 24px 48px -20px rgba(16, 19, 37, .22);

    /* ตัวอักษร */
    --font-body:    'IBM Plex Sans Thai', 'Sarabun', system-ui, sans-serif;
    --font-display: 'Noto Serif Thai', 'IBM Plex Sans Thai', serif;
    --font-num:     'Plus Jakarta Sans', 'IBM Plex Sans Thai', system-ui, sans-serif;

    --sidebar-w: 268px;
    --sidebar-w-collapsed: 84px;
}

/* ---------- พื้นฐาน ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.ui2 {
    margin: 0;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
.ui2 a { color: inherit; text-decoration: none; }
.ui2 h1, .ui2 h2, .ui2 h3 { margin: 0; }
.ui2 p { margin: 0; }
.ui2 :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 8px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.dec { opacity: .45; font-weight: 500; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- โครงหน้า ---------- */
.app { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; }
.page { max-width: 1320px; margin: 0 auto; padding: 32px 36px 56px; }
.page--wide { max-width: 1840px; }

/* ---------- Sidebar ---------- */
.sidebar {
    position: sticky; top: 0; height: 100vh; flex-shrink: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    transition: width .28s cubic-bezier(.4, 0, .2, 1);
    z-index: 60;
}
.sb-brand { display: flex; align-items: center; gap: 12px; height: 76px; padding: 0 22px; }
.sb-logo {
    width: 40px; height: 40px; flex-shrink: 0; border-radius: 13px;
    display: grid; place-items: center; color: #fff; font-size: 19px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    box-shadow: 0 8px 18px -8px rgba(91, 76, 255, .7);
}
.sb-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sb-title strong { font-family: var(--font-num); font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.sb-title span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sb-toggle {
    margin-left: auto; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
}
.sb-toggle:hover { color: var(--ink); border-color: var(--line-strong); }

.sb-nav { flex: 1; overflow-y: auto; padding: 8px 14px 16px; scrollbar-width: thin; }
.sb-section { margin: 22px 10px 8px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sb-link {
    position: relative; display: flex; align-items: center; gap: 12px;
    min-height: 44px; padding: 0 12px; margin: 2px 0; border-radius: 12px;
    color: var(--ink-2); font-weight: 500; font-size: 14.5px; white-space: nowrap;
    transition: background .15s, color .15s;
}
.sb-link i { font-size: 18px; width: 22px; text-align: center; color: var(--muted); transition: color .15s; flex-shrink: 0; }
.sb-link:hover { background: var(--surface-2); color: var(--ink); }
.sb-link:hover i { color: var(--ink-2); }
.sb-link.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sb-link.is-active i { color: var(--brand); }
.sb-link.is-active::before {
    content: ""; position: absolute; left: -14px; top: 10px; bottom: 10px; width: 4px;
    border-radius: 0 4px 4px 0; background: var(--brand);
}

.sb-user { padding: 14px; border-top: 1px solid var(--line); }
.sb-user-card { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; background: var(--surface-2); }
.sb-avatar {
    width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
    font-weight: 700; color: var(--brand); background: var(--brand-soft);
}
.sb-user-text { min-width: 0; flex: 1; line-height: 1.3; }
.sb-user-text strong { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-text span { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.sb-logout { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex-shrink: 0; }
.sb-logout:hover { color: var(--bad); background: var(--bad-soft); }
.sb-login {
    display: flex; align-items: center; justify-content: center; gap: 8px; height: 46px; border-radius: 14px;
    color: #fff !important; font-weight: 600; background: linear-gradient(135deg, var(--brand), var(--brand-2));
    box-shadow: 0 10px 20px -10px rgba(91, 76, 255, .8);
}

/* sidebar แบบย่อ (จอใหญ่) */
.sidebar.is-collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.is-collapsed .sb-brand { padding: 0; justify-content: center; }
.sidebar.is-collapsed .sb-title,
.sidebar.is-collapsed .sb-section,
.sidebar.is-collapsed .sb-text,
.sidebar.is-collapsed .sb-user-text,
.sidebar.is-collapsed .sb-logout,
.sidebar.is-collapsed .sb-login span { display: none; }
.sidebar.is-collapsed .sb-toggle { position: absolute; right: -17px; top: 21px; box-shadow: var(--shadow-sm); }
.sidebar.is-collapsed .sb-link { justify-content: center; padding: 0; }
.sidebar.is-collapsed .sb-user-card { justify-content: center; background: none; padding: 0; }
.sidebar.is-collapsed .sb-section-gap { height: 18px; }
.sidebar.is-collapsed .sb-link:hover::after {
    content: attr(data-tip); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    padding: 6px 12px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 500;
    white-space: nowrap; box-shadow: var(--shadow); pointer-events: none;
}

/* แถบบนสำหรับมือถือ */
.topbar { display: none; }
.sb-backdrop { display: none; }

/* ---------- ส่วนหัวของหน้า ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 28px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--brand); letter-spacing: .02em; }
.eyebrow::before { content: ""; width: 18px; height: 2px; border-radius: 2px; background: currentColor; }
.page-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(26px, 3vw, 34px); line-height: 1.25; letter-spacing: -0.01em; margin-top: 6px !important; }
.page-sub { color: var(--muted); margin-top: 6px !important; }
.page-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.back-link { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; color: var(--muted); font-weight: 500; margin-bottom: 8px; }
.back-link:hover { color: var(--brand); }

/* segmented control */
.segmented { display: inline-flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.segmented a {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px;
    font-weight: 500; font-size: 14px; color: var(--muted); transition: background .15s, color .15s;
}
.segmented a:hover { color: var(--ink); }
.segmented a[aria-current="page"] { background: var(--ink); color: #fff; box-shadow: 0 6px 14px -8px rgba(16, 19, 37, .6); }

/* select */
.select-wrap { position: relative; display: inline-flex; align-items: center; }
.select-wrap label { position: absolute; left: 14px; font-size: 12px; color: var(--muted); pointer-events: none; }
.select-wrap select {
    appearance: none; -webkit-appearance: none; height: 48px; padding: 0 40px 0 98px; border-radius: 14px;
    border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm);
    font: 600 15px var(--font-num); color: var(--ink); cursor: pointer;
}
.select-wrap select:hover { border-color: var(--line-strong); }
.select-wrap i { position: absolute; right: 14px; color: var(--muted); pointer-events: none; font-size: 13px; }

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow); }
.card-pad { padding: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.card-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.card-hint { font-size: 13px; color: var(--muted); }

.grid { display: grid; gap: 20px; }
.grid-hero { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); margin-bottom: 20px; }
.grid-kpi  { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.grid-viz  { grid-template-columns: minmax(0, 1fr) minmax(0, 1.45fr); margin-bottom: 20px; }

/* Hero */
.hero {
    position: relative; overflow: hidden; color: #fff; border-radius: var(--r-xl); padding: 30px 32px;
    background:
        radial-gradient(600px 300px at 100% 0%, rgba(167, 139, 250, .55), transparent 60%),
        radial-gradient(500px 280px at 0% 120%, rgba(56, 189, 248, .30), transparent 60%),
        linear-gradient(135deg, #17123F 0%, #2A1F8F 48%, #5B3FE0 100%);
    box-shadow: var(--shadow-lg);
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 28px; align-items: center;
}
.hero::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
    background-image: radial-gradient(rgba(255, 255, 255, .10) 1px, transparent 1px);
    background-size: 18px 18px;
    mask-image: linear-gradient(90deg, transparent 30%, #000 100%);
    -webkit-mask-image: linear-gradient(90deg, transparent 30%, #000 100%);
}
.hero > * { position: relative; z-index: 1; }
.hero-label { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; color: rgba(255, 255, 255, .78); }
.hero-value { font-family: var(--font-num); font-weight: 800; font-size: clamp(48px, 6vw, 72px); line-height: 1; letter-spacing: -0.04em; margin: 14px 0 8px !important; }
.hero-value small { font-size: .45em; font-weight: 700; margin-left: 4px; opacity: .8; }
.hero-formula { font-size: 13px; color: rgba(255, 255, 255, .62); }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 26px; }
.hero-stat { padding: 14px 16px; border-radius: 16px; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .12); backdrop-filter: blur(6px); }
.hero-stat span { display: block; font-size: 12.5px; color: rgba(255, 255, 255, .7); }
.hero-stat strong { display: block; margin-top: 4px; font-family: var(--font-num); font-size: 19px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.hero-stat em { font-style: normal; font-size: 12px; font-weight: 500; opacity: .7; margin-left: 3px; }

.ring { width: 188px; height: 188px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center strong { font-family: var(--font-num); font-size: 15px; font-weight: 700; }
.ring-center span { font-size: 12px; color: rgba(255, 255, 255, .7); }
.ring-legend { display: flex; justify-content: center; gap: 14px; margin-top: 12px; font-size: 12.5px; color: rgba(255, 255, 255, .78); }
.ring-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.pill-glass { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .18); }
.pill-glass::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, #fff); box-shadow: 0 0 0 3px rgba(255, 255, 255, .12); }

/* KPI */
.kpi { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.kpi-top { display: flex; align-items: center; gap: 12px; }
.kpi-icon { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 19px; flex-shrink: 0; color: var(--c); background: var(--c-soft); }
.kpi-label { font-size: 14px; font-weight: 500; color: var(--ink-2); line-height: 1.35; }
.kpi-value { font-family: var(--font-num); font-size: clamp(22px, 2vw, 27px); font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; white-space: nowrap; }
.kpi-value small { font-family: var(--font-body); font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.kpi-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.kpi-foot b { font-family: var(--font-num); font-weight: 700; color: var(--c); }
.kpi--dark { background: linear-gradient(160deg, #13162B, #1E2240); border-color: transparent; color: #fff; }
.kpi--dark .kpi-label { color: rgba(255, 255, 255, .78); }
.kpi--dark .kpi-value small, .kpi--dark .kpi-foot { color: rgba(255, 255, 255, .62); }
.kpi--dark .kpi-icon { background: rgba(15, 181, 126, .18); }

/* แถบความคืบหน้า */
.bar { display: flex; height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar > span { height: 100%; }
.bar > span + span { box-shadow: -2px 0 0 var(--surface); }
.bar--thin { height: 6px; }
.bar--lg { height: 12px; }
.bar-spent { background: linear-gradient(90deg, #6D5DFF, var(--spent)); }
.bar-debt { background: var(--debt); }
.bar-solid { background: var(--c, var(--brand)); }
.kpi--dark .bar { background: rgba(255, 255, 255, .12); }

/* ป้ายสถานะ */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill--good { color: var(--good); background: var(--good-soft); }
.pill--warn { color: var(--warn); background: var(--warn-soft); }
.pill--bad  { color: var(--bad);  background: var(--bad-soft); }
.pill--none { color: var(--muted); background: var(--surface-2); }
.pill--debt { color: #C46A00; background: var(--debt-soft); }
.pill--spent { color: var(--brand); background: var(--brand-soft); }

/* รายการที่ควรติดตาม */
.watch { display: flex; flex-direction: column; }
.watch-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.watch-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 16px; border: 1px solid var(--line); transition: border-color .15s, background .15s, transform .15s; }
.watch-item:hover { border-color: var(--line-strong); background: var(--surface-2); transform: translateY(-1px); }
.watch-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; color: var(--c); background: var(--c-soft); }
.watch-text { flex: 1; min-width: 0; line-height: 1.4; }
.watch-text strong { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-text span { font-size: 13px; color: var(--muted); }
.watch-item > .bi-chevron-right { color: var(--muted); font-size: 13px; }
.watch-empty { flex: 1; display: grid; place-content: center; text-align: center; gap: 8px; padding: 20px; color: var(--muted); }
.watch-empty i { font-size: 30px; color: var(--good); }

/* สัดส่วนงบ */
.share { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 24px; align-items: center; }
.share-chart { position: relative; width: 190px; height: 190px; }
.share-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.share-center strong { font-family: var(--font-num); font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.share-center span { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow-y: auto; scrollbar-width: thin; }
.legend li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; font-size: 13.5px; }
.legend li:hover { background: var(--surface-2); }
.legend i { width: 10px; height: 10px; border-radius: 4px; flex-shrink: 0; }
.legend span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.legend b { font-family: var(--font-num); font-weight: 600; font-size: 13px; }

.chart-box { position: relative; width: 100%; }
.legend-inline { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--muted); }
.legend-inline span { display: inline-flex; align-items: center; gap: 7px; }
.legend-inline i { width: 10px; height: 10px; border-radius: 4px; }

/* ---------- ตารางข้อมูล ---------- */
.table-card { overflow: hidden; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.table-head .card-title small { font-family: var(--font-num); font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 6px; }
.table-scroll { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.dtable th {
    padding: 12px 14px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--muted); text-align: left; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.dtable td { padding: 16px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dtable th:first-child, .dtable td:first-child { padding-left: 24px; }
.dtable th:last-child,  .dtable td:last-child  { padding-right: 24px; }
.dtable .r { text-align: right; }
.dtable tbody tr { transition: background .12s; }
.dtable tbody tr:hover { background: #FAFAFE; }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tfoot td { background: var(--surface-2); border-top: 1px solid var(--line-strong); border-bottom: 0; font-weight: 700; }
.dtable .money { font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.dtable .money.strong { font-weight: 700; }
.dtable .money.soft { color: var(--muted); }
.dtable .money.neg { color: var(--bad); }

.row-name { display: flex; align-items: center; gap: 12px; min-width: 220px; text-align: left; background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.row-swatch { width: 10px; height: 34px; border-radius: 6px; flex-shrink: 0; background: var(--c); }
.row-name strong { display: block; font-weight: 600; line-height: 1.4; }
.row-name small { display: block; font-size: 12.5px; color: var(--muted); }
.row-name:hover strong { color: var(--brand); }
.row-name .bi-arrow-up-right { color: var(--muted); font-size: 12px; opacity: 0; transition: opacity .15s; }
tr:hover .row-name .bi-arrow-up-right { opacity: 1; }

.progress-cell { display: flex; align-items: center; gap: 12px; min-width: 190px; }
.progress-cell .bar { flex: 1; }
.progress-cell b { font-family: var(--font-num); font-weight: 700; font-size: 14px; width: 56px; text-align: right; }

/* ตัวกรองรายการ */
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { position: relative; }
.search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input {
    height: 42px; width: 260px; max-width: 100%; padding: 0 14px 0 40px; border-radius: 12px;
    border: 1px solid var(--line); background: var(--surface-2); font: inherit; font-size: 14px; color: var(--ink);
}
.search input:focus { outline: none; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 4px var(--brand-soft); }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
    height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
    font: 500 13.5px var(--font-body); color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--line-strong); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip b { font-family: var(--font-num); font-weight: 700; font-size: 12px; opacity: .7; }
.no-results { display: none; padding: 40px; text-align: center; color: var(--muted); }

/* ---------- หน้าต่างรายการเคลื่อนไหว ---------- */
dialog.sheet {
    width: min(920px, calc(100vw - 32px)); max-height: min(86vh, 900px); padding: 0; border: 0;
    border-radius: var(--r-xl); box-shadow: var(--shadow-lg); color: var(--ink); background: var(--surface);
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .22s cubic-bezier(.2, .8, .2, 1); }
dialog.sheet::backdrop { background: rgba(16, 19, 37, .45); backdrop-filter: blur(3px); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px) scale(.985); } to { opacity: 1; transform: none; } }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { font-size: 18px; font-weight: 600; line-height: 1.4; }
.sheet-head p { font-size: 13.5px; color: var(--muted); margin-top: 4px !important; }
.sheet-close { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.sheet-close:hover { color: var(--ink); background: var(--surface-2); }
.sheet-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.sheet-summary div { background: var(--surface); padding: 14px 24px; }
.sheet-summary span { display: block; font-size: 12.5px; color: var(--muted); }
.sheet-summary strong { font-family: var(--font-num); font-size: 16px; font-weight: 700; white-space: nowrap; }
.sheet-body { overflow-y: auto; }
.sheet-body .dtable th { position: sticky; top: 0; z-index: 1; }
.tx-desc { font-weight: 500; }
.tx-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
tr.is-overdue { background: #FFF7F8; }

/* ---------- สถานะว่าง ---------- */
.empty { padding: 64px 24px; text-align: center; display: grid; justify-items: center; gap: 10px; }
.empty-icon { width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center; font-size: 30px; color: var(--brand); background: var(--brand-soft); margin-bottom: 6px; }
.empty h2 { font-size: 20px; font-weight: 600; }
.empty p { color: var(--muted); }
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 20px;
    border-radius: 14px; border: 0; font: 600 14.5px var(--font-body); cursor: pointer; margin-top: 10px;
    color: #fff !important; background: linear-gradient(135deg, var(--brand), var(--brand-2));
    box-shadow: 0 10px 20px -10px rgba(91, 76, 255, .8);
}

.foot-note { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
    .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-hero, .grid-viz { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1023px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w) !important;
        transform: translateX(-100%); transition: transform .28s cubic-bezier(.4, 0, .2, 1); box-shadow: var(--shadow-lg);
    }
    .sidebar.is-open { transform: none; }
    .sidebar .sb-toggle { display: none; }
    /* บนมือถือแสดงเมนูเต็มเสมอ แม้เคยย่อไว้บนจอใหญ่ */
    .sidebar.is-collapsed .sb-title, .sidebar.is-collapsed .sb-section, .sidebar.is-collapsed .sb-text,
    .sidebar.is-collapsed .sb-user-text, .sidebar.is-collapsed .sb-logout { display: initial; }
    .sidebar.is-collapsed .sb-brand { justify-content: flex-start; padding: 0 22px; }
    .sidebar.is-collapsed .sb-link { justify-content: flex-start; padding: 0 12px; }
    .sidebar.is-collapsed .sb-user-card { justify-content: flex-start; background: var(--surface-2); padding: 10px; }
    .sb-backdrop.is-open { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(16, 19, 37, .4); backdrop-filter: blur(2px); }
    .topbar {
        display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 40; height: 62px; padding: 0 16px;
        background: rgba(255, 255, 255, .86); backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--line);
    }
    .topbar button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; font-size: 20px; color: var(--ink); cursor: pointer; }
    .topbar strong { font-family: var(--font-num); font-weight: 800; letter-spacing: -0.02em; }
    .page { padding: 24px 20px 48px; }
}

@media (max-width: 760px) {
    body.ui2 { font-size: 14.5px; }
    .page { padding: 20px 16px 40px; }
    .page-head { margin-bottom: 20px; }
    .page-tools, .segmented { width: 100%; }
    .segmented a { flex: 1; justify-content: center; padding: 0 10px; }
    .select-wrap, .select-wrap select { width: 100%; }
    .grid { gap: 14px; }
    .grid-hero, .grid-kpi, .grid-viz { margin-bottom: 14px; }
    .grid-kpi { grid-template-columns: minmax(0, 1fr); }
    .card-pad { padding: 20px; }
    .hero { grid-template-columns: minmax(0, 1fr); padding: 24px 20px; gap: 20px; }
    .hero .ring-wrap { order: -1; justify-self: center; }
    .ring { width: 160px; height: 160px; }
    .hero-stats { grid-template-columns: minmax(0, 1fr); }
    .hero-stat { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
    .hero-stat strong { margin-top: 0; font-size: 17px; }
    .share { grid-template-columns: minmax(0, 1fr); justify-items: center; }
    .legend { width: 100%; max-height: none; }
    .table-head { padding: 18px 16px; }
    .search, .search input { width: 100%; }
    .filters { width: 100%; }

    /* ตาราง → การ์ด */
    .dtable thead { display: none; }
    .dtable, .dtable tbody, .dtable tfoot, .dtable tr, .dtable td { display: block; width: 100%; }
    .dtable tbody tr { padding: 16px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
    .dtable tbody tr:last-child { border-bottom: 0; }
    .dtable td { padding: 0 !important; border: 0; }
    .dtable td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); font-family: var(--font-body); font-weight: 400; }
    .dtable td.r { text-align: left; }
    .dtable td.span-2 { grid-column: 1 / -1; }
    .dtable td.cell-status { grid-column: 1 / -1; order: -1; }
    .dtable td.cell-name { grid-column: 1 / -1; order: -2; }
    .dtable tfoot tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 16px; }
    .dtable tfoot td.cell-name { grid-column: 1 / -1; }
    .progress-cell { min-width: 0; }
    .row-name { min-width: 0; }
    .sheet-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sheet-summary div { padding: 12px 16px; }
    .sheet-head { padding: 18px 16px; }
    .dtable.tx tbody tr { grid-template-columns: 1fr auto; }
    dialog.sheet { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: var(--r-xl) var(--r-xl) 0 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
