/* ═══════════════════════════════════════════════════════════════════════════
   BRZ CRM — Calendar Page
   calendar.css  ·  appended to or loaded alongside additions.css
   ═══════════════════════════════════════════════════════════════════════════ */


/* ── Page layout ─────────────────────────────────────────────────────────── */

#page-calendar {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h) - 48px - 56px);  /* full-height minus header, page-header, toolbar */
  min-height: 0;
}

/* Toolbar ------------------------------------------------------------------ */

.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 14px;
  flex-wrap: wrap;
}

.cal-toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.cal-period-label {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -.02em;
  white-space: nowrap;
  margin: 0;
}

/* View pills --------------------------------------------------------------- */

.cal-view-pills {
  display: flex;
  gap: 2px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 3px;
}

.cal-view-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: calc(var(--r-lg) - 2px);
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.cal-view-pill:hover        { color: var(--text-1); background: var(--bg-hover); }
.cal-view-pill.active       { background: var(--bg-card); color: var(--amber); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.cal-view-pill svg          { flex-shrink: 0; }

/* Refresh spin animation */
.spinning svg {
  animation: spin .7s linear infinite;
}


/* ── Canvas wrapper ────────────────────────────────────────────────────────
   The canvas fills the remaining height of the page.                        */

.cal-canvas {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
}


/* ══════════════════════════════════════════════════════════════════════════
   MONTH VIEW
   ══════════════════════════════════════════════════════════════════════════ */

.cal-canvas--month {
  overflow-y: auto;
}

/* Day-of-week header */
.cal-month-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}
.cal-month-dow {
  padding: 8px 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-3);
  text-align: center;
}

/* 6-week grid */
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, minmax(100px, 1fr));
  flex: 1;
}

.cal-month-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  cursor: pointer;
  transition: background .12s;
  overflow: hidden;
  min-height: 100px;
}
.cal-month-cell:nth-child(7n) { border-right: none; }
.cal-month-cell:nth-last-child(-n+7) { border-bottom: none; }
.cal-month-cell:hover { background: var(--bg-hover); }
.cal-month-cell--other { background: rgba(0,0,0,.04); }
.cal-month-cell--other .cal-month-date { color: var(--text-3); }
.cal-month-cell--today { background: rgba(245,158,11,.04); }

.cal-month-date {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 4px;
  text-align: right;
  line-height: 1;
}
.cal-month-cell--today .cal-month-date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  float: right;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--amber);
  color: #000;
  font-weight: 700;
  font-size: 11px;
}

/* Event pills in month cells */
.cal-event-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  font-size: 11px;
  margin-bottom: 2px;
  cursor: pointer;
  overflow: hidden;
  transition: filter .12s;
  white-space: nowrap;
}
.cal-event-pill:hover { filter: brightness(1.15); }
.cal-event-pill--done { opacity: .5; text-decoration: line-through; }

.cal-pill-icon  { font-size: 10px; flex-shrink: 0; }
.cal-pill-title { overflow: hidden; text-overflow: ellipsis; color: var(--text-1); font-size: 11px; }

.cal-more-link {
  font-size: 10px;
  color: var(--amber);
  cursor: pointer;
  padding: 1px 6px;
  border-radius: var(--r-xs);
  transition: background .12s;
}
.cal-more-link:hover { background: var(--amber-dim); }


/* ══════════════════════════════════════════════════════════════════════════
   WEEK / DAY VIEW  —  shared time-grid styles
   ══════════════════════════════════════════════════════════════════════════ */

.cal-time-grid {
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-rows: 48px 1fr;
  grid-template-areas:
    "corner  headers"
    "gutter  body";
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.cal-time-corner { grid-area: corner; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }

/* Day column headers */
.cal-time-day-headers {
  grid-area: headers;
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.cal-time-day-header {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  gap: 2px;
}
.cal-time-day-header:last-child { border-right: none; }
.cal-time-day-header:hover { background: var(--bg-hover); }
.cal-time-day-header--today { background: rgba(245,158,11,.06); }

.cal-dow {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.cal-date-num {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-2);
  line-height: 1;
}
.cal-today-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--amber);
  color: #000;
  font-weight: 700;
}
.cal-month-chip {
  font-size: 10px;
  color: var(--text-3);
}

/* Hour gutter */
.cal-time-gutter {
  grid-area: gutter;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: none;
}
.cal-time-gutter::-webkit-scrollbar { display: none; }

.cal-gutter-hour {
  flex-shrink: 0;
  height: 56px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 2px 6px 0 0;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-3);
  border-bottom: 1px solid transparent;
}
.cal-gutter-hour:first-child { color: transparent; } /* hide 12 AM label */

/* Scrollable body */
.cal-time-body {
  grid-area: body;
  display: flex;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

/* Day columns */
.cal-time-col {
  flex: 1;
  position: relative;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.cal-time-col:last-child { border-right: none; }
.cal-time-col--today { background: rgba(245,158,11,.02); }

/* Hour slots (visual separators) */
.cal-hour-slot {
  height: 56px;
  border-bottom: 1px solid var(--border);
  border-top: none;
}

/* Timed event blocks */
.cal-timed-block {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: var(--r-sm);
  padding: 3px 6px;
  cursor: pointer;
  overflow: hidden;
  font-size: 11px;
  transition: filter .12s, box-shadow .12s;
  min-height: 20px;
  z-index: 2;
}
.cal-timed-block:hover {
  filter: brightness(1.2);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  z-index: 3;
}
.cal-timed-title {
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.cal-timed-time {
  font-size: 10px;
  color: var(--text-2);
  font-family: var(--font-mono);
}

/* "Now" line */
.cal-now-line {
  position: absolute;
  height: 2px;
  background: var(--rose);
  z-index: 10;
  pointer-events: none;
}
.cal-now-line::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rose);
}


/* ══════════════════════════════════════════════════════════════════════════
   TIMELINE VIEW
   ══════════════════════════════════════════════════════════════════════════ */

.cal-canvas--timeline {
  overflow-y: auto;
}

.cal-timeline-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: auto;
}

/* Header row */
.cal-tl-header {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cal-tl-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  flex: 1;
}
.cal-tl-day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  border-right: 1px solid var(--border);
  font-size: 11px;
  gap: 2px;
}
.cal-tl-day-cell:last-child { border-right: none; }
.cal-tl-day-cell span:first-child { color: var(--text-3); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.cal-tl-day-cell--today { background: rgba(245,158,11,.06); }
.cal-tl-day-num { font-family: var(--font-mono); font-size: 14px; font-weight: 600; color: var(--text-2); }

/* Lane label column */
.cal-tl-lane-label {
  width: 130px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-right: 1px solid var(--border);
}
.cal-tl-lane-icon  { font-size: 15px; }
.cal-tl-lane-name  { font-size: 12px; font-weight: 600; color: var(--text-1); flex: 1; }
.cal-tl-lane-count { font-size: 10px; color: var(--text-2); font-family: var(--font-mono); }

/* Body */
.cal-tl-body { flex: 1; overflow-y: auto; }

.cal-tl-lane {
  display: flex;
  border-bottom: 1px solid var(--border);
  min-height: 58px;
}
.cal-tl-lane:last-child { border-bottom: none; }
.cal-tl-lane .cal-tl-lane-label {
  height: auto;
  min-height: 58px;
  background: var(--bg-raised);
  position: sticky;
  left: 0;
  z-index: 5;
}

/* Track */
.cal-tl-track {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 58px;
}
.cal-tl-col-div {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
  pointer-events: none;
}
.cal-tl-today-col {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(245,158,11,.05);
  pointer-events: none;
}

/* Event bars on the timeline */
.cal-tl-event {
  position: absolute;
  top: 8px;
  height: calc(100% - 16px);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  cursor: pointer;
  overflow: hidden;
  transition: filter .12s, box-shadow .12s;
  min-width: 40px;
}
.cal-tl-event:hover {
  filter: brightness(1.2);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  z-index: 3;
}
.cal-tl-event-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.cal-tl-event-time {
  font-size: 10px;
  color: var(--text-2);
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}


/* ══════════════════════════════════════════════════════════════════════════
   AGENDA VIEW
   ══════════════════════════════════════════════════════════════════════════ */

.cal-canvas--agenda {
  overflow-y: auto;
}

.cal-agenda {
  padding: 0;
}

/* Date group header */
.cal-agenda-date-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 20px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.cal-agenda-date-header--past .cal-agenda-date-label { color: var(--text-3); }
.cal-agenda-date-label {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--amber);
}
.cal-agenda-date-sub {
  font-size: 12px;
  color: var(--text-2);
}
.cal-agenda-date-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font-mono);
}

/* Agenda items container */
.cal-agenda-items {
  padding: 6px 16px 6px;
}

/* Individual agenda item */
.cal-agenda-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background .12s;
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.cal-agenda-item:hover { background: var(--bg-hover); border-color: var(--border); }
.cal-agenda-item:focus { outline: 2px solid var(--amber); outline-offset: 2px; }
.cal-agenda-item--done { opacity: .55; }
.cal-agenda-item--overdue { background: rgba(244,63,94,.04); }
.cal-agenda-item--overdue:hover { background: rgba(244,63,94,.08); }

.cal-agenda-type-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.cal-agenda-item-body {
  flex: 1;
  min-width: 0;
}
.cal-agenda-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.cal-agenda-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
}
.cal-agenda-item-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-2);
  margin-top: 3px;
  flex-wrap: wrap;
}
.cal-agenda-dot { color: var(--text-3); }
.cal-agenda-item-desc {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 4px;
  line-height: 1.4;
}

.cal-agenda-item-time {
  text-align: right;
  flex-shrink: 0;
}
.cal-agenda-time-main {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-1);
}
.cal-agenda-time-dur {
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--font-mono);
  margin-top: 2px;
}


/* ══════════════════════════════════════════════════════════════════════════
   DETAIL MODAL
   ══════════════════════════════════════════════════════════════════════════ */

.cal-detail-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 20px;
}
.cal-detail-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.cal-detail-row:last-child { border-bottom: none; }
.cal-detail-row--col { flex-direction: column; align-items: flex-start; gap: 6px; }
.cal-detail-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  width: 80px;
  flex-shrink: 0;
}
.cal-detail-value {
  font-size: 13px;
  color: var(--text-1);
}
.cal-detail-desc {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  background: var(--bg-elevated);
  padding: 8px 12px;
  border-radius: var(--r);
  width: 100%;
}
.cal-detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}


/* ══════════════════════════════════════════════════════════════════════════
   POPOVER (month view "more" overlay)
   ══════════════════════════════════════════════════════════════════════════ */

.cal-popover {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: 230px;
  overflow: hidden;
  animation: dropdown-in .15s var(--ease) both;
}
.cal-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
}
.cal-popover-close {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: color .12s;
}
.cal-popover-close:hover { color: var(--text-1); }
.cal-popover-body { padding: 6px 0; max-height: 240px; overflow-y: auto; }
.cal-popover-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 12px;
  transition: background .12s;
}
.cal-popover-item:hover { background: var(--bg-hover); }
.cal-popover-item span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-1); }


/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .cal-period-label { font-size: 14px; }
  .cal-view-pill span { display: none; }
  .cal-view-pill { padding: 5px 8px; }

  .cal-tl-lane-label { width: 90px; }
  .cal-tl-lane-name  { display: none; }
}

@media (max-width: 768px) {
  #page-calendar { height: auto; min-height: 0; }
  .cal-canvas { height: 70vh; min-height: 400px; }

  .cal-toolbar { gap: 8px; }
  .cal-period-label { font-size: 13px; }

  /* Month: reduce cell min-height */
  .cal-month-grid { grid-template-rows: repeat(6, minmax(72px, 1fr)); }
  .cal-month-cell { min-height: 72px; padding: 4px; }
  .cal-event-pill { font-size: 10px; padding: 1px 4px; }
  .cal-month-dow  { font-size: 9.5px; padding: 6px 4px; }

  /* Time grid: narrower gutter */
  .cal-time-grid { grid-template-columns: 40px 1fr; }
  .cal-gutter-hour { font-size: 9px; padding: 2px 3px 0; }
  .cal-timed-title { font-size: 10px; }
  .cal-timed-time  { display: none; }

  /* Agenda */
  .cal-agenda-date-header { padding: 10px 14px 6px; }
  .cal-agenda-items       { padding: 4px 10px; }

  /* Timeline */
  .cal-tl-lane-label { width: 70px; }
  .cal-tl-event-time { display: none; }
}

@media (max-width: 480px) {
  .cal-view-pills { gap: 1px; padding: 2px; }
  .cal-view-pill  { padding: 4px 6px; }
  .cal-month-grid { grid-template-rows: repeat(6, minmax(56px, 1fr)); }
  .cal-month-cell { min-height: 56px; padding: 3px; }
  .cal-month-date { font-size: 11px; }
  .cal-dow        { font-size: 9px; }
  .cal-date-num   { font-size: 14px; }
}