/* Global Styles */
body {
    background-color: #008080; 
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    font-family: 'Pixelated MS Sans Serif', Arial;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
}

/* App Container (for index.html) */
.smolify-app-container {
    padding: 20px; /* Default padding for desktop */
    width: 100%;
    height: 100%; /* Ensure container can facilitate full height for #appWindow on mobile */
    display: flex; /* To center #appWindow if it's not full width */
    align-items: center;
    justify-content: center;
}

/* Main Application Window (for index.html) */
#appWindow {
    width: 95vw; 
    max-width: 600px; 
    margin: auto; /* Centering for desktop */
    display: flex;
    flex-direction: column;
    /* Default height will be auto based on content */
}
.main-window-body { 
    padding: 1px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; 
    position: relative;
}

/* App Header (for index.html) */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 8px;
    margin-bottom: 5px;
    flex-shrink: 0; /* Prevent header from shrinking */
}
.welcome-message { margin: 0; font-size: 1.4em; }
.app-logo { max-height: 48px; width: auto; }


/* Tab Menu */
.main-window-body > menu[role="tablist"] {
    flex-shrink: 0; /* Prevent tab menu from shrinking */
}

/* Tab Panels & Content (for index.html) */
article[role="tabpanel"].window {
    display: none;
    padding: 8px; 
    flex-grow: 1; 
    overflow-y: auto;
    /* 98.css will style the .window part */
}
article[role="tabpanel"].window.active {
    display: flex; /* Use flex to allow internal content to be structured */
    flex-direction: column;
}
@media (min-width: 600px) {
    article[role="tabpanel"].window {
        min-height: 450px; 
    }
}
/* Make form inside active panel take up space */
article[role="tabpanel"].window.active form {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100%; /* Try to make form fill parent article */
}
/* Ensure fieldsets and option containers within form don't cause overflow issues unnecessarily */
article[role="tabpanel"].window.active form > fieldset,
article[role="tabpanel"].window.active form > .options-columns-container {
    flex-shrink: 0;
}
/* Allow the options container to grow if there's space, but not shrink beyond content */
article[role="tabpanel"].window.active form > .options-columns-container {
    flex-grow: 1;
    /* overflow-y: auto; /* If this section needs to scroll independently */
}


menu[role="tablist"] li[role="tab"].disabled a {
    color: grey;
    cursor: default;
    pointer-events: none;
}

/* File Upload Area (for index.html) */
.file-upload-area { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.file-name-display {
    font-size: 0.9em; color: #333; padding: 3px 6px;
    border: 1px inset #7f7f7f; background-color: #fff;
    flex-grow: 1; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; min-height: 1.5em; line-height: 1.5;
}

/* Image Preview Container (for index.html) */
#imagePreviewContainer {
    display: flex; align-items: center; justify-content: center;
    background: #fff; border: 1px dashed #ccc; overflow: hidden;
    width: 100%; aspect-ratio: 1 / 1; margin-left: auto; margin-right: auto;
    margin-top: 10px; max-height: 240px; 
}
@media (min-width: 468px) { #imagePreviewContainer { max-height: 320px; } }
@media (min-width: 768px) { #imagePreviewContainer { max-height: 400px; } }
@media (min-width: 1024px) { #imagePreviewContainer { max-height: 480px; } }

#imagePreviewContainer img { display: none; max-width: 100%; max-height: 100%; object-fit: contain; }
#imagePreviewContainer span#imagePreviewPlaceholder { color: #aaa; }

/* Options Layout (for index.html) */
.options-columns-container { display: flex; flex-direction: row; gap: 15px; margin-top: 15px; }
.options-column { flex: 1; min-width: 200px; }
.options-column fieldset { height: 100%; }
.options-column .option-group { margin-bottom: 12px; }
.options-column .option-group:last-child { margin-bottom: 0; }
.options-column .option-group label { display: block; margin-bottom: 3px; }
.options-column .option-group select,
.options-column .option-group .info-display { width: 100%; margin-top: 2px; }
.info-display {
    font-weight: bold; color: #333; padding: 2px 5px;
    background-color: #fff; border: 1px inset #7f7f7f;
    min-height: 1.5em; display: block; line-height: 1.5;
}

/* Process button container (for index.html) */
#panel-image form > div:has(> #processButton) { /* Targets the div wrapping the process button */
    flex-shrink: 0; /* Prevent this from shrinking */
    margin-top: auto; /* Push to bottom if form is flex-grow */
}


/* Status Bar (Now a direct child of #appWindow) */
#appWindow > .status-bar { /* More specific selector */
    display: flex; justify-content: space-between; align-items: center; 
    flex-shrink: 0; /* Crucial: Prevent status bar from shrinking */
    /* 98.css provides its own padding and border for .status-bar */
}
#appStatus { flex-grow: 1; text-align: left; }
.status-bar-field-secondary {
    color: #555; font-size: 0.9em; flex-shrink: 0;
    max-width: 150px; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; text-align: right; padding-left: 10px;
}

/* JPEG Quality Slider (for index.html) */
#jpegQualityContainer input[type="range"]:disabled { opacity: 0.5; cursor: not-allowed; }
#jpegQualityContainer input[type="range"]:disabled + span { opacity: 0.5; }
#jpegQualityValue { font-weight: bold; }

/* About Panel (for index.html) */
#panel-about h4 { margin-top: 0; }


/* Styles for process_image.php result page */
.result-window {
    width: auto; min-width: 320px; max-width: 500px; margin: 20px;
}
.result-window p { margin-bottom: 10px; }
.result-window .image-preview-result {
    max-width: 100%; max-height: 300px; border: 1px solid #7f7f7f;
    margin: 10px auto; display: block; background-color: #fff;
}
.result-window .button-bar { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.result-window button a { text-decoration: none; color: inherit; }
.result-window pre {
    background-color: #fff; border: 1px inset #7f7f7f; padding: 5px;
    max-height: 150px; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
}
.result-window code { font-family: "Monaco", "Consolas", monospace; background-color: #eee; padding: 1px 3px; border-radius: 3px; }


/* Responsive Adjustments for #appWindow (Desktop first) */
@media (min-width: 768px) { #appWindow { max-width: 700px; } }
@media (min-width: 1024px) { #appWindow { max-width: 800px; } }
@media (min-width: 1300px) { #appWindow { max-width: 1000px; } }

/* Mobile Viewport Adjustments (<600px generally for index.html) */
@media (max-width: 599px) {
    .smolify-app-container {
        padding: 0; /* Remove padding around the app window on mobile */
    }
    #appWindow {
        width: 100vw;   /* Full viewport width */
        height: 100vh;  /* Full viewport height */
        max-width: 100vw; /* Override desktop max-width */
        margin: 0;
        border-radius: 0;
        border: none; /* Remove window border for seamless full-screen look */
    }
    .main-window-body {
        /* overflow-y: auto; -- Already set earlier for mobile, good */
    }
    article[role="tabpanel"].window {
        min-height: auto; 
        flex-grow: 1; /* Allow tab panel to grow to fill space on mobile */
    }
    #appWindow .title-bar { flex-shrink: 0; }
    .app-header { flex-direction: column; align-items: center; text-align: center; }
    .app-logo { margin-top: 5px; }
    .options-columns-container { flex-direction: column; gap: 0; }
    .options-column { min-width: 100%; margin-bottom: 15px; }
    .options-column:last-child { margin-bottom: 0; }
    .file-upload-area { flex-direction: column; align-items: stretch; }
    .file-name-display { text-align: center; margin-top: 5px; }
    
    .result-window { /* Ensure result window is also responsive on mobile */
        min-width: 90vw; max-width: 95vw;
    }
}
