html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background-color: #818181;
}

/* Ensure Bootstrap modals respect safe area on mobile */
.modal-dialog {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    margin-top: 0.5rem;
}

.modal-content {
    max-height: calc(100vh - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
}

@media (min-width: 576px) {
    .modal-dialog {
        margin-top: 1.75rem;
    }
    .modal-content {
        max-height: calc(100vh - 3.5rem);
        max-height: calc(100dvh - 3.5rem);
    }
}

.modal-header,
.modal-footer {
    flex-shrink: 0;
}

.modal-body {
    overflow-y: auto;
    min-height: 0;
}

/* Loading screen */
.loading-screen {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #818181;
}

.loading-content {
    text-align: center;
    color: #eee;
    font-family: Arial, sans-serif;
}

.loading-content-fade-out {
    animation: fadeOut 0.4s ease-out forwards;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

.loading-content p {
    margin-top: 1rem;
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Fade-in for the full layout */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.frame-fade-in {
    animation: fadeIn 0.8s ease-out;
}

.graph-container {
    overflow: auto; /* or overflow-y, overflow-x, etc. */
    /* scrollbar-gutter: stable; */
    height: 100%;
    width: 100%;
}

/* Flag Styles */
.flag-select-item-active {
    background-color: #afa;
    display: flex;
    align-items: center;
}

.flag-select-item-normal {
    display: flex;
    align-items: center;
}

.flag-icon {
    margin-right: 6px;
    flex-shrink: 0;
    box-shadow: 0.5px 0.5px 3px rgba(0, 0, 0, 0.3);
    border-radius: 2px;
}

.post-button-wrapper-vertical {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    margin: 0;
    transition: all 0.3s ease;
    flex: 0 0 auto;
}

/* Non-square vertical buttons: fixed width, proportional height */
.post-button-wrapper-vertical:not(.square) {
    width: 150px;  /* Matches verticalWidth from large layout */
}

.post-button-wrapper-vertical:not(.square) > img {
    width: 100%;
    height: auto;  /* Height will be proportional based on image ratio */
    object-fit: cover;
    object-position: top;  /* Show top part of image */
}

/* Square vertical buttons: fixed width and height */
.post-button-wrapper-vertical.square {
    width: 90px;  /* Matches horizontalHeight */
    height: 90px;
}

.post-button-wrapper-vertical.square > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top left;  /* Show top-left part of image */
}

.post-button-wrapper-horizontal {
    display: flex;
    flex-direction: row;
    align-items: center;
    cursor: pointer;
    margin: 0;
    transition: all 0.3s ease;
    flex: 0 0 auto;
}

/* Non-square horizontal buttons: fixed height, proportional width */
.post-button-wrapper-horizontal:not(.square) {
    height: 90px;  /* Matches horizontalHeight from layout config */
}

.post-button-wrapper-horizontal:not(.square) > img {
    height: 100%;
    width: auto;  /* Width will be proportional based on image ratio */
    object-fit: cover;
    object-position: left;  /* Show left part of image */
}

/* Square horizontal buttons: fixed width and height */
.post-button-wrapper-horizontal.square {
    width: 90px;  /* Matches horizontalHeight */
    height: 90px;
}

.post-button-wrapper-horizontal.square > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top left;  /* Show top-left part of image */
}

/* Text styling for buttons */
.post-button-wrapper-vertical > span,
.post-button-wrapper-horizontal > span {
    font-size: 0.9em;
    text-align: center;
    margin-top: 4px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Frame containers for different layouts */
.frame-container-large-landscape,
.frame-container-large-portrait {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: 90px auto 90px;  /* Match horizontalHeight */
    grid-template-columns: 150px auto 150px;  /* Match verticalWidth from large layout */
    gap: 5px;
    padding: 5px;
    background-color: #818181;
}

.frame-container-medium-landscape {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: 90px auto 90px;  /* Match button height */
    grid-template-columns: 90px auto 90px;  /* Match medium layout button width */
    gap: 5px;
    padding: 5px;
    background-color: #818181;
}

.frame-container-medium-portrait {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: 90px auto 90px;  /* Match button height */
    grid-template-columns: 90px auto 90px;  /* Match square button size */
    gap: 5px;
    padding: 5px;
    background-color: #818181;
}

.frame-container-small-portrait {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: 90px auto 90px;  /* Match button height */
    grid-template-columns: 0px auto 0px;
    gap: 5px;
    padding: 5px;
    background-color: #818181;
}

.frame-container-small-landscape {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: 0px auto 0px;
    grid-template-columns: 90px auto 90px;  /* Match square button size */
    gap: 5px;
    padding: 5px;
    background-color: #818181;
}

/* Frame positions */
.frame-top {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    grid-row: 1;
    grid-column: 1 / span 3;
    background-color: #818181;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 5px;
    white-space: nowrap;
    scrollbar-width: none;  /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
}

.frame-bottom {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    grid-row: 3;
    grid-column: 1 / span 3;
    background-color: #818181;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 5px;
    white-space: nowrap;
    scrollbar-width: none;  /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
}

.frame-left {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    grid-row: 2;
    grid-column: 1;
    background-color: #818181;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 5px;
}

.frame-right {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    grid-row: 2;
    grid-column: 3;
    background-color: #818181;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 5px;
}

.frame-center {
    position: relative;
    grid-row: 2;
    grid-column: 2;
    background-color: #ffffff;
    min-width: 0;
    min-height: 0;
    overflow: auto;
}

/* Hide scrollbars but keep functionality */
.frame-top::-webkit-scrollbar,
.frame-bottom::-webkit-scrollbar,
.frame-left::-webkit-scrollbar,
.frame-right::-webkit-scrollbar {
    display: none;
}

.frame-top,
.frame-bottom,
.frame-left,
.frame-right {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.frame-center-full {
    position: relative;
    grid-row: 1 / span 3;
    grid-column: 1 / span 3;
    background-color: #ffffff;
    min-width: 0; 
    min-height: 0; 
}

.burger-menu-button {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 30px;
    height: 24px;
    margin-right: 40px;
    /* display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer; */
}
  
.burger-menu-button > button > div > span {
    display: block;
    height: 2px;
    width: 20px;
    margin: 4px;
    background-color: #333;
    border-radius: 2px;
}

.burger-menu {
    position: absolute;
    top: 0;
    right: 0;
    width: 200px;
    height: 100%;
    background-color: #f5f5f5;
    display: none;
    flex-direction: column;
    align-items: center;
    padding-top: 80px;
    transform: translateX(200px);
    transition: transform 0.3s ease-in-out;
}

.burger-menu-open {
    display: flex;
}

.no-caret > a.dropdown-toggle::after {
    display: none !important;
}

.burger-menu-button > .dropdown-toggle {
    box-shadow: 0 0 4px rgba(160, 160, 160, 0.7);
}

.burger-menu-button > .dropdown-toggle::after {
    display: none;
}

/* Constrain burger menu dropdown to viewport */
.burger-menu-button > .dropdown-menu {
    max-height: 80vh;
    max-height: 80dvh;
    overflow-y: auto;
    max-width: calc(100vw - 20px);
}

/* Stack sub-dropdowns inline within the burger menu (accordion-style) */
.burger-menu-button .dropdown-menu .nav-item.dropdown {
    position: static;
}

.burger-menu-button .dropdown-menu .dropdown-menu {
    position: static !important;
    transform: none !important;
    float: none;
    border: 0;
    border-left: 3px solid rgba(0, 0, 0, 0.12);
    padding-left: 0.5rem;
    box-shadow: none;
    background-color: transparent;
    margin: 0;
}

/* Point submenu arrow downward instead of right */
.burger-menu-button .dropdown-menu .dropdown-toggle::after {
    border-left: 0.3em solid transparent;
    border-right: 0.3em solid transparent;
    border-top: 0.3em solid;
    border-bottom: 0;
    vertical-align: 0.15em;
}

.nav-link {
    margin: 4px;
}

.image-preview-area {
    max-width: 100%;
    max-height: 350px;
    margin-bottom: 8px;
    border: 1px solid #CCC;
    border-radius: 6px;
}

.image-preview-area > img {
    max-width: 100%;
    max-height: 348px;
    margin: auto;
    display: block;
    border-radius: 6px;
}

.image-preview-area > span {
    display: block;
    text-align: center;
    margin-top: 8px;
}

.form-label {
    margin-bottom: .2rem;
    margin-top: .6rem;
}

/* Dynamic grid layouts */
/* When top or bottom is missing, adjust row template */
.frame-layout-no-top-bottom-left-right,
.frame-layout-no-top-bottom-left-no-right,
.frame-layout-no-top-bottom-no-left-right,
.frame-layout-no-top-bottom-no-left-no-right {
    grid-template-rows: auto !important;
}

.frame-layout-top-no-bottom-left-right,
.frame-layout-top-no-bottom-left-no-right,
.frame-layout-top-no-bottom-no-left-right,
.frame-layout-top-no-bottom-no-left-no-right {
    grid-template-rows: 90px auto !important;  /* Match button height */
}

.frame-layout-no-top-bottom-left-right,
.frame-layout-no-top-bottom-left-no-right,
.frame-layout-no-top-bottom-no-left-right,
.frame-layout-no-top-bottom-no-left-no-right {
    grid-template-rows: auto 90px !important;  /* Match button height */
}

/* When left or right is missing, adjust column template */
.frame-layout-top-bottom-no-left-no-right,
.frame-layout-top-no-bottom-no-left-no-right,
.frame-layout-no-top-bottom-no-left-no-right,
.frame-layout-no-top-no-bottom-no-left-no-right {
    grid-template-columns: auto !important;
}

.frame-layout-top-bottom-left-no-right,
.frame-layout-top-no-bottom-left-no-right,
.frame-layout-no-top-bottom-left-no-right,
.frame-layout-no-top-no-bottom-left-no-right {
    grid-template-columns: var(--side-frame-width, 150px) auto !important;  /* Use CSS variable for dynamic width */
}

.frame-layout-top-bottom-no-left-right,
.frame-layout-top-no-bottom-no-left-right,
.frame-layout-no-top-bottom-no-left-right,
.frame-layout-no-top-no-bottom-no-left-right {
    grid-template-columns: auto var(--side-frame-width, 150px) !important;  /* Use CSS variable for dynamic width */
}

/* Adjust center frame span based on missing frames */
.frame-layout-top-bottom-no-left-no-right .frame-center,
.frame-layout-top-no-bottom-no-left-no-right .frame-center,
.frame-layout-no-top-bottom-no-left-no-right .frame-center,
.frame-layout-no-top-no-bottom-no-left-no-right .frame-center {
    grid-column: 1 !important;
}

.frame-layout-top-bottom-left-no-right .frame-center,
.frame-layout-top-no-bottom-left-no-right .frame-center,
.frame-layout-no-top-bottom-left-no-right .frame-center,
.frame-layout-no-top-no-bottom-left-no-right .frame-center {
    grid-column: 2 !important;
}

.frame-layout-top-bottom-no-left-right .frame-center,
.frame-layout-top-no-bottom-no-left-right .frame-center,
.frame-layout-no-top-bottom-no-left-right .frame-center,
.frame-layout-no-top-no-bottom-no-left-right .frame-center {
    grid-column: 1 !important;
}

/* Adjust top/bottom frame span based on missing side frames */
.frame-layout-top-bottom-no-left-no-right .frame-top,
.frame-layout-top-bottom-no-left-no-right .frame-bottom,
.frame-layout-top-no-bottom-no-left-no-right .frame-top,
.frame-layout-no-top-bottom-no-left-no-right .frame-bottom {
    grid-column: 1 !important;
}