/* ==========================================================================
   Dashboard: department tabs, performance grid, machine + production info cards
   ========================================================================== */

/* --- Department tabs (rendered into the header toolbar section) --- */
.dept-tabs { display: flex; gap: 3px; padding: 3px; background: #E8EDF7; border: 1px solid #DAE1EF; border-radius: 10px; }
.dept-tab {
    display: flex; align-items: center; gap: 8px;
    border: 0; background: transparent; color: var(--muted);
    font: inherit; font-size: 13px; text-decoration: none;
    padding: 7px 14px; border-radius: 7px;
    cursor: pointer; white-space: nowrap;
}
.dept-tab:hover { color: var(--text); }
.dept-tab.active { background: linear-gradient(135deg, #3B6FE0, #5B8CFF); color: #FFFFFF; font-weight: 600; box-shadow: 0 6px 14px -4px rgba(59,111,224,.55); }
.dept-tab:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.dept-tab .score { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 20px; }
.dept-tab .score.g { background: var(--green-bg); color: var(--green); }
.dept-tab .score.a { background: var(--amber-bg); color: var(--amber); }
.dept-tab .score.r { background: var(--red-bg); color: var(--red); }
.dept-tab .score.n { background: #E3E8F2; color: var(--muted); }
.dept-tab.active .score { background: rgba(255,255,255,.22); color: #FFFFFF; }

/* --- Grid: 3 x 2 cards fill one desktop viewport --- */
.perf-grid {
    height: 100%; min-height: 560px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

/* --- Card frame (machine + production info) --- */
.perf-col {
    --c1: #94A3B8; --c2: #CBD5E1; --tint: #F3F6FB; --glow: rgba(20,30,50,.10);
    min-width: 0; min-height: 0; overflow: hidden;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: .82fr 1fr 1fr;
    grid-template-areas: "oee stats" "trend output" "downtime split";
    gap: 8px; padding: 9px;
    border: 1.5px solid transparent; border-top: 5px solid transparent; border-radius: 12px;
    /* layered: status-tinted body, gradient top strip, hairline outline */
    background:
        linear-gradient(180deg, var(--tint) 0%, #FFFFFF 46%) padding-box,
        linear-gradient(90deg, var(--c1), var(--c2)) top / 100% 5px no-repeat border-box,
        linear-gradient(#DCE3EF, #DCE3EF) border-box;
    box-shadow: 0 12px 28px -14px var(--glow), 0 2px 6px rgba(20,30,50,.05);
    transition: transform .18s ease, box-shadow .18s ease;
}
.perf-col:hover { transform: translateY(-2px); box-shadow: 0 18px 36px -14px var(--glow), 0 3px 8px rgba(20,30,50,.06); }
.perf-col.pf-g { --c1: #1FAE68; --c2: #6EE7B7; --tint: #E8F8F0; --glow: rgba(31,174,104,.40); }
.perf-col.pf-a { --c1: #D9962A; --c2: #FCD68A; --tint: #FDF3E1; --glow: rgba(201,138,29,.40); }
.perf-col.pf-r { --c1: #E14D63; --c2: #FF9AA8; --tint: #FDEBEE; --glow: rgba(225,77,99,.45); }

.perf-col .card {
    min-width: 0; min-height: 0; overflow: hidden;
    padding: 9px 11px; border-radius: 8px;
    display: flex; flex-direction: column; justify-content: center;
    background: rgba(255,255,255,.94);
    border: 1px solid #E6EBF4;
    box-shadow: 0 1px 2px rgba(20,30,50,.04);
}
.perf-col .card h3 { font-size: 9.5px; margin: 0 0 4px; color: #8795B2; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.card.c-oee { grid-area: oee; }
.card.c-trend { grid-area: trend; }
.card.c-output { grid-area: output; }
.card.c-stats { grid-area: stats; }
.card.c-down { grid-area: downtime; }
.card.c-split { grid-area: split; }

.perf-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.perf-head h2 { font-size: 13px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Machine card: OEE --- */
.oee-row { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.oee-row .lbl { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.oee-row .val { font-size: 20px; font-weight: 700; margin-top: 2px; }
.oee-row svg { width: 44px; height: 44px; margin-left: auto; flex: none; }
.c-oee.grouped .oee-row { margin-top: 2px; }
.unit-row { display: flex; gap: 12px; margin-top: 2px; line-height: 1.2; font-size: 9.5px; color: var(--muted); white-space: nowrap; }
.unit-row b { color: var(--text); }
.unit-row .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }

/* --- Machine card: charts, stats, current job --- */
.mini-line-row { display: flex; gap: 10px; font-size: 9px; color: var(--muted); margin-top: 3px; }
.mini-line-row span::before { content: "●"; margin-right: 5px; font-size: 9px; }

.stats3 { display: flex; justify-content: space-between; align-items: center; gap: 3px; text-align: center; }
.stats3 .lbl { font-size: 8.5px; color: var(--muted); }
.stats3 .val { font-size: 11px; font-weight: 700; margin-top: 3px; white-space: nowrap; }

.cur .lbl { font-size: 8.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cur-line { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-top: 2px; }
.cur-line b { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cur-line .num { font-size: 9.5px; color: var(--muted); white-space: nowrap; }
.cur .qbar { margin-top: 3px; }
.cur-time { display: flex; justify-content: space-between; gap: 6px; margin-top: 2px; line-height: 1.2; font-size: 8.5px; color: var(--muted); white-space: nowrap; }
.cur-time .stop { color: var(--red); }
.perf-col .card.c-stats { padding-top: 6px; padding-bottom: 6px; } /* job + start/stop + hours share one cell */
.cur + .stats3 { margin-top: 3px; padding-top: 3px; border-top: 1px dashed #E3E8F2; }



/* --- Production Info card (grid cell 0,0): dark navy so it reads apart from machines --- */
.perf-col.pf-info {
    --muted: #8EA0C6;
    --glow: rgba(11,21,48,.55);
    grid-template-areas: "po po" "po po" "sched out";
    color: #E6ECFA;
    background:
        radial-gradient(420px 220px at 100% 0%, rgba(91,140,255,.28), transparent 60%) padding-box,
        linear-gradient(180deg, #132449 0%, #0B1530 100%) padding-box,
        linear-gradient(90deg, #5B8CFF, #A78BFA) top / 100% 5px no-repeat border-box,
        linear-gradient(#1E3160, #1E3160) border-box;
    box-shadow: 0 14px 30px -14px rgba(11,21,48,.55), 0 2px 6px rgba(20,30,50,.08);
}
.pf-info .card { background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.08); box-shadow: none; }
.pf-info .card h3 { color: #8EA0C6; }
.pf-info .perf-head h2 { color: #FFFFFF; }

.card.c-po { grid-area: po; justify-content: flex-start; }
.card.c-sched { grid-area: sched; }
.card.c-out { grid-area: out; }

.card-sub { display: flex; justify-content: space-between; align-items: baseline; margin-top: 5px; }
.card-sub h3 { margin: 0 !important; }
.card-sub span { font-size: 9px; color: var(--muted); }

.po-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 10px; line-height: 1.15; margin-top: 3px; }
.po-table th { font-size: 8.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: left; padding: 0 4px 3px; }
.po-table td { padding: 3px 4px; border-top: 1px solid rgba(255,255,255,.07); color: #E6ECFA; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.po-table td b { color: #FFFFFF; }
.po-table .qty { font-size: 9.5px; }
.po-table .time { font-size: 9.5px; color: #C9D3E8; }
.po-table .status-pill { font-size: 8.5px; padding: 1px 6px; }
.po-table td.empty { text-align: center; color: var(--muted); padding: 18px 4px; font-style: italic; }

.pf-info .qbar, .pf-info .out-bar, .pf-info .timeline { background: rgba(255,255,255,.10); }
.pf-info .status-pill.g { background: rgba(31,174,104,.18); color: #5FD99A; }
.pf-info .status-pill.b { background: rgba(91,140,255,.20); color: #A9C2FF; }
.pf-info .status-pill.n { background: rgba(255,255,255,.10); color: #B6C3DE; }
.pf-info .status-pill.r { background: rgba(225,77,99,.20); color: #FF9AA8; }

/* Schedule timeline */
.tl-wrap { position: relative; margin-top: 4px; }
.timeline { position: relative; height: 16px; border-radius: 5px; overflow: hidden; }
.timeline .seg { position: absolute; top: 0; bottom: 0; border-right: 2px solid var(--navy); }
.seg.done { background: #56668A; }
.seg.run { background: linear-gradient(90deg, #3B6FE0, #6C9BFF); }
.seg.plan { background: #3A5596; }
.seg.maint { background: repeating-linear-gradient(135deg, #8A6A2E 0 4px, #6B5226 4px 8px); }
.tl-now { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--red); border-radius: 2px; }
.tl-now::before { content: ""; position: absolute; top: -3px; left: -2px; width: 6px; height: 6px; border-radius: 50%; background: var(--red); }
.tl-ticks { display: flex; justify-content: space-between; font-size: 8px; color: var(--muted); margin-top: 3px; }
.tl-next { font-size: 9.5px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-next b { color: #FFFFFF; }

/* Output */
.out-big { font-size: 18px; font-weight: 700; line-height: 1.1; color: #FFFFFF; }
.out-big small { font-size: 9.5px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.out-plan { font-size: 9px; color: var(--muted); margin-top: 2px; }
.out-bar { height: 6px; border-radius: 4px; margin: 5px 0; overflow: hidden; }
.out-bar i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, #1FAE68, #5FD99A); }
.out-stats { display: flex; justify-content: space-between; font-size: 8.5px; color: var(--muted); }
.out-stats b { display: block; font-size: 10.5px; color: #FFFFFF; }
.out-stats b.reject { color: #FF9AA8; }

/* --- Card sparklines (uPlot, TimeSeriesChart Compact) --- */
.perf-col .card h3 small { text-transform: none; letter-spacing: 0; font-weight: 500; margin-left: 3px; }
.perf-col .ts.compact { flex: none; }
.perf-col .ts.compact .ts-plot { flex: none; min-height: 0; height: 38px; }

/* --- Card time split: compact Grafana bar gauges --- */
.mini-gauges { display: flex; flex-direction: column; gap: 5px; }
.mg-row { display: grid; grid-template-columns: 58px 1fr 30px; align-items: center; gap: 6px; }
.mg-label { font-size: 9px; color: var(--muted); white-space: nowrap; }
.mg-track { height: 7px; background: #F1F3F8; border-radius: 2px; overflow: hidden; }
.mg-fill { height: 100%; border-radius: 2px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 35%, transparent), var(--c)); }
.mg-value { font-size: 10px; text-align: right; color: var(--c); }
/* --- Responsive --- */
@media (prefers-reduced-motion: reduce) {
    .perf-col:hover { transform: none; }
}
@media (max-height: 760px) and (min-width: 1101px) {
    .perf-grid { gap: 9px; min-height: 0; }
    .perf-col { gap: 6px; padding: 7px; }
    .perf-col .card { padding: 7px 9px; }
    .perf-col .ts.compact .ts-plot { height: 31px; }
    .mini-gauges { gap: 3px; }
    .oee-row svg { width: 38px; height: 38px; }
    .oee-row .val { font-size: 18px; }
    .po-table td { padding: 2px 4px; }
    .c-oee.grouped .oee-row { margin-top: 0; }
    .unit-row { margin-top: 0; }
    .cur + .stats3 { margin-top: 2px; padding-top: 2px; }
    .cur-line { margin-top: 1px; }
    .cur-time { margin-top: 1px; }
    .stats3 .lbl { line-height: 1.1; }
    .perf-col .card.c-stats { padding-top: 4px; padding-bottom: 4px; }
    .cur .qbar { margin-top: 2px; }
    .stats3 .val { margin-top: 1px; }
}
@media (max-width: 1100px) {
    .perf-grid { height: auto; min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; }
    .perf-col { min-height: 330px; }
}
@media (max-width: 700px) {
    .dept-tabs { order: 3; width: 100%; }
    .dept-tab { flex: 1; justify-content: center; padding: 8px 10px; }
    .perf-grid { grid-template-columns: 1fr; }
    .perf-col { min-height: 350px; }
}
