/* ===== เครื่องมือผู้ช่วยเอเย่นต์ SUPERLOT999 ===== */
:root {
    --bg: #f1f5f9;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --primary: #4f46e5;
    --primary-d: #4338ca;
    --success: #059669;
    --danger: #dc2626;
    --warn: #d97706;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Noto Sans Thai', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
code { background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: .88em; }

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px; background: #0f172a; color: #cbd5e1; flex-shrink: 0;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 1.05rem; font-weight: 700; color: #fff; padding: 20px 18px 14px; display: flex; gap: 10px; align-items: center; }
.brand small { color: #94a3b8; font-weight: 500; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; flex: 1; }
.sidebar nav a { color: #cbd5e1; padding: 10px 14px; border-radius: 10px; font-weight: 500; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .logout { color: #f87171; font-size: .9rem; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 14px 22px;
    background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.topbar h2 { margin: 0; font-size: 1.15rem; }
.menu-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; font-size: 1.1rem; padding: 4px 10px; cursor: pointer; }
.content { padding: 20px 22px 40px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ===== Components ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card h3 { margin: 0 0 12px; font-size: 1.02rem; }
.card h4 { margin: 0 0 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1.2fr 1.4fr auto; gap: 14px; align-items: end; }
.grid-2-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.field > span { font-size: .88rem; color: var(--muted); }
input, select {
    font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); min-width: 0;
}
input:focus, select:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
.btn {
    font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
    background: #fff; color: var(--ink); cursor: pointer; transition: filter .15s;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); filter: none; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.alert { border-radius: 10px; padding: 11px 14px; margin: 0 22px; margin-top: 12px; font-weight: 500; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0; }
.muted { color: var(--muted); }
.mt { margin-top: 12px; }
.hidden { display: none !important; }
.ok-text { color: var(--success); } .err-text { color: var(--danger); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.err { background: #fee2e2; color: #991b1b; }
.badge.win { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.badge.full { background: #fee2e2; color: #991b1b; }
.badge.open { background: #dcfce7; color: #166534; }

/* ===== Tabs (ดูของ/คาดคะเน) ===== */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.tab { font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.tab small { color: var(--muted); font-weight: 500; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tab.active small { color: #e0e7ff; }
.num-bold { font-weight: 700; font-size: 1.02rem; letter-spacing: 1px; }
tr.row-win { background: #fefce8; }
tr.row-win:hover { background: #fef9c3; }
.mode-badge { font-size: .75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.mode-demo { background: #fef3c7; color: #92400e; }
.mode-live { background: #d1fae5; color: #065f46; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.tbl { border-collapse: collapse; width: 100%; font-size: .88rem; background: #fff; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { background: #f8fafc; font-weight: 600; position: sticky; top: 0; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tfoot td { font-weight: 700; background: #eef2ff; border-top: 2px solid var(--primary); }
.tbl .num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--success); } .neg { color: var(--danger); }
.search-input { min-width: 180px; }
.grow { flex: 1; }

/* ===== Report ===== */
.rep-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.rep-sub { color: var(--muted); font-size: .88rem; }
.result-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chip { background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; padding: 4px 12px; border-radius: 999px; font-weight: 600; font-size: .88rem; }
.chip b { font-size: 1rem; letter-spacing: 1px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat-label { font-size: .78rem; color: var(--muted); }
.stat-value { font-size: 1.06rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.sign-note { font-size: .8rem; color: var(--muted); background: #fffbeb; border: 1px solid #fde68a; padding: 8px 12px; border-radius: 8px; }
#repStatus.loading { color: var(--muted); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #c7d2fe; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Dashboard ===== */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.dash-full { display: flex; flex-direction: column; gap: 4px; }
.dash-big { padding: 20px 22px; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.chart-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 8px; min-width: 0; }
.chart-box h4 { margin: 0 0 6px; font-size: .92rem; }
.chart-wrap { position: relative; height: 300px; }
@media (max-width: 860px) {
    .chart-grid { grid-template-columns: 1fr; }
    .chart-wrap { height: 240px; }
}
.dash-card h4 { display: flex; justify-content: space-between; align-items: baseline; }
.dash-card .period { font-size: .82rem; color: var(--muted); font-weight: 500; }
.dash-card .big { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.dash-card .mini-row { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-top: 4px; }
.dash-card .mini-row b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ===== Members ===== */
.member-search-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.member-search-row h3 { margin: 0; }
.transfer-box { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-width: 280px; }
.info-list { list-style: none; padding: 0; margin: 8px 0; }
.info-list li { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.info-list li:last-child { border: none; }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: #fff; border-radius: 16px; padding: 22px 24px; max-width: 460px; width: 100%; box-shadow: 0 20px 50px rgba(15,23,42,.25); }
.modal h3 { margin: 0 0 10px; }
.modal .confirm-lines { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 10px 0 16px; }
.modal .confirm-lines div { display: flex; justify-content: space-between; padding: 4px 0; }
.modal .confirm-lines b { font-variant-numeric: tabular-nums; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Switch ===== */
.switch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch-row input { display: none; }
.switch { width: 46px; height: 26px; background: #cbd5e1; border-radius: 999px; position: relative; transition: background .2s; flex-shrink: 0; }
.switch::after { content: ''; position: absolute; width: 20px; height: 20px; background: #fff; border-radius: 50%; top: 3px; left: 3px; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch-row input:checked + .switch { background: var(--success); }
.switch-row input:checked + .switch::after { left: 23px; }

/* ===== Login ===== */
.login-body { background: linear-gradient(135deg, #1e1b4b 0%, #312e81 55%, #4338ca 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: #fff; border-radius: 20px; padding: 36px 34px; width: 100%; max-width: 390px; box-shadow: 0 25px 60px rgba(0,0,0,.35); }
.login-logo { font-size: 2.4rem; text-align: center; }
.login-card h1 { text-align: center; font-size: 1.25rem; margin: 8px 0 2px; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 20px; font-weight: 600; letter-spacing: 1px; }
.login-card .field { margin-bottom: 14px; }
.login-hint { text-align: center; color: var(--muted); font-size: .8rem; margin: 16px 0 0; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
    .sidebar { position: fixed; left: -240px; transition: left .25s; z-index: 50; height: 100vh; }
    .sidebar.open { left: 0; }
    .menu-toggle { display: inline-block; }
    .content { padding: 14px 12px 40px; }
    .grid-3, .grid-2, .grid-2-col { grid-template-columns: 1fr; }
    .topbar { padding: 12px 14px; }
    .alert { margin: 10px 12px 0; }
    .rep-head { flex-direction: column; }
    .transfer-box { min-width: 0; width: 100%; }
    .member-search-row input[type="date"] { min-width: 140px; }
}
