/*
 * HYDRO - Mobile-First CSS - MINIMAL VERSION
 * Only essential enhancements, NO Bootstrap overrides
 */

/* ============================================================================
   CSS CUSTOM PROPERTIES
   ============================================================================ */

:root {
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --touch-target-min    : 44px;
    --touch-target-optimal: 48px;
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
}

/* ============================================================================
   BASE STYLES
   ============================================================================ */

* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

body {
    padding-top   : var(--sat);
    padding-right : var(--sar);
    padding-bottom: var(--sab);
    padding-left  : var(--sal);
    overscroll-behavior-y     : contain;
    -webkit-overflow-scrolling: touch;
}

/* ============================================================================
   PREVENT iOS ZOOM
   ============================================================================ */

input,
select,
textarea,
.form-control,
.form-select {
    font-size: max(16px, 1rem);
}

/* ============================================================================
   NOTIFICATIONS - HORIZONTAL LAYOUT
   ============================================================================ */

#ntf_btn {
    display       : inline-flex !important;
    flex-direction: row !important;
    align-items   : center !important;
    gap           : 0.5rem !important;
    background    : transparent;
    border        : none;
    color         : #fff;
    padding       : 0.5rem 0.75rem;
    cursor        : pointer;
}

#ntf_btn:hover,
#ntf_btn:focus {
    background-color: rgba(255, 255, 255, 0.1);
}

#ntf_btn i {
    font-size : 1.25rem;
    flex-shrink: 0;
}

#ntf_btn > span {
    display       : inline-flex !important;
    flex-direction: row !important;
    align-items   : center !important;
    gap           : 0.25rem !important;
}

#ntf_lt_nb,
#ntf_td_nb {
    position     : relative !important;
    min-width    : 20px;
    height       : 20px;
    padding      : 0 6px;
    font-size    : 0.7rem;
    line-height  : 20px;
    text-align   : center;
    border-radius: 10px;
    font-weight  : bold;
    display      : none;
    flex-shrink  : 0;
}

#ntf_lt_nb {
    background-color: #dc3545 !important;
    color           : white !important;
}

#ntf_td_nb {
    background-color: #ffc107 !important;
    color           : #000 !important;
}

#ntf_lt_nb:not(:empty),
#ntf_td_nb:not(:empty) {
    display: inline-block !important;
}

#ntf_lst {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    min-width : 320px;
    max-width : 400px;
}

#ntf_lst::-webkit-scrollbar        { width: 8px; }
#ntf_lst::-webkit-scrollbar-track  { background: #1a1a1a; }
#ntf_lst::-webkit-scrollbar-thumb  { background: #555; border-radius: 4px; }

#ntf_lst li               { border-bottom: 1px solid rgba(255,255,255,0.1); list-style: none; }
#ntf_lst li:last-child    { border-bottom: none; }
#ntf_lst .dropdown-item   { white-space: normal; padding: 0.75rem 1rem; word-wrap: break-word; }
#ntf_lst .dropdown-item.text-warning { color: #ffc107 !important; }
#ntf_lst .dropdown-item.text-danger  { color: #dc3545 !important; }
#ntf_lst .fw-bold { font-weight: 600 !important; margin-bottom: 0.25rem; display: block; }
#ntf_lst small    { font-size: 0.85rem; opacity: 0.9; line-height: 1.4; display: block; }

/* ============================================================================
   MOBILE RESPONSIVENESS
   ============================================================================ */

@media (max-width: 767px) {

    /* ── Display -----------------------------------------------------------
       Anchor content at the top so GMAO tables/forms start at the top of
       the display area (which is already below the navbar via flex-column).
       SCADA overrides alignItems/justifyContent directly in _addGrid() and
       resets them in dispose(), so these rules do not affect SCADA on desktop.
       ----------------------------------------------------------------------- */
    #display {
        align-items    : flex-start !important;
        justify-content: flex-start !important;
        overflow-y     : auto !important;
        padding        : var(--spacing-sm);
    }

    /* Buttons */
    .btn-lg,
    button.btn-lg {
        min-height: var(--touch-target-optimal);
        padding   : var(--spacing-md) var(--spacing-lg);
    }

    #status { display: none !important; }

    /* Notifications */
    #ntf_btn   { padding: 0.5rem; }
    #ntf_btn i { font-size: 1.1rem; }

    #ntf_lt_nb,
    #ntf_td_nb {
        min-width  : 18px;
        height     : 18px;
        font-size  : 0.65rem;
        line-height: 18px;
        padding    : 0 5px;
    }

    #ntf_lst {
        max-height: 60vh;
        min-width : 280px;
        max-width : calc(100vw - 2rem);
    }

    #ntf_lst .dropdown-item { padding: 0.625rem 0.875rem; font-size: 0.9rem; }

    /* ── Modal dialogs ----------------------------------------------------- */
    dialog.h-modal {
        width     : 94vw !important;
        max-height: 82vh !important;
        overflow-y: auto;
    }
    dialog.h-modal .modal-body { overflow-y: auto; }

    /* ── Left navbar dropdown (#subMenu) -----------------------------------
       position:fixed escapes any overflow:hidden ancestor (navbar, display).
       top is set dynamically by JS (Gui._initAllDropdowns → fixSubMenu).
       bottom:0 stretches the panel to the viewport bottom — JS must NOT
       override this with style.height (that line was removed from Gui.js).
       overflow-y:auto makes the full list scrollable on portrait mobile.
       ----------------------------------------------------------------------- */
    #subMenu {
        position                  : fixed !important;
        top                       : 56px !important; /* overridden by JS */
        left                      : 0 !important;
        right                     : auto !important;
        bottom                    : 0 !important;    /* fills to viewport bottom */
        width                     : 80vw !important;
        max-width                 : 320px !important;
        max-height                : calc(var(--vh, 1vh) * 100 - 56px); /* --vh from Screen.js = visual viewport */
        overflow-y                : auto !important;
        overflow-x                : hidden;
        -webkit-overflow-scrolling: touch;
        z-index                   : 1050;
        border-radius             : 0 !important;
    }

    /* ── Nested submenus ---------------------------------------------------
       On mobile, position:absolute + left:100% (dropdown.css) would push
       them off-screen. Override to static so they expand inline within the
       scrollable #subMenu panel.
       JS (Gui._initSubmenus) toggles [data-open] to show/hide them.
       ----------------------------------------------------------------------- */
    .dropdown-menu .submenu,
    .dropdown-menu .submenu-left {
        position        : static !important;
        display         : none !important;
        left            : auto !important;
        top             : auto !important;
        margin-left     : 0.75rem;
        border-left     : 2px solid rgba(255, 255, 255, 0.15);
        box-shadow      : none !important;
        background-color: rgba(255, 255, 255, 0.04) !important;
        width           : auto !important;
        max-width       : none !important;
    }

    .submenu[data-open] { display: block !important; }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

*:focus,
*:focus-visible {
    outline       : 2px solid #0d6efd;
    outline-offset: 2px;
}

/* ============================================================================
   SMOOTH ANIMATIONS
   ============================================================================ */

@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration       : 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration      : 0.01ms !important;
    }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    #navbar, #ntf, .modal, .alert { display: none !important; }
    body { background: white !important; color: black !important; }
}

/* ============================================================================
   GMAO — Aesthetic layer
   ============================================================================ */

.gmao-table-container {
    width        : 100%;
    max-width    : 1024px;
    margin       : 0.75rem auto;
    border-radius: 10px;
    overflow     : hidden;
    box-shadow   : 0 4px 24px rgba(0,0,0,.45);
    border       : 1px solid #2e2e4a;
}

.gmao-table { margin-bottom: 0 !important; }

.gmao-thead tr th {
    background    : linear-gradient(135deg, #1e1e35, #15152a) !important;
    color         : #7a9fd4 !important;
    font-size     : 0.72rem;
    font-weight   : 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    padding       : 0.65rem 0.9rem !important;
    border-bottom : 2px solid #3d3d5c !important;
    white-space   : nowrap;
}

.gmao-table tbody tr {
    transition  : background-color .15s ease, border-left-color .15s ease;
    border-left : 3px solid transparent;
    cursor      : pointer;
}

.gmao-table tbody tr:hover {
    background-color : rgba(90,130,196,.13) !important;
    border-left-color: #5a82c4;
}

.gmao-table tbody td,
.gmao-table tbody th {
    padding       : 0.55rem 0.9rem !important;
    font-size     : 0.87rem;
    vertical-align: middle;
    border-color  : rgba(255,255,255,.05) !important;
    color         : #c8d0e0;
}

.gmao-form-card {
    width        : 100%;
    max-width    : 720px;
    margin       : 0.75rem auto;
    background   : #16162a;
    border       : 1px solid #2e2e4a;
    border-radius: 12px;
    padding      : 1.25rem 1.5rem 1.5rem;
    box-shadow   : 0 4px 24px rgba(0,0,0,.45);
}

.gmao-table-badge {
    display       : inline-block;
    font-size     : 0.68rem;
    font-weight   : 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color         : #5a82c4;
    background    : rgba(90,130,196,.1);
    border        : 1px solid #2e2e4a;
    border-radius : 4px;
    padding       : 2px 10px;
    margin-bottom : 1rem;
}

.gmao-form {
    display              : grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap                  : 0.65rem;
}

.gmao-field      { display: flex; flex-direction: column; }
.gmao-field-wide { grid-column: 1 / -1; }
.gmao-field-inline {
    display       : flex;
    flex-direction: row;
    align-items   : center;
    gap           : 0.6rem;
}
.gmao-field-inline .gmao-label {
    margin-bottom : 0;
    flex          : 0 0 auto;
    white-space   : nowrap;
}
.gmao-field-inline .gmao-input {
    flex          : 1;
    min-width     : 0;
}

@media (max-width: 767px) {
    .gmao-field-inline .gmao-label { flex-basis: 5.5rem; }
}
.gmao-label {
    font-size     : 0.68rem !important;
    font-weight   : 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color         : #7a9fd4 !important;
    margin-bottom : 0.25rem;
}

.gmao-input {
    background   : #0e0e1c !important;
    border       : 1px solid #3d3d5c !important;
    color        : #c8d0e0 !important;
    border-radius: 6px !important;
    font-size    : 0.88rem !important;
    transition   : border-color .15s, box-shadow .15s;
}

.gmao-input:focus {
    background  : #0e0e1c !important;
    border-color: #5a82c4 !important;
    color       : #e0e8f0 !important;
    box-shadow  : 0 0 0 2px rgba(90,130,196,.22) !important;
    outline     : none;
}

.gmao-input[readonly],
.gmao-input:read-only {
    background  : #0a0a15 !important;
    color       : #666e80 !important;
    border-color: #22223a !important;
    cursor      : default;
}

.gmao-switch                      { display: flex; align-items: center; gap: 0.6rem; padding: 0.35rem 0; }
.gmao-switch .form-check-input    { width: 2.4rem; height: 1.3rem; cursor: pointer; flex-shrink: 0; }

.gmao-subfield-row                           { display: flex; align-items: stretch; gap: 0; min-width: 0; }
.gmao-subfield-row .form-control             { border-radius: 6px 0 0 6px !important; flex: 1; min-width: 0; }
.gmao-subfield-row .btn                      { border-radius: 0 6px 6px 0 !important; border-left: none; flex-shrink: 0; }
.gmao-subfield-row .form-control:only-child  { border-radius: 6px !important; }

.gmao-calendar-wrapper {
    width         : 100%;
    height        : 100%;
    display       : flex;
    flex-direction: column;
    padding       : 0.5rem;
    box-sizing    : border-box;
}

.gmao-calendar-inner {
    flex         : 1;
    min-height   : 0;
    background   : #1a1a2e;
    border       : 1px solid #2e2e4a;
    border-radius: 10px;
    overflow     : hidden;
}

.gmao-calendar-inner .fc {
    --fc-border-color              : #2e2e4a;
    --fc-today-bg-color            : rgba(90,130,196,.12);
    --fc-event-bg-color            : #3a5a9a;
    --fc-event-border-color        : #2a4a8a;
    --fc-page-bg-color             : #1a1a2e;
    --fc-neutral-bg-color          : #1e1e35;
    --fc-list-event-hover-bg-color : rgba(90,130,196,.15);
}

.gmao-calendar-inner .fc-toolbar-title              { font-size: 1rem; color: #c8d0e0; }
.gmao-calendar-inner .fc-button                     { font-size: 0.78rem !important; padding: 0.25rem 0.6rem !important; }
.gmao-calendar-inner .fc-col-header-cell-cushion,
.gmao-calendar-inner .fc-daygrid-day-number         { color: #8892a4; font-size: 0.8rem; }
.gmao-calendar-inner .fc-list-day-cushion           { background: #1e1e35 !important; color: #7a9fd4; font-size: 0.78rem; }
.gmao-calendar-inner .fc-list-event td             { font-size: 0.84rem; }

.gmao-carousel-container { width: 100%; max-width: 960px; margin: 0 auto; padding: 0.5rem; box-sizing: border-box; }

@media (max-width: 767px) {
    .gmao-table-container { margin: 0.25rem; border-radius: 6px; }

    .gmao-table tbody td,
    .gmao-table tbody th  { font-size: 0.8rem;  padding: 0.45rem 0.6rem !important; }
    .gmao-thead tr th     { font-size: 0.65rem; padding: 0.5rem  0.6rem !important; }

    .gmao-form-card { margin: 0.25rem; padding: 0.9rem; border-radius: 8px; }
    .gmao-form      { grid-template-columns: 1fr; }
}