/* Layout: เมนูซ้ายแบบลิ้นชักสไลด์เปิด-ปิด + พื้นที่การ์ดด้านขวา
   โทน: ขาวสะอาดแบบ Apple ปุ่มฟ้า iOS */
:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-2: #f2f2f5;
  --panel-3: #e8e8ed;
  --line: rgba(0, 0, 0, .07);
  --line-2: rgba(0, 0, 0, .12);
  --fg: #1d1d1f;
  --fg-2: #6e6e73;
  --fg-3: #a1a1a6;
  --accent: #007aff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(0, 122, 255, .1);
  --gain: #248a3d;
  --gain-soft: rgba(52, 199, 89, .14);
  --loss: #d70015;
  --loss-soft: rgba(255, 59, 48, .1);
  --warn: #c93400;
  --warn-soft: rgba(255, 149, 0, .14);
  --i-blue: #007aff;
  --i-green: #34c759;
  --i-orange: #ff9500;
  --i-red: #ff3b30;
  --i-gray: #8e8e93;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 20px rgba(0, 0, 0, .04);
  --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .25);
  --scrim: rgba(0, 0, 0, .28);
  --glass: rgba(245, 245, 247, .78);
  --font: "Kanit", -apple-system, BlinkMacSystemFont, "Helvetica Neue", system-ui, sans-serif;
  --font-display: "Kanit", -apple-system, BlinkMacSystemFont, "Helvetica Neue", system-ui, sans-serif;
  --drawer-w: 272px;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --panel: #1c1c1e; --panel-2: #2c2c2e; --panel-3: #3a3a3c;
    --line: rgba(255, 255, 255, .08); --line-2: rgba(255, 255, 255, .14);
    --fg: #f5f5f7; --fg-2: #98989d; --fg-3: #636366;
    --accent: #0a84ff; --accent-ink: #ffffff; --accent-soft: rgba(10, 132, 255, .18);
    --gain: #30d158; --gain-soft: rgba(48, 209, 88, .16); --loss: #ff453a; --loss-soft: rgba(255, 69, 58, .16);
    --warn: #ff9f0a; --warn-soft: rgba(255, 159, 10, .16);
    --i-blue: #0a84ff; --i-green: #30d158; --i-orange: #ff9f0a; --i-red: #ff453a; --i-gray: #8e8e93;
    --shadow: none; --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .7); --scrim: rgba(0, 0, 0, .55); --glass: rgba(0, 0, 0, .72);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --panel: #1c1c1e; --panel-2: #2c2c2e; --panel-3: #3a3a3c;
  --line: rgba(255, 255, 255, .08); --line-2: rgba(255, 255, 255, .14);
  --fg: #f5f5f7; --fg-2: #98989d; --fg-3: #636366;
  --accent: #0a84ff; --accent-ink: #ffffff; --accent-soft: rgba(10, 132, 255, .18);
  --gain: #30d158; --gain-soft: rgba(48, 209, 88, .16); --loss: #ff453a; --loss-soft: rgba(255, 69, 58, .16);
  --warn: #ff9f0a; --warn-soft: rgba(255, 159, 10, .16);
  --i-blue: #0a84ff; --i-green: #30d158; --i-orange: #ff9f0a; --i-red: #ff453a; --i-gray: #8e8e93;
  --shadow: none; --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .7); --scrim: rgba(0, 0, 0, .55); --glass: rgba(0, 0, 0, .72);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; letter-spacing: 0; font-weight: 400;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 40; background: var(--glass); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.chart svg, .hero-spark svg, .donut svg { stroke: none; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); line-height: 1.2; text-wrap: balance; }
p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

/* ---------- โลโก้ ---------- */
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none; position: relative;
  background: linear-gradient(180deg, #4aa3ff, #007aff);
  box-shadow: 0 4px 12px -4px rgba(0, 122, 255, .55);
}
.logo span { position: absolute; inset: 7px 11px; border-radius: 4px; border: 1.8px solid #fff; }
.logo span::after { content: ""; position: absolute; top: 2px; left: 50%; width: 5px; height: 1.8px; margin-left: -2.5px; border-radius: 2px; background: #fff; }
.logo.lg { width: 72px; height: 72px; border-radius: 18px; }
.logo.lg span { inset: 13px 22px; border-radius: 7px; border-width: 2.8px; }
.logo.lg span::after { top: 4px; width: 10px; margin-left: -5px; height: 2.6px; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 980px;
  padding: 10px 18px; font-weight: 600; font-size: 15px; background: var(--panel-2); transition: transform .12s ease, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn svg { width: 18px; height: 18px; stroke-width: 2.4; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-ghost { background: var(--panel-2); color: var(--accent); }
.btn-ghost:hover { background: var(--panel-3); }
.btn-danger { background: var(--loss-soft); color: var(--loss); }
.btn-danger.armed { background: var(--loss); color: #fff; }
.btn-lg { width: 100%; padding: 14px; font-size: 17px; border-radius: 14px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  border: 0; background: var(--panel-2); color: var(--fg);
}
.icon-btn:hover { background: var(--panel-3); }
.icon-btn svg { width: 20px; height: 20px; stroke-width: 2.1; }
.icon-btn.ghost { background: none; color: var(--fg-2); }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 500; font-size: 15px; padding: 2px 0; white-space: nowrap; }
.link-btn::after { content: " ›"; font-size: 18px; line-height: 0; }

/* ---------- ช่องกรอก ---------- */
input, select, textarea {
  width: 100%; border: 1px solid transparent; background: var(--panel-2); border-radius: var(--r-sm);
  padding: 12px 14px; font-size: 17px; outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder, textarea::placeholder { color: var(--fg-3); }
input:focus, select:focus, textarea:focus { background: var(--panel); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
textarea { resize: vertical; }
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 500; color: var(--fg-2); }
.field-label em { font-style: normal; color: var(--fg-3); font-weight: 400; margin-left: 4px; }
.form-error { color: var(--loss); font-size: 14px; }
.form-error:empty { display: none; }
.select { width: auto; padding: 9px 34px 9px 14px; font-size: 15px; border-radius: 980px; background-color: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }

/* ---------- ล็อกอิน ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding-block: 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.login-sheen { display: none; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 16px; text-align: center; }
.login-card .logo { margin: 0 auto 6px; }
.login-title { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.login-sub { color: var(--fg-2); margin-top: -10px; margin-bottom: 14px; font-size: 17px; }
.login-card .field { text-align: left; }
.login-card input { background: var(--panel); box-shadow: var(--shadow); border-color: var(--line); }

/* ---------- เมนูลิ้นชัก ---------- */
.drawer {
  position: fixed; z-index: 35; top: 0; bottom: 0; left: 0; width: var(--drawer-w);
  display: flex; flex-direction: column; gap: 8px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px)); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: 12px;
  background: var(--panel); border-right: 1px solid var(--line);
  transform: translateX(-100%); transition: transform .32s cubic-bezier(.32, .72, 0, 1), box-shadow .32s;
  overflow-y: auto; overscroll-behavior: contain;
}
.shell.open .drawer { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 4px 4px 12px; }
.drawer-brand { flex: 1; min-width: 0; line-height: 1.25; }
.drawer-brand strong { display: block; font-family: var(--font-display); font-size: 17px; font-weight: 700; }
.drawer-brand small { display: block; color: var(--fg-2); font-size: 12.5px; }
.drawer-nav { display: grid; gap: 2px; }
.drawer-label { font-size: 12.5px; color: var(--fg-3); font-weight: 500; padding: 14px 10px 6px; }
.drawer-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; border-radius: 12px; border: 0; background: none;
  font-size: 15.5px; font-weight: 500; text-align: left; color: var(--fg); transition: background .15s;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.danger { color: var(--loss); }
.nav-ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; }
.nav-ico svg { width: 17px; height: 17px; stroke-width: 2.2; }
.nav-ico.blue { background: var(--i-blue); }
.nav-ico.green { background: var(--i-green); }
.nav-ico.orange { background: var(--i-orange); }
.nav-ico.red { background: var(--i-red); }
.nav-ico.gray { background: var(--i-gray); }
.nav-count { margin-left: auto; font-style: normal; font-size: 14px; color: var(--fg-3); font-variant-numeric: tabular-nums; }
.nav-item.active .nav-count { color: var(--accent); }
.scrim {
  position: fixed; inset: 0; z-index: 34; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity .3s;
}

/* ---------- พื้นที่หลัก ---------- */
.main { min-width: 0; transition: margin-left .32s cubic-bezier(.32, .72, 0, 1); }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 12px;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--glass); backdrop-filter: saturate(1.8) blur(20px); -webkit-backdrop-filter: saturate(1.8) blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; line-height: 1.2; }
.topbar-title strong { display: block; font-family: var(--font-display); font-size: 17px; font-weight: 600; }
.topbar-title small { display: block; font-size: 12.5px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-btn { padding: 9px 16px 9px 13px; }

.stage {
  max-width: 1240px; margin: 0 auto; display: grid; gap: 20px;
  padding-block: 24px 64px; padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px));
}

@media (min-width: 1024px) {
  .shell.open .main { margin-left: var(--drawer-w); }
  .shell.open .topbar { padding-left: 24px; }
}
@media (max-width: 1023px) {
  .shell.open .drawer { box-shadow: var(--shadow-lg); }
  .shell.open .scrim { opacity: 1; pointer-events: auto; }
  .drawer { width: min(var(--drawer-w), 84vw); }
}

.view { display: grid; gap: 20px; animation: rise .35s ease; }
@keyframes rise { from { opacity: .001; transform: translateY(6px); } }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 13px; color: var(--fg-2); font-weight: 500; }
.view-title { font-size: 34px; font-weight: 700; letter-spacing: -.025em; }

.chips { display: flex; gap: 2px; padding: 2px; border-radius: 10px; background: var(--panel-3); overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0; background: none; padding: 6px 14px; border-radius: 8px; color: var(--fg); font-size: 14px; font-weight: 500;
  white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; transition: background .15s;
}
.chip i { font-style: normal; font-size: 13px; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.chip.active { background: var(--panel); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); font-weight: 600; }

/* ---------- การ์ด ---------- */
.bento { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.panel, .tile, .hero { background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow); min-width: 0; }
.hero { grid-column: span 6; grid-row: span 2; position: relative; overflow: hidden; padding: 24px 24px 0; display: flex; flex-direction: column; gap: 6px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hero-label { font-size: 15px; color: var(--fg-2); font-weight: 500; }
.delta { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 980px; }
.delta.up { background: var(--gain-soft); color: var(--gain); }
.delta.down { background: var(--loss-soft); color: var(--loss); }
.hero-value { display: flex; align-items: baseline; gap: 4px; line-height: 1.1; font-family: var(--font-display); font-weight: 600; letter-spacing: -.02em; color: var(--fg); }
.hero-value .cur { font-size: 36px; color: var(--fg-2); font-weight: 600; }
.hero-value .num { font-size: clamp(56px, 7vw, 80px); }
.hero-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--fg-2); font-size: 14px; margin-top: 4px; }
.hero-meta b { color: var(--fg); font-weight: 600; }
.dot { width: 3px; height: 3px; border-radius: 50%; background: var(--fg-3); }
.hero-spark { margin: auto -24px 0; height: 130px; }
.hero-spark svg { display: block; width: 100%; height: 100%; }

.tile { grid-column: span 3; padding: 18px; display: grid; gap: 2px; align-content: start; }
.tile-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; margin-bottom: 12px; color: #fff; }
.tile:nth-of-type(2) .tile-icon { background: var(--i-blue); }
.tile:nth-of-type(3) .tile-icon { background: var(--i-orange); }
.tile:nth-of-type(4) .tile-icon { background: var(--i-green); }
.tile:nth-of-type(5) .tile-icon { background: var(--i-gray); }
.tile-icon svg { width: 17px; height: 17px; stroke-width: 2.2; }
.tile-label { font-size: 14px; color: var(--fg-2); font-weight: 500; }
.tile-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { font-size: 13px; color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panel { padding: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.panel-sub { font-size: 13px; color: var(--fg-2); margin-top: 2px; }
.span-chart { grid-column: span 8; display: flex; flex-direction: column; }
.span-chart .chart { flex: 1; min-height: 260px; }
.span-donut { grid-column: span 4; }
.span-half { grid-column: span 6; }

.legend { display: flex; gap: 14px; font-size: 13px; color: var(--fg-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend span::before { content: ""; width: 10px; height: 10px; border-radius: 50%; }
.lg-profit::before { background: var(--accent); }
.lg-rev::before { background: var(--panel-3); }

.chart { position: relative; height: 260px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart text { font-family: var(--font); }
.chart .col-hit { cursor: pointer; }
.chart-tip {
  position: absolute; transform: translate(-50%, -100%); pointer-events: none; z-index: 2; white-space: nowrap;
  background: var(--panel); border-radius: 12px; padding: 8px 12px; font-size: 13px; box-shadow: var(--shadow-lg), 0 0 0 .5px var(--line-2);
}
.chart-tip b { display: block; font-size: 15px; }
.chart-tip span { color: var(--fg-2); }

.donut-wrap { display: grid; gap: 18px; justify-items: center; }
.donut { position: relative; width: 180px; height: 180px; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center b { font-family: var(--font-display); font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.donut-center span { font-size: 12px; color: var(--fg-2); }
.donut-legend { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 9px; }
.donut-legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; font-size: 14px; }
.donut-legend i { width: 10px; height: 10px; border-radius: 50%; }
.donut-legend span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend b { font-variant-numeric: tabular-nums; font-weight: 600; }
.donut-legend small { color: var(--fg-3); width: 36px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- แถว ---------- */
.rows { display: grid; }
.row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 10px 8px; margin: 0 -8px;
  border: 0; background: none; text-align: left; border-radius: 12px; transition: background .15s; position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 56px; right: 8px; height: 1px; background: var(--line); }
.row:hover { background: var(--panel-2); }
.row-main { min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; }
.row-end b { font-variant-numeric: tabular-nums; font-weight: 600; }

.device {
  --c: var(--panel-3); width: 34px; height: 48px; border-radius: 9px; position: relative; flex: none;
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 100%, white 25%), var(--c) 55%, color-mix(in srgb, var(--c) 82%, black));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08), inset 0 1px 0 rgba(255, 255, 255, .4);
}
.device::before {
  content: ""; position: absolute; top: 5px; left: 5px; width: 13px; height: 13px; border-radius: 4px;
  background: color-mix(in srgb, var(--c) 72%, black); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.device::after { content: ""; position: absolute; top: 8px; left: 8px; width: 4px; height: 4px; border-radius: 50%; background: rgba(0, 0, 0, .55); box-shadow: 4px 4px 0 rgba(0, 0, 0, .55); }
.device.lg { width: 44px; height: 62px; border-radius: 11px; }
.device.lg::before { width: 17px; height: 17px; top: 6px; left: 6px; border-radius: 5px; }
.device.lg::after { top: 10px; left: 10px; width: 5px; height: 5px; box-shadow: 5px 5px 0 rgba(0, 0, 0, .55); }

.age { font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 980px; background: var(--panel-2); color: var(--fg-2); white-space: nowrap; }
.age.warn { background: var(--warn-soft); color: var(--warn); }
.age.hot { background: var(--loss-soft); color: var(--loss); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.ex { font-size: 11px; font-weight: 500; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); color: var(--fg-2); margin-left: 6px; vertical-align: 2px; }
.muted-empty { color: var(--fg-3); font-size: 14px; padding: 18px 0; text-align: center; }

/* ---------- รายการ ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { position: relative; flex: 1 1 260px; min-width: 0; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--fg-3); pointer-events: none; }
.search input { padding: 10px 14px 10px 38px; background: var(--panel-3); border-radius: 12px; font-size: 16px; }
.search input:focus { background: var(--panel); }
.list-summary { color: var(--fg-2); font-size: 14px; }
.list-summary b { color: var(--fg); font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.pcard {
  display: grid; gap: 14px; padding: 16px; border-radius: var(--r-lg); text-align: left; width: 100%; border: 0;
  background: var(--panel); box-shadow: var(--shadow); transition: transform .18s ease, box-shadow .18s;
}
.pcard:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(0, 0, 0, .04), 0 12px 32px rgba(0, 0, 0, .08); }
.pcard-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.pcard-title { font-family: var(--font-display); font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 12.5px; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); color: var(--fg-2); white-space: nowrap; }
.status { font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 980px; white-space: nowrap; }
.status.in_stock { background: var(--warn-soft); color: var(--warn); }
.status.sold { background: var(--gain-soft); color: var(--gain); }
.pcard-nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--panel-2); border-radius: 12px; }
.pcard-nums div { padding: 10px 12px; display: grid; }
.pcard-nums div + div { border-left: 1px solid var(--line); }
.pcard-nums span { font-size: 12px; color: var(--fg-2); }
.pcard-nums b { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard-foot { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--fg-2); }
.pcard-foot span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { display: grid; justify-items: center; gap: 14px; padding: 48px 0; color: var(--fg-3); }
.empty-glyph { width: 46px; height: 70px; border-radius: 12px; border: 2px dashed var(--line-2); }

/* ---------- ฟอร์ม ---------- */
dialog.sheet {
  border: 0; padding: 0; border-radius: 22px; width: min(580px, calc(100% - 32px)); max-height: calc(100dvh - 40px);
  background: var(--bg); color: var(--fg); box-shadow: var(--shadow-lg); overflow: hidden;
}
dialog.sheet[open] { animation: pop .3s cubic-bezier(.32, .72, 0, 1); }
@keyframes pop { from { opacity: .001; transform: translateY(16px) scale(.98); } }
dialog.sheet::backdrop { background: var(--scrim); }
.sheet form { display: flex; flex-direction: column; max-height: calc(100dvh - 40px); }
.sheet-grab { display: none; }
.sheet-head { display: flex; align-items: center; gap: 14px; padding: 18px 18px 14px; }
.sheet-titles { flex: 1; min-width: 0; }
.sheet-titles h2 { font-size: 22px; font-weight: 700; letter-spacing: -.015em; }
.sheet-titles p { font-size: 14px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { overflow-y: auto; padding: 0 18px 8px; overscroll-behavior: contain; display: grid; gap: 14px; align-content: start; }
.fs { display: grid; gap: 14px; padding: 16px; background: var(--panel); border-radius: 16px; }
.fs-title { font-size: 13px; color: var(--fg-2); font-weight: 600; margin: 0; }
.fs input, .fs textarea { background: var(--panel-2); }
.fs input:focus, .fs textarea:focus { background: var(--panel); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -6px; }
.quick:empty { display: none; }
.quick button { border: 0; background: var(--accent-soft); border-radius: 980px; padding: 4px 11px; font-size: 13px; color: var(--accent); font-weight: 500; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { border: 0; background: var(--panel-2); border-radius: 980px; padding: 8px 14px; font-size: 14.5px; font-weight: 500; transition: all .15s; }
.pill[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  --c: #888; width: 32px; height: 32px; border-radius: 50%; border: 0; padding: 0;
  background: linear-gradient(145deg, color-mix(in srgb, var(--c) 100%, white 25%), var(--c) 55%, color-mix(in srgb, var(--c) 80%, black));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.swatch[aria-checked="true"] { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 2px; border-radius: 10px; background: var(--panel-3); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px; border-radius: 8px; font-weight: 500; font-size: 14.5px; cursor: pointer; transition: all .18s; }
.seg input:checked + span { background: var(--panel); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--accent-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money { position: relative; display: block; }
.money b { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--fg-3); font-weight: 600; pointer-events: none; font-size: 17px; }
.money input { padding-left: 30px; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.profit-card { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-radius: 14px; background: var(--gain-soft); color: var(--gain); }
.profit-card.neg { background: var(--loss-soft); color: var(--loss); }
.profit-card > span:first-child { font-size: 14px; font-weight: 500; }
.profit-card strong { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.profit-pct { font-weight: 500; font-size: 14px; }
#formError { padding: 0 18px 6px; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 18px 18px; background: var(--bg); }
.spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: transform .3s cubic-bezier(.32, .72, 0, 1), opacity .25s;
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 980px; font-weight: 500; font-size: 15px;
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow-lg); max-width: calc(100% - 32px);
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--i-green); flex: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.demo-note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 14px; font-size: 14px; background: var(--accent-soft); color: var(--fg); }
.demo-note b { color: var(--accent); white-space: nowrap; }

/* ---------- ปรับตามขนาดจอ ---------- */
@media (max-width: 1180px) {
  .hero { grid-column: span 12; grid-row: auto; min-height: 290px; }
  .span-chart, .span-donut { grid-column: span 12; }
  .donut-wrap { grid-template-columns: 180px minmax(0, 1fr); align-items: center; justify-items: stretch; gap: 28px; }
}
@media (max-width: 680px) {
  .stage { padding-block: 16px 48px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); gap: 16px; }
  .view-head { display: grid; gap: 12px; }
  .view-title { font-size: 30px; }
  .bento { gap: 12px; }
  .hero { padding: 20px 20px 0; min-height: 0; }
  .hero-spark { margin: 6px -20px 0; height: 104px; }
  .hero-value .cur { font-size: 28px; }
  .hero-value .num { font-size: 56px; }
  .tile { grid-column: span 6; padding: 16px 14px; }
  .tile-icon { margin-bottom: 10px; }
  .tile-value { font-size: 22px; }
  .panel { padding: 18px 16px; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .donut { width: 168px; height: 168px; }
  .span-half { grid-column: span 12; }
  .chips { width: 100%; }
  .chips .chip { flex: 1; justify-content: center; }
  .toolbar .select { flex: 1; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .add-btn span { display: none; }
  .add-btn { width: 38px; height: 38px; padding: 0; }
  dialog.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: calc(94dvh - env(safe-area-inset-top, 0px)); }
  dialog.sheet[open] { animation: slide .35s cubic-bezier(.32, .72, 0, 1); }
  @keyframes slide { from { transform: translateY(40%); opacity: .001; } }
  .sheet form { max-height: calc(94dvh - env(safe-area-inset-top, 0px)); }
  .sheet-grab { display: block; width: 36px; height: 5px; border-radius: 99px; background: var(--fg-3); opacity: .5; margin: 6px auto 0; }
  .sheet-head { padding: 8px 16px 12px; }
  .sheet-body { padding: 0 16px 6px; }
  .sheet-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
  #formError { padding: 0 16px 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
