/* ============================================================
   Time Clock, Employee KPIs, Tasks & Projects
   (js/modules/timeclock.js, kpis.js, tasks.js load this with
   ui.stylesheet). Builds on app.css tokens and classes.
   ============================================================ */

/* ---------------- Shared ---------------- */

/* A list row with a trailing action button beside it (the app's swipe
   actions): the button sits next to the link, never inside it. */
.work-action-row { display: flex; align-items: center; min-width: 0; }
.work-action-row > .row { flex: 1; min-width: 0; }
.work-action-row > .btn { margin-right: 8px; color: var(--text-dim); }
.work-action-row > .btn:hover:not(:disabled) { color: var(--red); }

/* ---------------- Tasks & Projects ---------------- */

.work-done { text-decoration: line-through; color: var(--text-dim); }
.work-title-line { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.work-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-progress { padding: 6px 0 2px; }
.work-progress .progress { height: 6px; }
.row.work-danger .row-title, .row.work-danger .row-lead { color: var(--red); }
.work-headline { font-size: 1.08rem; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }

/* ---------------- KPIs: team averages (horizontal bars) ---------------- */

.kpi-bars { display: flex; flex-direction: column; gap: 10px; }
.kpi-bar-row { display: grid; grid-template-columns: minmax(80px, 30%) minmax(0, 1fr); align-items: center; gap: 12px; }
.kpi-bar-name { font-size: 0.88rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.kpi-bar-fill { display: block; flex: 0 1 auto; height: 18px; min-width: 2px; border-radius: 0 4px 4px 0; }
.kpi-bar-value { font-size: 0.8rem; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------- KPIs: trend (lines by month) ---------------- */

/* Categorical series colors, fixed order (validated palette). */
.kpi-s1 { --c: #2a78d6; }
.kpi-s2 { --c: #eb6834; }
.kpi-s3 { --c: #1baf7a; }
.kpi-s4 { --c: #eda100; }
.kpi-s5 { --c: #e87ba4; }
.kpi-s6 { --c: #008300; }
.kpi-s7 { --c: #4a3aa7; }
.kpi-s8 { --c: #e34948; }

.kpi-trend { display: flex; flex-direction: column; gap: 10px; }
.kpi-trend-frame { padding-left: 46px; padding-right: 6px; }
.kpi-trend-plot { position: relative; height: 180px; outline: none; touch-action: pan-y; }
.kpi-trend-plot:focus-visible { box-shadow: 0 0 0 3px rgba(23, 32, 51, 0.16); border-radius: 6px; }
.kpi-trend-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.kpi-trend-svg .kpi-grid { stroke: rgba(23, 32, 51, 0.08); stroke-width: 1; }
.kpi-trend-svg .kpi-base { stroke: rgba(23, 32, 51, 0.24); stroke-width: 1; }
.kpi-trend-svg .kpi-line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.kpi-dot {
  position: absolute; width: 10px; height: 10px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 2px #fff; transform: translate(-50%, -50%); pointer-events: none;
}
.kpi-ytick {
  position: absolute; right: calc(100% + 8px); transform: translateY(-50%);
  font-size: 0.72rem; color: var(--text-faint); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.kpi-xaxis { position: relative; height: 18px; margin-top: 6px; }
.kpi-xtick { position: absolute; top: 0; transform: translateX(-50%); font-size: 0.72rem; color: var(--text-faint); white-space: nowrap; }
.kpi-xtick.is-first { transform: none; }
.kpi-xtick.is-last { transform: translateX(-100%); }
.kpi-cross { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(23, 32, 51, 0.3); pointer-events: none; }
.kpi-tip {
  position: absolute; top: 4px; margin-left: 10px; min-width: 140px; max-width: 240px; z-index: 2;
  padding: 8px 10px; border-radius: 10px; background: #fff; border: 1px solid var(--line);
  box-shadow: var(--shadow-deep); font-size: 0.82rem; pointer-events: none;
}
.kpi-tip.is-left { transform: translateX(-100%); margin-left: -10px; }
.kpi-tip-head { font-weight: 650; color: var(--ink); margin-bottom: 4px; }
.kpi-tip-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.kpi-tip-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-tip-row .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; background: var(--c); flex-shrink: 0; }
.kpi-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.82rem; color: var(--text-dim); }
.kpi-legend-item { display: inline-flex; align-items: center; gap: 6px; }

/* ---------------- Time Clock: punch card ---------------- */

.tc-punch { display: flex; flex-direction: column; gap: 16px; padding: 18px 18px 16px; }
.tc-punch-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.tc-punch-dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(23, 32, 51, 0.28); flex-shrink: 0; }
.tc-punch-dot.is-in { background: var(--green); }
.tc-punch-dot.is-break { background: #d97a06; }
.tc-punch-status { flex: 1 1 auto; min-width: 0; }
.tc-punch-title { font-size: 1.2rem; font-weight: 700; color: var(--ink); line-height: 1.3; }
.tc-punch-since { font-size: 0.86rem; color: var(--text-dim); }
.tc-punch-timer { margin-left: auto; font-size: 2.1rem; line-height: 1.1; }
.tc-punch-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.tc-punch-actions .btn { flex: 1 1 150px; min-height: 46px; }

.tc-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tc-punch .tc-stats { border-top: 1px solid var(--line); padding-top: 14px; }
.tc-stat { text-align: center; min-width: 0; }
.tc-stat-value { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.tc-stat-label { font-size: 0.76rem; color: var(--text-dim); line-height: 1.3; }

.tc-notice { align-items: center; }
.tc-notice > span { flex: 1; min-width: 0; }
.tc-notice > .btn { min-height: 28px; min-width: 28px; padding: 2px; color: inherit; }

.tc-banner .ink-label { font-weight: 650; color: var(--ink); }

/* ---------------- Time Clock: team status & history ---------------- */

.tc-status { display: block; font-size: 0.86rem; }
.tc-caption { display: flex; gap: 8px; min-width: 0; font-size: 0.82rem; color: var(--text-dim); }
.tc-notes { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-edited { display: inline-flex; color: var(--ink); }
.tc-day-total { font-size: 0.86rem; font-weight: 650; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.tc-range { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.tc-range-field { flex: 1 1 180px; }
.tc-range-field .select { width: 100%; }
.tc-log {
  font-size: 0.82rem; color: var(--text-dim); background: var(--well); border: 1px solid var(--line);
  border-radius: var(--radius-ui); padding: 10px 12px; max-height: 220px; overflow: auto;
}

/* ---------------- Small screens ---------------- */

@media (max-width: 760px) {
  .tc-punch { padding: 16px 14px 14px; }
  .tc-punch-timer { font-size: 1.75rem; }
}

@media (max-width: 560px) {
  /* Only the first and last month fit under a phone-width chart. */
  .kpi-xtick.is-mid { display: none; }
}

@media (max-width: 420px) {
  .tc-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 12px; }
  .kpi-bar-row { grid-template-columns: minmax(70px, 34%) minmax(0, 1fr); gap: 8px; }
  .kpi-trend-frame { padding-left: 40px; }
}
