/* ==========================================================================
   Work calendar (#/calendar) - web/js/pages/calendar.js
   Every class starts with "cal-". A team member's colour comes from the data
   and is passed in as the CSS variable --c; payment states use data-pay.
   ========================================================================== */

/* ---------- Clock in / clock out (page actions) ---------- */
.cal-clock-slot { display: contents; }
.cal-clock-skel { display: block; width: 118px; height: 40px; border-radius: var(--radius-pill); }
.cal-clock {
  display: inline-flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 4px 0 14px; max-width: 100%;
  border-radius: var(--radius-pill);
  background: var(--up-soft); border: 1px solid var(--line);
}
.cal-clock-text { font-size: 14px; color: var(--text-2); white-space: nowrap; }
.cal-clock-text .cal-live { color: var(--text); font: 600 14px var(--font-mono); }
.cal-clock .btn { height: 32px; background: var(--surface); }
.cal-clock .btn:hover { background: var(--surface-2); }
.cal-live-strong { color: var(--text); font-family: var(--font-mono); font-weight: 600; }

/* ---------- Toolbar: month, arrows, Month | List ---------- */
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
.cal-nav { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cal-month {
  font-size: clamp(26px, 3.2vw, 34px); line-height: 1.05; font-weight: 400;
  min-width: 7.2em; text-align: center; letter-spacing: -.01em;
}
.cal-nav .btn-sm { margin-left: 6px; }

/* ---------- Member filter chips ---------- */
.cal-filters { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.cal-filter {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 12px; max-width: 100%;
  border-radius: var(--radius-pill); border: 1px solid var(--line-2);
  background: transparent; color: var(--text-2);
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.cal-filter:hover { color: var(--text); border-color: var(--text-3); }
.cal-filter.active { background: var(--surface-3); color: var(--text); border-color: var(--teal-line); box-shadow: inset 0 0 0 1px var(--teal-line); }
.cal-filter-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c, var(--teal)); }

/* ---------- Page layout: calendar + side cards ---------- */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.cal-main { min-width: 0; }
.cal-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 1100px) {
  .cal-layout { grid-template-columns: minmax(0, 1fr); }
  .cal-side { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
}
.cal-foot-note { padding: 10px 22px 14px; }

/* ---------- Month view ---------- */
.cal-card { padding: 10px; container-type: inline-size; overflow: hidden; }
.cal-card .cal-foot-note { padding: 10px 6px 2px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-weekdays { margin-bottom: 6px; }
.cal-wd {
  padding: 6px 0; text-align: center;
  font-size: 11px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--text-3);
}
.cal-day {
  display: flex; flex-direction: column; align-items: stretch; gap: 5px;
  min-width: 0; min-height: 112px; padding: 8px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); text-align: left; font: inherit; cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease), transform .08s;
}
.cal-day:hover { border-color: var(--text-3); background: var(--surface-3); }
.cal-day:active { transform: translateY(1px); }
.cal-day.weekend { background: var(--bg-2); }
.cal-day.weekend:hover { background: var(--surface-3); }
.cal-day.out { opacity: .42; }
.cal-day.out:hover { opacity: .8; }
.cal-day.today { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.cal-day-top { display: flex; align-items: center; justify-content: space-between; gap: 4px; min-width: 0; }
.cal-num {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 5px;
  border-radius: var(--radius-pill); font: 600 13px var(--font-mono); color: var(--text-2);
}
.cal-day.has-work .cal-num { color: var(--text); }
.cal-day.today .cal-num { background: var(--teal); color: var(--teal-ink); }
.cal-day-total { font: 500 11.5px var(--font-mono); color: var(--text-3); white-space: nowrap; }

.cal-chips { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 4px; min-width: 0;
  padding: 2px 6px; border-radius: 6px;
  font-size: 11.5px; line-height: 1.35; color: var(--text);
  background: color-mix(in srgb, var(--c, var(--teal)) 16%, transparent);
  border-left: 3px solid var(--c, var(--teal));
}
.cal-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cal-chip-h { flex: none; font: 500 11px var(--font-mono); color: var(--text-2); }
.cal-chip.running .cal-chip-h::before {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 4px; vertical-align: 1px;
  border-radius: 50%; background: var(--up); animation: pulse 2s infinite;
}
.cal-chip.more {
  background: none; border-left: 0; padding: 0 2px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-dots { display: none; }
.cal-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--c, var(--teal)); }
.cal-dot.running { box-shadow: 0 0 0 2px var(--up-soft); }

/* Payment markers. Status colour: --pc */
:is(.cal-pay, .cal-pay-row)[data-pay="overdue"]  { --pc: var(--down); }
:is(.cal-pay, .cal-pay-row)[data-pay="today"]    { --pc: var(--warn); }
:is(.cal-pay, .cal-pay-row)[data-pay="tomorrow"] { --pc: var(--lime); }
:is(.cal-pay, .cal-pay-row)[data-pay="upcoming"] { --pc: var(--teal); }
:is(.cal-pay, .cal-pay-row):is([data-pay="paid"], [data-pay="skipped"]) { --pc: var(--text-3); }

.cal-pays { display: flex; flex-direction: column; gap: 3px; margin-top: auto; min-width: 0; }
.cal-pay {
  display: flex; align-items: center; gap: 4px; min-width: 0;
  padding: 1px 6px; border-radius: 6px;
  font-size: 11px; line-height: 1.4; color: var(--text-2);
  background: var(--surface); border-left: 2px solid var(--pc, var(--line-2));
}
.cal-pay svg { width: 11px; height: 11px; flex: none; color: var(--pc, var(--text-3)); }
.cal-pay-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cal-pay[data-pay="overdue"] { background: var(--down-soft); color: var(--down); }
.cal-pay[data-pay="today"] { background: var(--warn-soft); color: var(--text); }
.cal-pay[data-pay="tomorrow"] { background: var(--lime-soft); color: var(--text); }
.cal-pay[data-pay="paid"] { background: transparent; color: var(--text-3); }
.cal-pay[data-pay="skipped"] { background: transparent; color: var(--text-3); text-decoration: line-through; }
.cal-pay.more { background: none; border-left: 0; color: var(--text-3); }

/* Narrow calendar (phones, or a narrow column): dots and totals instead of chips */
@container (max-width: 620px) {
  .cal-grid { gap: 3px; }
  .cal-wd { font-size: 10px; letter-spacing: .06em; padding: 4px 0; }
  .cal-day {
    min-height: 60px; padding: 5px 2px; gap: 3px; align-items: center;
    border-radius: 9px;
  }
  .cal-day-top { flex-direction: column; gap: 1px; }
  .cal-num { min-width: 22px; height: 22px; font-size: 12px; padding: 0 3px; }
  .cal-day-total { font-size: 10px; color: var(--text-2); }
  .cal-chips { display: none; }
  .cal-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 100%; }
  .cal-dot { width: 6px; height: 6px; }
  .cal-pays { flex-direction: row; justify-content: center; gap: 2px; margin-top: auto; }
  .cal-pay { width: 14px; height: 4px; padding: 0; border: 0; border-radius: 2px; background: var(--pc, var(--text-3)); }
  .cal-pay[data-pay="paid"], .cal-pay[data-pay="skipped"] { background: var(--line-2); }
  .cal-pay svg, .cal-pay-text { display: none; }
  .cal-pay.more { display: none; }
  .cal-card .cal-foot-note { padding: 8px 4px 0; }
}

/* ---------- List view and entry rows ---------- */
.cal-list-card { overflow: hidden; }
.cal-list-day + .cal-list-day { border-top: 1px solid var(--line); }
.cal-list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 22px 4px; }
.cal-list-date {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0;
  border: 0; background: none; color: var(--text); cursor: pointer;
  font: 600 15px var(--font-ui);
}
.cal-list-date:hover { color: var(--teal); }
.cal-list-total { font: 500 13px var(--font-mono); color: var(--text-2); white-space: nowrap; }
.cal-list-day .list-row { padding: 12px 22px; border-bottom: 0; }
.cal-list-day .list:last-child .list-row:last-child { padding-bottom: 16px; }

.cal-entry, .cal-pay-row { align-items: start; }
.cal-entry-main { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.cal-entry-text { min-width: 0; flex: 1; }
.cal-entry-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cal-entry .row-title, .cal-pay-row .row-title { font-size: 15px; flex-wrap: wrap; row-gap: 4px; }
.cal-entry .row-value, .cal-pay-row .row-value { font-size: 15.5px; }
.cal-entry.is-running .row-value { color: var(--up); }
.cal-entry .badge .pulse { width: 6px; height: 6px; }
.cal-note {
  margin-top: 6px; font-size: 13.5px; line-height: 1.45; color: var(--text-2);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.cal-pay-icon {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border-radius: 50%; background: var(--surface-3); color: var(--pc, var(--text-2));
}
.cal-pay-icon svg { width: 16px; height: 16px; }
.cal-pay-row[data-pay="paid"] .row-title, .cal-pay-row[data-pay="skipped"] .row-title { color: var(--text-2); }
.cal-pay-row[data-pay="skipped"] .row-title span { text-decoration: line-through; }
.cal-pay-row[data-pay="paid"] .row-value, .cal-pay-row[data-pay="skipped"] .row-value { color: var(--text-3); }

/* ---------- Day panel (modal) ---------- */
.cal-panel { display: flex; flex-direction: column; gap: 16px; padding-bottom: 4px; }
.cal-panel-head { flex-wrap: wrap; }
.cal-panel-sec { display: flex; flex-direction: column; gap: 8px; }
.cal-panel-list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-panel-list .list-row { padding: 12px 14px; }

/* ---------- Add / change dialog ---------- */
.cal-mode { align-self: flex-start; }
.cal-mode .tab svg { width: 15px; height: 15px; }
.cal-preview { min-height: 18px; margin-top: -6px; }
.cal-preview.down { color: var(--down); }

/* ---------- Side cards ---------- */
.cal-sum-total { display: flex; align-items: baseline; gap: 8px; margin-bottom: 18px; }
.cal-sum-big { font-family: var(--font-display); font-size: 48px; line-height: .95; letter-spacing: -.01em; }
.cal-sum-unit { font-size: 13px; color: var(--text-2); }
.cal-sum-empty { margin: -8px 0 14px; }
.cal-bars { display: flex; flex-direction: column; gap: 6px; }
.cal-bar {
  display: flex; flex-direction: column; gap: 6px; width: 100%;
  padding: 7px 8px; margin: 0 -8px; box-sizing: content-box;
  border: 0; border-radius: 10px; background: none; color: inherit;
  font: inherit; text-align: left; cursor: pointer;
  transition: background .15s var(--ease), opacity .15s var(--ease);
}
.cal-bar:hover { background: var(--surface-2); }
.cal-bar.dim { opacity: .45; }
.cal-bar.selected { background: var(--surface-2); }
.cal-bar-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; font-size: 13.5px; }
.cal-bar-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 500; }
.cal-bar-val { flex: none; font: 500 12.5px var(--font-mono); color: var(--text-2); white-space: nowrap; }
.cal-bar-track { height: 8px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.cal-bar-fill { height: 100%; border-radius: inherit; background: var(--c, var(--teal)); transition: width .4s var(--ease); }

.cal-now .list-row { padding: 12px 18px; }
.cal-now .row-title { font-size: 14.5px; }
.cal-now .cal-live { font: 500 14px var(--font-mono); color: var(--up); white-space: nowrap; }

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  .cal-toolbar { flex-direction: column; align-items: stretch; }
  .cal-nav { width: 100%; }
  .cal-month { flex: 1; min-width: 0; font-size: 26px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cal-view-tabs { align-self: stretch; }
  .cal-view-tabs .tab { flex: 1; justify-content: center; }
  .cal-list-head { padding: 12px 16px 4px; }
  .cal-list-day .list-row { padding: 12px 16px; }
  .cal-panel-list .list-row { padding: 12px; }
  .cal-entry-main { gap: 10px; }
  /* Clock and "Add work time" share the full width (and wrap when the clock is running) */
  .cal-page .page-head .page-actions { width: 100%; }
  .cal-page .page-actions > .btn, .cal-clock-slot > .btn, .cal-clock-slot > .cal-clock { flex: 1 1 auto; }
  .cal-clock { justify-content: space-between; }
  .cal-clock-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }
}
