/* grid.css - Day grid styles. Built up across phase 3 stages. */

:root {
  /* Vertical scale: pixels per minute. 780 min × 1.2 px = 936 px tall column. */
  --minute-px: 1.2px;
  /* Per-column horizontal width and axis gutter. */
  --col-width: 180px;
  --axis-width: 56px;
  --header-height: 40px;
  --grid-line: var(--color-border);
}

/* ── Day-view shell ──────────────────────────────────────────────────────── */

#day-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
#day-view[hidden] { display: none; }

#day-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

#day-header .btn-icon {
  width: 28px;
  height: 28px;
  font-size: 16px;
}

.day-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

#date-picker {
  font-family: inherit;
  font-size: 11px;
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  background: var(--color-surface);
}

.day-header-refresh {
  margin-left: auto;
}

#day-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: 0.01em;
}

#day-summary {
  font-size: 10px;
  color: var(--color-text-muted);
}

/* ── Grid scroller ───────────────────────────────────────────────────────── */

#day-grid {
  flex: 1;
  overflow: auto;
  background: var(--color-bg);
  position: relative;
  min-height: 0;
}

#day-grid-inner {
  display: grid;
  grid-template-areas:
    "corner headers"
    "axis   cols";
  grid-template-columns: var(--axis-width) max-content;
  grid-template-rows: var(--header-height) max-content;
}

/* Sticky corner — pins both directions when scrolling. */
#day-grid-corner {
  grid-area: corner;
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

/* Sticky column headers — pin to top when scrolling vertically. */
#day-grid-headers {
  grid-area: headers;
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

/* Sticky time axis — pin to left when scrolling horizontally. */
#day-grid-axis {
  grid-area: axis;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  width: var(--axis-width);
}

#day-grid-cols {
  grid-area: cols;
  display: flex;
}

/* ── Time axis ───────────────────────────────────────────────────────────── */

.hour-tick {
  height: calc(60 * var(--minute-px));
  font-size: 9px;
  color: var(--color-text-muted);
  text-align: right;
  padding: 2px 6px 0 0;
  border-top: 1px solid var(--grid-line);
  font-variant-numeric: tabular-nums;
}
.hour-tick:first-child { border-top: none; }

/* ── Column headers ──────────────────────────────────────────────────────── */

.day-col-hdr {
  width: var(--col-width);
  flex-shrink: 0;
  padding: 8px 10px;
  border-right: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-col-hdr-name {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.day-col-hdr-name:hover {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.day-col-hdr-count {
  flex-shrink: 0;
  font-size: 9px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.day-col-hdr-refresh {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.day-col-hdr-refresh:hover {
  color: var(--color-primary);
  background: var(--color-primary-light);
}

/* ── Column bodies ───────────────────────────────────────────────────────── */

.day-col {
  width: var(--col-width);
  flex-shrink: 0;
  height: calc(780 * var(--minute-px));
  position: relative;
  border-right: 1px solid var(--color-border);
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(60 * var(--minute-px) - 1px),
      var(--grid-line) calc(60 * var(--minute-px) - 1px),
      var(--grid-line) calc(60 * var(--minute-px))
    ),
    var(--color-surface);
}

/* Empty-state placeholder when no calendars loaded */
.day-col-empty-msg {
  padding: 40px 24px;
  color: var(--color-text-muted);
  font-size: 11px;
  text-align: center;
  font-style: italic;
}

/* ── All-day ribbon ──────────────────────────────────────────────────────── */

#day-grid-allday-row {
  display: flex;
  width: max-content;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
#day-grid-allday-row:empty { display: none; }

.day-allday-gutter {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--axis-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  font-size: 9px;
  color: var(--color-text-muted);
  padding: 6px 8px;
  text-align: right;
  font-style: italic;
}

.day-allday-cols {
  display: flex;
}

.day-allday-col {
  width: var(--col-width);
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  padding: 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 24px;
}

.day-allday-chip {
  font-size: 9px;
  background: var(--appt-default);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── WorkHours availability bands ────────────────────────────────────────── */

.wh-band {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 0;
  pointer-events: none;
}

/* Restore hour separators that the column gradient draws — they get covered
   by opaque bands. */
.wh-band-hour {
  border-top: 1px solid var(--grid-line);
}

/* ── Appointment cards ───────────────────────────────────────────────────── */

.appt-card {
  position: absolute;
  /* left + width set inline by grid.js per lane assignment */
  background: var(--appt-default);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-size: 9px;
  line-height: 1.25;
  overflow: hidden;
  box-shadow: 0 1px 2px var(--color-shadow);
  z-index: 1;
}

.appt-card-title {
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appt-card-meta {
  font-size: 8px;
  color: var(--color-text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Search highlight (phase 10). Inset shadow rather than border to avoid
   reflowing the card — width/left were computed against the 1px border. */
.appt-card.is-search-match,
.day-allday-chip.is-search-match {
  box-shadow: inset 0 0 0 3px orangered;
  z-index: 2;
}

/* Phase 11: PowerApps card-fill rules. First match wins (computed in
   grid.js:_fillModifier) — high importance > Cover > Sick > online > NSN. */
.appt-card.is-high,    .day-allday-chip.is-high   { background: var(--appt-importance-high); }
.appt-card.is-cover,   .day-allday-chip.is-cover  { background: var(--appt-cover); }
.appt-card.is-sick,    .day-allday-chip.is-sick   { background: var(--appt-sick); }
.appt-card.is-online,  .day-allday-chip.is-online { background: var(--appt-online); }
.appt-card.is-nsn,     .day-allday-chip.is-nsn    { background: var(--appt-nsn); }

/* Dashed border for non-"Type: Student" titles (no colon in title). */
.appt-card.is-dashed,
.day-allday-chip.is-dashed { border-style: dashed; }

/* Phase 11 stage 2: location icon. <img> in the lower-right corner of the
   card, sourced from TravelCosts.Thumbnail. .appt-card already has
   position: absolute (positioned in the grid); .day-allday-chip needs
   position: relative so the absolutely-positioned child anchors to it. */
.day-allday-chip { position: relative; }

.appt-card-loc {
  position: absolute;
  right: 3px;
  bottom: 2px;
  width: 16px;
  height: 16px;
  object-fit: contain;
  pointer-events: none;
  /* Soft white halo so the icon stays legible over coloured fills. */
  background: rgba(255, 255, 255, 0.6);
  border-radius: 2px;
}

.day-allday-chip .appt-card-loc {
  width: 12px;
  height: 12px;
  bottom: 50%;
  transform: translateY(50%);
}

/* ── Teacher week view (phase 8 stage 1 scaffolding) ─────────────────────── */

#teacher-week-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
#teacher-week-view[hidden] { display: none; }

#teacher-week-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

#teacher-week-header .btn-icon {
  width: 28px;
  height: 28px;
  font-size: 16px;
}

#week-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: 0.01em;
}

#week-summary {
  font-size: 10px;
  color: var(--color-text-muted);
}

#week-teacher-picker {
  font-family: inherit;
  font-size: 11px;
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  background: var(--color-surface);
}

#btn-refresh-week {
  margin-left: auto;
}

#teacher-week-grid {
  flex: 1;
  overflow: auto;
  background: var(--color-bg);
  position: relative;
  min-height: 0;
}

#teacher-week-inner {
  display: grid;
  grid-template-areas:
    "corner headers"
    "axis   cols";
  grid-template-columns: var(--axis-width) max-content;
  grid-template-rows: var(--header-height) max-content;
}

#teacher-week-corner {
  grid-area: corner;
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

#teacher-week-headers {
  grid-area: headers;
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

#teacher-week-axis {
  grid-area: axis;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  width: var(--axis-width);
}

#teacher-week-cols {
  grid-area: cols;
  display: flex;
}

#teacher-week-allday-row {
  display: flex;
  width: max-content;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
#teacher-week-allday-row:empty { display: none; }
