/* --- CSS Variables (Theme Foundation) --- */
:root {
    --font-family-base: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-family-monospace: 'SFMono-Regular', Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --border-radius-sm: 0.3rem;
    --border-radius-md: 0.6rem;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
    --transition-speed: 0.25s;
    --transition-timing: cubic-bezier(0.4, 0, 0.2, 1); /* Smoother ease */
    --content-max-width: 1200px; /* Optional: Limit content width */
}

/* --- Light Theme (Default) --- */
html.theme-light {
    --primary-hue: 211;
    --primary-saturation: 100%;
    --primary-lightness: 50%; /* #0d6efd */
    --primary-color: hsl(var(--primary-hue), var(--primary-saturation), var(--primary-lightness));
    --primary-color-dark: hsl(var(--primary-hue), var(--primary-saturation), 40%);
    --primary-color-light: hsl(var(--primary-hue), var(--primary-saturation), 95%); /* Lighter bg */
    --secondary-hue: 210;
    --secondary-saturation: 7%;
    --secondary-lightness: 49%; /* #6c757d */
    --secondary-color: hsl(var(--secondary-hue), var(--secondary-saturation), var(--secondary-lightness));
    --secondary-color-dark: hsl(var(--secondary-hue), var(--secondary-saturation), 35%);
    --secondary-color-light: hsl(var(--secondary-hue), var(--secondary-saturation), 93%);
    --success-color: #198754; --success-color-light: #d1e7dd;
    --danger-color: #dc3545; --danger-color-light: #f8d7da;
    --info-color: #0dcaf0; --info-color-light: #cff4fc;
    --warning-color: #ffc107; --warning-color-light: #fff3cd;
    --text-color: #212529;
    --text-muted-color: var(--secondary-color);
    --bg-color: #f4f7fa; /* Slightly off-white */
    --card-bg-color: #ffffff;
    --border-color: #dee2e6;
    --input-bg: #ffffff;
    --input-border: #ced4da;
    --link-color: var(--primary-color);
    --sidebar-bg: #ffffff;
}

/* --- Dark Theme --- */
html.theme-dark {
    --primary-hue: 208;
    --primary-saturation: 90%; /* Brighter blue for dark */
    --primary-lightness: 65%;
    --primary-color: hsl(var(--primary-hue), var(--primary-saturation), var(--primary-lightness));
    --primary-color-dark: hsl(var(--primary-hue), var(--primary-saturation), 55%);
    --primary-color-light: hsl(220, 13%, 25%); /* Darker highlight */
    --secondary-hue: 210;
    --secondary-saturation: 10%;
    --secondary-lightness: 70%; /* Lighter gray */
    --secondary-color: hsl(var(--secondary-hue), var(--secondary-saturation), var(--secondary-lightness));
    --secondary-color-dark: hsl(var(--secondary-hue), var(--secondary-saturation), 55%);
    --secondary-color-light: hsl(215, 8%, 30%);
    --success-color: #40c057; --success-color-light: #2f4834;
    --danger-color: #fa5252; --danger-color-light: #592a2a;
    --info-color: #3bc9db; --info-color-light: #25494e;
    --warning-color: #fcc419; --warning-color-light: #594a1c;
    --text-color: #e9ecef; /* Lighter text */
    --text-muted-color: var(--secondary-color);
    --bg-color: #121212; /* Very dark */
    --card-bg-color: #1e1e1e; /* Slightly lighter card */
    --border-color: #3a3a3a; /* Subtle border */
    --input-bg: #2a2a2a;
    --input-border: #4a4a4a;
    --link-color: var(--primary-color);
    --sidebar-bg: var(--card-bg-color);
}

/* --- Base & Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: var(--font-family-base);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color var(--transition-speed) var(--transition-timing), color var(--transition-speed) var(--transition-timing);
}
a { color: var(--link-color); text-decoration: none; transition: color var(--transition-speed) var(--transition-timing); }
a:hover { text-decoration: underline; filter: brightness(1.1); }
small { font-size: 0.875em; }

/* --- Layout --- */
.app-container { display: flex; flex-grow: 1; overflow: hidden; }

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0; /* Prevent shrinking */
    transition: width var(--transition-speed) var(--transition-timing), padding var(--transition-speed) var(--transition-timing), box-shadow var(--transition-speed) var(--transition-timing);
    box-shadow: var(--shadow-md);
    z-index: 10; /* Keep above content */
    position: relative; /* For shadow */
}
.sidebar.collapsed {
    width: 75px; /* Slightly wider for icons */
    box-shadow: var(--shadow-sm);
}
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-heading span { display: none; }
.sidebar.collapsed .sidebar-header { padding: 1.2rem 0; justify-content: center; }
.sidebar.collapsed .logo-icon { font-size: 1.8rem; } /* Make icon slightly bigger */
.sidebar.collapsed .nav-heading { padding: 1rem 0.5rem 0.5rem; text-align: center; } /* Center divider */
.sidebar.collapsed .nav-heading::before { content: '...'; } /* Indicate collapsed heading */


.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.2rem 1.5rem 1.2rem 1.8rem; /* More padding */
    border-bottom: 1px solid var(--border-color);
    min-height: 65px;
    transition: padding var(--transition-speed) var(--transition-timing);
}

.logo {
    font-size: 1.4rem;
    font-weight: 700; /* Bolder */
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    white-space: nowrap;
}
.logo-icon { transition: transform var(--transition-speed) ease; color: var(--primary-color); }
.logo:hover .logo-icon { transform: rotate(-10deg) scale(1.1); }

.sidebar-toggle-btn {
     color: var(--text-muted-color);
     margin-left: auto; /* Push to the right */
     margin-right: -0.5rem; /* Adjust position */
}
.sidebar.collapsed .sidebar-toggle-btn { margin: 0; }

.sidebar-nav { flex-grow: 1; overflow-y: auto; padding: 0.5rem 0; }
.nav-list { list-style: none; padding: 0; margin: 0; }
.nav-heading {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em; /* More spacing */
    font-weight: 600;
    color: var(--text-muted-color);
    padding: 1.5rem 1.5rem 0.5rem;
    white-space: nowrap;
}

.tool-button {
    display: flex;
    align-items: center;
    gap: 0.9rem; /* More gap */
    width: calc(100% - 2rem); /* Adjust width for margin */
    margin: 0.2rem 1rem;
    padding: 0.75rem 1.2rem; /* Adjusted padding */
    background-color: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    border-radius: var(--border-radius-md); /* More rounded */
    font-size: 0.95rem;
    font-weight: 500; /* Slightly bolder */
    color: var(--text-color);
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
    white-space: nowrap;
}
.sidebar.collapsed .tool-button {
     width: 45px; /* Fixed width */
     height: 45px; /* Fixed height */
     margin: 0.3rem auto; /* Center horizontally */
     padding: 0;
     justify-content: center;
     border-radius: 50%; /* Circular when collapsed */
     gap: 0;
}
.tool-button i.fa-fw { width: 1.1em; text-align: center; font-size: 1.1em; }

.tool-button:hover {
    background-color: var(--primary-color-light);
    color: var(--primary-color);
}
.sidebar.collapsed .tool-button:hover {
    transform: scale(1.05); /* Slight scale on hover when collapsed */
}

.tool-button.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 5px hsla(var(--primary-hue), var(--primary-saturation), 30%, 0.3);
}
.tool-button.active:hover {
     background-color: var(--primary-color-dark); /* Darken on hover when active */
}
.sidebar.collapsed .tool-button.active {
    box-shadow: none; /* No shadow needed when collapsed */
}
.sidebar.collapsed .tool-button.active i { color: white; }


.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border-color); }
.theme-toggle-btn {
    width: 100%;
    justify-content: flex-start; /* Align left */
    background-color: var(--secondary-color-light);
    color: var(--text-muted-color);
}
.theme-toggle-btn:hover { background-color: var(--border-color); color: var(--text-color); }
.sidebar.collapsed .theme-toggle-btn { justify-content: center; border-radius: 50%; width: 45px; height: 45px; padding: 0; }
.sidebar.collapsed .theme-toggle-btn .nav-text { display: none; }

/* --- Main Content --- */
.main-content {
    flex: 1;
    padding: 2rem 2.5rem; /* More padding */
    overflow-y: auto;
}

/* --- Tool Panel & Card --- */
.tool-panel { display: none; }
.tool-panel.active { display: block; animation: fadeInUp 0.5s var(--transition-timing) forwards; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }

.card {
    background-color: var(--card-bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg); /* Larger radius */
    margin-bottom: 2.5rem;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: background-color var(--transition-speed) var(--transition-timing), border-color var(--transition-speed) var(--transition-timing);
}

.panel-header {
    background: linear-gradient(135deg, hsla(var(--primary-hue), var(--primary-saturation), 98%, 0.5), transparent); /* Subtle gradient */
    border-bottom: 1px solid var(--border-color);
    padding: 1.2rem 2rem; /* More padding */
}
html.theme-dark .panel-header {
     background: linear-gradient(135deg, hsla(var(--primary-hue), var(--primary-saturation), 15%, 0.3), transparent);
}


.panel-header h2 {
    margin: 0 0 0.3rem 0;
    font-size: 1.5rem; /* Larger */
    font-weight: 600;
    color: var(--primary-color);
    display: flex; align-items: center; gap: 0.7rem;
}
.panel-header p { margin: 0; color: var(--text-muted-color); font-size: 0.95rem; }
.panel-header small { display: block; margin-top: 0.5rem; font-family: var(--font-family-monospace); font-size: 0.85rem; color: var(--secondary-color); }

.panel-body { padding: 2rem; }

/* --- Forms & Inputs --- */
fieldset {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 1.5rem 2rem;
    margin-bottom: 2rem;
}
legend { padding: 0 0.75rem; font-weight: 600; color: var(--secondary-color-dark); }

.form-grid { display: grid; gap: 1.2rem 1.8rem; } /* Increased gap */
.form-grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
.input-group.span-2 { grid-column: span 2; }

.input-group label { font-weight: 500; font-size: 0.9rem; color: var(--text-muted-color); }

input[type="number"], input[type="text"], input[type="search"], select.form-select {
    width: 100%;
    padding: 0.75rem 1rem; /* Adjusted padding */
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-sm);
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition-speed) var(--transition-timing), box-shadow var(--transition-speed) var(--transition-timing);
}
input::placeholder { color: var(--text-muted-color); opacity: 0.7; }

/* Use :focus-visible for better accessibility */
input:focus-visible, select:focus-visible {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px hsla(var(--primary-hue), var(--primary-saturation), var(--primary-lightness), 0.25);
}

.input-group-row { display: flex; gap: 0.5rem; align-items: stretch; }
.input-group-row input { flex-grow: 1; }
.input-group-row select { flex-shrink: 0; min-width: 80px; }

select.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    background-size: 14px 10px;
    padding-right: 2.8rem; /* More space for arrow */
    cursor: pointer;
}
html select.form-select { color: var(--text-muted-color); } /* Default color for arrow */

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.6rem;
    padding: 0.8rem 1.8rem; /* Slightly more padding */
    font-size: 1rem; font-weight: 600; /* Bolder */
    border-radius: var(--border-radius-md);
    cursor: pointer; border: none;
    transition: all var(--transition-speed) var(--transition-timing);
    text-align: center; white-space: nowrap;
    line-height: 1.5; /* Ensure text aligns well */
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0px); box-shadow: var(--shadow-sm); filter: brightness(0.95); }
.btn-icon-left i { margin-right: 0.2em; } /* Slight spacing adjustment */

.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-color-dark); }
.btn-secondary { background-color: var(--secondary-color); color: white; }
.btn-secondary:hover { background-color: var(--secondary-color-dark); }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 500; }

.btn-icon { /* Generic icon button */
    background: transparent; border: none; color: var(--text-muted-color);
    padding: 0.5rem; font-size: 1.2rem; border-radius: 50%;
    width: 40px; height: 40px; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background-color: var(--secondary-color-light); color: var(--text-color); }

/* --- Results & Feedback --- */
.results-area {
    margin-top: 2rem; /* More space */
    padding: 1.5rem;
    background-color: var(--secondary-color-light);
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--primary-color);
    border-radius: var(--border-radius-md);
    min-height: 50px;
    transition: all var(--transition-speed) var(--transition-timing);
}
.results-area:empty {
    padding: 0; border: none; min-height: 0; margin-top: 0;
    opacity: 0; /* Fade out when empty */
}

/* Structured Result Items */
.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px dashed var(--border-color);
}
.result-item:last-child { border-bottom: none; }

.result-label {
    font-weight: 500;
    color: var(--text-muted-color);
    margin-right: 1rem;
}

.result-value {
    font-weight: 600;
    font-size: 1.1em;
    color: var(--primary-color-dark);
    text-align: right;
}
html.theme-dark .result-value { color: var(--primary-color); }

.results-area.monospace {
    font-family: var(--font-family-monospace);
    background-color: var(--input-bg); /* Use input bg for code-like look */
    border-color: var(--input-border);
    color: var(--text-color);
    white-space: pre-wrap; /* Keep formatting */
    font-size: 1rem;
    line-height: 1.7;
}


/* Enhanced Feedback Styles */
#feedback-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 1050; display: flex; flex-direction: column-reverse; /* Stack from bottom */ gap: 0.8rem; max-width: 380px; }
.feedback {
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-md);
    border: 1px solid transparent;
    display: flex; align-items: flex-start; gap: 0.8rem;
    box-shadow: var(--shadow-lg);
    opacity: 0; transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2); /* Bounce effect */
    position: relative; /* For close button */
    color: var(--text-color); /* Default text color */
}
.feedback.show { opacity: 1; transform: translateY(0); }
.feedback-icon { font-size: 1.3rem; margin-top: 0.1rem; flex-shrink: 0; }
.feedback-message { flex-grow: 1; line-height: 1.5; }
.btn-close {
    position: absolute; top: 0.5rem; right: 0.5rem;
    background: none; border: none; font-size: 1.5rem; cursor: pointer;
    opacity: 0.6; padding: 0.2rem; line-height: 1; color: inherit;
    transition: opacity var(--transition-speed);
}
.btn-close:hover { opacity: 1; }

.feedback-error { background-color: #ffebee; border-color: #f5c6cb; color: #c62828; } /* Material Design Red-ish */
.feedback-error .feedback-icon { color: #d32f2f; }
html.theme-dark .feedback-error { background-color: #3e2121; border-color: #853a3a; color: #ffcdd2; }
html.theme-dark .feedback-error .feedback-icon { color: #ef9a9a; }

.feedback-success { background-color: #e8f5e9; border-color: #c8e6c9; color: #2e7d32; } /* Material Green */
.feedback-success .feedback-icon { color: #4caf50; }
html.theme-dark .feedback-success { background-color: #1e3a21; border-color: #4b704e; color: #c8e6c9; }
html.theme-dark .feedback-success .feedback-icon { color: #a5d6a7; }

.feedback-info { background-color: #e3f2fd; border-color: #bbdefb; color: #1565c0; } /* Material Blue */
.feedback-info .feedback-icon { color: #42a5f5; }
html.theme-dark .feedback-info { background-color: #1c2e40; border-color: #426080; color: #bbdefb; }
html.theme-dark .feedback-info .feedback-icon { color: #90caf9; }

/* Inline feedback (non-toast) */
.tool-panel .feedback { margin-top: 1.5rem; opacity: 1; transform: none; display: none; box-shadow: none; }
.tool-panel .feedback:not(:empty) { display: flex; animation: fadeIn 0.5s ease; }


.loading-indicator { display: none; font-style: italic; color: var(--text-muted-color); padding: 0.5rem 0; }
.loading-indicator.small { font-size: 0.9em; }
.mw-display { font-size: 0.9em; color: var(--text-muted-color); margin-top: 0.3rem; display: block; min-height: 1.2em; }

/* --- Functional Group Specific --- */
.fg-details img {
    max-width: 150px;
    height: auto;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    margin-top: 0.5rem;
    border-radius: var(--border-radius-sm);
    background-color: var(--bg-color); /* Match bg */
}
.fg-details .result-value { font-family: var(--font-family-monospace); } /* Monospace for formulas */

/* --- Utilities --- */
.text-muted { color: var(--text-muted-color) !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.p-2 { padding: 0.5rem; } .p-3 { padding: 1rem; }
.d-flex { display: flex; } .align-items-center { align-items: center; } .gap-1 { gap: 0.5rem; } .gap-2 { gap: 1rem; }

/* --- Responsive Adjustments (Basic Example) --- */
@media (max-width: 992px) {
    .sidebar {
        position: absolute; /* Or fixed */
        left: -260px; /* Start hidden */
        height: 100%;
        transition: left var(--transition-speed) var(--transition-timing);
    }
    .sidebar.open {
        left: 0;
    }
    .sidebar.collapsed {
         left: -75px; /* Still hidden when collapsed state active */
    }
     .sidebar.collapsed.open {
         left: 0; /* Show collapsed when opened */
     }

    .main-content {
        padding: 1.5rem; /* Reduce padding */
    }
    /* Add overlay for background dimming when sidebar is open */
}
@media (max-width: 768px) {
    .form-grid.cols-2, .form-grid.cols-3 {
        grid-template-columns: 1fr; /* Stack columns */
    }
    .input-group.span-2 { grid-column: span 1; }
    .main-content { padding: 1rem; }
    .panel-body { padding: 1.5rem; }
    .panel-header { padding: 1rem 1.5rem; }
    .results-area { padding: 1rem; }
    #feedback-container { right: 1rem; bottom: 1rem; max-width: calc(100% - 2rem); }
}