/* =====================================================================
   Miftah — Calendar grids
   One scroller carries both axes; the day headers and the hour gutter
   stick to its edges, so they stay with their columns at every width.
   ===================================================================== */

.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.cal-nav {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface);
}
.cal-nav .icon-btn { border: none; border-radius: 0; height: 30px; width: 30px; }
.cal-nav .icon-btn + .icon-btn { border-inline-start: 1px solid var(--border); }
.cal-range { font-size: 13px; white-space: nowrap; }

/* --- Frame ------------------------------------------------------------- */
.cal {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.cal-scroll {
  overflow: auto;
  max-height: min(66vh, 620px);
  overscroll-behavior: contain;
}
.cal-inner { position: relative; }

/* --- Header row -------------------------------------------------------- */
.cal-head {
  position: sticky;
  top: 0;
  z-index: 7;
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.cal-head-gutter {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  border-inline-end: 1px solid var(--border);
  background: var(--surface-2);
}
.cal-head-cols { display: grid; grid-template-columns: var(--cols); }
.cal-head-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 6px;
  border-inline-start: 1px solid var(--border);
  min-width: 0;
}
.cal-head-day:first-child { border-inline-start: none; }
.cal-dow {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: capitalize;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.cal-date { font-size: 15px; font-weight: 600; line-height: 1.3; }
.cal-role {
  font-size: 10.5px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.cal-head-day.is-weekend .cal-dow,
.cal-head-day.is-weekend .cal-date { color: var(--ink-3); }
.cal-head-day.is-today .cal-date {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
  padding: 0 6px;
}
.cal-head-day.is-orphan .cal-dow { color: var(--ink-3); font-style: italic; }

/* --- Body -------------------------------------------------------------- */
.cal-body {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
}
.cal-gutter {
  position: sticky;
  inset-inline-start: 0;
  z-index: 6;
  border-inline-end: 1px solid var(--border);
  background: var(--surface-2);
}
.cal-hour {
  position: absolute;
  inset-inline-end: 8px;
  font-size: 10.5px;
  line-height: 1;
  color: var(--ink-3);
  white-space: nowrap;
}
.cal-grid {
  position: relative;
  display: grid;
  grid-template-columns: var(--cols);
}

.cal-col {
  position: relative;
  border-inline-start: 1px solid var(--border);
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
  /* hour rules, then a lighter half-hour rule between them */
  background-image:
    repeating-linear-gradient(to bottom,
      var(--border) 0, var(--border) 1px, transparent 1px, transparent var(--hour)),
    repeating-linear-gradient(to bottom,
      transparent 0, transparent var(--half),
      color-mix(in srgb, var(--grid) 70%, transparent) var(--half),
      color-mix(in srgb, var(--grid) 70%, transparent) calc(var(--half) + 1px),
      transparent calc(var(--half) + 1px), transparent var(--hour));
}
.cal-col:first-child { border-inline-start: none; }
.cal-col.is-weekend { background-color: var(--surface-2); }
.cal-col.is-today { background-color: color-mix(in srgb, var(--info-mark) 5%, transparent); }
.cal-col.is-orphan { background-color: var(--surface-3); }
.cal-col.is-drop { background-color: color-mix(in srgb, var(--accent) 6%, transparent); }

/* --- Clickable empty slots (30 minutes each) --------------------------- */
.cal-slots { position: absolute; inset: 0; z-index: 0; }
.cal-slot {
  position: absolute;
  inset-inline: 0;
  border: none;
  background: transparent;
  transition: background var(--t-fast) var(--ease);
}
.cal-slot:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.cal-slot:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.cal-grid.is-busy .cal-slot { pointer-events: none; }
.cal-grid.is-busy .cal-slot:hover { background: transparent; }

/* --- Event blocks ------------------------------------------------------- */
.cal-event {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  text-align: start;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
  transition: box-shadow var(--t-fast) var(--ease);
}
.cal-event:hover { box-shadow: var(--shadow-pop); z-index: 4; }
.cal-event:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; z-index: 4; }
.cal-event.tone-good { border-inline-start-color: var(--good-mark); }
.cal-event.tone-warn { border-inline-start-color: var(--warn-mark); }
.cal-event.tone-info { border-inline-start-color: var(--info-mark); }
.cal-event.tone-mute { border-inline-start-color: var(--border-strong); opacity: .66; }
.cal-event.is-appt {
  background: var(--surface-2);
  border-style: dashed;
  border-inline-start-style: solid;
}

.cal-event-time {
  font-size: 10px;
  line-height: 1.2;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.cal-event-title {
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-event-sub {
  font-size: 10.5px;
  line-height: 1.25;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A short block puts the clock and the name on one line instead of
   stacking two rows into a space that cannot hold them. */
.cal-event.is-dense {
  flex-direction: row;
  align-items: baseline;
  gap: 5px;
  padding-block: 2px;
}
.cal-event.is-dense .cal-event-time { flex: none; }
.cal-event.is-dense .cal-event-title { min-width: 0; font-weight: 500; }

/* --- Drag ------------------------------------------------------------- */
.cal-grip {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 7px;
  cursor: ns-resize;
  touch-action: none;
}
.cal-grip::after {
  content: "";
  position: absolute;
  inset-inline: 38%;
  bottom: 2px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink-3);
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease);
}
.cal-event:hover .cal-grip::after,
.cal-band:hover .cal-grip::after { opacity: .45; }

.cal-event.is-grabbed, .cal-band.is-grabbed { cursor: grabbing; }
.cal-event.is-dragging, .cal-band.is-dragging {
  z-index: 5;
  box-shadow: var(--shadow-pop);
  opacity: .93;
  cursor: grabbing;
}
.cal-grid.is-busy .cal-event:not(.is-dragging),
.cal-grid.is-busy .cal-band:not(.is-dragging) { opacity: .5; }

/* --- Day view: the agency is at the notary, across every column -------- */
.cal-band {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  padding: 4px 8px;
  border: 1px dashed var(--info-mark);
  border-inline-start: 3px solid var(--info-mark);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--info-mark) 10%, var(--surface));
  cursor: grab;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cal-band:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.cal-band-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11px;
  line-height: 1.3;
  min-width: 0;
}
.cal-band-label .mono { font-size: 10px; color: var(--ink-2); flex: none; }
.cal-band-name { font-weight: 600; }
.cal-band-label .dim { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Now ---------------------------------------------------------------- */
.cal-now {
  position: absolute;
  inset-inline: 0;
  z-index: 3;
  height: 0;
  border-top: 1.5px solid var(--crit-mark);
  pointer-events: none;
}
.cal-now::before {
  content: "";
  position: absolute;
  inset-inline-start: -3px;
  top: -4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--crit-mark);
}

/* --- Footer ------------------------------------------------------------- */
.cal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.cal-hint { font-size: 11.5px; color: var(--ink-3); }

@media (max-width: 620px) {
  .cal-toolbar { gap: 8px; }
  .cal-range { width: 100%; order: 3; }
  .cal-scroll { max-height: 60vh; }
}

@media (prefers-reduced-motion: reduce) {
  .cal-slot, .cal-event, .cal-grip::after { transition: none; }
}
