/* Enhanced Classless CSS with Theme Switching and Sidebar - SHARED TEMPLATE FILE */

/* CSS Variables for Themes */
:root {
    /* Light theme (default) */
    --background-color: #ffffff;
    --background-color-light: #f0f4f8; /* Lighter background for sections */
    --text-color: #1a202c; /* Darker text */
    --heading-color: #2d3748; /* Even darker headings */
    --link-color: #3182ce; /* Blue links */
    --link-hover-color: #2a699c; /* Darker blue hover */
    --border-color: #e2e8f0; /* Light border */
    --accent-color: #38a169; /* Green accent */
    --accent-color-dark: #2f855a; /* Darker green accent */
    --error-color: #e53e3e; /* Red error */
    --sidebar-bg: #f7fafc; /* Very light sidebar background */
    --sidebar-border: #e2e8f0; /* Sidebar border */
    --sidebar-width: 250px; /* Default sidebar width */
    --sidebar-width-collapsed: 0px; /* Collapsed width */
    --sidebar-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

body[data-theme='dark'] {
    /* Dark theme */
    --background-color: #1a202c;
    --background-color-light: #2d3748; /* Lighter dark background for sections */
    --text-color: #e2e8f0; /* Light text */
    --heading-color: #f7fafc; /* Lighter headings */
    --link-color: #63b3ed; /* Lighter blue links */
    --link-hover-color: #90cdf4; /* Even lighter blue hover */
    --border-color: #4a5568; /* Dark border */
    --accent-color: #48bb78; /* Green accent */
    --accent-color-dark: #68d391; /* Lighter green accent */
    --error-color: #fc8181; /* Lighter red error */
    --sidebar-bg: #2d3748; /* Dark sidebar background */
    --sidebar-border: #4a5568; /* Sidebar border */
    --sidebar-shadow: 2px 0 5px rgba(0,0,0,0.5);
}

/* Base Layout with Sidebar Space */
body {
    font-family: sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0; /* Remove body padding, use padding on main/sections */
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    display: grid; /* Use grid for main layout */
    grid-template-columns: var(--sidebar-width-collapsed) 1fr; /* Sidebar (collapsed) and main content */
    grid-template-rows: auto 1fr auto; /* Header, Main, Footer */
    grid-template-areas:
        "sidebar header"
        "sidebar main"
        "sidebar footer";
    min-height: 100vh;
    transition: grid-template-columns 0.3s ease; /* Smooth transition for sidebar opening */
}

/* When sidebar is open */
body.sidebar-open {
     grid-template-columns: var(--sidebar-width) 1fr;
}


/* Grid Areas */
#sidebar { grid-area: sidebar; }
header { grid-area: header; }
main { grid-area: main; }
footer { grid-area: footer; }


/* Sidebar Styles */
#sidebar {
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    color: var(--text-color);
    padding: 20px;
    overflow-y: auto; /* Scroll if too many tools */
    display: flex; /* Arrange header, nav, footer */
    flex-direction: column;
    position: sticky; /* Sticky sidebar if height permits */
    top: 0;
    height: 100vh; /* Take full viewport height */
    box-shadow: var(--sidebar-shadow);
    transform: translateX(0); /* Default position */
    transition: transform 0.3s ease; /* Smooth slide */
}

/* When sidebar is closed */
body:not(.sidebar-open) #sidebar {
     transform: translateX(-100%); /* Hide sidebar */
     position: fixed; /* Fix position when closed so it doesn't affect layout */
     /* Also hide contents visually/from screen readers if completely off-screen */
     visibility: hidden;
     opacity: 0;
     transition: transform 0.3s ease, visibility 0s linear 0.3s, opacity 0.3s ease;
}


#sidebar header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--sidebar-border);
    grid-area: unset; /* Override grid area */
}

#sidebar header h2 {
    margin: 0;
    color: var(--heading-color); /* Sidebar headings match main headings */
    font-size: 1.5em;
}

#sidebar nav {
    flex-grow: 1; /* Navigation takes available space */
    grid-area: unset; /* Override grid area */
}

#sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#sidebar li {
    margin-bottom: 10px;
}

#sidebar a {
    text-decoration: none;
    color: var(--text-color); /* Sidebar links match general text */
    display: block; /* Make links block-level for padding */
    padding: 5px 0; /* Add padding for click area */
    border-radius: 4px; /* Subtle rounded corners */
}

#sidebar a:hover {
    text-decoration: underline;
    color: var(--link-hover-color);
    background-color: var(--background-color-light); /* Highlight on hover */
}

#sidebar a[aria-current="page"] { /* Style for the active tool link */
     font-weight: bold;
     color: var(--accent-color);
     background-color: var(--background-color);
}


#sidebar footer {
    margin-top: auto; /* Push footer to the bottom */
    padding-top: 20px;
    border-top: 1px solid var(--sidebar-border);
    text-align: center;
    grid-area: unset; /* Override grid area */
}

#sidebar #theme-toggle {
    width: 100%; /* Full width toggle in sidebar footer */
}

#sidebar-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-color);
    padding: 5px;
}
#sidebar-close:hover {
    color: var(--link-hover-color);
}


/* Sidebar Toggle Button (in main content area) */
#sidebar-toggle {
    position: fixed; /* Keep toggle button fixed */
    top: 10px;
    left: 10px;
    z-index: 100; /* Ensure it's above other content */
    background-color: var(--accent-color);
    color: var(--background-color);
    border: none;
    padding: 10px 15px;
    font-size: 1.2em;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: left 0.3s ease;
}

body.sidebar-open #sidebar-toggle {
     left: calc(var(--sidebar-width) + 10px); /* Move button when sidebar is open */
}


/* Main Content Area */
header {
    margin-bottom: 40px;
    padding: 20px; /* Add padding to header */
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    background-color: var(--background-color); /* Ensure header has background */
}

header h1 {
    margin: 0;
    font-size: 2.2em; /* Slightly larger heading */
    color: var(--heading-color);
    flex-grow: 1;
}


main {
    max-width: 800px;
    margin: 0 auto; /* Center main content */
    width: 100%;
    padding: 20px; /* Add padding to main content area */
    box-sizing: border-box; /* Include padding in width */
}

section, article, aside {
    margin-bottom: 40px;
    padding: 25px; /* Slightly more padding */
    border: 1px solid var(--border-color);
    background-color: var(--background-color-light);
    position: relative;
    border-radius: 8px; /* Rounded corners for sections */
}

section h2, article h2, aside h3 {
    color: var(--accent-color-dark); /* Use darker accent for section titles */
    margin-top: 0;
    font-size: 1.8em;
}

/* Tool Container Specific Styles */
#tool-container {
     border-color: var(--accent-color);
     background-color: var(--background-color); /* Match body background */
     padding: 25px; /* Ensure consistent padding */
}
#tool-container h2 {
     color: var(--heading-color); /* Tool title matches main headings */
     font-size: 2em;
}


/* Form Elements */
form div {
    margin-bottom: 20px; /* More space between form groups */
}

label {
    display: block;
    margin-bottom: 8px; /* More space below labels */
    font-weight: bold;
    color: var(--heading-color); /* Labels match heading color */
}

input[type="text"], input[type="number"], input[type="email"], input[type="url"], textarea {
    width: 100%;
    padding: 12px; /* More padding */
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    color: var(--text-color);
    box-sizing: border-box;
    border-radius: 4px; /* Subtle rounded corners */
    font-size: 1em;
}

button {
    padding: 12px 20px; /* More padding */
    background-color: var(--accent-color);
    color: var(--background-color);
    border: none;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s ease, opacity 0.3s ease;
    margin-right: 10px;
    margin-bottom: 10px;
    border-radius: 4px;
}

button:last-child {
    margin-right: 0;
}

button:hover:not(:disabled) {
    background-color: var(--accent-color-dark);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}


/* Output Areas */
#output-area, pre {
    margin-top: 20px;
    border: 1px solid var(--border-color);
    padding: 15px;
    background-color: var(--background-color-light);
    overflow-x: auto;
    border-radius: 4px;
}

pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; /* Monospace font for code/pre */
}

/* Links */
a {
    color: var(--link-color);
    text-decoration: none;
    transition: color 0.3s ease, text-decoration 0.3s ease;
}

a:hover {
    text-decoration: underline;
    color: var(--link-hover-color);
}

/* Lists and Definitions */
ul, ol {
    padding-left: 25px; /* Match section padding */
}

li {
    margin-bottom: 8px;
}

dt {
    font-weight: bold;
    margin-top: 15px;
    margin-bottom: 5px;
    color: var(--heading-color);
}

dd {
    margin-left: 25px;
    margin-bottom: 15px;
}

/* Accessibility: Focus styles */
button:focus, a:focus, input:focus, textarea:focus, select:focus, #sidebar-toggle:focus, #sidebar-close:focus {
    outline: 2px solid var(--link-color);
    outline-offset: 2px;
    border-color: var(--link-color); /* Also highlight border */
}

/* Specific element styles for template sections */
#paywall-area {
    background: rgba(255, 255, 255, 0.98); /* More opaque overlay */
    backdrop-filter: blur(5px);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    text-align: center;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--heading-color); /* Use heading color for contrast */
    border-radius: 8px; /* Match section border-radius */
}

body[data-theme='dark'] #paywall-area {
     background: rgba(30, 30, 30, 0.98); /* Darker opaque overlay */
     color: var(--heading-color);
}


#ad-area-1, #ad-area-2 {
    margin-top: 40px;
    text-align: center;
    min-height: 100px;
    border: 1px dashed var(--border-color);
    padding: 15px;
     display: flex;
     justify-content: center;
     align-items: center;
     font-size: 0.9em;
     color: var(--text-color);
     background-color: var(--background-color-light);
     border-radius: 8px;
}

#sponsorship-area {
     border-color: var(--accent-color);
     background-color: var(--background-color-light);
     border-radius: 8px;
}
#sponsorship-area h3 {
    color: var(--accent-color-dark);
}


/* Footer */
footer {
    margin-top: 40px;
    padding: 20px; /* Add padding */
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.9em;
    color: var(--text-color);
    background-color: var(--background-color); /* Ensure footer has background */
}
footer a {
     color: var(--text-color); /* Footer links match text color */
     margin: 0 10px;
}
footer a:hover {
     color: var(--link-hover-color);
}


/* Optional: Responsive Adjustments */
@media (max-width: 768px) {
    /* Mobile layout adjustments */
    body {
         grid-template-columns: 1fr; /* Only main content area */
         grid-template-areas:
             "header"
             "main"
             "footer";
    }

    #sidebar {
         grid-area: unset; /* Remove from grid */
         position: fixed; /* Fixed position */
         top: 0;
         left: 0;
         bottom: 0;
         width: var(--sidebar-width); /* Maintain sidebar width */
         z-index: 100; /* Ensure it's above main content */
         /* Transform and transition handled by JS class toggle */
         transform: translateX(-100%); /* Start hidden */
         transition: transform 0.3s ease;
    }

    body.sidebar-open #sidebar {
        transform: translateX(0); /* Slide in */
    }

    #sidebar-toggle {
        left: 10px; /* Keep button position consistent */
    }

    body.sidebar-open #sidebar-toggle {
        left: calc(var(--sidebar-width) + 10px); /* Move button when open */
    }


    header {
         flex-direction: column;
         align-items: flex-start;
         gap: 15px; /* More space */
         padding: 15px;
    }

    header h1 {
        width: 100%;
        text-align: center;
        font-size: 1.8em;
    }

    main {
        padding: 15px; /* Adjust padding */
    }

    section, article, aside {
        padding: 20px;
        margin-bottom: 30px;
    }
     section h2, article h2, aside h3 {
         font-size: 1.5em;
     }


    button {
        width: auto; /* Revert to auto width */
        display: inline-block; /* Ensure buttons can sit side-by-side */
        margin-right: 10px;
        margin-bottom: 10px;
    }
    /* Specific button styles for mobile if needed */

}

/* Hide sidebar toggle on pages where it's not needed (like the directory) */
body:not(.has-sidebar) #sidebar-toggle {
     display: none;
}

/* Optional: Adjust main content width/margin when sidebar is fixed on desktop if needed */
/* body.sidebar-open main {
    margin-left: calc(var(--sidebar-width) + 20px);
    margin-right: 20px;
    max-width: calc(800px - var(--sidebar-width));
} */
