/* Storage Graph — interactive storage overview for Sample Management (lab) */

.sg-root {
    background: #ffffff;
    border: 1px solid #dee2e6;
    /* Right margin clears the fixed 160px action bar (#persistent-action-panel) */
    margin: 0 160px 15px 0;
    padding: 14px 16px 16px 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    color: #2a3b4d;
}

/* Toolbar -------------------------------------------------------------- */
.sg-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-bottom: 12px;
}

.sg-title-wrap {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.sg-title {
    font-size: 18px;
    font-weight: 700;
    color: #2a3b4d;
}

.sg-summary {
    font-size: 12px;
    color: #6c757d;
}

.sg-summary-overdue {
    color: #e03131;
    font-weight: 700;
}

.sg-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.sg-filter {
    display: flex;
    flex-direction: column;
    font-size: 11px;
    color: #6c757d;
    gap: 2px;
}

.sg-filter-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sg-select {
    min-width: 150px;
    max-width: 220px;
    padding: 4px 6px;
    font-size: 13px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #fff;
    color: #2a3b4d;
}

.sg-checkbox {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #495057;
    align-self: flex-end;
    cursor: pointer;
}

.sg-reset-btn {
    align-self: flex-end;
    padding: 5px 12px;
    font-size: 13px;
    border: 1px solid #007bff;
    background: #fff;
    color: #007bff;
    border-radius: 4px;
    cursor: pointer;
}

.sg-reset-btn:hover {
    background: #007bff;
    color: #fff;
}

/* Canvas: wrapping grid of location tiles ------------------------------ */
.sg-canvas {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
}

/* ---------------------------------------------------------------------- */
/* Generic accordion node (location / temperature group / unit)           */
/* ---------------------------------------------------------------------- */
.sg-node {
    border-radius: 6px;
    background: #fff;
}

.sg-node-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    min-height: 20px;
    line-height: 1.3;
    position: relative;
    cursor: pointer;
    user-select: none;
}

.sg-caret {
    font-size: 10px;
    color: #6c757d;
    flex-shrink: 0;
    transform: rotate(-90deg);
    transition: transform 0.12s ease;
}

.sg-node.sg-open > .sg-node-header > .sg-caret {
    transform: rotate(0deg);
}

.sg-node-name {
    font-size: 12px;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sg-node-meta {
    font-size: 10px;
    color: #6c757d;
    white-space: nowrap;
    margin-left: auto;
}

/* Body height animates open/closed via the grid-template-rows 0fr↔1fr trick;
   the inner wrapper clips overflow so children collapse to zero height. */
.sg-node-body {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.22s ease;
}

.sg-node.sg-open > .sg-node-body {
    grid-template-rows: 1fr;
}

.sg-node-body-inner {
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px 8px 8px 8px;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.sg-node.sg-open > .sg-node-body > .sg-node-body-inner {
    opacity: 1;
}

.sg-dimmed-node {
    opacity: 0.5;
}

/* Shared square-tile faces (collapsed) for Location, Temp group & Unit --- */
.sg-location > .sg-node-header,
.sg-tempgroup > .sg-node-header,
.sg-unit > .sg-node-header {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 4px;
    min-height: 78px;
    padding: 12px 14px;
}

/* Keep the label from stretching so name + meta sit tight together */
.sg-location > .sg-node-header .sg-node-name,
.sg-tempgroup > .sg-node-header .sg-node-name,
.sg-unit > .sg-node-header .sg-node-name {
    flex: 0 0 auto;
}

/* Clickable affordance: lift collapsed tiles on hover */
.sg-location,
.sg-tempgroup,
.sg-unit {
    transition: box-shadow 0.15s ease;
}

.sg-location:not(.sg-open):hover,
.sg-tempgroup:not(.sg-open):hover,
.sg-unit:not(.sg-open):hover {
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.sg-location > .sg-node-header .sg-caret,
.sg-tempgroup > .sg-node-header .sg-caret,
.sg-unit > .sg-node-header .sg-caret {
    position: absolute;
    top: 10px;
    right: 10px;
}

.sg-location > .sg-node-header .sg-node-meta,
.sg-tempgroup > .sg-node-header .sg-node-meta,
.sg-unit > .sg-node-header .sg-node-meta {
    margin-left: 0;
}

.sg-location > .sg-node-header .sg-badge-overdue,
.sg-tempgroup > .sg-node-header .sg-badge-overdue,
.sg-unit > .sg-node-header .sg-badge-overdue {
    position: absolute;
    top: 9px;
    right: 30px;
    margin: 0;
}

/* When opened, all collapse to a compact single-line header bar */
.sg-location.sg-open > .sg-node-header,
.sg-tempgroup.sg-open > .sg-node-header,
.sg-unit.sg-open > .sg-node-header {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    min-height: 0;
    gap: 8px;
    padding: 8px 12px;
}

.sg-location.sg-open > .sg-node-header .sg-caret,
.sg-tempgroup.sg-open > .sg-node-header .sg-caret,
.sg-unit.sg-open > .sg-node-header .sg-caret {
    position: static;
}

.sg-location.sg-open > .sg-node-header .sg-node-meta,
.sg-tempgroup.sg-open > .sg-node-header .sg-node-meta,
.sg-unit.sg-open > .sg-node-header .sg-node-meta {
    margin-left: auto;
}

.sg-location.sg-open > .sg-node-header .sg-badge-overdue,
.sg-tempgroup.sg-open > .sg-node-header .sg-badge-overdue,
.sg-unit.sg-open > .sg-node-header .sg-badge-overdue {
    position: static;
    margin-left: 6px;
}

/* Level 1: Location tile */
.sg-location {
    flex: 0 0 176px;
    border: 1px solid #dee2e6;
    overflow: hidden;
    align-self: flex-start;
}

.sg-location.sg-open {
    flex: 1 1 100%;
}

.sg-location > .sg-node-header {
    background: #2a3b4d;
    color: #fff;
}

.sg-location > .sg-node-header .sg-caret {
    color: #cbd5e1;
}

.sg-location > .sg-node-header .sg-node-name {
    font-size: 14px;
    font-weight: 700;
    white-space: normal;
    padding-right: 18px;
}

.sg-location > .sg-node-header .sg-node-meta {
    font-size: 11px;
    color: #cbd5e1;
}

/* Temperature tiles arranged as a wrapping grid inside the location */
.sg-location > .sg-node-body > .sg-node-body-inner {
    flex-flow: row wrap;
    gap: 10px;
    align-items: flex-start;
}

/* Level 2: Temperature group tile */
.sg-tempgroup {
    flex: 0 0 150px;
    border: 1px solid #e3e5e8;
    border-left: 4px solid #adb5bd;
    overflow: hidden;
    align-self: flex-start;
    background: #fff;
}

.sg-tempgroup.sg-open {
    /* Wrap around the unit/container content instead of taking a full row.
       max-width caps it so many units still wrap rather than overflow. */
    flex: 0 0 auto;
    max-width: 100%;
}

.sg-tempgroup > .sg-node-header {
    background: #f7f9fb;
    font-weight: 600;
}

.sg-tempgroup > .sg-node-header .sg-node-name,
.sg-tempgroup > .sg-node-header .sg-node-meta {
    font-size: 11px;
}

.sg-tempgroup-orphan {
    border-left-style: dashed;
    border-left-color: #ced4da;
}

/* Unit tiles arranged as a wrapping grid inside the temperature group */
.sg-tempgroup > .sg-node-body > .sg-node-body-inner {
    flex-flow: row wrap;
    gap: 10px;
    align-items: flex-start;
}

/* Level 3: Unit tile — a box in the grid; opens to fit its container grid */
.sg-unit {
    flex: 0 0 150px;
    border: 1px solid #e3e5e8;
    border-left: 4px solid #adb5bd;
    overflow: hidden;
    align-self: flex-start;
    background: #fff;
}

.sg-unit.sg-open {
    /* Size to the container grid rather than stretching to full width */
    flex: 0 0 auto;
}

.sg-unit > .sg-node-header .sg-node-name {
    font-size: 12px;
    white-space: normal;
    padding-right: 18px;
}

.sg-unit > .sg-node-header:hover,
.sg-tempgroup > .sg-node-header:hover,
.sg-location > .sg-node-header:hover {
    filter: brightness(0.97);
}

/* Temperature colour coding (left border + badge) */
.sg-node.temp-ambient { border-left-color: #adb5bd; }
.sg-node.temp-cold { border-left-color: #4dabf7; }
.sg-node.temp-frozen { border-left-color: #4263eb; }
.sg-node.temp-ultracold { border-left-color: #7048e8; }
.sg-node.temp-ln { border-left-color: #12b886; }

.sg-temp-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 3px;
    background: #e9ecef;
    color: #495057;
    white-space: nowrap;
    flex-shrink: 0;
}

.sg-node.temp-cold .sg-temp-badge { background: #e7f5ff; color: #1971c2; }
.sg-node.temp-frozen .sg-temp-badge { background: #edf2ff; color: #364fc7; }
.sg-node.temp-ultracold .sg-temp-badge { background: #f3f0ff; color: #5f3dc4; }
.sg-node.temp-ln .sg-temp-badge { background: #e6fcf5; color: #087f5b; }

/* Overdue notification bubble ----------------------------------------- */
.sg-badge-overdue {
    background: #e03131;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 4px;
    box-sizing: border-box;
    margin-left: 6px;
    flex-shrink: 0;
}

.sg-badge-corner {
    position: absolute;
    top: 2px;
    right: 2px;
    margin: 0;
    box-shadow: 0 0 0 2px #fff;
    z-index: 3;
}

/* Level 4: Container grid --------------------------------------------- */
.sg-container-grid {
    display: grid;
    /* Fixed-width columns so an opened unit shrink-wraps to a box (max 5 wide) */
    grid-template-columns: repeat(5, 58px);
    gap: 5px;
    justify-content: start;
}

.sg-container {
    position: relative;
    min-height: 42px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 4px 4px 3px 4px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    /* fill shading: background intensity scales with --sg-fill (0..1) */
    background:
        linear-gradient(
            to top,
            rgba(0, 123, 255, calc(0.10 + 0.55 * var(--sg-fill, 0))) 0%,
            rgba(0, 123, 255, calc(0.10 + 0.55 * var(--sg-fill, 0))) calc(var(--sg-fill, 0) * 100%),
            #ffffff calc(var(--sg-fill, 0) * 100%),
            #ffffff 100%
        );
    transition: box-shadow 0.1s ease, transform 0.1s ease;
}

.sg-container:hover {
    box-shadow: 0 0 0 2px #007bff;
    transform: translateY(-1px);
    z-index: 2;
}

.sg-container.sg-container-active {
    box-shadow: 0 0 0 2px #1971c2, 0 2px 8px rgba(25, 113, 194, 0.35);
    z-index: 2;
}

.sg-container-name {
    font-size: 10px;
    font-weight: 600;
    line-height: 1.15;
    color: #2a3b4d;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    padding-right: 14px;
}

.sg-container-count {
    align-self: flex-end;
    font-size: 11px;
    font-weight: 700;
    color: #1971c2;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 3px;
    padding: 0 3px;
    min-width: 16px;
    text-align: center;
}

.sg-container.sg-dimmed {
    opacity: 0.28;
    filter: grayscale(0.6);
}

.sg-container.sg-dimmed:hover {
    opacity: 0.85;
}

.sg-empty-note {
    font-size: 12px;
    color: #adb5bd;
    padding: 8px 4px;
    font-style: italic;
}
