/*
   UNIT CONVERTER - EXPERT WEB TOOLS
*/

@font-face { font-family: 'Inter'; src: url('/fonts/inter-v20-latin-regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Orbitron'; src: url('/fonts/orbitron-v35-latin-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Roboto Mono'; src: url('/fonts/roboto-mono-v31-latin-regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }

:root {
    /* Dark Theme Variables (Default) */
    --bg-main: #0a0a0f;
    --primary-accent: #3b82f6;
    --secondary-accent: #8b5cf6;
    --text-main: #ffffff;
    --text-muted: #94a3b8;
    --card-bg: rgba(25, 25, 35, 0.6);
    --card-border: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(255, 255, 255, 0.05);
    --option-bg: #1e1e2d;
    --formula-bg: rgba(59, 130, 246, 0.08);
    --hover-bg: rgba(255, 255, 255, 0.1);
    
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-code: 'Roboto Mono', monospace;
}

/* Light Theme Variables scoped to HTML */
html.light-theme {
    --bg-main: #f8fafc;
    --primary-accent: #2563eb;
    --secondary-accent: #7c3aed;
    --text-main: #0f172a;
    --text-muted: #475569;
    --card-bg: #ffffff;
    --card-border: #cbd5e1;
    --input-bg: #f1f5f9;
    --option-bg: #ffffff;
    --formula-bg: #e0e7ff;
    --hover-bg: rgba(0, 0, 0, 0.05);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Prevent global color transition to avoid Chromium text-clip bug */
html, body {
    width: 100%;
    max-width: 100%;
    transition: background-color 0.2s ease;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-accent); }

/* Accessibility */
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; 
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

/* Dynamic Glow */
.background-glow {
    position: fixed; top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle at center, rgba(59,130,246,0.08) 0%, transparent 50%);
    z-index: -1; pointer-events: none; transition: background 0.3s ease;
}
html.light-theme .background-glow {
    background: radial-gradient(circle at center, rgba(37,99,235,0.05) 0%, transparent 50%);
}

/* ============================================================
   HEADER
   ============================================================ */
.tool-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.25rem 1rem; width: 100%; max-width: 1400px; margin: 0 auto;
    flex-wrap: wrap; gap: 8px;
}
.back-btn {
    color: var(--text-muted); text-decoration: none; display: flex; align-items: center; gap: 8px;
    transition: color 0.3s; padding: 8px 4px; min-height: 44px; white-space: nowrap; font-weight: 500;
}
.back-btn:hover { color: var(--primary-accent); }
.back-btn:focus-visible { outline: 2px solid var(--primary-accent); color: var(--primary-accent); }

.logo { font-family: var(--font-heading); font-size: clamp(1rem, 3vw, 1.2rem); white-space: nowrap; margin: 0 auto; }
.logo span { color: var(--primary-accent); }

/* Theme Button (Standardized) */
.theme-toggle-btn { 
    padding: 8px 12px; font-size: 1.2rem; background: transparent; border: 1px solid var(--card-border); 
    color: var(--text-muted); border-radius: 6px; cursor: pointer; display: flex; align-items: center; 
    justify-content: center; min-height: 44px; min-width: 44px; transition: all 0.2s; 
}
.theme-toggle-btn:hover { color: var(--primary-accent); border-color: var(--primary-accent); background: var(--hover-bg); }
.theme-toggle-btn:focus-visible { outline: 2px solid var(--primary-accent); }

/* ============================================================
   MAIN CONTENT WRAPPER
   ============================================================ */
.main-content {
    flex-grow: 1; width: 100%; padding: 1.25rem 1rem; max-width: 1200px; margin: 0 auto;
    min-width: 0; contain: layout;
}

/* ============================================================
   INTRO
   ============================================================ */
.tool-intro { text-align: center; margin-bottom: 1.5rem; }
.tool-intro h1 { font-family: var(--font-heading); font-size: clamp(1.3rem, 4vw, 2rem); margin-bottom: 0.5rem; line-height: 1.2; }
.tool-intro p { color: var(--text-muted); font-size: 0.9rem; }

/* ============================================================
   TOOL LAYOUT
   ============================================================ */
.tool-layout { display: flex; flex-direction: column; gap: 0; width: 100%; min-width: 0; }

/* ============================================================
   CATEGORY SIDEBAR (Mobile 3-Pill Grid)
   ============================================================ */
.category-sidebar {
    position: sticky; top: 0; z-index: 100; background: var(--bg-main); padding: 10px 0 8px; margin-bottom: 1.25rem;
    display: flex; flex-direction: column; gap: 8px; transition: background 0.3s ease;
    margin-left: -1rem; margin-right: -1rem; padding-left: 1rem; padding-right: 1rem; width: calc(100% + 2rem);
}

.search-wrapper { position: relative; width: 100%; display: none; }
.search-wrapper i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
#categorySearch {
    width: 100%; padding: 11px 12px 11px 38px; background: var(--input-bg); border: 1px solid var(--card-border);
    border-radius: 8px; color: var(--text-main); font-size: 0.9rem; outline: none; font-family: var(--font-body); transition: border-color 0.2s;
}
#categorySearch:focus { border-color: var(--primary-accent); }

/* 3 Pills per row on Mobile */
.nav-grid {
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 6px; 
    width: 100%;
}

.nav-btn {
    width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; 
    background: var(--input-bg); border: 1px solid var(--card-border); color: var(--text-muted); 
    padding: 10px 4px; border-radius: 20px; cursor: pointer; font-size: 0.75rem; 
    font-family: var(--font-body); font-weight: 500; transition: all 0.2s; white-space: nowrap; 
    min-height: 40px;
}
.nav-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.nav-btn:focus-visible { outline: 2px solid var(--primary-accent); }
.nav-btn.active { background: rgba(59,130,246,0.15); border-color: rgba(59,130,246,0.5); color: var(--primary-accent); }
.nav-btn i { font-size: 0.8rem; flex-shrink: 0; }

/* ============================================================
   CONVERTER DISPLAY AREA
   ============================================================ */
.converter-display { width: 100%; min-width: 0; }

.converter-card {
    background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 16px; padding: 1.5rem 1.25rem;
    width: 100%; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    opacity: 0; transform: translateY(6px); transition: opacity 0.22s ease, transform 0.22s ease, background 0.3s ease, border-color 0.3s ease; display: none;
}
.converter-card.active { display: block; opacity: 1; transform: translateY(0); }

.card-header { margin-bottom: 1.5rem; border-bottom: 1px solid var(--card-border); padding-bottom: 0.875rem; }
.card-header h2 { font-family: var(--font-heading); font-size: clamp(0.95rem, 2.5vw, 1.25rem); color: var(--text-main); display: flex; align-items: center; gap: 9px; line-height: 1.3; }
.card-header h2 i { color: var(--secondary-accent); flex-shrink: 0; }

.conversion-body { display: flex; flex-direction: column; gap: 1rem; }

.input-group { display: flex; flex-direction: column; gap: 6px; width: 100%; min-width: 0; }
.input-group label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

.input-wrapper { display: flex; position: relative; width: 100%; min-width: 0; }
.input-wrapper input {
    flex: 1; min-width: 0; width: 100%; background-color: var(--input-bg); border: 1px solid var(--card-border);
    color: var(--text-main); padding: 13px 42px 13px 12px; border-radius: 8px; font-size: 1rem; outline: none;
    font-family: var(--font-code); transition: border-color 0.2s;
}
.input-wrapper input:focus { border-color: var(--primary-accent); }

.copy-input-btn {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: none;
    color: var(--text-muted); cursor: pointer; font-size: 0.95rem; width: 34px; height: 34px; display: flex;
    align-items: center; justify-content: center; border-radius: 4px; transition: color 0.2s, background 0.2s;
}
.copy-input-btn:hover { color: var(--primary-accent); background: var(--hover-bg); }
.copy-input-btn:focus-visible { outline: 2px solid var(--primary-accent); }

/* Modern Custom Select Dropdown */
select {
    width: 100%; min-width: 0; background-color: var(--input-bg); border: 1px solid var(--card-border);
    color: var(--text-main); padding: 13px 40px 13px 12px; border-radius: 8px; font-size: 0.9rem; outline: none; 
    font-family: var(--font-body); cursor: pointer; transition: border-color 0.2s; overflow: hidden; text-overflow: ellipsis; 
    -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%2394a3b8%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}
select:focus { border-color: var(--primary-accent); }

/* Custom SVG Arrow for Light Mode */
html.light-theme select {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23475569%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
}

/* Fix Option Contrast */
select option { 
    background-color: var(--option-bg); 
    color: var(--text-main); 
}

.swap-btn {
    align-self: center; background: transparent; border: 1px solid var(--card-border); color: var(--text-muted);
    width: 42px; height: 42px; min-width: 42px; min-height: 42px; border-radius: 50%; cursor: pointer; display: flex;
    align-items: center; justify-content: center; font-size: 0.95rem; transition: all 0.25s; flex-shrink: 0; order: 0;
}
.swap-btn:hover { background: var(--hover-bg); color: var(--text-main); border-color: var(--primary-accent); transform: rotate(180deg); }
.swap-btn:focus-visible { outline: 2px solid var(--primary-accent); }

/* Formula Box */
.formula-box {
    background: var(--formula-bg); border: 1px solid rgba(59,130,246,0.2); padding: 10px 12px; border-radius: 8px;
    font-family: var(--font-code); font-size: clamp(0.72rem, 2vw, 0.82rem); color: var(--primary-accent); text-align: center;
    word-break: break-word; overflow-wrap: break-word; min-height: 40px; display: flex; align-items: center; justify-content: center;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1e1e24; border: 1px solid var(--primary-accent);
    color: #fff; padding: 10px 20px; border-radius: 8px; z-index: 9999; font-size: 0.9rem; pointer-events: none; white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5); transition: opacity 0.3s; opacity: 1;
}
.toast.hidden { opacity: 0; pointer-events: none; display: block !important; }
html.light-theme .toast { background: #ffffff; color: #0f172a; border-color: var(--primary-accent); }

/* ============================================================
   INFO & FAQ SECTION
   ============================================================ */
.info-section { margin-top: 3rem; }
.info-section h2 { font-family: var(--font-heading); color: var(--text-main); margin-bottom: 1.75rem; font-size: 1.3rem; text-align: center; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.info-grid h3 { color: var(--primary-accent); font-family: var(--font-heading); font-size: 0.95rem; margin-bottom: 0.5rem; }
.info-grid i { margin-right: 6px; }
.info-grid p { color: var(--text-muted); font-size: 0.88rem; line-height: 1.65; }
.info-grid code { background: var(--input-bg); padding: 1px 5px; border-radius: 4px; font-family: var(--font-code); font-size: 0.85em; }

.faq-container { margin-top: 2rem; background: var(--card-bg); border: 1px solid var(--card-border); padding: 2rem; border-radius: 16px; }
.faq-container h3 { font-family: var(--font-heading); color: var(--text-main); margin-bottom: 1.5rem; border-bottom: 1px solid var(--card-border); padding-bottom: 0.5rem; }
.faq-container h4 { color: var(--secondary-accent); font-size: 0.95rem; margin-bottom: 0.5rem; margin-top: 1.5rem; font-family: var(--font-body); }
.faq-container p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; line-height: 1.65; }

footer { text-align: center; padding: 2rem 0; color: var(--text-muted); font-size: 0.85rem; border-top: 1px solid var(--card-border); margin-top: 2.5rem; }
footer a { color: var(--primary-accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ============================================================
   DESKTOP LAYOUT (900px+)
   ============================================================ */
@media (min-width: 900px) {
    .main-content { padding: 2rem 2.5rem; }
    .tool-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 2rem; align-items: start; }
    
    .category-sidebar { position: sticky; top: 1rem; background: transparent; padding: 0; margin: 0; width: 100%; box-shadow: none; gap: 1rem; }
    .search-wrapper { display: block; }
    
    /* Revert to vertical list on desktop */
    .nav-grid { 
        display: flex; 
        flex-direction: column; 
        overflow-x: visible; overflow-y: auto; max-height: 70vh; gap: 4px; padding-bottom: 0; 
    }
    .nav-btn { 
        justify-content: flex-start; /* Left-align desktop nav */
        border-radius: 8px; padding: 10px 14px; font-size: 0.9rem; min-height: 44px; width: 100%; 
    }
    
    .converter-card { padding: 2rem 2.5rem; max-width: 600px; }
    .card-header h2 { font-size: 1.25rem; }
}

@media (max-width: 480px) {
    .tool-header { padding: 1rem; align-items: center; justify-content: space-between; }
    .logo { margin: 0; }
    .faq-container { padding: 1.5rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
    .swap-btn:hover { transform: none; }
}