/* calendar.css — month/week calendar view inside a project.
   Sits next to Kanban / Table tabs. Reuses the same design tokens
   (colors, radii, spacing) as the rest of the app. */

/* Outer wrapper — fills the project content pane */
.cal-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  align-items: stretch;
  padding: 0 14px 14px;
  min-height: calc(100vh - 200px);
}
@media (max-width: 1100px) {
  .cal-wrap { grid-template-columns: minmax(0, 1fr); }
  .cal-rail { order: 2; }
}

/* Main calendar surface */
.cal-main {
  background: var(--card, #fff);
  border: 1px solid var(--bd, #e6e9ef);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Header bar inside the calendar — month title on the left, control
   cluster on the right. Two flex children, space-between layout. */
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--bd, #e6e9ef);
  flex-wrap: wrap;
}
.cal-head-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-head-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cal-title { font-size: 18px; font-weight: 700; color: #0f1729; letter-spacing: -.01em; line-height: 1.15; }
.cal-sub   { font-size: 12px; color: var(--ink-muted, #676879); line-height: 1.2; }

.cal-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #f3f4f7;
  border: 1px solid var(--bd, #e6e9ef);
  border-radius: 10px;
  padding: 2px;
  height: 32px;
  box-sizing: border-box;
}
.cal-nav-btn {
  appearance: none;
  background: transparent;
  border: 0;
  color: #0f1729;
  width: 26px; height: 26px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 14px; font-weight: 700;
  transition: background .12s ease;
}
.cal-nav-btn:hover { background: #fff; }
.cal-today-btn {
  appearance: none;
  background: #fff;
  border: 1px solid var(--bd, #e6e9ef);
  color: #0f1729;
  font-size: 12px; font-weight: 600;
  height: 32px;
  padding: 0 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
  display: inline-flex; align-items: center; gap: 4px;
  box-sizing: border-box;
}
.cal-today-btn:hover { background: #f3f4f7; border-color: #d6dae3; }

/* Month / Week toggle */
.cal-modes {
  display: inline-flex;
  background: #f3f4f7;
  border: 1px solid var(--bd, #e6e9ef);
  border-radius: 10px;
  padding: 2px;
  height: 32px;
  box-sizing: border-box;
}
.cal-mode {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--ink-muted, #676879);
  font-size: 12px; font-weight: 600;
  height: 100%;
  padding: 0 12px;
  border-radius: 8px;
  cursor: pointer;
}
.cal-mode.is-active { background: #fff; color: #0f1729; box-shadow: 0 1px 2px rgba(15,23,41,.06); }

/* Day-of-week strip above the grid */
.cal-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--bd, #e6e9ef);
  background: #fbfcfd;
}
.cal-dow > div {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted, #676879);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 8px 10px;
}
.cal-dow > div.is-weekend { color: #a3a8b3; }

/* Month grid */
.cal-grid {
  display: grid;
  /* `minmax(0, 1fr)` instead of plain `1fr` — without it, grid items
     default to `min-width: auto`, which lets a long task title push
     its cell wider than the column and break the alignment. */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(110px, 1fr);
  flex: 1;
  background: var(--bd, #e6e9ef);
  gap: 1px;
}
.cal-cell {
  background: #fff;
  position: relative;
  padding: 6px 8px 30px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  transition: background .12s ease;
  min-height: 110px;
  /* Belt-and-braces: never let cell content overflow the column. */
  min-width: 0;
  overflow: hidden;
}
.cal-cell:hover { background: #fafbfd; }
.cal-cell.is-other-month { background: #f7f8fa; }
.cal-cell.is-other-month .cal-date { color: #c9ccd4; }
.cal-cell.is-weekend { background: #fbfcfd; }
.cal-cell.is-other-month.is-weekend { background: #f4f5f8; }
.cal-cell.is-past .cal-date { color: #a3a8b3; }
.cal-cell.is-today {
  background: #fff8e6;
  box-shadow: inset 0 0 0 1px #f1c40f;
}
.cal-cell.is-today .cal-date {
  color: #0f1729;
  background: #f1c40f;
  color: #4d3a00;
  border-radius: 6px;
  padding: 1px 6px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
}
.cal-cell.is-drop-target {
  background: #eaf3ff;
  box-shadow: inset 0 0 0 2px #2563eb;
}

.cal-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink, #0f1729);
  margin-bottom: 2px;
}
.cal-add {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: rgba(15,23,41,.06);
  border: 0;
  color: var(--ink-muted, #676879);
  font-size: 12px;
  line-height: 16px;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease, background .12s ease;
}
.cal-cell:hover .cal-add { opacity: 1; }
.cal-add:hover { background: rgba(15,23,41,.12); color: #0f1729; }

/* Footer "more" line for cells with overflow */
.cal-more {
  position: absolute;
  left: 8px;
  bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #2563eb;
  cursor: pointer;
}
.cal-more:hover { text-decoration: underline; }

/* Event chip — single task on a day */
.cal-event {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 3px 4px;
  border-radius: 5px;
  background: #f3f4f7;
  font-size: 11.5px;
  font-weight: 500;
  color: #0f1729;
  border-left: 3px solid #888;
  cursor: grab;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: transform .08s ease, opacity .12s ease, box-shadow .12s ease;
}
.cal-event:hover { box-shadow: 0 1px 4px rgba(15,23,41,.10); transform: translateY(-1px); }
.cal-event:active { cursor: grabbing; }
.cal-event.is-dragging { opacity: .35; }

/* Priority side-stripe colors — match table.css priority pills */
.cal-event.prio-critical { border-left-color: #d83a52; background: #fdebee; color: #6a1422; }
.cal-event.prio-high     { border-left-color: #f0883e; background: #fdf1e3; color: #6f3a0c; }
.cal-event.prio-medium   { border-left-color: #2f6df3; background: #e8f0ff; color: #11306f; }
.cal-event.prio-low      { border-left-color: #00a884; background: #e3f6f0; color: #0a4a3c; }
.cal-event.prio-none     { border-left-color: #b3b8c2; background: #f3f4f7; color: #4d525c; }

/* Status overrides */
.cal-event.is-done {
  opacity: .55;
}
.cal-event.is-done .cal-event-title { text-decoration: line-through; }
.cal-event.is-overdue { box-shadow: inset 0 0 0 1px rgba(216,58,82,.45); }

.cal-event-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event-time {
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-muted, #676879);
  flex-shrink: 0;
}
.cal-event-avatar {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #b3b8c2;
  color: #fff;
  font-size: 8px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cal-event-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Side rail (unscheduled + overdue) */
.cal-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.cal-rail-card {
  background: var(--card, #fff);
  border: 1px solid var(--bd, #e6e9ef);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
}
.cal-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--bd, #e6e9ef);
}
.cal-rail-title {
  font-size: 13px;
  font-weight: 700;
  color: #0f1729;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cal-rail-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted, #676879);
  background: #f3f4f7;
  border-radius: 999px;
  padding: 1px 8px;
}
.cal-rail-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.cal-rail-empty {
  font-size: 12px;
  color: var(--ink-muted, #676879);
  font-style: italic;
  padding: 12px 4px;
  text-align: center;
}

/* Compact event chip for the rail */
.cal-rail-event {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 6px;
  border-radius: 8px;
  background: #fbfcfd;
  border: 1px solid var(--bd, #e6e9ef);
  border-left: 3px solid #b3b8c2;
  font-size: 12px;
  font-weight: 500;
  color: #0f1729;
  cursor: grab;
  user-select: none;
  transition: background .12s ease, transform .08s ease;
}
.cal-rail-event:hover { background: #fff; transform: translateY(-1px); }
.cal-rail-event:active { cursor: grabbing; }
.cal-rail-event.prio-critical { border-left-color: #d83a52; }
.cal-rail-event.prio-high     { border-left-color: #f0883e; }
.cal-rail-event.prio-medium   { border-left-color: #2f6df3; }
.cal-rail-event.prio-low      { border-left-color: #00a884; }
.cal-rail-event-meta {
  font-size: 10px;
  color: var(--ink-muted, #676879);
  margin-left: auto;
  flex-shrink: 0;
}

/* Empty state when the project has no tasks at all */
.cal-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  color: var(--ink-muted, #676879);
  font-size: 13px;
  z-index: 0;
}

/* Week view — replaces grid with a 7-column day-strip */
.cal-week {
  display: grid;
  grid-template-columns: 64px repeat(7, 1fr);
  flex: 1;
  background: var(--bd, #e6e9ef);
  gap: 1px;
}
.cal-week-hour {
  background: #fbfcfd;
  font-size: 10px;
  color: var(--ink-muted, #676879);
  padding: 4px 6px;
  border-bottom: 1px solid #eef0f4;
  text-align: right;
}
.cal-week-col {
  background: #fff;
  position: relative;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 100%;
}
.cal-week-col.is-today { background: #fff8e6; }
.cal-week-col.is-drop-target {
  background: #eaf3ff;
  box-shadow: inset 0 0 0 2px #2563eb;
}
.cal-week-day-header {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted, #676879);
  padding: 8px 4px;
  background: #fbfcfd;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cal-week-day-header .num {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: #0f1729;
  margin-top: 2px;
}
.cal-week-day-header.is-today .num {
  background: #f1c40f;
  color: #4d3a00;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

/* Drag ghost when dragging a chip across cells */
.cal-event[draggable="true"] { -webkit-user-drag: element; }

/* Quick-add popover (re-uses existing .popover system) */
.cal-quick {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  width: 280px;
}
.cal-quick-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted, #676879);
}
.cal-quick-input {
  appearance: none;
  border: 1px solid var(--bd, #e6e9ef);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.cal-quick-input:focus {
  border-color: #2f6df3;
  box-shadow: 0 0 0 3px rgba(47,109,243,.15);
}
.cal-quick-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}
.cal-quick-btn {
  appearance: none;
  background: #fff;
  border: 1px solid var(--bd, #e6e9ef);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}
.cal-quick-btn.is-primary {
  background: #0f1729;
  border-color: #0f1729;
  color: #fff;
}
.cal-quick-btn:disabled { opacity: .5; cursor: not-allowed; }
