:root {
    /*
     * Demosthine.com palette derived from LogoHeader.png
     * Black / midnight navy / electric blue / cyan / silver-white
     */
    --page-black: #000000;
    --header-black: #000000;

    --nav-bg: #031326;
    --nav-bg-hover: #06264A;
    --nav-border: #075E9D;

    --menu-bg: #082747;
    --menu-bg-hover: #0A3B68;

    --content-bg: #0A1E32;
    --content-surface: #0D2942;

    --text-primary: #F0F0F0;
    --text-secondary: #B8C5D1;

    --accent: #00B7F4;
    --accent-deep: #0088D4;
    --accent-electric: #009FE3;

    --body-edge-glow: rgba(0, 183, 244, 0.34);
    --body-edge-shadow: rgba(0, 0, 0, 0.96);

    --site-max-width: 1400px;
    --nav-height: 56px;
    --footer-height: 50px;
    --transition-speed: 180ms;
}

/* =========================================================
   RESET / DOCUMENT
   ========================================================= */

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

html {
    overflow-y: scroll;
}

html,
body {
    margin: 0;
    min-height: 100%;
    width: 100%;
}

html {
    background: var(--page-black);
}

body {
    min-height: 100vh;
    background: var(--page-black);
    color: var(--text-primary);
    font-family:
        Inter,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
    overflow-x: hidden;
}

a {
    color: inherit;
}

button,
input,
textarea,
select {
    font: inherit;
}

/* =========================================================
   MAIN PAGE SHELL
   ========================================================= */

.page-shell {
    position: relative;
    display: flex;
    flex-direction: column;

    width: min(100%, var(--site-max-width));
    min-height: 100vh;

    margin: 0 auto;

    background: var(--content-bg);

    box-shadow:
        -24px 0 38px -28px var(--body-edge-glow),
        24px 0 38px -28px var(--body-edge-glow),
        -10px 0 18px -12px var(--body-edge-shadow),
        10px 0 18px -12px var(--body-edge-shadow);
}

/*
 * Side gradients create the raised / recessed transition from
 * the centered site body into the black browser background.
 */
.page-shell::before,
.page-shell::after {
    content: "";
    position: fixed;
    top: 0;
    bottom: 0;

    width: 42px;
    pointer-events: none;
    z-index: 1000;
}

.page-shell::before {
    left: max(0px, calc((100vw - var(--site-max-width)) / 2 - 42px));

    background: linear-gradient(
        to right,
        rgba(0, 0, 0, 0),
        rgba(118, 153, 181, 0.06),
        rgba(118, 153, 181, 0.18),
        rgba(0, 0, 0, 0.62)
    );
}

.page-shell::after {
    right: max(0px, calc((100vw - var(--site-max-width)) / 2 - 42px));

    background: linear-gradient(
        to left,
        rgba(0, 0, 0, 0),
        rgba(118, 153, 181, 0.06),
        rgba(118, 153, 181, 0.18),
        rgba(0, 0, 0, 0.62)
    );
}

/* =========================================================
   HEADER
   ========================================================= */

.site-header {
    position: relative;
    flex: 0 0 auto;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    padding: 0;

    background: var(--header-black);
    overflow: hidden;
}

.site-logo-link {
    display: block;
    line-height: 0;
    text-decoration: none;
}

.site-logo {
    display: block;

    width: auto;
    max-width: 100%;
    height: auto;

    margin: 0 auto;
}

/* =========================================================
   NAVIGATION BAR
   ========================================================= */

.navigation-bar {
    position: relative;
    z-index: 500;

    flex: 0 0 var(--nav-height);
    height: var(--nav-height);

    background: var(--nav-bg);
    border-top: 1px solid var(--nav-border);
    border-bottom: 1px solid var(--nav-border);

    color: var(--text-primary);
}

.navigation-inner {
    position: relative;

    display: flex;
    align-items: stretch;

    width: 100%;
    height: 100%;
}

/* =========================================================
   COLLAPSIBLE MENU
   ========================================================= */

.menu-wrapper {
    position: relative;
    flex: 0 0 auto;
}

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    height: 100%;
    min-width: 118px;

    padding: 0 18px;

    border: 0;
    border-right: 1px solid var(--nav-border);

    background: var(--nav-bg);
    color: var(--text-primary);

    cursor: pointer;

    transition:
        background var(--transition-speed) ease,
        color var(--transition-speed) ease;
}

.menu-toggle:hover,
.menu-toggle:focus-visible,
.menu-toggle[aria-expanded="true"] {
    background: var(--nav-bg-hover);
}

.menu-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.menu-toggle-icon {
    display: flex;
    flex-direction: column;
    gap: 4px;

    width: 20px;
}

.menu-toggle-icon span {
    display: block;

    width: 100%;
    height: 2px;

    border-radius: 2px;
    background: currentColor;
}

.menu-toggle-text {
    font-size: 0.95rem;
    font-weight: 600;
}

.collapsible-menu {
    position: absolute;

    /*
     * Anchors the menu's top-left corner to the bottom-left
     * corner of the Navigation Bar / menu button.
     */
    top: 100%;
    left: 0;

    width: 260px;
    max-width: calc(100vw - 24px);

    padding: 8px 0;

    background: var(--menu-bg);
    border-right: 1px solid var(--nav-border);
    border-bottom: 1px solid var(--nav-border);

    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.42);

    opacity: 0;
    visibility: hidden;

    transform: translateY(-8px);
    transform-origin: top left;

    transition:
        opacity var(--transition-speed) ease,
        transform var(--transition-speed) ease,
        visibility var(--transition-speed) ease;
}

.collapsible-menu.open {
    opacity: 1;
    visibility: visible;

    transform: translateY(0);
}

.collapsible-menu-link {
    display: block;

    width: 100%;
    padding: 13px 20px;

    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;

    transition:
        background var(--transition-speed) ease,
        padding-left var(--transition-speed) ease;
}

.collapsible-menu-link:hover,
.collapsible-menu-link:focus-visible {
    background: var(--menu-bg-hover);
    padding-left: 26px;
}

.collapsible-menu-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.collapsible-menu-separator {
    height: 1px;
    margin: 7px 14px;

    background: var(--nav-border);
}

/* =========================================================
   STATIC NAVIGATION
   ========================================================= */

.static-navigation {
    display: flex;
    align-items: stretch;
    justify-content: flex-start;

    min-width: 0;
    height: 100%;
}

.navigation-link {
    position: relative;

    display: flex;
    align-items: center;
    justify-content: center;

    min-width: 112px;
    padding: 0 22px;

    color: var(--text-primary);
    text-decoration: none;

    font-size: 0.95rem;
    font-weight: 600;

    border-right: 1px solid rgba(255, 255, 255, 0.06);

    transition:
        background var(--transition-speed) ease,
        color var(--transition-speed) ease;
}

.navigation-link:hover,
.navigation-link:focus-visible {
    background: var(--nav-bg-hover);
}

.navigation-link.active {
    background: var(--nav-bg-hover);
}

.navigation-link.active::after {
    content: "";
    position: absolute;

    left: 18px;
    right: 18px;
    bottom: 0;

    height: 3px;
    border-radius: 3px 3px 0 0;

    background: var(--accent);
}

.navigation-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* =========================================================
   CONTENT PANEL
   ========================================================= */

.content-panel {
    position: relative;

    flex: 1 1 auto;

    display: block;

    width: 100%;
    min-height: 0;

    padding: clamp(22px, 4vw, 48px);

    background: var(--content-bg);
    color: var(--text-primary);
}

.content-section {
    width: 100%;
    max-width: 1100px;

    margin: 0 auto;
    padding: clamp(24px, 4vw, 42px);

    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;

    background: var(--content-surface);
    box-shadow:
        0 12px 26px rgba(0, 0, 0, 0.20),
        inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

.content-section h1 {
    margin: 0 0 18px;

    font-size: clamp(1.7rem, 3vw, 2.6rem);
    line-height: 1.15;
}

.content-section p {
    margin: 0;

    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.7;
}

/* =========================================================
   FOOTER
   ========================================================= */

.site-footer {
    flex: 0 0 var(--footer-height);

    display: flex;
    align-items: center;
    justify-content: center;

    min-height: var(--footer-height);

    padding: 10px 20px;

    background: var(--nav-bg);
    border-top: 1px solid var(--nav-border);

    color: var(--text-primary);
    text-align: center;
}

.site-footer p {
    margin: 0;

    font-size: 0.9rem;
    line-height: 1.4;
}

/* =========================================================
   RESPONSIVE LAYOUT
   ========================================================= */

@media (max-width: 1400px) {
    .page-shell {
        width: 100%;
        box-shadow: none;
    }

    .page-shell::before,
    .page-shell::after {
        display: none;
    }
}

@media (max-width: 700px) {
    :root {
        --nav-height: 54px;
    }

    .site-logo {
        max-width: 100%;
    }

    .menu-toggle {
        min-width: 58px;
        padding: 0 17px;
    }

    .menu-toggle-text {
        display: none;
    }

    .static-navigation {
        flex: 1 1 auto;
    }

    .navigation-link {
        flex: 1 1 0;

        min-width: 0;
        padding: 0 10px;

        font-size: 0.9rem;
    }

    .navigation-link.active::after {
        left: 10px;
        right: 10px;
    }

    .collapsible-menu {
        width: min(280px, calc(100vw - 18px));
    }

    .content-panel {
        padding: 18px 14px;
    }

    .content-section {
        padding: 22px 18px;
        border-radius: 7px;
    }

    .site-footer {
        padding-left: 12px;
        padding-right: 12px;
    }
}

@media (max-width: 430px) {
    .navigation-link {
        padding: 0 6px;
        font-size: 0.82rem;
    }
}

/* =========================================================
   ACCESSIBILITY / MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}


/* =========================================================
   SCHNEIDER CONEXT CONFIGURATION FORM
   ========================================================= */

.schneider-content {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.schneider-form {
    width: 100%;
    max-width: 100%;
}

.schneider-section {
    width: 100%;
    margin: 0 0 24px;
    overflow: hidden;
    border: 1px solid var(--nav-border);
    border-radius: 9px;
    background: var(--content-surface);
    box-shadow:
        0 10px 24px rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

.schneider-section-heading,
.device-section-toolbar {
    min-height: 54px;
    padding: 10px 16px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
}

.schneider-section-heading {
    display: flex;
    align-items: center;
}

.schneider-section-heading h1,
.device-section-toolbar h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.12rem;
    font-weight: 700;
}

.system-fields {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.system-field-row {
    display: grid;
    grid-template-columns: minmax(150px, 220px) minmax(0, 360px);
    align-items: start;
    gap: 16px;
}

.system-field-row > label {
    padding-top: 10px;
    color: var(--text-primary);
    font-weight: 700;
}

.field-input-wrap {
    width: 100%;
}

.text-input {
    width: 100%;
    height: 40px;
    padding: 7px 10px;
    border: 1px solid #557087;
    border-radius: 5px;
    background: #FFFFFF;
    color: #111820;
    outline: none;
}

.text-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 183, 244, 0.18);
}

.field-help {
    display: block;
    margin-top: 5px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.35;
}

.device-section-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.device-section-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}

.toolbar-button,
.primary-action-button,
.delete-device-button {
    min-height: 36px;
    padding: 7px 15px;
    border: 1px solid var(--accent-deep);
    border-radius: 5px;
    background: var(--nav-bg-hover);
    color: var(--text-primary);
    font-weight: 700;
    cursor: pointer;
    transition:
        background var(--transition-speed) ease,
        border-color var(--transition-speed) ease,
        box-shadow var(--transition-speed) ease;
}

.toolbar-button:hover,
.toolbar-button:focus-visible,
.primary-action-button:hover,
.primary-action-button:focus-visible {
    background: var(--accent-deep);
    border-color: var(--accent);
}

.toolbar-button:focus-visible,
.primary-action-button:focus-visible,
.delete-device-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.device-table {
    width: 100%;
    overflow-x: auto;
}

.device-row {
    display: grid;
    grid-template-columns:
        minmax(110px, 0.72fr)
        minmax(110px, 0.72fr)
        minmax(220px, 4fr)
        minmax(110px, 0.72fr);
    width: 100%;
    min-width: 700px;
}

.device-header-row {
    background: rgba(0, 0, 0, 0.22);
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
    color: var(--text-primary);
    font-weight: 700;
}

.device-data-row {
    border-bottom: 1px solid rgba(255, 255, 255, 0.075);
}

.device-data-row:last-child {
    border-bottom: 0;
}

.device-cell {
    display: flex;
    align-items: center;
    min-width: 0;
    padding: 10px 12px;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
}

.device-cell:last-child {
    border-right: 0;
}

.col-row-id,
.col-modbus,
.col-delete {
    justify-content: center;
    text-align: center;
}

.col-device-name {
    justify-content: stretch;
}

.row-id-value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    min-height: 32px;
    padding: 4px 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.20);
    font-weight: 700;
}

.modbus-input {
    width: 84px;
    text-align: center;
}

.delete-device-button {
    width: 84px;
    padding-left: 8px;
    padding-right: 8px;
    border-color: #8A3B3B;
    background: #4A1E24;
}

.delete-device-button:hover,
.delete-device-button:focus-visible {
    background: #6B2930;
    border-color: #C75A63;
}

.mobile-cell-label {
    display: none;
}

.schneider-form-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 2px;
}

.primary-action-button {
    min-width: 190px;
}

/* Schneider Sensors popup placeholder */

body.modal-open {
    overflow: hidden;
}

.sensor-modal {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.sensor-modal.open {
    display: flex;
}

.sensor-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
}

.sensor-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(620px, 100%);
    min-height: 240px;
    overflow: hidden;
    border: 1px solid var(--nav-border);
    border-radius: 9px;
    background: var(--content-bg);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}

.sensor-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 54px;
    padding: 10px 14px 10px 18px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
}

.sensor-modal-header h2 {
    margin: 0;
    font-size: 1.12rem;
}

.sensor-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-primary);
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
}

.sensor-modal-close:hover,
.sensor-modal-close:focus-visible {
    background: var(--nav-bg-hover);
}

.sensor-modal-content {
    padding: 24px;
    color: var(--text-secondary);
}

@media (max-width: 760px) {
    .system-field-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .system-field-row > label {
        padding-top: 0;
    }

    .device-section-toolbar {
        align-items: flex-start;
    }

    .device-table {
        overflow: visible;
    }

    .device-header-row {
        display: none;
    }

    .device-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        min-width: 0;
        padding: 12px;
        gap: 10px;
    }

    .device-cell {
        display: block;
        padding: 0;
        border: 0;
    }

    .col-device-name {
        grid-column: 1 / -1;
    }

    .mobile-cell-label {
        display: block;
        margin-bottom: 5px;
        color: var(--text-secondary);
        font-size: 0.75rem;
        font-weight: 700;
        text-align: left;
    }

    .col-row-id,
    .col-modbus,
    .col-delete {
        text-align: left;
    }

    .row-id-value,
    .modbus-input,
    .delete-device-button {
        width: 100%;
    }

    .row-id-value {
        min-height: 40px;
    }
}

@media (max-width: 480px) {
    .device-section-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .device-section-actions {
        justify-content: flex-end;
    }

    .device-row {
        grid-template-columns: 1fr;
    }

    .col-device-name {
        grid-column: auto;
    }

    .schneider-form-actions {
        justify-content: stretch;
    }

    .primary-action-button {
        width: 100%;
    }
}


/* =========================================================
   SCHNEIDER SENSOR REGISTER SELECTION
   ========================================================= */

.sensor-modal-dialog {
    width: min(1280px, calc(100vw - 48px));
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
}

.sensor-modal-content {
    min-height: 180px;
    overflow: auto;
}

.sensor-table-wrapper {
    width: 100%;
    overflow: auto;
}

.sensor-selection-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    color: var(--text-primary);
    font-size: 0.84rem;
}

.sensor-selection-table th,
.sensor-selection-table td {
    padding: 9px 10px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.sensor-selection-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--nav-bg);
    color: var(--text-primary);
    font-weight: 700;
}

.sensor-selection-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.025);
}

.sensor-selection-table tbody tr:hover {
    background: rgba(0, 183, 244, 0.08);
}

.sensor-selection-table .sensor-select-column {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 68px;
    text-align: center;
    background: var(--content-bg);
}

.sensor-selection-table th.sensor-select-column {
    z-index: 3;
    background: var(--nav-bg);
}

.sensor-register-checkbox {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.sensor-loading-message,
.sensor-empty-message,
.sensor-unavailable-message,
.sensor-error-message {
    margin: 0;
    color: var(--text-secondary);
}

.sensor-unavailable-message strong,
.sensor-error-message strong {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.sensor-unavailable-message p,
.sensor-error-message p {
    margin: 0;
    line-height: 1.55;
}

@media (max-width: 760px) {
    .sensor-modal {
        padding: 10px;
    }

    .sensor-modal-dialog {
        width: calc(100vw - 20px);
        max-height: calc(100vh - 20px);
    }

    .sensor-modal-content {
        padding: 14px;
    }

    .sensor-selection-table {
        font-size: 0.78rem;
    }

    .sensor-selection-table th,
    .sensor-selection-table td {
        padding: 8px;
    }
}
