:root {
  --red: #c62424;
  --red-d: #a51d1d;
  --ink: #1c1f26;
  --muted: #7a808c;
  --line: #e7e8ec;
  --bg: #f4f5f7;
  --card: #fff;
  --new: #fff7d6;
  --new-line: #f2c94c;
  --navy: #00467f;
  --navy-d: #00355f;
  --green: #22c55e;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; color: var(--navy); font-weight: 700; white-space: nowrap; }
.brand b { font-weight: 800; color: var(--red); }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-sep { width: 1px; height: 24px; background: var(--line); }
.auth-logo { display: block; width: 180px; max-width: 70%; margin: 0 auto 6px; }
.brand small { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }
.brand.big { font-size: 26px; justify-content: center; }
.logo { width: 26px; height: 26px; border-radius: 50%; background: var(--red); position: relative; flex: none; }
.logo::before { content: ""; position: absolute; inset: 6px; border: 2px solid #fff; border-radius: 50%; }
.logo::after { content: ""; position: absolute; left: 11px; top: 11px; width: 4px; height: 4px; border-radius: 50%; background: #fff; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: #cfd2d8; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); }
.btn.primary.off { background: #fff; color: var(--muted); border-color: var(--line); }
.btn.ghost { background: #e9f0f7; border-color: #e9f0f7; color: var(--navy); }
.btn.icon { padding: 8px 11px; }
.btn.block { width: 100%; padding: 12px; }
.btn.turbo { background: var(--navy); border-color: var(--navy); color: #fff; border-radius: 999px; padding: 8px 16px; }
.btn.turbo span { font-size: 10px; opacity: .7; margin-left: 4px; }
.btn.turbo.on { background: linear-gradient(90deg, var(--navy), var(--red)); border-color: var(--red); box-shadow: 0 0 0 3px #c6242430; }
.btn.turbo.on span { opacity: 1; }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 3px solid var(--navy);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.menu { position: fixed; right: 16px; top: 60px; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px #0002; padding: 6px; min-width: 200px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 6px; }
.menu button:hover { background: var(--bg); }
.menu-phone { padding: 8px 12px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* add bar */
.addbar {
  display: grid; grid-template-columns: 1fr 110px 110px 150px auto; gap: 8px;
  padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.addbar input, .auth input {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: #fff; min-width: 0; width: 100%;
}
.addbar input:focus, .auth input:focus { outline: 2px solid #c6242440; border-color: var(--red); }
.addbar .form-msg { grid-column: 1 / -1; }
.form-msg { font-size: 13px; color: var(--muted); min-height: 0; }
.form-msg.error { color: var(--red); }
.form-msg.ok { color: #15803d; }

.filterbar { display: flex; gap: 6px; padding: 10px 16px 0; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* grid */
.grid {
  display: grid; gap: 12px; padding: 12px 16px 40px;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}
.card {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--line);
  padding: 10px 10px 6px; display: flex; flex-direction: column; min-width: 0;
  transition: box-shadow .2s, opacity .2s;
}
.card.dragging { opacity: .4; border: 2px dashed var(--red); }
.card.drop-target { box-shadow: 0 0 0 2px var(--red); }
.card.paused { opacity: .6; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 4px 4px; }
.card-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.kw { color: var(--navy); font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ago { color: var(--red); font-style: italic; font-size: 12px; white-space: nowrap; }
.ago.err { color: #b45309; }
.card-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.ic { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--muted); display: grid; place-items: center; padding: 0; font-size: 14px; }
.ic:hover { color: var(--ink); border-color: #cfd2d8; }
.ic.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 0; padding: 0; margin-left: 4px; background: #c7cad1; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px #22c55e30; }
.dot.on.pulse { animation: pulse 1.4s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #22c55e80; } 100% { box-shadow: 0 0 0 8px #22c55e00; } }
.card-sub { color: var(--muted); font-size: 12px; padding: 0 4px 6px; }
.card-sub .tag { background: var(--bg); border-radius: 4px; padding: 1px 6px; margin-right: 4px; }

.items { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: start;
  padding: 7px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; position: relative;
}
.item:hover { background: #fafafb; border-color: var(--line); }
.item.new { background: var(--new); border-color: var(--new-line); }
.item.new::after { content: "MỚI"; position: absolute; left: 4px; top: 4px; background: var(--red); color: #fff; font-size: 9px; font-weight: 800; padding: 1px 4px; border-radius: 3px; }
.item img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.item .row1 { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.price { color: var(--red); font-weight: 800; font-size: 15px; }
.vnd { color: var(--muted); font-size: 12px; margin-left: 6px; font-weight: 500; }
.time { color: var(--muted); font-size: 11px; font-style: italic; white-space: nowrap; }
.title { font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.item.sold { opacity: .5; }
.item.sold .soldtag { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #333d; color: #fff; font-weight: 800; padding: 4px 12px; border-radius: 4px; font-size: 13px; letter-spacing: .5px; }
.items .placeholder { color: var(--muted); padding: 22px 8px; text-align: center; font-size: 13px; }
.more { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 8px; }
.more:hover { color: var(--red); }

.empty { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); margin: 18px 0 8px; }
.radar-anim { width: 90px; height: 90px; margin: auto; border-radius: 50%; border: 2px solid #c6242440; position: relative; overflow: hidden; }
.radar-anim::before { content: ""; position: absolute; inset: 0; background: conic-gradient(from 0deg, #c6242400 0 300deg, #c6242480 360deg); animation: spin 2.4s linear infinite; }

/* toasts */
.toasts { position: fixed; right: 16px; top: 70px; z-index: 40; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--red); color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 700; box-shadow: 0 8px 24px #c6242455; animation: slidein .25s ease-out; pointer-events: auto; cursor: pointer; max-width: 320px; }
.toast.info { background: var(--navy); box-shadow: 0 8px 24px #0003; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

/* modal */
.modal { position: fixed; inset: 0; background: #0008; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; width: min(860px, 100%); max-height: calc(100vh - 32px); overflow: auto; position: relative; }
.modal-close { position: absolute; right: 10px; top: 10px; z-index: 2; width: 34px; height: 34px; border-radius: 50%; border: 0; background: #fffc; font-size: 16px; }
.detail { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 20px; }
.gallery .main { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--bg); border-radius: 10px; }
.thumbs { display: flex; gap: 6px; overflow-x: auto; margin-top: 8px; }
.thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 2px solid transparent; flex: none; }
.thumbs img.active { border-color: var(--red); }
.detail h2 { font-size: 18px; margin: 0 0 4px; line-height: 1.35; }
.detail .ja { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.detail .bigprice { color: var(--red); font-size: 26px; font-weight: 800; }
.detail .bigprice small { color: var(--muted); font-size: 14px; font-weight: 500; margin-left: 8px; }
.specs { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.specs td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.specs td:first-child { color: var(--muted); width: 38%; }
.desc { white-space: pre-wrap; font-size: 13px; line-height: 1.5; background: var(--bg); border-radius: 8px; padding: 10px; max-height: 260px; overflow: auto; }
.detail .btns { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.btn.big { padding: 13px; font-size: 15px; text-align: center; text-decoration: none; }
.badge-sold { display: inline-block; background: #333; color: #fff; padding: 2px 10px; border-radius: 4px; font-weight: 700; font-size: 12px; margin-bottom: 8px; }
.linkbtn { border: 0; background: none; color: var(--red); padding: 4px 0; font-size: 13px; }
.order-form { display: grid; gap: 8px; margin-top: 10px; }
.order-form input, .order-form textarea { border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: inherit; width: 100%; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { background: #fff; border-radius: 16px; padding: 28px 24px; width: min(400px, 100%); box-shadow: 0 10px 40px #0001; }
.auth-card .muted { text-align: center; color: var(--muted); margin: 10px 0 18px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 8px; padding: 3px; margin-bottom: 14px; }
.tab { border: 0; background: none; padding: 8px; border-radius: 6px; font-weight: 600; color: var(--muted); }
.tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px #0001; }
.auth label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.auth label input { margin-top: 4px; padding: 11px 12px; }
.hint { font-size: 12px; color: var(--muted); text-align: center; }

/* mobile */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  .brand { font-size: 18px; }
  .brand small { display: none; }
  .actions { width: 100%; justify-content: space-between; gap: 6px; }
  .actions .btn { padding: 7px 10px; font-size: 13px; }
  .addbar { grid-template-columns: 1fr 1fr; }
  .addbar input[name=keyword], .addbar button { grid-column: 1 / -1; }
  .grid { grid-template-columns: 1fr; padding: 10px 12px 40px; }
  .detail { grid-template-columns: 1fr; padding: 14px; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { border-radius: 14px 14px 0 0; max-height: 94vh; }
  .toasts { left: 12px; right: 12px; top: auto; bottom: 16px; }
}
.order-form .who { background: var(--bg); border-radius: 8px; padding: 10px; font-size: 13px; }
.order-form .qty { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.order-form .qty input { width: 90px; }
.hint a { color: var(--red); }

@media (max-width: 760px) { .brand-logo { height: 26px; } }
@media (max-width: 760px) {
  .actions .btn { flex: 1 1 auto; }
  .actions .btn.icon { flex: none; }
}

/* ---- điều hướng + khám phá ---- */
.nav { display: flex; gap: 4px; margin-right: auto; margin-left: 18px; }
.navtab { border: 0; background: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.navtab:hover { background: var(--bg); }
.navtab.active { color: var(--navy); background: #e9f0f7; }
.navtab span { font-weight: 500; }

.searchbar { display: flex; gap: 8px; padding: 14px 16px 6px; max-width: 900px; }
.searchbar input { flex: 1; min-width: 0; border: 2px solid var(--navy); border-radius: 10px; padding: 11px 14px; font: inherit; font-size: 15px; background: #fff; }
.searchbar input:focus { outline: none; box-shadow: 0 0 0 3px #00467f22; }
.catbar { display: flex; gap: 6px; padding: 8px 16px; overflow-x: auto; scrollbar-width: none; }
.catbar::-webkit-scrollbar { display: none; }
.catbar .chip { white-space: nowrap; flex: none; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 4px 16px 8px; }
.filters select, .filters input[inputmode] { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: inherit; background: #fff; }
.filters input[inputmode] { width: 110px; }
.filters .check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.filters #watchThis { margin-left: auto; color: var(--navy); border-color: var(--navy); }
.explore-info { padding: 2px 16px 8px; color: var(--muted); font-size: 13px; }
.explore-info b { color: var(--ink); }

.pgrid { display: grid; gap: 12px; padding: 0 16px 20px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.pcard:hover { box-shadow: 0 6px 20px #00467f1f; transform: translateY(-2px); }
.pimg { position: relative; aspect-ratio: 1; background: var(--bg); }
.pimg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard.sold .pimg img { opacity: .45; }
.pcard .soldtag { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #333d; color: #fff; font-weight: 800; padding: 4px 12px; border-radius: 4px; font-size: 13px; }
.pbody { padding: 8px 10px 10px; }
.vnd2 { color: var(--muted); font-size: 12px; }
.pbody .title { margin-top: 4px; min-height: 2.7em; }
.pbody .time { margin-top: 4px; display: block; }
.pcard.skel { cursor: default; }
.pcard.skel .pimg, .pcard.skel .pbody div { background: linear-gradient(90deg, #eef0f3, #f7f8fa, #eef0f3); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.pcard.skel .pbody div { height: 12px; border-radius: 4px; margin: 6px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }
.pgrid .placeholder { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px; }
.loadmore-wrap { text-align: center; padding: 0 16px 40px; }

/* đăng nhập dạng cửa sổ nổi */
.auth { position: fixed; inset: 0; z-index: 60; background: #0009; min-height: 0; }
.auth-card { position: relative; }

@media (max-width: 760px) {
  .nav { order: 3; width: 100%; margin: 4px 0 0; }
  .navtab { flex: 1; }
  .searchbar { padding: 10px 12px 4px; }
  .catbar, .filters, .explore-info { padding-left: 12px; padding-right: 12px; }
  .filters input[inputmode] { width: 90px; }
  .filters #watchThis { margin-left: 0; width: 100%; }
  .pgrid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 0 12px 20px; }
}
