/* =====================================================================
   TRANG TÀI KHOẢN — các khối dùng chung: bố cục 2 cột, biểu đồ cột, hộp key,
   tiến trình, khung chat (job · trung gian · tin nhắn), thẻ đơn hàng, cài đặt.
   ===================================================================== */

/* ---------- Bố cục ---------- */
.page-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--sp-6); align-items: start; }
.page-side { display: flex; flex-direction: column; gap: var(--sp-4); position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); }
.page-main { display: flex; flex-direction: column; gap: var(--sp-6); min-width: 0; }
@media (max-width: 1000px) { .page-grid { grid-template-columns: 1fr; } .page-side { position: static; } }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-4); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.quick-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.muted-sm { color: var(--text-2); font-size: var(--fs-sm); }
.link-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.link-row:last-child { border-bottom: 0; }

/* ---------- Biểu đồ cột (doanh thu 6 tháng) — thuần CSS ---------- */
.bars { display: flex; align-items: flex-end; gap: var(--sp-3); height: 160px; padding-top: var(--sp-4); }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-fill { width: 100%; max-width: 48px; min-height: 2px; border-radius: 6px 6px 0 0; background: var(--text); opacity: .85; }
.bar:last-child .bar-fill { background: var(--link); opacity: 1; }
.bar-label { font-size: var(--fs-xs); color: var(--text-2); }
.bar-value { font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }

/* ---------- Thẻ mua hàng (Tool đã mua) ---------- */
.order-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.order-card { display: grid; grid-template-columns: 168px minmax(0, 1fr) auto; gap: var(--sp-4); align-items: center; padding: var(--sp-3); border-radius: var(--r-md); }
.order-card:hover { background: var(--surface-2); }
.order-thumb { aspect-ratio: 16 / 9; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); }
.order-thumb img { width: 100%; height: 100%; object-fit: cover; }
.order-title { font-weight: 500; font-size: var(--fs-lg); }
.order-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 720px) {
    .order-card { grid-template-columns: 112px minmax(0, 1fr); }
    .order-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- Hộp license key ---------- */
.key-box { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm); background: var(--surface-2); }
.key-box code { flex: 1; font-family: var(--font-mono); font-size: var(--fs-lg); letter-spacing: 1px; overflow-wrap: anywhere; }
.key-box-sm { padding: 4px var(--sp-2); }
.key-box-sm code { font-size: var(--fs-sm); letter-spacing: 0; }

/* ---------- Đánh giá sao ---------- */
.stars-input { display: inline-flex; flex-direction: row-reverse; gap: 2px; }
.stars-input input { position: absolute; opacity: 0; pointer-events: none; }
.stars-input label { font-size: 28px; line-height: 1; cursor: pointer; color: var(--surface-press); }
.stars-input input:checked ~ label, .stars-input label:hover, .stars-input label:hover ~ label { color: var(--warning); }
.stars { color: var(--warning); letter-spacing: 1px; }

/* ---------- Tiến trình (job / giao dịch trung gian) ---------- */
.steps { display: flex; gap: var(--sp-2); margin: var(--sp-2) 0 var(--sp-4); }
.step { flex: 1; min-width: 0; }
.step-bar { height: 4px; border-radius: 2px; background: var(--surface-hover); }
.step.is-done .step-bar { background: var(--success); }
.step.is-current .step-bar { background: var(--link); }
.step-label { margin-top: 6px; font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step.is-current .step-label, .step.is-done .step-label { color: var(--text); }
.action-stack { display: flex; flex-direction: column; gap: var(--sp-2); }

/* ---------- Khung chat dùng chung ---------- */
.chat-box { display: flex; flex-direction: column; height: 460px; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }
.chat-scroll { flex: 1; overflow-y: auto; padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
.msg { max-width: 75%; display: flex; flex-direction: column; align-items: flex-start; }
.msg.is-mine { align-self: flex-end; align-items: flex-end; }
.msg-bubble { padding: 8px 12px; border-radius: 18px; background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.is-mine .msg-bubble { background: var(--link); color: #fff; }
.msg-meta { font-size: var(--fs-xs); color: var(--text-3); margin: 2px 8px 0; }
.msg-img { max-width: 240px; max-height: 240px; border-radius: var(--r-md); cursor: zoom-in; display: block; }
.msg-file { display: inline-flex; align-items: center; gap: 6px; text-decoration: underline; }
.msg-day { align-self: center; font-size: var(--fs-xs); color: var(--text-3); margin: var(--sp-2) 0; }
.chat-empty { margin: auto; color: var(--text-2); text-align: center; }
.chat-compose { display: flex; align-items: flex-end; gap: var(--sp-2); padding: var(--sp-3); border-top: 1px solid var(--border); }
.chat-compose textarea { flex: 1; min-height: 40px; max-height: 140px; height: 40px; padding: 9px 14px; border-radius: 20px; resize: none; }
.chat-typing { padding: 0 var(--sp-4) var(--sp-2); font-size: var(--fs-xs); color: var(--text-2); min-height: 18px; }

/* ---------- Trang tin nhắn (2 cột) ---------- */
.messenger { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - var(--topbar-h) - var(--sp-8)); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }
.messenger-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.messenger-list-head { padding: var(--sp-4); border-bottom: 1px solid var(--border); }
.messenger-convs { flex: 1; overflow-y: auto; padding: var(--sp-2); }
.conv { display: flex; gap: var(--sp-3); align-items: center; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); cursor: pointer; }
.conv:hover { background: var(--surface-2); }
.conv.is-active { background: var(--surface-hover); }
.conv-body { flex: 1; min-width: 0; }
.conv-name { font-weight: 500; }
.conv-last { color: var(--text-2); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { color: var(--text-3); font-size: var(--fs-xs); flex-shrink: 0; }
.conv.has-unread .conv-name, .conv.has-unread .conv-last { color: var(--text); font-weight: 700; }
.messenger-pane { display: flex; flex-direction: column; min-height: 0; }
.messenger-pane .chat-box { height: auto; flex: 1; border: 0; border-radius: 0; }
.messenger-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.messenger-empty { flex: 1; display: grid; place-items: center; color: var(--text-2); text-align: center; padding: var(--sp-6); }
@media (max-width: 720px) {
    .messenger { grid-template-columns: 1fr; height: calc(100vh - var(--topbar-h) - var(--bottomnav-h) - var(--sp-6)); }
    .messenger.is-open .messenger-list { display: none; }
    .messenger:not(.is-open) .messenger-pane { display: none; }
}

/* ---------- Hồ sơ ---------- */
.profile-head { display: flex; gap: var(--sp-6); align-items: center; flex-wrap: wrap; margin-bottom: var(--sp-6); }
.profile-head .avatar { width: 120px; height: 120px; font-size: 48px; }
.profile-name { font-size: var(--fs-3xl); font-weight: 700; }
.profile-meta { color: var(--text-2); margin-top: var(--sp-1); }
.profile-bio { margin-top: var(--sp-2); max-width: 640px; white-space: pre-wrap; }
@media (max-width: 720px) { .profile-head .avatar { width: 80px; height: 80px; font-size: 32px; } .profile-name { font-size: var(--fs-2xl); } }

/* ---------- Cài đặt ---------- */
.settings { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--sp-6); align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); }
.settings-nav a { display: flex; gap: var(--sp-3); align-items: center; height: 40px; padding: 0 var(--sp-3); border-radius: 10px; }
.settings-nav a:hover { background: var(--surface-2); }
.settings-nav a.is-active { background: var(--surface-2); font-weight: 500; }
.settings-panel { display: none; }
.settings-panel.is-active { display: block; }
.settings-section + .settings-section { margin-top: var(--sp-6); }
.avatar-edit { display: flex; align-items: center; gap: var(--sp-4); }
.upload-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: 132px; border: 1px dashed var(--border-strong); border-radius: var(--r-md); color: var(--text-2); cursor: pointer; overflow: hidden; position: relative; text-align: center; padding: var(--sp-2); }
.upload-tile:hover { background: var(--surface-2); }
.upload-tile input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); }
.check-chip { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); background: var(--surface-2); cursor: pointer; }
.check-chip:has(input:checked) { background: var(--primary); color: var(--on-primary); }
.check-chip input { accent-color: var(--primary); }
@media (max-width: 860px) {
    .settings { grid-template-columns: 1fr; }
    .settings-nav { position: static; flex-direction: row; overflow-x: auto; }
    .settings-nav a { flex-shrink: 0; }
}

/* ---------- Nạp tiền ---------- */
.deposit-box { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--sp-6); align-items: start; }
.qr-frame { width: 240px; aspect-ratio: 1; border-radius: var(--r-md); background: #fff; padding: 8px; display: grid; place-items: center; }
.qr-frame img { width: 100%; height: 100%; object-fit: contain; }
.copy-val { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 700; }
.paycode { font-family: var(--font-mono); font-size: var(--fs-xl); letter-spacing: 2px; color: var(--warning); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--success); margin-right: 6px; animation: k-pulse 1.5s infinite; }
@keyframes k-pulse { 50% { opacity: .3; } }
@media (max-width: 720px) { .deposit-box { grid-template-columns: 1fr; } .qr-frame { margin: 0 auto; } }

/* ---------- Form yêu cầu ---------- */
.form-section { padding: var(--sp-5); }
.form-section + .form-section { margin-top: var(--sp-4); }
.form-section h2 { font-size: var(--fs-lg); margin-bottom: var(--sp-4); }
.form-row { display: grid; gap: var(--sp-4); grid-template-columns: 1fr 1fr; }
.form-row .field + .field { margin-top: 0; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 40px; padding: 4px 8px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid transparent; }
.tag-input:focus-within { border-color: var(--link); background: var(--bg); }
.tag-input input { flex: 1; min-width: 120px; border: 0; background: transparent; outline: none; height: 30px; }
.tag-pill { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 10px; border-radius: var(--r-pill); background: var(--surface-hover); font-size: var(--fs-sm); }
.tag-pill button { width: 20px; height: 20px; border: 0; border-radius: 50%; background: none; line-height: 1; }
.tag-pill button:hover { background: var(--surface-press); }
.req-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px 40px; gap: var(--sp-2); align-items: center; }
.req-row + .req-row { margin-top: var(--sp-2); }
.file-list { display: flex; flex-direction: column; gap: 6px; margin-top: var(--sp-2); }
.file-item { display: flex; align-items: center; gap: var(--sp-2); padding: 6px var(--sp-3); border-radius: var(--r-sm); background: var(--surface-2); font-size: var(--fs-sm); }
.file-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-zone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: var(--sp-6); border: 1px dashed var(--border-strong); border-radius: var(--r-md); color: var(--text-2); text-align: center; cursor: pointer; }
.drop-zone.is-over, .drop-zone:hover { background: var(--surface-2); }

/* ---------- Form tool: lưới ảnh, gói giá, tiến trình tải lên ---------- */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); }
.img-tile { position: relative; aspect-ratio: 16 / 9; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); }
.img-tile img { width: 100%; height: 100%; object-fit: cover; }
.img-cover { position: absolute; left: 6px; top: 6px; padding: 1px 6px; border-radius: 4px; background: rgba(0, 0, 0, .75); color: #fff; font-size: var(--fs-xs); }
.img-actions { position: absolute; right: 6px; top: 6px; display: flex; gap: 4px; }
.img-actions button { width: 26px; height: 26px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .7); color: #fff; font-size: 13px; line-height: 1; }
.img-actions button:hover { background: rgba(0, 0, 0, .9); }
.plan-row { padding: var(--sp-3); border-radius: var(--r-sm); background: var(--surface-2); }
.plan-row + .plan-row { margin-top: var(--sp-2); }
.plan-row-main { display: grid; grid-template-columns: 130px minmax(0, 1fr) 140px 36px; gap: var(--sp-2); align-items: center; }
.plan-row .input, .plan-row .select, .plan-row .textarea { background: var(--surface); }
.plan-row .textarea { margin-top: var(--sp-2); min-height: 56px; }
.plan-row [data-f="keyinfo"] { margin-top: 6px; }
@media (max-width: 640px) {
  .plan-row-main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px; }
  .plan-row-main [data-f="label"] { grid-column: 1 / 3; order: -2; }
  .plan-row-main [data-remove] { order: -1; }
  .plan-row-main [data-f="price"] { grid-column: 2 / 4; }
}
.upload-progress { margin-top: var(--sp-3); }
.upload-progress > div { height: 6px; border-radius: 3px; background: var(--link); width: 0; }
.upload-progress::before { content: ""; display: block; height: 6px; border-radius: 3px; background: var(--surface-hover); margin-bottom: -6px; }
.chip:disabled { opacity: .4; cursor: not-allowed; }
.field > label.btn { align-self: flex-start; }
