/* === RESET & BASE === */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{-webkit-text-size-adjust:100%;scroll-behavior:smooth}
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  line-height:1.6;color:var(--text);background:var(--bg);transition:background .2s,color .2s}
a{color:var(--link);text-decoration:none}
a:hover{text-decoration:underline}
img,svg{display:block;max-width:100%}
button,input,select{font:inherit;color:inherit;background:var(--bg);color-scheme:light dark}
table{border-collapse:collapse;width:100%}

/* === CSS CUSTOM PROPERTIES === */
:root{
  --bg:#ffffff;--bg-alt:#f7f8fa;--bg-card:#ffffff;
  --text:#1a1a2e;--text-muted:#6b7280;--text-light:#9ca3af;
  --link:#2563eb;--link-hover:#1d4ed8;
  --border:#e5e7eb;--border-focus:#2563eb;
  --primary:#2563eb;--primary-hover:#1d4ed8;--primary-light:#dbeafe;
  --success:#059669;--success-light:#d1fae5;
  --radius:8px;--radius-lg:12px;
  --shadow:0 1px 3px rgba(0,0,0,.08);--shadow-lg:0 4px 12px rgba(0,0,0,.1);
  --header-h:56px;
  --container:1100px;
  --gap:16px;
}

/* Dark theme */
.theme-dark,:root:has(.theme-dark){
  --bg:#0f172a;--bg-alt:#1e293b;--bg-card:#1e293b;
  --text:#e2e8f0;--text-muted:#94a3b8;--text-light:#64748b;
  --link:#60a5fa;--link-hover:#93bbfd;
  --border:#334155;--border-focus:#60a5fa;
  --primary:#3b82f6;--primary-hover:#60a5fa;--primary-light:#1e3a5f;
  --success:#34d399;--success-light:#064e3b;
  --shadow:0 1px 3px rgba(0,0,0,.3);--shadow-lg:0 4px 12px rgba(0,0,0,.4);
}
@media(prefers-color-scheme:dark){
  .theme-auto{
    --bg:#0f172a;--bg-alt:#1e293b;--bg-card:#1e293b;
    --text:#e2e8f0;--text-muted:#94a3b8;--text-light:#64748b;
    --link:#60a5fa;--link-hover:#93bbfd;
    --border:#334155;--border-focus:#60a5fa;
    --primary:#3b82f6;--primary-hover:#60a5fa;--primary-light:#1e3a5f;
    --success:#34d399;--success-light:#064e3b;
    --shadow:0 1px 3px rgba(0,0,0,.3);--shadow-lg:0 4px 12px rgba(0,0,0,.4);
  }
}

/* RTL */
[dir="rtl"]{direction:rtl;text-align:right}
[dir="rtl"] .converter-row{flex-direction:row-reverse}
[dir="rtl"] .breadcrumb li+li::before{content:"\\"}

/* === LAYOUT === */
.container{max-width:var(--container);margin:0 auto;padding:0 var(--gap)}
.main-content{padding:var(--gap) var(--gap) 48px}

/* === HEADER === */
.site-header{position:sticky;top:0;z-index:100;background:var(--bg);border-bottom:1px solid var(--border);height:var(--header-h)}
.header-inner{display:flex;align-items:center;height:100%;gap:12px}
.logo{display:flex;align-items:center;gap:8px;font-weight:700;font-size:1.1rem;color:var(--text);white-space:nowrap}
.logo:hover{text-decoration:none}
.main-nav{display:flex;gap:16px;margin-inline-start:24px}
.main-nav a{color:var(--text-muted);font-size:.9rem;font-weight:500}
.main-nav a:hover{color:var(--text)}
.header-actions{display:flex;align-items:center;gap:8px;margin-inline-start:auto}
.btn-icon{display:flex;align-items:center;justify-content:center;width:36px;height:36px;border:1px solid var(--border);border-radius:var(--radius);background:transparent;cursor:pointer;color:var(--text-muted);transition:all .15s}
.btn-icon:hover{background:var(--bg-alt);color:var(--text)}
.hamburger{display:none}
@media(max-width:640px){
  .main-nav{display:none}
  .hamburger{display:flex}
  .main-nav.open{display:flex;position:absolute;top:var(--header-h);left:0;right:0;flex-direction:column;background:var(--bg);border-bottom:1px solid var(--border);padding:12px var(--gap);gap:8px;z-index:99}
}

/* Locale dropdown */
.locale-selector{position:relative}
.locale-dropdown{position:absolute;top:100%;right:0;margin-top:4px;background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow-lg);padding:8px 0;max-height:320px;overflow-y:auto;min-width:180px;z-index:101}
[dir="rtl"] .locale-dropdown{right:auto;left:0}
.locale-dropdown a{display:block;padding:6px 16px;font-size:.85rem;color:var(--text);white-space:nowrap}
.locale-dropdown a:hover{background:var(--bg-alt);text-decoration:none}
.locale-dropdown a.active{font-weight:700;color:var(--primary)}

/* Theme icon toggle */
.theme-dark .icon-sun,.theme-auto .icon-sun{display:none}
.theme-dark .icon-moon{display:block}
.theme-light .icon-moon{display:none}
.theme-light .icon-sun{display:block}
@media(prefers-color-scheme:dark){
  .theme-auto .icon-sun{display:none}
  .theme-auto .icon-moon{display:block}
}
@media(prefers-color-scheme:light){
  .theme-auto .icon-sun{display:block}
  .theme-auto .icon-moon{display:none}
}

/* === BREADCRUMB === */
.breadcrumb{display:flex;flex-wrap:wrap;list-style:none;font-size:.85rem;color:var(--text-muted);margin-bottom:16px;gap:4px}
.breadcrumb li+li::before{content:"/";margin-inline-end:4px}
.breadcrumb a{color:var(--text-muted)}
.breadcrumb a:hover{color:var(--link)}

/* === HERO (HOME) === */
.hero{text-align:center;padding:32px 0 24px}
.hero h1{font-size:1.8rem;font-weight:800;margin-bottom:8px}
.hero-tagline{color:var(--text-muted);font-size:1.05rem;margin-bottom:24px}
@media(min-width:768px){.hero h1{font-size:2.4rem}}

/* === CONVERTER WIDGET === */
.quick-converter,.converter-widget{background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-lg);padding:20px;box-shadow:var(--shadow);margin-bottom:24px}
.converter-row{display:flex;align-items:flex-end;gap:12px;flex-wrap:wrap}
.converter-input-group{flex:1;min-width:160px;display:flex;flex-direction:column;gap:4px}
.converter-input-group label{font-size:.8rem;font-weight:600;color:var(--text-muted);text-transform:uppercase;letter-spacing:.03em}
.converter-input-group input,.converter-input-group select{width:100%;padding:10px 12px;border:1px solid var(--border);border-radius:var(--radius);background:var(--bg);font-size:1rem;transition:border-color .15s}
.converter-input-group input:focus,.converter-input-group select:focus{outline:none;border-color:var(--border-focus);box-shadow:0 0 0 3px var(--primary-light)}
.converter-result{display:block;padding:10px 12px;border:1px solid var(--border);border-radius:var(--radius);background:var(--bg-alt);font-size:1.15rem;font-weight:600;min-height:44px;word-break:break-all}
.btn-swap{flex-shrink:0;width:44px;height:44px;border:1px solid var(--border);border-radius:50%;background:var(--bg);cursor:pointer;display:flex;align-items:center;justify-content:center;color:var(--primary);transition:all .15s}
.btn-swap:hover{background:var(--primary-light);border-color:var(--primary)}
.converter-actions{display:flex;align-items:center;gap:12px;margin-top:12px;flex-wrap:wrap}
.btn-copy{padding:6px 14px;border:1px solid var(--border);border-radius:var(--radius);background:var(--bg);cursor:pointer;font-size:.85rem;font-weight:500;transition:all .15s}
.btn-copy:hover{background:var(--bg-alt)}
.btn-copy.copied{background:var(--success-light);border-color:var(--success);color:var(--success)}
.decimals-control{display:flex;align-items:center;gap:6px;font-size:.85rem}
.decimals-control select{padding:4px 8px;border:1px solid var(--border);border-radius:var(--radius);background:var(--bg)}
.btn-fav svg{transition:fill .15s}
.btn-fav.active svg{fill:var(--primary);stroke:var(--primary)}

/* === CATEGORY GRID === */
.categories-grid{margin-bottom:32px}
.categories-grid h2,.popular-section h2,.pairs-section h2,.all-units-section h2{font-size:1.25rem;margin-bottom:16px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:12px}
.category-card{display:flex;align-items:center;gap:12px;padding:16px;border:1px solid var(--border);border-radius:var(--radius);background:var(--bg-card);box-shadow:var(--shadow);transition:all .15s;text-decoration:none;color:var(--text)}
.category-card:hover{box-shadow:var(--shadow-lg);border-color:var(--primary);text-decoration:none}
.category-card .card-icon{width:40px;height:40px;border-radius:var(--radius);background:var(--primary-light);display:flex;align-items:center;justify-content:center;color:var(--primary);flex-shrink:0}
.category-card .card-body h3{font-size:.95rem;font-weight:600;margin-bottom:2px}
.category-card .card-body p{font-size:.8rem;color:var(--text-muted);line-height:1.3}

/* === POPULAR/PAIR LINKS === */
.popular-grid,.pairs-grid,.related-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:8px}
.pair-link{display:block;padding:10px 14px;border:1px solid var(--border);border-radius:var(--radius);font-size:.9rem;background:var(--bg-card);transition:all .15s}
.pair-link:hover{border-color:var(--primary);background:var(--primary-light);text-decoration:none}

/* === CONVERSION TABLE === */
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch;margin-bottom:24px}
.conversion-table,.units-table{width:100%;font-size:.9rem}
.conversion-table caption{text-align:start;font-weight:600;margin-bottom:8px;color:var(--text-muted);font-size:.85rem}
.conversion-table th,.conversion-table td,.units-table th,.units-table td{padding:8px 12px;text-align:start;border-bottom:1px solid var(--border)}
.conversion-table th,.units-table th{font-weight:600;background:var(--bg-alt);position:sticky;top:0}
.conversion-table tr:hover td,.units-table tr:hover td{background:var(--bg-alt)}

/* === FORMULA === */
.formula-box{padding:16px;background:var(--bg-alt);border:1px solid var(--border);border-radius:var(--radius);margin-bottom:24px}
.formula-box code{display:block;font-size:1.1rem;font-weight:600;margin-bottom:8px;color:var(--primary)}
.formula-box p{font-size:.9rem;color:var(--text-muted)}

/* === EXAMPLES === */
.examples-list{list-style:none;columns:2;gap:8px}
.examples-list li{padding:6px 0;font-size:.9rem;break-inside:avoid}
@media(max-width:480px){.examples-list{columns:1}}

/* === FAQ === */
.faq-section{margin-bottom:24px}
.faq-item{border:1px solid var(--border);border-radius:var(--radius);margin-bottom:8px;overflow:hidden}
.faq-question{width:100%;padding:14px 16px;background:var(--bg-card);border:none;cursor:pointer;text-align:start;font-weight:600;font-size:.95rem;display:flex;justify-content:space-between;align-items:center;color:var(--text)}
.faq-question::after{content:"+";font-size:1.2rem;color:var(--text-muted);transition:transform .2s}
.faq-item.open .faq-question::after{transform:rotate(45deg)}
.faq-answer{padding:0 16px;max-height:0;overflow:hidden;transition:max-height .3s ease,padding .3s}
.faq-item.open .faq-answer{max-height:200px;padding:0 16px 14px}
.faq-answer p{font-size:.9rem;color:var(--text-muted);line-height:1.6}

/* === ADS === */
.ad-slot{min-height:90px;margin:24px 0;display:flex;align-items:center;justify-content:center;background:var(--bg-alt);border-radius:var(--radius)}

/* === FOOTER === */
.site-footer{border-top:1px solid var(--border);padding:24px 0;margin-top:32px}
.footer-inner{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:12px;font-size:.85rem;color:var(--text-muted)}
.footer-nav{display:flex;gap:16px}
.footer-nav a{color:var(--text-muted)}
.footer-nav a:hover{color:var(--text)}

/* === PAIR PAGE INTRO === */
.pair-intro{font-size:1rem;color:var(--text-muted);margin-bottom:20px;max-width:680px}

/* === RELATED SECTION === */
.related-section,.table-section,.formula-section,.examples-section{margin-bottom:24px}
.related-section h2,.table-section h2,.formula-section h2,.examples-section h2,.faq-section h2{font-size:1.15rem;margin-bottom:12px}

/* === UTILITIES === */
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}
.units-table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}

/* === RESPONSIVE === */
@media(max-width:480px){
  .converter-row{flex-direction:column;align-items:stretch}
  .btn-swap{align-self:center;transform:rotate(90deg)}
  .grid{grid-template-columns:1fr}
  .popular-grid,.pairs-grid,.related-grid{grid-template-columns:1fr}
  .hero h1{font-size:1.4rem}
}
@media(min-width:1024px){
  :root{--gap:24px}
  .grid{grid-template-columns:repeat(4,1fr)}
}
