@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ============================================================
   CALCHUB MASTER STYLESHEET (SOURCE OF TRUTH)
   ============================================================ */

:root {
  /* COLORS (Preserved) */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f4f6f8;
  --surface: #f8f8f8;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #cbd5e1;
  --nav-bg: rgba(255, 255, 255, 0.9);
  --danger: #ef4444;

  /* TYPOGRAPHY & TRANSITIONS */
  --font-main: 'Inter', sans-serif;
  --transition: 0.3s ease;

  /* ADVANCED SCALE (Spacing, Radius, Shadows) */
  --space-1: 4px; --space-2: 8px; --space-3: 12px;
  --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --space-7: 40px; --space-8: 48px; --space-9: 64px;

  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px;
  --radius-xl: 18px; --radius-pill: 999px;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 12px 30px rgba(0,0,0,0.12);
}

/* DARK THEME */
[data-theme="dark"] {
    --bg: #020617;
    --surface: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --nav-bg: rgba(15, 23, 42, 0.9); 
}

/* ============================================================
   GLOBAL FOUNDATION SYSTEM
   ============================================================ */

/* Performance-Safe Transitions */
* {
    transition-property: background-color, color, border-color, box-shadow;
    transition-duration: var(--transition);
    transition-timing-function: ease;
}

/* Smooth Scroll */
html {
    scroll-behavior: smooth;
}

/* Accessibility Focus System */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Mobile UI Cleanliness */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Global Reset */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: var(--font-main); 
}

/* Body Structure for Footer Animation */
body { 
    background-color: var(--bg); 
    color: var(--text-main); 
    line-height: 1.6; 
    transition: background var(--transition); 
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   GLOBAL PAGE STRUCTURE (ENGINE SAFE VERSION)
   ============================================================ */

.page-container {
    width: 100%;
    padding: var(--space-6) var(--space-5);
}

/* SAFE VERTICAL RHYTHM (ONLY FOR MAIN SECTIONS) */
.page-container > * {
    margin-top: var(--space-7);
}

/* FIRST CHILD CLEAN RESET */
.page-container > *:first-child {
    margin-top: 0;
}

/* ENGINE SAFETY RULE (IMPORTANT) */
.page-container .ad-slot,
.page-container .header-ad-section,
.page-container .footer-ad-section {
    margin-top: var(--space-5);
    margin-bottom: var(--space-5);
}

/* GLOBAL CONTENT CONTAINER */
.container { 
    width: 100%;
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 0 var(--space-4); /* 🔥 Optimized using variable system */
}



/* GLOBAL LAYOUT SYSTEM */
.main-layout {
    display: grid;
    /* Main content takes remaining space (1fr), Sidebar is fixed (320px) */
    grid-template-columns: 1fr 320px; 
    gap: var(--space-6);
    max-width: 1200px; 
    margin: 0 auto;    
    padding: var(--space-9) var(--space-4);
    /* CHANGE THIS from 'start' to 'stretch' */
    align-items: stretch; 
}

/* ============================================================
   TABLET & MOBILE LAYOUT FIX (CLEAN + STABLE)
============================================================ */

@media (max-width: 900px) {

    .main-layout {
        grid-template-columns: 1fr;
        gap: var(--space-6);
    }

    .main-content {
        grid-column: auto;
        width: 100%;
    }

    .sidebar-area {
        grid-column: auto;   /* ❌ FIX: removed column 2 bug */
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: var(--space-4);
        margin-top: var(--space-6);
    }
}

/* MAIN CONTENT */
main { 
    flex: 1; /* Keeps the sticky footer logic */
    padding-top: var(--space-6); /* Use your existing variable system */
}

.hero-section { 
    padding: 80px 0 40px; 
    text-align: center; 
}

.hero-section h1 { 
    font-size: 2.8rem; 
    font-weight: 800; 
    margin-bottom: 12px; 
    color: var(--text-main); 
}

.hero-section p { 
    color: var(--text-muted); 
    font-size: 1.1rem; 
    margin-bottom: 35px; 
}

/* SEARCH BOX */
.search-wrapper { 
    position: relative; 
    width: 60%; 
    margin: 0 auto; 
}

.search-icon { 
    position: absolute; 
    left: 18px; 
    top: 50%; 
    transform: translateY(-50%); 
    width: 20px; 
    height: 20px; 
    color: var(--text-muted); 
    opacity: 0.6; 
    pointer-events: none; 
    z-index: 10; 
}

.search-input { 
    width: 100%; 
    padding: 16px 24px 16px 52px; 
    border-radius: 16px; 
    border: 2px solid var(--border); 
    background: var(--surface); 
    color: var(--text-main); 
    outline: none; 
    transition: var(--transition); 
}

.search-input:focus { 
    border-color: var(--primary); 
}

@media (max-width: 768px) { 
    .search-wrapper { 
        width: 90%; 
    } 
}

/* CATEGORY FILTERS */
.category-filter { 
    display: flex; 
    justify-content: center; 
    gap: 8px; 
    flex-wrap: wrap; 
    margin-bottom: 40px; 
}

.cat-pill { 
    padding: 8px 18px; 
    border-radius: 99px; 
    background: var(--surface); 
    border: 1px solid var(--border); 
    font-size: 0.85rem; 
    font-weight: 600; 
    color: var(--text-muted); 
    cursor: pointer; 
    transition: var(--transition); 
}

.cat-pill.active { 
    background: var(--primary); 
    color: white; 
    border-color: var(--primary); 
}

.tool-card-container {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Inputs on left, Results on right */
    gap: 20px;
}

/* On mobile, stack them */
@media (max-width: 768px) {
    .tool-card-container {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   GLOBAL RESPONSIVE OVERRIDES
   ============================================================ */

@media (max-width: 768px) {
    .page-container {
        padding: var(--space-5) var(--space-3);
    }
}





/* ============================================================
   UNIFIED ARTICLE SYSTEM (CALCHUB FLAT & CENTERED)
   ============================================================ */

/* MAIN CONTAINER: Centers the article and removes the "card" look */
.article-section.is-centered, 
.content-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: var(--space-10, 30px); /* Gap below tool card */
    background: none;
    border: none;
    box-shadow: none;
}

/* INTERNAL CONTAINER: Matches the 860px Tool Card width */
.article-container, 
.article-content {
    width: 100%;
    max-width: 920px; /* Increased slightly for a more open feel */
    padding: var(--space-8) var(--space-5);
    box-sizing: border-box;
    /*border-top: 1px solid var(--border);*/ /* Subtle divider from the tool above */
    line-height: 1.8;
}

/* HEADINGS: Unified for Homepage and Tool Pages */
.article-header { 
    text-align: center; 
    margin-bottom: var(--space-8); 
}

.article-header h2, 
.article-container h2,
.article-content h2 { 
    font-size: 2.2rem; 
    font-weight: 800; 
    color: var(--text-main); 
    margin-bottom: var(--space-3); 
    line-height: 1.2; 
}

.article-container h3,
.article-content h3 { 
    font-size: 1.6rem; 
    color: var(--text-main); 
    margin: var(--space-8) 0 var(--space-4); 
    font-weight: 700; 
}

/* BODY TEXT */
.article-container p,
.article-content p { 
    font-size: 1.05rem; 
    color: var(--text-muted); 
    margin-bottom: var(--space-5); 
}

/* LISTS: Unified spacing for bullet points */
.article-container ul,
.article-content ul,
.article-container ol,
.article-content ol {
    margin-bottom: var(--space-6);
    padding-left: var(--space-6);
}

.article-container li,
.article-content li {
    margin-bottom: var(--space-3);
    color: var(--text-muted);
}

/* ============================================================
   TABLE SYSTEM (OPTIMIZED & CONSOLIDATED)
============================================================ */

/* 1. WRAPPER (REQUIRED FOR MOBILE) */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: var(--space-6) 0;
}

/* 2. TABLE BASE */
.benchmark-table {
    width: 100%;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-md);
    overflow: hidden;
}

/* 3. CELL & HEADER SYSTEM */
.benchmark-table th,
.benchmark-table td {
    padding: 12px 15px !important;
    text-align: center !important;
    vertical-align: middle !important;
    border-right: 1px solid var(--border) !important;
    border-bottom: 1px solid var(--border) !important;
    color: var(--text-muted); /* Default body text color */
}

/* 4. CLEANUP (REMOVE LAST BORDERS) */
.benchmark-table th:last-child,
.benchmark-table td:last-child {
    border-right: none !important;
}

.benchmark-table tr:last-child td {
    border-bottom: none !important;
}

/* 5. HEADER STYLE */
.benchmark-table thead th {
    background: var(--bg);
    color: var(--text-main);
    font-weight: 600;
}

/* ============================================================
   FAQ SYSTEM (BULLETPROOF GAP FIX)
============================================================ */

/* 1. Ensure the parent acts as a vertical stack */
.faq {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* 2. Apply margin to every item, except the last one */
.faq-item:not(:last-child) {
    margin-bottom: var(--space-4);
}

/* FAQ ITEM WRAPPER */
.faq-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all var(--transition, 0.3s ease);
}

/* FAQ HEADER */
.faq-header {
    width: 100%;
    background: none;
    border: none;
    padding: var(--space-5);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text-main);
    text-align: left;
    user-select: none;
}

/* ICON */
.faq-header .icon {
    transition: transform var(--transition, 0.3s ease);
    color: var(--text-muted);
    font-size: 1.4rem;
}

/* OPEN STATE */
.faq-item.is-open {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

/* ICON ROTATION */
.faq-item.is-open .icon {
    transform: rotate(135deg);
    color: var(--primary);
}

/* ============================================================
   FAQ CONTENT ANIMATION SYSTEM
============================================================ */
.faq-content-wrapper {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.faq-item.is-open .faq-content-wrapper {
    grid-template-rows: 1fr;
}

.faq-answer {
    overflow: hidden;
}

/* TEXT */
.faq-answer p {
    padding: 0 var(--space-5) var(--space-5) var(--space-5);
    margin: 0;
    color: var(--text-muted);
    line-height: 1.8;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.35s ease, transform 0.45s ease;
}

/* REVEAL */
.faq-item.is-open .faq-answer p {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.2s;
}

/* ============================================================
   RESPONSIVE FAQ
============================================================ */
@media (max-width: 768px) {
    .faq-header {
        padding: var(--space-4);
        font-size: 0.95rem;
    }

    .faq-answer p {
        padding: 0 var(--space-4) var(--space-4) var(--space-4);
    }
}





/* ============================================================
   AD LAYOUT SYSTEM (ENGINE SAFE)
   ============================================================ */

.ad-slot,
.header-ad-section,
.footer-ad-section {
    display: none;
    width: 100%;

    justify-content: center;
    align-items: center;

    margin-top: var(--space-5);
    
    min-height: 90px;
    border-radius: var(--radius-md);
    overflow: hidden;
}


/* ============================================================
   RESPONSIVE ARTICLE
============================================================ */

@media (max-width: 768px) {

    .article-content h2 {
        font-size: 1.5rem;
    }

    .article-content h3 {
        font-size: 1.2rem;
    }

    .article-content p {
        font-size: 0.95rem;
    }
}

/* ============================================================
   DARK MODE OVERRIDES (SYSTEM SAFE)
============================================================ */

[data-theme="dark"] .page-container {
    color: var(--text-main);
}

[data-theme="dark"] .tool-card-container {
    background: var(--surface);
    border: 1px solid var(--border); /* Explicitly setting border width ensures consistency */
    box-shadow: var(--shadow-lg);
}

/* ============================================================
   MISSING DARK MODE COVERAGE
============================================================ */

/* 1. Sidebar Card */
[data-theme="dark"] .sidebar-area {
    background: var(--surface);
    border-color: var(--border);
}

/* 2. Search Input */
[data-theme="dark"] .search-input {
    background: var(--surface);
    color: var(--text-main);
    border-color: var(--border);
}

[data-theme="dark"] .search-input:focus { 
    border-color: var(--primary); 
}

/* 3. Category Filters */
[data-theme="dark"] .cat-pill {
    background: var(--bg);
    color: var(--text-muted);
    border-color: var(--border);
}

[data-theme="dark"] .cat-pill.active {
    background: var(--primary);
    color: white;
}

/* ============================================================
   ENGINE STATE SYSTEM (CLEAN VERSION)
============================================================ */

/* HIDE ELEMENT */
.is-hidden {
    display: none !important;
}

/* EMPTY STATE (DATA-BASED) */
.is-empty {
    display: none;
}

/* LOADING STATE */
.is-loading {
    min-height: 90px;
}

/* AD READY STATE */
.ad-loaded {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ============================================================
   MOBILE FIX (CLEAN SYSTEM VERSION)
============================================================ */

@media (max-width: 768px) {
    #header-placeholder {
        margin-bottom: var(--space-4);
    }
}

/* ============================================================
   HOMEPAGE TOOLS: UNIFIED 2-COLUMN MOBILE GRID
   ============================================================ */

@media (max-width: 768px) {
    /* Target only the container specifically for homepage tools */
    .tools-grid, .tools-container {
        display: flex !important;
        flex-wrap: wrap; 
        gap: var(--space-3); 
        justify-content: center; 
        padding: 0 var(--space-2);
    }

    /* SCOPED SELECTOR: Added parent class to avoid affecting sidebar */
    .tools-grid .tool-card, 
    .tools-container .tool-card {
        flex: 1 1 calc(50% - var(--space-3));
        height: 140px; /* Fixed height for homepage grid only */
        
        padding: var(--space-3) !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center; 
        text-align: center;
        box-sizing: border-box;
        overflow: hidden;
    }

    /* Target headers only within the homepage grid cards */
    .tools-grid .tool-card h3, 
    .tools-container .tool-card h3 {
        font-size: 0.9rem;
        line-height: 1.2;
        margin-top: var(--space-2);
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        height: 2.4em; 
    }
}

/* ============================================================
   MOBILE ARTICLE SPACING REFINEMENT
   ============================================================ */

@media (max-width: 768px) {
    /* Decreasing the gap between the tool/sidebar and the article */
    .article-section.is-centered, 
    .content-wrapper {
        margin-top: var(--space-4) !important; /* Reduced from space-10/space-6 */
    }

    /* Reducing the internal top padding of the article container */
    .article-container, 
    .article-content {
        padding-top: var(--space-2) !important;
    }

    /* Ensuring the article header has less bottom margin on mobile */
    .article-header {
        margin-bottom: var(--space-5) !important;
    }
}