:root { color-scheme: light;
  --bg: #f3f5f8; --panel: #ffffff; --ink: #1d2733; --muted: #5d6b7a; --line: #d8dee6;
  --brand: #1f4e79; --brand2: #2e75b6; --ok: #1e8449; --bad: #c0392b; --warn: #b9770e; --na: #7f8c8d;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Sarabun', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
h1 { font-size: 18px; margin: 0; } h3 { margin: 0 0 8px; font-size: 15px; color: var(--brand); }
button, select, input, textarea { font: inherit; }
button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--brand2); }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.danger { color: var(--bad); }
input, select, textarea { border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; background: #fff; }
.topbar { display: flex; justify-content: space-between; 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(--brand); color: #fff; flex-wrap: wrap; }
.topbar .sub { opacity: .8; font-size: 12px; }
.brand { display: flex; gap: 10px; align-items: center; }
.logo { background: #fff; color: var(--brand); font-weight: 700; border-radius: 8px; padding: 6px 8px; }
.logos { display: flex; gap: 6px; background: #fff; border-radius: 8px; padding: 4px 8px; align-items: center; }
.logos img { height: 34px; width: auto; }
.logos img + img { height: 26px; }
.rp-head { display: grid; grid-template-columns: 70px 1fr 140px; align-items: center; gap: 8px; border-bottom: 2px solid var(--brand); padding-bottom: 6px; }
.rp-head img { width: 100%; }
.soil-label { font-size: 10px; color: #3b2f22; background: rgba(255,255,255,.7); padding: 0 4px; border-radius: 3px; white-space: nowrap; }
.level-tag { font-size: 11px; color: #fff; background: rgba(192,57,43,.9); padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.inst-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 12px; }
.mini-in { display: inline-flex; flex-direction: column; font-size: 10px; color: var(--muted); margin-right: 4px; }
.mini-in input[type=number] { width: 72px; }
.sec-title { font-size: 16px; color: var(--brand); margin: 18px 0 8px; }
.chart.tall { height: 520px; }
.chart-wrap select { margin-bottom: 4px; }
.report table.small { font-size: 9px; }
.report h4 + .imgs { margin-top: 4px; }
@media (max-width: 1100px) { .inst-grid { grid-template-columns: 1fr; } }
.top-controls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; min-width: 0; max-width: 100%; }
.top-controls select { max-width: 100%; }
#testSelect { max-width: min(420px, 100%); }
.top-controls .mini { display: flex; gap: 4px; align-items: center; font-size: 12px; }
.tabs { display: flex; gap: 2px; padding-block: 0; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 10px 14px; white-space: nowrap; }
.tabs button.active { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }
main { padding-block: 12px 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.tab { display: none; } .tab.active { display: block; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.row.between { justify-content: space-between; }
.hint { color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* training */
.train-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 12px; height: calc(100vh - 150px); min-height: 520px; }
.viewport-wrap { position: relative; background: #dfe8ef; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
#viewport { position: absolute; inset: 0; }
.label-layer { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 1; }
.part-label { background: rgba(255,255,255,.88); border: 1px solid #9fb3c8; border-radius: 4px; padding: 1px 6px; font-size: 11px; pointer-events: auto; cursor: pointer; white-space: nowrap; }
.part-label.active { background: #ff9800; color: #fff; border-color: #e65100; }
.vp-toolbar { position: absolute; top: 8px; left: 8px; display: flex; gap: 10px; background: rgba(255,255,255,.9); padding: 6px 10px; border-radius: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.sim-hud { position: absolute; bottom: 8px; left: 8px; background: rgba(15,30,45,.8); color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; display: none; }
.side { overflow-y: auto; }
.subtabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.subtabs button.active { background: var(--brand); color: #fff; }
.sub { display: none; } .sub.active { display: block; }
.part-list { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.part-list button { font-size: 12px; padding: 3px 8px; }
.part-list button.active { background: #ff9800; color: #fff; border-color: #e65100; }
.dial-row { display: flex; gap: 6px; flex-wrap: wrap; }
.dial-row svg { width: 88px; height: 88px; }
.dial-big svg { width: 260px; height: 260px; display: block; margin: 0 auto; }

/* setup */
.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }
.setup-grid .card.wide { grid-column: 1 / -1; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; align-items: center; }
.form label { color: var(--muted); font-size: 12px; }
.form input, .form select { width: 100%; }
.inline-unit { display: flex; gap: 4px; align-items: center; } .inline-unit input { flex: 1; } .inline-unit span { color: var(--muted); font-size: 12px; min-width: 34px; }

/* tables */
.table-wrap { overflow: auto; max-height: 62vh; }
table.grid { border-collapse: collapse; width: 100%; font-size: 12px; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 3px 6px; text-align: right; white-space: nowrap; }
table.grid th { background: #eef3f8; position: sticky; top: 0; z-index: 1; text-align: center; }
table.grid td.l { text-align: left; white-space: normal; }
table.grid tr.step-start td { border-top: 2px solid #9fb3c8; }
table.grid input { width: 70px; padding: 1px 3px; text-align: right; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; color: #fff; }
.b-pass { background: var(--ok); } .b-fail { background: var(--bad); } .b-warn { background: var(--warn); } .b-info { background: var(--brand2); } .b-na { background: var(--na); }

/* record */
.rec-top { display: grid; grid-template-columns: 320px minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.step-card .big { font-size: 26px; font-weight: 700; color: var(--brand); }
.step-card .kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin-top: 6px; }
.step-card .kv b { text-align: right; }
.state { margin-top: 8px; padding: 6px 8px; border-radius: 6px; font-weight: 600; }
.state.ok { background: #e8f6ee; color: var(--ok); } .state.bad { background: #fdecea; color: var(--bad); } .state.wait { background: #fff6e0; color: var(--warn); }
.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.entry-grid label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.entry-grid .wide { grid-column: span 2; }
.alert { padding: 5px 8px; border-radius: 5px; background: #fff3cd; color: #7a5300; margin-top: 4px; font-size: 12px; }
.chart { background: #fff; border: 1px solid var(--line); border-radius: 8px; height: 380px; }
.chart.small { height: 260px; border: 0; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 12px; margin-bottom: 12px; }
.filebtn { border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; background: #fff; }
.verdict { padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; font-size: 16px; font-weight: 600; }
.verdict.pass { background: #e8f6ee; color: var(--ok); border: 1px solid #b7e1c7; }
.verdict.fail { background: #fdecea; color: var(--bad); border: 1px solid #f5c2bd; }
.verdict.engineer { background: #eef3f8; color: var(--brand); border: 1px solid #c8d6e5; }
.verdict small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* report (A4) */
.report { background: #fff; max-width: 210mm; margin: 0 auto; padding: 14mm 14mm; box-shadow: 0 2px 10px rgba(0,0,0,.1); font-size: 12px; }
.report h2 { text-align: center; font-size: 17px; margin: 0; color: var(--brand); }
.report h4 { font-size: 13px; margin: 14px 0 6px; color: var(--brand); border-bottom: 1px solid var(--line); padding-bottom: 2px; }
.report .center { text-align: center; }
.report table.kv { width: 100%; border-collapse: collapse; }
.report table.kv td { padding: 2px 6px; border: 1px solid var(--line); }
.report table.kv td:nth-child(odd) { background: #f5f8fb; width: 22%; color: var(--muted); }
.report img { width: 100%; }
.report .imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.report .sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 30px; text-align: center; }
.report .sign div { border-top: 1px solid #333; padding-top: 4px; margin-top: 40px; }
.report .comment { min-height: 60px; border: 1px solid var(--line); padding: 6px; }
.report .foot { color: var(--muted); font-size: 10px; margin-top: 12px; text-align: center; }
.page-break { break-before: page; }

@media (max-width: 1100px) {
  .train-layout { grid-template-columns: 1fr; height: auto; }
  .viewport-wrap { height: 60vh; }
  .rec-top { grid-template-columns: 1fr; }
}
@media (max-width: 600px) { .rp-head { grid-template-columns: 40px 1fr 72px; } .report { padding: 8px; } main { padding-block: 10px; } .form { grid-template-columns: 1fr; } .chart-grid { grid-template-columns: 1fr; } }
@media print {
  body { background: #fff; }
  .no-print, .tabs, .topbar { display: none !important; }
  main { padding: 0; } .tab { display: none !important; } #tab-report { display: block !important; }
  .report { box-shadow: none; padding: 0; max-width: none; }
  @page { size: A4; margin: 12mm; }
  table.grid th { position: static; }
  .table-wrap { max-height: none; overflow: visible; }
}

.tt-tag { font-size: 11px; color: #fff; background: rgba(39,174,96,.92); padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.soil-label { padding-left: 4px; }

.new-sel { font-weight: 600; }
.sim-chart-box { position: relative; width: 100%; min-width: 0; }
.sim-chart-box .chart.small { width: 100%; height: 300px; border: 1px solid var(--line); }
.sim-chart-box .expand-btn { position: absolute; z-index: 5; right: 4px; top: -30px; padding: 2px 8px; }
.sim-chart-box.expanded { position: fixed; inset: 5vh 5vw; z-index: 1000; background: #fff; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.35); padding: 36px 12px 12px; }
.sim-chart-box.expanded .chart.small { height: 100%; border: 0; }
.sim-chart-box.expanded .expand-btn { top: 6px; right: 10px; }
.side { min-width: 0; }
.cycle-hud { z-index: 3; position: absolute; top: 56px; left: 8px; max-width: min(560px, calc(100% - 16px)); background: rgba(255,255,255,.93); border-radius: 8px; padding: 6px 8px; font-size: 11px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.cycle-hud .ch-title { font-weight: 600; color: var(--brand); margin-bottom: 3px; }
.cycle-hud .ch-row { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; margin: 2px 0; }
.cycle-hud .ch-c { color: #fff; border-radius: 50%; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; margin-right: 2px; }
.cycle-hud .ch-s { padding: 1px 4px; font-size: 10px; line-height: 1.2; border-radius: 4px; background: #f3f5f8; display: inline-flex; flex-direction: column; align-items: center; }
.cycle-hud .ch-s small { color: var(--muted); font-size: 9px; }
.cycle-hud .ch-s.unload { background: #eef6f0; }
.cycle-hud .ch-s.done { background: #d6e4f0; }
.cycle-hud .ch-s.now { background: #c0392b; color: #fff; border-color: #c0392b; }
.cycle-hud .ch-s.now small { color: #fde; }
.inst-card svg { width: 100%; max-height: 190px; }
.inst-card .gauge-mini svg { width: 120px; height: 120px; display: block; margin: 0 auto; }
.inst-card .dial-row svg { width: 90px; height: 90px; }
.inst-card .dial-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 6px; }
.inst-card .dial-grid svg { width: 100%; max-width: 130px; height: auto; }
.inst-val { font-size: 12px; background: #f6f9fc; border-radius: 6px; padding: 6px 8px; margin-top: 6px; }
.cycle-hud .ch-title { cursor: pointer; user-select: none; }
.cycle-hud.collapsed .ch-row { display: none; }
.vp-toolbar, .sim-hud { z-index: 3; }

.level-tag { line-height: 1.25; font-size: 10.5px; padding: 2px 6px; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.level-tag .tt-in { color: #c9f7d8; }
.xr-opt.off { opacity: .45; pointer-events: none; }
.viewport-wrap { background: #cfe0ee; }

.primary-file { background: var(--brand); color: #fff; border-color: var(--brand); }
tr.flag-row td { background: #fff3cd; }

.pdf-top { background: #fff3e0; border-color: #e67e22; color: #a04000; font-weight: 600; }

.hosted-only { display: none; }
body.hosted .hosted-only { display: block; }
body.hosted .local-only { display: none !important; }
.hosted-banner { background: #fff4d6; color: #7a5300; border-bottom: 1px solid #f0d58a; padding-block: 6px; padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); font-size: 12px; }
.ask-overlay { position: fixed; inset: 0; background: rgba(20,30,40,.45); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.ask-box { background: #fff; border-radius: 10px; padding: 16px 18px; max-width: 360px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #1d2733; color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 2100; max-width: calc(100% - 32px); font-size: 13px; }
