/* =========================================================================
   style.css — global, host-agnostic stylesheet (loaded on every page).
   Organized top-to-bottom: reset, layout, components, then responsive.
   Design tokens (var(--...)) come from the site stylesheet via base.css.
   ========================================================================= */

/* ---- Reset & base elements ---------------------------------------------- */
@font-face {
    font-family: 'Roboto Condensed';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/static/fonts/roboto-condensed-latin-400-normal.woff2') format('woff2');
}
@font-face {
    font-family: 'Roboto Condensed';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('/static/fonts/roboto-condensed-latin-700-normal.woff2') format('woff2');
}

* {
    box-sizing: border-box;
}
[hidden] { display: none !important; }

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    font-family: 'Roboto Condensed', system-ui, -apple-system, sans-serif;
    background: var(--brcolor);
}

hr {
    border: 0;
    padding: 0;
    height: 1px;
    background: var(--brcolor);
    width: 100%;
}

/* ---- Layout & structure ------------------------------------------------- */
main,
h2,
footer,
.auth,
.breadcrumbs {
    display: flex;
    width: 100%;
    max-width: var(--containerwidth);
    padding-inline: var(--space);
}

header {
    display: flex;
    width: 100%;
    max-width: var(--containerwidth);
    position: relative;
    align-items: center;
    justify-content: space-between;
    min-height: var(--navbarheight);
    background: var(--navbarcolor);
}

main {
    flex-direction: column;
    background: var(--mainbody);
    padding-block: var(--space);
    flex: 1;
    /* Content too wide to fit (mostly tables) scrolls here instead of dragging
       the header and footer sideways with it. See the Tables section. */
    overflow-x: auto;
}

h2 {
    margin: 0;
    padding-block: var(--space);
    background-color: var(--lightestcolor);
}

/* ---- Code blocks -------------------------------------------------------- */
pre {
    background-color: #f0f0f0;
    padding: calc(var(--space) / 2);
    border-radius: var(--bo-radius, 8px);
    position: relative;
}

pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    color: initial;
}

/* ---- Footer ------------------------------------------------------------- */
footer {
    display: flex;
    flex-basis: 100%;
    background: var(--footercolor);
    padding-block: calc(var(--space) * 2);
    gap: var(--space);
    flex-direction: column;
    color: white;
}

footer>section {
    display: flex;
    flex-basis: 100%;
    flex-direction: row;
    gap: var(--space);
}

footer h3 {
    color: #b4b8bb;
}

footer a,
footer a:visited,
footer a:active,
footer a:hover {
    color: #b4b8bb;
}

h3,
h4 {
    color: var(--footercolor);
}

/* ---- Header, nav & auth bar --------------------------------------------- */
.logo {
    display: flex;
    align-items: center;
    padding-left: var(--space);
    height: var(--navbarheight);
    z-index: 7;
}

.auth {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    background: var(--navbaritemcolor);
    padding-block: calc(var(--space) / 2);
    gap: calc(var(--space) / 2);
}

.breadcrumbs {
    flex-direction: row;
    align-items: baseline;
    flex-wrap: wrap;
    background: #e4c7ab;
    padding-block: calc(var(--space) / 2);
    row-gap: calc(var(--space) / 3);
    line-height: 1.4;
}

.breadcrumb-chunk {
    display: inline-flex;
    align-items: baseline;
    flex-shrink: 0;
    white-space: nowrap;
}

.breadcrumb-sep {
    color: inherit;
    opacity: 0.55;
    padding-inline: 0.45em;
}

.auth>span:not(.cg-api-spinner),
.auth>strong,
.auth>form {
    white-space: nowrap;
    display: inline-block;
}

.auth>.cg-api-spinner {
    margin-left: auto;
    flex: 0 0 20px;
    width: 20px;
    height: 1em;
    color: #222;
    font-size: 12px;
    line-height: 1;
    text-align: center;
    animation: cg-auth-spinner-pulse 1s ease-in-out infinite;
}

.auth>.cg-api-spinner::before {
    content: '•••';
}

@keyframes cg-auth-spinner-pulse {
    50% {
        opacity: 0.3;
    }
}

#name,
#password {
    margin-right: calc(var(--space) / 2);
}

select {
    padding: calc(var(--space) / 2);
    padding-right: calc(var(--space) * 2 + var(--space) / 2);
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    appearance: none;

    border: 1px solid black;
    background-color: white;
    background-image: url('/static/img/select_arrow.svg');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px 18px;
}

/* ---- Forms -------------------------------------------------------------- */
.formline {
    display: flex;
    margin: calc(var(--space) / 2) 0;
    align-items: center;
    flex-wrap: wrap;
}

.formline>label {
    min-width: 300px;
    margin: calc(var(--space)/4) 0;
}

.formline>input,
.formline>button {
    padding: calc(var(--space) / 2);
}

.formline>button[type='reset'] {
    background-color: #ffcc7f;
}

.formline>message {
    width: 100%;
    color: red;
}

.formline>input[type='checkbox'] {
    -ms-transform: scale(2);
    -moz-transform: scale(2);
    -webkit-transform: scale(2);
    -o-transform: scale(2);
    transform: scale(2);
    margin: calc(var(--space) / 2);
}

small {
    opacity: 0.7;
}

/* ---- Tables ------------------------------------------------------------- */
/* `overflow-x` needs a block box, and `display: block` on a <table> collapses
   its rows into a shrink-to-fit anonymous table — which is why these tables
   used to render far narrower than the page. So keep the table a table and let
   `main` (or a `div.table_scroll` wrapper) own the horizontal scrolling. */
table.table_scroll {
    display: table;
    width: 100%;
}

div.table_scroll {
    display: block;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

div.table_scroll > table {
    margin-bottom: 0;
}

table {
    border-collapse: collapse;
    border: 5px solid var(--bordercolor);
    width: 100%;
    margin-bottom: var(--space);
}

td,
th {
    padding: calc(var(--space) / 2) var(--space);
    border-width: 0;
    font-size: 95%;
}

th {
    background: var(--thcolor);
    text-align: left;
}

tr + tr th.table-group-header {
    border-top: 2px solid var(--bordercolor);
}

tr:nth-child(odd) td {
    background: var(--oddrowcolor);
}

tr:nth-child(even) td {
    background: var(--evenrowcolor);
}

/* Keep thermostat table striping tied to the rows that remain visible after filtering. */
#thermostats-table tbody > tr:nth-child(odd of :not([hidden]):not([style*="display: none"])) > td,
.hub-thermostat-table tbody > tr:nth-child(odd of :not([hidden]):not([style*="display: none"])) > td {
    background: var(--oddrowcolor);
}

#thermostats-table tbody > tr:nth-child(even of :not([hidden]):not([style*="display: none"])) > td,
.hub-thermostat-table tbody > tr:nth-child(even of :not([hidden]):not([style*="display: none"])) > td {
    background: var(--evenrowcolor);
}

td:not(:first-of-type),
th:not(:first-of-type) {
    border-left: 1px solid var(--bordercolor);
}

td.td_buttons,
th.td_buttons {
    width: 1%;
}

/* Key/value property tables (no thead): keep the label column tight. */
table.table_scroll:not(:has(thead)) > tr > td:first-of-type,
table.table_scroll:not(:has(thead)) > tbody > tr > td:first-of-type {
    width: 1%;
    white-space: nowrap;
}

/* ---- Menu --------------------------------------------------------------- */
.menu {
    display: flex;
    list-style-type: none;
    background: var(--navbarcolor);
    white-space: nowrap;
    margin: 0;
    padding: 0;
}

.menu>li>a {
    padding: 0 var(--space);
    color: var(--navbaritemcolor);
    display: flex;
    align-items: center;
}

.menu>li>a:hover {
    background: var(--lightestcolor);
    color: var(--navbarcolor);
    transition: all var(--speed) ease-out;
}

/* ---- Details / summary -------------------------------------------------- */
details {
    cursor: pointer;
}

summary {
    text-wrap: nowrap;
}

/* ---- Responsive — landscape --------------------------------------------- */
@media (orientation: landscape) {
    .menu {
        justify-content: flex-end;
    }

    .menu>li>a {
        height: var(--navbarheight);
    }

    .menu>li>a.selected {
        background: var(--navbaritemcolor);
        color: var(--navbarcolor);
    }

    #burger,
    #burger+label {
        display: none;
    }

    .formline>input[type='text'],
    .formline>textarea,
    .formline>input[type='email'],
    .formline>input[type='date'],
    .formline>input[type='number'] {
        min-width: 55%;
    }

    .formline>textarea {
        min-height: 100px;
    }
}

/* ---- Responsive — portrait ---------------------------------------------- */
@media (orientation: portrait) {
    table.table_scroll,
    div.table_scroll > table {
        border-left-width: 0;
        border-right-width: 0;
    }

    .logo {
        position: absolute;
        top: 0;
        right: var(--space);
        height: var(--navbarheight);
        display: flex;
        align-items: center;
    }

    #burger,
    #burger+label {
        position: absolute;
        display: flex;
        align-items: center;
        height: var(--navbarheight);
        top: 0;
        width: 20%;
        font-size: 30px;
    }

    #burger {
        opacity: 0;
        z-index: 9;
        cursor: pointer;
    }

    #burger+label>img,
    #burger+label>span {
        position: absolute;
        width: 30px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        box-shadow: inset 0 0 0 20px rgba(0, 0, 0, 0.1), 0 0 0 10px rgba(0, 0, 0, 0.1);
        color: var(--navbaritemcolor);
        transition: var(--speed);
        z-index: 2;
        left: var(--space);
    }

    #burger:not(:checked)+label>img {
        opacity: 0;
        transform: scale(0.01, 0.01);
    }

    #burger:checked+label>img {
        transition-delay: var(--speed);
    }

    #burger:checked+label>span {
        opacity: 0;
        box-shadow: inset 0 0 0 20px rgba(0, 0, 0, 0.1), 0 0 20px 360px rgba(0, 0, 0, 0.1);
    }

    .menu {
        align-items: baseline;
        justify-content: flex-start;
        flex-direction: column;
        width: 100%;
        transition: var(--speed);
        z-index: 5;
    }

    #burger:checked~.menu {
        /*height: calc(var(--mobilemenuitemheight) * 5);*/
        margin-top: var(--navbarheight);
        box-shadow: 0 240px 90px 120px rgba(0, 0, 0, 0.8);
    }

    #burger:not(:checked)~.menu {
        height: var(--navbarheight);
        padding: 35px 0 0 calc(var(--space) + 5px);
        opacity: 0;
    }

    .menu>li>a,
    .menu>li {
        height: var(--mobilemenuitemheight);
        width: 100%;
        transition: var(--speed);
    }

    #burger:not(:checked)~.menu>li>a,
    #burger:not(:checked)~.menu>li {
        padding: 5px 0;
        height: 5px;
        width: calc(var(--space) + 2px);
    }

    #burger:not(:checked)~.menu>li>a {
        font-size: 5px;
    }

    .formline>input[type='text'],
    .formline>textarea,
    .formline>input[type='email'],
    .formline>input[type='date'],
    .formline>input[type='number'],
    .formline>button,
    .formline>select {
        min-width: 100%;
    }

    .formline>textarea {
        min-height: 100px;
    }

    .table_scroll {
        margin-inline: calc(var(--space) * -1);
    }

    main>iframe,
    main>div,
    main>table {
        border-inline: none;
    }
}

@keyframes cg-modal-dialog-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Thermostat health details + reason chips (backoffice status_lights.html,
   hub building_thermostats.html, cg_util.js). */
.thermostat-health-details {
    display: inline-block;
    margin-inline-start: 0.25em;
}

.thermostat-health-details > summary {
    display: list-item;
    cursor: pointer;
}

.thermostat-health-reasons {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.45rem;
}

.thermostat-reason {
    position: relative;
    display: inline-block;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.16rem 0.58rem;
    font-size: 0.82rem;
    line-height: 1.4;
    text-decoration: none;
}

.thermostat-reason::after {
    position: absolute;
    z-index: 20;
    bottom: calc(100% + 0.5rem);
    left: 50%;
    width: max-content;
    max-width: min(20rem, 80vw);
    padding: 0.45rem 0.65rem;
    border-radius: 0.55rem;
    color: #fff;
    background: #292524;
    box-shadow: 0 4px 12px rgb(0 0 0 / 18%);
    content: attr(data-tooltip);
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, 0.2rem);
    transition: opacity 120ms ease, transform 120ms ease, visibility 120ms;
    pointer-events: none;
}

.thermostat-reason:hover::after,
.thermostat-reason:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.device-status-indicator {
    position: relative;
    display: inline-flex;
    line-height: 1;
}

.device-status-trigger {
    display: inline-flex;
    cursor: pointer;
    line-height: 1;
}

.device-status-tooltip {
    position: absolute;
    z-index: 100;
    top: calc(100% + 0.35rem);
    left: -0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    width: max-content;
    min-width: min(22rem, 80vw);
    max-width: min(32rem, 90vw);
    padding: 1rem 1.2rem;
    border: 2px solid transparent;
    border-radius: 0.7rem;
    color: #fff;
    background: #292524;
    box-shadow: 0 4px 12px rgb(0 0 0 / 20%);
    font-size: 95%;
    line-height: 1.55;
    white-space: normal;
    opacity: 0;
    visibility: hidden;
}

.device-status-indicator:hover .device-status-tooltip,
.device-status-indicator:focus-within .device-status-tooltip,
.device-status-indicator.is-pinned .device-status-tooltip {
    opacity: 1;
    visibility: visible;
}

.device-status-indicator.is-pinned .device-status-tooltip {
    border-color: #fff;
    animation: device-status-tooltip-pinned 500ms ease-out both;
}

.device-status-indicator.is-dismissed .device-status-tooltip {
    opacity: 0;
    visibility: hidden;
}

@keyframes device-status-tooltip-pinned {
    0% {
        border-color: transparent;
        box-shadow: 0 4px 12px rgb(0 0 0 / 20%), 0 0 0 0 rgb(255 255 255 / 0%);
    }
    35% {
        border-color: #fff;
        box-shadow: 0 4px 12px rgb(0 0 0 / 20%), 0 0 0 5px rgb(255 255 255 / 40%);
    }
    100% {
        border-color: #fff;
        box-shadow: 0 4px 12px rgb(0 0 0 / 20%), 0 0 0 0 rgb(255 255 255 / 0%);
    }
}

.device-status-tooltip__state,
.device-status-tooltip__alerts {
    font-weight: 700;
}

.device-status-tooltip__row {
    display: flex;
    justify-content: space-between;
    gap: 1.25rem;
}

.device-status-tooltip__alerts {
    margin-top: 0.35rem;
}

.device-status-tooltip__quiet {
    color: #d6d3d1;
}

.device-status-tooltip ul {
    margin: 0;
    padding-inline-start: 1.1rem;
}

.device-status-tooltip a {
    color: #bfdbfe;
    text-decoration: underline;
}

.thermostat-reason--fault,
.thermostat-reason--defect {
    color: #7f1d1d;
    background: #fee2e2;
    border-color: #fecaca;
}

.thermostat-reason--warning {
    color: #78350f;
    background: #fef3c7;
    border-color: #fde68a;
}

.thermostat-reason--offline,
.thermostat-reason--never_seen {
    color: #374151;
    background: #f3f4f6;
    border-color: #e5e7eb;
}

.thermostat-reason--warning:hover,
.thermostat-reason--fault:hover,
.thermostat-reason--defect:hover {
    filter: brightness(0.96);
}

.cg-toast-host {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(360px, calc(100vw - 24px));
    pointer-events: none;
}

.cg-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 10px 10px 14px;
    background: #fff;
    border: 1px solid var(--bordercolor, #8e7964);
    border-radius: var(--bo-radius, 8px);
    box-shadow: var(--shadow-subtle, 0 2px 4px rgba(6, 17, 12, 0.12));
}

.cg-toast--leaving {
    animation: cg-toast-out var(--speed, .3s) ease-in forwards;
    pointer-events: none;
}

@keyframes cg-toast-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(16px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cg-toast--leaving {
        animation: none;
    }
}

.cg-toast__message {
    margin: 0;
    flex: 1;
    min-width: 0;
}

.cg-toast__close {
    flex: none;
    padding: 0 6px;
    margin: -4px -4px 0 0;
    border: 0;
    background: transparent;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}
