:root {
  --kk-navy: #1f2a5c;
  --kk-navy-dark: #182250;
  --kk-accent: #5b63d3;
  --kk-accent-soft: #eceefb;
  --kk-bg: #f6f7fb;
  --kk-border: #e6e8f0;
  --kk-text: #1f2937;
  --kk-muted: #6b7280;
  --sidebar-width: 216px;
  --bs-primary: var(--kk-accent);
  --bs-primary-rgb: 91, 99, 211;
  --bs-link-color: var(--kk-accent);
}

html, body { height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--kk-bg);
  color: var(--kk-text);
  font-size: 0.875rem;
}

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar { padding: 1.25rem 1.5rem 0.75rem; }
.app-content { padding: 0.75rem 1.5rem 1.5rem; }
.topbar-title { font-size: 1.35rem; font-weight: 700; }
.wave { font-size: 1.1rem; }

.topbar-search { position: relative; width: 290px; max-width: 100%; }
.topbar-search .bi { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--kk-muted); }
.topbar-search .form-control { padding-left: 2.4rem; border-radius: 999px; border-color: var(--kk-border); height: 42px; }
.btn-icon {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--kk-border);
  background: #fff; display: inline-flex; align-items: center; justify-content: center; color: var(--kk-text);
}
.btn-icon .badge { font-size: 0.6rem; }

/* ---------- Sidebar ---------- */
.app-sidebar {
  width: var(--sidebar-width); background: var(--kk-navy); color: #fff;
  display: flex; flex-direction: column; flex-shrink: 0;
}
@media (min-width: 992px) {
  /* .offcanvas-lg forces a transparent background at this breakpoint; override it. */
  .app-sidebar { position: sticky; top: 0; height: 100vh; background: var(--kk-navy) !important; }
}
@media (max-width: 991.98px) {
  .app-sidebar.offcanvas-lg { width: var(--sidebar-width); background: var(--kk-navy); color: #fff; }
}
.sidebar-brand { padding: 1.25rem 1rem 1rem; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,0.12);
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; font-size: 1.15rem; }
.brand-sub { font-size: 0.8rem; opacity: 0.85; }

.sidebar-nav { padding: 0.25rem 0.6rem; overflow-y: auto; }
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 0.75rem; color: rgba(255,255,255,0.9);
  padding: 0.62rem 0.9rem; border-radius: 10px; margin-bottom: 0.15rem; font-weight: 500;
}
.sidebar-nav .nav-link .bi { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--kk-accent); color: #fff; }
.sidebar-nav .badge { font-size: 0.7rem; }

.sidebar-user { padding: 1rem; margin-top: auto; background: var(--kk-navy-dark); border-top: 1px solid rgba(255,255,255,0.08); }

/* ---------- Avatars ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--kk-accent); color: #fff; font-weight: 600; flex-shrink: 0;
}
.avatar-sm { width: 30px; height: 30px; font-size: 0.7rem; }
.avatar-md { width: 40px; height: 40px; font-size: 0.85rem; }
.avatar-soft { background: var(--kk-accent-soft); color: var(--kk-accent); }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--kk-border); border-radius: 12px; box-shadow: none; }
.card-header { background: transparent; border-bottom: 1px solid var(--kk-border); padding: 1rem 1.25rem; }
.card-title { font-size: 1rem; font-weight: 600; margin: 0; }
.link { color: var(--kk-accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.text-primary-soft { color: var(--kk-accent); }

/* Stat cards */
.stat-card .card-body { padding: 0.85rem 0.75rem; gap: 0.6rem !important; }
.stat-icon {
  width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 1.15rem; flex-shrink: 0;
}
.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-weight: 500; font-size: 0.78rem; white-space: nowrap; }
.stat-sub { font-size: 0.75rem; color: var(--kk-muted); margin-top: 0.15rem; }
.stat-purple { background: #f3f3fd; } .stat-purple .stat-icon { background: #e4e5fb; color: var(--kk-accent); }
.stat-green  { background: #f1faf5; } .stat-green  .stat-icon { background: #d9f2e4; color: #1f9d61; }
.stat-orange { background: #fff8ee; } .stat-orange .stat-icon { background: #ffe9c9; color: #e0902b; }
.stat-blue   { background: #f1f5fd; } .stat-blue   .stat-icon { background: #dce7fb; color: #2f6fe0; }

/* Caseload table */
.table-caseload thead th {
  background: #f9fafc; color: var(--kk-muted); font-weight: 500; font-size: 0.8rem;
  border-bottom: 1px solid var(--kk-border); padding: 0.7rem 1rem;
}
.table-caseload td { padding: 0.75rem 0.6rem; border-color: var(--kk-border); }
.table-caseload td:nth-child(4) { white-space: nowrap; }
.table-caseload thead th:first-child, .table-caseload td:first-child { padding-left: 1rem; width: 2.5rem; }
.table-caseload tbody tr:last-child td { border-bottom: 0; }
.alert-chip { display: inline-block; padding: 0.35rem 0.6rem; border-radius: 8px; font-size: 0.75rem; line-height: 1.2; max-width: 90px; }
.alert-warning-soft { background: #fff3d6; color: #9a6a12; }
.alert-danger-soft  { background: #fde5e5; color: #b53b3b; }

/* Alerts & reminders */
.alert-card { border: 1px solid var(--kk-border); border-radius: 12px; padding: 0.85rem; background: #fff; }
.alert-card-icon { font-size: 1.4rem; }
.alert-red    { background: #fff5f5; } .alert-red    .alert-card-icon { color: #d9534f; }
.alert-orange { background: #fff9ee; } .alert-orange .alert-card-icon { color: #e0902b; }
.alert-green  { background: #f2faf5; } .alert-green  .alert-card-icon { color: #1f9d61; }
.alert-illustration { background: #f3f3fd; }
.illustration-mark {
  width: 48px; height: 48px; border-radius: 50%; background: #e4e5fb; color: var(--kk-accent);
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0;
}

/* Tasks */
.task-item { display: flex; gap: 0.75rem; padding: 0.6rem 0 0.6rem 0.75rem; border-bottom: 1px solid var(--kk-border); border-left: 3px solid transparent; }
.task-item.urgent { border-left-color: #e05252; }
.task-item:last-child { border-bottom: 0; }
.task-item .form-check-input { margin-top: 0.2rem; }
.task-title { font-weight: 500; }

/* Calendar */
.calendar-item { display: flex; gap: 0.75rem; padding: 0.65rem 0 0.65rem 0.75rem; border-left: 3px solid var(--kk-accent); border-bottom: 1px solid var(--kk-border); }
.calendar-item:last-child { border-bottom: 0; }
.calendar-time { font-weight: 600; min-width: 64px; }
.cal-blue  { border-left-color: #2f6fe0; }
.cal-red   { border-left-color: #e05252; }
.cal-green { border-left-color: #1f9d61; }

/* Messages */
.message { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.message.mine { flex-direction: row; justify-content: flex-end; }
.message-body { max-width: 85%; }
.message-meta { margin-bottom: 0.25rem; }
.message.mine .message-meta { text-align: left; }
.message-bubble { background: #f3f4f8; border-radius: 12px; padding: 0.6rem 0.75rem; line-height: 1.4; }
.message.mine .message-bubble { background: #e6ecfb; }
.btn-outline-primary { --bs-btn-color: var(--kk-accent); --bs-btn-border-color: var(--kk-accent); --bs-btn-hover-bg: var(--kk-accent); --bs-btn-hover-border-color: var(--kk-accent); }

/* Quick actions */
.quick-action { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; text-decoration: none; color: var(--kk-text); text-align: center; }
.quick-action-icon {
  width: 46px; height: 46px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem;
}
.quick-action-label { font-size: 0.7rem; line-height: 1.2; }
.quick-action:hover .quick-action-icon { filter: brightness(0.95); }
.qa-purple .quick-action-icon { background: #e4e5fb; color: var(--kk-accent); }
.qa-green  .quick-action-icon { background: #d9f2e4; color: #1f9d61; }
.qa-blue   .quick-action-icon { background: #dce7fb; color: #2f6fe0; }
.qa-orange .quick-action-icon { background: #ffe9c9; color: #e0902b; }
.qa-red    .quick-action-icon { background: #fde5e5; color: #d9534f; }
.qa-teal   .quick-action-icon { background: #d9f2ef; color: #1f9d8f; }

/* =====================================================================
   Polish: motion & effects (design unchanged, just brought to life)
   ===================================================================== */

/* Page entrance: cards rise and fade in, staggered by data-reveal order */
@keyframes kk-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.reveal { opacity: 0; animation: kk-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards; animation-delay: calc(var(--i, 0) * 70ms); }

/* Sidebar items slide in from the left */
@keyframes kk-slide-in {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}
.sidebar-nav .nav-item { opacity: 0; animation: kk-slide-in 0.4s ease-out forwards; animation-delay: calc(var(--i, 0) * 45ms + 120ms); }

/* Hover lift + soft shadow on cards */
.card, .alert-card, .stat-card {
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.card:hover, .alert-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(31, 42, 92, 0.08);
  border-color: #dfe2ee;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(31, 42, 92, 0.10); }

/* Sheen sweep on stat cards and quick action tiles */
.sheen { position: relative; overflow: hidden; }
.sheen::after {
  content: ""; position: absolute; top: 0; left: -75%; width: 50%; height: 100%;
  background: linear-gradient(115deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.65) 50%, rgba(255,255,255,0) 100%);
  transform: skewX(-20deg); pointer-events: none; opacity: 0;
}
.sheen:hover::after { animation: kk-sheen 0.9s ease forwards; }
@keyframes kk-sheen {
  0%   { left: -75%; opacity: 0; }
  20%  { opacity: 1; }
  100% { left: 125%; opacity: 0; }
}

/* Stat icon bounce on hover */
.stat-icon { transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.stat-card:hover .stat-icon { transform: scale(1.12) rotate(-6deg); }

/* Waving hand */
@keyframes kk-wave {
  0%, 60%, 100% { transform: rotate(0deg); }
  10%, 30% { transform: rotate(16deg); }
  20%, 40% { transform: rotate(-8deg); }
  50% { transform: rotate(10deg); }
}
.wave { display: inline-block; transform-origin: 70% 70%; animation: kk-wave 2.4s ease-in-out 0.6s 2; }
.topbar-title:hover .wave { animation: kk-wave 1.6s ease-in-out infinite; }

/* Notification badge pulse */
@keyframes kk-pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.55); }
  100% { box-shadow: 0 0 0 9px rgba(220, 53, 69, 0); }
}
.btn-icon .badge, .sidebar-nav .badge, .message .badge { animation: kk-pulse-ring 2s ease-out infinite; }
.btn-icon { transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease; }
.btn-icon:hover { background: var(--kk-accent-soft); border-color: #d6d9f5; color: var(--kk-accent); transform: translateY(-1px); }

/* Search focus glow */
.topbar-search .form-control { transition: box-shadow 0.25s ease, border-color 0.25s ease, width 0.3s ease; }
.topbar-search .form-control:focus { border-color: var(--kk-accent); box-shadow: 0 0 0 4px rgba(91, 99, 211, 0.15); }

/* Sidebar link motion + active glow */
.sidebar-nav .nav-link { transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease; }
.sidebar-nav .nav-link:hover:not(.active) { transform: translateX(4px); }
.sidebar-nav .nav-link .bi { transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); }
.sidebar-nav .nav-link:hover .bi { transform: scale(1.15); }
.sidebar-nav .nav-link.active {
  background: linear-gradient(135deg, #6a72e6 0%, var(--kk-accent) 60%, #4e56c4 100%);
  box-shadow: 0 6px 16px rgba(91, 99, 211, 0.45);
}
.brand-mark { transition: transform 0.3s ease, background 0.3s ease; }
.sidebar-brand:hover .brand-mark { transform: rotate(-8deg) scale(1.08); background: rgba(255,255,255,0.2); }
@keyframes kk-heartbeat {
  0%, 100% { transform: scale(1); }
  14% { transform: scale(1.18); }
  28% { transform: scale(1); }
  42% { transform: scale(1.12); }
}
.brand-mark .bi { display: inline-block; animation: kk-heartbeat 2.8s ease-in-out 1.2s infinite; }
.sidebar-user { transition: background 0.2s ease; cursor: pointer; }
.sidebar-user:hover { background: #141d45; }

/* Caseload rows */
.table-caseload tbody tr { transition: background 0.2s ease; }
.table-caseload tbody tr:hover { background: #f8f8fe; }
.table-caseload .avatar { transition: transform 0.25s ease, box-shadow 0.25s ease; }
.table-caseload tbody tr:hover .avatar { transform: scale(1.08); box-shadow: 0 0 0 4px rgba(91, 99, 211, 0.15); }
.star-toggle { cursor: pointer; transition: transform 0.2s ease, color 0.2s ease; }
.star-toggle:hover { transform: scale(1.25); color: #f0b429 !important; }
.star-toggle.is-on { color: #f0b429 !important; }
@keyframes kk-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.4); } 100% { transform: scale(1); } }
.star-toggle.pop { animation: kk-pop 0.35s ease; }
.alert-chip { transition: transform 0.2s ease; }
.alert-chip:hover { transform: scale(1.04); }

/* Tasks: checking one fades and strikes it through */
.task-item { transition: background 0.2s ease, opacity 0.3s ease; }
.task-item:hover { background: #fafafe; }
.task-title { transition: color 0.3s ease; position: relative; }
.task-title::after {
  content: ""; position: absolute; left: 0; top: 55%; height: 1.5px; width: 0; background: var(--kk-muted);
  transition: width 0.35s ease;
}
.task-item.done .task-title { color: var(--kk-muted); }
.task-item.done .task-title::after { width: 100%; }
.task-item.done { opacity: 0.6; }
.form-check-input { transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease; cursor: pointer; }
.form-check-input:checked { background-color: var(--kk-accent); border-color: var(--kk-accent); }

/* Calendar entries slide slightly on hover, coloured bar glows */
.calendar-item { transition: transform 0.2s ease, background 0.2s ease; }
.calendar-item:hover { transform: translateX(3px); background: #fafafe; }

/* Message bubbles pop in */
@keyframes kk-bubble {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.message { opacity: 0; animation: kk-bubble 0.45s ease-out forwards; animation-delay: calc(var(--i, 0) * 120ms + 300ms); }
.message-bubble { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.message:hover .message-bubble { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(31, 42, 92, 0.08); }

/* Send Message button: gradient fill sweeps in on hover */
.btn-outline-primary { position: relative; overflow: hidden; transition: color 0.25s ease, box-shadow 0.25s ease; z-index: 0; }
.btn-outline-primary::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(135deg, #6a72e6, var(--kk-accent));
  transform: translateX(-101%); transition: transform 0.3s ease;
}
.btn-outline-primary:hover::before { transform: translateX(0); }
.btn-outline-primary:hover { color: #fff; box-shadow: 0 8px 20px rgba(91, 99, 211, 0.35); }

/* Quick actions: lift, sheen, icon pop */
.quick-action-icon { transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease; }
.quick-action:hover .quick-action-icon { transform: translateY(-4px) scale(1.08); box-shadow: 0 10px 20px rgba(31, 42, 92, 0.12); }
.quick-action-label { transition: color 0.2s ease; }
.quick-action:hover .quick-action-label { color: var(--kk-accent); }

/* Links get an animated underline */
.link { position: relative; }
.link::after { content: ""; position: absolute; left: 0; bottom: -2px; width: 0; height: 1.5px; background: currentColor; transition: width 0.25s ease; }
.link:hover { text-decoration: none; }
.link:hover::after { width: 100%; }

/* Illustration heart floats */
@keyframes kk-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.illustration-mark { animation: kk-float 3.5s ease-in-out infinite; }

/* Accessibility: honour reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal, .sidebar-nav .nav-item, .message { opacity: 1; }
}

/* ---------- Internal demo modal ---------- */
.demo-modal .modal-content { border: 0; border-radius: 16px; overflow: hidden; box-shadow: 0 24px 60px rgba(31, 42, 92, 0.25); }
.demo-modal .modal-header { background: linear-gradient(135deg, var(--kk-navy) 0%, #2b3a7a 100%); color: #fff; border: 0; padding: 1.25rem 1.5rem; }
.demo-modal .modal-title { font-size: 1.1rem; font-weight: 700; }
.demo-modal .modal-body { padding: 1.5rem; font-size: 0.95rem; }
.demo-modal .modal-footer { border: 0; padding: 0 1.5rem 1.5rem; }
.demo-modal .btn-primary { --bs-btn-bg: var(--kk-accent); --bs-btn-border-color: var(--kk-accent); --bs-btn-hover-bg: #4e56c4; --bs-btn-hover-border-color: #4e56c4; box-shadow: 0 8px 20px rgba(91, 99, 211, 0.35); }
.demo-modal.fade .modal-dialog { transform: translateY(16px) scale(0.96); transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1); }
.demo-modal.show .modal-dialog { transform: none; }
.modal-backdrop.show { opacity: 0.55; backdrop-filter: blur(2px); }
