/* Team MEM dashboard styles: filter bar, KPI tiles, bar and column charts, heat map, tables,
   job pop-up and tooltip. Used by the Jobs Dashboard and Monash Uni. Page-specific styles stay
   in each page. */
/* Chart roles. Bars: dark MEM cerulean (3.7:1 on white); hover: MEM cerulean;
   filtered-out bars: grey. Heat map: one-hue cerulean-to-navy ramp (monotone lightness). */
.dashboard {
  --bar: #0b87b6;
  --bar-hover: #0fa8e0;
  --bar-muted: #cfd8e1;
  --track: #eef3f7;
  --grid: #e3e9ef;
  --axis: #b8c2cc;
  --ink-muted: #7a8590;
  --heat-1: #9ad8f2;
  --heat-2: #4fbde9;
  --heat-3: #0b87b6;
  --heat-4: #0a5a80;
  --heat-5: #0b223a;
  --critical: #d03b3b;
}

main {
  max-width: 1400px;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* Filters: one row above everything they scope. */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  margin-bottom: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-bar .field {
  font-size: 12px;
  gap: 5px;
}

.filter-bar .field select,
.filter-bar .field input {
  padding: 9px 10px;
  font-size: 14px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -8px 0 16px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--mem-blue-soft);
  color: var(--mem-navy);
  font-size: 13px;
  font-weight: 600;
}

.filter-chip button {
  padding: 0 2px;
  background: none;
  color: var(--mem-navy);
  font-size: 15px;
  line-height: 1;
}

.filter-chip button:hover {
  background: none;
  color: var(--danger-text);
  transform: none;
}

/* KPI row */
.kpis {
  display: grid;
  grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: left;
  color: var(--text);
  font: inherit;
  display: flex;
  flex-direction: column;
  /* Left-aligned like the plain tiles (base.css centres button contents) */
  align-items: stretch;
  justify-content: space-between;
  min-height: 104px;
}

button.kpi:hover {
  background: var(--card);
  border-color: var(--bar);
  transform: none;
}

button.kpi[aria-pressed="true"] {
  border-color: var(--bar);
  box-shadow: 0 0 0 3px rgba(15, 168, 224, 0.25), var(--shadow);
}

.kpi-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-value {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.1;
}

.kpi.hero .kpi-value {
  font-size: 52px;
}

.kpi-sub {
  color: var(--muted);
  font-size: 12px;
}

.kpi.critical .kpi-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--danger-text);
}

.status-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: var(--critical);
}

/* Chart cards */
.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  transition: opacity 0.2s ease;
}

.charts.loading,
.kpis.loading,
.table-card.loading {
  opacity: 0.5;
}

.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}

.chart-card.wide {
  grid-column: 1 / -1;
}

.chart-title {
  margin: 0;
  font-size: 17px;
}

.chart-sub {
  margin: 4px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

/* Horizontal bars: HTML rows, each a button (hover, focus and click-to-filter). */
.bars {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 34%) 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 5px 4px;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  text-align: left;
}

.bar-row:hover,
.bar-row:focus-visible {
  background: #f5f8fb;
  transform: none;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.bar-fill {
  height: 16px;
  min-width: 2px;
  border-radius: 0 4px 4px 0;
  background: var(--bar);
  transition: width 0.25s ease, background 0.15s ease;
}

.bar-row:hover .bar-fill,
.bar-row:focus-visible .bar-fill {
  background: var(--bar-hover);
}

.bars.has-selection .bar-row:not(.selected) .bar-fill {
  background: var(--bar-muted);
}

.bar-value {
  flex: 0 0 auto;
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Columns: jobs issued per month */
.columns {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  align-items: end;
  gap: 2px;
  height: 200px;
  padding-top: 18px;
  border-bottom: 1px solid var(--axis);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px);
  background-size: 100% 25%;
  background-position: 0 -1px;
}

.column {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  padding: 0;
  background: transparent;
  border-radius: 0;
}

.column:hover {
  background: rgba(0, 0, 0, 0.02);
  transform: none;
}

.column-fill {
  width: min(24px, 70%);
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--bar);
  transition: height 0.25s ease;
}

.column:hover .column-fill,
.column:focus-visible .column-fill {
  background: var(--bar-hover);
}

.column-cap {
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.column-axis {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 2px;
  margin-top: 6px;
  color: var(--ink-muted);
  font-size: 11px;
  text-align: center;
}

/* Heat map: stage x status */
.heat-wrap {
  overflow-x: auto;
}

.heat {
  border-collapse: separate;
  border-spacing: 2px;
  width: 100%;
  font-size: 13px;
}

.heat th {
  padding: 6px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.heat th.row-head {
  text-align: left;
  color: var(--text);
  font-weight: 600;
  white-space: normal;
  min-width: 160px;
}

.heat td {
  padding: 0;
}

.heat-cell {
  width: 100%;
  min-width: 56px;
  height: 34px;
  padding: 0;
  border-radius: 4px;
  background: #f3f6f9;
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.heat-cell:hover,
.heat-cell:focus-visible {
  outline: 2px solid var(--mem-navy);
  outline-offset: 1px;
  transform: none;
}

.heat-cell[data-step="1"] { background: var(--heat-1); color: var(--mem-navy-dark); }
.heat-cell[data-step="2"] { background: var(--heat-2); color: var(--mem-navy-dark); }
.heat-cell[data-step="3"] { background: var(--heat-3); color: #fff; }
.heat-cell[data-step="4"] { background: var(--heat-4); color: #fff; }
.heat-cell[data-step="5"] { background: var(--heat-5); color: #fff; }

.heat .total {
  color: var(--text);
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.heat-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.heat-legend span.swatch {
  width: 28px;
  height: 12px;
  border-radius: 3px;
}

/* Table views and the job list */
details.table-view {
  margin-top: 14px;
  font-size: 13px;
}

details.table-view summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table td.num,
.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: #f7f9fb;
}

.data-table th button {
  padding: 0;
  background: none;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
}

.data-table th button:hover {
  background: none;
  color: var(--text);
  transform: none;
}

.table-card {
  grid-column: 1 / -1;
}

.table-scroll {
  overflow-x: auto;
  margin-top: 8px;
}

.stage-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e9eff5;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.overdue-flag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--danger-text);
  font-weight: 700;
  white-space: nowrap;
}

.overdue-flag .status-icon {
  width: 13px;
  height: 13px;
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

/* Job rows open the job details. */
.job-row {
  cursor: pointer;
}

.job-row:hover td {
  background: var(--mem-blue-soft);
}

/* Open-in-simPRO: a small link beside the job number, and a button in the job pop-up */
.simpro-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.simpro-link:hover {
  color: var(--mem-blue-text);
  text-decoration: underline;
}

.simpro-link svg,
.simpro-button svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.simpro-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--mem-navy);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}

.simpro-button:hover {
  background: var(--mem-navy-dark);
}

.job-link {
  padding: 0;
  background: none;
  color: var(--mem-blue-text);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.job-link:hover {
  background: none;
  color: var(--mem-blue-text);
  transform: none;
}

.job-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  border-top: 4px solid var(--mem-blue);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.job-dialog::backdrop {
  background: rgba(11, 34, 58, 0.55);
}

.job-dialog-inner {
  padding: 22px;
}

.job-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.job-dialog .message {
  margin-top: 16px;
}

.job-description h3 {
  margin: 20px 0 8px;
  font-size: 16px;
}

.job-description p {
  margin: 0;
  line-height: 1.55;
  white-space: pre-line;
  word-break: break-word;
}

/* Shared tooltip: value first, label second. */
.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  max-width: 260px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--mem-navy-dark);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.tooltip strong {
  display: block;
  font-size: 16px;
}

.tooltip span {
  color: #c9d6e2;
}

/* Monash work orders section */
.mu-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.mu-kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 4px 0 18px;
}

.mu-kpis .kpi {
  min-height: 84px;
  padding: 12px 14px;
}

.mu-kpis .kpi-value {
  font-size: 26px;
}

.mu-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 24px;
}

.mu-sub {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
}

.mu-flag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.mu-flag.extension {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.mu-flag.hold {
  background: #eef1f4;
  color: var(--muted);
}

@media (max-width: 980px) {
  .mu-kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* minmax(0, ...) lets the due-soonest table scroll in the card instead of widening the page */
  .mu-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 680px) {
  .mu-kpis {
    grid-template-columns: 1fr 1fr;
  }
}

.setup ol {
  margin: 12px 0 0;
  padding-left: 20px;
  line-height: 1.6;
}

.setup code {
  background: #eef3f7;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}

@media (max-width: 1100px) {
  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* Wide tables scroll inside their card instead of widening the page */
  .chart-card,
  .chart-card > * {
    min-width: 0;
  }

  .filter-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    position: static;
  }
}

@media (max-width: 800px) {
  .charts {
    grid-template-columns: 1fr;
  }
}

/* Phones: the "Filters" button (added by shared/filters.js) folds the filter bar away */
.filter-toggle {
  display: none;
}

@media (max-width: 680px) {
  .kpis,
  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }

  .filter-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 12px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    box-shadow: var(--shadow);
  }

  .filter-toggle:hover {
    background: var(--card);
    transform: none;
  }

  .filter-toggle-chevron {
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
  }

  .filter-toggle[aria-expanded="true"] .filter-toggle-chevron {
    transform: rotate(-135deg);
  }

  .filter-bar:not(.is-open) {
    display: none;
  }

  /* Search box and Reset get a full row each */
  .filter-bar .field-wide,
  .filter-bar > button {
    grid-column: 1 / -1;
  }

  .filter-bar .field select,
  .filter-bar .field input {
    font-size: 16px; /* 16px stops iPhones zooming in on focus */
  }

  .kpi.hero {
    grid-column: 1 / -1;
  }

  .kpi.hero .kpi-value {
    font-size: 48px;
  }

  .column-cap {
    font-size: 10px;
  }

  .job-dialog-inner {
    padding: 18px 16px;
  }

  .job-dialog .job-details {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  .job-dialog .job-details dd {
    margin-bottom: 8px;
  }
}
  
