/* ============================================================
   GoldAnalytics – app.css  (ธีมมาตรฐาน: navbar แดงเข้ม + sidebar ดำอมน้ำเงิน + พื้นที่ทำงานสว่าง)
   ============================================================ */

:root {
    --primary: #2563eb; --primary-dark: #1d4ed8; --primary-light: #3b82f6; --primary-soft: #eff6ff;
    --secondary: #f97316;

    --bg: #eef1f7; --surface: #ffffff; --surface-alt: #f8fafc; --border: #e5e7eb; --border-strong: #d6dbe4;
    --text: #1f2937; --text-muted: #6b7280; --text-light: #9ca3af;

    --success: #10b981; --success-dark: #047857; --warning: #f59e0b; --danger: #ef4444; --danger-dark: #b91c1c; --info: #3b82f6;
    --gold: #d97706; --gold-soft: #fffbeb;

    --sidebar-bg: #0d0f1a; --sidebar-bg-end: #12141f; --sidebar-active: #2563eb;
    --header-bg: #5a200b; --header-bg-end: #351002;
    --navbar-h: 56px; --sidebar-w: 212px;

    --radius: 6px; --radius-sm: 10px; --radius-btn: 10px; --radius-lg: 6px; --radius-pill: 999px;
    --shadow-sm: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
    --shadow-md: 0 4px 16px rgba(16,24,40,.08);
    --shadow-lg: 0 12px 32px rgba(16,24,40,.12);

    --grad-blue: linear-gradient(135deg,#4f8ef7,#2563eb);
    --grad-green: linear-gradient(135deg,#34d399,#10b981);
    --grad-indigo: linear-gradient(135deg,#8b7cf6,#6366f1);
    --grad-teal: linear-gradient(135deg,#10b981,#059669);
    --grad-pink: linear-gradient(135deg,#fb7185,#e11d48);
    --grad-orange: linear-gradient(135deg,#fbbf24,#f59e0b);
    --grad-purple: linear-gradient(135deg,#a78bfa,#8b5cf6);
    --grad-gold: linear-gradient(135deg,#fcd34d,#f59e0b);
    --grad-dark: linear-gradient(135deg,#334155,#0f172a);

    --font: 'Prompt', 'Noto Sans Thai', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --transition: .18s ease;

    /* ชื่อตัวแปรเดิม (ยังถูกใช้ใน inline style ของบางหน้า) */
    --bg-primary: var(--bg); --bg-secondary: var(--surface-alt); --bg-tertiary: var(--surface-alt);
    --bg-card: var(--surface); --bg-input: #f1f5f9; --bg-hover: #f1f5f9;
    --text-primary: var(--text); --text-secondary: #4b5563;
    --accent: var(--gold); --accent-dim: #b45309; --accent-pale: var(--gold-soft);
    --border-light: var(--border);
}

/* ---------- BASE ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body { font-family: var(--font); color: var(--text); line-height: 1.55; min-height: var(--vh, 100vh); display: flow-root; -webkit-font-smoothing: antialiased;
    background: radial-gradient(1100px 520px at 100% -8%, rgba(245,158,11,.10), transparent 62%), radial-gradient(900px 480px at 8% 0%, rgba(37,99,235,.07), transparent 60%), var(--bg); background-attachment: fixed; }
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }
img { display: block; max-width: 100%; }
ul { list-style: none; }
input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }
code { font-family: var(--font-mono); font-size: .86em; background: #f1f5f9; padding: 2px 6px; border-radius: 6px; color: #334155; }
h1, h2, h3, h4 { line-height: 1.3; }
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd2dd; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #a7b0bf; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: .95em; }

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--navbar-h); z-index: 300;
    display: flex; align-items: center; gap: 16px; padding: 0 16px 0 10px;
    background: linear-gradient(100deg, var(--header-bg), var(--header-bg-end)); color: #fff;
    box-shadow: 0 2px 10px rgba(53,16,2,.25);
}
.nav-burger { width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; flex-shrink: 0; }
.nav-burger span { width: 18px; height: 2px; background: #fff; border-radius: 2px; }
.nav-burger:hover { background: rgba(255,255,255,.1); }
.nav-brand { display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.nav-brand:hover { color: #fff; }
.nav-brand img { width: 32px; height: 32px; flex-shrink: 0; }
.nav-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.nav-brand-text b { font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.nav-brand-text small { font-size: 9.5px; letter-spacing: 1.2px; text-transform: uppercase; opacity: .65; }

.nav-search { position: relative; width: 280px; margin-left: 18px; }
.nav-search img { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); opacity: .75; pointer-events: none; }
.nav-search input { width: 100%; height: 36px; border-radius: var(--radius-pill); border: 1px solid rgba(255,255,255,.12); background: rgba(255,255,255,.08); color: #fff; padding: 0 14px 0 36px; outline: none; transition: var(--transition); }
.nav-search input::placeholder { color: rgba(255,255,255,.55); }
.nav-search input:focus { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.3); }
.nav-search-results { position: absolute; top: 42px; left: 0; right: 0; background: #fff; color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; display: none; z-index: 400; }
.nav-search-results.open { display: block; }
.nav-search-results a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-size: 13px; }
.nav-search-results a:hover, .nav-search-results a.hl { background: var(--primary-soft); color: var(--primary-dark); }
.nav-search-results .empty { padding: 10px; color: var(--text-muted); font-size: 12.5px; }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.nav-ticker { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 14px; border-radius: var(--radius-pill); background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.1); font-variant-numeric: tabular-nums; white-space: nowrap; }
.nav-ticker .sym { font-size: 11px; font-weight: 600; letter-spacing: .6px; opacity: .75; }
.nav-ticker .px { font-family: var(--font-mono); font-weight: 600; font-size: 14.5px; }
.nav-ticker .chg { font-family: var(--font-mono); font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 6px; }
.nav-ticker .chg.up { background: rgba(16,185,129,.22); color: #6ee7b7; }
.nav-ticker .chg.down { background: rgba(239,68,68,.22); color: #fca5a5; }
.nav-ticker .live { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; }
.nav-ticker .live.on { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.25); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(52,211,153,0); } }

.nav-bell { position: relative; width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.08); }
.nav-bell:hover { background: rgba(255,255,255,.16); }
.nav-bell .cnt { position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid var(--header-bg); }

.nav-user { position: relative; }
.nav-user-btn { display: flex; align-items: center; gap: 9px; background: transparent; border: 0; color: #fff; cursor: pointer; padding: 4px 6px 4px 4px; border-radius: var(--radius-pill); }
.nav-user-btn:hover { background: rgba(255,255,255,.08); }
.nav-user-name { display: flex; flex-direction: column; line-height: 1.15; text-align: right; }
.nav-user-name b { font-size: 13px; font-weight: 600; }
.nav-user-name small { font-size: 10.5px; opacity: .65; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grad-orange); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; border: 2px solid rgba(255,255,255,.25); }
.nav-caret { opacity: .7; font-size: 10px; }
.nav-dropdown { position: absolute; right: 0; top: 48px; min-width: 210px; background: #fff; color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; display: none; }
.nav-dropdown.open { display: block; }
.nav-dropdown .head { padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.nav-dropdown .head b { display: block; font-size: 13.5px; }
.nav-dropdown .head small { color: var(--text-muted); font-size: 11.5px; }
.nav-dropdown a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-size: 13px; }
.nav-dropdown a:hover { background: var(--surface-alt); }
.nav-dropdown a.danger { color: var(--danger-dark); }
.nav-dropdown a.danger:hover { background: #fef2f2; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed; top: var(--navbar-h); left: 0; width: var(--sidebar-w); height: calc(var(--vh, 100vh) - var(--navbar-h)); z-index: 250;
    display: flex; flex-direction: column; padding: 14px 10px 12px; overflow-y: auto; overflow-x: hidden;
    background: radial-gradient(ellipse at 20% 92%, rgba(249,115,22,.20), transparent 52%), radial-gradient(ellipse at 90% 8%, rgba(30,34,53,.95), transparent 60%), var(--sidebar-bg);
    transition: transform .25s ease;
}
.side-label { font-size: 10px; letter-spacing: 1.3px; text-transform: uppercase; color: #5d6680; padding: 6px 12px 6px; font-weight: 600; }
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-link { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 11px; color: #aab4c8; font-size: 13.5px; font-weight: 500; cursor: pointer; border: 0; background: transparent; width: 100%; text-align: left; transition: var(--transition); }
.side-link img { flex-shrink: 0; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.side-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-link.active { background: linear-gradient(135deg,#3b82f6,#2563eb); color: #fff; box-shadow: 0 8px 18px -8px rgba(37,99,235,.8); }
.side-link .lbl { flex: 1; }
.side-link .chev { transition: transform var(--transition); opacity: .6; }
.side-group.open > .side-link .chev { transform: rotate(180deg); }
.side-link .badge-red { background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; border-radius: 9px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 18px; }
.side-sub { display: none; flex-direction: column; gap: 2px; padding: 3px 0 4px 22px; }
.side-group.open > .side-sub { display: flex; }
.side-sub a { position: relative; display: block; padding: 7px 12px 7px 16px; border-radius: 9px; color: #8f99b0; font-size: 12.8px; }
.side-sub a::before { content: ''; position: absolute; left: 4px; top: 50%; width: 5px; height: 5px; border-radius: 50%; background: #475069; transform: translateY(-50%); }
.side-sub a:hover { color: #fff; background: rgba(255,255,255,.05); }
.side-sub a.active { color: #fff; background: rgba(59,130,246,.18); }
.side-sub a.active::before { background: #60a5fa; }
.side-bottom { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; align-items: center; }
.side-art { width: 156px; height: auto; opacity: .9; filter: drop-shadow(0 10px 18px rgba(0,0,0,.45)); }
.side-quote { color: #8f99b0; font-size: 11.5px; text-align: center; line-height: 1.5; margin: 8px 0 12px; }
.side-quote b { color: #e2e8f0; font-weight: 600; }
.side-status { width: 100%; border-radius: var(--radius); padding: 10px 12px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.07); }
.side-status .row { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; color: #8f99b0; }
.side-status .row + .row { margin-top: 5px; }
.side-status b { color: #e2e8f0; font-weight: 600; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #64748b; margin-right: 6px; vertical-align: middle; }
.dot.on { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.2); }
.dot.warn { background: #fbbf24; }
.dot.off { background: #ef4444; }
@media (max-height: 760px) { .side-art { width: 104px; } }
@media (max-height: 620px) { .side-art, .side-quote { display: none; } }

.side-overlay { position: fixed; inset: var(--navbar-h) 0 0 0; background: rgba(15,23,42,.5); z-index: 240; display: none; }
.side-overlay.active { display: block; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content { margin-left: var(--sidebar-w); margin-top: var(--navbar-h); padding: 20px 22px 32px; min-height: calc(var(--vh, 100vh) - var(--navbar-h)); transition: margin-left .25s ease; }
body.side-collapsed .sidebar { transform: translateX(-100%); }
body.side-collapsed .main-content { margin-left: 0; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-title { display: flex; align-items: center; gap: 13px; font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -.2px; }
.page-title-icon { width: 46px; height: 46px; border-radius: var(--radius); background: #fff; border: 1px solid #e6eaf2; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-md); flex-shrink: 0; }
.page-title-icon.gold { background: var(--grad-orange); box-shadow: 0 8px 18px -8px rgba(245,158,11,.8); }
.page-title-sub { display: block; font-size: 12.5px; font-weight: 400; color: var(--text-muted); margin-top: 1px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-chip { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: var(--radius-pill); background: rgba(255,255,255,.85); backdrop-filter: blur(6px); border: 1px solid #e3e8f0; font-size: 12px; color: var(--text-muted); box-shadow: var(--shadow-sm); white-space: nowrap; }
.page-chip .dot { margin-right: 0; }
.chip-session.open { border-color: #a7f3d0; background: #ecfdf5; color: #047857; }
.chip-session.open b { color: #065f46; }
.chip-session.closed { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.chip-session.closed b { color: #991b1b; }
.page-chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.page-fade { animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Flash ---------- */
.flash { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 16px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13px; border: 1px solid; }
.flash--success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash--error, .flash--danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash--warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash--info { background: var(--primary-soft); border-color: #bfdbfe; color: #1e40af; }
.flash-close { background: none; border: 0; cursor: pointer; opacity: .6; font-size: 14px; }
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert--error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert--success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.error-list { padding-left: 18px; list-style: disc; }

/* ============================================================
   GRID / KPI
   ============================================================ */
.grid { display: grid; gap: 14px; }
.grid-kpi { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 14px; margin-bottom: 16px; }
/* หน้าถูกย่อตามจอแล้ว (fit-screen) → แบ่ง 3+3 เฉพาะจอที่แคบจริง */
@media (max-width: 1100px) { .grid-kpi { grid-template-columns: repeat(3, minmax(0,1fr)); } }
.grid-kpi.in-col { grid-template-columns: repeat(3, minmax(0,1fr)); margin-bottom: 0; }

.kpi-card { position: relative; overflow: hidden; display: block; border-radius: var(--radius); padding: 14px 16px 13px; color: #fff; box-shadow: 0 10px 24px -12px rgba(16,24,40,.45), inset 0 1px 0 rgba(255,255,255,.25); min-width: 0; transition: transform var(--transition), box-shadow var(--transition); }
.kpi-card::before { content: ''; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(255,255,255,.18), rgba(255,255,255,0) 45%); pointer-events: none; }
.kpi-card::after { content: ''; position: absolute; right: -28px; bottom: -38px; width: 110px; height: 110px; border-radius: 50%; background: rgba(255,255,255,.12); pointer-events: none; }
a.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); color: #fff; }
.kpi-top { display: flex; align-items: center; gap: 9px; }
.kpi-blob { width: 36px; height: 36px; border-radius: var(--radius); background: rgba(255,255,255,.92); box-shadow: 0 4px 10px rgba(0,0,0,.12); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.kpi-label { font-size: 12.5px; font-weight: 500; opacity: .95; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-action { color: #fff; opacity: .8; font-size: 14px; }
.kpi-action:hover { color: #fff; opacity: 1; }
.kpi-value { font-size: 25px; font-weight: 700; margin-top: 9px; text-shadow: 0 1px 2px rgba(0,0,0,.12); line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.3px; }
.kpi-value small { font-size: 13px; font-weight: 500; opacity: .85; }
.kpi-sub { font-size: 11.5px; opacity: .92; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kpi-bar { height: 5px; border-radius: 99px; background: rgba(255,255,255,.25); margin-top: 7px; overflow: hidden; }
.kpi-bar > i { display: block; height: 100%; background: #fff; border-radius: 99px; transition: width .4s; }
.kc-blue { background: var(--grad-blue); } .kc-green { background: var(--grad-green); } .kc-indigo { background: var(--grad-indigo); }
.kc-teal { background: var(--grad-teal); } .kc-pink { background: var(--grad-pink); } .kc-orange { background: var(--grad-orange); }
.kc-purple { background: var(--grad-purple); } .kc-gold { background: var(--grad-gold); } .kc-dark { background: var(--grad-dark); }
.kpi-more { display: none; width: 100%; margin: -6px 0 14px; padding: 9px; border-radius: var(--radius-btn); border: 1px dashed var(--border-strong); background: var(--surface); color: var(--primary); font-weight: 600; cursor: pointer; }

/* ============================================================
   CARDS
   ============================================================ */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px -16px rgba(16,24,40,.18); border: 1px solid #e8ecf3; padding: 18px; min-width: 0; }
.card-header.divided, .card__header.divided { padding-bottom: 12px; border-bottom: 1px solid #eef1f6; }
.card-header, .card__header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title, .card__title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; color: var(--text); }
.card-title small { display: block; font-size: 11.5px; font-weight: 400; color: var(--text-muted); margin-top: 1px; }
h3.card-title { font-size: 14.5px; }
.card-title-icon { width: 36px; height: 36px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ci-blue { background: #e0ecff; } .ci-green { background: #d1fae5; } .ci-orange { background: #ffedd5; }
.ci-pink { background: #ffe4e6; } .ci-purple { background: #ede9fe; } .ci-teal { background: #ccfbf1; } .ci-gold { background: #fef3c7; }
.card-link { font-size: 12px; font-weight: 500; padding: 5px 11px; border-radius: var(--radius-pill); background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.card-link:hover { background: #dbeafe; }
.card-body { font-size: 13.5px; }
.card-sub { font-size: 12px; color: var(--text-muted); }
.card-scroll { overflow-y: auto; min-height: 0; }

/* legacy stat cards → แสดงแบบ KPI การ์ดขาว */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat-card { position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid #edf0f5; padding: 14px 16px; min-width: 0; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.stat-icon { position: absolute; right: 14px; top: 12px; opacity: .25; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 16px; border-radius: var(--radius-btn); border: 1px solid transparent; font-weight: 500; font-size: 13.5px; cursor: pointer; transition: var(--transition); white-space: nowrap; text-decoration: none; background: var(--surface-alt); color: var(--text); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn--sm, .btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 9px; }
.btn--full { width: 100%; }
.btn--primary, .btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 14px -6px rgba(37,99,235,.6); }
.btn--primary:hover, .btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn--secondary, .btn-outline { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover, .btn-outline:hover { border-color: var(--primary-light); color: var(--primary); background: var(--primary-soft); }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn--danger, .btn-danger { background: var(--danger); color: #fff; }
.btn--danger:hover, .btn-danger:hover { background: var(--danger-dark); color: #fff; }
.btn--success, .btn-success { background: var(--success); color: #fff; }
.btn-orange { background: var(--secondary); color: #fff; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: var(--transition); }
.btn-icon:hover { border-color: var(--primary-light); background: var(--primary-soft); }
.btn-icon.danger:hover { border-color: #fca5a5; background: #fef2f2; }

/* segmented (TF selector) */
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: #f1f5f9; border: 1px solid var(--border); gap: 2px; }
.seg button { border: 0; background: transparent; height: 28px; padding: 0 11px; border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--text-muted); cursor: pointer; font-family: var(--font-mono); }
.seg button:hover { color: var(--text); }
.seg button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-group label, .form-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.form-input, .form-select, .form-control {
    width: 100%; height: 40px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: #fff; color: var(--text);
    padding: 0 12px; outline: none; transition: var(--transition); font-size: 13.5px;
}
textarea.form-input, textarea.form-control { height: auto; padding: 10px 12px; min-height: 80px; }
.form-input:focus, .form-select:focus, .form-control:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row--space { display: flex; justify-content: space-between; align-items: center; }
.checkbox-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--primary); }
.input-icon-wrap { position: relative; }
.input-icon-wrap .form-input { padding-right: 42px; }
.input-icon-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 32px; height: 30px; border: 0; background: transparent; cursor: pointer; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.input-icon-btn:hover { background: var(--surface-alt); }
.password-strength { font-size: 11.5px; min-height: 16px; }
[data-tip] { display: inline-flex; width: 16px; height: 16px; border-radius: 50%; background: #e2e8f0; color: var(--text-muted); font-size: 10px; align-items: center; justify-content: center; cursor: help; position: relative; }
[data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 5px 9px; border-radius: 7px; font-size: 11.5px; white-space: nowrap; z-index: 10; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap, .table-container { overflow-x: auto; border-radius: var(--radius); border: 1px solid #eef1f6; }
.data-table, .mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .mini-table th { text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 600; letter-spacing: .3px; color: #64748b; background: #f6f8fb; border-bottom: 1px solid #e8ecf3; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.data-table th[data-sort] { cursor: pointer; user-select: none; }
.data-table th[data-sort]:hover { color: var(--primary); }
.data-table th[data-sort]::after { content: ' ↕'; opacity: .35; font-size: 10px; }
.data-table th.asc::after { content: ' ↑'; opacity: 1; }
.data-table th.desc::after { content: ' ↓'; opacity: 1; }
.data-table td, .mini-table td { padding: 10px 12px; border-bottom: 1px solid #f1f3f7; font-variant-numeric: tabular-nums; vertical-align: middle; }
.mini-table th, .mini-table td { padding: 7px 10px; font-size: 12px; }
.data-table tbody tr { transition: background .12s; }
.data-table tbody tr:hover td { background: #fffbeb; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.table-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.table-search { position: relative; }
.table-search img { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .6; pointer-events: none; }
.table-search input { height: 34px; width: 210px; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); padding: 0 12px 0 32px; outline: none; font-size: 12.5px; }
.table-search input:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.table-tools .form-select { height: 34px; width: auto; min-width: 120px; font-size: 12.5px; border-radius: var(--radius-pill); }
.td-up { color: var(--success-dark); } .td-down { color: var(--danger-dark); }
.text-up { color: var(--success-dark) !important; } .text-down { color: var(--danger-dark) !important; }

/* pagination */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.page-btn { min-width: 34px; height: 34px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--text-muted); font-size: 12.5px; font-weight: 500; }
.page-btn:hover { border-color: var(--primary-light); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============================================================
   BADGES / SIGNAL
   ============================================================ */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: var(--radius-pill); font-size: 11px; font-weight: 600; white-space: nowrap; background: #f1f5f9; color: #475569; }
.badge-success, .badge--success { background: #d1fae5; color: #047857; }
.badge-warning, .badge--warning { background: #fef3c7; color: #b45309; }
.badge-danger, .badge--danger { background: #fee2e2; color: #b91c1c; }
.badge-info, .badge--info, .badge-primary { background: #dbeafe; color: #1d4ed8; }
.badge-secondary, .badge--neutral { background: #f1f5f9; color: #475569; }
.badge-orange, .badge--gold { background: #ffedd5; color: #c2410c; }
.log-level-debug { background: #f1f5f9; color: #64748b; }
.log-level-info { background: #dbeafe; color: #1d4ed8; }
.log-level-warning { background: #fef3c7; color: #b45309; }
.log-level-error { background: #fee2e2; color: #b91c1c; }
.log-level-critical { background: #b91c1c; color: #fff; }
.admin-log-row td { font-size: 12px; }

.signal-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: var(--radius-pill); font-size: 11.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; white-space: nowrap; }
.signal-badge.strong-buy { background: #059669; color: #fff; }
.signal-badge.buy { background: #d1fae5; color: #047857; }
.signal-badge.neutral { background: #f1f5f9; color: #475569; }
.signal-badge.sell { background: #fee2e2; color: #b91c1c; }
.signal-badge.strong-sell { background: #dc2626; color: #fff; }
.signal-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.confidence-bar { height: 6px; background: #e8ecf2; border-radius: 99px; overflow: hidden; }
.confidence-bar__fill { height: 100%; background: linear-gradient(90deg,#60a5fa,#2563eb); border-radius: 99px; transition: width .4s; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); backdrop-filter: blur(2px); z-index: 900; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: #fff; border-radius: var(--radius); width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); max-height: calc(var(--vh, 100vh) - 32px); overflow-y: auto; animation: fadein .2s ease; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 600; font-size: 15px; }
.modal-close { width: 32px; height: 32px; border-radius: 9px; border: 0; background: var(--surface-alt); cursor: pointer; color: var(--text-muted); font-size: 14px; }
.modal-close:hover { background: #fee2e2; color: var(--danger-dark); }
.modal-box form > .form-group, .modal-box > p { padding: 0 20px; }
.modal-box form > .form-group:first-of-type { padding-top: 14px; }
.modal-box > p { margin: 16px 0; font-size: 13.5px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); margin-top: 6px; }

/* ============================================================
   UTILITIES
   ============================================================ */
.text-muted { color: var(--text-muted); } .text-danger { color: var(--danger-dark); } .text-success { color: var(--success-dark); }
.text-center { text-align: center; } .text-right { text-align: right; } .bold { font-weight: 600; }
.flex { display: flex; } .flex-wrap { flex-wrap: wrap; } .flex-gap-8 { gap: 8px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 16px; }
.mb-16 { margin-bottom: 14px; } .mb-24 { margin-bottom: 16px; }
.page-two-col { display: grid; grid-template-columns: 380px minmax(0,1fr); gap: 16px; align-items: start; }
.empty-state { text-align: center; color: var(--text-muted); padding: 34px 16px; font-size: 13px; }
.empty-state img { margin: 0 auto 10px; opacity: .5; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: currentColor; border-radius: 50%; animation: spin .6s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { font-family: var(--font); }

/* risk / backtest / alerts (หน้าเดิม) */
.risk-result-card { background: linear-gradient(135deg,#fffbeb,#fff); border: 1px solid #fde68a; border-radius: var(--radius); padding: 18px 20px; }
.kelly-meter { height: 6px; background: #e8ecf2; border-radius: 99px; overflow: hidden; margin-top: 8px; }
.kelly-meter__fill { height: 100%; background: linear-gradient(90deg,var(--success),var(--warning),var(--danger)); border-radius: 99px; }
.backtest-summary { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 16px; }
.equity-chart-wrap { height: 280px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.alert-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f1f3f7; }
.alert-row:last-child { border-bottom: 0; }
.alert-row__info { flex: 1; min-width: 0; }
.alert-row__type { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .6px; }
.alert-row__value { font-size: 14px; font-weight: 600; font-family: var(--font-mono); margin-top: 2px; }
.alert-row__note { font-size: 12px; color: var(--text-muted); }

/* steps (หน้า MT5) */
.steps { display: flex; flex-direction: column; gap: 14px; }
.step { display: flex; gap: 14px; align-items: flex-start; }
.step-no { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.step-no.ok { background: var(--success); }
.step ol { padding-left: 18px; list-style: decimal; color: var(--text-secondary); line-height: 1.9; font-size: 13px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: 130px minmax(0,1fr); gap: 8px 12px; align-items: center; font-size: 13px; }
.kv > span { color: var(--text-muted); }
.kv > div { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.kv code { word-break: break-all; }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body { min-height: var(--vh, 100vh); display: grid; grid-template-columns: 1.05fr 1fr; background: #fff; }
.auth-side { position: relative; overflow: hidden; color: #fff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between;
    background: linear-gradient(180deg, rgba(13,15,26,.35), rgba(13,15,26,.1) 45%, rgba(13,15,26,.55)), url(../img/login-bg.webp) left bottom / cover no-repeat, var(--sidebar-bg); }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand img { width: 44px; height: 44px; }
.auth-brand b { font-size: 20px; font-weight: 700; display: block; line-height: 1.1; }
.auth-brand small { font-size: 10.5px; letter-spacing: 1.4px; text-transform: uppercase; opacity: .6; }
.auth-hero h1 { font-size: 34px; font-weight: 700; line-height: 1.25; letter-spacing: -.5px; }
.auth-hero h1 span { background: linear-gradient(90deg,#fcd34d,#f97316); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-hero p { margin-top: 12px; color: #aab4c8; font-size: 14.5px; max-width: 420px; }
.auth-feats { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin-top: 28px; max-width: 520px; }
.auth-feat { border-radius: var(--radius); padding: 12px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #aab4c8; }
.auth-feat b { display: block; color: #fff; font-size: 13px; margin: 6px 0 2px; font-weight: 600; }
.auth-mascot { position: absolute; right: 40px; bottom: 26px; width: min(230px, 24%); height: auto; filter: drop-shadow(0 24px 40px rgba(0,0,0,.55)); animation: float 5s ease-in-out infinite; pointer-events: none; }
.auth-hero { position: relative; z-index: 1; max-width: 560px; }
@keyframes float { 50% { transform: translateY(-10px); } }
.mascot-empty { width: 120px; height: auto; margin: 0 auto 8px; filter: drop-shadow(0 10px 18px rgba(217,119,6,.25)); }
.auth-foot { font-size: 11.5px; color: #8f99b0; position: relative; z-index: 1; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 410px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 30px 30px 26px; }
.card-heading { font-size: 21px; font-weight: 700; }
.card-subheading { color: var(--text-muted); font-size: 13px; margin: 3px 0 20px; }
.auth-form .btn--full { height: 44px; font-size: 14.5px; margin-top: 6px; }
.auth-footer-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.auth-flash { max-width: 410px; width: 100%; }
.auth-main-inner { width: 100%; max-width: 410px; }

.error-page { min-height: var(--vh, 100vh); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; background: var(--bg); }
.error-code { font-size: 92px; font-weight: 800; line-height: 1; background: var(--grad-orange); -webkit-background-clip: text; background-clip: text; color: transparent; }
.error-msg { font-size: 24px; font-weight: 700; margin: 10px 0 6px; }
.error-detail { color: var(--text-muted); max-width: 400px; margin: 0 auto 24px; }

/* ============================================================
   BOTTOM NAV (มือถือ)
   ============================================================ */
.bottom-nav { display: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); box-shadow: none; }
    body.side-open .sidebar { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,.35); }
    body.side-collapsed .sidebar { transform: translateX(-100%); }
    .main-content, body.side-collapsed .main-content { margin-left: 0; }
    .page-two-col { grid-template-columns: 1fr; }
    .auth-body { grid-template-columns: 1fr; }
    .auth-side { display: none; }
}
@media (max-width: 900px) { .backtest-summary { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 768px) {
    .nav-search, .nav-user-name, .nav-caret { display: none; }
    .nav-brand-text small { display: none; }
    .main-content { padding: 14px 12px 84px; }
    .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 62px; background: #fff; border-top: 1px solid var(--border); z-index: 280; box-shadow: 0 -4px 16px rgba(16,24,40,.06); padding-bottom: env(safe-area-inset-bottom); }
    .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; color: var(--text-muted); background: none; border: 0; cursor: pointer; }
    .bottom-nav .active { color: var(--primary); font-weight: 600; }
    .bottom-nav img { opacity: .55; filter: grayscale(.6); }
    .bottom-nav .active img { opacity: 1; filter: none; }
    .form-row { grid-template-columns: 1fr; }
    .page-title { font-size: 17px; }
    .page-title-icon { width: 38px; height: 38px; }
}
@media (max-width: 620px) {
    .grid-kpi, .grid-kpi.in-col { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
    .grid-kpi:not(.open) > .kpi-card:nth-child(n+3) { display: none; }
    .kpi-more { display: block; }
    .kpi-card { padding: 12px; }
    .kpi-value { font-size: 18px; }
    .kpi-label { font-size: 11.5px; }
    .kpi-blob { width: 30px; height: 30px; }
    .kpi-blob img { width: 20px; height: 20px; }
    .nav-ticker .sym { display: none; }
    .nav-ticker { padding: 0 10px; gap: 7px; }
    .nav-brand-text { display: none; }
    .card { padding: 14px; }
    .table-search input { width: 100%; }
    .table-tools { width: 100%; }
    .table-tools > * { flex: 1; }
    .kv { grid-template-columns: 1fr; }
    .auth-card { padding: 24px 20px; }
}
@media (max-width: 380px) { .nav-ticker .chg { display: none; } }

/* ============================================================
   WORKSPACE COMPONENTS (equity / donut / ohlc / stat rows)
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: minmax(0,1.6fr) minmax(0,1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: minmax(0,1fr); } }
.equity-box { height: 240px; position: relative; }
.donut-row { display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 16px; align-items: center; }
.donut { position: relative; width: 150px; height: 150px; }
.donut svg { width: 150px; height: 150px; transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut-center b { font-size: 24px; font-weight: 700; line-height: 1.1; }
.donut-center span { font-size: 11px; color: var(--text-muted); }
.legend-list { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 9px; font-size: 12.5px; }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-item span { flex: 1; color: var(--text-secondary); }
.legend-item b { font-variant-numeric: tabular-nums; }
.legend-item em { font-style: normal; color: var(--text-muted); font-size: 11.5px; width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.side-compare { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin-top: 14px; }
.side-compare > div { border-radius: var(--radius); padding: 10px 12px; border: 1px solid #eef1f6; background: var(--surface-alt); }
.side-compare .h { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.side-compare .r { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }
.side-compare .r b { color: var(--text); font-variant-numeric: tabular-nums; }
.ohlc { position: absolute; left: 10px; top: 8px; z-index: 3; display: flex; gap: 10px; flex-wrap: wrap; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); background: rgba(255,255,255,.85); backdrop-filter: blur(4px); padding: 4px 9px; border-radius: var(--radius); border: 1px solid #eef1f6; pointer-events: none; }
.ohlc b { color: var(--text); font-weight: 600; }
.ohlc .up { color: var(--success-dark); } .ohlc .down { color: var(--danger-dark); }
.spark { display: block; width: 100%; height: 46px; }
.spark-wrap { margin: 2px 0 10px; padding: 6px 8px 2px; border-radius: var(--radius); background: linear-gradient(180deg,#f8fafc,#fff); border: 1px solid #eef1f6; }
.spark-wrap .cap { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); }
@media (max-width: 620px) { .ohlc { font-size: 10px; gap: 6px; padding: 3px 7px; left: 6px; top: 6px; max-width: calc(100% - 70px); } }
/* กราฟ canvas คำนวณตำแหน่งเมาส์ผิดเมื่อทั้งหน้าถูกย่อ → หักล้างการย่อเฉพาะกล่องกราฟ */
#lwchart, #equityChart { zoom: calc(1 / var(--z, 1)); }
#lwchart .ohlc { zoom: var(--z, 1); }
