/* =====================================================================
   Hồ sơ sức khỏe — stylesheet chính
   Mobile-first, CSS3 thuần, không framework.
   ===================================================================== */

:root {
    --primary:        #35ada8;
    --primary-dark:   #2b938f;
    --primary-light:  #dff5f3;
    --text:           #222222;
    --text-light:     #9b9b9b;
    --background:     #f5f6f6;
    --white:          #ffffff;
    --border:         #dddddd;

    --card-bg:        #f4f5f5;
    --hairline:       #ececec;
    --gold:           #d8b571;

    --radius:         10px;
    --radius-lg:      12px;
    --app-width:      430px;
    --nav-height:     64px;
}

/* ------------------------------- Reset ------------------------------ */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    color: var(--text);
    background: #e9e9e9;                    /* nền desktop bên ngoài "điện thoại" */
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

a { color: inherit; text-decoration: none; }

button { font: inherit; }

/* --------------------------- App container -------------------------- */

.app {
    position: relative;
    width: 100%;
    max-width: var(--app-width);
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    background: var(--white);
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

@media (min-width: 480px) {
    .app { box-shadow: 0 0 24px rgba(0, 0, 0, .12); }
}

.app__main { flex: 1 0 auto; }

/* Chừa chỗ cho thanh điều hướng dưới cùng */
.app--hasnav .app__main { padding-bottom: calc(var(--nav-height) + 16px); }

/* ------------------------------ Icons ------------------------------- */

.ico {
    width: 24px;
    height: 24px;
    display: block;
    flex: 0 0 auto;
}

.ico--back        { width: 26px; height: 26px; stroke-width: 2; }
.ico--action      { width: 22px; height: 22px; color: var(--text-light); }
.ico--filter      { width: 20px; height: 20px; color: var(--text-light); }
.ico--selectarrow { width: 18px; height: 18px; color: var(--primary-dark); }
.ico--star        { width: 25px; height: 25px; color: #d8d8d8; fill: #d8d8d8; stroke-width: 1; }
.ico--card        { width: 24px; height: 24px; }
.ico--arrow       { width: 20px; height: 20px; }
.ico--nav         { width: 21px; height: 21px; color: var(--text); }
.ico--field       { width: 20px; height: 20px; color: var(--text-light); }
.ico--logo        { width: 34px; height: 34px; color: var(--white); }

/* ------------------------------ Topbar ------------------------------ */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    height: 56px;
    padding: 0 14px;
    background: var(--white);
}

.topbar__back,
.topbar__action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 50%;
}

.topbar__back:active,
.topbar__action:active { background: var(--background); }

.topbar__back--empty,
.topbar__action--empty { pointer-events: none; }

.topbar__title {
    flex: 1 1 auto;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: .1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ------------------------------- Tabs ------------------------------- */

.tabs {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    padding: 2px 10px 10px;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs__item {
    flex: 0 0 auto;
    padding: 9px 11px;
    border-radius: 9px;
    font-size: 14.5px;
    font-weight: 500;
    color: #4a4a4a;
    white-space: nowrap;
    transition: background .15s ease, color .15s ease;
}

.tabs__item.is-active {
    background: var(--primary);
    color: var(--white);
    font-weight: 600;
}

/* ---------------------------- Filter bar ---------------------------- */

.filterbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 16px 14px;
    background: var(--white);
}

.filterbar__label {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 15.5px;
    color: var(--text);
}

.filterbar__select {
    position: relative;
    display: inline-flex;
    align-items: center;
    background: var(--primary-light);
    border-radius: 8px;
    padding: 0 30px 0 14px;
    height: 38px;
}

.filterbar__select select {
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: transparent;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-dark);
    padding: 0;
    height: 100%;
    cursor: pointer;
    outline: none;
}

.filterbar__select .ico--selectarrow {
    position: absolute;
    right: 8px;
    pointer-events: none;
}

.filterbar__go {
    border: 0;
    background: var(--primary);
    color: var(--white);
    border-radius: 8px;
    padding: 9px 14px;
    cursor: pointer;
}

/* --------------------------- Timeline list -------------------------- */

.timeline {
    background: var(--background);
    border-top: 1px solid var(--hairline);
}

.record {
    display: flex;
    gap: 2px;
    padding: 16px 16px 14px;
    background: var(--white);
    margin-bottom: 7px;                      /* tạo dải ngăn cách màu xám */
}

.record:last-child { margin-bottom: 0; }

.record__date {
    flex: 0 0 68px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding-top: 2px;
}

.record__month {
    font-size: 13.5px;
    font-weight: 500;
    color: #8fd3cf;
    letter-spacing: .2px;
}

.record__day {
    font-size: 27px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--primary-dark);
}

.record__body {
    flex: 1 1 auto;
    min-width: 0;
    border-left: 1px solid #e4e4e4;
    padding-left: 14px;
}

.record__card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 13px 12px;
    min-height: 66px;
}

.record__text { flex: 1 1 auto; min-width: 0; }

.record__title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
}

.record__doctor {
    margin-top: 3px;
    font-size: 14.5px;
    color: var(--text-light);
}

.record__star { display: flex; flex: 0 0 auto; }

.record__link {
    display: inline-block;
    margin-top: 11px;
    font-size: 15.5px;
    font-weight: 500;
    color: var(--primary);
}

.record__link:active { opacity: .6; }

/* ----------------------- Patient header block ----------------------- */

.patient {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 16px 18px;
    background: var(--white);
}

.patient__info { min-width: 0; }

.patient__name {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: .3px;
    line-height: 1.3;
}

.patient__meta {
    margin-top: 2px;
    font-size: 15px;
    color: var(--text-light);
}

.patient__dept {
    margin-top: 2px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.patient__code {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding-top: 2px;
}

.barcode {
    width: 132px;
    height: 46px;
    fill: #1a1a1a;
}

.patient__code-text {
    font-size: 14.5px;
    color: var(--text);
    letter-spacing: .4px;
}

/* --------------------------- Menu cards ----------------------------- */

.menu {
    background: var(--background);
    padding: 14px 14px 4px;
    border-top: 1px solid var(--hairline);
}

.menucard {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 76px;
    padding: 7px 14px;
    margin-bottom: 14px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
    transition: background .15s ease;
}

/* Icon PNG của 3 mục menu — dùng đúng file ảnh gốc, nền PNG trong suốt,
   không thêm background, không filter đổi màu, giữ tỉ lệ bằng object-fit */
.health-menu-icon {
    width: 62px;
    height: 62px;
    object-fit: contain;
    flex-shrink: 0;
    display: block;
    background: none;
}

.menucard__label {
    flex: 1 1 auto;
    font-size: 16.5px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.menucard__arrow { color: #b6b6b6; display: flex; }

/* Mục đang mở */
.menucard--active {
    background: var(--primary);
    box-shadow: none;
}

.menucard--active .menucard__label { color: var(--white); }
.menucard--active .menucard__arrow { color: var(--white); }

/* --------------------------- Lab results ---------------------------- */

.labs {
    background: var(--white);
    padding: 12px 16px 24px;
}

.labs__heading {
    font-size: 21px;
    font-weight: 700;
    margin-bottom: 14px;
}

.labs__group {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    margin: 18px 0 9px;
}

.labs__group:first-of-type { margin-top: 4px; }

/* ---------------------------------------------------------------------
   BẢNG KẾT QUẢ XÉT NGHIỆM — RESPONSIVE
   Một cấu trúc HTML duy nhất, CSS đổi cách trình bày theo bề ngang:
     >= 601px : CSS Grid 4 cột  -> bảng Dịch vụ | KQ | Tham chiếu | ĐV
     <= 600px : 1 group = 1 card lớn, mỗi chỉ số là 1 item nhãn - giá trị
   --------------------------------------------------------------------- */

/* ----- Desktop / tablet lớn (mặc định) ----- */

.labtable {
    display: grid;
    /*
     * 4 cột chia theo tỉ lệ (không dùng auto/max-content):
     * cột nào cũng có min = 0 và nội dung tự xuống dòng bên trong cột của nó,
     * nên kết quả dạng chữ dài không bao giờ tràn đè sang cột bên cạnh.
     * "Âm tính/Negative" sẽ tự ngắt sau dấu "/" -> "Âm tính/" + "Negative".
     */
    grid-template-columns:
        minmax(0, 1.3fr)    /* Dịch vụ    */
        minmax(0, 1fr)      /* KQ         */
        minmax(0, 1fr)      /* Tham chiếu */
        minmax(0, 0.7fr);   /* ĐV         */
    border: 1px solid #e0e0e0;
    border-radius: var(--radius);
    overflow: hidden;
}

.labtable__row { display: contents; }

.labtable__c {
    display: flex;
    align-items: center;          /* căn giữa dọc, đường kẻ vẫn thẳng hàng */
    min-width: 0;
    padding: 13px 5px;
    font-size: 14.5px;
    line-height: 1.4;
    color: var(--text);
    /*
     * anywhere: ưu tiên ngắt ở khoảng trắng / dấu "/" như bình thường,
     * chỉ cắt giữa từ khi thật sự không còn cách nào -> không bao giờ tràn cột.
     */
    overflow-wrap: anywhere;
    word-break: normal;
}

.labtable__c--name { padding-left: 11px; }
.labtable__c--unit { padding-right: 11px; }

.labtable__c--val,
.labtable__c--ref,
.labtable__c--unit { justify-content: flex-end; text-align: right; }

/* Giữ nguyên xuống dòng admin đã nhập cho phần tham chiếu */
.labtable__c--ref { white-space: pre-line; }

/* Đường kẻ giữa các dòng */
.labtable__row + .labtable__row > .labtable__c { border-top: 1px solid #ededed; }

.labtable__row--head > .labtable__c { font-weight: 700; font-size: 14.5px; }
.labtable__row--head + .labtable__row > .labtable__c { border-top-color: #e0e0e0; }

/* ----- Mobile: chuyển bảng thành card list ----- */

@media (max-width: 600px) {

    .labs__group {
        font-size: 18px;
        font-weight: 600;
        margin: 22px 0 12px;
    }

    .labs__group:first-of-type { margin-top: 6px; }

    .labtable {
        display: block;                 /* thoát khỏi lưới 4 cột */
        background: var(--white);
        border: 1px solid #e1e1e1;
        border-radius: 12px;
        overflow: hidden;
    }

    /* 1 group = 1 card lớn, mỗi chỉ số là 1 item ngăn nhau bằng 1 đường line */
    .labtable__row {
        display: block;
        padding: 15px 16px;
        border-bottom: 1px solid #eeeeee;
    }

    .labtable__row:last-child { border-bottom: 0; }

    /* Hàng tiêu đề của bảng không cần trên mobile (đặt sau để ghi đè display:block) */
    .labtable > .labtable__row--head { display: none; }

    /* Dòng nhãn - giá trị */
    .labtable__c {
        display: grid;
        grid-template-columns: 95px minmax(0, 1fr);
        gap: 8px;
        align-items: start;
        padding: 3px 0;
        border-top: 0 !important;       /* bỏ đường kẻ của layout bảng */
        text-align: left;
        justify-content: stretch;
        font-size: 15px;
        line-height: 1.45;
        color: #111111;
        overflow-wrap: anywhere;
        word-break: normal;
    }

    /* Nhãn KQ / THAM CHIẾU / ĐƠN VỊ sinh từ data-label (không lặp text trong HTML) */
    .labtable__c::before {
        content: attr(data-label);
        font-size: 13px;
        font-weight: 600;
        line-height: 1.5;
        letter-spacing: .2px;
        text-transform: uppercase;
        color: #b2b2b2;
    }

    /* Tên xét nghiệm nằm trên cùng, chiếm trọn chiều ngang, được phép xuống dòng */
    .labtable__c--name {
        display: block;
        padding: 0 0 12px;
        font-size: 16px;
        font-weight: 600;
        line-height: 1.4;
        color: #111111;
    }

    .labtable__c--name::before { content: none; }

    /* Đơn vị rỗng hoặc "-" -> PHP gắn class này, mobile ẩn hẳn dòng ĐƠN VỊ */
    .labtable__c--nomobile { display: none; }
}

/* Màn hình rất hẹp: thu gọn cột nhãn */
@media (max-width: 340px) {
    .labtable__row { padding: 14px 12px; }
    .labtable__c   { grid-template-columns: 88px minmax(0, 1fr); gap: 7px; font-size: 14.5px; }
    .labtable__c--name { font-size: 15.5px; }
}

/* ------------------------- Empty / alert ---------------------------- */

.empty {
    padding: 30px 18px;
    text-align: center;
    font-size: 15px;
    color: var(--text-light);
    background: var(--white);
}

.empty--inline {
    background: transparent;
    padding: 6px 4px 16px;
    text-align: left;
}

.alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: #fdecec;
    border: 1px solid #f4c7c7;
    color: #b3261e;
    font-size: 14.5px;
}

/* -------------------------- Bottom nav ------------------------------ */

.bottomnav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--app-width);
    height: var(--nav-height);
    display: flex;
    align-items: center;
    background: var(--white);
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 30;
}

.bottomnav::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #f0dfba 0%, var(--gold) 50%, #f0dfba 100%);
}

.bottomnav__item {
    flex: 1 1 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    height: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: .2px;
    cursor: pointer;
}

.bottomnav__item:active { background: var(--background); }

/* Màn hình rất hẹp: thu gọn thanh điều hướng + tên bệnh nhân */
@media (max-width: 600px) {
    .health-menu-icon { width: 58px; height: 58px; }
}

@media (max-width: 359px) {
    .bottomnav__item { font-size: 12.5px; gap: 7px; }
    .health-menu-icon { width: 52px; height: 52px; }
    .patient__name   { font-size: 17px; }
    .barcode         { width: 112px; height: 42px; }
    .menucard__label { font-size: 15.5px; }
}

/* ----------------------------- Login -------------------------------- */

.app--login { background: var(--white); }

.login {
    padding: 42px 24px 30px;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 40px);
}

.login__brand {
    text-align: center;
    margin-bottom: 30px;
}

.login__logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 66px;
    height: 66px;
    border-radius: 22px;
    background: var(--primary);
    margin-bottom: 14px;
    box-shadow: 0 6px 16px rgba(53, 173, 168, .3);
}

.login__title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text);
}

.login__subtitle {
    margin-top: 6px;
    font-size: 14.5px;
    color: var(--text-light);
}

.login__form { display: flex; flex-direction: column; gap: 16px; }

.field { display: block; }

.field__label {
    display: block;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 7px;
}

.field__control {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 50px;
    padding: 0 14px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color .15s ease, background .15s ease;
}

.field__control:focus-within {
    border-color: var(--primary);
    background: var(--white);
}

.field__control input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    font-size: 16px;
    color: var(--text);
}

.field__control input::placeholder { color: #b5b5b5; }

.btn {
    display: block;
    width: 100%;
    border: 0;
    border-radius: var(--radius);
    padding: 15px 16px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .6px;
    cursor: pointer;
}

.btn--primary {
    margin-top: 6px;
    background: var(--primary);
    color: var(--white);
    box-shadow: 0 4px 12px rgba(53, 173, 168, .28);
}

.btn--primary:active { background: var(--primary-dark); }

.login__hint {
    margin-top: auto;
    padding-top: 26px;
    text-align: center;
    font-size: 13.5px;
    color: var(--text-light);
}
