/*
 * KPRATIVE Mini App v1.1 — Calendar Month / Day (TASK 5/N).
 * Geometry from get_design_context on Calendar Month RU Light (263:2076),
 * Calendar Day RU Light (263:2124), CalendarDateCell (257:1057, all 7
 * variants), CalendarTimeGrid (244:1029), CalendarEventBlock (243:1059),
 * CalendarOverlapGroup (245:1029), CalendarConnectionState (229:1105),
 * CalendarEmptyState (229:1088). Colors exclusively via tokens.css.
 */

.kp-calendar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
}

/* Shared outer card (Month 263:2076 / Day 263:2124 both use this exact
   bordered-surface-rounded-26 container). */
.kp-cal-card {
  box-sizing: border-box;
  width: 100%;
  background: var(--kp-surface);
  border: 1px solid var(--kp-border-subtle);
  border-radius: 26px;
  padding: 16px 15px;
  overflow: hidden;
}

/* ---- Connection banner (229:1105) -- read-only status (dot + title +
   body). TASK 6/N temporarily added action buttons here (DR-305); TASK
   8/N retired that bridge now that Settings is the connection's real,
   permanent home (matches Figma's own NotConnected copy and proven
   production architecture) -- see calendar.js's own comment at
   connectionBannerHtml(). Regardless of which sub-view (Month/Day) is
   open. ---- */
.kp-cal-connection {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  background: var(--kp-surface-raised);
}
/* Dot aligns with the TITLE line (flex-start), not centered against the
   full two-line title+body block -- matches the real Figma reference
   render (229:1105) where the status dot sits level with the title,
   not floating between the two lines (found during Task 6/N's own
   screenshot review; DR-306). */
.kp-cal-connection__row { display: flex; align-items: flex-start; gap: 12px; padding-top: 3px; }
.kp-cal-connection__dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.kp-cal-connection__dot--ok { background: var(--kp-success); }
.kp-cal-connection__dot--warn { background: var(--kp-warning); }
.kp-cal-connection__body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kp-cal-connection__title { margin: 0; color: var(--kp-text-primary); font-family: "Manrope", Arial, sans-serif; font-weight: 600; font-size: 14px; }
.kp-cal-connection__text { margin: 0; color: var(--kp-text-secondary); font-family: "Manrope", Arial, sans-serif; font-size: 12px; }
/* ---- The action/redirect/error classes below are no longer used by
   Calendar itself (see above) but are kept here and reused verbatim by
   settings.js/settings.css -- Settings' OAuth actions are the exact
   same visual language as this banner always was, and duplicating
   near-identical rules under a new namespace would be exactly the kind
   of per-screen clone the guide's component-reuse rule forbids. ---- */
.kp-cal-connection__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.kp-cal-connection__action {
  border: 1px solid var(--kp-border-subtle);
  border-radius: 12px;
  padding: 8px 14px;
  background: var(--kp-surface);
  color: var(--kp-text-primary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.kp-cal-connection__action--primary { background: var(--kp-accent-primary); border-color: var(--kp-accent-primary); color: var(--kp-background); }
.kp-cal-connection__action[aria-busy="true"] { opacity: 0.6; }
.kp-cal-connection__redirect { margin: 0; color: var(--kp-success); font-size: 12px; }
.kp-cal-connection__redirect.is-error { color: var(--kp-recovery); }
.kp-cal-connection__error { margin: 0; color: var(--kp-recovery); font-size: 12px; }

/* ---- Pending Calendar actions (TASK 6/N) -- rendered above the
   Month/Day card, hidden entirely when empty. No dedicated Figma node;
   quiet, token-driven, matching the existing card language. ---- */
.kp-cal-pending__title { margin: 0 0 8px 0; color: var(--kp-text-secondary); }
.kp-cal-pending__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.kp-cal-pending__item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--kp-surface-raised);
}
.kp-cal-pending__text { margin: 0; color: var(--kp-text-primary); font-family: "Manrope", Arial, sans-serif; font-size: 14px; }
.kp-cal-pending__actions { display: flex; gap: 8px; }
.kp-cal-pending__confirm, .kp-cal-pending__reject {
  border: 1px solid var(--kp-border-subtle);
  border-radius: 12px;
  padding: 6px 14px;
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.kp-cal-pending__confirm { background: var(--kp-accent-primary); border-color: var(--kp-accent-primary); color: var(--kp-background); }
.kp-cal-pending__reject { background: transparent; color: var(--kp-text-secondary); }
.kp-cal-pending__confirm[aria-busy="true"], .kp-cal-pending__reject[aria-busy="true"] { opacity: 0.6; }
.kp-cal-pending__error { margin: 0; color: var(--kp-recovery); font-size: 12px; }

/* ---- Month nav (263:2078) ---- */
.kp-cal-month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}
.kp-cal-month-nav__label {
  margin: 0;
  min-width: 130px;
  text-align: center;
  color: var(--kp-text-primary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 16px;
}
.kp-cal-month-nav__btn {
  flex: none;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--kp-text-primary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.kp-cal-month-nav__btn:active { background: var(--kp-surface-raised); }
.kp-cal-month-nav__btn:focus-visible { outline: 2px solid var(--kp-accent-primary); outline-offset: 1px; }

/* ---- Weekday row + grid (7 columns, fluid width; 257:1057 reference
   is 40x44 at the 342px canonical viewport -- kept fluid here so 320/360
   preserve equal columns per the guide's explicit "preserve the grid"
   instruction). ---- */
.kp-cal-weekdays, .kp-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.kp-cal-weekdays { margin-bottom: 8px; }
.kp-cal-weekday {
  text-align: center;
  color: var(--kp-text-secondary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.kp-cal-datecell {
  position: relative;
  height: 44px;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.kp-cal-datecell__ring {
  position: absolute;
  left: 50%;
  top: 3px;
  transform: translateX(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  box-sizing: border-box;
}
.kp-cal-datecell.is-today .kp-cal-datecell__ring { border: 1px solid var(--kp-border-subtle); }
.kp-cal-datecell.is-selected .kp-cal-datecell__ring { background: var(--kp-surface-raised); }
.kp-cal-datecell__number {
  position: absolute;
  left: 50%;
  top: 9px;
  transform: translateX(-50%);
  margin: 0;
  color: var(--kp-text-secondary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 400;
  font-size: 12px;
  line-height: 16px;
}
.kp-cal-datecell.is-selected .kp-cal-datecell__number { color: var(--kp-text-primary); font-weight: 600; }
.kp-cal-datecell.is-selected.is-today .kp-cal-datecell__number { font-weight: 400; }
.kp-cal-datecell.is-outside .kp-cal-datecell__number { color: var(--kp-text-muted); }
.kp-cal-datecell__dot {
  position: absolute;
  left: 50%;
  top: 34px;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--kp-accent-primary);
}
.kp-cal-datecell:focus-visible { outline: 2px solid var(--kp-accent-primary); outline-offset: 2px; border-radius: 8px; }

/* ---- Selected date context (263:2121) -- taps into Day view. ---- */
.kp-cal-selected {
  width: 100%;
  box-sizing: border-box;
  margin-top: 16px;
  padding: 13px 14px;
  border: 1px solid var(--kp-border-subtle);
  border-radius: 16px;
  background: var(--kp-surface-raised);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.kp-cal-selected:focus-visible { outline: 2px solid var(--kp-accent-primary); outline-offset: 2px; }
.kp-cal-selected__date { margin: 0; color: var(--kp-text-primary); font-family: "Manrope", Arial, sans-serif; font-weight: 600; font-size: 13px; }
.kp-cal-selected__action { margin: 0; color: var(--kp-text-secondary); font-family: "Manrope", Arial, sans-serif; font-size: 11px; }

/* ---- Day view (263:2124) ---- */
.kp-cal-day-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0 0 10px 0;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--kp-text-secondary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.kp-cal-day-back:focus-visible { outline: 2px solid var(--kp-accent-primary); outline-offset: 2px; }
.kp-cal-day-meta {
  margin: 4px 0 14px 0;
  color: var(--kp-text-secondary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 11px;
}

/* ---- TimeGrid (244:1029): 56px per hour, label column 42px. ---- */
.kp-cal-timegrid {
  position: relative;
  width: 100%;
  box-sizing: border-box;
}
.kp-cal-timegrid__hour {
  position: absolute;
  left: 0;
  width: 100%;
  border-top: 1px solid var(--kp-border-subtle);
}
.kp-cal-timegrid__hour-label {
  position: absolute;
  left: 0;
  top: -7px;
  margin: 0;
  color: var(--kp-text-secondary);
  font-family: "Manrope", Arial, sans-serif;
  font-size: 10px;
  line-height: 14px;
  background: var(--kp-surface);
  padding-right: 4px;
}
.kp-cal-timegrid__rail { position: absolute; left: 42px; top: 0; bottom: 0; width: 0; }

/* ---- EventBlock (243:1059) -- Edge style (isolated) vs Tonal style
   (part of an overlapping cluster, per CalendarOverlapGroup 245:1029:
   "Overlapping events split into columns" with a distinct tonal
   treatment and no accent edge). ---- */
.kp-cal-event {
  /* Height is a MIN, set inline from real duration -- never a hard cap
     with overflow:hidden. A short slot with a long real title must grow
     to show it in full (read-only preview; clipping real user data is
     worse than a box extending slightly past its nominal time slot). */
  position: absolute;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  /* V1.1-CALENDAR-EVENT-DETAIL-001: a real <button> now (tap opens the
     event detail sheet) -- reset UA button chrome so it stays visually
     identical to the previous read-only <div>. */
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.kp-cal-event--edge {
  background: var(--kp-surface);
  border: 1px solid var(--kp-border-subtle);
}
.kp-cal-event--edge::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 2px;
  background: var(--kp-accent-primary);
}
.kp-cal-event--tonal {
  background: var(--kp-surface-raised);
  border: 1px solid var(--kp-border-subtle);
}
.kp-cal-event__time {
  margin: 0 0 3px 0;
  color: var(--kp-text-secondary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 10px;
  line-height: 14px;
}
.kp-cal-event__title {
  margin: 0;
  color: var(--kp-text-primary);
  font-family: "Manrope", Arial, sans-serif;
  font-weight: 600;
  font-size: 13px;
  line-height: 17px;
  overflow-wrap: break-word;
  /* A very long real title is truncated with an ellipsis after 2 lines
     rather than growing the box unboundedly -- an unbounded box can
     visually collide with a later, non-overlapping event once it grows
     past its own nominal time slot (real bug found during TASK 5/N
     Design QA, fixed here). Ellipsis is an honest "more text exists"
     signal; nothing is silently dropped without indication. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.kp-cal-event--all-day .kp-cal-event__time { font-style: normal; }

/* ---- Event detail sheet (V1.1-CALENDAR-EVENT-DETAIL-001) ----
   No Figma node models this interior sheet content (same disclosed-gap
   convention as sheet.js's own header note) -- token-consistent label/
   value rows reusing kp-type-ui-label/kp-type-ui-body typography and the
   existing kp-sheet__* structural classes, never a new color/typography
   token. Works unmodified in light/dark since every color below is a
   --kp-* custom property already redefined per theme elsewhere. */
.kp-cal-detail { padding-top: 4px; }
.kp-cal-detail__field { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--kp-border-subtle); }
.kp-cal-detail__field:last-child { border-bottom: none; }
.kp-cal-detail__label { margin: 0; color: var(--kp-text-secondary); }
.kp-cal-detail__value { margin: 0; color: var(--kp-text-primary); overflow-wrap: break-word; white-space: pre-wrap; }

/* ---- Empty / notice / error / loading ---- */
.kp-cal-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  padding: 22px 18px;
  border-radius: 18px;
  background: var(--kp-surface-raised);
}
.kp-cal-empty .kp-icon { color: var(--kp-icon-default); }
.kp-cal-empty__title { margin: 0; color: var(--kp-text-primary); font-family: "Manrope", Arial, sans-serif; font-weight: 600; font-size: 16px; }
.kp-cal-empty__body { margin: 0; color: var(--kp-text-secondary); font-family: "Manrope", Arial, sans-serif; font-size: 13px; line-height: 18px; }

.kp-cal-notice {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--kp-surface-raised);
  color: var(--kp-text-secondary);
  font-size: 12px;
  line-height: 17px;
}
.kp-cal-loading { padding: 14px 0; color: var(--kp-text-secondary); }
.kp-cal-error { padding: 14px 0; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.kp-cal-error__title { margin: 0; color: var(--kp-text-primary); }
.kp-cal-error__detail { margin: 0; color: var(--kp-text-secondary); }
.kp-cal-error__retry {
  border: 1px solid var(--kp-border-subtle);
  border-radius: 12px;
  padding: 8px 16px;
  background: transparent;
  color: var(--kp-text-primary);
  cursor: pointer;
}
