/* Week picker, toolbar, week grid, day view, calendar. */

/* ---------- week grid ----------
   The scroll container is height-capped so that BOTH the sticky header row and
   the sticky employee column actually stick while scrolling inside it. */
.grid-scroll {
  overflow: auto;
  max-height: calc(100dvh - 260px);
  min-height: 320px;
  overscroll-behavior: contain;
  border-radius: var(--radius);
}
table.grid {
  border-collapse: separate; border-spacing: 0;
  width: 100%; min-width: 900px; background: var(--surface);
}
table.grid th, table.grid td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.grid thead th {
  position: sticky; top: 0; z-index: 6;
  background: var(--surface-2);
  padding: 0; font-size: 12.5px; text-align: center; color: var(--muted);
}
table.grid thead th.col-head { padding: 9px 12px; }
table.grid thead th.emp-cell { z-index: 7; text-align: left; }
table.grid thead th.today { background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
/* the same warm tint turns muddy on a dark ground — mark today with a rule instead */
@media (prefers-color-scheme: dark) {
  table.grid thead th.today {
    background: var(--surface-2);
    box-shadow: inset 0 -2px 0 var(--accent);
  }
}

.day-th-btn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  width: 100%; min-height: var(--tap); padding: 8px 10px;
  border: none; background: transparent; cursor: pointer; transition: background .12s;
}
.day-th-btn:hover { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.day-th-btn .dow { font-weight: 800; color: var(--text); font-size: 14px; }
.day-th-btn .dow-date { font-size: 12px; color: var(--muted); }

/* sticky employee column */
.emp-cell {
  position: sticky; left: 0; z-index: 4;
  background: var(--surface);
  padding: 10px 12px; min-width: 170px; max-width: 210px; text-align: left;
}
.emp-cell.is-mine { background: color-mix(in srgb, var(--green) 9%, var(--surface)); }

.emp-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 700; }
.emp-code { color: var(--muted); font-size: 12px; font-weight: 400; }

.fav-star {
  flex: none; display: inline-flex; align-items: center; padding: 2px;
  border: none; background: transparent; cursor: pointer;
  color: var(--muted); opacity: .5; line-height: 1;
}
.fav-star:hover { opacity: 1; color: var(--yellow); }
.fav-star.on { color: var(--yellow); opacity: 1; }

.emp-badge {
  font-size: 10px; font-weight: 800; text-transform: uppercase;
  padding: 1px 6px; border-radius: 6px;
}
.emp-badge.mine {
  background: rgba(26, 165, 104, .16); color: var(--green);
  border: 1px solid rgba(26, 165, 104, .4);
}

/* totals column — deliberately NOT .emp-cell, so it stays narrow */
.total-cell {
  padding: 10px 12px; min-width: 92px; width: 92px;
  text-align: left; border-right: none;
}
.emp-total { font-size: 14px; color: var(--text); }
.emp-total b { color: var(--ok); font-size: 16px; }
.emp-total .net { margin-top: 2px; font-size: 11.5px; color: var(--muted); font-weight: 600; }

td.day-cell { padding: 6px; min-width: 118px; }
td.day-cell.empty {
  background: repeating-linear-gradient(45deg,
    transparent, transparent 7px, var(--surface-2) 7px, var(--surface-2) 8px);
}

/* ---------- shift ---------- */
.shift {
  border-radius: 8px; padding: 6px 8px; margin-bottom: 5px;
  background: var(--surface-2); border-left: 3px solid var(--pos, var(--primary));
}
.shift:last-child { margin-bottom: 0; }
.shift-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.shift-meta { margin-top: 2px; }
.shift-time { font-weight: 700; font-size: 13.5px; }
.shift-hours { font-size: 12px; color: var(--muted); }
.shift-breaks {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--muted);
}
.pos-badge {
  font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 5px;
  color: #fff; background: var(--pos, var(--primary));
}
.shift-inline {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 0; padding: 5px 10px; font-size: 13px;
  border: 1px solid var(--border); border-left: 3px solid var(--pos, var(--primary));
}

/* Picking a position keeps it in colour and pushes everything else back,
   so the chosen shifts read at a glance without losing the surrounding week. */
.shift.dim {
  opacity: .45;
  border-left-color: var(--faint);
  filter: grayscale(1);
}
.shift.dim .pos-badge { background: var(--faint); }
.shift:not(.dim) { transition: opacity .15s ease, filter .15s ease; }

/* ---------- day view ---------- */
.day-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.day-title { font-size: 18px; font-weight: 800; }
.dv-row {
  display: flex; gap: 14px; align-items: center;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
}
.dv-row:last-child { border-bottom: none; }
.dv-row.is-mine { background: color-mix(in srgb, var(--green) 8%, var(--surface)); }
.dv-emp { flex: none; width: 190px; min-width: 140px; }
.dv-shifts { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.dv-total { flex: none; font-size: 13px; color: var(--muted); }
.dv-total b { color: var(--ok); font-size: 15px; }

/* ---------- calendar ---------- */
.cal-modal { max-width: 380px; }
.cal-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.cal-title { font-weight: 800; font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd {
  text-align: center; font-size: 11px; color: var(--muted);
  font-weight: 700; padding-bottom: 4px;
}
.cal-cell {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.cal-cell.blank { background: transparent; border: none; cursor: default; }
.cal-cell.no { background: transparent; color: var(--muted); opacity: .45; cursor: default; }
.cal-cell.has {
  background: color-mix(in srgb, var(--ok) 14%, var(--surface));
  border-color: color-mix(in srgb, var(--ok) 40%, var(--surface));
}
.cal-cell.has:hover { background: color-mix(in srgb, var(--ok) 26%, var(--surface)); }
/* day states, weakest first so stronger ones win */
.cal-cell.off {
  background: repeating-linear-gradient(45deg,
    transparent, transparent 5px, var(--surface-2) 5px, var(--surface-2) 6px);
  border-color: var(--border); color: var(--muted);
}
.cal-cell.works {
  background: color-mix(in srgb, var(--ok) 16%, var(--surface));
  border-color: color-mix(in srgb, var(--ok) 45%, var(--surface));
  font-weight: 800;
}
.cal-cell.cur-week { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--primary) 45%, transparent); }
.cal-cell.today {
  outline: 2px solid var(--accent); outline-offset: -2px;
  color: var(--text); font-weight: 800;
}
.cal-cell.sel { background: var(--primary); border-color: var(--primary); color: #fff; }
.cal-cell.sel .cc-day { color: #fff; }

.cal-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 12px; font-size: 12px; color: var(--muted);
}
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg-dot { width: 8px; height: 8px; border-radius: 50%; }
.lg-box { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border); }
.lg-box.off {
  background: repeating-linear-gradient(45deg,
    transparent, transparent 3px, var(--surface-2) 3px, var(--surface-2) 4px);
}
.lg-box.today { border-color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-foot { font-size: 12px; margin-top: 10px; }

/* ---------- calendar: tracked days + preview ---------- */
.cal-cell { position: relative; flex-direction: column; gap: 1px; }
.cc-day { line-height: 1; }
.cc-dots { display: flex; gap: 2px; height: 4px; align-items: center; }
.cc-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ok); display: block; }
.cal-cell.sel .cc-dots i { background: #fff; }
.cal-cell.tracked { border-color: color-mix(in srgb, var(--ok) 55%, var(--surface)); }

/* popover floating above the tapped date */
.cal-pop {
  position: fixed; z-index: 60; width: min(280px, calc(100vw - 20px));
  padding: 10px 12px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
  animation: pop-in .14s ease both;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.cal-pop-arrow {
  position: absolute; bottom: -6px; width: 11px; height: 11px;
  background: var(--surface); border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: translateX(-50%) rotate(45deg);
}
.cal-pop.below .cal-pop-arrow {
  bottom: auto; top: -6px;
  border: none; border-left: 1px solid var(--border); border-top: 1px solid var(--border);
}
.cp-head { font-weight: 800; font-size: 13px; margin-bottom: 7px; }
.cp-body {
  display: flex; flex-direction: column;
  max-height: 168px; overflow-y: auto; overscroll-behavior: contain;
}
.cp-empty { font-size: 12.5px; padding: 4px 0 6px; }
.cp-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 7px 0; border-top: 1px solid var(--border);
}
.cp-row:first-child { border-top: none; padding-top: 0; }
.cp-who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.cp-name { font-weight: 700; font-size: 13px; }
.cp-code { font-size: 11.5px; color: var(--muted); }
.cp-shift {
  display: inline-flex; align-items: center; gap: 7px; align-self: flex-start;
  padding: 4px 9px; border-radius: 8px; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--pos, var(--primary));
}
.cp-row.is-mine .cp-name { color: var(--ok); }
.cp-open { width: 100%; margin-top: 10px; }
