/* --- GLOBAL HEADER SETTINGS --- */
.global-settings { 
    display: flex; 
    gap: 10px; 
}
.header-select {
    background-color: #fceeed;
    color: #121212;
    border: 1px solid #f2e1e3;
    padding: 6px 25px 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    background-position: right 8px top 50%;
    background-size: 10px;
}
.header-select:hover {
    border-color: #d98a94;
}

/* --- UNIVERSAL VARIABLES & RESET --- */
:root { 
    --primary: #121212; /* Technocorp Deep Charcoal */
    --bg: #fdf8f9; /* Very subtle pink tint for the whole page */
    --card: #ffffff; 
    --text: #333333; 
    --border: #f2e1e3; /* Soft pink border */
    --hover: #fceeed; /* Technocorp Pale Pink */
}
body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    background-color: var(--bg); 
    color: var(--text); 
    margin: 0; 
    padding: 0; 
}

/* Add this small fix to ensure the export button stays visible on hover */
.btn-export:hover { background: #333333; }

/* --- NAVIGATION BAR --- */
.navbar { background-color: var(--card); padding: 15px 30px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 4px rgba(0,0,0,0.05); position: sticky; top: 0; z-index: 100; }
.nav-brand a { text-decoration: none; font-size: 1.2rem; font-weight: bold; color: var(--primary); }
.nav-links { display: flex; gap: 20px; align-items: center; }
.nav-links a { text-decoration: none; color: var(--text); font-weight: 500; }
.nav-links a:hover { color: var(--primary); }
.dropdown { position: relative; display: inline-block; }
.dropbtn { background: none; border: none; font-size: 1rem; font-weight: 500; color: var(--text); cursor: pointer; padding: 0; font-family: inherit; }
.dropdown-content { display: none; position: absolute; right: 0; top: 100%; background-color: var(--card); min-width: 200px; box-shadow: 0 8px 16px rgba(0,0,0,0.1); border-radius: 8px; overflow: visible; z-index: 1; }
.dropdown-content a { color: var(--text); padding: 12px 16px; text-decoration: none; display: block; border-bottom: 1px solid var(--border); }
.dropdown:hover .dropdown-content { display: block; }

/* --- NESTED FLYOUT MENU --- */
.nested-dropdown { position: relative; }
.nested-dropbtn { display: flex !important; justify-content: space-between; align-items: center; cursor: pointer; }
.nested-dropdown-content { 
    display: none; 
    position: absolute; 
    left: 100%; /* Makes it open to the right side */
    top: 0; 
    background-color: var(--card); 
    min-width: 220px; 
    box-shadow: 0 8px 16px rgba(0,0,0,0.1); 
    border-radius: 8px; 
    overflow: hidden; 
    z-index: 2; 
    border: 1px solid var(--border);
}
.nested-dropdown:hover .nested-dropdown-content { display: block; }
.nested-dropdown-content a { color: var(--text); padding: 12px 16px; text-decoration: none; display: block; border-bottom: 1px solid var(--border); }
.nested-dropdown-content a:hover { background-color: #f8fafc; color: var(--primary); }

/* --- CALCULATOR CONTAINERS & GRIDS --- */
.container { max-width: 1000px; margin: 40px auto; background: var(--card); padding: 30px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.input-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-bottom: 30px; }
.summary-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 30px; }

/* --- INPUTS & CARDS --- */
.input-group label { display: block; font-weight: 600; margin-bottom: 8px; color: #475569; }
.slider-row { display: flex; align-items: center; gap: 10px; position: relative; }
.input-wrapper { position: relative; width: 140px; }
.input-wrapper input { width: 100%; padding: 8px 25px 8px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 15px; box-sizing: border-box; }
input.has-prefix { padding-left: 25px; }
.input-wrapper .suffix { position: absolute; right: 10px; top: 55%; transform: translateY(-50%); color: #64748b; font-weight: bold; pointer-events: none; }
.input-wrapper .prefix { position: absolute; left: 10px; top: 45%; transform: translateY(-50%); color: #64748b; font-weight: bold; pointer-events: none; }
input[type="range"] { flex-grow: 1; cursor: pointer; }

.card { background: #f1f5f9; padding: 20px; border-radius: 8px; text-align: center; border: 1px solid var(--border); }
.card h4 { margin: 0 0 10px 0; color: #64748b; font-size: 14px; text-transform: uppercase; }
.card .value { font-size: 22px; font-weight: bold; color: var(--primary); }

/* --- HOMEPAGE SPECIFIC STYLES --- */
.hero { text-align: center; padding: 60px 20px 40px; }
.hero h1 { color: var(--primary); font-size: 2.5rem; margin-bottom: 10px; }
.hero p { color: #4a3639; font-size: 1.1rem; max-width: 600px; margin: 0 auto; } /* Warmer dark tone */

.tools-grid { max-width: 1000px; margin: 0 auto 60px; padding: 0 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 25px; }

.tool-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 30px; text-decoration: none; color: inherit; transition: all 0.3s ease; display: block; box-shadow: 0 4px 6px rgba(0,0,0,0.02); }
/* Added a soft dusty rose glow on hover! */
.tool-card:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(217, 138, 148, 0.15); border-color: #d98a94; } 
.tool-card h3 { color: var(--primary); margin-top: 0; font-size: 1.4rem; margin-bottom: 10px;}
.tool-card p { color: #5a4b4d; margin: 0; line-height: 1.5; }

/* The "Live" Badges updated to Pale Pink & Dusty Rose */
.status-badge { display: inline-block; background: #fceeed; color: #d98a94; border: 1px solid #f2e1e3; font-size: 0.75rem; padding: 4px 8px; border-radius: 4px; font-weight: bold; margin-bottom: 15px; }

/* --- EMI CALCULATOR SPECIFIC STYLES --- */

/* Top Controls & Export Button */
.top-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 15px; }
.toggle-group { display: flex; gap: 15px; background: #f1f5f9; padding: 10px; border-radius: 6px; border: 1px solid var(--border); }
.toggle-group label { cursor: pointer; font-weight: 500; font-size: 14px; }

.btn-export { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-weight: bold; transition: background 0.3s; }
.btn-export:hover { background: #1d4ed8; }

/* EMI Bar Chart Wrapper */
.chart-container { position: relative; width: 100%; height: 400px; margin-bottom: 40px; display: block; }
@media (max-width: 600px) {
    .chart-container { height: 300px; margin-bottom: 20px; }
}

/* Amortization Table */
.table-container { overflow-x: auto; margin-top: 20px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--card); }
th, td { border: 1px solid var(--border); padding: 12px; text-align: center; }
th { background-color: var(--primary); color: white; position: sticky; top: 0; z-index: 10; }
.year-row { background-color: #f8fafc; font-weight: bold; cursor: pointer; transition: background 0.2s; }
.year-row:hover { background-color: #e2e8f0; }
.year-row td:first-child::after { content: ' ▼'; font-size: 10px; color: #64748b; }
.month-row { background-color: #ffffff; font-size: 13px; color: #475569; }
.hidden { display: none; }

/* --- FIXES FOR INPUTS & DROPDOWNS --- */

/* 1. Hide number input arrows to prevent overlap */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
input[type=number] {
    -moz-appearance: textfield; /* Firefox */
}

/* 2. Style Dropdowns to perfectly match text inputs */
select {
    width: 100%;
    padding: 8px 30px 8px 8px; /* Extra right padding for the arrow */
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 15px;
    box-sizing: border-box;
    background-color: var(--card);
    color: var(--text);
    font-family: inherit;
    appearance: none; /* Removes old Windows/Mac default styling */
    background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="%2364748b" viewBox="0 0 16 16"><path d="M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px top 50%;
    background-size: 12px;
    cursor: pointer;
}
select:focus { outline: none; border-color: #121212; }

/* --- MENSURATION VISUALIZER LAYOUT --- */
.geometry-workspace { display: flex; gap: 30px; align-items: stretch; margin-bottom: 30px; }
.geometry-controls { flex: 1; display: flex; flex-direction: column; gap: 20px; }
.geometry-visualizer { flex: 1; background: #ffffff; border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; min-height: 350px; position: relative; }
.geometry-visualizer svg { max-width: 100%; max-height: 200px; margin-bottom: 20px; }

/* Visualizer dynamic labels */
.vis-labels { text-align: center; width: 100%; }
.vis-labels .badge { display: inline-block; background: #fceeed; color: #121212; padding: 4px 10px; border-radius: 4px; font-size: 13px; font-weight: bold; margin: 5px; border: 1px solid #d98a94; }

@media (max-width: 768px) {
    .geometry-workspace { flex-direction: column; }
    .geometry-visualizer { min-height: 250px; }
}

/* --- ADVERTISEMENT PLACEHOLDERS --- */
.page-wrapper {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

.main-content-area {
    flex: 1;
    max-width: 1100px; /* Keeps your calculators the perfect size */
}

/* The Ad Boxes */
.ad-space {
    background-color: #f8fafc;
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Top Leaderboard (Standard 728x90) */
.ad-top {
    width: 100%;
    max-width: 728px;
    height: 90px;
    margin: 0 auto 20px auto;
}

/* Side Skyscrapers (Standard 160x600) */
.ad-side {
    width: 160px;
    height: 600px;
    flex-shrink: 0;
    position: sticky;
    top: 100px; /* Keeps the ad on screen when scrolling */
}

/* Hide side ads on mobile/tablets so they don't break the screen */
@media (max-width: 1200px) {
    .ad-side { display: none; }
}
/* =========================================
   DESKTOP HEADER BASE STYLES 
   ========================================= */

/* 1. Force the main header into a clean left-center-right row */
.header-container {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background: #fff;
}

/* 2. Remove all ugly bullet points from the navigation */
header nav ul, 
.nav-links, 
.dropdown-content, 
.sub-menu {
    list-style: none !important;
    padding: 0;
    margin: 0;
}

/* 3. Sit the Home and Calculators links side-by-side */
.nav-links {
    display: flex;
    align-items: center;
    gap: 30px;
}

/* 4. Fix the stretched Currency/Numbering Dropdowns */
.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}
.header-controls select {
    width: auto !important; /* Stops them from taking 100% of the screen */
    min-width: 120px;
}

/* 5. Desktop Dropdown Logic (Float below and to the right) */
.dropdown { position: relative; }

.dropdown-content {
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    min-width: 220px;
    border: 1px solid #f1f5f9;
    border-radius: 8px;
    display: none; /* Hidden until clicked */
    z-index: 100;
}

.nested-dropdown { position: relative; }

.sub-menu {
    position: absolute;
    top: 0;
    left: 100%; /* Flies out to the right on desktop */
    background: #fff;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    min-width: 220px;
    border: 1px solid #f1f5f9;
    border-radius: 8px;
    display: none;
    z-index: 101;
}

/* 6. Clean up the links inside the dropdowns */
.dropdown-content a, .sub-menu a {
    display: block;
    padding: 12px 20px;
    color: #475569;
    text-decoration: none;
    border-bottom: 1px solid #f8fafc;
}

.dropdown-content a:hover, .sub-menu a:hover {
    background-color: #f8fafc;
    color: var(--primary);
}

/* Show the menus when the JS adds the 'show' class */
.dropdown-content.show, .sub-menu.show {
    display: block;
}
/* =========================================
   MOBILE HEADER OPTIMIZATION (STACKED)
   ========================================= */
@media (max-width: 768px) {
    /* 1. Stack the header vertically to give everything room to breathe */
    header, 
    .header-container, 
    #header-placeholder > div {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        padding: 15px 10px !important;
        height: auto !important; /* Allows the header to grow vertically */
        
        /* THE DROPDOWN FIX: Stops the menu from being cut off when clicked */
        overflow: visible !important; 
        z-index: 9999 !important;
    }

    /* 2. Let the logo span clearly on its own line */
    .logo, 
    .brand-title, 
    header h1,
    header a.logo-link {
        font-size: 1.5rem !important;
        white-space: nowrap !important;
        margin-bottom: 10px !important;
        text-align: center !important;
    }

    /* 3. Group the links and dropdowns neatly below the logo */
    header nav, 
    .nav-links, 
    .header-controls,
    header div {
        display: flex !important;
        flex-wrap: wrap !important; /* Allows wrapping if the phone is super narrow */
        justify-content: center !important;
        align-items: center !important;
        gap: 12px !important;
        width: 100% !important;
    }

    /* 4. Fix dropdown tap behavior and visibility */
    header select {
        height: 35px !important;
        font-size: 14px !important;
        padding: 0 25px 0 10px !important;
        background-color: #fff !important;
        color: #333 !important;
        /* Ensures the dropdown stays above everything else when clicked */
        position: relative !important; 
        z-index: 10000 !important;
    }
    /* 5. Fix the Dropdown Menu flying off to the side */
    .dropdown-content, 
    header nav ul ul,
    .sub-menu {
        position: relative !important; /* Stops it from floating to the right */
        display: flex !important;
        flex-direction: column !important; /* Stacks the calculator links vertically */
        width: 100% !important;
        min-width: 100% !important;
        box-shadow: none !important; /* Removes the floating shadow box */
        background: transparent !important;
        padding: 0 !important;
        margin-top: 10px !important;
    }

    /* 6. Neatly space the individual links inside the dropdown */
    .dropdown-content a, 
    header nav ul ul a,
    .sub-menu a {
        text-align: center !important;
        padding: 10px !important;
        border-bottom: 1px solid #f1f5f9 !important; /* Adds a nice divider line */
        font-size: 14px !important;
        white-space: normal !important; /* Allows long names to wrap if needed */
    }
    /* 7. Fix Nested Sub-Menus (Level 3) flying out to the side */
    header nav ul ul ul,
    .sub-menu .sub-menu,
    .dropdown-content .dropdown-content,
    .dropdown-content ul {
        position: relative !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        box-shadow: none !important;
        background: transparent !important;
        /* Adds a left indent so users can tell it's a sub-menu */
        padding-left: 15px !important; 
        margin-top: 0 !important;
    }
    
    /* Ensure the sub-menu links match the mobile layout */
    header nav ul ul ul a,
    .sub-menu .sub-menu a {
        text-align: center !important;
        font-size: 13px !important; /* Slightly smaller to show hierarchy */
        padding: 8px !important;
        background-color: #f8fafc !important; /* Light background for contrast */
        border-radius: 4px;
        margin-bottom: 2px;
    }
    /* Force dropdowns to stack natively on mobile */
    .dropdown-content.show,
    .sub-menu.show {
        display: flex !important;
        flex-direction: column !important;
        position: relative !important;
        background: transparent !important;
        box-shadow: none !important;
        left: 0 !important;
        top: 0 !important;
        padding-left: 15px !important; /* Indents the nested menu */
    }

    /* Hide them when not clicked */
    .dropdown-content, .sub-menu {
        display: none !important; 
    }
}

.sub-menu {
    position: absolute;
    left: 100%;
    top: 0;
    display: none;
    background: #ffffff;
    border: 1px solid var(--border);
    min-width: 200px;
}
.nested-dropdown:hover > .sub-menu {
    display: block;
}