/* โทนเดียวกับ R&D Portal (cplservice.com/rd) */
:root {
  --brand: #E76500; --brand-dark: #C45400; --brand-light: #FAE3CC; --brand-pale: #FEF5EC;
  --bg: #F5F6F7; --surface: #fff; --surface-2: #F8F9FA; --border: #D9D9D9;
  --text-base: #32363A; --text-muted: #6A7177; --shadow: 0 1px 4px rgba(0,0,0,.08); --radius: 4px;
  --input: #5B6670; --ok: #1E7F4F;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, -apple-system, 'Noto Sans Thai', sans-serif; background: var(--bg); color: var(--text-base); font-size: 14px; line-height: 1.5; min-height: 100vh; }
a { color: inherit; }
button, input, select { font: inherit; }

.shell { background: var(--brand); color: #fff; min-height: 48px; display: flex; align-items: center; flex-wrap: wrap; padding: 6px 20px; gap: 12px; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.shell a { text-decoration: none; }
.shell-logo { font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.shell-sep { width: 1px; height: 20px; background: rgba(255,255,255,.35); }
.shell-app { font-size: 13px; opacity: .9; }
.shell-spacer { flex: 1; }
.shell-link { color: rgba(255,255,255,.85); font-size: 12px; padding: 4px 10px; border-radius: 3px; }
.shell-link:hover { background: rgba(255,255,255,.15); color: #fff; }
.shell-ce { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.shell-ce input { width: 64px; padding: 2px 6px; border: 0; border-radius: 3px; text-align: right; color: var(--text-base); }

.page { max-width: 1200px; margin: 0 auto; padding: 28px 16px; }
.loading { color: var(--text-muted); }
.hero { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 24px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 20px; }
.hero-icon { font-size: 40px; flex-shrink: 0; }
.hero h1 { font-size: 22px; font-weight: 700; color: var(--brand); margin-bottom: 4px; }
.hero p { color: var(--text-muted); font-size: 13px; line-height: 1.6; max-width: 720px; }
.search { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; background: var(--surface); }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); letter-spacing: .8px; margin: 22px 0 10px; }
.sub-title { font-size: 13px; font-weight: 700; color: var(--brand-dark); margin: 14px 0 8px; }
.nav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.nav-card { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); transition: all .2s; }
.nav-card:hover { box-shadow: 0 4px 16px rgba(231,101,0,.2); border-color: var(--brand); transform: translateY(-2px); }
.nav-card { flex-direction: row; align-items: flex-start; gap: 12px; }
.nav-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.nav-card b { font-size: 13.5px; color: var(--brand); line-height: 1.4; }
.nav-text > span { font-size: 12px; color: var(--text-muted); }
.nav-card mark, .nav-text mark { background: var(--brand-light); color: var(--brand-dark); border-radius: 2px; padding: 0 1px; }

/* ไอคอน */
.ic { flex: none; width: 38px; height: 38px; border-radius: 8px; background: var(--brand-pale); color: var(--brand); display: grid; place-items: center; transition: background .2s, color .2s; }
.ic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-card:hover .ic { background: var(--brand); color: #fff; }
.ic.big { width: 56px; height: 56px; border-radius: 12px; }
.ic.big svg { width: 32px; height: 32px; }
.ic.sm { width: 22px; height: 22px; border-radius: 5px; margin-right: 6px; vertical-align: -6px; display: inline-grid; }
.ic.sm svg { width: 15px; height: 15px; stroke-width: 2; }
.section-title span { font-weight: 400; color: var(--text-muted); }
.searchbar { margin-bottom: 8px; }
.searchbar .search { margin-bottom: 4px; }
.searchbar small { display: block; font-size: 12px; color: var(--text-muted); min-height: 18px; }
.searchbar small.bad { color: #B3261E; }
.empty { color: var(--text-muted); padding: 24px 0; }
.nav-card.solution { border-top-color: var(--brand-dark); background: var(--brand-pale); }
.nav-card.solution .ic { background: #fff; }
.nav-text em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--brand-dark); letter-spacing: .4px; }
.solution-bar { display: flex; gap: 12px; align-items: center; background: var(--brand-pale); border: 1px solid var(--brand-light); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; text-decoration: none; font-size: 13px; color: var(--text-base); }
.solution-bar b { color: var(--brand-dark); }
.solution-bar:hover { border-color: var(--brand); }
/* โฆษณา Universal Gateway */
.ugw-ad { display: flex; gap: 16px; align-items: center; background: linear-gradient(100deg, #FFF3E6 0%, #fff 70%); border: 1px solid var(--brand-light); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.ugw-ad > div { flex: 1; min-width: 0; }
.ugw-ad small { display: block; font-size: 11px; font-weight: 700; letter-spacing: .6px; color: var(--brand-dark); text-transform: uppercase; }
.ugw-ad b { display: block; font-size: 15px; color: var(--text-base); margin: 2px 0 4px; }
.ugw-ad p { font-size: 12.5px; color: var(--text-muted); }
.ugw-ad ul { list-style: none; font-size: 12.5px; display: grid; gap: 3px; }
.ugw-ad li span { display: inline-block; min-width: 64px; font-weight: 700; color: var(--brand-dark); }
.ugw-ad .ic.big { background: var(--brand); color: #fff; }
.ugw-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ugw-ad .btn { white-space: nowrap; text-decoration: none; }
.ugw-chip { font-style: normal; font-size: 10px; font-weight: 700; color: #fff; background: var(--brand); border-radius: 3px; padding: 0 5px; margin-left: 6px; letter-spacing: .4px; vertical-align: 1px; }
@media (max-width: 700px) { .ugw-ad { flex-direction: column; align-items: flex-start; } .ugw-ad .ic.big { display: none; } }
@media print { .solution-bar, .ugw-ad { display: none; } }

/* หน้ามาตรการ */
.crumb { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.crumb a { color: var(--brand); text-decoration: none; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: -8px 0 16px; }
.btn { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.note { background: #FFF8E1; border: 1px solid #F3D27A; border-radius: var(--radius); padding: 8px 12px; font-size: 13px; margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.kpi small { display: block; color: var(--text-muted); font-size: 12px; }
.kpi b { font-size: 22px; color: var(--brand-dark); font-variant-numeric: tabular-nums; }
.kpi i { font-style: normal; color: var(--text-muted); font-size: 12px; margin-left: 4px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.panel > h2 { font-size: 14px; font-weight: 700; padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.panel > h2 small { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.panel-body { padding: 14px 16px; }
.cols { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 18px; align-items: start; }
.cols > * { min-width: 0; }

/* diagram */
.diagram { overflow: auto; max-height: 75vh; padding: 8px; background: var(--surface-2); }
.diagram svg { display: block; }
.diagram .node rect { fill: #fff; stroke: var(--border); stroke-width: 1.2; }
.diagram .node.input rect { fill: #EEF1F4; stroke: #B9C2CA; }
.diagram .node.step rect { stroke: var(--brand); }
.diagram .node.result rect { fill: var(--brand); stroke: var(--brand-dark); }
.diagram .node.result text { fill: #fff !important; }
.diagram .node.side rect { fill: #fff; stroke-dasharray: 4 3; }
.diagram .node text { font-size: 11px; fill: var(--text-muted); }
.diagram .node .sym { font-size: 12.5px; font-weight: 700; fill: var(--text-base); }
.diagram .node .val { font-size: 12px; font-weight: 600; fill: var(--brand-dark); font-variant-numeric: tabular-nums; }
.diagram .node { cursor: pointer; }
.diagram path.edge { fill: none; stroke: #C3CAD1; stroke-width: 1.2; }
.diagram.hl .node:not(.on) { opacity: .25; }
.diagram.hl path.edge:not(.on) { opacity: .12; }
.diagram.hl path.edge.on { stroke: var(--brand); stroke-width: 2; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); padding: 8px 16px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; border: 1px solid #B9C2CA; background: #EEF1F4; vertical-align: -2px; margin-right: 4px; }
.legend i.s { background: #fff; border-color: var(--brand); }
.legend i.r { background: var(--brand); border-color: var(--brand-dark); }

/* inputs */
.inputs { width: 100%; border-collapse: collapse; }
.inputs td { padding: 5px 4px; border-bottom: 1px solid #EEE; vertical-align: middle; }
.inputs td:first-child { font-size: 12.5px; }
.inputs .sym { font-weight: 700; font-size: 12px; color: var(--input); white-space: nowrap; }
.inputs .unit { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.inputs input { width: 110px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 3px; text-align: right; font-variant-numeric: tabular-nums; }
.inputs input:focus { outline: 2px solid var(--brand-light); border-color: var(--brand); }
.inputs input.changed { background: var(--brand-pale); border-color: var(--brand); }
.inputs input.bound { background: #EAF6EF; border-color: #9FD3B5; }
.inputs .group td { font-weight: 700; color: var(--brand-dark); padding-top: 12px; border-bottom-color: var(--brand-light); }

/* steps */
.steps { list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 30px 1fr auto; gap: 4px 10px; padding: 9px 0; border-bottom: 1px solid #EEE; }
.steps li::before { content: counter(s); grid-row: span 3; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-light); color: var(--brand-dark); font-weight: 700; font-size: 12px; display: grid; place-items: center; }
.steps li.result::before { background: var(--brand); color: #fff; }
.steps li.section { counter-increment: none; display: block; font-weight: 700; color: var(--brand-dark); border-bottom: 2px solid var(--brand-light); padding-top: 14px; }
.steps li.section::before { content: none; }
.steps .desc { font-size: 13px; }
.steps .out { text-align: right; white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }
.steps .out small { font-weight: 400; color: var(--text-muted); margin-left: 4px; }
.steps code { grid-column: 2 / 4; font: 12.5px Consolas, 'Courier New', monospace; color: var(--text-base); background: var(--surface-2); padding: 2px 6px; border-radius: 3px; overflow-wrap: anywhere; }
.steps code.sub { color: var(--text-muted); background: none; padding: 0 6px; }
.steps li.flash .out { animation: flash .6s; }
@keyframes flash { from { color: var(--brand); } }

/* ตารางอ้างอิง / ตารางกว้าง */
.grid-wrap { overflow: auto; max-height: 60vh; }
table.grid { border-collapse: collapse; font-size: 12px; }
table.grid td, table.grid th { border: 1px solid #E3E3E3; padding: 3px 6px; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
table.grid th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; position: sticky; top: 0; }
table.grid td.t { text-align: left; color: var(--text-muted); }
table.grid td.f { color: var(--brand-dark); font-weight: 600; }
details > summary { cursor: pointer; padding: 10px 16px; font-weight: 700; font-size: 14px; }
.colpick { display: flex; gap: 6px; flex-wrap: wrap; }
.colpick button.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.footer { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); text-align: center; }

@media (max-width: 860px) { .cols { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 600px) {
  .nav-grid { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: flex-start; gap: 8px; }
  .hero-icon { display: none; }
  .shell { padding: 6px 12px; }
  .shell-link { display: none; }
  .inputs input { width: 90px; }
  .steps li { grid-template-columns: 26px 1fr; }
  .steps .out { grid-column: 2; text-align: left; }
}
@media print {
  body { background: #fff; }
  .shell, .toolbar, .search, .footer, .colpick { display: none !important; }
  .page { padding: 0; max-width: none; }
  .panel, .kpi, .hero { box-shadow: none; break-inside: avoid; }
  .cols { grid-template-columns: 1fr 1fr; }
  .diagram { max-height: none; overflow: visible; }
  .diagram svg { max-width: 100%; height: auto; }
  .inputs input { border: 0; background: none !important; }
  details { display: block; } details > *:not(summary) { display: block; }
}
