/* SS — ระบบคำนวณโครงสร้างเหล็ก
   ธีมสว่าง/มืด ผ่านตัวแปร CSS ชุดเดียว รูป SVG ใช้ตัวแปรเดียวกันจึงอ่านได้ทั้งสองโหมด */
:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel2: #f2f4f8; --ink: #16181d; --ink2: #5b6472;
  --line: #dfe3ea; --brand: #1e3a8a; --brand2: #3b5bdb; --accent: #0891b2;
  --ok: #15803d; --okbg: #f0fdf4; --ng: #b91c1c; --ngbg: #fef2f2; --warn: #92400e; --warnbg: #fffbeb;
  --steel: #bfdbfe; --steel-line: #1e40af; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --radius: 10px;
}
html[data-theme="dark"] {
  --bg: #0e1116; --panel: #161a22; --panel2: #1b212b; --ink: #e6e9ef; --ink2: #9aa4b2;
  --line: #262d3a; --brand: #93b4ff; --brand2: #6f8fff; --accent: #22d3ee;
  --ok: #4ade80; --okbg: #0f2418; --ng: #f87171; --ngbg: #2a1414; --warn: #fbbf24; --warnbg: #2a2210;
  --steel: #1e3a5f; --steel-line: #60a5fa; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- แถบบน ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff;
  font-weight: 800; letter-spacing: .5px;
}
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--ink2); font-size: 12px; }
.topactions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.proj-pick { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink2); }
.proj-pick select { max-width: 190px; }

.btn {
  background: var(--brand); color: #fff; border: 1px solid transparent; border-radius: 8px;
  padding: 7px 14px; cursor: pointer; font-size: 14px; font-weight: 500; transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.icon { padding: 7px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- ผังหน้า ---------- */
.layout { display: grid; grid-template-columns: 268px 1fr; min-height: calc(100vh - 59px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 10px 0 30px; overflow-y: auto; }
.navgroup { padding: 14px 16px 5px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink2); }
.navitem {
  display: block; width: 100%; text-align: right; background: none; border: 0; cursor: pointer;
  padding: 8px 16px; border-left: 3px solid transparent; text-align: left;
}
.navitem:hover { background: var(--panel2); }
.navitem.active { background: var(--panel2); border-left-color: var(--brand2); }
.ni-title { display: block; font-size: 14px; }
.ni-code { display: block; font-size: 11px; color: var(--ink2); }
.calclist { padding: 0 10px; }
.calclist .empty { color: var(--ink2); font-size: 12px; padding: 4px 6px; }
.calcitem {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 6px 8px; border-radius: 7px; font-size: 12.5px; cursor: pointer;
}
.calcitem:hover { background: var(--panel2); }
.calcitem .r { font-variant-numeric: tabular-nums; font-weight: 600; }
.calcitem.ok .r { color: var(--ok); } .calcitem.ng .r { color: var(--ng); }

.main { padding: 20px 24px 60px; max-width: 1180px; }

/* ---------- หน้าแรก ---------- */
.intro h1 { font-size: 21px; margin: 6px 0 8px; }
.intro > p { color: var(--ink2); max-width: 70ch; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-top: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 6px; font-size: 15px; color: var(--brand); }
.card p { margin: 0; font-size: 13.5px; color: var(--ink2); }

/* ---------- ฟอร์ม ---------- */
.form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 18px 20px; box-shadow: var(--shadow); }
.form h2 { margin: 0 0 2px; font-size: 19px; }
.form .code { color: var(--brand); font-size: 12.5px; margin: 0 0 2px; }
.form .desc { color: var(--ink2); font-size: 13.5px; margin: 0 0 14px; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 14px 0 0; padding: 12px 0 0; }
legend { font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink2); padding-right: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; }
.field .inp { display: flex; align-items: stretch; }
.field input[type=number], .field input[type=text], .field select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); min-width: 0;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand2); outline-offset: -1px; }
.field .unit {
  display: grid; place-items: center; padding: 0 9px; border: 1px solid var(--line); border-left: 0;
  border-radius: 0 8px 8px 0; background: var(--panel2); color: var(--ink2); font-size: 12.5px; white-space: nowrap;
}
.field .inp input { border-radius: 8px 0 0 8px; }
.field .help { font-size: 11.5px; color: var(--ink2); }
.field.bool { flex-direction: row; align-items: center; gap: 8px; }
.field.bool input { width: 17px; height: 17px; }
.actions { display: flex; gap: 10px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

/* ---------- ผลลัพธ์ ---------- */
.result { margin-top: 20px; }
.verdict {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius);
  border: 1px solid var(--line); margin-bottom: 16px; background: var(--panel);
}
.verdict.ok { border-left: 5px solid var(--ok); background: var(--okbg); }
.verdict.ng { border-left: 5px solid var(--ng); background: var(--ngbg); }
.verdict .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.verdict.ok .big { color: var(--ok); } .verdict.ng .big { color: var(--ng); }
.verdict .txt strong { display: block; }
.verdict .txt span { color: var(--ink2); font-size: 13px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
         padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel > h3 { margin: 0 0 10px; font-size: 15px; }
.figwrap { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; align-items: flex-start; }
.ss-fig { max-width: 100%; height: auto; }
.fig-section, .fig-column, .fig-bolt, .fig-weld, .fig-baseplate, .fig-filled { width: 330px; }
.fig-interaction { width: 420px; }
.fig-curve { width: 460px; }
.fig-beam { width: 100%; max-width: 760px; }
.fig-truss { width: 100%; max-width: 800px; }

table.trace { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.trace td { border-bottom: 1px solid var(--line); padding: 5px 7px; vertical-align: top; }
table.trace tr.hd td { background: var(--panel2); font-weight: 600; padding-top: 9px; }
table.trace tr.nt td { color: var(--ink2); font-size: 12.5px; }
table.trace tr.wn td { background: var(--warnbg); color: var(--warn); font-size: 12.5px; }
table.trace tr.ck.ok td { background: var(--okbg); }
table.trace tr.ck.ng td { background: var(--ngbg); color: var(--ng); font-weight: 600; }
.sym { font-style: italic; color: var(--brand); font-weight: 600; width: 62px; }
.val { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; width: 130px; }
.sub { font-size: 11.5px; color: var(--ink2); }
.formula, .subs { font-family: ui-monospace, "DejaVu Sans Mono", Consolas, monospace; font-size: 12px; }
.formula { color: var(--ink); } .subs { color: var(--ink2); }
.ref { color: var(--brand2); font-size: 11.5px; font-weight: 400; }

.props { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.prop { background: var(--panel2); border-radius: 8px; padding: 7px 10px; }
.prop b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.prop span { font-size: 11.5px; color: var(--ink2); }

.picker { position: relative; }
.picker .list {
  position: absolute; z-index: 30; top: 100%; left: 0; right: 0; max-height: 280px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.picker .list div { padding: 6px 10px; cursor: pointer; font-size: 13.5px; display: flex; justify-content: space-between; }
.picker .list div:hover, .picker .list div.sel { background: var(--panel2); }
.picker .list .fam { color: var(--ink2); font-size: 11.5px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 60; font-size: 14px;
}
.toast.err { background: var(--ng); color: #fff; }
.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink);
       padding: 20px; max-width: 520px; box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 16px 0 0; }
.setup { max-width: 640px; margin: 80px auto; padding: 24px; background: var(--panel);
         border: 1px solid var(--line); border-radius: var(--radius); }
.setup pre { background: var(--panel2); padding: 12px; border-radius: 8px; overflow-x: auto; }

/* ---------- สีของรูป SVG ---------- */
.steel { fill: var(--steel); stroke: var(--steel-line); stroke-width: 1.5; }
.ln, .axis { stroke: var(--ink2); stroke-width: 1; fill: none; }
.title, .paneltitle { font-size: 11px; fill: var(--ink); }
.title { text-anchor: middle; } .paneltitle { text-anchor: start; font-weight: 600; }
.sub, .tick { font-size: 9px; text-anchor: middle; fill: var(--ink2); }
.dim { stroke: var(--ink2); opacity: .7; } .dimhead { fill: var(--ink2); }
.dimlbl { font-size: 9px; text-anchor: middle; fill: var(--ink2); }
.curve { fill: none; stroke-width: 1.8; }
.shear { stroke: var(--accent); } .moment { stroke: #dc2626; } .defl { stroke: #7c3aed; }
.area { opacity: .18; stroke: none; }
.area.shear { fill: var(--accent); } .area.moment { fill: #dc2626; } .area.defl { fill: #7c3aed; }
.dot.shear { fill: var(--accent); } .dot.moment { fill: #dc2626; } .dot.defl { fill: #7c3aed; }
.member { fill: #94a3b8; stroke: #475569; } .support { fill: #64748b; }
.load { stroke: #dc2626; fill: #dc2626; stroke-width: 1.2; }
.buckled { fill: none; stroke: #dc2626; stroke-dasharray: 4 3; }
.ground { stroke: #64748b; stroke-width: 2.5; }
.truss-mem.ten { stroke: #2563eb; } .truss-mem.comp { stroke: #dc2626; } .truss-mem.zero { stroke: var(--line); }
.joint { fill: var(--ink); } .memlbl { font-size: 8.5px; text-anchor: middle; }
.memlbl.ten { fill: #2563eb; } .memlbl.comp { fill: #dc2626; }
.react, .peak { font-size: 9.5px; text-anchor: middle; fill: var(--ink); }
.plate { fill: var(--panel2); stroke: var(--ink2); } .bolt { fill: var(--panel); stroke: var(--ink); }
.centre { stroke: var(--ink2); stroke-width: .7; }
.colprofile { fill: none; stroke: var(--steel-line); stroke-dasharray: 4 2; }
.weldmetal { fill: #fca5a5; stroke: #b91c1c; } .throat { stroke: var(--ink); stroke-dasharray: 3 2; }
.axislbl { font-size: 12px; fill: var(--brand); text-anchor: middle; font-style: italic; }
.lbl { font-size: 11px; text-anchor: middle; fill: var(--ink); }
.hatchln { stroke: var(--ink2); stroke-width: 1; }

.envelope { fill: var(--brand2); opacity: .12; stroke: none; }
.curve.limit { stroke: var(--brand2); stroke-width: 2; fill: none; }
.point.ok { fill: var(--ok); stroke: var(--panel); stroke-width: 2; }
.point.ng { fill: var(--ng); stroke: var(--panel); stroke-width: 2; }
.concrete { fill: var(--panel2); stroke: var(--ink2); stroke-dasharray: 3 2; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 220px; }
  .main { padding: 16px; }
}
