/* ==========================================================================
   QRBarcodeTools — main.css
   Design tokens, base layout, header/footer, cards, buttons, forms,
   ad slots, utilities, responsive + print. Colors are CSS custom
   properties with a light and dark theme (guide §24).
   ========================================================================== */

:root {
  /* Brand + semantic colors */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-contrast: #ffffff;
  --secondary: #7c3aed;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --text: #111827;
  --muted: #5b6472;
  --border: #e2e6ee;
  --success: #10864a;
  --success-bg: #e7f6ee;
  --warning: #b45309;
  --warning-bg: #fef3e2;
  --error: #b91c1c;
  --error-bg: #fdeaea;
  --focus: #2563eb;

  /* Spacing / radius / shadow */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .08);
  --container: 1120px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --primary-contrast: #0b1220;
  --secondary: #a78bfa;
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1b2740;
  --text: #e8ecf4;
  --muted: #9aa6bd;
  --border: #26324b;
  --success: #34d399;
  --success-bg: #0f2c22;
  --warning: #fbbf24;
  --warning-bg: #33270c;
  --error: #f87171;
  --error-bg: #3a1616;
  --focus: #93c5fd;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #60a5fa; --primary-hover: #93c5fd; --primary-contrast: #0b1220;
    --secondary: #a78bfa; --bg: #0b1220; --surface: #131c2e; --surface-2: #1b2740;
    --text: #e8ecf4; --muted: #9aa6bd; --border: #26324b;
    --success: #34d399; --success-bg: #0f2c22; --warning: #fbbf24; --warning-bg: #33270c;
    --error: #f87171; --error-bg: #3a1616; --focus: #93c5fd;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); color: var(--text);
  background: var(--bg); line-height: 1.6; font-size: 16px;
  display: flex; flex-direction: column; min-height: 100vh;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
img { max-width: 100%; height: auto; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; color: var(--text); }
h1 { font-size: clamp(1.6rem, 4vw, 2.25rem); margin: .2em 0 .4em; }
h2 { font-size: clamp(1.3rem, 3vw, 1.6rem); margin: 1.4em 0 .5em; }
h3 { font-size: 1.15rem; margin: 1.2em 0 .4em; }
p { margin: .5em 0 1em; }
code, kbd, pre { font-family: var(--mono); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: 20px; }
main { flex: 1 0 auto; }
.section { padding: 40px 0; }
.muted { color: var(--muted); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Skip link (guide §22) */
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 200;
  background: var(--primary); color: var(--primary-contrast); padding: 10px 16px;
  border-radius: var(--radius-sm); transition: top .15s ease;
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.site-header .container { display: flex; align-items: center; gap: 16px; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .logo { width: 30px; height: 30px; color: var(--primary); flex: none; }
.brand b { color: var(--primary); }

.main-nav { display: flex; gap: 4px; margin-left: 8px; }
.main-nav a { color: var(--text); padding: 8px 12px; border-radius: var(--radius-sm); font-weight: 600; font-size: .95rem; }
.main-nav a:hover { background: var(--surface-2); text-decoration: none; }

.header-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* Search */
.search { position: relative; }
.search input {
  width: 220px; max-width: 46vw; padding: 9px 12px 9px 34px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: .95rem;
}
.search .search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; width: min(380px, 86vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 70vh; overflow: auto; display: none; padding: 6px;
}
.search-results.open { display: block; }
.search-results .sr-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: var(--radius-sm); color: var(--text); }
.search-results .sr-item:hover, .search-results .sr-item.active { background: var(--surface-2); text-decoration: none; }
.search-results .sr-item .sr-icon { width: 20px; height: 20px; color: var(--primary); flex: none; margin-top: 2px; }
.search-results .sr-name { font-weight: 700; font-size: .95rem; }
.search-results .sr-desc { font-size: .82rem; color: var(--muted); }
.search-results .sr-empty { padding: 14px; color: var(--muted); }
.search-results .sr-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px 2px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--border); }
.icon-btn svg { width: 18px; height: 18px; }

.nav-toggle { display: none; }

/* ---------- Footer ---------- */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); margin-top: 48px; padding: 40px 0 28px; }
.footer-grid { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: 28px; }
.footer-grid h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li { margin: 6px 0; }
.footer-grid a { color: var(--text); font-size: .92rem; }
.footer-bottom { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 10px 20px; justify-content: space-between; color: var(--muted); font-size: .85rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 700; font-size: .95rem; font-family: inherit; cursor: pointer;
  background: var(--surface-2); color: var(--text); transition: background .15s, border-color .15s, transform .05s;
  min-height: 44px; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; color: var(--primary-contrast);
}
.btn-outline.is-loading::after, .btn-ghost.is-loading::after { color: var(--text); }
.btn.is-success { background: var(--success); color: #fff; border-color: transparent; }
.btn.is-error { background: var(--error); color: #fff; border-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 20px;
}
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tool-card {
  display: flex; gap: 14px; align-items: flex-start; padding: 18px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: transform .12s, box-shadow .12s, border-color .12s; color: var(--text);
}
.tool-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); text-decoration: none; }
.tool-card .tc-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); flex: none; }
.tool-card .tc-icon svg { width: 22px; height: 22px; }
.tool-card h3 { margin: 0 0 4px; font-size: 1.02rem; }
.tool-card p { margin: 0; font-size: .88rem; color: var(--muted); }

/* ---------- Breadcrumb ---------- */
.breadcrumb { font-size: .85rem; color: var(--muted); padding: 16px 0 0; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.breadcrumb li::after { content: "/"; margin-left: 6px; color: var(--border); }
.breadcrumb li:last-child::after { content: ""; }
.breadcrumb a { color: var(--muted); }

/* ---------- Notices ---------- */
.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid transparent; }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice-info { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.notice-privacy { background: var(--success-bg); color: var(--text); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.notice-warning { background: var(--warning-bg); color: var(--text); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.notice-error { background: var(--error-bg); color: var(--text); border-color: color-mix(in srgb, var(--error) 40%, transparent); }
.notice-stack > * + * { margin-top: 10px; }

/* ---------- Hero ---------- */
.hero { padding: 56px 0 28px; text-align: center; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 640px; margin: 0 auto 20px; }
.hero .badges { display: flex; flex-wrap: wrap; gap: 10px 18px; justify-content: center; color: var(--muted); font-size: .9rem; font-weight: 600; }
.hero .badges span { display: inline-flex; align-items: center; gap: 6px; }
.hero .badges svg { width: 16px; height: 16px; color: var(--success); }

/* ---------- Trust strip ---------- */
.trust { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.trust .item { text-align: center; padding: 18px; }
.trust .item svg { width: 26px; height: 26px; color: var(--primary); }
.trust .item strong { display: block; margin-top: 8px; }
.trust .item span { font-size: .85rem; color: var(--muted); }

/* ---------- Content prose ---------- */
.prose { max-width: 760px; }
.prose h2 { border-top: 1px solid var(--border); padding-top: 24px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 6px 0; }
.prose table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: .92rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: .9em; }
.prose pre { background: var(--surface-2); padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; }

/* FAQ */
.faq details { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 14px; margin: 10px 0; background: var(--surface); }
.faq summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
.faq details[open] summary { border-bottom: 1px solid var(--border); }

/* ---------- Ad slots (guide §20) ---------- */
.ad-slot {
  display: flex; align-items: center; justify-content: center; margin: 24px auto; color: var(--muted);
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, transparent 10px, transparent 20px);
  border: 1px dashed var(--border); border-radius: var(--radius-sm); font-size: .8rem; letter-spacing: .04em; text-transform: uppercase;
}
.ad-slot span { background: var(--surface); padding: 2px 8px; border-radius: 4px; }
.ad-slot--leaderboard { width: 100%; max-width: 728px; height: 90px; }
.ad-slot--rectangle { width: 100%; max-width: 336px; height: 280px; }
.ad-slot--inline { width: 100%; min-height: 100px; }
body[data-ads="off"] .ad-slot { display: none; }

/* ---------- Related tools ---------- */
.related-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

/* ---------- Layout helpers ---------- */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 28px; align-items: start; }
.stack > * + * { margin-top: 16px; }
.center { text-align: center; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: .78rem; font-weight: 600; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .main-nav, .header-tools .search input { display: none; }
  .nav-toggle { display: inline-grid; }
  .site-header .container { gap: 10px; }
  .mobile-open .main-nav {
    display: flex; position: absolute; top: 64px; left: 0; right: 0; flex-direction: column;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px; gap: 2px; box-shadow: var(--shadow);
  }
  .footer-grid { grid-template-columns: 1fr; gap: 20px; }
}

/* ---------- Print (guide §26) ---------- */
@media print {
  .site-header, .site-footer, .ad-slot, .breadcrumb, .no-print,
  .generator .panel-inputs, .generator .actions, .related, .prose { display: none !important; }
  body { background: #fff; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
