/* ==========================================================================
   KCC Calendar — Schedule View
   Extends the base design system in style.css
   ========================================================================== */

/* ── Calendar month nav (in header) ─────────────────────────────────────────── */

.kcc-cal-month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 16px;
}

.kcc-cal-month-label {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.92); /* header is dark navy, needs light text */
  min-width: 140px;
  text-align: center;
  letter-spacing: -0.01em;
}

.kcc-cal-today-btn {
  font-size: 13px;
}

/* ── Calendar container ──────────────────────────────────────────────────────── */

.kcc-cal-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 16px 16px;
  min-height: 0;
  overflow: auto;
}

/* Day-of-week header row */
.kcc-cal-dow-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  padding: 0 0 4px;
  border-bottom: 1px solid var(--border);
}

.kcc-cal-dow {
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  text-transform: uppercase;
  text-align: center;
}

/* Grid */
.kcc-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(100px, auto);
  gap: 4px;
  flex: 1;
}

.kcc-cal-loading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  font-size: 13px;
  color: var(--text-faint);
}

/* ── Calendar cells ──────────────────────────────────────────────────────────── */

.kcc-cal-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
  overflow: hidden;
  min-height: 100px;
}

.kcc-cal-cell:hover {
  border-color: var(--blue);
  background: #fafcff;
  box-shadow: var(--shadow-sm);
}

.kcc-cal-cell-filler {
  background: transparent;
  border-color: transparent;
  cursor: default;
}

.kcc-cal-cell-filler:hover {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

/* Today highlight */
.kcc-cal-today {
  border-color: var(--blue);
  background: #f0f7ff;
}

.kcc-cal-today:hover {
  background: #e8f2ff;
}

/* Day number */
.kcc-cal-day-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.kcc-cal-day-num {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.kcc-cal-cell-filler .kcc-cal-day-num {
  font-size: 11px;
  color: var(--text-faint);
}

/* Today's date number — filled circle */
.kcc-cal-day-num-today {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

/* ── Event chips ─────────────────────────────────────────────────────────────── */

.kcc-cal-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kcc-cal-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 5px;
  border-radius: 3px;
  border-left: 3px solid;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: filter 0.1s;
}

.kcc-cal-chip:hover {
  filter: brightness(0.93);
}

.kcc-chip-job {
  background: #d1fae5;
  border-left-color: #059669;
  color: #065f46;
}

.kcc-chip-blocked {
  background: #fef3c7;
  border-left-color: #d97706;
  color: #78350f;
}

.kcc-chip-time {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.kcc-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.kcc-cal-more {
  font-size: 10px;
  color: var(--text-faint);
  padding: 0 5px;
  font-weight: 500;
}

/* ── Intent Modal ────────────────────────────────────────────────────────────── */

.kcc-intent-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 27, 45, 0.45);
  z-index: 200;
  animation: fadeIn 0.15s ease;
}

.kcc-intent-modal {
  position: fixed;
  z-index: 210;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  animation: slideUp 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 12px)); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

.kcc-intent-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-light);
}

.kcc-intent-modal-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 2px;
}

.kcc-intent-date-display {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.kcc-intent-modal-close {
  background: none;
  border: none;
  padding: 4px;
  border-radius: var(--radius);
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
  flex-shrink: 0;
  margin-top: 2px;
}

.kcc-intent-modal-close:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

/* Intent action buttons */
.kcc-intent-actions {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kcc-intent-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  color: var(--text-primary);
}

.kcc-intent-btn:hover {
  background: #dcfce7;
  border-color: #86efac;
  transform: translateX(2px);
}

.kcc-intent-btn:active {
  transform: translateX(1px);
}

.kcc-intent-btn-cancel {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text-muted);
  margin-top: 4px;
}

.kcc-intent-btn-cancel:hover {
  background: var(--border-light);
  border-color: var(--border);
  color: var(--text-body);
}

.kcc-intent-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: #dcfce7;
  border-radius: var(--radius);
  color: #16a34a;
  flex-shrink: 0;
}

.kcc-intent-btn-cancel .kcc-intent-btn-icon {
  background: var(--border-light);
  color: var(--text-muted);
}

.kcc-intent-btn-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.kcc-intent-btn-label {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: #15803d;
}

.kcc-intent-btn-cancel .kcc-intent-btn-label {
  color: var(--text-muted);
}

.kcc-intent-btn-sub {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.3;
}

/* ── Intent modal — day preview (jobs already on this day) ───────────────────── */

.kcc-intent-day-preview {
  margin: 0 8px 4px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.kcc-intent-preview-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.kcc-intent-preview-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
}

.kcc-intent-preview-row:last-child { border-bottom: none; }

.kcc-intent-preview-row::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.kcc-preview-row-job::before     { background: #059669; }
.kcc-preview-row-blocked::before { background: #d97706; }

.kcc-intent-preview-time {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  flex-shrink: 0;
}

.kcc-intent-preview-name {
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kcc-intent-preview-title {
  font-weight: 400;
  color: var(--text-muted);
}

/* ── Day View Modal ──────────────────────────────────────────────────────────── */

.kcc-day-view-modal {
  position: fixed;
  z-index: 210;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 440px;
  max-width: calc(100vw - 32px);
  max-height: 80vh;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.kcc-day-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.kcc-day-view-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.kcc-day-view-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kcc-day-view-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.kcc-day-view-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.kcc-day-row {
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  border-left: 4px solid;
  margin-bottom: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.kcc-day-row-job     { border-left-color: #059669; }
.kcc-day-row-blocked { border-left-color: #d97706; }

.kcc-day-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.kcc-day-row-primary {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kcc-day-row-secondary {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kcc-day-row-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.kcc-day-row-time-badge,
.kcc-day-row-phone {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.kcc-day-row-phone a {
  color: var(--teal);
  text-decoration: none;
}

.kcc-day-row-phone a:hover { text-decoration: underline; }

.kcc-day-row-notes {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border-light);
}

/* Calendar status badges */
.kcc-badge-cal-scheduled  { background: #dbeafe; color: #1e40af; }
.kcc-badge-cal-in_progress { background: #fef3c7; color: #92400e; }
.kcc-badge-cal-complete   { background: #dcfce7; color: #15803d; }
.kcc-badge-cal-cancelled  { background: var(--red-bg); color: var(--red); }

.kcc-badge-cal-scheduled,
.kcc-badge-cal-in_progress,
.kcc-badge-cal-complete,
.kcc-badge-cal-cancelled {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: capitalize;
  white-space: nowrap;
}

/* ── Customer search autocomplete ────────────────────────────────────────────── */

.kcc-search-wrap {
  /* no position: relative — results are in-flow, not a floating popup */
}

.kcc-customer-results {
  /* In-flow dropdown: avoids overflow-y:auto clipping inside the slideover panel.
     The slideover body scrolls, so results naturally push content down. */
  width: 100%;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
}

.kcc-sr-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  text-align: left;
  transition: background 0.08s;
}

.kcc-sr-row:last-child { border-bottom: none; }

.kcc-sr-row:hover { background: var(--bg); }

.kcc-sr-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.kcc-sr-meta {
  font-size: 11px;
  color: var(--text-faint);
}

.kcc-sr-empty {
  padding: 12px;
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
}

/* Selected customer display */
.kcc-selected-customer {
  margin-top: 6px;
}

.kcc-selected-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--blue-focus);
  border: 1px solid rgba(0,119,182,0.2);
  border-radius: var(--radius);
}

.kcc-selected-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.kcc-selected-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
}

.kcc-selected-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.kcc-selected-clear {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius);
  font-size: 12px;
  flex-shrink: 0;
  transition: color 0.1s;
}

.kcc-selected-clear:hover { color: var(--red); }

/* ── Quick-create customer (inline in schedule form) ─────────────────────────── */

.kcc-quick-cust {
  margin-top: 8px;
}

.kcc-quick-cust-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.kcc-quick-cust-toggle:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-focus);
}

.kcc-quick-cust-toggle-active {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-focus);
}

.kcc-quick-cust-form {
  margin-top: 10px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  animation: quickFormSlide 0.18s ease both;
}

@keyframes quickFormSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.kcc-quick-cust-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.kcc-quick-cust-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.kcc-quick-cust-hint {
  font-size: 11px;
  color: var(--text-faint);
}

.kcc-quick-cust-error {
  font-size: 12px;
  color: var(--red, #ef4444);
  min-height: 16px;
  margin: 4px 0;
}

.kcc-quick-cust-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ── Mobile responsive ───────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .kcc-cal-month-nav {
    margin-left: 8px;
  }

  .kcc-cal-month-label {
    min-width: 110px;
    font-size: 13px;
  }

  .kcc-page-nav {
    display: none; /* hidden on small screens — use breadcrumb or back button instead */
  }

  .kcc-cal-container {
    padding: 0 8px 8px;
  }

  .kcc-cal-grid {
    grid-auto-rows: minmax(72px, auto);
    gap: 3px;
  }

  .kcc-cal-cell {
    padding: 4px;
    min-height: 72px;
  }

  .kcc-cal-dow {
    font-size: 9px;
    padding: 4px 2px;
  }
}

@media (max-width: 640px) {
  .kcc-logo-text-desktop { display: none; }

  .kcc-cal-today-btn { display: none; }

  .kcc-cal-month-nav {
    margin-left: 0;
  }

  .kcc-cal-grid {
    grid-auto-rows: minmax(58px, auto);
    gap: 2px;
  }

  .kcc-cal-cell {
    padding: 3px;
    min-height: 58px;
  }

  .kcc-cal-chip {
    font-size: 9px;
    padding: 1px 3px;
  }

  .kcc-chip-time { display: none; } /* too cramped on small phones */

  .kcc-intent-modal {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideUpSheet 0.22s cubic-bezier(0.34, 1.2, 0.64, 1);
  }

  @keyframes slideUpSheet {
    from { opacity: 0; transform: translateY(100%); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .kcc-day-view-modal {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }
}
