/* ==========================================================
   CHADWAR — "Newsprint" zagvar
   Sonin sethuuliin harandaa: huits bulan, serif garchig,
   har/tsagaan, hurээ bur ni haragdana.
   Comment ni Mongol ug, Latin usegeer.
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Playfair+Display:ital,wght@0,400;0,700;0,900;1,400&family=Lora:ital,wght@0,400;0,600;1,400&display=swap');

/* ---- 1. Undsen utguud (CSS custom property) --------------
   Newsprint-d ongo ni gants: har beh, tsaasnii tsagaan, ba
   MASH hyzgaartai улаан. Улааныг zovhon "yaaraltai" zuild. */
:root {
    --ink: #111111;
    /* beh - buh tekst ba hurээ */
    --paper: #f9f9f7;
    /* tsaas - dulaahan tsagaan */
    --divider: #e5e5e0;
    /* zoolon хуваалт */
    --red: #cc0000;
    /* zovhon oncholohod */
    --grey-100: #f5f5f5;
    --grey-200: #e5e5e5;
    --grey-500: #737373;
    /* meta tekst */
    --grey-700: #404040;

    /* Newsprint-d bulan UGUI. Ene hувьсагч ni "0" hevээrээ. */
    --radius: 0;
    --page: 1180px;
    --fast: 0.2s ease-out;

    --f-head: 'Playfair Display', 'Times New Roman', serif;
    --f-body: 'Lora', Georgia, serif;
    --f-ui: 'Inter', 'Helvetica Neue', sans-serif;
    --f-mono: 'JetBrains Mono', 'Courier New', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Butun sait deer bulan tsegtsleh - ene bol Newsprint-iin gol duram */
    border-radius: var(--radius);
}

/* Tsaasnii butsarhai - 4x4px tsegen hee.
   Ene ni "hawtgai web" gej haragdahaas hamgaalna. */
body {
    font-family: var(--f-body);
    color: var(--ink);
    background-color: var(--paper);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Cpath fill='%23111111' fill-opacity='0.04' d='M1 3h1v1H1V3zm2-2h1v1H3V1z'%3E%3C/path%3E%3C/svg%3E");
    line-height: 1.6;
}

img {
    display: block;
    max-width: 100%;
    /* Sonin deerh zurag shig - bugd saaral */
    filter: grayscale(1);
}

.wrap {
    width: 100%;
    max-width: var(--page);
    margin: 0 auto;
    padding: 0 1rem;
}

/* ---- 2. Animation --------------------------------------- */
@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sonin deerh "yaaraltai medee" gulguur bichig */
@keyframes ticker {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

/* ---- 3. Masthead (soninii toloi hesg) --------------------
   Deed tald ni hevleliin medeelel: Vol, ognoo, hevlel. */
.masthead {
    border-bottom: 1px solid var(--ink);
    background: var(--paper);
}

.masthead-meta {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-width: var(--page);
    margin: 0 auto;
    padding: 0.4rem 1rem;
    border-bottom: 1px solid var(--divider);

    font-family: var(--f-mono);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--grey-500);
}

/* Flexbox: logo golduu, tses hoyor tald */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    max-width: var(--page);
    margin: 0 auto;
    padding: 1rem;

    & .logo {
        font-family: var(--f-head);
        font-weight: 900;
        font-size: 1.9rem;
        letter-spacing: -0.02em;
        color: var(--ink);
        text-decoration: none;
    }

    & nav {
        display: flex;
        gap: 1.25rem;
        flex: 1;

        & a {
            font-family: var(--f-ui);
            font-size: 0.7rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.15em;
            color: var(--ink);
            text-decoration: none;
            transition: color var(--fast);

            /* Newsprint: hover deer улаан bolno */
            &:hover {
                color: var(--red);
            }
        }
    }

    & .auth {
        display: flex;
        align-items: center;
        gap: 0.9rem;
        font-family: var(--f-ui);
        font-size: 0.75rem;

        /* :not(.btn) — esreg toholdold ene durem ni .btn-iin
           tsagaan usgiig darj, har deer har bolgoj haragdahaa
           bolino. Tovchiig ontsguuleh heregtei. */
        & a:not(.btn) {
            color: var(--ink);
            text-decoration: none;
        }
    }
}

/* ---- 4. Tovchnuud ---------------------------------------
   Undsen tovch: har dewsger, tsagaan useg. Hover deer
   BUTSAAD hoprogdno - tsagaan dewsger, har useg. */
.btn {
    display: inline-block;
    min-height: 44px;
    /* gar utsand daragdahad hangalttai */
    padding: 0.7rem 1.4rem;

    background: var(--ink);
    color: var(--paper);
    border: 1px solid var(--ink);

    font-family: var(--f-ui);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--fast), color var(--fast);

    &:hover {
        background: var(--paper);
        color: var(--ink);
    }
}

/* ---- 5. Hero — soninii negduger nuur --------------------- */
.hero {
    border-bottom: 4px solid var(--ink);
    padding: 3rem 1rem 2.5rem;
    text-align: center;

    & h1 {
        font-family: var(--f-head);
        font-weight: 900;
        /* Asar tom garchig - delgetsees hamaarch oorchlogdno */
        font-size: clamp(2.6rem, 7vw, 5.5rem);
        line-height: 0.95;
        letter-spacing: -0.03em;
        max-width: 16ch;
        margin: 0 auto 1rem;

        & span {
            font-style: italic;
        }
    }

    & .lede {
        font-size: 1.05rem;
        color: var(--grey-700);
        max-width: 54ch;
        margin: 0 auto 1.75rem;
    }
}

/* Hailt - hurээtei, bulan-gui */
.search {
    display: flex;
    max-width: 520px;
    margin: 0 auto;
    border: 1px solid var(--ink);

    & input {
        flex: 1;
        border: none;
        background: transparent;
        padding: 0.8rem 1rem;
        font-family: var(--f-mono);
        font-size: 0.85rem;
        outline: none;

        &:focus {
            background: var(--grey-100);
        }
    }

    & button {
        border: none;
        border-left: 1px solid var(--ink);
    }
}

.stats {
    margin-top: 1rem;
    font-family: var(--f-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--grey-500);
}

/* ---- 6. Gulguur medee (ticker) ---------------------------
   Har zurvas deer tsagaan bichig, sonin shig urshdag. */
.ticker {
    overflow: hidden;
    background: var(--ink);
    color: var(--paper);
    border-bottom: 1px solid var(--ink);

    & div {
        display: flex;
        width: max-content;
        /* 2 udaa davtsan tul tasraltgui erguuldeg harаgdana */
        animation: ticker 28s linear infinite;
    }

    & span {
        padding: 0.5rem 1.5rem;
        font-family: var(--f-mono);
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.15em;
        white-space: nowrap;
    }

    /* Улаан "яаралтай" temdeg */
    & b {
        color: var(--red);
    }
}

/* Hodolgoon bolihiig husegch hereglegchid hundetgel uzuulne */
@media (prefers-reduced-motion: reduce) {
    .ticker div {
        animation: none;
    }
}

/* ---- 7. Angilaliin shugam -------------------------------- */
.chips {
    display: flex;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--ink);
    margin-top: 2rem;

    & button {
        background: transparent;
        border: none;
        /* Hurээ ni zovhon baruun taldaa - grid shig nairuulna */
        border-right: 1px solid var(--ink);
        padding: 0.7rem 1.1rem;
        min-height: 44px;

        font-family: var(--f-ui);
        font-size: 0.68rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        cursor: pointer;
        transition: background var(--fast), color var(--fast);

        &:hover {
            background: var(--grey-100);
        }

        /* Songogdson angilal - hartai bolno */
        &.active {
            background: var(--ink);
            color: var(--paper);
        }
    }
}

/* ---- 8. Eremdeh mor ------------------------------------- */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--ink);

    font-family: var(--f-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--grey-500);

    & select {
        border: 1px solid var(--ink);
        background: var(--paper);
        padding: 0.4rem 0.6rem;
        font-family: var(--f-mono);
        font-size: 0.7rem;
        cursor: pointer;
    }
}

/* ---- 9. Uilchilgeenii bagana (card) ---------------------
   Sonin shig: hurээnuud ni hoorondoo nийлж, davhar shugam
   uusgehgui. Tiimees zovhon baruun ba dood hurээ ogno. */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    /* gap UGUI - baganuud hoorondoo shuud naaltsana */
    border-left: 1px solid var(--ink);
    margin-bottom: 3rem;
}

.card {
    border-right: 1px solid var(--ink);
    border-bottom: 1px solid var(--ink);
    background: var(--paper);
    animation: fade-up 0.3s ease-out;
    transition: background var(--fast);

    &:hover {
        background: var(--grey-100);
    }

    & a {
        display: block;
        color: inherit;
        text-decoration: none;
        padding: 1.1rem;
    }
}

/* Zurgiin oron - halftone (hevlelийн tseguud) */
.thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    margin-bottom: 0.9rem;
    border: 1px solid var(--ink);

    font-size: 2.4rem;
    /* Emoji-g ch saaral bolgono - sonin deer ongo baihgui */
    filter: grayscale(1);

    background-color: var(--grey-200);
    background-image: radial-gradient(var(--ink) 1px, transparent 1px);
    background-size: 8px 8px;
}

.card-body {
    & .cat {
        font-family: var(--f-mono);
        font-size: 0.6rem;
        text-transform: uppercase;
        letter-spacing: 0.2em;
        color: var(--red);
        padding-bottom: 0.4rem;
        margin-bottom: 0.5rem;
        border-bottom: 1px solid var(--divider);
    }

    & h3 {
        font-family: var(--f-head);
        font-weight: 700;
        font-size: 1.15rem;
        line-height: 1.2;
        margin-bottom: 0.4rem;
    }

    & .seller {
        font-family: var(--f-ui);
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        color: var(--grey-500);
    }

    & .rating {
        font-family: var(--f-mono);
        font-size: 0.72rem;
        margin-top: 0.5rem;
    }

    & .price {
        font-family: var(--f-mono);
        font-weight: 500;
        font-size: 1rem;
        margin-top: 0.6rem;
        padding-top: 0.6rem;
        border-top: 1px solid var(--ink);
    }
}

.empty {
    grid-column: 1 / -1;
    border-right: 1px solid var(--ink);
    border-bottom: 1px solid var(--ink);
    padding: 3rem 1rem;
    text-align: center;
    font-style: italic;
    color: var(--grey-500);
}

/* Chimeglelt хуваалт - sonin deerh odnuud */
.ornament {
    padding: 2rem 0;
    text-align: center;
    font-family: var(--f-head);
    font-size: 1.1rem;
    letter-spacing: 1em;
    color: var(--grey-500);
}

/* ---- 10. Delgerengui huudas ----------------------------
   Tenkhlegtei bish 8/4 хуваалт - sonin shig. */
.detail {
    display: grid;
    grid-template-columns: 2fr 1fr;
    border-left: 1px solid var(--ink);
    border-top: 1px solid var(--ink);
    margin: 2rem 0 3rem;
}

.detail-main {
    border-right: 1px solid var(--ink);
    border-bottom: 1px solid var(--ink);
    padding: 1.75rem;

    & .thumb {
        height: 200px;
        font-size: 3.5rem;
    }

    & h1 {
        font-family: var(--f-head);
        font-weight: 900;
        font-size: clamp(1.8rem, 4vw, 2.8rem);
        line-height: 1.05;
        letter-spacing: -0.02em;
        margin-bottom: 0.6rem;
    }

    & .meta {
        font-family: var(--f-mono);
        font-size: 0.68rem;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        color: var(--grey-500);
        padding-bottom: 1rem;
        margin-bottom: 1.25rem;
        border-bottom: 1px solid var(--ink);
    }

    /* Sonin shig hoyor talaaraa teguust bichleg */
    & .body-text {
        text-align: justify;
        font-size: 1rem;

        /* Ehnii useg ni TOM - sonin sethuuliin uev yos */
        &::first-letter {
            float: left;
            font-family: var(--f-head);
            font-weight: 900;
            font-size: 3.6rem;
            line-height: 0.8;
            padding: 0.1em 0.12em 0 0;
        }
    }
}

.buy-box {
    border-right: 1px solid var(--ink);
    border-bottom: 1px solid var(--ink);
    padding: 1.5rem;
    height: fit-content;

    & .big-price {
        font-family: var(--f-mono);
        font-weight: 500;
        font-size: 1.9rem;
        padding-bottom: 0.75rem;
        border-bottom: 4px solid var(--ink);
    }

    & ul {
        list-style: none;
        margin: 1rem 0 1.25rem;
        font-family: var(--f-ui);
        font-size: 0.78rem;

        & li {
            padding: 0.5rem 0;
            border-bottom: 1px solid var(--divider);
        }
    }

    & .btn {
        width: 100%;
        text-align: center;
    }
}

/* ---- 11. Zahialgiin huudas ----------------------------- */
.order {
    max-width: 560px;
    margin: 2rem auto 3rem;
}

.box {
    border: 1px solid var(--ink);
    padding: 1.75rem;
    background: var(--paper);
    animation: fade-up 0.3s ease-out;

    & h1 {
        font-family: var(--f-head);
        font-weight: 900;
        font-size: 1.7rem;
        line-height: 1.1;
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
        border-bottom: 4px solid var(--ink);
    }
}

.row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--divider);
    font-family: var(--f-ui);
    font-size: 0.85rem;

    /* Niit dun - ontsgoi tomruun, buden hurээtei */
    &.total {
        border-bottom: none;
        border-top: 2px solid var(--ink);
        margin-top: 0.4rem;
        padding-top: 0.75rem;
        font-family: var(--f-mono);
        font-weight: 500;
        font-size: 1.1rem;
    }
}

/* Form - zovhon dood hurээtei input (Newsprint-iin zagvar) */
.form {
    display: grid;
    gap: 1.1rem;
    margin-top: 1.25rem;

    & label {
        display: grid;
        gap: 0.35rem;
        font-family: var(--f-ui);
        font-size: 0.68rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.12em;
    }

    & input,
    & textarea {
        border: none;
        border-bottom: 2px solid var(--ink);
        background: transparent;
        padding: 0.6rem 0.2rem;
        font-family: var(--f-mono);
        font-size: 0.85rem;
        outline: none;
        transition: background var(--fast);

        &:focus {
            background: #f0f0f0;
        }
    }
}

.ok {
    text-align: center;

    & .tick {
        font-family: var(--f-head);
        font-size: 3rem;
        filter: grayscale(1);
    }

    & h1 {
        border-bottom: none;
    }
}

/* ---- 12. Nevtreh / burtguuleh -------------------------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--ink);
    padding: 2rem;
    background: var(--paper);
    animation: fade-up 0.3s ease-out;

    & h1 {
        font-family: var(--f-head);
        font-weight: 900;
        font-size: 1.8rem;
        padding-bottom: 0.75rem;
        margin-bottom: 1.25rem;
        border-bottom: 4px solid var(--ink);
    }

    & .btn {
        width: 100%;
        text-align: center;
        margin-top: 0.5rem;
    }

    & .small {
        margin-top: 1rem;
        font-family: var(--f-ui);
        font-size: 0.75rem;
        color: var(--grey-500);
        text-align: center;

        & a {
            color: var(--ink);
            text-decoration: underline;
            text-decoration-color: var(--red);
            text-decoration-thickness: 2px;
            text-underline-offset: 3px;
        }
    }
}

.msg {
    min-height: 1.2rem;
    margin-top: 0.6rem;
    font-family: var(--f-mono);
    font-size: 0.75rem;
    color: var(--red);
}

/* ---- 13. Hodolgoortoi hesg (footer) -------------------- */
.foot {
    border-top: 4px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    text-align: center;
    padding: 2rem 1rem;
    font-family: var(--f-mono);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
}

/* ---- 14. Egune AI tuslah tsonh ------------------------- */
.chat-btn {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: 3.25rem;
    height: 3.25rem;
    min-height: 44px;

    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    font-size: 1.2rem;
    cursor: pointer;
    transition: background var(--fast), color var(--fast), box-shadow var(--fast), transform var(--fast);

    /* Newsprint-iin "hatuu suuder" - zoolon biш, hurts */
    &:hover {
        background: var(--paper);
        color: var(--ink);
        box-shadow: 4px 4px 0 0 var(--ink);
        transform: translate(-2px, -2px);
    }
}

.chat-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 5rem;
    width: 330px;
    height: 430px;

    border: 1px solid var(--ink);
    background: var(--paper);
    box-shadow: 6px 6px 0 0 var(--ink);

    display: none;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;

    &.open {
        display: grid;
        animation: fade-up 0.25s ease-out;
    }

    & header {
        background: var(--ink);
        color: var(--paper);
        padding: 0.7rem 1rem;
        font-family: var(--f-mono);
        font-size: 0.65rem;
        text-transform: uppercase;
        letter-spacing: 0.18em;
    }
}

.chat-list {
    padding: 0.9rem;
    overflow-y: auto;
    font-size: 0.85rem;
}

.chat-line {
    margin-bottom: 0.7rem;
    padding: 0.5rem 0.7rem;
    max-width: 88%;
    white-space: pre-wrap;
    border: 1px solid var(--ink);

    /* Hereglegchiin asuult - hartai, baruun tald */
    &.me {
        margin-left: auto;
        background: var(--ink);
        color: var(--paper);
        font-family: var(--f-ui);
    }

    /* AI-iin hariu - tsaasan deer beh */
    &.ai {
        background: var(--paper);
        font-family: var(--f-body);
    }
}

.chat-form {
    display: flex;
    gap: 0.4rem;
    padding: 0.6rem;
    border-top: 1px solid var(--ink);

    & input {
        flex: 1;
        border: none;
        border-bottom: 2px solid var(--ink);
        background: transparent;
        padding: 0.45rem 0.2rem;
        font-family: var(--f-mono);
        font-size: 0.8rem;
        outline: none;

        &:focus {
            background: var(--grey-100);
        }
    }

    & button {
        padding: 0.45rem 0.9rem;
        min-height: 40px;
    }
}

/* ---- 15. Гар утас (media query) ------------------------
   Sonin shig harandaagaа hadgalna - zovhon 1 bagana bolno,
   босоо hurээ alga bolno. */
@media (max-width: 720px) {
    .topbar {
        flex-wrap: wrap;
        gap: 0.75rem;

        /* Utsan deer tses nuugdana */
        & nav {
            display: none;
        }
    }

    .hero {
        padding: 2rem 1rem;
    }

    /* 1 bagana bolohod baruun hurээ iluu bolno */
    .grid {
        grid-template-columns: 1fr;
        border-left: none;
        border-top: 1px solid var(--ink);
    }

    .card {
        border-right: none;
    }

    .detail {
        grid-template-columns: 1fr;
        border-left: none;
    }

    .detail-main,
    .buy-box {
        border-right: none;
    }

    /* Drop cap-iig utsan deer bagasgana */
    .detail-main .body-text::first-letter {
        font-size: 2.8rem;
    }

    /* Chat ni butsen ureg ezelne */
    .chat-panel {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 72vh;
        box-shadow: none;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }
}

/* ---- 16. Гарын хандалт (accessibility) ----------------- */
:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}
