/* ==========================================================================
   Machine detail view + clickable machine cards + dial gauge
   ========================================================================== */

/* --- Clickable machine card on the dashboard --- */
a.perf-col { color: inherit; text-decoration: none; }
a.perf-col.clickable { cursor: pointer; position: relative; }
a.perf-col.clickable::after {
    /* "open" hint in the top-right corner on hover */
    content: "↗";
    position: absolute; top: 4px; right: 6px;
    font-size: 11px; font-weight: 700; color: var(--c1);
    opacity: 0; transition: opacity .15s ease;
}
a.perf-col.clickable:hover::after, a.perf-col.clickable:focus-visible::after { opacity: 1; }
a.perf-col.clickable:focus-visible { outline: 3px solid rgba(59,111,224,.45); outline-offset: 2px; }

/* --- Header bits --- */
.page-header .title .crumb { color: var(--muted); text-decoration: none; }
.page-header .title .crumb:hover { color: var(--blue); text-decoration: underline; }
.dept-tab.off { opacity: .35; pointer-events: none; }

/* --- Grid --- */
.md-grid {
    --c1: #94A3B8; --c2: #CBD5E1; --tint: #F3F6FB;
    height: 100%; min-height: 640px;
    display: grid;
    grid-template-columns: 1.35fr 1fr 1fr 1.25fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
}
.md-grid.pf-g { --c1: #1FAE68; --c2: #6EE7B7; --tint: #E8F8F0; }
.md-grid.pf-a { --c1: #D9962A; --c2: #FCD68A; --tint: #FDF3E1; }
.md-grid.pf-r { --c1: #E14D63; --c2: #FF9AA8; --tint: #FDEBEE; }
.md-span2 { grid-column: span 2; }

.md-card {
    min-width: 0; min-height: 0;
    display: flex; flex-direction: column;
    padding: 14px 16px;
    background: rgba(255,255,255,.95);
    border: 1px solid #E3E8F2;
    border-radius: 12px;
    box-shadow: 0 10px 24px -18px rgba(20,30,50,.3), 0 1px 3px rgba(20,30,50,.04);
}
.md-card h3 { font-size: 10.5px; margin: 0 0 8px; color: #8795B2; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.md-card h3 small { text-transform: none; letter-spacing: 0; font-weight: 500; margin-left: 4px; }

/* Hero: status strip + tint like the dashboard card */
.md-hero {
    border: 1.5px solid transparent; border-top: 5px solid transparent;
    background:
        linear-gradient(180deg, var(--tint) 0%, #FFFFFF 55%) padding-box,
        linear-gradient(90deg, var(--c1), var(--c2)) top / 100% 5px no-repeat border-box,
        linear-gradient(#DCE3EF, #DCE3EF) border-box;
}
.md-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.md-head h2 { font-size: 18px; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.md-head .status-pill { font-size: 11px; padding: 3px 9px; }

.md-oee { display: flex; align-items: center; gap: 18px; }
.md-ring { position: relative; width: 112px; height: 112px; flex: none; }
.md-ring svg { width: 100%; height: 100%; display: block; }
.md-ring-copy { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.md-ring-copy b { font-size: 22px; line-height: 1; }
.md-ring-copy span { font-size: 10px; color: var(--muted); letter-spacing: .08em; margin-top: 4px; }

.md-factors { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.md-factors .metric { display: grid; grid-template-columns: 78px 1fr 40px; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
.md-factors .metric b { text-align: right; color: var(--text); font-size: 12px; }
.md-factors .track { height: 7px; border-radius: 5px; background: #EDF1F7; overflow: hidden; }
.md-factors .fill { height: 100%; border-radius: 5px; }
.md-factors .fill.g { background: linear-gradient(90deg, #1FAE68, #5FD99A); }
.md-factors .fill.a { background: linear-gradient(90deg, #C98A1D, #F2B94F); }
.md-factors .fill.r { background: linear-gradient(90deg, #E14D63, #FF8FA0); }
.md-target { font-size: 11px; color: var(--muted); }
.md-target b { color: var(--text); }

.md-units { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.md-unit { font-size: 11.5px; color: var(--muted); padding: 4px 10px; background: #F4F6FB; border: 1px solid #E6EBF4; border-radius: 20px; }
.md-unit .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.md-unit b { color: var(--text); margin-left: 4px; }

/* Meters */
.md-meter { align-items: stretch; }
.md-nometer p { margin: auto; font-size: 13px; color: var(--muted); text-align: center; }

.dial { display: flex; flex-direction: column; align-items: center; flex: 1; justify-content: center; }
.dial svg { width: 100%; max-width: 230px; height: auto; display: block; overflow: visible; }
.dial-track { fill: none; stroke: #EDF1F7; stroke-width: 14; stroke-linecap: round; }
.dial-value { fill: none; stroke-width: 14; stroke-linecap: round; }
.dial-zone { fill: none; stroke-width: 4; }
.dial-zone.zg { stroke: #9FE3C0; }
.dial-zone.za { stroke: #F6CF85; }
.dial-zone.zr { stroke: #F59AA8; }
.dial-tick { stroke: #C3CCDC; stroke-width: 1.2; }
.dial-tick.major { stroke: #8795B2; stroke-width: 1.8; }
.dial-end { font-size: 9px; fill: var(--muted); font-family: "SF Mono", Consolas, monospace; }
.dial-needle path { fill: #1B2433; }
.dial-hub { fill: #1B2433; }
.dial-hub-dot { fill: #FFFFFF; }
.dial-needle { transition: transform .6s cubic-bezier(.2,.8,.2,1); }
.dial-read { display: flex; align-items: baseline; gap: 5px; margin-top: 2px; }
.dial-read b { font-size: 24px; line-height: 1; }
.dial-read span { font-size: 12px; color: var(--muted); font-weight: 600; }
.dial-g .dial-read b { color: #1B2433; }
.dial-a .dial-read b { color: var(--amber); }
.dial-r .dial-read b { color: var(--red); }
.dial-sub { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

/* Info */
.md-job { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.md-job b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.md-job span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.md-job small { font-size: 11px; }
.md-info .qbar { height: 6px; margin: 6px 0 8px; }
.md-jobtime { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; padding: 7px 9px; background: #F6F8FC; border: 1px solid #E9EDF5; border-radius: 8px; }
.md-jobtime div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.md-jobtime span { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.md-jobtime b { font-size: 13px; white-space: nowrap; }
.md-jobtime b.bad { color: var(--red); }
.md-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 10px; margin-top: auto; border-top: 1px dashed #E3E8F2; }
.md-stats + .md-stats { margin-top: 10px; }
.md-stats div { display: flex; flex-direction: column; gap: 2px; }
.md-stats span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.md-stats b { font-size: 14px; }
.md-stats b.bad { color: var(--red); }

/* Charts: Grafana-style panels */
.md-chart, .md-split { padding: 10px 12px 8px; border-radius: 8px; box-shadow: 0 1px 2px rgba(20,30,50,.05); }
.md-chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.md-chart-head h3 { font-size: 13px; font-weight: 600; color: var(--text); text-transform: none; letter-spacing: 0; margin: 0; }
.md-chart-meta { font-size: 11px; color: var(--muted); }

.ts { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ts-plot { flex: 1; min-height: 90px; position: relative; }
.ts-plot .uplot, .ts-plot .u-wrap { position: absolute; inset: 0; }
.ts-plot .u-over { cursor: crosshair; }
.ts-plot .u-cursor-x, .ts-plot .u-cursor-y { border-color: rgba(30, 40, 60, .35) !important; }
.ts-plot .u-cursor-y { display: none; }

.ts-tip {
    position: fixed; top: 0; left: 0; z-index: 1000; pointer-events: none;
    min-width: 140px;
    padding: 7px 9px;
    background: rgba(24, 27, 31, .94);
    color: #D8D9DA;
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0,0,0,.25);
    font-size: 11px; line-height: 1.5;
}
.ts-tip-time { color: #9FA7B3; margin-bottom: 3px; font-family: "SF Mono", Consolas, monospace; }
.ts-tip-row { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 7px; }
.ts-tip-row i { width: 10px; height: 3px; border-radius: 1px; }
.ts-tip-row b { color: #FFFFFF; font-weight: 600; font-family: "SF Mono", Consolas, monospace; }

.ts-legend { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 4px; }
.ts-legend th { font-weight: 500; color: var(--muted); text-align: right; padding: 2px 8px; border-bottom: 1px solid #EEF1F7; }
.ts-legend td { text-align: right; padding: 2px 8px; color: #464C54; }
.ts-legend td:first-child { text-align: left; color: var(--text); white-space: nowrap; }
.ts-legend th:first-child, .ts-legend td:first-child { width: 100%; } /* keep stats compact on the right */
.ts-legend th:not(:first-child), .ts-legend td:not(:first-child) { min-width: 64px; white-space: nowrap; }
.ts-legend td:first-child i { display: inline-block; width: 12px; height: 3px; border-radius: 1px; margin-right: 7px; vertical-align: 3px; }
.ts-legend td.last { color: var(--text); font-weight: 600; }

/* Time split: Grafana bar gauge (gradient mode) */
.bar-gauges { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 4px 4px 6px; }
.bg-row { display: grid; grid-template-columns: 120px 1fr 52px; align-items: center; gap: 12px; }
.bg-label { display: flex; flex-direction: column; }
.bg-label span { font-size: 12.5px; color: var(--text); }
.bg-label small { font-size: 11px; color: var(--muted); }
.bg-track { height: 22px; background: #F1F3F8; border-radius: 3px; overflow: hidden; }
.bg-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 35%, transparent), var(--c)); }
.bg-value { font-size: 18px; text-align: right; color: var(--c); }
/* --- Responsive --- */
@media (max-height: 760px) and (min-width: 1101px) {
    .md-grid { gap: 9px; min-height: 0; }
    .md-card { padding: 10px 12px; }
    .md-ring { width: 92px; height: 92px; }
    .dial svg { max-width: 190px; }
}
@media (max-width: 1280px) and (min-width: 1101px) {
    .md-grid { grid-template-columns: 1.2fr 1fr 1fr 1.2fr; }
    .md-oee { gap: 12px; }
}
@media (max-width: 1100px) {
    .md-grid { height: auto; min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; }
    .md-chart, .md-split { min-height: 260px; }
}
@media (max-width: 700px) {
    .md-grid { grid-template-columns: 1fr; }
    .md-span2 { grid-column: auto; }
    .bg-row { grid-template-columns: 96px 1fr 46px; }
}
@media (prefers-reduced-motion: reduce) {
    .dial-needle { transition: none; }
}
