/* ═══════════════════════════════════════════════════════════════
   Kasaloma BOS — Phase 3 Premium Experience Layer
   Safe UI/UX additions: command palette, coach tips, micro-interactions,
   dashboard insight cards, premium empty states, and mobile refinement.
   No business logic, webhook, database, or AJAX endpoint changes.
   Version: 2.6.9.23
   ═══════════════════════════════════════════════════════════════ */

body.kcrm-frontend-body {
  --kbos-p3-ink: #08111f;
  --kbos-p3-muted: #64748b;
  --kbos-p3-soft: #f8fafc;
  --kbos-p3-line: rgba(226,232,240,.9);
  --kbos-p3-card: rgba(255,255,255,.97);
  --kbos-p3-navy: #06172d;
  --kbos-p3-blue: #2563eb;
  --kbos-p3-cyan: #06b6d4;
  --kbos-p3-green: #10b981;
  --kbos-p3-amber: #f59e0b;
  --kbos-p3-red: #ef4444;
  --kbos-p3-violet: #7c3aed;
  --kbos-p3-shadow: 0 24px 70px rgba(15,23,42,.11);
  --kbos-p3-shadow-soft: 0 12px 32px rgba(15,23,42,.075);
}

body.kcrm-frontend-body.kbos-phase3-ready * {
  -webkit-tap-highlight-color: transparent;
}

/* Refined motion without disturbing existing AJAX/navigation. */
body.kcrm-frontend-body.kbos-phase3-ready .kcrm-side-link,
body.kcrm-frontend-body.kbos-phase3-ready .ktc-btn,
body.kcrm-frontend-body.kbos-phase3-ready .ktc-btn-ghost,
body.kcrm-frontend-body.kbos-phase3-ready .kdash-btn,
body.kcrm-frontend-body.kbos-phase3-ready button,
body.kcrm-frontend-body.kbos-phase3-ready a {
  transition-property: transform, box-shadow, border-color, background, color, opacity;
  transition-duration: .16s;
  transition-timing-function: ease;
}

body.kcrm-frontend-body.kbos-phase3-ready .ktc-btn:hover,
body.kcrm-frontend-body.kbos-phase3-ready .ktc-btn-ghost:hover,
body.kcrm-frontend-body.kbos-phase3-ready .kdash-btn:hover,
body.kcrm-frontend-body.kbos-phase3-ready .kcrm-side-link:hover {
  transform: translateY(-1px);
}

body.kcrm-frontend-body.kbos-phase3-ready :focus-visible {
  outline: 3px solid rgba(37,99,235,.22) !important;
  outline-offset: 2px !important;
  border-radius: 10px;
}

/* Phase 3 Dashboard Intelligence */
body.kcrm-frontend-body .kbos-p3-insight-row {
  display: grid;
  grid-template-columns: minmax(270px, .75fr) minmax(360px, 1.25fr);
  gap: 12px;
  margin: 0 0 12px;
}
body.kcrm-frontend-body .kbos-p3-health-card,
body.kcrm-frontend-body .kbos-p3-priority-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(255,255,255,.98), rgba(248,250,252,.94));
  border: 1px solid var(--kbos-p3-line);
  border-radius: 22px;
  box-shadow: var(--kbos-p3-shadow-soft);
  padding: 16px;
}
body.kcrm-frontend-body .kbos-p3-health-card:before,
body.kcrm-frontend-body .kbos-p3-priority-card:before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--kbos-p3-blue), var(--kbos-p3-green));
}
body.kcrm-frontend-body .kbos-p3-health-card {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  gap: 16px;
}
body.kcrm-frontend-body .kbos-p3-health-ring {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--ring-color, #2563eb) calc(var(--score,0) * 1%), #e2e8f0 0);
  box-shadow: inset 0 0 0 1px rgba(15,23,42,.06);
}
body.kcrm-frontend-body .kbos-p3-health-ring:before {
  content: "";
  position: absolute;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 1px 3px rgba(15,23,42,.08);
}
body.kcrm-frontend-body .kbos-p3-health-value {
  position: relative;
  z-index: 1;
  color: #0f172a;
  font-size: 25px;
  font-weight: 950;
  letter-spacing: -.05em;
}
body.kcrm-frontend-body .kbos-p3-eyebrow {
  color: #64748b;
  font-size: 10px;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: .1em;
}
body.kcrm-frontend-body .kbos-p3-health-title,
body.kcrm-frontend-body .kbos-p3-priority-card h2 {
  margin: 3px 0 4px !important;
  color: #0f172a !important;
  font-size: 16px !important;
  font-weight: 950 !important;
  letter-spacing: -.04em !important;
}
body.kcrm-frontend-body .kbos-p3-health-copy {
  color: #64748b;
  font-size: 12px;
  line-height: 1.45;
}
body.kcrm-frontend-body .kbos-p3-health-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
body.kcrm-frontend-body .kbos-p3-mini-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #fff;
  color: #334155;
  font-size: 10.5px;
  font-weight: 850;
  padding: 5px 8px;
}
body.kcrm-frontend-body .kbos-p3-priority-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
body.kcrm-frontend-body .kbos-p3-priority-sub {
  color: #64748b;
  font-size: 12px;
}
body.kcrm-frontend-body .kbos-p3-priority-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 10px;
}
body.kcrm-frontend-body .kbos-p3-priority {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(226,232,240,.88);
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  min-height: 104px;
}
body.kcrm-frontend-body .kbos-p3-priority:before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--tone, #2563eb);
}
body.kcrm-frontend-body .kbos-p3-priority strong {
  display: block;
  color: #0f172a;
  font-size: 13px;
  font-weight: 950;
  line-height: 1.25;
  margin-bottom: 5px;
}
body.kcrm-frontend-body .kbos-p3-priority span {
  display: block;
  color: #64748b;
  font-size: 11.5px;
  line-height: 1.35;
}
body.kcrm-frontend-body .kbos-p3-priority a {
  display: inline-flex;
  margin-top: 9px;
  color: #1d4ed8 !important;
  font-size: 11px;
  font-weight: 900;
  text-decoration: none !important;
}

/* Command palette */
.kbos-p3-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 99980;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  background: linear-gradient(135deg, #071a33, #153a63);
  color: #fff;
  font-size: 12px;
  font-weight: 950;
  box-shadow: 0 16px 40px rgba(7,26,51,.28);
  cursor: pointer;
}
.kbos-p3-fab kbd {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255,255,255,.16);
  color: #e0f2fe;
  font: inherit;
}
.kbos-p3-palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99990;
  background: rgba(2,6,23,.42);
  backdrop-filter: blur(8px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 7vh 18px 24px;
}
.kbos-p3-palette-backdrop.is-open { display: flex; }
.kbos-p3-palette {
  width: min(680px, 100%);
  overflow: hidden;
  border: 1px solid rgba(226,232,240,.7);
  border-radius: 24px;
  background: rgba(255,255,255,.98);
  box-shadow: 0 30px 90px rgba(2,6,23,.28);
}
.kbos-p3-palette-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid #e2e8f0;
}
.kbos-p3-palette-head span { font-size: 18px; }
.kbos-p3-palette-input {
  flex: 1;
  border: 0 !important;
  outline: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  color: #0f172a !important;
  font-size: 15px !important;
  font-weight: 800;
  padding: 10px 4px !important;
}
.kbos-p3-palette-close {
  border: 0;
  border-radius: 12px;
  background: #f1f5f9;
  color: #334155;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-weight: 950;
}
.kbos-p3-palette-list {
  max-height: 430px;
  overflow: auto;
  padding: 8px;
}
.kbos-p3-palette-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: #0f172a;
  text-align: left;
  padding: 11px 12px;
  cursor: pointer;
}
.kbos-p3-palette-item:hover,
.kbos-p3-palette-item.is-active { background: #eff6ff; }
.kbos-p3-palette-item strong { display: block; font-size: 13px; font-weight: 950; }
.kbos-p3-palette-item small { display: block; margin-top: 2px; color: #64748b; font-size: 10px; }
.kbos-p3-palette-empty { padding: 28px 14px; text-align: center; color: #64748b; font-size: 13px; }
.kbos-p3-palette-foot {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px 14px;
  color: #64748b;
  font-size: 11px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}
.kbos-p3-palette-foot kbd {
  border: 1px solid #cbd5e1;
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fff;
  color: #334155;
  padding: 1px 5px;
  font: inherit;
  font-weight: 850;
}

/* Gentle coach panel */
.kbos-p3-coach {
  position: fixed;
  right: 22px;
  bottom: 78px;
  z-index: 99970;
  width: min(340px, calc(100vw - 28px));
  border: 1px solid rgba(226,232,240,.9);
  border-radius: 22px;
  background: rgba(255,255,255,.98);
  box-shadow: var(--kbos-p3-shadow);
  overflow: hidden;
}
.kbos-p3-coach.is-hidden { display: none; }
.kbos-p3-coach-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px;
}
.kbos-p3-coach-title { color: #0f172a; font-size: 14px; font-weight: 950; letter-spacing: -.03em; }
.kbos-p3-coach-sub { margin-top: 2px; color: #64748b; font-size: 11.5px; line-height: 1.35; }
.kbos-p3-coach-close {
  border: 0;
  background: #f1f5f9;
  color: #334155;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  font-weight: 950;
  cursor: pointer;
}
.kbos-p3-coach-list {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}
.kbos-p3-coach-tip {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 8px;
  align-items: start;
  padding: 9px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #334155;
  font-size: 11.5px;
  line-height: 1.35;
}
.kbos-p3-coach-tip b { color: #0f172a; }

/* Better empty/error/notice screens across modules */
body.kcrm-frontend-body .ktc-empty-state,
body.kcrm-frontend-body .kdash-empty,
body.kcrm-frontend-body .kcrm-empty,
body.kcrm-frontend-body .ksales-empty,
body.kcrm-frontend-body .kaa-empty-state {
  background: linear-gradient(135deg, #fff, #f8fafc) !important;
  border: 1px dashed rgba(148,163,184,.8) !important;
  border-radius: 20px !important;
  box-shadow: 0 10px 26px rgba(15,23,42,.04) !important;
}
body.kcrm-frontend-body .ktc-empty-state:before,
body.kcrm-frontend-body .kdash-empty:before,
body.kcrm-frontend-body .kcrm-empty:before,
body.kcrm-frontend-body .ksales-empty:before {
  content: "✨";
  display: block;
  font-size: 22px;
  margin-bottom: 5px;
}

/* Premium table affordance */
body.kcrm-frontend-body .kbos-p2-table-wrap,
body.kcrm-frontend-body .kwmc-log-table-wrap {
  position: relative;
}
body.kcrm-frontend-body .kbos-p2-table-wrap:after,
body.kcrm-frontend-body .kwmc-log-table-wrap:after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0 0 0 auto;
  width: 26px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.88));
  border-radius: 0 18px 18px 0;
}
body.kcrm-frontend-body table tbody tr:hover td {
  background: rgba(248,250,252,.78);
}

/* AI Inbox visual refinement */
body.kcrm-frontend-body .kaa-messages {
  background:
    radial-gradient(circle at 18% 12%, rgba(37,99,235,.05), transparent 26%),
    radial-gradient(circle at 85% 0%, rgba(16,185,129,.05), transparent 24%),
    #f8fafc;
}
body.kcrm-frontend-body .kaa-msg-bubble {
  box-shadow: 0 7px 18px rgba(15,23,42,.06) !important;
}
body.kcrm-frontend-body .kaa-msg.inbound .kaa-msg-bubble {
  border: 1px solid rgba(226,232,240,.86);
}
body.kcrm-frontend-body .kaa-msg.outbound .kaa-msg-bubble {
  border: 1px solid rgba(187,247,208,.78);
}
body.kcrm-frontend-body .kaa-chat-item,
body.kcrm-frontend-body .kaa-conv-item {
  border-radius: 16px !important;
}

/* Sticky module action bars where existing pages already have toolbars. */
@media (min-width: 900px) {
  body.kcrm-frontend-body .ktc-card-toolbar,
  body.kcrm-frontend-body .kwmc-card-toolbar,
  body.kcrm-frontend-body .ksales-page-head,
  body.kcrm-frontend-body .kcrm-contacts-toolbar {
    position: sticky;
    top: 10px;
    z-index: 30;
    backdrop-filter: blur(12px);
  }
}

/* Mobile refinement */
@media (max-width: 980px) {
  body.kcrm-frontend-body .kbos-p3-insight-row {
    grid-template-columns: 1fr;
  }
  body.kcrm-frontend-body .kbos-p3-priority-list {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 700px) {
  .kbos-p3-fab {
    right: 14px;
    bottom: 86px;
    padding: 10px 12px;
  }
  .kbos-p3-fab span { display: none; }
  .kbos-p3-coach {
    left: 14px;
    right: 14px;
    bottom: 142px;
    width: auto;
  }
  .kbos-p3-palette-backdrop {
    align-items: flex-end;
    padding: 14px;
  }
  .kbos-p3-palette {
    border-radius: 22px;
  }
  body.kcrm-frontend-body .kbos-p3-health-card {
    grid-template-columns: 76px 1fr;
  }
  body.kcrm-frontend-body .kbos-p3-health-ring {
    width: 74px;
    height: 74px;
  }
  body.kcrm-frontend-body .kbos-p3-health-ring:before {
    width: 54px;
    height: 54px;
  }
  body.kcrm-frontend-body .kbos-p3-health-value { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  body.kcrm-frontend-body.kbos-phase3-ready *,
  body.kcrm-frontend-body.kbos-phase3-ready *:before,
  body.kcrm-frontend-body.kbos-phase3-ready *:after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
