:root{
  --bg:#EFF4F3; --surface:#FFFFFF; --surface-2:#F6F9F8; --ink:#1E3437; --muted:#5F7476; --line:#DCE5E3;
  --accent:#2F7A73;
  --p-start:#9DB4CF; --p-tor:#6FAE9C; --p-bid:#E3B062; --p-con:#9C8CC9;
  --p-start-soft:#E6EDF5; --p-tor-soft:#E0F0EB; --p-bid-soft:#FBF0DD; --p-con-soft:#ECE8F6;
  --today:#D2696A;
  color-scheme:light;
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#131B1D; --surface:#1B2628; --surface-2:#202D30; --ink:#E2ECEA; --muted:#97ADAB; --line:#2C3B3E;
    --accent:#7CC6BC;
    --p-start:#7F9BBD; --p-tor:#5E9E8C; --p-bid:#C99A4E; --p-con:#8778B5;
    --p-start-soft:#24303B; --p-tor-soft:#203330; --p-bid-soft:#352D20; --p-con-soft:#2A2737;
    --today:#E58B8B;
    color-scheme:dark;
  }
}
*{box-sizing:border-box}
html,body{margin:0}
body{
  font-family:"IBM Plex Sans Thai Looped","Sarabun","Noto Sans Thai","Leelawadee UI",Tahoma,sans-serif;
  background:var(--bg); color:var(--ink); font-size:15px; line-height:1.65;
  -webkit-font-smoothing:antialiased;
  padding-top:env(safe-area-inset-top,0px); padding-bottom:env(safe-area-inset-bottom,0px);
}
.wrap{max-width:1180px; margin:0 auto; padding:40px 24px 64px}
h1,h2,h3,.fact b,.phase .range,.matrix td,.cm-row .val b,.sec-no,.nav a,.org{font-family:"Anuphan","IBM Plex Sans Thai Looped","Sarabun",sans-serif}
h1,h2,h3{line-height:1.3; margin:0}
h1{font-size:clamp(28px,3.8vw,42px); font-weight:700; letter-spacing:-.005em; line-height:1.25}
h2{font-size:23px; font-weight:600}
h3{font-size:17px; font-weight:600}
p{margin:0}
.muted{color:var(--muted)}
.num{font-variant-numeric:tabular-nums}

/* Header */
header{display:grid; gap:16px; margin-bottom:20px; padding-top:8px}
.org{color:var(--accent); font-weight:600; font-size:15px}
.lead{max-width:70ch; color:var(--muted)}
.facts{display:flex; flex-wrap:wrap; gap:10px 34px; padding-top:18px; border-top:1px solid var(--line)}
.fact b{display:block; font-size:30px; font-weight:600; line-height:1.2}
.fact span{font-size:13px; color:var(--muted)}

section{margin-top:28px; padding:30px 30px 32px; background:var(--surface-2); border:1px solid var(--line); border-radius:20px; scroll-margin-top:76px}
.sec-head{display:grid; grid-template-columns:auto 1fr; gap:4px 16px; align-items:center; margin-bottom:22px; padding-bottom:18px; border-bottom:1px solid var(--line)}
.sec-no{grid-row:span 2; width:46px; height:46px; border-radius:14px; display:grid; place-items:center; font-size:20px; font-weight:600; background:var(--accent); color:#fff}
.sec-head p{font-size:14px; color:var(--muted); max-width:72ch}
.sub-head{display:flex; flex-wrap:wrap; align-items:baseline; justify-content:space-between; gap:4px 16px; margin-bottom:12px}
.sub-head p{font-size:13px; color:var(--muted)}
.nav{position:sticky; top:0; z-index:20; margin:0 -24px 8px; padding:10px 24px; padding-top:calc(10px + env(safe-area-inset-top,0px)); background:color-mix(in srgb, var(--bg) 96%, transparent); backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px); border-bottom:1px solid var(--line); display:flex; gap:6px; overflow-x:auto; scrollbar-width:none}
.nav a{flex:none; text-decoration:none; color:var(--muted); font-size:14px; font-weight:500; padding:7px 14px; border-radius:999px; white-space:nowrap}
.nav a span{display:inline-grid; place-items:center; width:20px; height:20px; border-radius:50%; background:var(--line); color:var(--ink); font-size:12px; margin-right:7px}
.nav a:hover,.nav a.on{background:var(--surface); color:var(--ink); box-shadow:0 0 0 1px var(--line)}
.nav a.on span{background:var(--accent); color:#fff}
.panel{background:var(--surface); border:1px solid var(--line); border-radius:14px}

/* Phase legend + overview */
.phases{display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:0}
.phase{padding:18px 20px; border-right:1px solid var(--line); position:relative}
.phase:last-child{border-right:0}
.phase .bar{height:6px; border-radius:3px; margin-bottom:14px}
.phase .step{font-size:12px; color:var(--muted)}
.phase h3{margin:2px 0 6px}
.phase .range{font-size:20px; font-weight:600; line-height:1.3}
.phase .detail{font-size:13px; color:var(--muted); margin-top:6px}

/* Matrix */
.matrix{overflow-x:auto}
.matrix table{border-collapse:separate; border-spacing:6px; width:100%; min-width:640px; table-layout:fixed}
.matrix col.rc{width:180px}
.matrix th{font-weight:500; font-size:13px; color:var(--muted); text-align:center; padding:4px}
.matrix th.rowh{text-align:left; white-space:nowrap; color:var(--ink); padding-right:10px}
.matrix td{height:46px; border-radius:9px; text-align:center; font-weight:600; font-size:15px; position:relative}
.matrix td.empty{background:var(--surface-2); color:transparent}
.matrix th.now{color:var(--today)}
.dot{display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:8px; vertical-align:middle}

/* Contract months */
.two{display:grid; grid-template-columns:1.25fr 1fr; gap:18px}
.cm{padding:20px 22px}
.cm-row{display:grid; grid-template-columns:76px 1fr 110px; align-items:center; gap:12px; padding:9px 0; border-bottom:1px dashed var(--line)}
.cm-row:last-child{border-bottom:0}
.cm-bar{height:22px; background:var(--p-con-soft); border-radius:6px; overflow:hidden}
.cm-bar i{display:block; height:100%; background:var(--p-con); border-radius:6px; min-width:4px}
.cm-row .lbl{font-weight:500}
.cm-row .val{text-align:right; font-size:13px}
.cm-row .val b{font-size:15px}
.owners{padding:8px 22px 14px}
.owners table{width:100%; border-collapse:collapse; font-size:14px}
.owners td,.owners th{padding:9px 4px; border-bottom:1px solid var(--line); text-align:left}
.owners th{font-weight:500; color:var(--muted); font-size:13px}
.owners tr:last-child td{border-bottom:0}
.owners td.r,.owners th.r{text-align:right}
.owners tbody tr{cursor:pointer}
.owners tbody tr:hover td{background:var(--surface-2)}

/* Controls */
.controls{display:flex; flex-wrap:wrap; gap:10px; align-items:center; margin-bottom:12px}
.seg{display:inline-flex; background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:3px}
.seg button{border:0; background:transparent; color:var(--muted); font:inherit; font-size:14px; padding:6px 12px; border-radius:7px; cursor:pointer}
.seg button[aria-pressed="true"]{background:var(--accent); color:#fff}
@media (prefers-color-scheme: dark){ .seg button[aria-pressed="true"],.sec-no,.nav a.on span{color:#0F1A1A} }
select,input[type=search]{font:inherit; font-size:14px; color:var(--ink); background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:8px 12px}
input[type=search]{flex:1 1 220px; min-width:180px}
:focus-visible{outline:2px solid var(--accent); outline-offset:2px}
.count{font-size:13px; color:var(--muted); margin-left:auto}

/* Gantt */
.gantt{overflow-x:auto}
.g-inner{min-width:980px}
.g-head,.g-row{display:grid; grid-template-columns:40px minmax(300px,2.2fr) 96px 104px 88px 88px repeat(var(--ncols,6),minmax(50px,.8fr)); align-items:center}
.g-head{position:sticky; top:0; background:var(--surface); z-index:2; border-bottom:1px solid var(--line); font-size:12.5px; color:var(--muted); font-weight:500}
.g-head > div{padding:12px 6px}
.g-head .mh{text-align:center}
.g-head .mh.now{color:var(--today); font-weight:600}
.g-row{border-bottom:1px solid var(--line); cursor:pointer}
.g-row:hover{background:var(--surface-2)}
.g-row > div{padding:10px 6px}
.g-row .no{color:var(--muted); font-size:13px; text-align:center}
.g-row .nm{font-size:14px; line-height:1.45}
.g-row .nm .t{display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden}
.g-row .nm small{display:block; color:var(--muted); font-size:12px; margin-top:2px}
.tag{display:inline-block; font-size:11.5px; padding:0 7px; border-radius:5px; margin-right:6px; vertical-align:1px}
.tag.eq{background:var(--p-start-soft); color:var(--ink)}
.tag.cn{background:var(--p-bid-soft); color:var(--ink)}
.g-row .bud{text-align:right; font-size:14px}
.g-row .ms{font-size:13px; text-align:center}
.ms .pill{display:inline-block; padding:2px 8px; border-radius:6px}
.pill.tor{background:var(--p-tor-soft)} .pill.bid{background:var(--p-bid-soft)} .pill.con{background:var(--p-con-soft)}
.cell{height:30px; display:flex; flex-direction:column; justify-content:center; gap:2px; position:relative; border-left:1px solid var(--line); padding:0 3px !important}
.cell i{display:block; height:6px; border-radius:3px}
.cell.nowcol::after{content:""; position:absolute; top:-12px; bottom:-12px; left:var(--now-pos,50%); width:2px; background:var(--today); opacity:.55}
.lane-start{background:var(--p-start)} .lane-tor{background:var(--p-tor)} .lane-bid{background:var(--p-bid)} .lane-con{background:var(--p-con)}
.cell i.off{background:transparent}

.detail-row{display:none; background:var(--surface-2); border-bottom:1px solid var(--line)}
.detail-row.open{display:block}
.steps{padding:14px 18px 18px 52px}
.steps table{width:100%; border-collapse:collapse; font-size:13.5px}
.steps td,.steps th{padding:7px 8px; border-bottom:1px solid var(--line); text-align:left; vertical-align:top}
.steps th{white-space:nowrap; font-weight:500; color:var(--muted); font-size:12.5px}
.steps td.d{text-align:right; white-space:nowrap}
.steps td.m{white-space:nowrap}
.steps tr:last-child td{border-bottom:0}
.chev{display:inline-block; transition:transform .2s; color:var(--muted)}
.g-row.open .chev{transform:rotate(90deg)}

.legend{display:flex; flex-wrap:wrap; gap:6px 18px; font-size:13px; color:var(--muted); margin:2px 0 12px}
.legend .today-key{display:inline-block; width:2px; height:13px; background:var(--today); margin-right:8px; vertical-align:-2px}

.notes{padding:18px 22px; font-size:14px}
.notes ul{margin:8px 0 0; padding-left:20px}
.notes li{margin:4px 0}
footer{margin-top:36px; font-size:13px; color:var(--muted)}

@media (max-width:860px){
  .phases{grid-template-columns:repeat(2,minmax(0,1fr))}
  .phase:nth-child(2){border-right:0}
  .phase:nth-child(-n+2){border-bottom:1px solid var(--line)}
  .two{grid-template-columns:1fr}
}
@media (max-width:520px){
  .wrap{padding:28px 16px 48px}
  section{padding:22px 16px 24px}
  .nav{margin:0 -16px 8px; padding-left:16px; padding-right:16px}
  .sec-no{width:38px; height:38px; font-size:17px; border-radius:11px}
  .phases{grid-template-columns:1fr}
  .phase{border-right:0; border-bottom:1px solid var(--line)}
  .phase:last-child{border-bottom:0}
}
@media (prefers-reduced-motion: reduce){ *{transition:none !important} }
@media print{
  .nav{display:none}
  section{break-inside:avoid-page; background:#fff}
  body{background:#fff}
  .controls{display:none}
  .detail-row.open{display:block}
}

/* Loading / error state */
.status{margin:28px 0; padding:36px 28px; background:var(--surface); border:1px dashed var(--line); border-radius:20px; text-align:center; display:grid; justify-items:center; gap:14px}
.status[hidden]{display:none}
.status.error{border-style:solid; border-color:color-mix(in srgb, var(--today) 45%, var(--line))}
.status.error .spinner{display:none}
.status p{max-width:62ch; color:var(--muted)}
.spinner{width:30px; height:30px; border-radius:50%; border:3px solid var(--line); border-top-color:var(--accent); animation:spin 1s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion: reduce){ .spinner{animation-duration:3s} }
.btn{display:inline-block; cursor:pointer; font:inherit; font-size:14px; font-weight:500; padding:9px 18px; border-radius:10px; background:var(--accent); color:#fff; border:1px solid var(--accent)}
.btn.ghost{background:transparent; color:var(--accent)}
.btn:focus-within{outline:2px solid var(--accent); outline-offset:2px}
@media (prefers-color-scheme: dark){ .btn:not(.ghost){color:#0F1A1A} }
footer{display:flex; flex-wrap:wrap; gap:12px 24px; align-items:center; justify-content:space-between}
footer p{max-width:80ch}
.cell.out{height:auto; display:block; font-size:12.5px; color:var(--muted); text-align:center; padding:6px 8px !important; background:repeating-linear-gradient(135deg, transparent 0 8px, var(--surface-2) 8px 16px); border-radius:6px}
.matrix td.xcell{background:var(--surface-2); color:var(--muted); border:1px dashed var(--line)}
.matrix td.tcell{background:transparent; border-left:2px solid var(--line); border-radius:0}
.matrix th.xcol,.matrix th.tot{font-size:12.5px}
.cm-row.cm-total{border-bottom:0; border-top:2px solid var(--line); margin-top:4px}
.dot.dot-soft{background:transparent !important; box-shadow:inset 0 0 0 2px var(--p-bid)}
