/* ============ Moomoo Alert — glass design system ============ */
:root {
  --bg: #0a0f1e;
  --ink: #eef2ff;
  --ink-dim: rgba(238, 242, 255, 0.62);
  --ink-faint: rgba(238, 242, 255, 0.38);
  --glass: rgba(255, 255, 255, 0.055);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --stroke: rgba(255, 255, 255, 0.11);
  --stroke-strong: rgba(255, 255, 255, 0.2);
  --accent: #8b9dff;
  --accent-deep: #6678f2;
  --up: #4ade80;
  --down: #fb7185;
  --warn: #fbbf24;
  --radius: 20px;
  --radius-sm: 13px;
  --tabbar-h: 64px;
  --pad: 16px;
  font-size: 16px;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(1200px 800px at 85% -10%, rgba(99, 102, 241, 0.22), transparent 60%),
    radial-gradient(900px 700px at -10% 30%, rgba(45, 212, 191, 0.13), transparent 55%),
    radial-gradient(800px 900px at 70% 110%, rgba(217, 70, 239, 0.12), transparent 60%),
    var(--bg);
}

/* floating blurred blobs behind the glass */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; filter: blur(70px); }
.blob { position: absolute; border-radius: 50%; opacity: 0.5; }
.blob-a { width: 420px; height: 420px; left: -120px; top: 8%; background: #3b3fa0; animation: drift 26s ease-in-out infinite alternate; }
.blob-b { width: 380px; height: 380px; right: -110px; top: 38%; background: #155e63; animation: drift 32s ease-in-out infinite alternate-reverse; }
.blob-c { width: 300px; height: 300px; left: 30%; bottom: -120px; background: #71337f; animation: drift 38s ease-in-out infinite alternate; }
@keyframes drift { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(50px,-40px,0) scale(1.15); } }

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------- glass primitives ---------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  backdrop-filter: blur(22px) saturate(150%);
  border: 1px solid var(--stroke);
}

.card {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  backdrop-filter: blur(22px) saturate(150%);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}

.card + .card { margin-top: 12px; }
.card-title { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 12px; }

/* ---------- layout ---------- */
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

.app-header {
  position: sticky; top: 0; z-index: 40;
  border-width: 0 0 1px 0;
  padding-top: env(safe-area-inset-top);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px var(--pad); }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-icon { width: 40px; height: 40px; border-radius: 12px; box-shadow: 0 4px 14px rgba(102, 120, 242, 0.45); }
.app-header h1 { font-size: 1.25rem; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.header-sub { display: flex; align-items: center; gap: 6px; font-size: 0.74rem; color: var(--ink-dim); margin-top: 1px; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-on { background: var(--up); box-shadow: 0 0 8px var(--up); animation: pulse 2s infinite; }
.dot-off { background: var(--down); }
@keyframes pulse { 50% { opacity: 0.55; } }

.badge {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--stroke-strong); color: var(--ink-dim);
  text-transform: uppercase;
}
.badge.live { color: #052e16; background: var(--up); border-color: transparent; box-shadow: 0 2px 12px rgba(74, 222, 128, 0.45); }
.badge.demo { color: #2a1503; background: var(--warn); border-color: transparent; }

.view {
  flex: 1; padding: 16px var(--pad) calc(var(--tabbar-h) + 36px + env(safe-area-inset-bottom));
  animation: pagein 0.28s cubic-bezier(0.2, 0.7, 0.3, 1);
}
@keyframes pagein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  width: min(560px - 24px, calc(100vw - 24px));
  height: var(--tabbar-h);
  border-radius: 24px;
  display: grid; grid-template-columns: repeat(5, 1fr);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  margin-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-faint); text-decoration: none; font-size: 0.66rem; font-weight: 600;
  border-radius: 18px; margin: 6px 4px; transition: color 0.18s, background 0.18s;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--ink); background: var(--glass-strong); border: 1px solid var(--stroke); }
.tab:active { transform: scale(0.95); }

/* ---------- timeframe pills ---------- */
.tf-pills { display: flex; gap: 6px; margin-bottom: 14px; }
.tf-pills button {
  appearance: none; cursor: pointer; font: inherit; flex: 1;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em;
  color: var(--ink-dim); background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--stroke); border-radius: 10px; padding: 7px 0;
  transition: all 0.15s;
}
.tf-pills button.active {
  color: var(--bg); background: var(--accent); border-color: transparent;
  box-shadow: 0 2px 12px rgba(139, 157, 255, 0.35);
}

/* ---------- segmented control ---------- */
.segmented {
  display: grid; grid-auto-flow: column; gap: 4px;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--stroke);
  padding: 4px; border-radius: 14px; margin-bottom: 14px;
}
.segmented button {
  appearance: none; border: 0; background: transparent; color: var(--ink-dim);
  font: inherit; font-size: 0.78rem; font-weight: 600; padding: 8px 2px;
  border-radius: 10px; cursor: pointer; transition: all 0.18s;
}
.segmented button.active { background: var(--glass-strong); color: var(--ink); box-shadow: 0 2px 10px rgba(0,0,0,0.3); border: 1px solid var(--stroke); }
.segmented button .seg-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--up); margin-left: 5px; box-shadow: 0 0 6px var(--up); }

/* ---------- quote rows ---------- */
.qrow {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px;
  padding: 13px 14px; border-radius: var(--radius-sm);
  background: var(--glass);
  border: 1px solid var(--stroke);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  margin-bottom: 9px; position: relative; overflow: hidden;
  transition: transform 0.15s, border-color 0.3s;
}
.qrow:active { transform: scale(0.985); }
.qrow .sym { font-weight: 700; font-size: 0.98rem; letter-spacing: 0.01em; }
.qrow .sym small { color: var(--ink-faint); font-weight: 600; margin-left: 5px; font-size: 0.68rem; }
.qrow .name { color: var(--ink-dim); font-size: 0.74rem; margin-top: 2px; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qrow .vol { color: var(--ink-faint); font-size: 0.7rem; margin-top: 2px; }
.qrow .spark { width: 74px; height: 30px; opacity: 0.9; }
.qrow .px { text-align: right; }
.qrow .price { font-size: 1.02rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.qrow .price.flash-up { animation: flashup 0.9s ease-out; }
.qrow .price.flash-down { animation: flashdown 0.9s ease-out; }
@keyframes flashup { 0%, 40% { color: var(--up); } 100% { color: var(--ink); } }
@keyframes flashdown { 0%, 40% { color: var(--down); } 100% { color: var(--ink); } }
.chip {
  display: inline-block; margin-top: 4px; font-size: 0.72rem; font-weight: 700;
  padding: 3px 8px; border-radius: 8px; font-variant-numeric: tabular-nums;
}
.chip.up { color: #052e16; background: var(--up); }
.chip.down { color: #4c0519; background: var(--down); }
.chip.flat { color: var(--ink-dim); background: var(--glass-strong); }

/* ---------- market table ---------- */
.mkt-table {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  background: var(--glass); border: 1px solid var(--stroke);
  border-radius: var(--radius-sm); overflow: hidden;
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
.mkt-table th { padding: 0; border-bottom: 1px solid var(--stroke-strong); }
.mkt-table th button {
  appearance: none; background: none; border: 0; width: 100%; cursor: pointer;
  font: inherit; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 11px 8px; text-align: right; white-space: nowrap;
}
.mkt-table th.th-tk { width: 42%; }
.mkt-table th.th-tk button { text-align: left; padding-left: 14px; }
.mkt-table th button.active { color: var(--ink); }
.mkt-table td {
  padding: 9px 6px; border-bottom: 1px solid var(--stroke);
  font-variant-numeric: tabular-nums; vertical-align: middle;
}
.mkt-table tr:last-child td { border-bottom: 0; }
.mkt-table td.tk { padding-left: 14px; overflow: hidden; }
.mkt-table .sym { font-weight: 700; font-size: 0.92rem; letter-spacing: 0.01em; }
.mkt-table .nm { display: flex; gap: 6px; color: var(--ink-faint); font-size: 0.68rem; margin-top: 1px; }
.mkt-table .nm .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mkt-table .nm .v { flex-shrink: 0; }
.mkt-table td.num { text-align: right; font-weight: 600; font-size: 0.82rem; white-space: nowrap; }
.mkt-table td.num.price { font-weight: 700; }
.mkt-table td.up { color: var(--up); }
.mkt-table td.down { color: var(--down); }
.mkt-table td.flat { color: var(--ink-faint); }
.mkt-table th:last-child, .mkt-table td:last-child { padding-right: 14px; }
.qrow.dim .price, .qrow.dim .chip { opacity: 0.45; }
.qrow .rm {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--down); color: #4c0519; font-size: 1.1rem; font-weight: 800; line-height: 1;
  display: none; align-items: center; justify-content: center;
}
.edit-mode .qrow .rm { display: flex; }
.edit-mode .qrow .px, .edit-mode .qrow .spark { opacity: 0.15; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 0.72rem; font-weight: 600; color: var(--ink-dim); letter-spacing: 0.03em; }
input[type="text"], input[type="number"], select {
  appearance: none; width: 100%;
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--stroke);
  color: var(--ink); font: inherit; font-size: 0.92rem;
  padding: 11px 13px; border-radius: var(--radius-sm); outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 157, 255, 0.18); }
input::placeholder { color: var(--ink-faint); }
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%), linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  appearance: none; border: 1px solid var(--stroke-strong); cursor: pointer;
  background: var(--glass-strong); color: var(--ink);
  font: inherit; font-weight: 700; font-size: 0.9rem;
  padding: 12px 18px; border-radius: var(--radius-sm);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: transform 0.12s, filter 0.2s; width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent-deep), #8a5cf6);
  border-color: transparent; box-shadow: 0 6px 22px rgba(102, 120, 242, 0.45);
}
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); border-color: rgba(251, 113, 133, 0.4); background: rgba(251, 113, 133, 0.08); }
.btn.small { width: auto; padding: 8px 14px; font-size: 0.78rem; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.row-flex { display: flex; gap: 10px; align-items: center; }
.row-flex .grow { flex: 1; }
.row-flex select { flex: 0 0 154px; min-width: 132px; }

.market-tools { padding: 12px; }
.filters-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px; margin-top: 10px;
}
.filters-grid input { font-size: 0.78rem; padding: 9px 10px; }
.filters-grid .btn { width: 100%; padding: 9px 10px; }

@media (max-width: 430px) {
  .filters-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* market chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  appearance: none; cursor: pointer; font: inherit; font-size: 0.78rem; font-weight: 700;
  color: var(--ink-dim); background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--stroke); border-radius: 999px; padding: 7px 14px;
  transition: all 0.15s;
}
.chips button.active { color: var(--bg); background: var(--ink); border-color: transparent; }

/* toggle switch */
.switch { position: relative; width: 46px; height: 27px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .knob {
  position: absolute; inset: 0; border-radius: 999px; cursor: pointer;
  background: rgba(0, 0, 0, 0.4); border: 1px solid var(--stroke); transition: 0.2s;
}
.switch .knob::before {
  content: ""; position: absolute; width: 21px; height: 21px; border-radius: 50%;
  left: 2px; top: 2px; background: var(--ink-dim); transition: 0.2s;
}
.switch input:checked + .knob { background: var(--up); border-color: transparent; }
.switch input:checked + .knob::before { transform: translateX(19px); background: #052e16; }

/* ---------- alert cards ---------- */
.alert-card { display: flex; align-items: flex-start; gap: 12px; }
.alert-card .meta { flex: 1; min-width: 0; }
.alert-card .meta h3 { margin: 0 0 4px; font-size: 0.95rem; }
.alert-card .meta p { margin: 0; color: var(--ink-dim); font-size: 0.78rem; line-height: 1.45; }
.tag {
  display: inline-block; font-size: 0.62rem; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 7px; margin-bottom: 6px;
}
.tag.quote { color: #1e1b4b; background: var(--accent); }
.tag.screener { color: #042f2e; background: #2dd4bf; }
.tag.session { color: var(--ink-dim); background: var(--glass-strong); border: 1px solid var(--stroke); }
.icon-btn {
  appearance: none; background: transparent; border: 0; cursor: pointer;
  color: var(--ink-faint); padding: 6px; border-radius: 9px; line-height: 0;
}
.icon-btn:hover { color: var(--down); background: rgba(251, 113, 133, 0.1); }
.icon-btn.edit:hover { color: var(--accent); background: rgba(139, 157, 255, 0.12); }
.icon-btn svg { width: 18px; height: 18px; }

/* history */
.hist-row { padding: 11px 2px; border-bottom: 1px solid var(--stroke); }
.hist-row:last-child { border-bottom: 0; }
.hist-row .t { font-weight: 600; font-size: 0.86rem; }
.hist-row .b { color: var(--ink-dim); font-size: 0.78rem; margin-top: 2px; }
.hist-row .ts { color: var(--ink-faint); font-size: 0.68rem; margin-top: 3px; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(4, 6, 14, 0.55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  z-index: 90; animation: fadein 0.2s;
}
@keyframes fadein { from { opacity: 0; } }
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 95;
  width: min(560px, 100vw);
  max-height: 88dvh; overflow-y: auto;
  background: rgba(18, 23, 42, 0.88);
  -webkit-backdrop-filter: blur(30px) saturate(160%); backdrop-filter: blur(30px) saturate(160%);
  border: 1px solid var(--stroke-strong); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  animation: sheetup 0.3s cubic-bezier(0.2, 0.8, 0.25, 1);
}
@keyframes sheetup { from { transform: translate(-50%, 60px); opacity: 0; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 99px; background: var(--stroke-strong); margin: 6px auto 14px; }
.sheet h2 { margin: 0 0 16px; font-size: 1.1rem; }

/* condition rows */
.cond-row { display: grid; grid-template-columns: 1.2fr 0.75fr 1fr 34px; gap: 7px; margin-bottom: 9px; align-items: center; }
.cond-row .icon-btn { padding: 4px; }

/* alert trigger options (TradingView-style) */
.trig-opts { display: flex; flex-direction: column; gap: 8px; }
.trig-opt {
  appearance: none; font: inherit; text-align: left; cursor: pointer;
  display: flex; gap: 11px; align-items: flex-start; padding: 11px 13px;
  border-radius: 14px; border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.25); color: var(--ink-dim); transition: all 0.15s;
}
.trig-opt .ic { flex-shrink: 0; width: 22px; height: 22px; margin-top: 1px; line-height: 0; }
.trig-opt .ic svg { width: 22px; height: 22px; }
.trig-opt .t { display: block; font-weight: 700; font-size: 0.85rem; color: var(--ink); margin-bottom: 2px; }
.trig-opt .d { display: block; font-size: 0.72rem; line-height: 1.4; }
.trig-opt.active {
  border-color: var(--accent); background: rgba(129, 140, 248, 0.12);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.trig-opt.active .ic { color: var(--accent); }

/* ---------- toast ---------- */
#toast-root { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 120; width: min(480px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(18, 23, 42, 0.92); border: 1px solid var(--stroke-strong);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-radius: 16px; padding: 12px 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: toastin 0.3s cubic-bezier(0.2, 0.8, 0.25, 1); pointer-events: auto;
}
.toast .t { font-weight: 700; font-size: 0.86rem; }
.toast .b { color: var(--ink-dim); font-size: 0.78rem; margin-top: 2px; }
.toast.success { border-color: rgba(74, 222, 128, 0.5); }
.toast.error { border-color: rgba(251, 113, 133, 0.55); }
.toast.alert { border-color: rgba(251, 191, 36, 0.55); }
@keyframes toastin { from { opacity: 0; transform: translateY(-14px) scale(0.97); } }
.toast.out { transition: 0.25s; opacity: 0; transform: translateY(-10px); }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--ink-faint); padding: 38px 16px; font-size: 0.86rem; line-height: 1.6; }
.empty svg { width: 38px; height: 38px; opacity: 0.4; margin-bottom: 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 10px; }
.section-head h2 { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-faint); margin: 0; }
.muted { color: var(--ink-dim); font-size: 0.8rem; line-height: 1.55; }
.muted code { background: rgba(0,0,0,0.35); padding: 1px 6px; border-radius: 6px; font-size: 0.74rem; }
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--stroke); font-size: 0.85rem; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--ink-dim); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.skeleton { height: 58px; border-radius: var(--radius-sm); background: linear-gradient(100deg, var(--glass) 40%, var(--glass-strong) 50%, var(--glass) 60%); background-size: 200% 100%; animation: shimmer 1.4s infinite; margin-bottom: 9px; border: 1px solid var(--stroke); }
@keyframes shimmer { to { background-position: -200% 0; } }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--ink-faint); border-top-color: var(--ink); border-radius: 50%; animation: rot 0.7s linear infinite; vertical-align: -2px; }
@keyframes rot { to { transform: rotate(360deg); } }
