/* ============================================================
   VnCalc — Công cụ tính toán & chuyển đổi
   Stylesheet chung (responsive, mobile-first, thân thiện AdSense)
   ============================================================ */
:root {
  --brand: #0b6b5e;
  --brand-dark: #084c43;
  --brand-light: #e6f4f1;
  --accent: #f0a500;
  --text: #1c2b29;
  --muted: #5f726f;
  --bg: #f5f7f7;
  --card: #ffffff;
  --border: #e1e8e7;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(11, 107, 94, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Roboto", "Helvetica Neue", Arial,
    "Noto Sans", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Liên kết trong đoạn văn phải có gạch chân (không chỉ dựa vào màu, accessibility) */
p a { text-decoration: underline; text-underline-offset: 2px; }
/* Tiêu đề khu công cụ ở trang chủ */
.grid-head { margin: 30px 0 14px; }

/* ---------- Ảnh/media tự co giãn toàn cục (chống tràn bố cục) ---------- */
img, svg, video, canvas, iframe {
  max-width: 100%;
  height: auto;
  display: block;
}
/* Buộc xuống dòng với từ dài / URL dài / công thức dài */
body, p, li, td, th, h1, h2, h3, h4, a {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* ---------- Header ---------- */
.site-header {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 9px;
  display: grid; place-items: center;
  font-weight: 800; color: var(--brand-dark);
}
.nav { display: flex; gap: 6px; align-items: center; }
.nav a {
  color: #eafff9;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
}
.nav a:hover { background: rgba(255,255,255,0.14); text-decoration: none; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; }

/* ---------- Layout ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; }
main { min-height: 50vh; }

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 40px 16px 30px;
}
.hero h1 { font-size: 2rem; color: var(--brand-dark); margin-bottom: 10px; }
.hero p { color: var(--muted); max-width: 620px; margin: 0 auto; }

/* ---------- Tool grid ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
  margin-top: 30px;
}
.tool-card-link {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  display: block;
  transition: transform .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.tool-card-link:hover { transform: translateY(-4px); text-decoration: none; box-shadow: 0 10px 26px rgba(11,107,94,.14); }
.tool-card-link .ic { font-size: 1.8rem; }
.tool-card-link h3 { color: var(--text); margin: 8px 0 4px; font-size: 1.05rem; }
.tool-card-link p { color: var(--muted); font-size: .88rem; }

/* ---------- Tool page ---------- */
.tool-head { margin-bottom: 8px; }
.tool-head h1 { font-size: 1.7rem; color: var(--brand-dark); }
.tool-head .desc { color: var(--muted); margin-bottom: 18px; }

.tool-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  max-width: 560px;
}
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
.field input, .field select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.row { display: flex; gap: 12px; }
.row .field { flex: 1; }
.btn {
  width: 100%;
  background: var(--brand);
  color: #fff;
  border: 0;
  padding: 13px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}
.btn:hover { background: var(--brand-dark); }
.result {
  margin-top: 18px;
  background: var(--brand-light);
  border: 1px dashed var(--brand);
  border-radius: 10px;
  padding: 16px;
  font-size: 1.05rem;
}
.result .big { font-size: 1.5rem; font-weight: 800; color: var(--brand-dark); }
.result .sub { color: var(--muted); font-size: .9rem; }
.note { font-size: .82rem; color: var(--muted); margin-top: 14px; }

/* ---------- AdSense placeholder ---------- */
.ad-box {
  margin: 22px 0;
  background: repeating-linear-gradient(45deg,#fafafa,#fafafa 12px,#f0f0f0 12px,#f0f0f0 24px);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 90px;
  display: grid; place-items: center;
  color: #9aa;
  font-size: .85rem;
  text-align: center;
  padding: 10px;
}
.ad-box.tall { min-height: 250px; }

/* ---------- Other tools ---------- */
.other-tools { margin-top: 40px; }
.other-tools h2 { font-size: 1.15rem; color: var(--brand-dark); margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chips a {
  background: #fff; border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; font-size: .9rem;
}
.chips a:hover { border-color: var(--brand); text-decoration: none; }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--brand-dark);
  color: #cdeee7;
  padding: 34px 20px;
  margin-top: 40px;
}
.footer-inner { max-width: 1080px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 24px; justify-content: space-between; }
.footer-inner a { color: #cdeee7; }
.footer-inner h4 { color: #fff; margin-bottom: 8px; font-size: .98rem; }
.footer-inner ul { list-style: none; }
.footer-inner li { margin-bottom: 5px; font-size: .9rem; }
.copyright { text-align: center; color: #9fc7bf; font-size: .82rem; margin-top: 24px; }

/* ---------- Static pages ---------- */
.prose { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 30px; box-shadow: var(--shadow); }
.prose h2 { color: var(--brand-dark); margin: 22px 0 10px; }
.prose p, .prose li { color: #334; margin-bottom: 10px; }

/* ---------- Breadcrumb ---------- */
.breadcrumb { font-size: .85rem; color: var(--muted); margin: 4px 0 18px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb .sep { margin: 0 7px; color: #b8c6c3; }
.breadcrumb span:last-child { color: var(--brand); font-weight: 600; }

/* ---------- Tool content (chuyên nghiệp: công thức / bước / FAQ) ---------- */
.tool-content { margin-top: 14px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px 24px; box-shadow: var(--shadow); }
.tool-content h2 { color: var(--brand-dark); font-size: 1.2rem; margin: 22px 0 10px;
  padding-bottom: 6px; border-bottom: 2px solid var(--brand-light); }
.tool-content h2:first-child { margin-top: 4px; }
.tool-content p { color: #33433f; margin-bottom: 10px; }
.tool-content ul, .tool-content ol { color: #33433f; margin: 0 0 10px 20px; }
.tool-content li { margin-bottom: 7px; }
.formula-box { background: #0b2f2a; color: #eafff9; border-radius: 10px; padding: 14px 16px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .92rem;
  overflow-x: auto; line-height: 1.7; }
.formula-box code { color: #ffd479; }
.steps { counter-reset: step; list-style: none; margin-left: 0 !important; }
.steps li { position: relative; padding-left: 36px; margin-bottom: 12px !important; }
.steps li::before { counter-increment: step; content: counter(step); position: absolute; left: 0; top: 1px;
  width: 24px; height: 24px; background: var(--brand); color: #fff; border-radius: 50%;
  display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.updated { font-size: .8rem; color: var(--muted); margin-top: 14px; }
.updated b { color: var(--brand-dark); }

/* ---------- FAQ (dùng <details>, thân thiện SEO & không cần JS) ---------- */
.faq { display: flex; flex-direction: column; gap: 10px; }
.faq details { border: 1px solid var(--border); border-radius: 10px; background: #fbfdfc; overflow: hidden; }
.faq summary { cursor: pointer; padding: 13px 16px; font-weight: 600; color: var(--text); list-style: none;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--brand); font-size: 1.3rem; font-weight: 700; transition: transform .2s; }
.faq details[open] summary::after { content: "−"; }
.faq details p { padding: 0 16px 14px; color: #33433f; margin: 0; }

/* ---------- Slider (thanh trượt cho vay & BMI) ---------- */
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px;
  background: var(--brand-light); outline: none; margin-top: 10px; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px;
  border-radius: 50%; background: var(--brand); border: 3px solid #fff; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.slider::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--brand);
  border: 3px solid #fff; cursor: pointer; }

/* ---------- BMI gauge (thanh phân loại) ---------- */
.gauge { position: relative; height: 16px; border-radius: 999px; margin-top: 14px; overflow: hidden;
  background: linear-gradient(90deg, #4aa3ff 0%, #36c98d 24%, #ffd166 35%, #ff8a5c 48%, #ff5d5d 100%); }
.gauge-fill { position: absolute; top: 0; right: 0; height: 100%; background: rgba(255,255,255,.0); }
.gauge-mark { position: absolute; top: 0; width: 2px; height: 100%; background: rgba(0,0,0,.25); }

/* ---------- Live rate / gold ticker ---------- */
.live-box { background: var(--brand-light); border: 1px solid var(--brand); border-radius: 12px;
  padding: 14px 16px; margin: 16px 0; display: flex; flex-wrap: wrap; gap: 12px 22px; align-items: center; }
.live-box .lv { font-weight: 700; color: var(--brand-dark); font-size: 1.05rem; line-height: 1.4; }
.live-box .lv small { font-weight: 500; color: var(--muted); font-size: .8rem; display: block; margin-top: 2px; }
.live-box .ltag { font-size: .78rem; color: var(--muted); margin-left: auto; text-align: right; line-height: 1.5; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #36c98d; display: inline-block; margin-right: 5px; vertical-align: middle; }
.live-dot.off { background: #c9a436; }

/* ---------- Blog / Articles ---------- */
.blog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; margin-top: 22px; }
.blog-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 20px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; }
.blog-card:hover { transform: translateY(-4px); box-shadow: 0 10px 26px rgba(11,107,94,.14); text-decoration: none; }
.blog-card .tag { align-self: flex-start; background: var(--brand-light); color: var(--brand-dark); font-size: .72rem;
  font-weight: 700; padding: 3px 10px; border-radius: 999px; margin-bottom: 10px; }
.blog-card h3 { color: var(--text); font-size: 1.05rem; margin-bottom: 8px; }
.blog-card p { color: var(--muted); font-size: .88rem; flex: 1; }
.blog-card .meta { margin-top: 12px; font-size: .78rem; color: var(--muted); }
.blog-section-head { margin: 38px 0 4px; color: var(--brand-dark); font-size: 1.3rem; }
.blog-section-head + .sub { color: var(--muted); margin-bottom: 6px; }

.article { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 30px 28px; box-shadow: var(--shadow); }
.article .lede { font-size: 1.02rem; color: #3a4a47; }
.article h2 { color: var(--brand-dark); margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--brand-light); font-size: 1.2rem; }
.article h2:first-of-type { margin-top: 8px; }
.article p, .article li { color: #33433f; margin-bottom: 10px; }
.article ul, .article ol { margin: 0 0 10px 20px; }
.article li { margin-bottom: 7px; }
.article table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .92rem; }
.article th, .article td { border: 1px solid var(--border); padding: 9px 11px; text-align: left; }
.article th { background: var(--brand-light); color: var(--brand-dark); }
.article blockquote { border-left: 4px solid var(--brand); background: #fbfdfc; margin: 14px 0; padding: 10px 16px; color: #445; border-radius: 0 8px 8px 0; }
.article .callout { background: var(--brand-light); border-radius: 10px; padding: 12px 16px; font-size: .9rem; color: #2c4a44; margin: 14px 0; }
.article .callout b { color: var(--brand-dark); }
.article .faq { margin-top: 6px; }

/* ---------- Hero image (on-page featured image) ---------- */
/* Co giãn bằng width:100% + height:auto, tương thích mọi trình duyệt di động;
   tỉ lệ khung hình do thuộc tính width="1200" height="630" cung cấp, tránh CLS. */
.hero-img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: var(--radius);
  margin: 18px 0 22px;
  box-shadow: 0 6px 20px rgba(8, 76, 67, .12);
  background: var(--brand-dark);
}
/* Dự phòng: buộc ảnh trong bài viết/nội dung tự co giãn */
.article img, .tool-content img, .prose img, .card img, main img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .nav { display: none; position: absolute; top: 62px; left: 0; right: 0;
    flex-direction: column; background: var(--brand-dark); padding: 10px; }
  .nav.open { display: flex; }
  .nav-toggle { display: block; }
  .hero h1 { font-size: 1.5rem; }
  .row { flex-direction: column; gap: 0; }

  /* ---- Thu hẹp khoảng trắng, nhường chỗ cho nội dung ---- */
  .container { padding: 18px 14px 44px; }
  .site-header { padding: 0 14px; }
  .footer-inner { gap: 16px; padding: 0 14px; }

  /* ---- Ảnh tự co giãn ---- */
  .hero-img { margin: 14px 0 18px; border-radius: 10px; }

  /* ---- Bảng cuộn ngang thay vì tràn trang ---- */
  .article table, .tool-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    font-size: .84rem;
  }
  .article th, .article td,
  .tool-content th, .tool-content td {
    padding: 7px 10px;
    white-space: nowrap;
  }

  /* ---- Cỡ chữ tiêu đề và nội dung ---- */
  .article h2, .tool-content h2 { font-size: 1.08rem; margin-top: 20px; }
  .article .lede, .article p, .article li,
  .tool-content p, .tool-content li { font-size: .95rem; }

  /* ---- Khung công thức / thẻ ---- */
  .formula-box { font-size: .82rem; padding: 11px 12px; }
  .card, .tool-card, .blog-card { padding: 14px; }

  /* ---- Ô nhập 16px để tránh iOS tự phóng trang ---- */
  input, select, textarea, button { font-size: 16px; }

  /* ---- Breadcrumb / meta cho phép xuống dòng ---- */
  .breadcrumb, .post-meta, .updated { flex-wrap: wrap; gap: 6px; font-size: .78rem; }
}

/* ---------- Màn hình rất hẹp (<=380px, ví dụ iPhone SE) ---------- */
@media (max-width: 380px) {
  .container { padding: 16px 11px 40px; }
  .hero h1 { font-size: 1.32rem; }
  .btn { padding: 10px 14px; font-size: .9rem; }
  .tool-grid, .blog-grid { grid-template-columns: 1fr !important; }
}

/* ---------- Điều hướng bài viết (trước / sau) ---------- */
.post-nav { display: flex; gap: 14px; margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--border); }
.post-nav .pn { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; text-decoration: none; min-width: 0; transition: border-color .15s, box-shadow .15s; }
.post-nav .pn:hover { border-color: var(--brand); box-shadow: var(--shadow); text-decoration: none; }
.post-nav .pn span { display: block; font-size: .76rem; color: var(--muted); margin-bottom: 5px; }
.post-nav .pn b { display: block; color: var(--brand-dark); font-size: .92rem; line-height: 1.45; }
.post-nav .pn.next { text-align: right; }

/* ---------- Phân trang blog ---------- */
.pagination { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 30px; }
.pagination .page-btn { display: inline-block; background: var(--brand); color: #fff; padding: 10px 24px;
  border-radius: 999px; text-decoration: none; font-size: .9rem; font-weight: 600; }
.pagination .page-btn:hover { background: var(--brand-dark); text-decoration: none; }
.pagination .page-info { color: var(--muted); font-size: .88rem; }

@media (max-width: 640px) {
  .post-nav { flex-direction: column; }
  .post-nav .pn.next { text-align: left; }
}
