/* ============================================================
 * FILE:    monitor.css
 * PATH:    assets/monitor.css
 * ============================================================
 * PURPOSE: Bedside / operator-console styling for Feature MON.
 *          Loaded by monitor/bedside.php and the operator-console view in index.php.
 * PROGRESS REPORT:
 *   [2026-05-04] Feature MON Phase 3 — initial dark bedside theme + tile + alarm styles.
 * ============================================================ */

html, body { margin: 0; padding: 0; height: 100%; }
.mon-body {
    /* Use viewport-units directly so the grid below has a known height even
       when the html/body height-100% chain breaks (e.g. inside an iframe with
       no explicit height parent). */
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #000;
    color: #e5e7eb;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    user-select: none;
}

.mon-header {
    display: flex; align-items: center;
    flex-wrap: nowrap;          /* keep on one line */
    gap: 12px;
    padding: 4px 8px;
    background: #0a0a0a;
    border-bottom: 1px solid #1f2937;
    font-size: 13px;
    min-height: 32px;           /* not fixed, so a sweep dropdown can grow if needed */
    box-sizing: border-box;
    white-space: nowrap;
    overflow-x: auto;           /* horizontal scroll instead of clipping */
}
.mon-header-left, .mon-header-center { flex: 0 0 auto; }
.mon-header-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; margin-left: auto; }
.mon-header-center { font-weight: 600; color: #93c5fd; }
.mon-dim   { color: #94a3b8; font-weight: normal; }
.mon-sep   { color: #475569; margin: 0 8px; }
.mon-clock { font-family: ui-monospace, "SF Mono", monospace; font-size: 16px; color: #fbbf24; }
.mon-conn  { font-size: 18px; line-height: 1; }
.mon-conn.ok   { color: #22c55e; }
.mon-conn.bad  { color: #ef4444; }

.mon-grid {
    display: grid;
    grid-template-columns: 1fr 240px;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}
.mon-traces {
    /* Each row is a fixed 130 px. Container scrolls if many channels are
       enabled. This is the only configuration that has rendered reliably
       across every browser/iframe combination we've tested — flex-share
       chains keep collapsing rows to 0 in some path. */
    display: block;
    background: #000;
    overflow-y: auto;
    overflow-x: hidden;
}
.mon-row {
    display: grid;
    grid-template-columns: 50px 1fr;
    grid-template-rows: 130px;   /* explicit row height so canvas height:100% resolves to 130px
                                    instead of entering a circular dependency and computing to
                                    the canvas buffer height (260px on 2× Retina). */
    height: 130px;
    border-bottom: 1px solid #0f172a;
}
.mon-row-label {
    display: flex; align-items: flex-start; justify-content: flex-start;
    padding: 4px 6px;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.04em;
    background: #050505;
    border-right: 1px solid #0f172a;
}
.mon-canvas { width: 100%; height: 100%; display: block; background: #000; }

.mon-numerics {
    background: #050505;
    border-left: 1px solid #1f2937;
    padding: 4px;
    display: flex; flex-direction: column; gap: 4px;
    overflow-y: auto;
    /* Without an explicit height the column defaults to its content height,
       which can spill below the visible area and look like a "white block"
       hiding tiles below it. Sticking it to the viewport height + scrolling
       internally keeps every tile reachable. */
    height: 100%;
    min-height: 0;
}
.mon-tile {
    background: #0a0a0a;
    border: 1px solid #1f2937;
    border-radius: 4px;
    padding: 4px 8px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "label unit"
      "value sub";
    column-gap: 6px;
    color: var(--c, #e5e7eb);
}
.mon-tile-label { grid-area: label; font-size: 12px; font-weight: 600; opacity: .85; }
.mon-tile-value { grid-area: value; font-size: 28px; font-weight: 800; line-height: 1.05;
                  font-family: ui-monospace, "SF Mono", monospace; }
.mon-tile-sub   { grid-area: sub;   font-size: 11px; opacity: .7; }
.mon-tile-unit  { grid-area: unit;  font-size: 11px; opacity: .55; align-self: start; }

@keyframes monAlarmHi {
    0%, 100% { background: #0a0a0a; }
    50%      { background: #7f1d1d; }
}
@keyframes monAlarmMd {
    0%, 100% { background: #0a0a0a; }
    50%      { background: #78350f; }
}
.mon-tile.alarm-hi { animation: monAlarmHi 1.2s ease-in-out infinite;
                     border-color: #ef4444; }
.mon-tile.alarm-md { animation: monAlarmMd 1.6s ease-in-out infinite;
                     border-color: #f59e0b; }

/* Operator console */
.mon-console { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.mon-console fieldset {
    /* Native <fieldset> renders the <legend> floating over the top border, which
       leaves a visual notch and makes the heading look "too high" relative to
       the body content. Switch to a regular block with a styled top header so
       everything aligns to the same baseline. */
    border: 1px solid #1f2937; border-radius: 6px;
    padding: 30px 12px 12px 12px;        /* extra top padding for the header strip */
    background: #0b1220; color: #e5e7eb;
    position: relative;
    margin: 0;
    min-width: 0;
}
.mon-console legend {
    /* Position absolutely along the top edge so it never floats outside or pushes
       content down inconsistently across browsers. */
    position: absolute;
    top: 0; left: 0; right: 0;
    margin: 0; padding: 6px 12px;
    color: #93c5fd; font-weight: 600; font-size: 12px;
    background: #0f172a; border-bottom: 1px solid #1f2937;
    border-radius: 6px 6px 0 0;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.2;
}
.mon-console label  { display: flex; flex-direction: column; gap: 2px;
                      font-size: 12px; color: #cbd5e1; }
.mon-console input[type=number],
.mon-console input[type=text],
.mon-console select {
    background: #0a0a0a; color: #e5e7eb; border: 1px solid #334155;
    border-radius: 3px; padding: 4px 6px; font-size: 14px;
}
.mon-console input[type=range] { width: 100%; }
.mon-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.mon-row-flex { display: flex; flex-wrap: wrap; gap: 6px; }
.mon-btn {
    background: #1e293b; color: #e5e7eb; border: 1px solid #334155;
    border-radius: 4px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.mon-btn:hover { background: #334155; }
.mon-btn.danger  { background: #7f1d1d; border-color: #b91c1c; }
.mon-btn.warn    { background: #78350f; border-color: #b45309; }
.mon-btn.primary { background: #1d4ed8; border-color: #2563eb; }

/* In-console live preview (native canvases — replaces the iframe approach,
   so the engine doesn't get destroyed every poll) */
.mc-preview-bar  { color: #93c5fd; font-size: 11px; padding: 6px 10px;
                   background: #0b1220; border-bottom: 1px solid #1f2937;
                   text-transform: uppercase; letter-spacing: 0.05em;
                   display: flex; align-items: center; gap: 8px; }
.mc-preview-body { display: grid; grid-template-columns: 1fr 180px;
                   /* No fixed height — let rows define their own 90px and the
                      body expands. Numerics column aligns to the grid height. */
                   align-items: start; }
.mc-preview-grid { background: #000; padding: 2px 4px; display: flex;
                   flex-direction: column; gap: 1px; }
.mc-preview-row  { display: grid; grid-template-columns: 36px 1fr;
                   grid-template-rows: 90px; /* explicit px — canvas height:100%
                                                resolves to 90px, no circular dep. */
                   height: 90px;
                   flex-shrink: 0;           /* rows never squash below 90px */
                   align-items: stretch;
                   background: #050505; border: 1px solid #0f172a;
                   border-radius: 3px; cursor: default; }
.mc-preview-label { display: flex; align-items: flex-start; padding: 2px 4px;
                    font-weight: 700; font-size: 10px; letter-spacing: 0.04em; }
.mc-preview-canvas { width: 100%; height: 100%; display: block; background: #000; }
.mc-preview-numerics {
    background: #050505; border-left: 1px solid #1f2937;
    padding: 4px; display: flex; flex-direction: column; gap: 3px;
    overflow-y: auto;
    max-height: 630px; /* ~7 rows; scrolls if numerics exceed grid height */
    align-self: stretch;
}
.mc-preview-numerics .mon-tile {
    padding: 2px 6px;
}
.mc-preview-numerics .mon-tile-value { font-size: 20px; }
.mc-preview-numerics .mon-tile-label { font-size: 10px; }
.mc-preview-numerics .mon-tile-sub   { font-size: 10px; }
.mc-preview-numerics .mon-tile-unit  { font-size: 9px; }

/* Scenarios tab cards */
.mc-scenario {
    border: 1px solid #1f2937; border-radius: 6px; padding: 8px 10px;
    background: #050d1f; margin-bottom: 8px;
}
.mc-scenario-label { color: #e5e7eb; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.mc-scenario-desc  { color: #94a3b8; font-size: 12px; line-height: 1.45; }

/* Bedside click affordances + inline editor overlay */
.mon-row { cursor: pointer; transition: background-color 0.15s ease; }
.mon-row:hover { background: rgba(255,255,255,0.03); }
.mon-tile:hover { outline: 1px solid var(--c, #60a5fa); }

.mon-editor {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.65);
    display: flex; align-items: center; justify-content: center;
}
.mon-editor[hidden] { display: none; }
.mon-editor-card {
    background: #0b1220; color: #e5e7eb;
    border: 1px solid #334155; border-radius: 8px;
    padding: 16px 18px; min-width: 280px; max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.mon-editor-title {
    color: #93c5fd; font-weight: 600; font-size: 14px;
    margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.05em;
    border-bottom: 1px solid #1f2937; padding-bottom: 8px;
}
.mon-editor .mon-edit-row {
    display: grid; grid-template-columns: 130px 1fr;
    align-items: center; gap: 8px; padding: 4px 0;
    font-size: 13px;
}
.mon-editor .mon-edit-row span { color: #94a3b8; }
.mon-editor input, .mon-editor select {
    background: #0a0a0a; color: #e5e7eb;
    border: 1px solid #334155; border-radius: 3px;
    padding: 4px 6px; font-size: 14px; width: 100%;
    box-sizing: border-box;
}
.mon-editor input[type=checkbox] { width: auto; }
.mon-editor-actions {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 14px; padding-top: 10px; border-top: 1px solid #1f2937;
}
