:root {
  --ms-bg: #f4f6fa;
  --ms-surface: #ffffff;
  --ms-border: #e4e8f0;
  --ms-text: #1f2733;
  --ms-muted: #6b7686;
  --ms-primary: #3462ff;
  --ms-sidebar-bg: #151b2c;
  --ms-sidebar-text: #aeb7cc;
  --ms-sidebar-active-bg: #22294a;
  --ms-sidebar-active-text: #ffffff;
  --ms-radius: 0.6rem;
  --ms-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

html {
  font-size: 15px;
}

@media (min-width: 768px) {
  html {
    font-size: 15.5px;
  }
}

body {
  background: var(--ms-bg);
  color: var(--ms-text);
  margin: 0;
}

/* ---------- top loading bar ---------- */
#load-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--ms-primary);
  z-index: 2000;
  opacity: 0;
  transition: width 0.4s ease, opacity 0.2s ease;
}

#load-bar.loading {
  opacity: 1;
  width: 78%;
  transition: width 6s cubic-bezier(0.1, 0.6, 0.2, 1), opacity 0.2s ease;
}

.btn-busy {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border: 0.15rem solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ms-spin 0.6s linear infinite;
}

.btn-outline-primary.btn-busy::after,
.btn-outline-secondary.btn-busy::after,
.btn-outline-danger.btn-busy::after,
.btn-outline-success.btn-busy::after {
  border-color: rgba(0, 0, 0, 0.2);
  border-top-color: currentColor;
}

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

/* ---------- app shell & layout ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
  position: relative;
}

.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 1040;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--ms-sidebar-bg);
  color: var(--ms-sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1045;
  user-select: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  height: 64px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #fff;
  text-decoration: none;
  font-weight: 650;
  letter-spacing: 0.01em;
  font-size: 1.05rem;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.55rem;
  background: linear-gradient(135deg, #3462ff 0%, #1e40af 100%);
  color: #fff;
  font-size: 1.05rem;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(52, 98, 255, 0.35);
}

.sidebar-brand-text {
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.45rem;
  color: var(--ms-sidebar-text);
  width: 1.85rem;
  height: 1.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.sidebar-nav {
  flex: 1 1 auto;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  color: var(--ms-sidebar-text);
  text-decoration: none;
  font-size: 0.92rem;
  position: relative;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
  white-space: nowrap;
}

.sidebar-link .icon {
  flex: 0 0 auto;
  font-size: 1.15rem;
  width: 1.25rem;
  text-align: center;
  opacity: 0.85;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transform: translateX(2px);
}

.sidebar-link:hover .icon {
  opacity: 1;
  transform: scale(1.1);
}

.sidebar-link.active {
  background: var(--ms-sidebar-active-bg);
  color: var(--ms-sidebar-active-text);
  font-weight: 550;
  box-shadow: inset 3px 0 0 #3462ff;
}

.sidebar-link.active .icon {
  color: #60a5fa;
  opacity: 1;
}

.sidebar-foot {
  padding: 0.85rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
  font-family: var(--bs-font-monospace, monospace);
  color: rgba(255, 255, 255, 0.45);
  white-space: nowrap;
  overflow: hidden;
}

/* ---------- desktop collapsed sidebar (rail mode) ---------- */
.app-shell.sidebar-collapsed .sidebar {
  width: 72px;
  flex: 0 0 72px;
}

.app-shell.sidebar-collapsed .sidebar-header {
  padding: 1.15rem 0.5rem;
  justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-brand-text,
.app-shell.sidebar-collapsed .sidebar-link-text,
.app-shell.sidebar-collapsed .sidebar-foot-text {
  display: none !important;
  opacity: 0;
}

.app-shell.sidebar-collapsed .sidebar-toggle-btn {
  display: none !important;
}

.app-shell.sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding: 0.65rem 0;
  transform: none;
}

.app-shell.sidebar-collapsed .sidebar-foot {
  text-align: center;
  padding: 0.85rem 0.25rem;
}

/* Tooltip on hover when collapsed on desktop */
.app-shell.sidebar-collapsed .sidebar-link:hover::after {
  content: attr(data-title);
  position: absolute;
  left: 78px;
  top: 50%;
  transform: translateY(-50%);
  background: #0f172a;
  color: #f8fafc;
  padding: 0.35rem 0.75rem;
  border-radius: 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  z-index: 1060;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  animation: msTooltipPop 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msTooltipPop {
  from { opacity: 0; transform: translateY(-50%) translateX(-6px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* ---------- topbar & content ---------- */
.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.75rem;
  background: var(--ms-surface);
  border-bottom: 1px solid var(--ms-border);
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
}

.topbar-burger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.3rem;
  height: 2.3rem;
  border: 1px solid var(--ms-border);
  background: transparent;
  border-radius: 0.45rem;
  color: var(--ms-text);
  cursor: pointer;
  font-size: 1.25rem;
  transition: all 0.15s ease;
}

.topbar-burger:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: var(--ms-primary);
}

.topbar-title {
  font-size: 1.2rem;
  font-weight: 650;
  margin: 0;
  flex: 1 1 auto;
  letter-spacing: -0.01em;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
}

.topbar-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #334155;
}

.topbar-avatar {
  color: var(--ms-primary);
  font-size: 1.15rem;
  display: inline-flex;
}

.topbar-username {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-content {
  padding: 1.75rem;
  flex: 1 1 auto;
  animation: msFadeInUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msFadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- mobile responsive drawer ---------- */
@media (max-width: 991px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    transform: translateX(-100%);
    width: 250px;
    flex: 0 0 250px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }

  .sidebar-mobile-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-mobile-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .topbar {
    padding: 0.75rem 1rem;
  }

  .page-content {
    padding: 1rem;
  }
}

/* ---------- cards, stat tiles & tables ---------- */
.card {
  border: 1px solid var(--ms-border);
  border-radius: var(--ms-radius);
  background: var(--ms-surface);
  box-shadow: var(--ms-shadow);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease;
}

.card:hover {
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--ms-border);
}

.table-responsive {
  border-radius: var(--ms-radius);
}

.table {
  --bs-table-bg: transparent;
}

.table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ms-muted);
  font-weight: 650;
  border-bottom-width: 1px;
  background: #f8fafc;
  padding: 0.75rem 0.9rem;
  white-space: nowrap;
}

.table tbody td {
  padding: 0.75rem 0.9rem;
}

.table tbody tr {
  transition: background-color 0.12s ease;
}

.table tbody tr:hover {
  background-color: rgba(52, 98, 255, 0.025);
}

/* ---------- modern stat tiles ---------- */
.stat-tile {
  border: 1px solid var(--ms-border);
  border-radius: var(--ms-radius);
  background: var(--ms-surface);
  box-shadow: var(--ms-shadow);
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.stat-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px -6px rgba(16, 24, 40, 0.1), 0 8px 10px -6px rgba(16, 24, 40, 0.04);
}

.stat-tile .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-tile .stat-label {
  color: var(--ms-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin-top: 0.2rem;
}

.stat-tile .stat-icon {
  position: absolute;
  top: 1.1rem;
  right: 1.15rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  background: rgba(52, 98, 255, 0.08);
  color: var(--ms-primary);
  transition: transform 0.2s ease;
}

.stat-tile:hover .stat-icon {
  transform: scale(1.1);
}

.stat-tile.warn .stat-value { color: #d97706; }
.stat-tile.warn .stat-icon { background: rgba(217, 119, 6, 0.12); color: #d97706; }

.stat-tile.danger .stat-value { color: #dc2626; }
.stat-tile.danger .stat-icon { background: rgba(220, 38, 38, 0.1); color: #dc2626; }

.stat-tile.good .stat-value { color: #16a34a; }
.stat-tile.good .stat-icon { background: rgba(22, 163, 74, 0.1); color: #16a34a; }

/* ---------- interactive chart cards ---------- */
.chart-card {
  border: 1px solid var(--ms-border);
  border-radius: var(--ms-radius);
  background: var(--ms-surface);
  box-shadow: var(--ms-shadow);
  padding: 1.25rem 1.35rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.chart-card:hover {
  box-shadow: 0 10px 25px -4px rgba(16, 24, 40, 0.08);
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.chart-card-title {
  font-size: 0.95rem;
  font-weight: 650;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: -0.01em;
}

.chart-canvas-container {
  position: relative;
  width: 100%;
  height: 220px;
  flex: 1 1 auto;
}

/* ---------- animated status pulses ---------- */
@keyframes msPulseGlowWarn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}

@keyframes msPulseGlowDanger {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.badge-pulse-warning {
  animation: msPulseGlowWarn 2s infinite;
}

.badge-pulse-danger {
  animation: msPulseGlowDanger 2s infinite;
}

/* ---------- custom modern scrollbars ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.7);
}

/* ---------- interactive button micro-interactions ---------- */
.btn {
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.12rem white, 0 0 0 0.25rem rgba(52, 98, 255, 0.5);
}
