/* ---------------------------------------------------------------
   ธีมหลัก — เขียวเข้ม mobile-first (จอ >480px จะจัดกลางแบบ app frame)
----------------------------------------------------------------*/
:root {
  --bg: #050d09;
  --bg-2: #08170f;
  --card: rgba(14, 42, 26, 0.72);
  --card-2: rgba(10, 30, 19, 0.9);
  --line: rgba(52, 211, 153, 0.22);
  --line-strong: rgba(52, 211, 153, 0.45);
  --green: #22c55e;
  --green-2: #4ade80;
  --green-glow: rgba(34, 197, 94, 0.35);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.35);
  --amber: #f59e0b;
  --text: #e8fdf1;
  --muted: #7ea894;
  --radius: 16px;
  --nav-h: 66px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans Thai', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1000px 520px at 50% -10%, rgba(34, 197, 94, 0.16), transparent 65%),
    radial-gradient(700px 420px at 100% 100%, rgba(16, 185, 129, 0.10), transparent 60%),
    var(--bg);
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + 18px);
  position: relative;
}

a { color: var(--green-2); text-decoration: none; }

/* ------------------------------- หัวเว็บ ------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(5, 13, 9, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: 0.4px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--green), #065f46);
  box-shadow: 0 0 16px var(--green-glow);
  font-size: 15px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--card-2);
  font-size: 13px; font-weight: 600;
}

/* -------------------------------- การ์ด -------------------------------- */
.wrap { padding: 14px 16px; display: flex; flex-direction: column; gap: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.card.tight { padding: 12px; }
.card h2 { margin: 0 0 10px; font-size: 16px; display: flex; align-items: center; gap: 8px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row + .row { margin-top: 11px; }
.label { color: var(--muted); font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.value { font-weight: 700; font-variant-numeric: tabular-nums; }

.balance { font-size: 27px; font-weight: 800; color: var(--green-2); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tabular { font-variant-numeric: tabular-nums; }

/* ------------------------------- ปุ่มต่าง ๆ ------------------------------ */
button, .btn {
  font-family: inherit; font-size: 15px; font-weight: 700;
  border-radius: 13px; border: 1px solid var(--line-strong);
  background: var(--card-2); color: var(--text);
  padding: 12px 16px; cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:active, .btn:active { transform: scale(0.985); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--green), #15803d);
  border-color: transparent; color: #04140b;
  box-shadow: 0 6px 22px var(--green-glow);
}
.btn-buy {
  background: linear-gradient(135deg, #22c55e, #15803d);
  border-color: transparent; color: #04140b;
  box-shadow: 0 6px 22px var(--green-glow);
}
.btn-sell {
  background: linear-gradient(135deg, #f87171, #b91c1c);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 22px var(--red-glow);
}
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

/* ------------------------------- ฟอร์ม -------------------------------- */
label.field { display: block; margin-bottom: 11px; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select {
  width: 100%; font-family: inherit; font-size: 15px;
  padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(3, 12, 7, 0.75); color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14); }
select option { background: #08170f; }

/* ------------------------------- ป้ายสถานะ ------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; border: 1px solid transparent;
}
.badge.ok      { background: rgba(34, 197, 94, 0.16);  color: var(--green-2); border-color: rgba(34, 197, 94, 0.4); }
.badge.warn    { background: rgba(245, 158, 11, 0.15); color: #fbbf24;        border-color: rgba(245, 158, 11, 0.4); }
.badge.danger  { background: rgba(239, 68, 68, 0.15);  color: #fca5a5;        border-color: rgba(239, 68, 68, 0.4); }
.badge.neutral { background: rgba(148, 163, 184, 0.14);color: #cbd5e1;        border-color: rgba(148, 163, 184, 0.3); }

/* ------------------------------ แผงราคา -------------------------------- */
.price-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.price-tile {
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 11px 12px; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.price-tile.active { border-color: var(--green); background: rgba(34, 197, 94, 0.1); }
.price-tile .name { font-size: 12.5px; color: var(--muted); }
.price-tile .px { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.up   { color: var(--green-2); }
.down { color: #fca5a5; }
.flat { color: var(--text); }

/* กระพริบเมื่อราคาขยับ */
@keyframes flashUp   { from { background: rgba(34,197,94,0.28); } to { background: transparent; } }
@keyframes flashDown { from { background: rgba(239,68,68,0.28); } to { background: transparent; } }
.flash-up   { animation: flashUp 0.45s ease-out; }
.flash-down { animation: flashDown 0.45s ease-out; }

/* -------------------------------- กราฟ --------------------------------- */
.chart-box {
  height: 320px; border-radius: 13px; overflow: hidden;
  border: 1px solid var(--line); background: #0a1a12;
}
.chart-box iframe { border: 0; width: 100%; height: 100%; display: block; }

/* ------------------------------ แผงเทรด -------------------------------- */
.trade-panel { position: sticky; bottom: calc(var(--nav-h) + 8px); z-index: 20; }
.amount-quick { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 9px; }
.amount-quick button { flex: 1 1 0; min-width: 62px; padding: 9px 4px; font-size: 13px; border-radius: 10px; }
.dur-group { display: flex; gap: 7px; margin-top: 9px; }
.dur-group button { flex: 1; padding: 9px 4px; font-size: 13px; border-radius: 10px; }
.dur-group button.active, .amount-quick button.active {
  border-color: var(--green); background: rgba(34, 197, 94, 0.16); color: var(--green-2);
}
.trade-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.trade-actions button { padding: 15px 10px; font-size: 16px; }
.payout-note { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 9px; }

/* ---------------------------- สลับโหมดการเทรด ---------------------------- */
.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px;
  padding: 5px; border-radius: 15px;
  background: var(--card-2); border: 1px solid var(--line);
}
.mode-switch button {
  border: 0; background: transparent; color: var(--muted);
  padding: 11px 6px; font-size: 13.5px; border-radius: 11px;
}
.mode-switch button.active {
  background: linear-gradient(135deg, rgba(34,197,94,0.24), rgba(34,197,94,0.10));
  color: var(--green-2);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

/* --------------------------- เลือกฝั่งซื้อ / ขาย --------------------------- */
.side-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 5px; border-radius: 14px;
  background: rgba(3, 12, 7, 0.65); border: 1px solid var(--line);
}
.side-switch button {
  border: 0; background: transparent; color: var(--muted);
  padding: 12px 6px; font-size: 15px; font-weight: 800; border-radius: 10px;
}
.side-switch button[data-side="buy"].active {
  background: linear-gradient(135deg, var(--green), #15803d);
  color: #04140b; box-shadow: 0 4px 16px var(--green-glow);
}
.side-switch button[data-side="sell"].active {
  background: linear-gradient(135deg, #f87171, #b91c1c);
  color: #fff; box-shadow: 0 4px 16px var(--red-glow);
}

/* --------------------------- ราคาซื้อ / ราคาขาย --------------------------- */
.quote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quote-tile {
  border-radius: 13px; padding: 13px 12px; text-align: center;
  border: 1px solid var(--line); background: var(--card-2);
}
.quote-tile.buy  { border-color: rgba(34, 197, 94, 0.45);  background: rgba(34, 197, 94, 0.09); }
.quote-tile.sell { border-color: rgba(239, 68, 68, 0.45);  background: rgba(239, 68, 68, 0.09); }
.qt-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.qt-price { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.quote-tile.buy .qt-price  { color: var(--green-2); }
.quote-tile.sell .qt-price { color: #fca5a5; }

.calc-box {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  background: rgba(3, 12, 7, 0.6); border: 1px dashed var(--line);
}
.calc-box .row + .row { margin-top: 8px; }

/* ------------------------------ พอร์ตถือครอง ----------------------------- */
.holding {
  padding: 12px; border-radius: 13px;
  background: var(--card-2); border: 1px solid var(--line);
}
.holding .h-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.holding .h-qty { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.holding .h-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.holding .h-right { text-align: right; white-space: nowrap; }
.holding .h-sell { display: flex; gap: 7px; margin-top: 10px; }
.holding .h-sell input { flex: 1; padding: 9px 11px; font-size: 13.5px; }
.holding .h-pct { display: flex; gap: 6px; margin-top: 7px; }
.holding .h-pct button { flex: 1; padding: 7px 4px; font-size: 12.5px; border-radius: 9px; }

/* ------------------------------ รายการต่าง ๆ ---------------------------- */
.list { display: flex; flex-direction: column; gap: 9px; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 12px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line);
}
.item .left { min-width: 0; }
.item .t1 { font-weight: 700; font-size: 14px; }
.item .t2 { font-size: 12px; color: var(--muted); }
.item .right { text-align: right; white-space: nowrap; }

.countdown {
  font-variant-numeric: tabular-nums; font-weight: 800;
  color: var(--amber);
}

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }

/* ------------------------------ แถบเมนูล่าง ----------------------------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; height: var(--nav-h);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(6, 18, 11, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 40;
}
.bottom-nav button {
  border: 0; background: transparent; border-radius: 0;
  flex-direction: column; gap: 3px; padding: 8px 2px;
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.bottom-nav button .ico { font-size: 19px; line-height: 1; }
.bottom-nav button.active { color: var(--green-2); }
.bottom-nav button.active .ico { filter: drop-shadow(0 0 8px var(--green-glow)); }

/* -------------------------------- Toast -------------------------------- */
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px); z-index: 100;
  display: flex; flex-direction: column; gap: 8px; width: min(440px, 92vw);
}
.toast {
  padding: 12px 15px; border-radius: 12px; font-size: 14px; font-weight: 600;
  background: #0d2a1a; border: 1px solid var(--line-strong);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.22s ease-out;
}
.toast.error { background: #2a0f0f; border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }
.toast.win   { background: #0d2a1a; border-color: var(--green); color: var(--green-2); }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ------------------------------ หน้าเข้าสู่ระบบ -------------------------- */
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 34px 20px; }
.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo .mark {
  width: 62px; height: 62px; border-radius: 19px; margin: 0 auto 12px;
  display: grid; place-items: center; font-size: 30px;
  background: linear-gradient(145deg, var(--green), #065f46);
  box-shadow: 0 0 34px var(--green-glow);
}
.auth-logo h1 { margin: 0; font-size: 22px; letter-spacing: 1px; }
.auth-logo p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { flex: 1; }
.tabs button.active { border-color: var(--green); background: rgba(34, 197, 94, 0.14); color: var(--green-2); }

.hidden { display: none !important; }

/* ------------------------------- หลังบ้าน ------------------------------- */
.admin-shell { max-width: 1200px; margin: 0 auto; padding: 18px; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
tr:hover td { background: rgba(34, 197, 94, 0.05); }
.table-scroll { overflow-x: auto; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.68);
  display: grid; place-items: center; z-index: 90; padding: 18px;
}
.modal { width: min(560px, 100%); max-height: 88vh; overflow-y: auto; }
