:root {
  --ink: #15243a;
  --muted: #68758a;
  --line: #dde3ec;
  --paper: #ffffff;
  --canvas: #f3f6fa;
  --navy: #132338;
  --orange: #ee5d26;
  --orange-soft: #fff0e9;
  --green: #198754;
  --yellow: #a96500;
  --red: #c0392b;
  --blue: #2463a7;
  --shadow: 0 12px 38px rgba(22, 40, 64, .08);
}
* { box-sizing: border-box; }
html { font-family: "Noto Sans Thai", "Leelawadee UI", Arial, sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; font-size: 16px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); margin: .3rem 0 0; }
.eyebrow { margin: 0 0 .25rem; color: #7d8999; font-weight: 800; font-size: .76rem; letter-spacing: .12em; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: clamp(1.6rem, 3vw, 2.15rem); }
h2 { font-size: 1.12rem; }
label { display: grid; gap: .42rem; font-weight: 700; font-size: .88rem; color: #4c5a6d; }
input, select { min-height: 43px; padding: .65rem .78rem; border: 1px solid #ccd5e2; border-radius: 10px; background: #fff; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: #4d78a8; box-shadow: 0 0 0 3px rgba(77,120,168,.14); }
.primary, .secondary, .dark-button { min-height: 43px; border: 0; border-radius: 10px; padding: .68rem 1rem; font-weight: 800; }
.primary { background: var(--orange); color: #fff; box-shadow: 0 6px 16px rgba(238,93,38,.22); }
.primary:hover { background: #d94c18; }
.secondary { background: #fff; color: var(--ink); border: 1px solid #cfd7e3; }
.dark-button { background: var(--navy); color: #fff; }
.full { width: 100%; }
.link-button { border: 0; background: none; padding: .4rem; color: #52647b; text-decoration: underline; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 25% 15%, #324964 0, #132338 40%, #0c1725 100%); }
.login-card { width: min(420px, 100%); display: grid; gap: 1rem; padding: 2rem; border-radius: 24px; background: rgba(255,255,255,.97); box-shadow: 0 28px 70px rgba(0,0,0,.28); }
.brand-mark { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: var(--orange); color: #fff; font-weight: 900; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 12px; font-size: .88rem; }
.error-text { min-height: 1.2rem; color: var(--red); margin: 0; font-weight: 700; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 1.15rem; display: flex; flex-direction: column; color: #e8eef7; background: var(--navy); }
.brand-row { display: flex; align-items: center; gap: .8rem; padding: .35rem .3rem 1.4rem; }
.brand-row strong, .brand-row span { display: block; }
.brand-row span { margin-top: .1rem; color: #8fa0b7; font-size: .75rem; }
nav { display: grid; gap: .4rem; }
.nav-item { text-align: left; border: 0; border-radius: 10px; padding: .82rem .9rem; color: #aebdd0; background: transparent; font-weight: 800; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.1); }
.nav-item.active { box-shadow: inset 3px 0 var(--orange); }
.sidebar-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid rgba(255,255,255,.1); padding-top: 1rem; font-size: .88rem; }
.sidebar .link-button { color: #b8c5d5; }
main { min-width: 0; padding: 1.4rem clamp(1rem,3vw,2.3rem) 3rem; }
.topbar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1.25rem; }
.header-actions { display: flex; gap: .65rem; }
.view-stack { display: grid; gap: 1rem; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 1rem; box-shadow: var(--shadow); }
.filter-bar { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); align-items: end; gap: .7rem; }
.upload-panel { margin-bottom: 1rem; display: grid; gap: .9rem; border-left: 4px solid var(--orange); }
.upload-form { display: grid; grid-template-columns: 180px minmax(230px,1fr) auto; gap: .7rem; align-items: center; }
.progress-line { height: 5px; overflow: hidden; background: #e9edf3; border-radius: 999px; }
.progress-line span { display: block; width: 38%; height: 100%; background: var(--orange); animation: progress 1.1s infinite ease-in-out; }
@keyframes progress { from { transform: translateX(-100%); } to { transform: translateX(280%); } }
.notice { margin: 0; color: var(--green); font-weight: 700; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1rem; }
.kpi-card { padding: 1rem; min-height: 128px; border-radius: 16px; color: #fff; background: linear-gradient(145deg, #1c3552, #14263d); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi-card:after { content: ""; position: absolute; width: 90px; height: 90px; right: -25px; bottom: -40px; border-radius: 50%; background: rgba(255,255,255,.07); }
.kpi-card.orange { background: linear-gradient(145deg, #ff7040, #dc4b18); }
.kpi-card.light { color: var(--ink); background: #fff; border: 1px solid var(--line); }
.kpi-label { color: inherit; opacity: .75; font-size: .84rem; font-weight: 800; }
.kpi-value { display: block; margin-top: .55rem; font-size: clamp(1.65rem,3vw,2.3rem); line-height: 1; font-weight: 900; }
.kpi-sub { display: block; margin-top: .7rem; font-size: .78rem; opacity: .7; }
.skeleton-grid:empty:before { content: "กำลังโหลดข้อมูล…"; color: var(--muted); padding: 1rem; }
.content-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 1rem; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .9rem; }
.pill { border: 1px solid #d5dde8; background: #f5f7fa; border-radius: 999px; padding: .38rem .65rem; font-size: .78rem; color: #5f6c7d; }
.status-list { display: grid; gap: .62rem; }
.status-row { display: grid; grid-template-columns: 12px minmax(0,1fr) auto; gap: .65rem; align-items: center; padding: .66rem .2rem; border-bottom: 1px solid #edf0f4; }
.status-row:last-child { border-bottom: 0; }
.status-dot { width: 10px; height: 10px; border-radius: 3px; }
.status-row strong { font-size: 1.05rem; }
.bar-list { display: grid; gap: .9rem; }
.bar-item { display: grid; gap: .35rem; }
.bar-label { display: flex; justify-content: space-between; gap: .6rem; font-size: .84rem; }
.bar-track { height: 8px; overflow: hidden; border-radius: 999px; background: #edf1f6; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--orange), #ff946e); }
.table-panel { padding-bottom: .35rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th { padding: .68rem .7rem; text-align: left; color: #6c7889; background: #f7f9fc; font-size: .78rem; text-transform: uppercase; }
td { padding: .78rem .7rem; border-bottom: 1px solid #edf0f4; font-size: .9rem; vertical-align: top; }
tbody tr:hover { background: #fafbfd; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.wide-table { min-width: 1050px; }
.orders-head { align-items: center; }
.search-input { width: min(360px,100%); }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: .7rem; padding: .9rem 0 .6rem; }
.connection-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .85rem; }
.connection-card { border: 1px solid var(--line); border-radius: 14px; padding: .9rem; display: grid; gap: .55rem; }
.connection-top { display: flex; justify-content: space-between; align-items: center; }
.connection-code { font-size: 1.1rem; font-weight: 900; }
.session-badge { padding: .25rem .48rem; border-radius: 999px; font-size: .72rem; font-weight: 800; }
.session-badge.active { color: var(--green); background: #e7f6ee; }
.session-badge.missing, .session-badge.expired, .session-badge.error { color: var(--red); background: #fdecea; }
.connection-meta { color: var(--muted); font-size: .8rem; min-height: 2.4rem; }
.connector-help { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }
.connector-help > div { padding: .6rem; }
.connector-help p { color: var(--muted); font-size: .86rem; margin: .35rem 0 0 2.45rem; }
.step { display: inline-grid; place-items: center; width: 31px; height: 31px; margin-right: .55rem; border-radius: 9px; background: var(--orange-soft); color: var(--orange); font-weight: 900; }
dialog { width: min(430px,calc(100% - 2rem)); border: 0; border-radius: 18px; padding: 1.2rem; box-shadow: 0 25px 70px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(8,18,31,.58); }
dialog form { display: grid; gap: 1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; }
.toast { position: fixed; right: 1rem; bottom: 1rem; max-width: 420px; padding: .85rem 1rem; border-radius: 12px; color: #fff; background: #17283e; box-shadow: var(--shadow); z-index: 20; }
.toast.error { background: #a83226; }

@media (max-width: 1080px) {
  .filter-bar { grid-template-columns: repeat(3,1fr); }
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .connection-grid { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: .75rem 1rem; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand-row { padding: 0; min-width: 170px; }
  .sidebar nav { display: flex; min-width: max-content; margin-left: .5rem; }
  .sidebar-foot { display: none; }
  .nav-item { padding: .68rem .75rem; }
  main { padding: 1rem .75rem 2rem; }
  .topbar { align-items: flex-start; }
  .header-actions { flex-direction: column; }
  .filter-bar, .upload-form { grid-template-columns: 1fr; }
  .content-grid, .connector-help { grid-template-columns: 1fr; }
  .connection-grid { grid-template-columns: 1fr; }
}
@media (max-width: 460px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar { display: grid; }
  .header-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .orders-head { display: grid; }
}
/* 0.3 account reports */
.account-tabs{display:flex;gap:8px;flex-wrap:wrap}.source-banner{padding:16px 20px;background:#fff4eb;border-left:4px solid #ef6228;border-radius:12px;display:grid;gap:6px}.source-banner small{color:#5d6877}.daily-chart{display:flex;gap:12px;align-items:flex-end;overflow-x:auto;padding:16px 0}.day-column{flex:0 0 88px;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:7px}.day-column small{font-size:10px}.day-bar{background:linear-gradient(#ff9b5e,#ef6228);width:36px;border-radius:5px 5px 0 0}.live-metrics{display:grid;grid-template-columns:1fr 1fr;gap:12px}.live-metrics dt{font-size:12px;color:#65748a}.live-metrics dd{margin:4px 0;font-size:24px;font-weight:700}#sourceList{max-height:220px;overflow:auto}#liveProgress{color:#a34b1c}
