/* =====================================================================
   KRENDE UI — NỀN TẢNG & KHUNG TRANG
   Thanh trên (topbar) · menu trượt (drawer) · thanh dưới trên điện thoại · vùng nội dung.
   KHÔNG có hiệu ứng chuyển trang: trang hiện ngay, khi chờ dữ liệu thì dùng khung xương
   (skeleton) + thanh tiến trình mảnh ở mép trên để cảm giác luôn mượt kể cả khi mạng chậm.
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 400 var(--fs-md)/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}
img, svg, video { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
a.link, .prose a { color: var(--link); }
a.link:hover, .prose a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.25; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p  { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
::selection { background: var(--link); color: #fff; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.mono  { font-family: var(--font-mono); }

/* ---------- Thanh tiến trình khi chuyển trang / tải dữ liệu chậm ---------- */
.k-progress {
    position: fixed; top: 0; left: 0; height: 2px; width: 0;
    background: var(--danger); z-index: 1000; pointer-events: none;
}
.k-progress.is-active { width: 70%; transition: width 8s cubic-bezier(.1, .7, .1, 1); }
.k-progress.is-done   { width: 100%; opacity: 0; transition: width .15s, opacity .3s .15s; }

/* ---------- Thanh trên ---------- */
.k-topbar {
    position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 100;
    display: flex; align-items: center; gap: var(--sp-4);
    padding: 0 var(--sp-4);
    background: var(--bg);
}
.k-topbar-start, .k-topbar-end { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }
.k-topbar-center { flex: 1; display: flex; justify-content: center; min-width: 0; }

.k-logo { display: flex; align-items: center; gap: 8px; padding: 0 var(--sp-2); }
.k-logo-mark {
    width: 30px; height: 30px; border-radius: 8px;
    display: grid; place-items: center;
    background: var(--primary); color: var(--on-primary);
    font-weight: 900; font-size: 18px; letter-spacing: -1px;
}
.k-logo-text { font-weight: 700; font-size: 19px; letter-spacing: -.4px; }

/* Ô tìm kiếm dạng viên thuốc */
.k-search { display: flex; width: 100%; max-width: 640px; height: 40px; }
.k-search input {
    flex: 1; min-width: 0; padding: 0 var(--sp-4);
    background: var(--bg); border: 1px solid var(--border-strong); border-right: 0;
    border-radius: var(--r-pill) 0 0 var(--r-pill); outline: none;
}
.k-search input:focus { border-color: var(--link); }
.k-search button {
    width: 64px; border: 1px solid var(--border-strong);
    border-radius: 0 var(--r-pill) var(--r-pill) 0; background: var(--surface-2);
}
.k-search button:hover { background: var(--surface-hover); }

/* Số dư dạng chip */
.k-balance {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 var(--sp-3);
    border-radius: var(--r-pill); background: var(--surface-2); font-weight: 500; white-space: nowrap;
}
.k-balance:hover { background: var(--surface-hover); }

/* ---------- Menu trượt (drawer) ---------- */
.k-scrim {
    position: fixed; inset: 0; z-index: 200; background: var(--overlay);
    display: none;
}
.k-drawer {
    position: fixed; inset: 0 auto 0 0; width: var(--drawer-w); z-index: 201;
    background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
    transform: translateX(-100%); visibility: hidden;
}
body.drawer-open { overflow: hidden; }
body.drawer-open .k-scrim { display: block; }
body.drawer-open .k-drawer { transform: none; visibility: visible; }
.k-drawer-head { height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-4); }
.k-drawer-section { padding: var(--sp-3) var(--sp-3); border-bottom: 1px solid var(--border); }
.k-drawer-section:last-child { border-bottom: 0; }
.k-drawer-title { padding: 6px var(--sp-3) 4px; font-size: var(--fs-lg); font-weight: 700; }
.k-nav-item {
    display: flex; align-items: center; gap: var(--sp-6);
    height: 40px; padding: 0 var(--sp-3); border-radius: 10px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.k-nav-item:hover  { background: var(--surface-2); }
.k-nav-item:active { background: var(--surface-hover); }
.k-nav-item.is-active { background: var(--surface-2); font-weight: 500; }
.k-nav-item.is-highlight { color: var(--link); font-weight: 500; }
.k-nav-icon { width: 24px; text-align: center; font-size: 18px; flex-shrink: 0; }
.k-drawer-langs { display: flex; align-items: center; gap: var(--sp-2); padding-left: var(--sp-6) !important; font-size: var(--fs-sm); }
.k-drawer-langs .k-nav-icon { margin-right: var(--sp-2); }
.k-drawer-langs a { color: var(--text-2); }
.k-drawer-langs a:hover { color: var(--text); }
.k-drawer-langs a.is-active { color: var(--text); font-weight: 500; }
.k-lang-btn { font-size: 12px !important; font-weight: 700; letter-spacing: .04em; }

/* ---------- Vùng nội dung ---------- */
.k-main { padding: calc(var(--topbar-h) + var(--sp-4)) var(--sp-6) var(--sp-10); }
.k-container { max-width: var(--content-max); margin: 0 auto; }
.k-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.k-page-head p { color: var(--text-2); margin-top: var(--sp-1); }

/* ---------- Thanh dưới (điện thoại) ---------- */
.k-bottomnav {
    position: fixed; inset: auto 0 0 0; height: var(--bottomnav-h); z-index: 100;
    display: none; background: var(--bg); border-top: 1px solid var(--border);
}
.k-bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 10px; color: var(--text-2);
}
.k-bottomnav a span:first-child { font-size: 20px; line-height: 1; }
.k-bottomnav a.is-active { color: var(--text); font-weight: 500; }

/* ---------- Responsive ---------- */
.k-show-mobile { display: none !important; }   /* chỉ hiện trên điện thoại (xem media query dưới) */
@media (max-width: 1000px) {
    .k-balance .k-balance-label { display: none; }
}
@media (max-width: 720px) {
    .k-topbar { gap: var(--sp-2); padding: 0 var(--sp-2); }
    .k-topbar-center { display: none; }               /* tìm kiếm chuyển thành nút kính lúp */
    .k-hide-mobile { display: none !important; }
    .k-show-mobile { display: inline-flex !important; }
    .k-main { padding: calc(var(--topbar-h) + var(--sp-3)) var(--sp-4) calc(var(--bottomnav-h) + var(--sp-6)); }
    .k-bottomnav { display: flex; }
}

/* Ô tìm kiếm mở rộng toàn thanh trên điện thoại */
body.search-open .k-topbar-start,
body.search-open .k-topbar-end { display: none; }
body.search-open .k-topbar-center { display: flex; }

/* ---------- Khung trang dùng class tiền tố "k-" riêng ----------
   Tự đặt lại font, màu chữ, cỡ chữ để không bị CSS của trang (hoặc trang admin dùng CSS riêng)
   làm lệch. */
.k-topbar, .k-drawer, .k-bottomnav, .k-menu, .k-scrim {
    font: 400 var(--fs-md)/1.5 var(--font);
    color: var(--text);
    letter-spacing: normal;
    text-transform: none;
}
.k-topbar *, .k-drawer *, .k-bottomnav *, .k-menu * { box-sizing: border-box; }
.k-topbar a, .k-drawer a, .k-bottomnav a, .k-menu a { color: inherit; text-decoration: none; }
.k-topbar button, .k-drawer button, .k-menu button { font-family: var(--font); margin: 0; }

.k-icon-btn {
    position: relative; display: inline-grid; place-items: center; flex-shrink: 0;
    width: 40px; height: 40px; padding: 0; border-radius: 50%; border: 0;
    background: transparent; color: var(--text); font-size: 20px; line-height: 1; cursor: pointer;
}
.k-icon-btn:hover  { background: var(--surface-2); }
.k-icon-btn:active { background: var(--surface-hover); }
.k-dot {
    position: absolute; top: 4px; right: 2px; min-width: 18px; height: 16px; padding: 0 4px;
    border-radius: var(--r-pill); background: var(--badge); color: #fff;
    font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
.k-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
    display: grid; place-items: center; background: var(--surface-hover); color: var(--text);
    font-weight: 500; font-size: 14px;
}
.k-avatar img { width: 100%; height: 100%; object-fit: cover; }
.k-avatar-lg { width: 40px; height: 40px; font-size: 16px; }
.k-login {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 var(--sp-3);
    border-radius: var(--r-pill); border: 1px solid var(--border-strong); color: var(--link) !important;
    font-weight: 500; white-space: nowrap;
}
.k-login:hover { background: var(--info-bg); border-color: transparent; }

.k-menu-anchor { position: relative; }
.k-menu {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 300; min-width: 280px;
    padding: var(--sp-2) 0; border-radius: var(--r-md); background: var(--surface-2);
    box-shadow: var(--shadow-pop); display: none;
}
.k-menu.is-open { display: block; }
.k-menu-head { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); }
.k-menu-item {
    display: flex; align-items: center; gap: var(--sp-4); width: 100%; height: 40px;
    padding: 0 var(--sp-4); border: 0; background: none; color: var(--text); text-align: left;
    font-size: var(--fs-md); cursor: pointer;
}
.k-menu-item:hover { background: var(--surface-hover); }
.k-menu-sep { height: 1px; margin: var(--sp-2) 0; background: var(--border-strong); }

/* ---------- Hộp thoại & toast của khung (class "k-" riêng, dùng được cả trên trang cũ) ---------- */
.k-modal-scrim { position: fixed; inset: 0; z-index: 1000; background: var(--overlay); display: grid; place-items: center; padding: var(--sp-4); font: 400 var(--fs-md)/1.5 var(--font); color: var(--text); }
.k-modal { width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; border-radius: var(--r-lg); background: var(--surface-2); padding: var(--sp-6); box-shadow: var(--shadow-pop); }
.k-modal-title { font-size: var(--fs-xl); font-weight: 700; margin-bottom: var(--sp-2); }
.k-modal-msg { margin: 0; color: var(--text-2); white-space: pre-line; }
.k-modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-6); }
.k-field { display: flex; flex-direction: column; gap: 6px; margin-top: var(--sp-3); }
.k-label { font-size: var(--fs-sm); font-weight: 500; }
.k-input { width: 100%; height: 40px; padding: 0 var(--sp-3); border: 1px solid transparent; border-radius: var(--r-sm); background: var(--surface-hover); color: var(--text); font: inherit; outline: none; }
.k-textarea { height: auto; min-height: 84px; padding: var(--sp-3); resize: vertical; }
.k-input:focus { border-color: var(--link); }
.k-input.is-error { border-color: var(--danger); }
.k-btn { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 var(--sp-4); border: 0; border-radius: var(--r-pill); background: var(--surface-hover); color: var(--text); font: 500 var(--fs-md) var(--font); cursor: pointer; }
.k-btn-primary { background: var(--primary); color: var(--on-primary); }
.k-btn-primary:hover { background: var(--primary-hover); }
.k-btn-ghost { background: transparent; }
.k-btn-ghost:hover { background: var(--surface-hover); }
.k-btn-danger { background: var(--danger); color: #fff; }
.k-toast-stack { position: fixed; left: var(--sp-6); bottom: var(--sp-6); z-index: 1001; display: flex; flex-direction: column; gap: var(--sp-2); font: 400 var(--fs-md)/1.5 var(--font); }
.k-toast { min-width: 280px; max-width: 420px; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm); background: var(--text); color: var(--text-invert); box-shadow: var(--shadow-pop); }
.k-toast-error { background: var(--danger); color: #fff; }
@media (max-width: 720px) { .k-toast-stack { left: var(--sp-3); right: var(--sp-3); bottom: calc(var(--bottomnav-h) + var(--sp-3)); } }


@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
