/* Custom styles for timnetworks-app-store - v0.4.2 */

html {
  height: 100%;
  overflow: hidden; /* Prevent scroll on the root element */
  margin: 0;
  padding: 0;
}
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* Allow vertical scroll ONLY if absolutely necessary */
  overflow-y: hidden; /* Explicitly hide vertical scroll on body too */
}

body.background-teal {
  background-color: #008080;
  background-image: url('./img/setup.jpg');
  background-repeat: no-repeat;
  background-position: center center;
  background-attachment: fixed;
  background-size: cover;
}

/* Page Container */
.page-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%; /* Use 100% to fill body */
    box-sizing: border-box;
    padding: 2vh 0; /* Desktop padding */
    overflow: hidden; /* Contain the window strictly */
}

/* --- Base Window & Common Styles --- */
.main-app-window {
    position: relative;
    margin: 0;
    width: 75vw;
    height: 80vh; /* Desktop target height */
    min-width: 640px;
    min-height: 500px;
    max-width: 1200px;
    max-height: 900px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    /* Add overflow hidden here to help contain */
    overflow: hidden;
}

.title-bar {
    flex-shrink: 0;
}

.title-bar-controls {
    position: relative;
    display: flex;
    align-items: center;
}
#menu-toggle {
    display: none;
    margin-left: 3px;
    font-weight: bold;
    font-size: 16px;
    padding: 0 5px;
    order: -1;
}
.desktop-controls {
    display: inline-block;
    display: flex;
    align-items: center;
}

/* Mobile Menu Dropdown Styles */
#mobile-menu {
    position: absolute;
    top: 28px;
    left: 0;
    right: 0;
    background: #c0c0c0;
    z-index: 10;
    border-top: none;
    padding: 5px;
    max-height: 60vh;
    overflow-y: auto;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease-in-out, visibility 0s 0.2s linear;
    box-sizing: border-box;
}
#mobile-menu.is-open {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.2s ease-in-out;
}
#mobile-menu .tree-view { padding: 5px; }
#mobile-menu .tree-view a { display: block; padding: 4px 6px; color: black; text-decoration: none; }
#mobile-menu .tree-view a:hover,
#mobile-menu .tree-view a.active { background-color: #000080; color: white; }

/* Common Window Body Layout */
.window-body.has-sidebar {
    display: flex;
    gap: 3px;
    flex-grow: 1;
    overflow: hidden; /* Ensure this doesn't scroll */
    /* Adding position relative MIGHT help establish a stacking context */
    position: relative;
}

/* Common Content Pane */
main.content-pane.sunken-panel {
    flex-grow: 1;
    background-color: #ffffff;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Ensure this doesn't scroll */
}
.store-header-image { flex-shrink: 0; height: 12%; min-height: 60px; background-color: #eee; border-bottom: 1px solid #808080; display: flex; justify-content: center; align-items: center; overflow: hidden; }
.store-header-image img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Scrollable Container */
.scrollable-content {
    flex-grow: 1;
    overflow-y: auto; /* This MUST be scrollable */
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    /* Add position relative and z-index to ensure it's treated as a distinct layer */
    position: relative;
    z-index: 1;
}
.scrollable-content-inner {
    padding: 10px 15px;
}

.welcome-section { margin-bottom: 20px; }
.welcome-section h2 { margin-top: 0; margin-bottom: 10px; font-size: 1.1em; border-bottom: 1px solid #ccc; padding-bottom: 5px; }
.welcome-section p { margin-bottom: 5px; line-height: 1.5; }
.category-sections-container { }
.category-section { margin-bottom: 25px; scroll-margin-top: 15px; transition: opacity 0.3s ease-in-out; }
.category-section.de-emphasized { opacity: 0.4; }
.category-title { font-size: 1em; font-weight: bold; color: #000080; border-bottom: 2px solid #008080; padding-bottom: 4px; margin-bottom: 12px; }
.category-icon-row { display: flex; flex-wrap: wrap; gap: 15px 20px; align-items: flex-start; justify-content: flex-start; padding-left: 5px; }
.app-icon { display: flex; flex-direction: column; align-items: center; width: 75px; text-decoration: none; color: black; text-align: center; padding: 4px; cursor: pointer; }
.app-icon:hover, .app-icon:focus { background-color: #000080; color: white; outline: 1px dotted white; outline-offset: -4px; }
.app-icon:focus { outline: none; }
.app-icon:focus-visible { background-color: #000080; color: white; outline: 1px dotted white; outline-offset: -4px; }
.app-icon img { width: 32px; height: 32px; margin-bottom: 4px; object-fit: contain; }
.app-icon span { font-size: 11px; word-wrap: break-word; display: block; line-height: 1.2; max-height: 2.4em; overflow: hidden; }

/* Status Bar */
.status-bar {
    display: flex;
    background-color: #c0c0c0;
    border-top: 1px solid #ffffff;
    box-sizing: border-box;
    width: 100%;
    flex-shrink: 0;
    margin: 0;
}
.status-bar-field {
    padding: 1px 3px;
    margin: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 11px;
    border: 1px solid;
    border-color: #808080 #ffffff #ffffff #808080;
    box-shadow: inset 1px 1px 0 #dfdfdf;
    box-sizing: border-box;
}
.status-bar-field:nth-child(2) {
    flex-grow: 1; flex-shrink: 1; min-width: 80px;
}


/* --- Desktop Styles (Tablet landscape and wider) --- */
@media (min-width: 769px) {
    aside.sidebar.sunken-panel {
        width: 180px;
        flex-shrink: 0;
        padding: 3px;
        overflow-y: auto;
        display: block;
    }
    .sidebar .tree-view { }
    .sidebar .tree-view a { display: block; padding: 2px 4px; text-decoration: none; color: black; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .sidebar .tree-view a:hover { background-color: #000080; color: white; }
    .sidebar .tree-view a.active { background-color: #000080; color: white; font-weight: bold; }
}


/* --- Mobile/Tablet Styles (Tablet portrait and smaller) --- */
@media (max-width: 768px) {
    .page-container {
        padding: 0; /* Remove padding for full screen */
        justify-content: flex-start; /* Align window top */
    }
    .main-app-window {
        width: 100%;
        height: 100%;
        min-width: 0;
        min-height: 0;
        max-width: none;
        max-height: none;
        border: none;
        box-shadow: none;
        /* Ensure window respects container */
        position: static; /* Override relative if needed */
    }

    #menu-toggle {
        display: inline-block;
    }
    .desktop-controls {
        display: none;
    }

    aside.sidebar.sunken-panel {
        display: none;
    }

    .window-body.has-sidebar {
        gap: 0;
    }

    main.content-pane.sunken-panel {
        width: 100%;
    }

    .store-header-image { height: 10%; min-height: 40px; }
    .scrollable-content-inner {
        padding: 5px 8px;
    }
    .category-icon-row {
        gap: 10px 15px;
        padding-left: 0;
        justify-content: flex-start;
    }
    .app-icon { width: 70px; }
    .status-bar-field { font-size: 10px; }
}

/* Very small screens */
@media (max-width: 480px) {
    .scrollable-content-inner {
        padding: 5px;
    }
    .category-icon-row { gap: 8px 10px; }
    .app-icon { width: 65px; }
    .app-icon span { font-size: 10px; }
}
