/* Hourly Production Tracking tab - replica of the "HOURLY PRODUCTION TRACKING BOARD - BATTERY ASSEMBLY"
 * Google Sheet (+ its Dashboard + Production_Log sheets), restyled to this ERP's own dark theme (app.css'
 * :root tokens - --bg/--panel/--panel2/--navy/--gold/--txt/--mut/--line/--green/--amber/--grey/--red/--blue -
 * already defined globally, just referenced here with var(...)). The original sheet's light "spreadsheet"
 * palette (white panels, navy/blue header bars, pale yellow input cells) is gone; every panel, table and
 * input now reads as a native panel of this ERP, the same way prodtrack.css and inventory.js's cards do -
 * only the semantic meaning (achievement-% colour bands, variance colours, "this cell is editable" highlight)
 * is kept, re-expressed with this app's own colours.
 */
#page-hourlyproduction{
  --hp-font:'Segoe UI',system-ui,Arial,sans-serif;
}

#page-hourlyproduction .hp-tabs{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:16px}
#page-hourlyproduction .hp-pane{display:none}
#page-hourlyproduction .hp-pane.show{display:block}

/* Title bar / subtitle: a dark panel with a gold accent heading, instead of a solid navy banner. */
#page-hourlyproduction .hp-titlebar{
  font-family:var(--hp-font);background:var(--panel);color:var(--gold);font-weight:700;font-size:16px;
  text-align:center;letter-spacing:.3px;padding:14px 16px;border:1px solid var(--line);border-bottom:none;
  border-radius:10px 10px 0 0;
}
#page-hourlyproduction .hp-titlebar-deep{background:var(--panel2)}
#page-hourlyproduction .hp-subtitle{
  font-family:var(--hp-font);background:var(--panel2);color:var(--mut);font-style:italic;
  font-size:12px;text-align:center;padding:8px 16px 14px;border:1px solid var(--line);border-top:none;
  border-radius:0 0 10px 10px;margin-bottom:16px;
}

#page-hourlyproduction .hp-card{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:16px;margin-bottom:16px}
#page-hourlyproduction .hp-row{display:flex;gap:14px;flex-wrap:wrap;align-items:flex-end}
#page-hourlyproduction .hp-row .fld{min-width:150px}
#page-hourlyproduction .hp-status{font-size:12px;color:var(--mut);margin-left:auto}
#page-hourlyproduction .hp-status.ok{color:var(--green)}
#page-hourlyproduction .hp-status.err{color:var(--red)}

/* Editable KPI inputs (Shift Duration / Target 2W / Target 3W): the same gentle gold "editable" glow used
 * for the live board cells below, instead of a solid pale-yellow spreadsheet cell. */
#page-hourlyproduction .hp-in-yellow{background:rgba(245,197,24,.10)!important;color:var(--gold)!important;font-weight:700;border:1px solid var(--gold)}
/* Calculated (read-only) KPI cells: muted panel, no implied editability. */
#page-hourlyproduction .hp-in-calc{background:var(--panel2)!important;color:var(--txt)!important;font-weight:700;border:1px solid var(--line);cursor:default}

/* Bounded box with its own scrollbars (both directions) so the header - sticky to THIS box, not the
   page - never scrolls out of view: reaching the horizontal scrollbar no longer means losing the header
   first. Also made click-and-drag pannable (see hpEnableDragScroll in hourlyproduction.js) for mouse users
   who don't want to hunt for the thin scrollbar at the very bottom. */
#page-hourlyproduction .hp-tblwrap{
  overflow:auto;max-height:70vh;border-radius:10px;margin-bottom:14px;background:var(--panel);
  border:1px solid var(--line);cursor:grab;
  scrollbar-width:thin;scrollbar-color:var(--line) var(--panel);
}
#page-hourlyproduction .hp-tblwrap.hp-dragging{cursor:grabbing;user-select:none}
#page-hourlyproduction .hp-tblwrap::-webkit-scrollbar{height:10px;width:10px}
#page-hourlyproduction .hp-tblwrap::-webkit-scrollbar-track{background:var(--panel2)}
#page-hourlyproduction .hp-tblwrap::-webkit-scrollbar-thumb{background:var(--line);border-radius:6px}
#page-hourlyproduction .hp-tblwrap::-webkit-scrollbar-thumb:hover{background:var(--gold2)}
#page-hourlyproduction table.hp-tbl{width:100%;border-collapse:collapse;font-family:var(--hp-font);font-size:12.5px;background:var(--panel);min-width:980px}
#page-hourlyproduction table.hp-tbl th{
  background:var(--panel2);color:var(--gold);font-weight:700;padding:9px 8px;text-align:center;white-space:nowrap;
  border:1px solid var(--line);position:sticky;top:0;z-index:2;
}
#page-hourlyproduction table.hp-tbl td{padding:7px 8px;text-align:center;border:1px solid var(--line);color:var(--txt);white-space:nowrap}
#page-hourlyproduction table.hp-tbl td.hp-left{text-align:left;white-space:normal;min-width:160px}
#page-hourlyproduction table.hp-tbl tbody tr:nth-child(even){background:var(--panel2)}
#page-hourlyproduction table.hp-tbl tbody tr:nth-child(odd){background:var(--panel)}
/* Live, editable cells (Actual / Scrap Qty / Scrap Material / Remarks) - the gold "you can type here" glow. */
#page-hourlyproduction table.hp-tbl input{
  width:70px;padding:4px 6px;font-size:12px;border:1px solid var(--gold);border-radius:4px;background:rgba(245,197,24,.10);
  color:var(--txt);text-align:center;
}
#page-hourlyproduction table.hp-tbl input:focus{outline:none;border-color:var(--gold2);background:rgba(245,197,24,.18)}
#page-hourlyproduction table.hp-tbl input.hp-material,#page-hourlyproduction table.hp-tbl input.hp-remarks{width:130px;text-align:left}
#page-hourlyproduction .hp-empty{padding:16px;color:var(--mut);text-align:center;white-space:normal}

/* Variance / Achievement % conditional colour - SAME 3-way rule everywhere it is used (Hourly Board row,
 * Hourly Board TOTAL row, Monthly Dashboard day-wise table, Production Log): blue = positive/ahead of plan,
 * green = exactly on target, red = negative/short of plan.
 * These are qualified with "table.hp-tbl td" (not just the bare class) so they always win over the generic
 * "table.hp-tbl td{color:var(--txt)}" cell-text rule above (same class-count, but an extra element-selector on
 * the generic rule otherwise out-specifies a bare ".hp-var-pos" class and silently cancels the colour - that
 * was the actual bug: these colours were being assigned in the HTML all along but never actually rendering). */
#page-hourlyproduction table.hp-tbl td.hp-var-zero{color:var(--green);font-weight:700}
#page-hourlyproduction table.hp-tbl td.hp-var-pos{color:var(--blue);font-weight:700}
#page-hourlyproduction table.hp-tbl td.hp-var-neg{color:var(--red);font-weight:700}
/* Achievement % on the Hourly Board + Production Log specifically keeps its own 3-way rule (100%=green,
 * >100%=blue, <100%=red) - the Monthly Dashboard day-wise table's Achievement % keeps the separate 4-band
 * ramp below (hp-ach-cell.hp-ok100/hp-ok90/hp-warn/hp-fail), which is intentionally NOT touched. */
#page-hourlyproduction table.hp-tbl td.hp-ach-100{color:var(--green);font-weight:700}
#page-hourlyproduction table.hp-tbl td.hp-ach-over{color:var(--blue);font-weight:700}
#page-hourlyproduction table.hp-tbl td.hp-ach-under{color:var(--red);font-weight:700}
#page-hourlyproduction .hp-blank{color:var(--mut)}

/* TOTAL row - Total Actual / Cum Actual are plain magnitudes (not signed), so they keep the default gold
 * TOTAL-row styling; Variance / Achievement % are coloured dynamically by the same hp-var-*/hp-ach-* classes
 * as every per-row cell (previously hardcoded red regardless of sign - see JS report). */
#page-hourlyproduction table.hp-tbl tfoot td{
  background:var(--panel2);font-weight:700;color:var(--gold);border-top:2px solid var(--gold);
}
#page-hourlyproduction table.hp-tbl tfoot td.hp-var-zero{color:var(--green)}
#page-hourlyproduction table.hp-tbl tfoot td.hp-var-pos{color:var(--blue)}
#page-hourlyproduction table.hp-tbl tfoot td.hp-var-neg{color:var(--red)}
#page-hourlyproduction table.hp-tbl tfoot td.hp-ach-100{color:var(--green)}
#page-hourlyproduction table.hp-tbl tfoot td.hp-ach-over{color:var(--blue)}
#page-hourlyproduction table.hp-tbl tfoot td.hp-ach-under{color:var(--red)}

#page-hourlyproduction .hp-note{font-family:var(--hp-font);font-style:italic;font-size:12px;color:var(--mut);background:var(--panel2);border:1px dashed var(--line);border-radius:8px;padding:10px 14px;margin-bottom:24px}

/* Monthly Dashboard KPI cards - same look as this app's .card / .fgrid panels elsewhere. */
#page-hourlyproduction .hp-kpis{display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:10px;margin-bottom:16px}
#page-hourlyproduction .hp-kpi{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:12px 14px;text-align:center}
#page-hourlyproduction .hp-kpi .hp-kpi-label{background:var(--panel2);color:var(--mut);font-size:10.5px;font-weight:700;text-transform:uppercase;letter-spacing:.3px;border-radius:6px;padding:4px 6px;margin-bottom:6px}
#page-hourlyproduction .hp-kpi .hp-kpi-value{color:var(--txt);font-size:18px;font-weight:800}
#page-hourlyproduction .hp-kpi .hp-kpi-value.hp-pct-100{color:var(--green)}
#page-hourlyproduction .hp-kpi .hp-kpi-value.hp-pct-90{color:var(--green)}
#page-hourlyproduction .hp-kpi .hp-kpi-value.hp-pct-70{color:var(--amber)}
#page-hourlyproduction .hp-kpi .hp-kpi-value.hp-pct-low{color:var(--red)}
/* KPI cards that are fundamentally a signed/variance number (the "Variance" KPI, "Days Below Target") use the
 * same 3-way blue/green/red rule as the table columns below them, via the same hp-var-pos/zero/neg class names. */
#page-hourlyproduction .hp-kpi .hp-kpi-value.hp-var-pos{color:var(--blue)}
#page-hourlyproduction .hp-kpi .hp-kpi-value.hp-var-zero{color:var(--green)}
#page-hourlyproduction .hp-kpi .hp-kpi-value.hp-var-neg{color:var(--red)}

/* Day-wise dashboard table row colouring - tinted overlays instead of pastel spreadsheet fills. */
#page-hourlyproduction table.hp-tbl td.hp-sunday{background:rgba(245,197,24,.08)!important}
#page-hourlyproduction table.hp-tbl tr.hp-scrap-row td{background:rgba(231,76,60,.07)}
#page-hourlyproduction table.hp-tbl td.hp-ach-cell.hp-ok100{background:rgba(39,194,76,.16);color:var(--green);font-weight:700}
#page-hourlyproduction table.hp-tbl td.hp-ach-cell.hp-ok90{background:rgba(39,194,76,.10);color:var(--green);font-weight:700}
#page-hourlyproduction table.hp-tbl td.hp-ach-cell.hp-warn{background:rgba(245,166,35,.14);color:var(--amber);font-weight:700}
#page-hourlyproduction table.hp-tbl td.hp-ach-cell.hp-fail{background:rgba(231,76,60,.16);color:var(--red);font-weight:700}

/* Charts - row 1: the two trend charts (Daily Plan vs Actual, Cumulative Plan vs Actual), side by side,
 * roughly equal width (same auto-fit/minmax pattern as the app-wide .fgrid in app.css, reused here). */
#page-hourlyproduction .hp-dash-charts{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:16px;margin-bottom:16px}
#page-hourlyproduction .hp-chartcard{background:var(--panel);border-radius:12px;padding:14px;border:1px solid var(--line)}
#page-hourlyproduction .hp-chartcard h4{font-family:var(--hp-font);color:var(--gold);font-size:13px;margin-bottom:10px;text-align:center}

/* Scrap panel (row 2) - the Scrap Share doughnut and its Scrap Type qty table are a single self-contained
 * unit: pie on the left, its breakdown table on the right, inside one shared row, instead of the pie being
 * aligned with the other charts above while the table sits orphaned below with a gap under the pie. */
#page-hourlyproduction .hp-scrap-panel{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:16px;margin-bottom:16px;align-items:stretch}
#page-hourlyproduction .hp-scrap-tablecard{display:flex;flex-direction:column}
#page-hourlyproduction .hp-scrap-tablecard .hp-tblwrap{margin-bottom:0;flex:1}

/* Production Log pager */
#page-hourlyproduction .hp-pager{display:flex;align-items:center;gap:10px;justify-content:flex-end;font-size:12px;color:var(--mut);margin-bottom:24px}

/* Scrap Material live Odoo dropdown (Hourly Board rows) - reuses the app-wide .ss-list/.ss-item look (already
 * dark-theme, see app.css) via its own wrapper so the field positions correctly inside a table cell without
 * being clipped by the table's horizontal scroll box (the dropdown itself is fixed-positioned by JS, same
 * technique as the Scrap tab's Item Name search). */
#page-hourlyproduction .hp-ss-wrap{position:relative;display:inline-block;width:100%}
#page-hourlyproduction .hp-ss-wrap .hp-material{width:100%}
#page-hourlyproduction .ss-list{min-width:220px}

@media(max-width:700px){
  #page-hourlyproduction .hp-row .fld{min-width:120px}
  #page-hourlyproduction .hp-dash-charts{grid-template-columns:1fr}
  #page-hourlyproduction .hp-scrap-panel{grid-template-columns:1fr}
}
