/* Trade PWA — Nebula theme (theo _nebula.scss của trade dashboard) */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0a0713;
    --card: rgba(30, 24, 54, .55);
    --line: rgba(150, 130, 255, .16);
    --line2: rgba(150, 130, 255, .22);
    --text: #f0ecff;
    --muted: #948dbb;
    --dim: #6f6890;
    --vio: #a855f7;
    --ind: #6366f1;
    --lav: #c084fc;
    --ok: #34e5b0;
    --bad: #f87171;
    --warn: #fbbf24;
    --info: #38bdf8;
    --grad: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
}

html { background: var(--bg); }
body {
    background:
        radial-gradient(ellipse 70% 42% at 12% -6%, rgba(168, 85, 247, .2), transparent 62%),
        radial-gradient(ellipse 55% 36% at 88% -4%, rgba(56, 189, 248, .14), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}
.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.up { color: var(--ok); }
.dn { color: var(--bad); }

button, input { font: inherit; color: inherit; background: none; border: none; outline: none; }
button { cursor: pointer; touch-action: manipulation; }
button:active { opacity: .75; transform: scale(.98); }

#app { padding: calc(var(--sat) + 8px) 14px calc(var(--sab) + 86px); max-width: 560px; margin: 0 auto; }

/* Header */
.hdr { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 12px; }
.hdr h1 { font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.hact { display: flex; gap: 8px; align-items: center; }

/* Chips / segments */
.chip {
    display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 999px;
    border: 1px solid var(--line2); background: rgba(255, 255, 255, .04);
    font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.chip.on { color: #fff; background: var(--grad); border-color: transparent; box-shadow: 0 4px 14px rgba(120, 70, 240, .35); }
.chiprow { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chiprow::-webkit-scrollbar { display: none; }
.seg { display: inline-flex; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { padding: 5px 14px; border-radius: 999px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--grad); color: #fff; }

/* Cards */
.card {
    background: var(--card); border: 1px solid var(--line); border-radius: 16px;
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 8px 32px rgba(80, 40, 160, .18); margin-bottom: 12px;
}
.card .ct { padding: 13px 14px 11px; }
.ct-title { font-size: 12px; font-weight: 700; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.ct-title span { font-size: 10px; color: var(--dim); font-weight: 500; }

/* Stat strip + KPI + tiles */
.strip { display: flex; gap: 9px; overflow-x: auto; margin: 0 -14px 12px; padding: 2px 14px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.stat { flex: none; min-width: 112px; padding: 11px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); backdrop-filter: blur(14px); }
.k { font-size: 9.5px; font-weight: 700; letter-spacing: .9px; text-transform: uppercase; color: var(--dim); margin-bottom: 4px; white-space: nowrap; }
.v { font-size: 15px; font-weight: 600; white-space: nowrap; }
.s { font-size: 10px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 12px; }
.kpi { padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); backdrop-filter: blur(14px); }
.kpi .v { font-size: 17px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 12px; }
.tile { padding: 11px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); backdrop-filter: blur(14px); }

/* List rows */
.row { display: flex; align-items: center; gap: 11px; padding: 12px 14px; border-bottom: 1px solid rgba(150, 130, 255, .08); }
.row:last-child { border-bottom: none; }
.tk { width: 38px; height: 38px; flex: none; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; background: rgba(168, 85, 247, .13); color: var(--lav); }
.rin { flex: 1; min-width: 0; }
.rt { font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 6px; overflow: hidden; }
.rb { font-size: 10.5px; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rr { text-align: right; flex: none; }
.rp { font-size: 14px; font-weight: 600; }
.rn { font-size: 10px; color: var(--dim); margin-top: 2px; }
.ex { font-size: 8.5px; font-weight: 700; letter-spacing: .5px; padding: 2px 6px; border-radius: 5px; background: rgba(56, 189, 248, .13); color: var(--info); flex: none; }
.ex.k { background: rgba(251, 191, 36, .12); color: var(--warn); }
.ex.m { background: rgba(192, 132, 252, .14); color: var(--lav); }
.dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px rgba(52, 229, 176, .7); }
.dot.off { background: var(--bad); box-shadow: 0 0 8px rgba(248, 113, 113, .6); }
.dot.idle { background: var(--warn); box-shadow: 0 0 8px rgba(251, 191, 36, .6); }

/* Progress bar */
.wr { height: 4px; border-radius: 3px; background: rgba(255, 255, 255, .06); overflow: hidden; margin-top: 7px; }
.wr i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, #34e5b0, #22d3ee); }
.wr i.low { background: linear-gradient(90deg, #fb7185, #ef4444); }

/* Terminal */
.term { background: rgba(5, 3, 10, .72); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.tbar { display: flex; align-items: center; gap: 6px; padding: 10px 13px; border-bottom: 1px solid rgba(150, 130, 255, .1); font-size: 10px; color: var(--dim); }
.tbar .b { width: 9px; height: 9px; border-radius: 50%; }
.logs { padding: 6px 13px 10px; font-size: 11px; line-height: 1.55; overflow-x: hidden; max-height: 64vh; overflow-y: auto; overscroll-behavior: contain; }
.pl { padding: 3px 0; white-space: pre-wrap; word-break: break-word; }
.pl .proc { color: var(--info); }
.pl .srv { color: var(--lav); font-weight: 700; }
.ln { padding: 7px 0; border-bottom: 1px solid rgba(150, 130, 255, .07); }
.ln:last-child { border-bottom: none; }
.ln .meta { display: flex; align-items: center; gap: 7px; font-size: 10px; margin-bottom: 2px; }
.ln .meta .srv { color: var(--muted); font-weight: 700; }
.ln .kind { font-size: 8.5px; font-weight: 700; letter-spacing: .4px; padding: 1px 6px; border-radius: 4px; background: rgba(255, 255, 255, .06); }
.ln .body { white-space: normal; word-break: break-word; color: var(--text); }
.ln .note { color: var(--dim); }
.ts { color: #5a5380; }
.c-ok { color: #34e5b0; } .c-er { color: #f87171; } .c-wn { color: #fbbf24; } .c-in { color: #38bdf8; } .c-vi { color: #c084fc; } .c-gy { color: #948dbb; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 12px; padding: 4px 0 12px; min-height: 40vh; }
.msg { max-width: 84%; padding: 11px 14px; font-size: 12.5px; line-height: 1.55; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--grad); color: #fff; border-radius: 16px 16px 4px 16px; box-shadow: 0 6px 18px rgba(120, 70, 240, .35); }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; backdrop-filter: blur(14px); white-space: pre-wrap; }
.msg .who { display: flex; align-items: center; gap: 6px; font-size: 9.5px; font-weight: 700; letter-spacing: .8px; color: var(--lav); margin-bottom: 6px; }
.msg .who i { width: 5px; height: 5px; border-radius: 50%; background: var(--ok); }
.inbar {
    position: fixed; left: 14px; right: 14px; bottom: calc(var(--sab) + 76px); z-index: 8;
    display: flex; align-items: center; gap: 9px; max-width: 532px; margin: 0 auto;
    background: rgba(24, 18, 44, .96); border: 1px solid rgba(150, 130, 255, .24); border-radius: 999px;
    padding: 7px 7px 7px 16px; backdrop-filter: blur(18px);
}
.inbar input { flex: 1; font-size: 15px; color: var(--text); min-width: 0; }
.inbar input::placeholder { color: var(--dim); }
.send { width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--grad); display: flex; align-items: center; justify-content: center; box-shadow: 0 5px 14px rgba(120, 70, 240, .45); }
.send svg { width: 16px; height: 16px; stroke: #fff; }

/* Bottom nav */
.bnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; display: flex;
    padding: 6px 8px calc(var(--sab) + 6px);
    background: rgba(18, 13, 34, .86); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
}
.bnav[hidden] { display: none; }
.bnav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 9px; color: var(--dim); font-size: 10px; font-weight: 600; position: relative; }
.bnav button.on { color: var(--lav); }
.bnav button.on::before { content: ""; position: absolute; top: 0; width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: linear-gradient(90deg, #a855f7, #6366f1); }
.bnav svg { width: 21px; height: 21px; }
svg.ic { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* Sheet (Thêm) */
.dimmer { position: fixed; inset: 0; z-index: 10; background: rgba(5, 3, 10, .55); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; transform: translateY(105%); transition: transform .25s cubic-bezier(.2, .8, .25, 1);
    /* KHÔNG backdrop-filter ở đây: Safari iOS lỗi render blur+transform cùng element fixed → sheet biến mất, blur leak toàn màn */
    background: #191231; border: 1px solid rgba(150, 130, 255, .22); border-bottom: none;
    border-radius: 20px 20px 0 0; padding: 10px 18px calc(var(--sab) + 22px);
    box-shadow: 0 -18px 60px rgba(80, 40, 160, .4); max-width: 560px; margin: 0 auto;
}
.sheet.open { transform: translateY(0); }
.dimmer.open { opacity: 1; pointer-events: auto; }
.handle { width: 42px; height: 4.5px; border-radius: 3px; background: rgba(240, 236, 255, .22); margin: 4px auto 14px; }
.sheet h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.sgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.sgi { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 15px 6px 12px; border-radius: 14px; background: rgba(255, 255, 255, .035); border: 1px solid var(--line); color: var(--muted); font-size: 10.5px; font-weight: 600; }
.sgi .icw { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: rgba(168, 85, 247, .14); color: var(--lav); }
.sgi .icw svg { width: 19px; height: 19px; }
.sfoot { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; border-top: 1px solid rgba(150, 130, 255, .12); font-size: 12px; }
.sfoot .who { color: var(--muted); }
.sfoot .out { color: var(--bad); font-weight: 600; display: flex; align-items: center; gap: 6px; }

/* Login */
.login { display: flex; flex-direction: column; justify-content: center; min-height: calc(100vh - 140px); padding: 0 16px; }
.ring { width: 86px; height: 86px; border-radius: 50%; margin: 0 auto 20px; background: conic-gradient(from 210deg, #a855f7, #6366f1, #22d3ee, #a855f7); padding: 3px; box-shadow: 0 0 40px rgba(168, 85, 247, .45); }
.ring .in { width: 100%; height: 100%; border-radius: 50%; background: #0d0918; display: flex; align-items: center; justify-content: center; }
.ring svg { width: 38px; height: 38px; stroke: #c084fc; fill: none; stroke-width: 1.8; stroke-linecap: round; }
.wm { text-align: center; font-size: 21px; font-weight: 800; letter-spacing: 6px; margin-bottom: 4px; }
.wm i { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tag { text-align: center; color: var(--muted); font-size: 12.5px; margin-bottom: 30px; }
.login label { display: block; font-size: 11px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase; color: var(--dim); margin: 0 0 7px 2px; }
.inp { display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, .04); border: 1px solid rgba(150, 130, 255, .2); border-radius: 9px; padding: 12px 14px; margin-bottom: 16px; }
.inp:focus-within { border-color: #a855f7; box-shadow: 0 0 0 3px rgba(168, 85, 247, .18); }
.inp input { flex: 1; font-size: 16px; min-width: 0; }
.btn-primary { width: 100%; padding: 14px; border-radius: 9px; background: var(--grad); color: #fff; font-size: 14.5px; font-weight: 700; box-shadow: 0 8px 24px rgba(120, 70, 240, .4); margin-top: 6px; }
.err { color: var(--bad); font-size: 12px; text-align: center; margin-top: 12px; min-height: 18px; }
.alt { text-align: center; margin-top: 18px; font-size: 12.5px; color: var(--lav); }

/* Skeleton */
.sk { border-radius: 10px; background: rgba(150, 130, 255, .08); position: relative; overflow: hidden; }
.sk::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(192, 132, 252, .12) 50%, transparent 70%); animation: shimmer 1.4s infinite; }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.empty { text-align: center; color: var(--dim); font-size: 12px; padding: 28px 0; }
.center { text-align: center; }
