* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sidebar-width: 240px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f8fafc;
    color: #1e293b;
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

/* ========== Footer Container ========== */
#footer-container {
    flex-shrink: 0;
    margin-top: auto;
}

/* ========== Left Sidebar ========== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: #fff;
    color: #334155;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid #e8ecf1;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 24px 20px 18px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
}

.sidebar-brand a {
    font-size: 18px;
    font-weight: 700;
    color: #4f46e5;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.3px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: #eef2ff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

/* Collapse toggle button */
.sidebar-toggle-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: auto;
    transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
    background: #f1f5f9;
    color: #334155;
    border-color: #cbd5e1;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-nav .nav-section {
    font-size: 12px;
    color: #94a3b8;
    padding: 16px 12px 6px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #475569;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    overflow: hidden;
    white-space: nowrap;
}

.nav-icon {
    width: 18px;
    text-align: center;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-nav a:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.sidebar-nav a.active {
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 600;
}

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid #f1f5f9;
    font-size: 12px;
    color: #94a3b8;
    text-align: center;
}

/* ========== Collapsed Sidebar ========== */
.sidebar.collapsed {
    transform: translateX(calc(var(--sidebar-width) * -1));
}

/* ========== Floating Toggle Ball ========== */
.sidebar-float-ball {
    position: fixed;
    top: 20px;
    left: 16px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.04);
    cursor: pointer;
    z-index: 99;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.sidebar-float-ball.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.sidebar-float-ball:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.06);
    transform: scale(1.08);
}

.sidebar-float-ball .ball-icon {
    font-size: 18px;
    line-height: 1;
}

.sidebar-float-ball .ball-tooltip {
    position: absolute;
    left: 52px;
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #fff;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.sidebar-float-ball:hover .ball-tooltip {
    opacity: 1;
}

/* ========== Page Hero (unified header for all tool pages) ========== */
.page-hero {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 50%, #f0f4ff 100%);
    color: #1e293b;
    padding: 30px 0;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.page-hero::after {
    content: '';
    position: absolute;
    right: -60px;
    top: -60px;
    width: 200px;
    height: 200px;
    background: rgba(99, 102, 241, 0.06);
    border-radius: 50%;
}

.page-hero::before {
    content: '';
    position: absolute;
    right: 100px;
    bottom: -40px;
    width: 140px;
    height: 140px;
    background: rgba(99, 102, 241, 0.04);
    border-radius: 50%;
}

.page-hero h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
    position: relative;
    z-index: 1;
    letter-spacing: -0.5px;
}

.page-hero p {
    font-size: 14px;
    color: #475569;
    position: relative;
    z-index: 1;
    max-width: 800px;
    margin: 0 auto;
}

/* ========== Page Horizontal Ad ========== */
.page-ad {
    display: flex;
    justify-content: center;
    padding: 16px 0;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.page-ad .ad-container {
    width: 100%;
    max-width: 970px;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border-radius: 8px;
    overflow: hidden;
}

.page-ad .ad-label {
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
    padding: 4px;
    letter-spacing: 0.3px;
}

/* ========== Main Content ========== */
.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 0 24px;
    transition: margin-left 0.3s ease;
}

body.sidebar-collapsed main.main {
    margin-left: 0 !important;
    width: 100% !important;
    flex: none !important;
}



/* ========== Page Footer ========== */
.footer {
    background-color: #6771a1;
    color: #fff;
    padding: 40px 0;
    text-align: center;
    margin-top: auto;
}

.footer p {
    margin: 0;
    font-size: 14px;
    color: white;
}

/* Collapse toggle button */
.sidebar-toggle-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: auto;
    transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
    background: #f1f5f9;
    color: #334155;
    border-color: #cbd5e1;
}

.sidebar-toggle-btn svg {
    transition: transform 0.25s ease;
}


/* Mobile toggle */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--border);
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    align-items: center;
    justify-content: center;
}

/* Sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
}

.sidebar-overlay.show {
    display: block;
}

/* Sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
}

.sidebar-overlay.show {
    display: block;
}


/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        padding-bottom: 3rem;
    }

    body.sidebar-collapsed main.main {
        margin-left: 0 !important;
    }

    .main {
        margin-left: 0;
        padding: 0 10px;
        width: 100%;
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-brand {
        padding: 24px 65px 10px;
    }

    .sidebar-float-ball,
    .sidebar-toggle-btn {
        display: none;
    }


    .page-hero {
        padding: 24px 0;
    }

    .page-hero h1 {
        font-size: 22px;
    }

    .page-hero p {
        font-size: 13px;
    }

    .page-ad {
        padding: 10px 0;
    }

    .footer {
        padding: 24px 16px;
    }
}

@media (max-width: 480px) {
    .main {
        padding: 0 10px;
        width: 100%;
    }

    .sidebar-brand {
        padding: 24px 65px 10px;
    }


    .page-hero {
        padding: 20px 0;
    }

    .page-hero h1 {
        font-size: 19px;
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-float-ball,
    .sidebar-toggle-btn {
        display: none;
    }

    .page-hero p {
        font-size: 12px;
        padding: 0 8px;
    }

    .footer {
        padding: 20px 12px;
        font-size: 12px;
    }

    .footer p {
        font-size: 12px;
    }
}