/* i-Log 4.0 dashboard.
 *
 * Built for two panels: the 800x480 Pi touchscreen and the 1280x720 16:9 panel.
 * The look is a calm instrument face: cool mineral ground, marine-ink text, and
 * colour reserved for what an operator must act on (below / near / over the
 * baku mutu). The one distinctive element is the threshold-band gauge on each
 * reading card. The product's purple stays as the only interaction accent.
 */

:root {
    --ground: #E3EAE8;
    --surface: #F8FAF9;
    --surface-2: #EDF2F0;
    --ink: #12292E;
    --ink-muted: #566A6E;
    --rule: #CBD8D5;

    --brand: #5533A4;
    --brand-tint: rgba(85, 51, 164, 0.12);

    --ok: #1D7A4F;
    --ok-tint: #E1F3E9;
    --ok-zone: #A9D8BF;
    --near: #8A5A00;
    --near-tint: #FFF0CC;
    --near-zone: #F2D487;
    --over: #B3261E;
    --over-tint: #FBE4E1;
    --over-zone: #EAA39B;

    /* Names other stylesheets/pages may still read. */
    --semantic-warning-100: var(--near-tint);
    --semantic-warning-400: var(--near);
    --semantic-positive-100: var(--ok-tint);
    --semantic-positive-600: var(--ok);
    --semantic-negative-100: var(--over-tint);
    --semantic-negative-600: var(--over);

    --font-ui: "Barlow", system-ui, sans-serif;
    --font-num: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;

    --bs-body-color: var(--ink);
    --bs-body-font-size: 13px;
    --bottom-bar-h: 2.75rem;
}

body {
    font-family: var(--font-ui);
    color: var(--ink);
    background: var(--ground);
}

#app-layout {
    background-color: var(--ground);
}

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.material-symbols-outlined {
    color: var(--ink-muted);
    width: 12px;
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.caption-regular { font-weight: 400; }
.body-02-semibold { font-weight: 600; }
.body-02-medium,
.display-2 { font-weight: 500; }

/* ---- Surfaces ---------------------------------------------------------- */

.card,
.card-body,
.card-header {
    border: none;
    border-radius: 10px;
}

.card {
    height: 100%;
    background: var(--surface);
    border: 1px solid var(--rule);
    box-shadow: none;
}

.card-body {
    height: 100%;
    padding: 0.5rem;
    background: transparent;
}

.card-header {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    background: transparent;
    padding: 0.55rem 0.75rem 0.25rem;
    border-bottom: 0;
}

.card-header.settings-section-title,
.settings-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.card-header.settings-section-title { min-height: 2.6em; }
.settings-section-title { margin-bottom: 0.5rem; }

/* ---- Row 1: logo + baku mutu key --------------------------------------- */

.logo-card { width: 140px; }

.logo-card { height: auto; min-height: 104px; }

.logo-img { width: 78%; }

#card-header-nbm {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--ink-muted);
    font-size: 12px;
}

#card-header-nbm > .float-start,
#card-header-nbm > .float-end { float: none !important; }

#circle-container {
    display: flex;
    align-items: center;
    margin-right: 0.9rem;
    color: var(--ink);
    font-weight: 500;
}

#circle-container p { margin-bottom: 0; }

#circle {
    margin-right: 0.3rem;
    height: 8px;
    width: 8px;
    border-radius: 50%;
}

.bg-red { background-color: var(--over); }
.bg-orange { background-color: var(--near-zone); box-shadow: inset 0 0 0 1px #D69600; }
.bg-green { background-color: var(--ok); }

/* The value already names the parameter ("TSS > 50"), so the small label above it is
   redundant; hiding it halves the key's height on the 480 px panel. */
.reference-parameter { display: none; }

.reference-value {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 13px !important;
    font-weight: 600;
    color: inherit;
    text-wrap: nowrap;
    width: 100%;
}

.reference-left-col,
.reference-right-col {
    list-style-type: none;
    padding: 0;
    margin: 0;
    flex: auto;
}

.reference-right-col { margin-left: 0.75rem; }

#row-reference-values .card.negative,
#row-reference-values .card.warning,
#row-reference-values .card.positive { border: 0; }

#row-reference-values .card-body { padding: 0.45rem 0.6rem; }

ul {
    list-style-type: none;
    padding-left: 0;
    margin-bottom: 0;
}

li { margin-bottom: 0.2rem; }
li:last-child { margin-bottom: 0; }

/* Status colours, one set per place they appear. */
.card.negative,
.card-modal.negative { background-color: var(--over-tint); color: var(--over); }
.card.warning,
.card-modal.warning { background-color: var(--near-tint); color: var(--near); }
.card.positive,
.card-modal.positive { background-color: var(--ok-tint); color: var(--ok); }

.negative .card-body,
.warning .card-body,
.positive .card-body { background-color: inherit !important; }

/* ---- Row 2: reading cards ---------------------------------------------- */

#row-current-values {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.5rem;
    margin: 0;
}

#row-current-values > .col {
    padding: 0;
    width: auto;
    max-width: none;
}

/* A hidden custom-sensor card ({'display': 'none'} set by the callback for
   unconfigured slots) would otherwise still claim a grid track; drop it out of
   grid flow so only visible cards are laid out. */
#row-current-values .col:has(> .card[style*="display: none"]) { display: none; }

/* The big card around the reading cards is just a frame. */
#row-dashboard-2 > .col > .card {
    background: transparent;
    border: 0;
}

#row-dashboard-2 > .col > .card > .card-body { padding: 0 !important; }

/* Reading card: quiet by default, loud only when over the limit. */
#row-current-values .card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--rule);
    border-left-width: 4px;
}

#row-current-values .card.positive { border-left-color: var(--ok); }
#row-current-values .card.warning { border-left-color: #D69600; background: #FFFBEF; }
#row-current-values .card.negative {
    border-color: var(--over);
    background: var(--over-tint);
}

.current-body {
    flex: 1 1 auto;
    height: auto;
    padding: 0.4rem 0.55rem 0.25rem;
    background: transparent;
    border-radius: 10px 10px 0 0 !important;
}

.current-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.25rem;
}

.current-parameter {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.current-unit {
    font-size: 11px;
    font-weight: 500;
    color: var(--ink-muted);
    white-space: nowrap;
}

.current-value {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: clamp(28px, 4.2vw, 36px);
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.01em;
    min-height: 1.05em;
    margin: 0;
    color: var(--ink);
}

#row-current-values .card.negative .current-value { color: var(--over); }

/* Threshold-band gauge: three zones, the limits, and a pin at the reading. */
.band-gauge { margin-top: 0.25rem; }

.gauge-state {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 3px;
}

.positive .gauge-state { color: var(--ok); }
.warning .gauge-state { color: var(--near); }
.negative .gauge-state { color: var(--over); }

.gauge-track {
    position: relative;
    height: 8px;
}

.gauge-zones {
    position: absolute;
    inset: 0;
    border-radius: 4px;
    overflow: hidden;
    background: var(--rule);
}

.zone {
    position: absolute;
    top: 0;
    bottom: 0;
}

.zone-positive { background: var(--ok-zone); }
.zone-warning { background: var(--near-zone); }
.zone-negative { background: var(--over-zone); }

.gauge-pin {
    position: absolute;
    top: -4px;
    width: 4px;
    height: 16px;
    margin-left: -2px;
    background: var(--ink);
    border: 1px solid var(--surface);
    border-radius: 2px;
    box-sizing: content-box;
}

.gauge-scale {
    position: relative;
    height: 12px;
    margin-top: 3px;
}

.gauge-tick {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 11px;
    line-height: 1;
    color: var(--ink-muted);
}

/* Detail button: a plain text action. The status colour classes bootstrap puts
   on it (success/warning/danger) are overridden; the card already carries status. */
.btn { font-size: 12px; font-weight: 600; border-width: 0; border-radius: 10px; }

.btn.btn-detail {
    --bs-btn-bg: transparent;
    --bs-btn-hover-bg: var(--brand-tint);
    --bs-btn-active-bg: var(--brand-tint);
    --bs-btn-color: var(--brand);
    --bs-btn-hover-color: var(--brand);
    --bs-btn-active-color: var(--brand);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-color: var(--ink-muted);
    color: var(--brand);
    padding: 0.3rem 0.6rem;
    border-radius: 0 0 8px 8px;
    border-top: 1px solid var(--rule);
    text-align: left;
    font-size: 12px;
}

.btn.btn-detail::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 0.4rem;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
    transform: rotate(45deg) translateY(-1px);
}

#row-current-values .card.negative .btn.btn-detail { border-top-color: rgba(179, 38, 30, 0.3); }

.btn:disabled { border-width: 0; }

.btn-success:not(.btn-detail),
.btn-warning:not(.btn-detail),
.btn-danger:not(.btn-detail) {
    color: white;
    --bs-btn-hover-color: white;
    --bs-btn-active-color: white;
}

.btn-save {
    font-size: 15px;
    color: white !important;
    --bs-btn-bg: var(--brand);
    --bs-btn-hover-bg: #43288A;
    --bs-btn-active-bg: #43288A;
    opacity: 1;
    padding: 0.45rem 1.1rem;
}

.btn-save:hover { background-color: #43288A; opacity: 1; }
.btn-save:active { --bs-btn-active-bg: #43288A; }

/* ---- Row 3: one status strip ------------------------------------------- */

.row-dashboard-3 {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0;
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 10px;
}

.row-dashboard-3 > .dashboard-card-col {
    min-width: 0;
    padding: 0;
    flex: 0 0 auto;
    border-left: 1px solid var(--rule);
}

.row-dashboard-3 > .dashboard-card-col:first-child { border-left: 0; }
.row-dashboard-3 > .dashboard-card-col-real-time-data { min-width: max-content; }
/* Feedback takes whatever width is left; its summary truncates before the date and time do. */
.row-dashboard-3 > .dashboard-card-col-last-feedback { flex: 1 1 0; min-width: 0; }

.row-dashboard-3 > .dashboard-card-col > .card {
    width: 100%;
    min-width: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
}

.row-dashboard-3 .card-header {
    font-size: 11px;
    font-weight: 500;
    color: var(--ink-muted);
    padding: 0.3rem 0.6rem 0;
}

.row-dashboard-3 .card .card-body { background: transparent; padding: 0 0.6rem 0.4rem; }

.card-last-data,
.card-real-time-data,
.card-temperature,
.card-last-feedback {
    height: 56px;
    display: grid;
    grid-template-rows: auto 1fr;
}

.card-last-feedback { max-width: none; }

.row-dashboard-3-body {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    height: 100%;
    min-width: 0;
}

.row-dashboard-3-content {
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    padding: 0;
    max-width: 100%;
    min-width: 0;
}

#val-temperature {
    font-family: var(--font-num);
    font-size: 24px;
    line-height: 1;
    font-weight: 600;
}

.text-status { font-size: 12px; color: var(--ink); }

#real-time-data {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 12px;
    gap: 0.4rem !important;
}

#real-time-data .hstack { gap: 0.4rem !important; }

#last-feedback { min-width: 0; overflow: hidden; gap: 0.4rem !important; font-size: 13px; }

#last-data { gap: 0.4rem !important; font-size: 13px; }

#last-feedback > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}

#last-feedback > span:first-child { flex-shrink: 1; }

.vr {
    border-left: 1px solid var(--rule);
    opacity: 1;
    height: 14px;
    align-self: center;
}

.hstack { justify-content: space-evenly; }

#dashboard-current-date-time { width: 100%; }

/* ---- Detail modal ------------------------------------------------------- */

.modal-content { background-color: var(--ground); border: 1px solid var(--rule); }
.modal-footer { border-top: 0; }

.card-modal {
    gap: 0.6rem;
    display: flex;
    flex-direction: row;
    height: 36px;
    align-items: center;
    width: auto;
    padding: 0 0.75rem;
    border-radius: 10px 0 0 10px;
}

.current-parameter-modal { font-size: 15px; font-weight: 600; }

.current-value-modal {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 22px;
    font-weight: 600;
}

.logs-graph { padding: 0; }
.modebar-container { top: -20px !important; }

.btn-graph-group {
    background-color: var(--surface-2);
    border: 1px solid var(--rule);
    border-radius: 9px;
    padding: 3px;
}

.btn-graph {
    border-radius: 7px !important;
    color: var(--ink-muted);
    background-color: transparent;
    box-shadow: none;
    padding: 3px 10px;
}

.btn-graph.active {
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--rule);
}

/* ---- Forms, tables, info pages ------------------------------------------ */

.row-reports .card-body { padding-top: 0; }

table {
    font-family: inherit !important;
    --text-color: var(--ink) !important;
}

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-muted);
}

.form-control,
.form-select {
    background-color: var(--surface-2);
    border: 1px solid var(--rule);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-tint);
    background-color: var(--surface);
}

.form-control::placeholder {
    opacity: 1;
    color: #7A8C90;
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.settings-row .col:nth-child(n+3) .form-label { margin-top: 0.5rem; }

.info-label { display: inline-block; width: 150px; }
#info-value { margin-left: 10px; }
.sensor-parameter-list { width: 130px; }
.infos-card-body { background-color: var(--surface-2); }
.sensor-card p { margin-bottom: 0.25rem; }

.fs-4 {
    color: var(--brand);
    font-family: var(--font-num);
    font-weight: 600;
}

.modal-data-saved { justify-content: center; }

.modal-data-saved > .modal-content {
    width: 200px;
    height: 200px;
    background-color: var(--surface);
}

.modal-data-saved > .modal-content > .modal-body {
    align-items: center;
    justify-content: center;
    display: flex;
}

.infos-card-body > .row > .col > .row:nth-child(2) { height: 40px; }

#page-container { padding-bottom: var(--bottom-bar-h); }

.page-footer {
    /* Bottom bar: Restart + device IP (left), navbar (centre), copyright (right). A fixed, solid
       strip; #page-container reserves its height so content ends above it. */
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottom-bar-h);
    z-index: 999; /* below the dock and navbar (1000) that sit on it */
    background: var(--surface);
    border-top: 1px solid var(--rule);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-right: 0.75rem;
}

.watermark { text-align: right; line-height: 1.15; }

.watermark p {
    color: var(--ink-muted);
    margin-bottom: 0;
    font-size: 9px;
}

.watermark p:first-child {
    color: var(--ink);
    font-size: 11px;
    font-weight: 600;
}

.nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    height: var(--bottom-bar-h);
    align-items: center;
    flex-wrap: nowrap;
    width: auto;
    padding: 0 0.25rem;
    background-color: transparent;
    z-index: 1000;
    margin: auto;
    gap: 0.25rem;
}

.nav-link {
    padding: 0.3rem 0.7rem;
    border-radius: 9px;
}

.nav-link img {
    display: block;
    opacity: 0.55;
}

.nav-link:hover img { opacity: 0.85; }

.nav-link.active { background: var(--brand-tint); }
.nav-link.active img { opacity: 1; }

.reboot-dock {
    position: fixed;
    bottom: 0;
    left: 0.75rem;
    height: var(--bottom-bar-h);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.reboot-fab {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background-color: var(--surface);
    border: 1px solid var(--rule);
    color: var(--ink);
    padding: 0.2rem 0.55rem;
}

.reboot-fab .material-symbols-outlined {
    width: 22px;
    font-size: 22px;
    line-height: 1;
}

.host-ip {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 11px;
    color: var(--ink-muted);
}

/* ---- Wide panels ---------------------------------------------------------- */

@media (min-width: 801px) {
    .container-fluid#page-container {
        max-width: 1280px;
        width: 100%;
        margin: auto;
        padding-top: 1.5rem;
        padding-bottom: 3rem;
    }

    /* Settings has room to breathe: a wider grid means a less cramped custom
       sensor table and send-config panels. */
    .container-fluid#page-container:has(.settings-page) {
        width: 95% !important;
        max-width: 1300px;
    }

    .modal-dialog { max-width: 100%; }

    .modal-content {
        width: 800px;
        margin: auto;
    }
}

/* New 16:9 panel (1280x720 and up). The older 800x480 displays never match this
   query, so their layout is untouched. */
@media (min-width: 1024px) {
    /* Keep content at a compact width; the Restart button stays fixed at the
       left of the bottom bar, outside the capped column. */
    .container-fluid#page-container,
    .container-fluid#page-container:has(.settings-page) { max-width: 960px; }

    /* Dashboard only: centre vertically instead of top-aligning. */
    .container-fluid#page-container:has(#dashboard-container) {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .container-fluid#page-container:has(#dashboard-container) > #dashboard-container {
        flex: 0 0 auto;
    }
}

/* Baku mutu key: keep the three cards on one line whenever Bootstrap's md
   layout applies, and let columns shrink below content width. */
@media (min-width: 768px) {
    #row-reference-values { flex-wrap: nowrap; }
    #row-reference-values > .col-md-4 { min-width: 0; }
    .nbm-col { min-width: 0; }
}

/* Phone widths: stack the logo above the key. */
@media (max-width: 575px) {
    .logo-card,
    .nbm-col { height: auto; }

    .logo-card { width: 100%; height: 72px; }
    #row-reference-values { flex-wrap: wrap; }
    .row-dashboard-3 { flex-wrap: wrap; }
    .row-dashboard-3 > .dashboard-card-col { flex: 1 1 50%; }
}
