:root {
  --bg: #0f0f0f;
  --panel: #161616;
  --panel-2: #1e1e1e;
  --border: #2a2a2a;
  --border-2: #2f2f2f;
  --border-3: #3a3a3a;
  --text: #d1d4dc;
  --text-strong: #ffffff;
  --muted: #8a8e97;
  --faint: #5d606b;
  --accent: #2962ff;
  --up: #089981;
  --down: #f23645;
  --hover: #2a2e39;
  --sel: #1c2333;
  --sticky: #1b1b1b;
  --row-line: #1f1f1f;
  --grid-gap: #262626;
  --track: #2a2a2a;
  --code-bg: #000000;
  --danger-line: #5a1f26;
  --notice-bg: #3a2d00;
  --notice-text: #f0c040;
  --notice-line: #6b5200;
  --warn-bg: #2a1f12;
  --shadow: #000a;
  --backdrop: #0008;
  color-scheme: dark;
}
/* โหมดสว่าง (ปุ่ม ☀/☾ บนแถบบน) — โทนเดียวกับ TradingView light */
:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f8f9fb;
  --panel-2: #ffffff;
  --border: #e0e3eb;
  --border-2: #d6dae3;
  --border-3: #c9ced8;
  --text: #131722;
  --text-strong: #000000;
  --muted: #6a6d78;
  --faint: #9598a1;
  --hover: #eef1f7;
  --sel: #e3ebff;
  --sticky: #f0f3fa;
  --row-line: #eef0f4;
  --grid-gap: #d6dae3;
  --track: #dfe3ea;
  --code-bg: #eef1f6;
  --danger-line: #f5c2c7;
  --notice-bg: #fff6dc;
  --notice-text: #8a5a00;
  --notice-line: #f0c040;
  --warn-bg: #fff4e5;
  --shadow: #0003;
  --backdrop: #0005;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 "Segoe UI", "Leelawadee UI", "Noto Sans Thai", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

#app { display: grid; grid-template-columns: 46px 1fr 0; grid-template-rows: 44px 1fr; height: 100vh; height: 100dvh;
  /* PWA เต็มจอบน iPad: เว้นแถบสถานะ (บน) / แถบโฮม (ล่าง) — ใน browser ปกติค่าเหล่านี้เป็น 0 */
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
#topbar { grid-column: 1 / 4; display: flex; align-items: center; gap: 4px; padding: 0 8px;
  background: var(--panel); border-bottom: 1px solid var(--border); white-space: nowrap; overflow-x: auto; }
#toolbar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  align-items: center; padding: 6px 0; gap: 2px; overflow-y: auto; }
#chartWrap { position: relative; min-width: 0; min-height: 0; }
#chart { position: absolute; inset: 0; }

.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; flex: none; }
.spacer { flex: 1; }
.group { display: flex; gap: 1px; }
.tb-btn, .tb-select { background: transparent; color: var(--text); border: 0; border-radius: 4px; height: 32px;
  padding: 0 9px; font-size: 14px; cursor: pointer; font: inherit; flex: none; }
.tb-select { background: var(--panel); border: 1px solid transparent; }
.tb-btn:hover, .tb-select:hover { background: var(--hover); }
.tb-btn.active { color: var(--text-strong); background: var(--hover); }
.tb-btn.tf.active { color: var(--accent); }
.tb-btn.icon { width: 32px; padding: 0; font-size: 15px; }
.tb-btn.sym { font-weight: 700; font-size: 15px; letter-spacing: .3px; }
.badge { font-size: 12px; padding: 2px 6px; border-radius: 3px; background: var(--panel-2); color: var(--muted); }
.badge.live { color: var(--up); }
.badge.stale { color: #f0b90b; }
#countdown, #clock { font-size: 13px; padding: 0 6px; }

.tool { width: 34px; height: 34px; border: 0; border-radius: 4px; background: transparent; color: var(--text);
  cursor: pointer; display: grid; place-items: center; flex: none; position: relative; }
.tool svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.4; }
.tool:hover { background: var(--hover); }
.tool.active { color: var(--accent); background: var(--hover); }
.tool-sep { width: 24px; height: 1px; background: var(--border); margin: 4px 0; flex: none; }
#tip { position: fixed; z-index: 200; max-width: min(300px, calc(100vw - 70px)); background: #000; color: #fff;
  padding: 6px 10px; border-radius: 4px; font-size: 13px; line-height: 1.45; white-space: normal; pointer-events: none;
  box-shadow: 0 2px 8px #0008; }

#warning { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: var(--notice-bg); color: var(--notice-text);
  border: 1px solid var(--notice-line); padding: 6px 14px; border-radius: 4px; font-size: 13px; z-index: 5; }
#loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); color: var(--muted); z-index: 5; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 0;
  width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: var(--backdrop); }
.dlg { display: flex; flex-direction: column; max-height: 70vh; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; font-weight: 600;
  border-bottom: 1px solid var(--border); }
.x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; }
#symInput { margin: 12px 16px; padding: 8px 10px; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; font: inherit; font-size: 14px; }
#symInput:focus { outline: 1px solid var(--accent); }
.list { overflow-y: auto; padding: 4px 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 16px; cursor: pointer; }
.row:hover, .row.sel { background: var(--hover); }
.row .s { font-weight: 700; min-width: 90px; }
.row .n { color: var(--muted); flex: 1; }
.row .src { font-size: 11px; color: var(--muted); }
.row .chk { width: 16px; color: var(--accent); }
.row input { width: 90px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 3px;
  padding: 2px 6px; font: inherit; }
.hint { color: var(--muted); font-size: 12px; padding: 10px 16px; border-top: 1px solid var(--border); }

/* ── user / login ─────────────────────────────────────────────────────── */
.tb-btn.user { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.tb-btn.user .avatar { color: var(--accent); font-size: 10px; }
#authView { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top, 0px)); padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)); }
.auth-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 28px 28px 22px; display: flex; flex-direction: column; }
.auth-brand { display: flex; margin-bottom: 10px; }
.auth-brand img { width: 210px; max-width: 100%; height: auto; display: block; }
.tb-logo { display: flex; align-items: center; padding: 0 4px 0 2px; flex: none; }
.tb-logo img { height: 22px; width: auto; display: block; }
.auth-card h1 { font-size: 22px; margin: 6px 0 18px; }
.auth-card label, .dlg-body label { font-size: 13px; color: var(--muted); margin: 10px 0 5px; }
.auth-card input:not([type=checkbox]), .dlg-body input { background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 9px 11px; font: inherit; font-size: 15px; }
.auth-card input:focus, .dlg-body input:focus { outline: none; border-color: var(--accent); }
input.invalid { border-color: var(--down) !important; }
.field-err, .form-err { color: var(--down); font-size: 12.5px; min-height: 0; margin-top: 4px; }
.form-err:empty, .field-err:empty { display: none; }
.auth-card label.check, .dlg-body label.check { display: flex; align-items: center; gap: 8px; color: var(--text); margin-top: 14px; cursor: pointer; }
#authPass2Row { display: flex; flex-direction: column; }
#authPass2Row[hidden] { display: none !important; }
button.primary { margin-top: 16px; background: var(--accent); color: #fff; border: 0; border-radius: 5px; padding: 10px;
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; }
button.primary:disabled { opacity: .6; cursor: wait; }
button.danger { background: transparent; color: var(--down); border: 1px solid var(--danger-line); border-radius: 5px; padding: 9px;
  font: inherit; cursor: pointer; }
#authSwitch { margin-top: 14px; text-align: center; color: var(--accent); text-decoration: none; font-size: 14px; }
.auth-hint { margin-top: 14px; color: var(--muted); font-size: 12px; text-align: center; }
.dlg-body { display: flex; flex-direction: column; padding: 4px 16px 18px; }
.dlg-body .sub { font-weight: 600; margin-top: 8px; }
.dlg-body hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0 12px; width: 100%; }
#userDialog .dlg { max-height: none; }
#authGuest { margin-top: 10px; text-align: center; color: var(--muted); text-decoration: none; font-size: 14px; }
#authGuest:hover { color: var(--text); }
.tb-btn.user.guest .avatar { color: var(--muted); }
.tool[data-badge]:not([data-badge=""])::before { content: attr(data-badge); position: absolute; right: 2px; bottom: 1px;
  font-size: 9px; font-weight: 700; color: var(--accent); line-height: 1; }
/* แถบเครื่องมือ/แถบบน: เลื่อนได้ แต่ไม่โชว์ scrollbar (กินที่จนปุ่มเบียด) */
#toolbar, #topbar { scrollbar-width: none; }
#toolbar { overflow-x: hidden; }
#toolbar::-webkit-scrollbar, #topbar::-webkit-scrollbar { display: none; }

/* ── แถบเครื่องมือของเส้นที่เลือก (แบบ TradingView) ───────────────────── */
#objBar { position: absolute; z-index: 20; display: flex; align-items: center; gap: 2px; padding: 3px 4px;
  background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 7px; box-shadow: 0 4px 14px var(--shadow); user-select: none; }
.ob-grip { width: 16px; height: 30px; display: grid; place-items: center; cursor: grab; color: var(--faint); }
.ob-grip:active { cursor: grabbing; }
.ob-grip svg { width: 16px; height: 16px; fill: currentColor; }
.ob-btn { position: relative; height: 32px; min-width: 32px; padding: 0 6px; border: 0; border-radius: 5px; background: transparent;
  color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 13px; }
.ob-btn:hover, .ob-btn.open { background: var(--hover); }
.ob-btn.on { color: var(--accent); }
.ob-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.ob-color svg { margin-bottom: 3px; }
#obColorBar { position: absolute; left: 7px; right: 7px; bottom: 4px; height: 3px; border-radius: 2px; }
.ob-line { display: inline-block; width: 16px; border-top: 1px solid currentColor; }
.ob-line.dashed { border-top-style: dashed; }
.ob-line.dotted { border-top-style: dotted; }
.ob-wide { font-weight: 600; }

#obPop { position: absolute; z-index: 21; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 7px;
  box-shadow: 0 6px 20px var(--shadow); padding: 10px; }
.pal { display: grid; grid-template-columns: repeat(10, 20px); gap: 4px; }
.pal-gap { margin-top: 8px; }
.pal-sw { width: 20px; height: 20px; border-radius: 3px; cursor: pointer; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 10%, transparent); }
.pal-sw:hover { transform: scale(1.12); }
.pal-sw.on { outline: 2px solid var(--text-strong); outline-offset: 1px; }
.pal-sep { height: 1px; background: var(--border-2); margin: 10px 0; }
.pal-tools { display: flex; align-items: center; gap: 8px; }
.pal-add { position: relative; width: 24px; height: 24px; display: grid; place-items: center; font-size: 20px; color: var(--text);
  cursor: pointer; border-radius: 4px; }
.pal-add:hover { background: var(--hover); }
.pal-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pal-multi { height: 26px; padding: 0 10px; border-radius: 4px; border: 1px solid var(--border-3); color: var(--text); cursor: pointer; font: inherit;
  font-size: 12.5px; background: linear-gradient(90deg, #f2364526, #ff980026, #08998126, #2962ff26, #9c27b026); }
.pal-multi.on { border-color: var(--accent); }
.pal-op-label { color: var(--muted); font-size: 12.5px; margin: 10px 0 6px; }
.pal-op { display: flex; align-items: center; gap: 10px; }
.pal-op input[type=range] { flex: 1; height: 6px; -webkit-appearance: none; appearance: none; border-radius: 3px; cursor: pointer;
  background: linear-gradient(90deg, color-mix(in srgb, var(--text) 6%, transparent), #b39ddb var(--fill, 100%), var(--track) var(--fill, 100%)); }
.pal-op input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--panel-2); box-shadow: 0 0 0 1px #888; }
.pal-op-num { display: flex; align-items: center; gap: 2px; border: 1px solid var(--border-3); border-radius: 4px; padding: 2px 6px; }
.pal-op-num input { width: 34px; background: transparent; border: 0; color: var(--text); font: inherit; text-align: right; -moz-appearance: textfield; }
.pal-op-num input::-webkit-inner-spin-button { -webkit-appearance: none; }
.pop-list { display: flex; flex-direction: column; min-width: 150px; margin: -4px -4px; }
.pop-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.pop-item:hover { background: var(--hover); }
.pop-item.on { color: var(--accent); }
.pop-item.danger { color: var(--down); }
.pop-item .pv { display: inline-block; width: 28px; border-top: 1px solid currentColor; }
.pop-item .pv.dashed { border-top: 2px dashed currentColor; }
.pop-item .pv.dotted { border-top: 2px dotted currentColor; }
.pop-item .pv.solid { border-top: 2px solid currentColor; }
.pop-list .pal-sep { margin: 4px 0; }

/* หน้าต่างตั้งค่า fibo */
#fibDialog { width: min(520px, calc(100vw - 32px)); }
.fib-body { max-height: 70vh; overflow-y: auto; }
.fib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin: 8px 0; }
.fib-row { display: flex; align-items: center; gap: 8px; }
.fib-row .fl-v { width: 90px; padding: 5px 8px !important; font-size: 14px !important; }
.fib-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.fib-row input[type=color] { width: 30px; height: 26px; padding: 0 2px; border: 1px solid var(--border); border-radius: 4px; background: transparent; }
.fib-opts { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.fib-opts label { display: flex; align-items: center; gap: 8px; color: var(--text) !important; }
.fib-opts select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 5px 8px; font: inherit; }
.fib-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.fib-btns .primary { margin-top: 0; padding: 8px 22px; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 8px 12px;
  font: inherit; cursor: pointer; }
button.ghost:hover { background: var(--hover); }
#fibAdd { align-self: flex-start; padding: 5px 10px; }
.hint-inline { color: var(--muted); font-size: 12.5px; margin-top: 12px; }

/* ── แถบขวา: Watchlist / ข่าว ─────────────────────────────────────────── */
#app.side-open { grid-template-columns: 46px 1fr 330px; }
#side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--border); }
#side[hidden] { display: none !important; }
.side-tabs { display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.side-tabs [data-tab] { background: transparent; border: 0; color: var(--muted); font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 6px 10px; border-radius: 5px; cursor: pointer; }
.side-tabs [data-tab].on { color: var(--text); background: var(--hover); }
.side-add { width: 28px; height: 28px; border: 0; border-radius: 5px; background: transparent; color: var(--text); font-size: 20px; cursor: pointer; }
.side-add:hover { background: var(--hover); }
.side-pane { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.side-pane[hidden] { display: none !important; }
.side-empty { color: var(--muted); padding: 16px; font-size: 13px; }
.wl-head, .wl-row { display: grid; grid-template-columns: minmax(70px, 1fr) 80px 66px 58px 14px; align-items: center; gap: 4px; padding: 0 8px 0 12px; }
.wl-head { height: 28px; color: var(--muted); font-size: 11.5px; border-bottom: 1px solid var(--border); }
.wl-head span:not(:first-child), .wl-row span:not(:first-child) { text-align: right; }
.wl-row { height: 34px; cursor: pointer; font-variant-numeric: tabular-nums; border-left: 2px solid transparent; }
.wl-row:hover { background: var(--hover); }
.wl-row.active { background: var(--sel); border-left-color: var(--accent); }
.wl-row.dragging { opacity: .4; }
.wl-row.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.wl-sym { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-px { font-size: 13px; border-radius: 3px; transition: background .4s; }
.wl-ch, .wl-pct { font-size: 12px; }
.up { color: var(--up); } .down { color: var(--down); }
.flash-up { background: #08998140; } .flash-down { background: #f2364540; }
.wl-x { visibility: hidden; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0; }
.wl-row:hover .wl-x { visibility: visible; }
.wl-x:hover { color: var(--down); }
.news-filter { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.news-filter label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.news-filter input { accent-color: var(--accent); }
.news-day { position: sticky; top: 0; background: var(--sticky); color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 12px; z-index: 1; }
.news-row { display: grid; grid-template-columns: 40px 10px 34px 1fr; gap: 6px; align-items: start; padding: 7px 12px; cursor: pointer; font-size: 12.5px; }
.news-row:hover { background: var(--hover); }
.news-row.past { opacity: .45; }
.news-row.next { background: var(--warn-bg); box-shadow: inset 2px 0 0 #ff9800; }
.news-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.news-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: #787b86; }
.news-dot.high { background: #f23645; } .news-dot.medium { background: #ff9800; } .news-dot.low { background: #f0b90b; }
.news-ccy { font-weight: 700; }
.news-title { line-height: 1.35; }
.news-title em { display: inline-block; margin-left: 6px; font-style: normal; color: #ff9800; font-size: 11.5px; }
.news-title small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.news-src { color: var(--faint); font-size: 11px; padding: 8px 12px; border-top: 1px solid var(--border); margin-top: auto; }
@media (max-width: 900px) { #app.side-open { grid-template-columns: 46px 1fr 240px; } .wl-head, .wl-row { grid-template-columns: 1fr 70px 0 52px 14px; } .wl-ch, .wl-head span:nth-child(3) { display: none; } }

/* ── multi-chart ──────────────────────────────────────────────────────── */
#grid { position: absolute; inset: 0; display: grid; gap: 3px; background: var(--grid-gap); z-index: 4; }
#grid[hidden] { display: none !important; }
.grid-2v { grid-template-columns: 1fr 1fr; }
.grid-2h { grid-template-rows: 1fr 1fr; }
.grid-3 { grid-template-columns: 1.4fr 1fr; grid-template-rows: 1fr 1fr; }
.grid-3 .pane:first-child { grid-row: 1 / 3; }
.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.pane { position: relative; min-width: 0; min-height: 0; background: var(--bg); }
.pane iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.pane.active::after { content: ''; position: absolute; inset: 0; border: 1px solid var(--accent); pointer-events: none; }
#layoutPop { position: fixed; z-index: 60; width: 260px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 7px;
  box-shadow: 0 6px 20px var(--shadow); padding: 10px 12px; }
#layoutPop[hidden] { display: none !important; }
#ctPop { position: fixed; z-index: 60; min-width: 180px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 7px;
  box-shadow: 0 6px 20px var(--shadow); padding: 4px; display: flex; flex-direction: column; }
#ctPop[hidden] { display: none !important; }
.ct-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: 0; border-radius: 5px; background: transparent;
  color: var(--text); font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
.ct-item:hover { background: var(--hover); }
.ct-item.on { color: var(--accent); }
.lp-title { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.lp-modes { display: flex; gap: 4px; }
.lp-mode { width: 40px; height: 34px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text); cursor: pointer;
  display: grid; place-items: center; }
.lp-mode:hover { background: var(--hover); }
.lp-mode.on { border-color: var(--accent); color: var(--accent); }
.lp-chk { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; font-size: 13px; }
.lp-chk input { accent-color: var(--accent); }
.lp-hint { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.4; }
/* ช่องย่อย: เหลือแต่กราฟ */
body.embed #topbar, body.embed #toolbar, body.embed #side, body.embed #authView { display: none !important; }
body.embed #app { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; }
/* ช่องย่อยเล็กกว่า 640×500 → media query จอมือถือทำงานใน iframe แล้วดัน #chartWrap ไปแถวที่ 2 (ซึ่งไม่มี = สูง 0)
   ตรึงไว้แถว/คอลัมน์แรกเสมอ */
body.embed #chartWrap { grid-row: 1 !important; grid-column: 1 !important; }

/* ── แจ้งเตือน ────────────────────────────────────────────────────────── */
.tg-box { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 12.5px; line-height: 1.5; }
.tg-box b { color: var(--text); }
.tg-box .tg-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.tg-box code { background: var(--code-bg); padding: 2px 6px; border-radius: 3px; font-size: 13px; letter-spacing: 1px; }
.tg-box a { color: var(--accent); }
button.small { padding: 4px 10px; font-size: 12.5px; }
.al-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; }
.al-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 8px 12px; border-top: 1px solid var(--row-line); font-size: 12.5px; }
.al-row:hover { background: var(--hover); }
.al-row .al-main { cursor: pointer; }
.al-row .al-sym { font-weight: 700; margin-right: 6px; }
.al-row .al-sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.al-row.triggered { opacity: .55; }
.al-row.paused .al-main { opacity: .6; }
.al-acts { display: flex; gap: 2px; align-items: flex-start; }
.al-acts button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 4px; font-size: 13px; border-radius: 3px; }
.al-acts button:hover { color: var(--text); background: var(--hover); }
.al-badge { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 9px; margin-left: 4px; }
.al-badge.active { background: #08998133; color: var(--up); }
.al-badge.paused { background: #78787833; color: var(--muted); }
.al-badge.triggered { background: #ff980033; color: #ff9800; }
#alertDialog { width: min(420px, calc(100vw - 32px)); }
.al-body select, .al-body input { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 5px;
  padding: 8px 10px; font: inherit; font-size: 14px; }
.al-target { font-size: 15px; margin: 4px 0 6px; }
#toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--warn-bg); border: 1px solid #ff9800; border-left-width: 4px; color: var(--text); border-radius: 6px; padding: 10px 34px 10px 12px;
  font-size: 13px; line-height: 1.45; white-space: pre-line; box-shadow: 0 6px 20px var(--shadow); position: relative; animation: toastIn .25s ease-out; }
.toast .tx { position: absolute; right: 8px; top: 6px; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; }
.toast small { display: block; color: var(--muted); margin-top: 4px; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ปุ่มภาษา TH | EN */
html.i18n-pending body { visibility: hidden; }
.lang-seg { display: inline-flex; flex: none; border: 1px solid var(--border); border-radius: 5px; overflow: hidden; height: 26px; margin: 0 2px; }
.lang-seg button { background: transparent; color: var(--muted); border: 0; padding: 0 7px; font: inherit; font-size: 11.5px; font-weight: 600;
  letter-spacing: .3px; cursor: pointer; }
.lang-seg button:hover { color: var(--text); background: var(--hover); }
.lang-seg button.on { background: var(--accent); color: #fff; cursor: default; }
.auth-card { position: relative; }
.auth-lang { position: absolute; top: 14px; right: 14px; }

/* เลือกเครื่องมือบนแถบซ้าย */
.tool[hidden], .tool-sep[hidden] { display: none; }
.tool.tools-cfg { margin-top: auto; color: var(--muted); }
#toolsDialog { width: min(400px, calc(100vw - 32px)); }
#toolsDialog .dlg-body { max-height: min(70vh, 560px); overflow-y: auto; }
.tools-list { display: flex; flex-direction: column; }
.dlg-body label.tools-row { display: flex; align-items: center; gap: 10px; margin: 0; padding: 6px 4px; color: var(--text);
  font-size: 14px; cursor: pointer; border-radius: 4px; }
.tools-row:hover { background: var(--hover); }
.tools-row input { width: 16px; height: 16px; margin: 0; padding: 0; accent-color: var(--accent); flex: none; }
.tools-row .ti { display: grid; place-items: center; flex: none; }
.tools-row .ti svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.4; }
.tools-row .tn { min-width: 0; }
.tools-sep { height: 1px; background: var(--border); margin: 4px 0; }
.tools-body .ghost { margin-top: 10px; }

/* ส่งออก / นำเข้า */
#dataDialog { width: min(440px, calc(100vw - 32px)); }
.data-body { gap: 6px; }
.data-body .primary, .data-body .ghost { margin-top: 8px; }
.data-note { margin: 0 0 4px; font-size: 13px; line-height: 1.5; }
.data-who { font-size: 13px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
.data-msg { font-size: 13px; line-height: 1.5; min-height: 0; margin-top: 8px; white-space: pre-line; }
.data-msg.ok { color: var(--up); }
.data-msg.err { color: var(--down); }

/* ปุ่มสลับธีม + โลโก้ 2 แบบ (ตัวขาวบนพื้นมืด / ตัวเข้มบนพื้นสว่าง) */
#themeBtn .ic-sun { display: none; }
:root[data-theme="light"] #themeBtn .ic-sun { display: block; }
:root[data-theme="light"] #themeBtn .ic-moon { display: none; }
.logo-on-light { display: none !important; }
:root[data-theme="light"] .logo-on-light { display: block !important; }
:root[data-theme="light"] .logo-on-dark { display: none !important; }
:root[data-theme="light"] .badge.stale { color: #a87c00; }
/* ชี้โดนเส้นที่วาด (ตั้งจาก app.js updateCursor) — ทับเคอร์เซอร์ crosshair ของ library */
#chart.ov-pick, #chart.ov-pick * { cursor: pointer !important; }
#chart.ov-move, #chart.ov-move * { cursor: move !important; }

/* ── PWA / iPad ── */
/* แถบสถานะของ iPad (โหมดเต็มจอ ตัวหนังสือสีขาว) → ทาพื้นเข้มเสมอ ทั้งธีมมืดและสว่าง */
:root { --statusbar: #161616; }
:root[data-theme="light"] { --statusbar: #131722; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--statusbar); z-index: 1000; }
/* ปิดดับเบิลแตะซูมทั้งหน้า (pinch ยังได้) · บนกราฟให้ library จัดการนิ้วเองทั้งหมด ไม่ให้ browser เลื่อน/ซูมหน้า หรือขึ้นเมนูกดค้าง */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
#chartWrap { touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* ── จอเล็ก: มือถือ / จอพับ ─────────────────────────────────────────────── */
#toolsBtn, #tfSelect { display: none; }
/* แถบบนไม่ต้องมี ปุ่มถ่ายภาพ / ป้ายแหล่งข้อมูล (● MT5) / นาฬิกา (user เลือก 2026-11-26)
   ซ่อนแทนลบ เพราะ app.js ยังอ้าง element พวกนี้ · ราคาไม่ได้มาจาก MT5 ยังมีแถบ #warning บอกอยู่ */
#shotBtn, #srcBadge, #clock { display: none !important; }
/* จอใน Magic V6 / iPad แนวตั้ง: ย่อแถบบนให้ปุ่มสำคัญ (Watchlist, ธีม, user) ไม่ตกขอบ */
@media (max-width: 900px) {
  .tb-logo, .tb-logo + .sep, #userName, #shotBtn, #fsBtn, #srcBadge { display: none; }
  .tb-btn.tf { padding-left: 6px; padding-right: 6px; }
}
/* มือถือ (แนวตั้ง ≤ 640px หรือแนวนอนเตี้ย ≤ 500px): กราฟเต็มความกว้าง
   แถบเครื่องมือวาด = แผงลอยซ้าย (ปุ่ม ✎) · Watchlist/ข่าว/แจ้งเตือน = แผ่นทับกราฟจากขวา · TF = dropdown */
@media (max-width: 640px), (max-height: 500px) {
  #app, #app.side-open { grid-template-columns: 1fr; }
  #topbar { grid-column: 1 / -1; padding: 0 4px; }
  #chartWrap { grid-column: 1; grid-row: 2; }
  #toolsBtn { display: inline-flex; align-items: center; justify-content: center; }
  #tfGroup, #fsBtn { display: none; }
  #topbar { gap: 2px; } #topbar .sep { margin: 0 2px; }
  #tfSelect { display: inline-block; font-weight: 600; }
  #toolbar { display: none; position: fixed; z-index: 40; width: 46px;
    left: env(safe-area-inset-left, 0px); top: calc(44px + env(safe-area-inset-top, 0px)); bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 4px 0 14px var(--shadow); }
  #app.tools-open #toolbar { display: flex; }
  #side { position: fixed; z-index: 40; width: min(360px, 100vw);
    right: env(safe-area-inset-right, 0px); top: calc(44px + env(safe-area-inset-top, 0px)); bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: -4px 0 14px var(--shadow); }
  .wl-head, .wl-row { grid-template-columns: 1fr 80px 0 56px 14px; } .wl-ch, .wl-head span:nth-child(3) { display: none; }
}
/* มือถือแนวตั้ง: เหลือเฉพาะปุ่มที่ใช้บ่อย (รูปแบบกราฟ / หลายกราฟ / ส่งออก-นำเข้า ใช้ได้ตอนหมุนแนวนอน) */
@media (max-width: 640px) {
  #layoutBtn, #dataBtn { display: none; }
  /* ปุ่มภาษาเหลือปุ่มเดียว = ภาษาที่จะเปลี่ยนไป (ประหยัดที่บนแถบบน) */
  #langSeg button.on { display: none; }
  #langSeg { border: 0; }
  #topbar .sep { display: none; }
  #topbar .tb-btn.icon { width: 28px; }
  .tb-btn.sym { padding-left: 4px; padding-right: 4px; font-size: 14px; }
  #topbar { gap: 0; }
  #tfSelect { padding: 0 2px; max-width: 58px; }
}
/* จอนอก Magic V6 (~360px): ซ่อน Redo (Undo ยังอยู่) ให้ปุ่มขวาสุด (รายการเฝ้าดู/ธีม/ภาษา/บัญชี) ไม่ตกขอบ */
@media (max-width: 400px) {
  #redoBtn { display: none; }
}
