/* Define the local font */
@font-face {
    font-family: 'Rubik';
    src: url('../fonts/Rubik-VariableFont_wght.ttf') format('truetype');
    font-weight: 300 900;
    font-display: swap;
    font-style: normal;
}

body {
    margin: 0;
    padding: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Rubik', sans-serif;
}

/* Ensure Semantic UI elements use it */
.ui.header, .ui.button, .ui.input, .ui.list, .ui.modal {
    font-family: 'Rubik', sans-serif !important;
}

#top-navbar {
    height: 64px;
    background-color: #0068f5;
    color: white;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    margin: 0; /* Remove default margin */
    border-radius: 0; /* Remove default border-radius */
    border: none; /* Remove default border */
}

#top-navbar .left-section,
#top-navbar .right-section,
#bottom-navbar .left-section,
#bottom-navbar .right-section {
    display: flex;
    align-items: center;
    width: 33%;
}

#top-navbar .right-section,
#bottom-navbar .right-section {
    justify-content: flex-end;
}

#top-navbar .center-section,
#bottom-navbar .center-section {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34%;
}

@media (max-width: 768px) {
    #bottom-navbar .center-section {
        display: flex !important;
        flex: 1;
        width: auto !important;
    }
}

#top-navbar .center-section {
    font-size: 1.8rem;
    font-weight: bold;
}

#top-navbar .logo-img {
    height: 48px;
    margin-left: 10px;
}

#bottom-navbar .logo-img {
    height: 48px;
}

#top-navbar .left-section .button,
#bottom-navbar .button {
    border-radius: 15px !important;
    padding: 0.5rem !important;
    min-height: unset !important;
    min-width: unset !important;
}

#help-button {
    width: 24px;
    height: 24px;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

#help-button i.icon {
    margin: 0 !important;
}

#top-navbar .left-section .button {
    margin-right: 5px;
}

#bottom-navbar {
    height: 48px;
    background-color: #0068f5;
    color: white;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    margin: 0; /* Remove default margin */
    border-radius: 0; /* Remove default border-radius */
    border: none; /* Remove default border */
    position: relative;
    z-index: 10;
}

.status-indicator {
    display: flex;
    align-items: center;
}

.status-light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-left: 8px;
}

.status-light.green {
    background-color: #21ba45;
}

/* RTL Support for containers */
#addresses-container, #layers-container {
    text-align: right;
}

#addresses-container .ui.items > .item {
    text-align: right;
}

#addresses-container .ui.items > .item > .content {
    text-align: right;
}

#addresses-container .ui.items > .item .extra {
    text-align: right;
}

#addresses-container .ui.items > .item .description i.icon {
    margin-left: 0.25rem;
    margin-right: 0;
}

.status-light.red {
    background-color: #db2828;
    box-shadow: 0 0 5px #db2828;
}

#main-container {
    flex-grow: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    height: calc(100vh - 112px); /* 64px top + 48px bottom */
}

.side-portion {
    background-color: #ffffff;
    transition: width 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    overflow-y: auto;
    border-left: 1px solid #ddd;
    border-right: 1px solid #ddd;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
    width: 300px;
}

#left-portion {
    border-right: none;
}

#right-portion {
    border-left: none;
    width: 600px;
}

.side-portion.closed {
    width: 30px !important;
    overflow: hidden;
    background-color: #ffffff;
    cursor: pointer;
    display: flex;
    flex-direction: row;
}

.side-portion .side-strip {
    display: none;
    width: 30px;
    height: 100%;
    text-align: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: #0068f5;
    user-select: none;
}

.side-portion.closed .side-strip {
    display: flex;
    flex-shrink: 0;
}

/* Mobile Responsive Adjustments */
/* Floating toggle buttons for mobile */
.mobile-toggle-container {
    position: absolute;
    top: 10px;
    z-index: 100;
    display: none; /* Hidden by default, shown via media query */
    flex-direction: column;
    gap: 10px;
}

@media (max-width: 768px) {
    #top-navbar {
        height: auto;
        min-height: 60px;
        flex-direction: column;
        padding: 0.5rem;
    }

    #top-navbar .left-section,
    #top-navbar .right-section,
    #top-navbar .center-section {
        width: 100%;
        justify-content: center;
        padding: 0.25rem 0;
    }

    #top-navbar .center-section {
        order: -1;
        font-size: 1.1rem;
    }

    #top-navbar .right-section {
        order: -2;
    }

    #bottom-navbar {
        height: 48px !important;
        min-height: 48px;
        padding: 0 1rem;
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between;
        z-index: 2000;
    }

    #bottom-navbar .center-section {
        display: flex !important;
        flex: 1;
        width: auto !important;
    }

    #bottom-navbar .left-section,
    #bottom-navbar .right-section {
        width: auto !important;
        flex: 1;
    }

    #main-container {
        flex: 1; /* Ensure it grows to fill space */
        height: 0; /* Standard flexbox trick to allow content to define height within flex parent */
        min-height: 0;
        flex-direction: column;
        position: relative; /* Keep relative for absolute children */
    }

    .side-portion {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 85% !important;
        z-index: 1000;
        box-shadow: 0 0 15px rgba(0,0,0,0.3);
        transition: transform 0.3s ease-in-out;
        border: none;
        display: block !important;
    }

    #left-portion {
        left: 0;
        transform: translateX(0);
    }

    #left-portion.closed {
        transform: translateX(-100%);
        display:none;
    }

    #right-portion {
        right: 0;
        bottom: 0;
        top: auto !important;
        width: 100% !important;
        height: 50% !important;
        transform: translateY(0);
    }

    #right-portion.closed {
        transform: translateY(100%);
        visibility: hidden !important;
    }

    .side-portion .side-strip {
        display: none !important; /* Hide strips on mobile */
    }

    .side-portion.closed,
    .side-portion.closed .side-strip {
        display: none !important;
    }


    .mobile-toggle-container {
        display: flex;
    }

    #mobile-left-toggle-container {
        left: 10px;
    }

    #mobile-right-toggle-container {
        right: 10px;
    }

    .ui.button.mobile-fab {
        width: 45px;
        height: 45px;
        border-radius: 50% !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 5px rgba(0,0,0,0.3);
        background-color: white !important;
        color: #0068f5 !important;
    }

    #center-portion {
        height: 100%;
        width: 100%;
    }

    .search-container {
        width: 100% !important;
        max-width: 100%;
        z-index: 2000;
    }

    .search-container:focus-within {
        z-index: 2001;
    }

    .search-container input {
        width: 100% !important;
        border-radius: 20px !important;
        padding-right: 35px !important;
    }
}

.close-drawer-btn {
    position: sticky;
    top: 0;
    z-index: 2001;
    width: auto !important; /* Change from 100% to auto */
    display: flex;
    align-self: flex-start; /* Aligns to the start (right side in RTL) */
    background-color: white !important;
    margin-bottom: 10px !important;
    border: none !important; /* Optional: cleaner look */
    font-size: 1.2rem !important; /* Adjust size of X icon */
    padding: 10px !important;
}

.content-wrapper {
    display: flex;
    flex-direction: column;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    opacity: 1;
}

.side-portion.closed .content-wrapper {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    width: 0;
    overflow: hidden;
}

#center-portion {
    flex-grow: 1;
    background-color: white;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.map-container {
    width: 100%;
    height: 100%;
}

.toggle-btn {
    margin: 0.5rem;
}

/* Search History Styles */
.search-container {
    position: relative;
    z-index: 10;
}

.search-container input {
    border-radius: 20px !important;
    padding-right: 35px !important;
}


.search-history-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
}

.search-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    color: #333;
    border-bottom: 1px solid #eee;
}

.search-history-item:last-child {
    border-bottom: none;
}

.search-history-item:hover {
    background-color: #f5f5f5;
}

.search-history-item .remove-history {
    color: #999;
    padding: 4px;
    cursor: pointer;
}

.search-history-item .remove-history:hover {
    color: #db2828;
}

.search-history-item .history-text {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
}

/* Modal RTL Support */
.ui.modal {
    direction: rtl;
    text-align: right;
}

.ui.modal > .close {
    left: 1rem !important;
    right: auto !important;
}

.ui.modal > .header {
    text-align: right;
}

.ui.modal > .actions {
    text-align: right;
}

/* Modal Positioning and Scrolling fix */
#help-modal, #terms-modal, #csv-modal {
    max-height: 80vh !important;
    top: 5% !important;
    margin: 0 auto !important;
}

#help-modal .content, #terms-modal .content, #csv-modal .content {
    padding: 1.5rem !important;
    /* Allow content to define height, let Semantic UI handle scrolling */
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch; /* Critical for smooth touch scrolling on iOS/Android */
}

.ui.modal {
    overscroll-behavior: contain;
}

/* Prevent Semantic UI from breaking flex layout by adding unnecessary padding or height to body when modal is open */
body.dimmable.dimmed {
    height: 100vh !important;
    overflow: hidden !important;
}

body.dimmable.dimmed.scrolling {
    height: 100vh !important;
    overflow: hidden !important;
}

/* Modal RTL Support */

#help-modal > .actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ui.modal > .actions > .button {
    margin-left: 0;
    margin-right: 0.25em;
}

.ui.modal .ui.checkbox {
    float: right !important;
    margin-right: 0;
    margin-left: 1em;
}

/* Make checkbox appear on the right side of the label text */
.ui.modal .ui.checkbox label {
    padding-left: 0;
    padding-right: 1.85714em;
}

.ui.modal .ui.checkbox label:before,
.ui.modal .ui.checkbox label:after {
    left: auto;
    right: 0;
}

#help-modal .header {
    display: flex;
    justify-content: center;
    text-align: center;
    align-items: center;
    gap: 10px;
    height: auto;
    min-height: 64px;
    padding: 1rem;
    font-size: 1.8rem !important; /* Increased font size */
}


#help-modal .description p{
    font-size: 1.5rem;
    line-height: 1.6;
}

#help-modal .ui.table td {
    padding-top: 5px;
    padding-bottom: 5px;
}

#layers-list .item {
    border-bottom: 1px solid rgba(34, 36, 38, 0.1) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 10px 0 !important;
    direction: ltr; /* Ensure flex layout is manageable, children will use RTL */
    width: 100%;
}

#layers-list .item:last-child {
    border-bottom: none !important;
}

#layers-list .layer-meta {
    display: flex;
    align-items: center;
    text-align: right;
    direction: rtl;
    flex-grow: 1;
}

#layers-list .layer-icon {
    margin-left: 8px;
    width: 24px !important;
    height: 24px !important;
}

#layers-list .toggle.checkbox {
    min-height: 1.2rem;
    margin-left: 0;
    margin-right: 10px;
}

#layers-list .only-btn {
    margin-right: 0 !important;
    margin-left: auto !important;
    min-width: 40px;
    padding: 0.5em 0.8em !important;
}

#layers-list .header {
    font-size: 1rem;
}

/* Center alignment */
.text-center {
    text-align: center;
}

/* Right alignment */
.text-right {
    text-align: right;
}