/* Calendar — month-grid mode for the calendar view (timeline mode keeps the
   old .cal-* rules in css/timeline.css). Token-driven throughout, so light and
   dark both come from the css/base.css tokens; the per-kind chip colors are
   the --status-* tokens, which flip with the theme on their own. */

/* ---- toolbar (mode toggle) + header (month nav + label) ---- */
.calgrid-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.calgrid-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}
.calgrid-label {
  font-size: var(--fs-body);
  font-weight: 700;
  white-space: nowrap;
}

/* ---- month grid: 7 columns, 1px border-colored gaps ---- */
.calgrid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
/* Type, case and colour come from the shared eyebrow rule in css/base.css. */
.calgrid-dow {
  background: var(--surface);
  padding: var(--sp-1);
  text-align: center;
}

/* ---- day cells ---- */
.calgrid-day {
  display: block;
  min-height: 92px;
  padding: var(--sp-1);
  background: var(--surface);
  border: 0;
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.calgrid-day:hover { background: var(--surface-2); }
.calgrid-num {
  display: block;
  text-align: right;
  font-size: var(--fs-2xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  margin-bottom: var(--sp-0);
}
.calgrid-out .calgrid-num { opacity: 0.45; }
.calgrid-out .calgrid-ev { opacity: 0.55; }
.calgrid-today { box-shadow: inset 0 0 0 1px var(--accent); }
.calgrid-today .calgrid-num { color: var(--accent); font-weight: 700; }
.calgrid-sel { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---- event chips: tinted background + left color bar per kind ---- */
.calgrid-ev {
  display: block;
  width: 100%;
  margin-top: var(--sp-0);
  padding: 1px var(--sp-1);
  border: 0;
  border-left: 3px solid var(--ev-strong);
  border-radius: var(--radius);
  background: var(--ev-soft);
  color: var(--ev-strong);
  font: inherit;
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: var(--lh);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
/* Chip internals: the left bar carries the color on desktop, so the dot span
   stays hidden; the title span does the single-line truncation. */
.calgrid-ev-dot { display: none; }
.calgrid-ev-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-homework { --ev-strong: var(--accent); --ev-soft: var(--accent-soft); }
.ev-test,
.ev-exam { --ev-strong: var(--status-bad-fg); --ev-soft: var(--status-bad-bg); }
.ev-quiz { --ev-strong: var(--status-warn-fg); --ev-soft: var(--status-warn-bg); }
.ev-project,
.ev-fair { --ev-strong: var(--status-info-fg); --ev-soft: var(--status-info-bg); }
.ev-other { --ev-strong: var(--status-ok-fg); --ev-soft: var(--status-ok-bg); }
.ev-study { --ev-strong: var(--accent); --ev-soft: var(--accent-soft); }
.ev-review { --ev-strong: var(--status-warn-fg); --ev-soft: var(--status-warn-bg); }

/* ---- .badge-purple (restored) — calendar.js puts it on project/fair badges
   but the styles.css rewrite never defined it. Same palette as the chips. */
.badge-purple { background: var(--status-info-bg); color: var(--status-info-fg); }

/* ---- "+N more" toggle ---- */
.calgrid-more {
  display: block;
  margin-top: var(--sp-0);
  padding: 1px var(--sp-1);
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--fs-2xs);
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  cursor: pointer;
}
.calgrid-more:hover { color: var(--accent); }

/* ---- day panel under the grid (rows reuse the timeline itemRow styles;
   title/empty text reuse .section-title / .item-meta from css/base.css) ---- */
.calgrid-panel { margin-top: var(--sp-4); }

/* ---- "new/edit event" modal form (chrome itself is the shared
   .modal-backdrop/.modal-card/.modal-head from css/base.css) ---- */
.cal-event-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.cal-event-form-row {
  display: flex;
  gap: var(--sp-3);
}
.cal-event-form-row > * { flex: 1; }
.cal-event-form input,
.cal-event-form select,
.cal-event-form textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.cal-event-form input[type="text"],
.cal-event-form textarea {
  width: 100%;
}
.cal-event-form textarea { resize: vertical; }

/* ---- small screens: shrink cells, collapse chips to color pips ---- */
@media (max-width: 760px) {
  /* 2px sides keep "+N more" on one line at 11px in a 50px cell. */
  .calgrid-day { min-height: 56px; padding: var(--sp-1) var(--sp-0); }
  /* A 24px hit area around the 7px pip, which the dot span now draws. */
  .calgrid-ev {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: none;
    font-size: 0;
    color: transparent;
  }
  .calgrid-ev .calgrid-ev-dot {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: var(--radius);
    background: var(--ev-strong);
  }
  .calgrid-ev-title { display: none; }
  .calgrid-more { padding: 0; font-size: var(--fs-2xs); }
}

/* Layout fixes (issue #16 item 4)
   Beside the sidebar (761-1000px) the day cells are almost as narrow as on a
   phone and chip titles were cut to about 40px, so the page column's own
   width switches to colour pips like the phone rule above. Each pip keeps a
   24px target (the chip it replaces was 17px tall), with the 7px dot span
   drawn in its middle. Phones (760px and below) keep the rule above. */
@media (min-width: 761px) {
  @container main (max-width: 699px) {
    .calgrid-day { min-height: 56px; padding: var(--sp-1); }
    .calgrid-ev {
      display: inline-block;
      width: 24px;
      height: 24px;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: var(--radius);
      background: none;
      font-size: 0;
      color: transparent;
      vertical-align: top;
    }
    /* The dot is the event's own .calgrid-ev-dot span, as on phones. */
    .calgrid-ev .calgrid-ev-dot {
      display: block;
      width: 7px;
      height: 7px;
      margin: 8.5px auto 0;
      border-radius: var(--radius);
      background: var(--ev-strong);
    }
    .calgrid-ev:hover { background: var(--surface-2); }
    .calgrid-ev-title { display: none; }
    .calgrid-more { padding: 0 var(--sp-0); min-height: 24px; }
  }
}
