/* ════════════════════════════════════════════════════════════════════════
   RRGtoPHP — institutional "paper" theme (default) + variants
   palette อ้างอิงจาก Structured Note Screener: cream + navy + gold
   ════════════════════════════════════════════════════════════════════════ */

/* ── Themes (สลับ bg/surface/ink/accent; quadrant คงความหมายไว้) ───────── */
:root,
body[data-theme="paper"]{
  --bg:#efeee8; --surface:#faf9f5; --surface-2:#f5f4ef; --surface-info:#f6f8fb;
  --border:#dcd9cf; --border-2:#e6e3da; --border-info:#dde6f0;
  --ink:#1f2935; --navy:#13314f; --gold:#b88a3e; --muted:#5a6675; --muted-2:#9aa3ad;
  --accent:#13314f; --shadow:0 10px 26px -24px rgba(20,30,45,.55);
}
body[data-theme="pearl"]{
  --bg:#f4f5f7; --surface:#ffffff; --surface-2:#eef1f5; --surface-info:#eef4fb;
  --border:#dde1e7; --border-2:#e6e9ee; --border-info:#d6e3f2;
  --ink:#1d2733; --navy:#1b3a5b; --gold:#a87d2f; --muted:#5b6573; --muted-2:#9aa3ad;
  --accent:#1b3a5b; --shadow:0 10px 26px -24px rgba(20,30,45,.35);
}
body[data-theme="sand"]{
  --bg:#f3ead0; --surface:#fbf6e6; --surface-2:#f0e6c9; --surface-info:#f6efda;
  --border:#ddcfa6; --border-2:#e6dcbb; --border-info:#e0d4ab;
  --ink:#3a3220; --navy:#5a4a1f; --gold:#a06d1c; --muted:#6e6242; --muted-2:#9a8c62;
  --accent:#5a4a1f; --shadow:0 10px 26px -24px rgba(60,45,20,.4);
}
body[data-theme="graphite"]{
  --bg:#1b2027; --surface:#232a33; --surface-2:#2a323c; --surface-info:#243140;
  --border:#363f4a; --border-2:#2f3741; --border-info:#324456;
  --ink:#e7ebf0; --navy:#7fb0e6; --gold:#e0b964; --muted:#9aa6b4; --muted-2:#6b7686;
  --accent:#7fb0e6; --shadow:0 14px 30px -22px rgba(0,0,0,.7);
}
body[data-theme="midnight"]{
  --bg:#0d1b2a; --surface:#13283d; --surface-2:#16304a; --surface-info:#15314d;
  --border:#234866; --border-2:#1c3a55; --border-info:#2a577c;
  --ink:#e3ecf5; --navy:#8fc0f0; --gold:#e8c071; --muted:#8ea4ba; --muted-2:#5f7790;
  --accent:#8fc0f0; --shadow:0 14px 30px -22px rgba(0,0,0,.75);
}

/* semantic quadrant colors — readable บนทั้ง light & dark (medium saturation) */
:root{
  --q-leading:#1f9d5f; --q-weakening:#cf9b2e; --q-lagging:#d33f33; --q-improving:#3a7fc0;
  --chart-max:760px;   /* ← ปรับขนาดกราฟตรงนี้ที่เดียว (เล็กลง=ค่าน้อย / ใหญ่ขึ้น=ค่ามาก) */
}

*{ box-sizing:border-box; }
body{
  margin:0; min-height:100vh; color:var(--ink);
  font-family:'IBM Plex Sans Thai','Segoe UI',Tahoma,sans-serif;
  -webkit-font-smoothing:antialiased; background:var(--bg);
}
.mono{ font-family:'IBM Plex Mono',ui-monospace,Consolas,monospace; }

/* ── Topbar ───────────────────────────────────────────────────────────── */
.topbar{ display:flex; align-items:center; justify-content:space-between;
  max-width:1080px; margin:0 auto; padding:18px 22px 10px; flex-wrap:wrap; gap:12px; }
.brand{ display:flex; align-items:center; gap:13px; }
.logo{ font-size:30px; color:var(--gold); }
.brand h1{ font-size:19px; margin:0; color:var(--navy); font-weight:600; letter-spacing:.2px; }
.brand .sub{ font-size:11px; color:var(--muted); letter-spacing:.3px; }
.status{ display:flex; gap:10px; }
.pill{ display:inline-flex; flex-direction:column; padding:7px 13px; background:var(--surface);
  border:1px solid var(--border); border-radius:10px; line-height:1.3; box-shadow:var(--shadow); }
.pill-k{ font-size:9px; letter-spacing:2px; color:var(--muted-2); text-transform:uppercase; }
.pill-v{ font-family:'IBM Plex Mono',monospace; font-size:13px; font-weight:600; color:var(--navy); }

/* ── Controls ─────────────────────────────────────────────────────────── */
.controls{ display:flex; gap:18px; align-items:center; flex-wrap:wrap;
  max-width:1080px; margin:0 auto; padding:12px 22px 16px; }
.controls label{ display:flex; align-items:center; gap:8px; font-size:11px; color:var(--muted);
  text-transform:uppercase; letter-spacing:1.2px; font-weight:600; }
.controls select{ background:var(--surface); color:var(--ink); border:1px solid var(--border);
  border-radius:8px; padding:7px 10px; font-size:13px; font-family:inherit; }
.controls input[type=range]{ accent-color:var(--gold); }
#tail-val{ min-width:24px; text-align:center; color:var(--gold); font-weight:600; }
.btn{ background:var(--navy); color:#fff; border:0; border-radius:8px; padding:8px 15px;
  font-weight:600; font-size:13px; cursor:pointer; transition:.15s; font-family:inherit; }
.btn:hover{ filter:brightness(1.12); transform:translateY(-1px); }
.btn-ghost{ background:transparent; color:var(--navy); border:1px solid var(--border); }

/* ── Stage (chart ไม่เกิน 460px และไม่เกิน 90% ของจอ) ──────────────────── */
.stage{ display:flex; flex-wrap:wrap; gap:24px; justify-content:center; align-items:flex-start;
  max-width:1120px; margin:0 auto; padding:4px 22px 22px; }
.chart-wrap{ position:relative; width:min(var(--chart-max),90vw); flex:0 0 auto; background:var(--surface);
  border:1px solid var(--border); border-radius:14px; padding:10px; box-shadow:var(--shadow); }
.legend{ width:236px; flex:0 0 auto; }
@media (max-width:760px){ .legend{ width:min(var(--chart-max),90vw); } }
#rrg{ width:100%; height:auto; display:block; }
.loading{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  color:var(--muted); font-size:14px; }
.loading[hidden]{ display:none; }

.tip{ position:absolute; pointer-events:none; z-index:5; background:var(--surface);
  border:1px solid var(--border); border-radius:10px; padding:10px 12px; font-size:12px;
  max-width:266px; box-shadow:0 12px 30px -10px rgba(20,30,45,.4); color:var(--ink); }
.tip .tip-h{ display:flex; align-items:baseline; gap:8px; margin-bottom:2px; }
.tip .tip-sym{ font-family:'IBM Plex Mono',monospace; font-weight:600; font-size:15px; }
.tip .tip-nm{ color:var(--navy); font-weight:600; }
.tip .tip-info{ color:var(--muted); font-size:11.5px; line-height:1.45; margin:2px 0 0; }
.tip .tip-when{ background:var(--surface-info); border:1px solid var(--border-info); border-radius:7px;
  padding:5px 8px; margin:8px 0; font-family:'IBM Plex Mono',monospace; }
.tip .tip-when .wk{ color:var(--navy); font-weight:600; }
.tip .tip-when .ago{ color:var(--muted); font-size:11px; }
.tip .tip-sep{ height:1px; background:var(--border-2); margin:8px 0; }
.tip .tip-q{ color:var(--muted); font-size:11px; line-height:1.4; margin:2px 0 4px; }
.tip .row{ display:flex; justify-content:space-between; gap:14px; padding:1px 0;
  font-family:'IBM Plex Mono',monospace; }
.tip .row > span:first-child{ color:var(--muted); font-family:'IBM Plex Sans Thai',sans-serif; }

/* ── Legend ───────────────────────────────────────────────────────────── */
.legend h3{ font-size:10px; letter-spacing:2px; color:var(--muted-2); text-transform:uppercase;
  font-weight:600; margin:10px 0 8px; }
.quad-legend, .sym-legend{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:6px; }
.quad-legend li{ font-size:12px; display:flex; align-items:center; gap:8px; }
.quad-legend em{ color:var(--muted); font-style:normal; font-size:11px; margin-left:auto; }
.dot{ width:11px; height:11px; border-radius:50%; flex:0 0 auto; }
.q-leading{ background:var(--q-leading);} .q-weakening{ background:var(--q-weakening);}
.q-lagging{ background:var(--q-lagging);} .q-improving{ background:var(--q-improving);}
.sym-legend li{ font-size:12px; display:flex; align-items:center; gap:8px; cursor:pointer;
  padding:3px 6px; border-radius:6px; }
.sym-legend li:hover{ background:var(--surface-2); }
.sym-legend li.dim{ opacity:.34; }
.sym-legend .sw{ width:10px; height:10px; border-radius:2px; flex:0 0 auto; }
.sym-legend .sym{ font-family:'IBM Plex Mono',monospace; font-weight:600; }
.sym-legend .nm{ color:var(--muted); margin-left:auto; font-size:11px; }
.legend-hint{ margin:14px 0 0; font-size:11px; line-height:1.55; color:var(--muted);
  background:var(--surface-2); border:1px solid var(--border-2); border-radius:8px; padding:8px 10px; }
.legend-hint b{ color:var(--navy); }

/* ── SVG bits ─────────────────────────────────────────────────────────── */
.q-rect-leading  { fill:var(--q-leading);   opacity:.07; }
.q-rect-weakening{ fill:var(--q-weakening); opacity:.07; }
.q-rect-lagging  { fill:var(--q-lagging);   opacity:.07; }
.q-rect-improving{ fill:var(--q-improving); opacity:.07; }
.q-label{ font-family:'IBM Plex Sans Thai',sans-serif; font-size:12px; font-weight:600;
  opacity:.7; text-transform:uppercase; letter-spacing:1px; }
.axis-line{ stroke:var(--border); stroke-width:1; }
.center-line{ stroke:var(--muted-2); stroke-width:1; stroke-dasharray:4 4; opacity:.6; }
.grid-line{ stroke:var(--border-2); stroke-width:1; opacity:.55; }
.axis-text{ font-family:'IBM Plex Mono',monospace; font-size:10px; fill:var(--muted-2); }
.tail-line{ fill:none; stroke-width:2.2; opacity:.6; stroke-linecap:round; }
.tail-dot{ cursor:pointer; }
.head-dot{ stroke:var(--surface); stroke-width:1.6; cursor:pointer; }
.head-label{ font-family:'IBM Plex Mono',monospace; font-size:11px; font-weight:600; fill:var(--ink);
  paint-order:stroke; stroke:var(--surface); stroke-width:3px; cursor:pointer; }
.rrg-series{ transition:opacity .15s ease; }
.faded{ opacity:.13 !important; }

/* ── Footer ───────────────────────────────────────────────────────────── */
.foot{ max-width:1080px; margin:8px auto 0; padding:18px 22px 30px; border-top:1px solid var(--border); }
.theme-bar{ display:flex; align-items:center; gap:9px; }
.theme-label{ font-size:10px; letter-spacing:2px; color:var(--muted-2); text-transform:uppercase; font-weight:600; }
.theme-swatch{ width:20px; height:20px; border-radius:50%; border:2px solid var(--border); cursor:pointer; padding:0; }
.theme-swatch.active{ border-color:var(--gold); box-shadow:0 0 0 2px rgba(184,138,62,.3); }
.disclaimer{ font-size:11px; color:var(--muted); margin:14px 0 0; line-height:1.6; }
.foot-meta{ display:flex; flex-wrap:wrap; justify-content:space-between; gap:8px;
  margin-top:10px; padding-top:10px; border-top:1px solid var(--border-2);
  font-size:11px; color:var(--muted); }
.foot-meta b{ color:var(--navy); font-weight:600; }
.foot-meta .muted{ color:var(--muted-2); }
.foot-credit{ color:var(--gold); letter-spacing:.5px; }
.foot-credit b{ color:var(--gold); }
