
/* ============== CSS VARIABLES ============== */
:root {
  --blue-500: #0da574;       /* primary */
  --blue-600: #0da574;
  --bg: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --card: #f8fafc;
  --border: #e2e8f0;
  --accent: #0ea5e9;
  --success: #16a34a;
  --warning: #ea580c;
  --focus: #22d3ee;
  --shadow: 0 10px 25px rgba(2, 6, 23, .08);
  --radius: 16px;
  --font-scale: 1; /* adjustable by settings */
}

:root[data-theme="dark"] {
      --blue-500: #ffffff;       /* primary */
  --blue-600: #ffffff;
  --bg: #0b1220;
  --text: #e5e7eb;
  --muted: #cbd5e1;
  --card: #0f172a;
  --border: #172554;
  --shadow: 0 10px 25px rgba(2, 6, 23, .6);
}

html { font-size: calc(16px * var(--font-scale)); scroll-behavior: smooth; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; line-height: 1.6; }

a { color: var(--blue-600); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:focus { outline: 3px solid var(--focus); outline-offset: 4px; }
button:focus, input:focus, select:focus { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Skip link */
.skip-link { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.skip-link:focus { position: fixed; left: 12px; top: 12px; width: auto; height: auto; background: var(--blue-600); color: white; padding: .5rem .75rem; border-radius: 10px; z-index: 10000; }

/* ============== LAYOUT ============== */
.container { max-width: 1200px; margin: 0 auto; padding: 16px; }

.header {
  position: sticky; top: 0; z-index: 999;
  background: rgba(255,255,255,.7); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
[data-theme="dark"] .header { background: rgba(15, 23, 42, .7); }

/* Use grid with areas so it reflows cleanly on small screens */
.header-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "brand search actions";
  align-items: center;
  gap: 16px;
  padding: 12px 0;
}

.brand { grid-area: brand; display: flex; align-items: center; gap: 10px; }
.brand img { height: 32px; width: auto; }
.brand .title { font-weight: 800; letter-spacing: .3px; }

.searchbar { grid-area: search; position: relative; }
.searchbar input {
  width: 100%;
  padding: 12px 44px 12px 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card); color: var(--text);
}
.searchbar svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  pointer-events: none;
}
.searchbar .suggestions {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 320px; overflow: auto; display: none;
}
.searchbar .suggestions[aria-expanded="true"] { display: block; }
.searchbar .suggestions button {
  width: 100%; padding: 10px 12px; border: 0; background: transparent;
  text-align: left; cursor: pointer;
}
.searchbar .suggestions button:hover { background: var(--card); }

.header-actions { grid-area: actions; display: flex; gap: 10px; align-items: center; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--card); cursor: pointer;
}
.icon-btn[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--blue-500); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: var(--blue-500); color: white; border-radius: 999px; text-decoration: none; font-weight: 600;
}

/* Main grid */
.main-grid { display: grid; grid-template-columns: 1fr 320px; gap: 24px; margin-top: 18px; }
@media (max-width: 980px) { .main-grid { grid-template-columns: 1fr; } }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-hd { padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 700; }
.card .card-bd { padding: 14px 18px; }

/* Category tree */
.tree { display: grid; gap: 12px; }
.tree details { border: 1px dashed var(--border); border-radius: 14px; padding: 10px 12px; background: linear-gradient(0deg, transparent, rgba(37,99,235,.04)); }
.tree summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; font-weight: 700; }
.tree summary::-webkit-details-marker { display: none; }
.tree .count {
  margin-left: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 4px 8px;
  font-size: .85rem; color: var(--muted);
}
.tree ul { margin: 10px 0 0 28px; padding-left: 0; display: grid; gap: 8px; }
.tree li { list-style: none; display: flex; align-items: center; gap: 8px; }
.tree li a { text-decoration: none; }
.tree .subcount { margin-left: auto; font-size: .85rem; color: var(--muted); }

/* Right rail */
.rail .btn-group { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.rail .btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); text-decoration: none; font-weight: 600; }
.rail .btn:hover { background: var(--card); }

/* Breadcrumbs */
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .95rem; color: var(--muted); }
.breadcrumbs a { text-decoration: none; }
.breadcrumbs .sep { opacity: .6; }

/* Article layout */
.article { display: grid; grid-template-columns: 1fr 260px; gap: 24px; }
@media (max-width: 980px) { .article { grid-template-columns: 1fr; } }
.article .content { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.article aside { position: sticky; top: 84px; align-self: start; }
.article .meta { color: var(--muted); font-size: .9rem; margin-top: 8px; }
.article .actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* Related */
.related { margin-top: 24px; }
.related .list { display: grid; gap: 10px; }

/* FAQ */
.faq .item { border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.faq .q {
  width: 100%; padding: 12px 14px; background: transparent; border: 0; text-align: left;
  display: grid; grid-template-columns: 1fr auto; align-items: center; cursor: pointer; font-weight: 700;
}
.faq .a { padding: 0 14px 14px 14px; display: none; }
.faq .item[aria-expanded="true"] .a { display: block; }

/* Footer (centered) */
.footer {
  margin: 36px 0; color: var(--muted); font-size: .9rem;
  text-align: center; display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* Scroll-to-top + progress */
#toTop {
  position: fixed; right: 16px; bottom: 16px; z-index: 1000;
  display: none; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--card);
}
#toTop .pct { font-weight: 700; min-width: 2ch; text-align: right; }
#progressBar { position: fixed; left: 0; top: 0; height: 4px; background: var(--blue-500); width: 0; z-index: 1100; }

/* WhatsApp bubble */
.whatsapp {
  position: fixed; left: 16px; bottom: 16px; z-index: 1000;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px; border-radius: 999px; background: #10b981; color: white; text-decoration: none; font-weight: 700;
  box-shadow: var(--shadow);
}

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

/* Tablet */
@media (max-width: 1024px) {
  .header-inner {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "search search";
    gap: 12px;
  }
  .rail .btn-group { grid-template-columns: 1fr 1fr; }
}

/* Mobile */
@media (max-width: 640px) {
  .container { padding: 12px; }
  .brand img { height: 28px; }
  .brand .title { font-size: 1rem; }
  .icon-btn { padding: 8px 10px; }
  .badge { padding: 6px 10px; }
  .searchbar input { padding: 10px 40px; }
  .rail .btn-group { grid-template-columns: 1fr; }
  .tree ul { margin-left: 18px; }
}

/* Print styles for PDF via browser print */
@media print {
  .header, .rail, #toTop, .whatsapp, #progressBar { display: none !important; }
  .content { border: 0; box-shadow: none; }
  body { background: white; color: black; }
}


/* ===== Header translate dropdown (Google) ===== */
.header-actions .translate { min-width: 160px; }
.goog-te-gadget { font-size: 0 !important; } /* hide "Powered by" text but keep aria content */
.goog-te-gadget .goog-te-combo {
  font-size: 14px !important;
  border: 1px solid var(--border) !important;
  background: var(--card) !important;
  color: var(--text) !important;
  border-radius: 12px;
  padding: 8px 10px;
  outline: none;
}
/* Ensure the translate iframe doesn't add extra spacing */
.goog-te-banner-frame, .goog-te-balloon-frame { display:none !important; }
body { top:0px !important; }

/* ===== Centered footer (reinforced) ===== */
footer.container.footer { width: 100%; max-width: 1200px; margin-left:auto; margin-right:auto; }
.footer { text-align:center; display:flex; justify-content:center; align-items:center; gap:8px; flex-wrap:wrap; padding: 24px 0; }

/* ===== Filter by category styling ===== */
.controls { display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.controls label { font-weight: 600; color: var(--muted); }
.select-modern { position:relative; display:inline-flex; align-items:center; }
.select-modern::before {
  content: "▾"; position:absolute; right:12px; pointer-events:none; opacity:.7;
}
#catFilter {
  appearance:none; -webkit-appearance:none; -moz-appearance:none;
  padding:10px 36px 10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-weight:600;
  transition: box-shadow .15s ease, border-color .15s ease;
}
#catFilter:focus { border-color: var(--blue-500); box-shadow: 0 0 0 4px rgba(37,99,235,.15); }
#catFilter:hover { border-color: var(--accent); }


/* Screen-reader only utility (also hide Google widget) */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Chevron arrow for all relevant selects */
#catFilter,
#sideCat,
#sideCat2 {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  /* room for the arrow */
  padding-right: 2rem;

  /* inline SVG chevron (dark gray for light theme) */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M10.59 1.59 6 6.17 1.41 1.59 0 3l6 6 6-6-1.41-1.41Z' fill='%23475569'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}

/* Swap arrow color in dark mode */
[data-theme="dark"] #catFilter,
[data-theme="dark"] #sideCat,
[data-theme="dark"] #sideCat2 {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M10.59 1.59 6 6.17 1.41 1.59 0 3l6 6 6-6-1.41-1.41Z' fill='%23cbd5e1'/></svg>");
}

/* Hide native arrow in old Edge/IE */
#catFilter::-ms-expand,
#sideCat::-ms-expand,
#sideCat2::-ms-expand {
  display: none;
}

/* Basic pretty code blocks */
.article pre {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  overflow: auto;
}
.article pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.95em;
  color: var(--text);
}
/* Unified select styling (Filter + Jump to category) */
#catFilter,
#sideCat,
#sideCat2 {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;

  padding: 10px 2.2rem 10px 12px; /* right space for chevron */
  font: inherit;
  line-height: 1.2;

  /* Chevron */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M10.59 1.59 6 6.17 1.41 1.59 0 3l6 6 6-6-1.41-1.41Z' fill='%23475569'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;

  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

/* Sizes: filter keeps compact width; side selects fill the card */
#catFilter { max-width: 280px; }
#sideCat,
#sideCat2 { width: 100%; }

/* Hover & focus */
#catFilter:hover,
#sideCat:hover,
#sideCat2:hover { background-color: rgba(37,99,235,.04); }
#catFilter:focus,
#sideCat:focus,
#sideCat2:focus { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Dark mode chevron color */
[data-theme="dark"] #catFilter,
[data-theme="dark"] #sideCat,
[data-theme="dark"] #sideCat2 {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M10.59 1.59 6 6.17 1.41 1.59 0 3l6 6 6-6-1.41-1.41Z' fill='%23cbd5e1'/></svg>");
}

/* Hide native arrow on old Edge/IE */
#catFilter::-ms-expand,
#sideCat::-ms-expand,
#sideCat2::-ms-expand { display: none; }

/* ===== Mobile header toggle ===== */
.show-sm { display: none; }

.header .container { position: relative; } /* so the panel can anchor under header */

@media (max-width: 640px) {
  .show-sm { display: inline-flex; }
  /* Hide actions by default on small screens; they’ll open as a panel */
  .header-actions {
    display: none;
  }
  body.nav-open .header-actions {
    display: flex;
    position: absolute;
    left: 0; right: 0; top: calc(100% + 2px);
    background: var(--bg);
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 14px 14px;
    padding: 10px;
    gap: 8px;
    z-index: 1000;
  }

  /* Make search full width under brand/menu row */
  .header-inner {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "search search";
    gap: 10px;
  }

  /* Tidy icons and badge in tight spaces */
  .icon-btn { padding: 8px 10px; }
  .header-actions .badge { padding: 6px 10px; }
}

/* When on small screens, stack article sidebar and turn off sticky */
@media (max-width: 980px) {
  .article { grid-template-columns: 1fr; }
  .article aside { position: static; }
}

/* Keep breadcrumbs from squishing; allow wrapping nicely */
.breadcrumbs { row-gap: 4px; }

/* Give selects the same modern look (if you hadn’t added earlier) */
#catFilter, #sideCat, #sideCat2 {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 2.2rem 10px 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M10.59 1.59 6 6.17 1.41 1.59 0 3l6 6 6-6-1.41-1.41Z' fill='%23475569'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}
[data-theme="dark"] #catFilter,
[data-theme="dark"] #sideCat,
[data-theme="dark"] #sideCat2 {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M10.59 1.59 6 6.17 1.41 1.59 0 3l6 6 6-6-1.41-1.41Z' fill='%23cbd5e1'/></svg>");
}
#sideCat, #sideCat2 { width: 100%; }

/* iOS safe area for sticky header contents */
@supports (padding: max(0px)) {
  .header { padding-left: max(0px, env(safe-area-inset-left)); padding-right: max(0px, env(safe-area-inset-right)); }
}

/* --- Responsive embeds: YouTube/iframes/videos --- */
.article .article-body iframe,
.article .article-body embed,
.article .article-body video {
  display: block;
  max-width: 100%;
  width: 100% !important;
  height: auto !important;   /* let aspect-ratio (below) control height */
  border: 0;
}

/* Prefer aspect-ratio when supported (modern browsers) */
@supports (aspect-ratio: 16 / 9) {
  .article .article-body iframe[src*="youtube.com"],
  .article .article-body iframe[src*="youtu.be"],
  .article .article-body video {
    aspect-ratio: 16 / 9;    /* classic 16:9 */
  }
}

/* Guardrail to prevent any horizontal overflow on small screens */
@media (max-width: 640px) {
  .article .content { overflow-x: hidden; }
}
