/**
 * NorthStar SwitchBoard â Premium Design v2
 *
 * Enhancement layer on top of twilio-flex-theme.css.
 * Adds: gradient utilities, glassmorphism, ambient glow, micro-animations,
 * progress bars, timeline, metric displays, gradient borders, and more.
 *
 * All rules scoped to body.twilio-flex to avoid conflicts.
 */

/* ====== KEYFRAMES ====== */

@keyframes ns-gradient-shift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes ns-loading-bar {
  0%   { background-position: 200% center; }
  100% { background-position: -200% center; }
}

@keyframes ns-ring-pulse {
  0%   { transform: scale(1); opacity: 0.7; }
  70%  { transform: scale(2); opacity: 0; }
  100% { transform: scale(2); opacity: 0; }
}

@keyframes ns-shine {
  0%        { left: -100%; }
  60%, 100% { left: 150%; }
}

@keyframes ns-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

@keyframes ns-spin-slow {
  to { transform: rotate(360deg); }
}

/* ====== BODY MESH GRADIENT ====== */

body.twilio-flex {
  background:
    radial-gradient(ellipse 55% 45% at 18% 8%,  rgba(31, 111, 255, 0.055) 0%, transparent 65%),
    radial-gradient(ellipse 45% 35% at 82% 85%,  rgba(99, 102, 241, 0.045) 0%, transparent 65%),
    radial-gradient(ellipse 65% 55% at 50% 50%,  rgba(20, 184, 111, 0.025) 0%, transparent 70%),
    linear-gradient(180deg, #eef3fb 0%, #f8fbff 100%);
}

:root[data-theme="dark"] body.twilio-flex {
  background:
    radial-gradient(ellipse 55% 45% at 18% 8%,  rgba(31, 111, 255, 0.07) 0%, transparent 65%),
    radial-gradient(ellipse 45% 35% at 82% 85%,  rgba(99, 102, 241, 0.06) 0%, transparent 65%),
    #0f172a;
}

/* ====== TOPBAR / HEADER ENHANCEMENT ====== */

body.twilio-flex header#topbar,
body.twilio-flex .topbar,
body.twilio-flex .wb-header,
body.twilio-flex .login-header,
body.twilio-flex .page-header {
  background: linear-gradient(135deg, #0b1b4d 0%, #132a67 55%, #1a3580 100%) !important;
  box-shadow: 0 4px 24px rgba(11, 27, 77, 0.35), 0 1px 0 rgba(255, 255, 255, 0.06) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07) !important;
}

/* ====== CARD ENHANCEMENTS ====== */

body.twilio-flex .card,
body.twilio-flex .card-custom,
body.twilio-flex .card-standard {
  background: linear-gradient(160deg, #ffffff 0%, #f9fbff 100%);
}

:root[data-theme="dark"] body.twilio-flex .card,
:root[data-theme="dark"] body.twilio-flex .card-custom,
:root[data-theme="dark"] body.twilio-flex .card-standard {
  background: linear-gradient(160deg, #0f172a 0%, #141e30 100%);
}

/* Card with gradient top accent bar */
body.twilio-flex .card-accent-top {
  position: relative;
  overflow: hidden;
}

body.twilio-flex .card-accent-top::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--flex-accent), #8b5cf6, var(--flex-accent));
  background-size: 200% 100%;
  animation: ns-gradient-shift 5s linear infinite;
}

/* Gradient border card */
body.twilio-flex .card-gradient-border {
  position: relative;
  background: linear-gradient(160deg, #ffffff 0%, #f9fbff 100%);
  border: none !important;
  border-radius: var(--flex-radius-lg) !important;
}

body.twilio-flex .card-gradient-border::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: calc(var(--flex-radius-lg) + 1px);
  background: linear-gradient(135deg,
    rgba(31, 111, 255, 0.28),
    rgba(139, 92, 246, 0.18),
    rgba(20, 184, 111, 0.12));
  z-index: -1;
}

:root[data-theme="dark"] body.twilio-flex .card-gradient-border {
  background: linear-gradient(160deg, #0f172a 0%, #141e30 100%);
}

/* Card hover lift */
body.twilio-flex .card-hover-lift {
  transition: transform var(--flex-transition), box-shadow var(--flex-transition) !important;
}

body.twilio-flex .card-hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px -12px rgba(10, 37, 115, 0.18) !important;
}

/* Shine sweep effect */
body.twilio-flex .card-shine {
  position: relative;
  overflow: hidden;
}

body.twilio-flex .card-shine::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 55%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  transform: skewX(-18deg);
  pointer-events: none;
  animation: ns-shine 4s ease-in-out infinite;
}

/* ====== GLASSMORPHISM UTILITIES ====== */

body.twilio-flex .glass {
  background: rgba(255, 255, 255, 0.70);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 32px rgba(10, 37, 115, 0.08);
}

body.twilio-flex .glass-navy {
  background: rgba(11, 27, 77, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

:root[data-theme="dark"] body.twilio-flex .glass {
  background: rgba(15, 23, 42, 0.70);
  border-color: rgba(71, 85, 105, 0.42);
}

/* ====== GRADIENT TEXT UTILITIES ====== */

body.twilio-flex .text-gradient-primary {
  background: linear-gradient(135deg, var(--flex-accent) 0%, #8b5cf6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

body.twilio-flex .text-gradient-success {
  background: linear-gradient(135deg, #14b86f 0%, #0ea5e9 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

body.twilio-flex .text-gradient-warm {
  background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ====== BUTTON ENHANCEMENTS ====== */

body.twilio-flex .btn-gradient-primary {
  background: linear-gradient(135deg, var(--flex-accent) 0%, #6366f1 100%);
  border: none;
  color: #fff;
  font-weight: 600;
  position: relative;
  overflow: hidden;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 14px -4px rgba(31, 111, 255, 0.45);
}

body.twilio-flex .btn-gradient-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
  transition: left 0.45s ease;
}

body.twilio-flex .btn-gradient-primary:hover::before { left: 100%; }

body.twilio-flex .btn-gradient-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px -4px rgba(31, 111, 255, 0.5);
}

body.twilio-flex .btn-gradient-success {
  background: linear-gradient(135deg, #14b86f 0%, #0ea5e9 100%);
  border: none;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px -4px rgba(20, 184, 111, 0.4);
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

body.twilio-flex .btn-gradient-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px -4px rgba(20, 184, 111, 0.5);
}

/* ====== STAT / KPI CARDS ====== */

body.twilio-flex .stat-card-blue {
  background: linear-gradient(135deg, rgba(31, 111, 255, 0.07) 0%, rgba(31, 111, 255, 0.02) 100%);
  border-left: 3px solid var(--flex-accent) !important;
}

body.twilio-flex .stat-card-green {
  background: linear-gradient(135deg, rgba(20, 184, 111, 0.07) 0%, rgba(20, 184, 111, 0.02) 100%);
  border-left: 3px solid var(--flex-success) !important;
}

body.twilio-flex .stat-card-amber {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.07) 0%, rgba(245, 158, 11, 0.02) 100%);
  border-left: 3px solid var(--flex-warning) !important;
}

body.twilio-flex .stat-card-red {
  background: linear-gradient(135deg, rgba(219, 58, 68, 0.07) 0%, rgba(219, 58, 68, 0.02) 100%);
  border-left: 3px solid var(--flex-danger) !important;
}

body.twilio-flex .stat-card-purple {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.07) 0%, rgba(139, 92, 246, 0.02) 100%);
  border-left: 3px solid #8b5cf6 !important;
}

/* Metric display values */
body.twilio-flex .metric-display {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

body.twilio-flex .metric-label {
  font-size: 0.71rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--flex-muted);
  font-weight: 600;
}

body.twilio-flex .metric-change {
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

body.twilio-flex .metric-change.positive { color: var(--flex-success); }
body.twilio-flex .metric-change.negative { color: var(--flex-danger); }

/* ====== AMBIENT GLOW WRAPPERS ====== */

body.twilio-flex .glow-blue {
  box-shadow: 0 0 0 1px rgba(31, 111, 255, 0.1), 0 8px 24px -8px rgba(31, 111, 255, 0.22) !important;
}

body.twilio-flex .glow-green {
  box-shadow: 0 0 0 1px rgba(20, 184, 111, 0.12), 0 8px 24px -8px rgba(20, 184, 111, 0.25) !important;
}

body.twilio-flex .glow-amber {
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.12), 0 8px 24px -8px rgba(245, 158, 11, 0.25) !important;
}

body.twilio-flex .glow-red {
  box-shadow: 0 0 0 1px rgba(219, 58, 68, 0.12), 0 8px 24px -8px rgba(219, 58, 68, 0.25) !important;
}

/* ====== PROGRESS BAR GRADIENTS ====== */

body.twilio-flex .progress-gradient .progress-bar {
  background: linear-gradient(90deg, var(--flex-accent), #6366f1);
  box-shadow: 0 2px 8px rgba(31, 111, 255, 0.28);
}

body.twilio-flex .progress-gradient-success .progress-bar {
  background: linear-gradient(90deg, #14b86f, #0ea5e9);
  box-shadow: 0 2px 8px rgba(20, 184, 111, 0.28);
}

body.twilio-flex .progress-gradient-warning .progress-bar {
  background: linear-gradient(90deg, #f59e0b, #f97316);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.28);
}

body.twilio-flex .progress-gradient-danger .progress-bar {
  background: linear-gradient(90deg, #ef4444, #db2777);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.28);
}

body.twilio-flex .progress {
  border-radius: 999px;
  overflow: hidden;
  background: rgba(200, 212, 230, 0.4);
}

:root[data-theme="dark"] body.twilio-flex .progress {
  background: rgba(30, 41, 59, 0.6);
}

/* ====== ANIMATED LOADING BAR ====== */

body.twilio-flex .loading-bar {
  height: 3px;
  background: linear-gradient(90deg,
    transparent,
    var(--flex-accent),
    var(--flex-info),
    #8b5cf6,
    var(--flex-accent),
    transparent);
  background-size: 300% 100%;
  animation: ns-loading-bar 2s linear infinite;
  border-radius: 2px;
}

/* ====== PULSE RING (for status dots) ====== */

body.twilio-flex .ring-pulse {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body.twilio-flex .ring-pulse::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  animation: ns-ring-pulse 2s ease-out infinite;
}

/* ====== BADGE ENHANCEMENTS ====== */

body.twilio-flex .badge-gradient-primary {
  background: linear-gradient(135deg, var(--flex-accent), #6366f1);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(31, 111, 255, 0.28);
}

body.twilio-flex .badge-gradient-success {
  background: linear-gradient(135deg, #14b86f, #0ea5e9);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(20, 184, 111, 0.28);
}

body.twilio-flex .badge-gradient-warning {
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.28);
}

body.twilio-flex .badge-gradient-danger {
  background: linear-gradient(135deg, #ef4444, #db2777);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.28);
}

/* ====== TIMELINE COMPONENT ====== */

body.twilio-flex .timeline {
  position: relative;
  padding-left: 1.6rem;
}

body.twilio-flex .timeline::before {
  content: '';
  position: absolute;
  left: 0.45rem;
  top: 0.3rem;
  bottom: 0.3rem;
  width: 2px;
  background: linear-gradient(180deg, var(--flex-accent), rgba(200, 212, 230, 0.5));
  border-radius: 1px;
}

body.twilio-flex .timeline-item {
  position: relative;
  margin-bottom: 1.25rem;
}

body.twilio-flex .timeline-item::before {
  content: '';
  position: absolute;
  left: -1.18rem;
  top: 0.38rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--flex-accent);
  border: 2px solid var(--flex-surface);
  box-shadow: 0 0 0 3px rgba(31, 111, 255, 0.18);
}

body.twilio-flex .timeline-item.success::before  { background: var(--flex-success); box-shadow: 0 0 0 3px rgba(20, 184, 111, 0.18); }
body.twilio-flex .timeline-item.warning::before  { background: var(--flex-warning); box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
body.twilio-flex .timeline-item.danger::before   { background: var(--flex-danger);  box-shadow: 0 0 0 3px rgba(219, 58, 68, 0.18); }

:root[data-theme="dark"] body.twilio-flex .timeline::before {
  background: linear-gradient(180deg, var(--flex-accent), rgba(71, 85, 105, 0.3));
}

:root[data-theme="dark"] body.twilio-flex .timeline-item::before {
  border-color: var(--flex-surface);
}

/* ====== AVATAR STACK ====== */

body.twilio-flex .avatar-stack {
  display: flex;
  align-items: center;
}

body.twilio-flex .avatar-stack .avatar-item {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--flex-surface);
  margin-left: -8px;
  background: linear-gradient(135deg, var(--flex-accent), #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: transform var(--flex-transition);
}

body.twilio-flex .avatar-stack .avatar-item:first-child { margin-left: 0; }
body.twilio-flex .avatar-stack .avatar-item:hover { transform: translateY(-2px); z-index: 2; }

/* ====== DIVIDER / SECTION LINE ====== */

body.twilio-flex .divider-gradient {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--flex-border), transparent);
  border: none;
  margin: 1.5rem 0;
}

/* ====== EMPTY STATE ENHANCEMENT ====== */

body.twilio-flex .empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(31, 111, 255, 0.08), rgba(139, 92, 246, 0.06));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  font-size: 1.75rem;
  color: var(--flex-accent);
}

/* ====== TOOLTIP ENHANCEMENT ====== */

body.twilio-flex .tooltip-inner {
  background: linear-gradient(135deg, #0b1b4d, #1f3b8a);
  box-shadow: 0 4px 12px rgba(11, 27, 77, 0.3);
}

/* ====== SECTION HEADER ====== */

body.twilio-flex .section-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--flex-border);
  margin-bottom: 1rem;
}

body.twilio-flex .section-header .section-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--flex-accent), #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.78rem;
  flex-shrink: 0;
}

body.twilio-flex .section-header .section-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--flex-muted);
}

/* ====== FLOATING NOTIFICATION DOT ====== */

body.twilio-flex .has-notif {
  position: relative;
}

body.twilio-flex .has-notif::after {
  content: '';
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: var(--flex-danger);
  border-radius: 50%;
  border: 2px solid var(--flex-surface);
  pointer-events: none;
}

/* ====== DARK ADDITIONS ====== */

:root[data-theme="dark"] body.twilio-flex .stat-card-blue,
:root[data-theme="dark"] body.twilio-flex .stat-card-green,
:root[data-theme="dark"] body.twilio-flex .stat-card-amber,
:root[data-theme="dark"] body.twilio-flex .stat-card-red,
:root[data-theme="dark"] body.twilio-flex .stat-card-purple {
  background: linear-gradient(135deg, rgba(31, 111, 255, 0.1) 0%, rgba(31, 111, 255, 0.04) 100%);
}

:root[data-theme="dark"] body.twilio-flex .stat-card-green {
  background: linear-gradient(135deg, rgba(20, 184, 111, 0.1) 0%, rgba(20, 184, 111, 0.04) 100%);
}

:root[data-theme="dark"] body.twilio-flex .stat-card-amber {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1) 0%, rgba(245, 158, 11, 0.04) 100%);
}

:root[data-theme="dark"] body.twilio-flex .stat-card-red {
  background: linear-gradient(135deg, rgba(219, 58, 68, 0.1) 0%, rgba(219, 58, 68, 0.04) 100%);
}

:root[data-theme="dark"] body.twilio-flex .stat-card-purple {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(139, 92, 246, 0.04) 100%);
}
