/* =========================================
   1. DESIGN TOKENS & VARIABLES
   ========================================= */
:root {
    --primary: #4f46e5;      
    --primary-dark: #4338ca;  
    --accent: #ec4899;        
    
    --bg-body: #f3f4f6;       
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-sidebar: #ffffff;
    
    --text-main: #111827;     
    --text-muted: #374151;    
    
    --border-subtle: #e5e7eb;
    
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-sidebar: 4px 0 15px rgba(0,0,0,0.1);
    
    --radius-md: 12px;        
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --header-height: 70px; 
}

body.dark-mode {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-header: #1e293b;
    --bg-sidebar: #1e293b;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --border-subtle: #374151;
}

/* =========================================
   2. RESET & BASE (GLOBAL OVERFLOW FIX)
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%;
    /* CRITICAL: This prevents the page from zooming out or shifting left */
    overflow-x: hidden; 
    position: relative;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; transition: 0.2s; }

/* =========================================
   3. HEADER & NAV
   ========================================= */
.header {
    position: fixed; top: 0; left: 0; width: 100%;
    height: var(--header-height);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-subtle);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; z-index: 100;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.brand-logo {
    font-size: 1.4rem; font-weight: 800;
    color: var(--text-main); display: flex; align-items: center; gap: 8px;
}
.brand-logo i { color: var(--accent); }

.menu-btn, .theme-btn, .icon-btn {
    background: none; border: none; cursor: pointer;
    font-size: 1.4rem; color: var(--text-main);
    padding: 8px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
}
.menu-btn:hover, .theme-btn:hover, .icon-btn:hover { background-color: rgba(0,0,0,0.05); }

/* Sidebar & Overlay */
.menu-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 150;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.menu-overlay.active { opacity: 1; pointer-events: auto; }

.sidebar {
    position: fixed; top: 0; left: 0; width: 280px; height: 100%;
    background: var(--bg-sidebar); z-index: 200;
    box-shadow: var(--shadow-sidebar);
    transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column;
}
.sidebar.active { transform: translateX(0); }

.sidebar-header {
    height: var(--header-height); border-bottom: 1px solid var(--border-subtle);
    display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
}
.sidebar-links { list-style: none; padding: 20px; }
.sidebar-links li { margin-bottom: 10px; }
.sidebar-links a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-radius: 8px; font-weight: 600; color: var(--text-main);
}
.sidebar-links a:hover { background-color: rgba(79, 70, 229, 0.1); color: var(--primary); }
.sidebar-links i { width: 24px; text-align: center; }

/* =========================================
   4. LAYOUT & GRID SYSTEMS
   ========================================= */
.main-content { margin-top: var(--header-height); padding: 20px; flex: 1; }
.content-wrapper { max-width: 1200px; margin: 0 auto; width: 100%; }

/* --- HOME PAGE HERO --- */
.hero-section { text-align: center; padding: 60px 20px 40px; background: var(--bg-body); }
.hero-title { font-size: 2.5rem; font-weight: 800; margin-bottom: 16px; color: var(--text-main); }
.hero-subtitle { font-size: 1.25rem; color: var(--text-muted); max-width: 600px; margin: 0 auto 40px; line-height: 1.6; }

/* --- TOOL PAGE MINI HERO (Global) --- */
.tool-hero {
    text-align: center; padding: 30px 20px 20px; background: var(--bg-body);
}
.tool-hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: 10px; color: var(--text-main); }
.tool-hero p { font-size: 1rem; color: var(--text-muted); max-width: 600px; margin: 0 auto 20px; line-height: 1.5; }

/* --- HOME PAGE GRID --- */
.grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }

.tool-card {
    background: var(--bg-card); padding: 30px 20px; border-radius: var(--radius-md);
    text-align: center; border: 1px solid transparent; box-shadow: var(--shadow-card);
    cursor: pointer; transition: all 0.2s ease; display: flex; flex-direction: column;
    align-items: center; justify-content: center; height: 100%; color: var(--text-main);
}
.tool-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-hover); border-color: var(--primary); }
.tool-card i { font-size: 2.5rem; margin-bottom: 16px; color: var(--primary); }
.tool-card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.tool-card p { font-size: 0.9rem; color: var(--text-muted); line-height: 1.4; }

/* --- GLOBAL TOOL LAYOUT (The Responsive Swapper) --- */
.tool-layout { display: grid; grid-template-columns: 1fr; gap: 30px; }

/* Desktop: Swap Content Left / Tool Right */
@media(min-width: 900px) {
    .tool-layout { grid-template-columns: 1fr 350px; align-items: start; }
    .content-panel { grid-column: 1; grid-row: 1; }
    .tool-panel { grid-column: 2; grid-row: 1; }
}

.tool-panel {
    background: var(--bg-card); padding: 24px; border-radius: var(--radius-md);
    box-shadow: var(--shadow-card); border: 1px solid var(--border-subtle);
    width: 100%; box-sizing: border-box;
}

.content-panel {
    background: var(--bg-card); padding: 40px; border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle); width: 100%; box-sizing: border-box;
}
.content-panel h2 { margin-bottom: 16px; font-size: 1.8rem; }
.content-panel p { margin-bottom: 20px; line-height: 1.7; color: var(--text-main); }
.content-panel ul { margin-left: 20px; margin-bottom: 20px; line-height: 1.6; }

/* =========================================
   5. GLOBAL TOOL INPUT STYLES
   ========================================= */
.input-group { margin-bottom: 16px; width: 100%; }
.input-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.input-group input, 
.input-group select, 
.tool-input {  /* <-- We added this single line */
    width: 100%; 
    padding: 10px; 
    border: 1px solid var(--border-subtle);
    border-radius: 6px; 
    background: var(--bg-body); 
    color: var(--text-main);
    box-sizing: border-box; 
    font-size: 1rem;
}
.btn-calc {
    width: 100%; padding: 12px; background: var(--primary); color: white;
    font-weight: 600; border: none; border-radius: 6px; cursor: pointer; margin-top: 10px;
}
.btn-calc:hover { background: var(--primary-dark); }

/* --- GLOBAL TOOL GRID (Use this inside tools for inputs) --- */
.tool-grid {
    display: grid; 
    /* Default: 2 columns, but safe for small screens */
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); 
    gap: 15px; margin-bottom: 20px;
}

/* =========================================
   6. FOOTER & EXTRAS
   ========================================= */
.footer {
    background: var(--bg-card); border-top: 1px solid var(--border-subtle);
    padding: 40px 20px; text-align: center; margin-top: auto;
}
.footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 20px; margin-top: 20px; }

/* Search Modal */
.search-modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2000; justify-content: center; align-items: flex-start; padding-top: 100px;
    opacity: 0; transition: opacity 0.3s ease;
}
.search-modal.open { opacity: 1; }
.search-modal-bg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px); }
.search-modal-content {
    position: relative; z-index: 50; width: 90%; max-width: 600px;
    background: var(--bg-card); border-radius: var(--radius-md);
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); transform: translateY(-20px); transition: transform 0.3s ease;
}
.search-modal.open .search-modal-content { transform: translateY(0); }
.search-bar-wrapper { display: flex; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--border-subtle); }
.search-bar-wrapper input { flex: 1; border: none; font-size: 1.2rem; background: transparent; color: var(--text-main); outline: none; }
.search-results { max-height: 300px; overflow-y: auto; }
.search-result-item { padding: 15px 20px; cursor: pointer; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 10px; }
.search-result-item:hover { background: var(--bg-body); color: var(--primary); }

/* Cookie Banner */
.cookie-banner {
    position: fixed; bottom: 20px; right: 20px; max-width: 400px;
    width: calc(100% - 40px); background: var(--bg-card);
    border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
    box-shadow: var(--shadow-hover); padding: 24px; z-index: 2500;
    transform: translateY(150%); transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column; gap: 16px;
}
.cookie-banner.show { transform: translateY(0); }
.cookie-buttons { display: flex; gap: 12px; }
.cookie-btn { flex: 1; padding: 12px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.btn-accept { background: var(--primary); color: white; border: none; }
.btn-reject { background: transparent; border: 1px solid var(--border-subtle); color: var(--text-muted); }

/* =========================================
   7. CRITICAL MOBILE FIXES (Small Screens)
   ========================================= */
@media (max-width: 480px) {
    /* 1. Base Container Padding (Keeps Tool Pages normal) */
    .main-content { padding: 10px !important; }
    
    /* 2. HOME PAGE SPECIFIC FIX: Adds extra gap to the sides of the grid */
    .grid-container {
        padding-left: 12px; 
        padding-right: 12px;
        gap: 15px; /* Adds space between the cards themselves */
    }
    
    /* 3. Shrink Panels to fit iPhone SE (320px) */
    .tool-panel { padding: 15px !important; }
    .content-panel { padding: 20px !important; }
    
    /* 4. Force Tool Grid to 1 Column on tiny screens */
    .tool-grid { grid-template-columns: 1fr !important; }
    
    /* 5. Fix Hero Font Size */
    .hero-title, .tool-hero h1 { font-size: 1.8rem !important; }
    
    /* 6. Ensure Inputs don't overflow */
    .input-group input, .input-group select { font-size: 16px; width: 100%; }
}

/* =========================================
   8. REPAIRS & MOBILE FIXES (Add to bottom)
   ========================================= */

/* FIX 1: Hero Search Bar Design (Restored) */
.hero-search-wrapper {
    position: relative;
    max-width: 500px;
    margin: 30px auto 0;
    width: 100%;
}
.hero-search-wrapper input {
    width: 100%;
    padding: 16px 20px;
    padding-right: 50px; /* Space for icon */
    font-size: 1rem;
    border: 2px solid var(--border-subtle);
    border-radius: 50px; /* Pill shape */
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: var(--shadow-card);
    outline: none;
    transition: all 0.2s ease;
}
.hero-search-wrapper input:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-hover);
}
.hero-search-wrapper i {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 1.2rem;
    pointer-events: none;
}

/* FIX 2: Menu Cross Button (Restored) */
.sidebar-header .close-btn {
    background: transparent;
    border: none;
    font-size: 1.8rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}
.sidebar-header .close-btn:hover {
    color: var(--accent);
}

/* FIX 3: iPhone SE & Small Mobile Layout Shift */
@media (max-width: 380px) {
    /* Tighten Header to prevent overflow on 320px screens */
    .header {
        padding: 0 10px; /* Reduced from 20px */
    }
    .brand-logo {
        font-size: 1.2rem; /* Slightly smaller logo */
    }
    .menu-btn, .theme-btn, .icon-btn {
        padding: 5px; /* Smaller touch targets */
        font-size: 1.2rem;
    }
    
    /* Ensure tool container doesn't push width */
    .tool-panel, .content-panel {
        padding: 15px 12px !important; /* Tighter padding */
    }
    
    /* Force inputs to fit */
    .input-group input, .input-group select {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* =========================================
   9. UNIVERSAL RESPONSIVENESS POLISH
   ========================================= */

/* RULE 1: Standardize Container Padding Globally */
/* This ensures standard gap on sides for ALL devices (Home & Tools) */
.content-wrapper {
    width: 100%;
    margin: 0 auto;
    /* Keeps content from touching the edges on Tablets/Laptops */
    padding-left: 20px;
    padding-right: 20px;
}

/* RULE 2: Image Safety */
/* Prevents any image from ever breaking the layout on small screens */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* RULE 3: Touch Target Safety (For Mobile/Tablets) */
/* Ensures buttons are easy to tap on touchscreens */
button, input, select, .tool-card {
    min-height: 44px; /* Apple's recommended minimum touch size */
}

/* RULE 4: The "Home Grid" Specific Gap (Your Request) */
/* On Mobile, we give the grid a bit more breathing room on the sides */
@media (max-width: 480px) {
    .grid-container {
        gap: 20px; /* Space between cards */
        /* Extra padding on sides so cards don't touch screen edges */
        padding-left: 10px; 
        padding-right: 10px;
    }


    /* Inside the last @media (max-width: 480px) block at the bottom of style.css */

    .grid-container {
        gap: 20px; 
        /* Side gaps */
        padding-left: 10px; 
        padding-right: 10px;
        
        /* NEW: Bottom gap to separate grid from footer */
        padding-bottom: 20px; 
    }
    
    /* Reset the wrapper padding so we don't have double padding */
    .content-wrapper {
        padding-left: 0;
        padding-right: 0;
    }
}