/*
 * TopEspressoMachine UI — "mosaic"
 * Chỉ nạp ở is_front_page() và is_category() (tem_ui_assets()).
 *
 * Ngôn ngữ hình của riêng site này, cố ý khác hai site đã dựng:
 *   bestrvw  "editorial"   → bo 10px, có đổ bóng, hero ảnh lớn, mono cho số
 *   offago   "index board" → bo 2px, không card, bảng kẻ dọc, mono cho cả nhãn
 *   tem      "mosaic"      → bo 18px, KHÔNG đổ bóng, viền 2px màu theo chuyên
 *                            mục, ô lệch cỡ, số cỡ lớn in đè bằng chính font
 *                            sans của theme (không mono) — mono chỉ còn ở nhãn
 *                            siêu nhỏ.
 *
 * Màu: mỗi chuyên mục một GÓC MÀU (--tem-h, do PHP đặt inline), light/dark
 * derive từ cùng góc đó nên không có bảng màu thứ hai để lệch.
 * Theme cha bật dark bằng [data-theme="dark"] trên <html>, KHÔNG dùng
 * prefers-color-scheme — mọi khối dark ở dưới viết theo đúng selector đó.
 */

/* ==========================================================================
   Token
   ========================================================================== */

.tem {
    --tem-h: 176;                      /* góc màu mặc định, PHP ghi đè inline */

    --tem-ink: var(--color-text, #1a1d21);
    --tem-dim: var(--color-text-muted, #6b7280);
    --tem-line: var(--color-border, #e5e2dc);
    --tem-face: var(--color-surface, #fff);
    --tem-sunk: var(--color-bg-alt, #f7f5f0);

    /* Mặt ô ảnh cố định trắng ở CẢ HAI theme: ảnh Amazon là JPEG nền trắng
       đặc, đặt lên ô tối chỉ tạo ra một mảng trắng chói. Chỉ viền đổi màu. */
    --tem-plate: #fff;
    --tem-plate-line: #e6e2da;

    --tem-r: 18px;                     /* bo lớn — dấu hiệu của hướng này */
    --tem-r-sm: 10px;
    --tem-gap: 14px;
    --tem-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.tem, .tem-hue {
    --tem-c: hsl(var(--tem-h, 176) 55% 32%);
    --tem-cs: hsl(var(--tem-h, 176) 62% 96%);
    --tem-cl: hsl(var(--tem-h, 176) 40% 80%);
}

[data-theme="dark"] .tem {
    --tem-plate-line: #3a4049;
}

[data-theme="dark"] .tem,
[data-theme="dark"] .tem-hue {
    --tem-c: hsl(var(--tem-h, 176) 62% 68%);
    --tem-cs: hsl(var(--tem-h, 176) 32% 13%);
    --tem-cl: hsl(var(--tem-h, 176) 26% 32%);
}

.tem {
    color: var(--tem-ink);
    padding-bottom: var(--space-16, 4rem);
}

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

.tem-wrap {
    width: 100%;
    max-width: 1260px;
    margin: 0 auto;
    padding: 0 clamp(16px, 4vw, 32px);
}

/* Mọi con số của giao diện này */
.tem b,
.tem .tem-num,
.tem-rb,
.tem-stat b,
.tem-chip__n,
.tem-shelf__n {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* Nhãn siêu nhỏ — chỗ duy nhất còn dùng mono */
.tem-lb {
    display: inline-block;
    font-family: var(--tem-mono);
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--tem-c);
    margin: 0 0 10px;
}

/* ==========================================================================
   Masthead
   ========================================================================== */

.tem-head {
    padding: clamp(28px, 5vw, 56px) 0 clamp(20px, 3vw, 30px);
}

.tem-head h1 {
    margin: 0;
    font-size: clamp(2rem, 5.2vw, 3.4rem);
    line-height: 1.04;
    letter-spacing: -.035em;
    font-weight: 800;
    max-width: 20ch;
}

.tem-head p {
    margin: 16px 0 0;
    max-width: 62ch;
    color: var(--tem-dim);
    font-size: clamp(.95rem, 1.4vw, 1.06rem);
    line-height: 1.6;
}

.tem-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 28px;
    margin-top: 26px;
    padding-top: 18px;
    border-top: 1px solid var(--tem-line);
}

.tem-stat {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.tem-stat b {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -.02em;
}

.tem-stat span {
    font-size: .8rem;
    color: var(--tem-dim);
}

/* ==========================================================================
   Mảng khảm — lưới ô không đều
   ========================================================================== */

.tem-mosaic {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 118px;
    gap: var(--tem-gap);
}

.tem-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 2px solid var(--tem-cl);
    border-radius: var(--tem-r);
    background: var(--tem-face);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--duration-200, .2s) var(--ease-out, ease),
                transform var(--duration-200, .2s) var(--ease-out, ease);
}

.tem-tile:hover,
.tem-tile:focus-visible {
    border-color: var(--tem-c);
    transform: translateY(-2px);
}

.tem-tile--xl { grid-column: span 6; grid-row: span 4; }
.tem-tile--m  { grid-column: span 3; grid-row: span 2; }
.tem-tile--w  { grid-column: span 4; grid-row: span 2; }

/* Ô ảnh chiếm phần trên, luôn trắng */
.tem-tile__img {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--tem-plate);
    border-bottom: 1px solid var(--tem-plate-line);
}

.tem-tile__img .tem-plate,
.tem-tile__img .tem-plate img {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
}

.tem-tile__cap {
    flex: 0 0 auto;
    padding: 12px 14px 14px;
}

.tem-tile__cat {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--tem-mono);
    font-size: 10px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--tem-c);
    margin-bottom: 6px;
}

.tem-tile__t {
    margin: 0;
    font-size: .95rem;
    font-weight: 650;
    line-height: 1.3;
    letter-spacing: -.012em;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tem-tile--xl .tem-tile__cap { padding: 20px 24px 24px; }
.tem-tile--xl .tem-tile__cat { font-size: 11px; margin-bottom: 10px; }

.tem-tile--xl .tem-tile__t {
    font-size: clamp(1.25rem, 2.2vw, 1.7rem);
    font-weight: 800;
    letter-spacing: -.028em;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.tem-tile__dek {
    margin: 10px 0 0;
    font-size: .9rem;
    line-height: 1.55;
    color: var(--tem-dim);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Con số in đè — dấu hiệu thứ hai của hướng này */
.tem-rb {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 5px 10px 6px;
    border-radius: var(--tem-r-sm);
    background: var(--tem-c);
    color: #fff;
    line-height: 1;
}

[data-theme="dark"] .tem-rb {
    color: #0c0e12;
}

.tem-rb b {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -.03em;
}

.tem-rb i {
    font-size: .62rem;
    opacity: .9;
}

.tem-rb span {
    font-size: .68rem;
    opacity: .85;
    letter-spacing: .02em;
}

.tem-rb--xl {
    top: 16px;
    left: 16px;
    padding: 10px 16px 12px;
    border-radius: 14px;
}

.tem-rb--xl b { font-size: 2.1rem; }
.tem-rb--xl i { font-size: .9rem; }
.tem-rb--xl span { font-size: .78rem; }

/* Giá đặt ở góc đối diện để không đè lên số điểm */
.tem-tile__price {
    position: absolute;
    right: 10px;
    top: 10px;
    z-index: 2;
    padding: 5px 9px;
    border-radius: var(--tem-r-sm);
    background: rgba(255, 255, 255, .92);
    border: 1px solid var(--tem-plate-line);
    color: #1a1d21;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: -.01em;
}

.tem-tile--xl .tem-tile__price {
    right: 16px;
    top: 16px;
    font-size: .95rem;
    padding: 8px 12px;
}

/* ==========================================================================
   Ô ảnh dùng lại (kệ sản phẩm, dải chuyên mục)
   ========================================================================== */

.tem-plate {
    display: block;
    position: relative;
    aspect-ratio: 1;
    background: var(--tem-plate);
    border: 1px solid var(--tem-plate-line);
    border-radius: var(--tem-r-sm);
    overflow: hidden;
}

.tem-plate img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;          /* KHÔNG cover — cover cắt mất thân sản phẩm */
    padding: 8%;
}

/* Bóng ellipse mờ để ô trắng không trôi trên nền sáng */
.tem-plate::after {
    content: "";
    position: absolute;
    left: 22%;
    right: 22%;
    bottom: 7%;
    height: 7%;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, .13), transparent 72%);
    pointer-events: none;
}

/* Ô RỖNG thì KHÔNG giữ nền trắng.
   Quy tắc "ô ảnh luôn trắng ở cả hai theme" (mục 3) có lý do là ảnh Amazon
   là JPEG nền trắng đặc — không có ảnh thì lý do đó biến mất, mà cái ô vẫn
   trắng thì ở dark mode nó thành một mảng chói giữa trang tối, đúng thứ quy
   tắc kia muốn tránh. Màu icon cũng phải là token chứ không hard-code:
   #b9b4ab trên nền tối là 2.1:1, gần như không đọc được. */
.tem-plate--empty {
    display: grid;
    place-items: center;
    color: var(--tem-dim);
    font-size: 1.5rem;
    background: var(--tem-sunk);
    border-style: dashed;
}

.tem-plate--empty::after { display: none; }

/* ==========================================================================
   Dải phổ chuyên mục — mỗi chuyên mục một sắc, bề ngang theo số bài
   ========================================================================== */

.tem-sec {
    padding-top: clamp(40px, 6vw, 72px);
}

.tem-sec__hd {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.tem-sec__hd h2 {
    margin: 0;
    font-size: clamp(1.3rem, 2.6vw, 1.9rem);
    font-weight: 800;
    letter-spacing: -.03em;
}

.tem-sec__hd p {
    margin: 6px 0 0;
    color: var(--tem-dim);
    font-size: .9rem;
    max-width: 58ch;
}

.tem-spectrum {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tem-chip {
    flex: 1 1 168px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 62px;
    padding: 12px 14px;
    border-radius: var(--tem-r);
    border: 2px solid var(--tem-cl);
    background: var(--tem-cs);
    color: inherit;
    text-decoration: none;
    transition: border-color var(--duration-200, .2s) var(--ease-out, ease);
}

.tem-chip:hover,
.tem-chip:focus-visible { border-color: var(--tem-c); }

.tem-chip i {
    font-size: 1.15rem;
    color: var(--tem-c);
    flex: 0 0 auto;
}

.tem-chip__b { min-width: 0; }

.tem-chip__t {
    display: block;
    font-size: .88rem;
    font-weight: 650;
    line-height: 1.25;
    letter-spacing: -.012em;
}

.tem-chip__n {
    display: block;
    margin-top: 2px;
    font-family: var(--tem-mono);
    font-size: 10px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--tem-c);
}

/* ==========================================================================
   Kệ sản phẩm theo chuyên mục
   ========================================================================== */

.tem-shelf { margin-top: 30px; }

.tem-shelf__hd {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 10px;
    margin-bottom: 16px;
    border-bottom: 3px solid var(--tem-c);
}

.tem-shelf__hd h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 750;
    letter-spacing: -.02em;
}

.tem-shelf__hd h3 a {
    color: inherit;
    text-decoration: none;
}

.tem-shelf__hd h3 a:hover { color: var(--tem-c); }

.tem-shelf__n {
    font-family: var(--tem-mono);
    font-size: 11px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--tem-dim);
}

.tem-shelf__more {
    margin-left: auto;
    font-size: .82rem;
    font-weight: 600;
    color: var(--tem-c);
    text-decoration: none;
    white-space: nowrap;
}

.tem-shelf__more:hover { text-decoration: underline; }

.tem-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--tem-gap);
}

.tem-item {
    display: block;
    text-decoration: none;
    color: inherit;
}

.tem-item .tem-plate {
    border-color: var(--tem-cl);
    transition: border-color var(--duration-200, .2s) var(--ease-out, ease);
}

.tem-item:hover .tem-plate,
.tem-item:focus-visible .tem-plate { border-color: var(--tem-c); }

.tem-item .tem-rb {
    top: 8px;
    left: 8px;
    padding: 4px 8px 5px;
}

.tem-item .tem-rb b { font-size: .92rem; }

.tem-item__t {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 10px 0 0;
    font-size: .82rem;
    line-height: 1.35;
    font-weight: 550;
}

.tem-item__m {
    margin-top: 4px;
    font-size: .78rem;
    font-weight: 700;
    color: var(--tem-c);
}

/* ==========================================================================
   Ghi chú cuối trang
   ========================================================================== */

.tem-notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--tem-gap);
    margin-top: 22px;
}

.tem-note {
    padding: 20px 22px;
    border: 1px solid var(--tem-line);
    border-radius: var(--tem-r);
    background: var(--tem-sunk);
}

.tem-note h4 {
    margin: 0 0 8px;
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: -.015em;
}

.tem-note p {
    margin: 0;
    font-size: .86rem;
    line-height: 1.6;
    color: var(--tem-dim);
}

/* ==========================================================================
   Trang chuyên mục
   ========================================================================== */

.tem-cathead {
    margin-top: clamp(18px, 3vw, 30px);
    padding: clamp(24px, 4vw, 44px) clamp(20px, 4vw, 44px);
    border: 2px solid var(--tem-cl);
    border-radius: var(--tem-r);
    background: var(--tem-cs);
}

.tem-cathead__crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--tem-mono);
    font-size: 11px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--tem-c);
    margin-bottom: 12px;
}

.tem-cathead__crumb a {
    color: inherit;
    text-decoration: none;
}

.tem-cathead__crumb a:hover { text-decoration: underline; }

.tem-cathead h1 {
    margin: 0;
    font-size: clamp(1.9rem, 5vw, 3.1rem);
    line-height: 1.05;
    letter-spacing: -.035em;
    font-weight: 800;
}

.tem-cathead p {
    margin: 14px 0 0;
    max-width: 64ch;
    color: var(--tem-dim);
    font-size: .98rem;
    line-height: 1.6;
}

.tem-cathead .tem-stats { border-top-color: var(--tem-cl); }

/* Dải sản phẩm đứng đầu chuyên mục */
.tem-strip {
    margin-top: 26px;
}

.tem-strip .tem-row {
    grid-template-columns: repeat(5, 1fr);
}

/* Lưới guide — ô lệch cỡ theo chu kỳ 6/3/3 · 4/4/4 do PHP đặt class */
.tem-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 118px;
    gap: var(--tem-gap);
    margin-top: 18px;
}

/* Điều hướng cuối trang */
.tem-tail {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: clamp(24px, 4vw, 48px);
    margin-top: clamp(36px, 5vw, 60px);
    padding-top: clamp(26px, 4vw, 40px);
    border-top: 1px solid var(--tem-line);
}

.tem-tail h2 {
    margin: 0 0 14px;
    font-size: 1.1rem;
    font-weight: 750;
    letter-spacing: -.02em;
}

.tem-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tem-list li {
    border-bottom: 1px solid var(--tem-line);
}

.tem-list li:last-child { border-bottom: 0; }

.tem-list a {
    display: block;
    padding: 11px 0;
    font-size: .9rem;
    line-height: 1.4;
    font-weight: 550;
    color: inherit;
    text-decoration: none;
}

.tem-list a:hover { color: var(--tem-c); }

/* Phân trang */
.tem-pager {
    margin-top: 30px;
    display: flex;
    justify-content: center;
}

.tem-pager .page-numbers {
    display: inline-block;
    min-width: 40px;
    padding: 9px 12px;
    margin: 0 4px;
    text-align: center;
    border: 1px solid var(--tem-line);
    border-radius: var(--tem-r-sm);
    font-size: .86rem;
    font-weight: 650;
    color: inherit;
    text-decoration: none;
    font-variant-numeric: tabular-nums;
}

.tem-pager .page-numbers:hover { border-color: var(--tem-c); color: var(--tem-c); }

.tem-pager .page-numbers.current {
    background: var(--tem-c);
    border-color: var(--tem-c);
    color: #fff;
}

[data-theme="dark"] .tem-pager .page-numbers.current { color: #0c0e12; }

.tem-empty {
    margin-top: 24px;
    padding: 40px 24px;
    text-align: center;
    color: var(--tem-dim);
    border: 1px dashed var(--tem-line);
    border-radius: var(--tem-r);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1080px) {
    .tem-mosaic,
    .tem-grid { grid-template-columns: repeat(6, 1fr); }

    .tem-tile--xl { grid-column: span 6; grid-row: span 4; }
    .tem-tile--m  { grid-column: span 3; grid-row: span 2; }
    .tem-tile--w  { grid-column: span 2; grid-row: span 2; }

    .tem-row { grid-template-columns: repeat(4, 1fr); }
    .tem-row > *:nth-child(5) { display: none; }

    .tem-notes { grid-template-columns: 1fr; }
    .tem-tail { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .tem { --tem-gap: 10px; }

    .tem-mosaic,
    .tem-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 104px;
    }

    .tem-tile--xl { grid-column: span 2; grid-row: span 4; }
    .tem-tile--m,
    .tem-tile--w  { grid-column: span 1; grid-row: span 3; }

    .tem-row { grid-template-columns: repeat(2, 1fr); }
    .tem-row > *:nth-child(n+5) { display: none; }

    .tem-chip { flex: 1 1 140px; }
}

@media (prefers-reduced-motion: reduce) {
    .tem-tile,
    .tem-chip,
    .tem-item .tem-plate { transition: none; }

    .tem-tile:hover { transform: none; }
}
